diff --git a/locales/en/stamp-web.json b/locales/en/stamp-web.json index fe575f4..5146a01 100644 --- a/locales/en/stamp-web.json +++ b/locales/en/stamp-web.json @@ -2,6 +2,7 @@ "nav": { "manage": "Manage", "settings": "Manage settings", + "settings-short": "Settings", "stamps": "Stamps", "upgrade": "Upgrade", "title": "Stamp Web", @@ -13,6 +14,7 @@ "clear-all": "Clear all selected stamps" }, "footer": { + "filtering-total": "Stamps matching filter criteria:", "totalSelected": "Selected", "total": "Total" }, @@ -66,6 +68,7 @@ "defects-select": "Select defects", "description": "Description", "details-title": "Details", + "filtering-catalogue": "Filtering Catalogue", "grade": "Grade", "grade-select": "Select grade", "hide": "close", @@ -80,6 +83,7 @@ "purchase-total": "Total purchase", "purchased": "Purchased", "rate": "Denomination", + "replacement-catalogue": "Replacement Catalogue", "seller": "Seller", "seller-select": "Select a seller", "stamp-collection": "Stamp collection", @@ -154,6 +158,7 @@ }, "actions": { "add-cn": "Add a new catalogue number", + "apply": "Apply", "purchase": "Enter purchase information for selected stamps", "cancel": "Cancel", "cancel-changes" : "Cancel edit", @@ -164,7 +169,11 @@ "save": "Save", "save-and-new": "Save and new", "save-changes" : "Save edit", - "page-size": "Size" + "page-size": "Size", + "show-as-grid": "Show as a grid", + "show-as-table": "Show as a table", + "show-as-upgrade": "Update catalogue numbers to a new catalogue", + "show-reference-cataloguenumbers": "Show reference catalogue numbers" }, "paging-toolbar": { "page": "Page" diff --git a/src/app.js b/src/app.js index 270c2f5..3da2aa6 100644 --- a/src/app.js +++ b/src/app.js @@ -42,8 +42,7 @@ export class App { title: this.i18n.tr('nav.stamps') }, {route: 'manage', moduleId: './views/manage/manage-list', nav: true, title: this.i18n.tr('nav.manage')}, - {route: 'settings', moduleId: './views/preferences/user-settings', nav: false, title: 'Settings'}, - {route: 'upgrade', name: 'upgrade', moduleId: './views/catalogues/catalogue-upgrade', nav: true, title: this.i18n.tr('nav.upgrade')} + {route: 'settings', moduleId: './views/preferences/user-settings', nav: false, title: this.i18n.tr('nav.settings-short')} ]); this.router = router; } diff --git a/src/components/catalogue-numbers/cn-details.js b/src/components/catalogue-numbers/cn-details.js index 72d82f5..1e530ac 100644 --- a/src/components/catalogue-numbers/cn-details.js +++ b/src/components/catalogue-numbers/cn-details.js @@ -142,9 +142,7 @@ export class CatalogueNumberDetailsComponent extends EventManaged { loadCatalogues() { var self = this; - this.catalogueService.find({ - $orderby: 'issue desc' - }).then(results => { + this.catalogueService.find(this.catalogueService.getDefaultSearchOptions()).then(results => { self.catalogues = results.models; self.loading = false; }); diff --git a/src/components/stamps/stamp-replacement-table.html b/src/components/stamps/stamp-replacement-table.html index 534978d..7f1eaee 100644 --- a/src/components/stamps/stamp-replacement-table.html +++ b/src/components/stamps/stamp-replacement-table.html @@ -2,19 +2,78 @@ + + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ + + + + ${filteredStamps.length} + +
+
+ + + + - + + + +
${'table.country'|t} ${'table.description'|t}${'table.catalogue-number'|t}${'table.condition'|t}${'table.catalogue-value'|t}
${ stamp.countryRef | byName:'countries' } ${ stamp.rate + ' ' + stamp.description } + + + + + ${ getReplacementCatalogueNumber(stamp).number } + + + + + + + + ${ getReplacementCatalogueNumber(stamp).condition|asEnum:'Condition'|t } + + + + + + + ${ getReplacementCatalogueNumber(stamp).value|asCurrencyFormatted:getCurrencyCode(getReplacementCatalogueNumber(stamp)) } + +
diff --git a/src/components/stamps/stamp-replacement-table.js b/src/components/stamps/stamp-replacement-table.js index 484156d..49d5b16 100644 --- a/src/components/stamps/stamp-replacement-table.js +++ b/src/components/stamps/stamp-replacement-table.js @@ -13,9 +13,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {customElement, bindable} from 'aurelia-framework'; +import {customElement, bindable, computedFrom, LogManager} from 'aurelia-framework'; +import {BindingEngine} from 'aurelia-binding'; +import {Stamps} from '../../services/stamps'; +import {Catalogues} from '../../services/catalogues'; +import {Condition} from '../../util/common-models'; -// import dataTable from 'datatables'; // eslint-disable-line no-unused-vars +import _ from 'lodash'; +import $ from 'jquery'; + + +const logger = LogManager.getLogger('stamp-replacement-table'); @customElement('stamp-replacement-table') @bindable( { @@ -24,32 +32,97 @@ import {customElement, bindable} from 'aurelia-framework'; }) export class StampReplacementTable { - //_dataTable; + model = { + filterCatalogueRef: -1, + replacementCatalogueRef: -1 + }; + catalogues = []; + filteredStamps = []; + editingRow = -1; + conditions = Condition.symbols(); + editingCatalogueNumber; + static inject() { - return [Element]; + return [Element, BindingEngine, Catalogues, Stamps]; } - constructor(element) { + constructor(element, bindingEngine, catalogues, stamps) { this.element = element; + this.bindingEngine = bindingEngine; + this.catalogueService = catalogues; + this.stampsService = stamps; + } + + stampsChanged(newList, oldList) { + if( newList !== oldList ) { + this.filterStamps(); + } + } + + editingRowChanged(newIndex) { + this.editingCatalogueNumber = this.getReplacementCatalogueNumber( this.filteredStamps[newIndex]); + logger.debug(this.editingCatalogueNumber); + _.debounce( () => { + $('.replacement-number-input').focus(); + }, 250)(); } attached( ) { - /*this._dataTable = $(this.element).find('table').dataTable({ - data: this.stamps, - info: false, - paging: false, - scrollX: false, - scrollY: '100%', - scrollCollapse: true, - searching: false - }); */ + this.loading = true; + this.catalogueService.find(this.catalogueService.getDefaultSearchOptions()).then(results => { + this.catalogues = results.models; + this.loading = false; + }); + this._modelSubscribers = []; + this._modelSubscribers.push(this.bindingEngine.propertyObserver(this, 'editingRow').subscribe(this.editingRowChanged.bind(this))); } detached( ) { - /*if( this._dataTable) { - this._dataTable.api().destroy(); - }*/ + this._modelSubscribers.forEach(sub => { + sub.dispose(); + }); + } + + filterStamps( ) { + this.filteredStamps.splice(0, this.filteredStamps.length); + let self = this; + _.each( this.stamps, stamp => { + let index = _.findIndex( stamp.catalogueNumbers, { catalogueRef: self.model.filterCatalogueRef}); + if( index >= 0 ) { + let s = _.clone(stamp, true); + s.catalogueNumbers[index].catalogueRef = self.model.replacementCatalogueRef; + s.catalogueNumbers[index].replacing = true; + self.filteredStamps.push( s ); + } + }); + if( this.filteredStamps.length > 0 ) { + _.debounce( context => { + context.editingRow = 0; + })(this); + } + } + + select($event, $index) { + this.editingRow = $index; + } + + getCurrencyCode(cn) { + if( cn ) { + if( !cn.currencyCode ) { + cn.currencyCode = _.find( this.catalogues, { id: cn.catalogueRef }).code; + } + return cn.currencyCode; + } + } + + getReplacementCatalogueNumber(stamp) { + return _.find( stamp.catalogueNumbers, {replacing: true}); + } + + @computedFrom('model.filterCatalogueRef', 'model.replacementCatalogueRef') + get filterReady() { + return ( this.model.filterCatalogueRef >= 0 && this.model.replacementCatalogueRef >= 0 ); } } diff --git a/src/components/stamps/stamp-replacement-table.less b/src/components/stamps/stamp-replacement-table.less index a72f7c9..e0654f9 100644 --- a/src/components/stamps/stamp-replacement-table.less +++ b/src/components/stamps/stamp-replacement-table.less @@ -10,5 +10,13 @@ stamp-replacement-table { width: 100%; height: 100%; overflow-y: auto; + tr { + height: 39px; + } + } + + .form-control { + height: 28px; + font-size: @font-size-small; } } diff --git a/src/util/common-models.js b/src/util/common-models.js index e118a1a..ba7750f 100644 --- a/src/util/common-models.js +++ b/src/util/common-models.js @@ -89,7 +89,7 @@ export class Enum { let self = this; let symbol; this.keys().forEach( k => { - if( self[k].ordinal === ordinal ) { + if( self[k].ordinal === +ordinal ) { symbol = self[k]; } }); diff --git a/src/views/catalogues/catalogue-upgrade.html b/src/views/catalogues/catalogue-upgrade.html deleted file mode 100644 index 4fef9e4..0000000 --- a/src/views/catalogues/catalogue-upgrade.html +++ /dev/null @@ -1,23 +0,0 @@ - diff --git a/src/views/catalogues/catalogue-upgrade.js b/src/views/catalogues/catalogue-upgrade.js deleted file mode 100644 index 89d9c34..0000000 --- a/src/views/catalogues/catalogue-upgrade.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - Copyright 2016 Jason Drake - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ -import {LogManager} from 'aurelia-framework'; -import {Router} from 'aurelia-router'; -import {SessionContext} from '../../services/session-context'; -import {Stamps} from '../../services/stamps'; - -const logger = LogManager.getLogger('catalogue-upgrade'); - -export class CatalogueUpgradeManager { - - stamps = []; - currentFilters = []; - - static inject() { - return [Router, Stamps]; - } - - constructor(router, stampService) { - this.router = router; - this.stampService = stampService; - } - - attached() { - this._searchHandle = this.processSearchRequest.bind(this); - SessionContext.addContextListener(SessionContext.SEARCH_CHANGE, this._searchHandle ); - }; - - detached() { - SessionContext.removeContextListener(SessionContext.SEARCH_CHANGE, this._searchHandle ); - }; - - processSearchRequest(data, oldData) { //eslint-disable-line no-unused-vars - let self = this; - let options = (!self.options) ? {} : self.options; - if( data ) { - options.$filter = data.serialize(); - self.currentFilters = data.flatten(); - logger.debug(self.currentFilters); - } - self.search(options); - } - - search(options) { - return new Promise((resolve, reject) => { - //var opts = this.options; // this.buildOptions(); - //this.stampService.clearSelected(); - this.stampService.find(options).then(result => { - this.router.navigate(this.router.generate('upgrade', options)); - this.processStamps(result, options); - resolve(); - }).catch(err => { - logger.debug(err); - reject(err); - }); - }); - } - - processStamps(result, opts) { - this.stamps = result.models; - console.table(opts); - } - - -} diff --git a/src/views/catalogues/catalogue-upgrade.less b/src/views/catalogues/catalogue-upgrade.less deleted file mode 100644 index 138bb1e..0000000 --- a/src/views/catalogues/catalogue-upgrade.less +++ /dev/null @@ -1,30 +0,0 @@ -@import "@@pathToTheme/@@theme/variables.less"; - -@grid-nav-height: 55px; - -.stamp-replacement-main { - height: calc(~"100% - 110px"); - position: relative; - top: @grid-nav-height; - - .stamp-replacement-content { - height: 100%; - position: relative; - right: 0; - top: 0; - bottom: 0; - // background-color: pink; - } - - .stamp-replacement-search { - height: 100%; - position: relative; - left: 0; - top: 0; - bottom: 0; - padding-top: 2 * @padding-large-vertical; - // background-color: blue; - - } -} - diff --git a/src/views/stamps/stamp-list.html b/src/views/stamps/stamp-list.html index 479ed32..df3c1c9 100644 --- a/src/views/stamps/stamp-list.html +++ b/src/views/stamps/stamp-list.html @@ -3,6 +3,7 @@ + @@ -46,16 +47,19 @@
- - +
-
@@ -118,10 +122,11 @@
- - + +
diff --git a/src/views/stamps/stamp-list.js b/src/views/stamps/stamp-list.js index 92dbe41..e332d85 100644 --- a/src/views/stamps/stamp-list.js +++ b/src/views/stamps/stamp-list.js @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {inject, LogManager} from 'aurelia-framework'; +import {inject, LogManager, computedFrom} from 'aurelia-framework'; import {EventAggregator} from 'aurelia-event-aggregator'; import {I18N} from 'aurelia-i18n'; import {Countries} from '../../services/countries'; @@ -54,7 +54,7 @@ export class StampList extends EventManaged { stampCount = 0; countries = []; heading = "Stamp List"; - gridMode = true; + displayMode = 'Grid'; imageShown = false; editorShown = false; panelContents = "stamp-editor"; @@ -290,10 +290,17 @@ export class StampList extends EventManaged { this.editorShown = true; } - setViewMode(mode) { - var m = ( mode === 'Grid'); - this.gridMode = m; - this.listMode = !m; + setDisplayMode(mode) { + this.displayMode = mode; + } + + getDisplayModeClass(mode) { + return ( this.displayMode === mode ) ? 'active' : ''; + } + + @computedFrom('referenceMode', 'displayMode') + get referenceTableState() { + return this.referenceMode && this.displayMode === 'Grid' ? 'active' : (this.displayMode !== 'Grid') ? 'disabled' : ''; } toggleCatalogueNumbers() {