Skip to content

Commit 4412730

Browse files
committed
Refine the catalogue update capability
Fixes #196
1 parent 359948b commit 4412730

File tree

7 files changed

+3039
-17158
lines changed

7 files changed

+3039
-17158
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ The following is a list of test statistics for the project by date and commit
9494

9595
| Date | Commit | Number of Tests | Code Coverage |
9696
|------------|-----------------------------------------------------------------------------------------------------------|-----------------|---------------|
97-
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12.05% |
98-
| 2022-01-15 | [081fe3f](https://github.com/stamp-web/stamp-web-aurelia/commit/081fe3f31d5962c10777f4017e2c7a5dbe26e12e) | 86 | 12.20% |
99-
| 2022-01-15 | [38899a3](https://github.com/stamp-web/stamp-web-aurelia/commit/38899a32d69cd5c62ade7341a83708d4a8e1e726) | 94 | 13.29% | |
100-
| 2022-01-25 | [c17f067](https://github.com/stamp-web/stamp-web-aurelia/commit/c17f06784332adff83e0a2594a705de26285d30a) | 98 | 18.35% |
101-
| 2022-06-08 | [a798ac3](https://github.com/stamp-web/stamp-web-aurelia/commit/a798ac36ac61a06258729173d8fa5cacf6a0ff24) | 102 | 18.41% |
102-
| 2022-06-08 | [e64d964](https://github.com/stamp-web/stamp-web-aurelia/commit/e64d964202e6b9930dda0712837682a71ad0d1db) | 104 | 18.59% |
103-
| 2023-01-04 | | 107 | 18.80% |
97+
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12.05% |
98+
| 2022-01-15 | [081fe3f](https://github.com/stamp-web/stamp-web-aurelia/commit/081fe3f31d5962c10777f4017e2c7a5dbe26e12e) | 86 | 12.20% |
99+
| 2022-01-15 | [38899a3](https://github.com/stamp-web/stamp-web-aurelia/commit/38899a32d69cd5c62ade7341a83708d4a8e1e726) | 94 | 13.29% |
100+
| 2022-01-25 | [c17f067](https://github.com/stamp-web/stamp-web-aurelia/commit/c17f06784332adff83e0a2594a705de26285d30a) | 98 | 18.35% |
101+
| 2022-06-08 | [a798ac3](https://github.com/stamp-web/stamp-web-aurelia/commit/a798ac36ac61a06258729173d8fa5cacf6a0ff24) | 102 | 18.41% |
102+
| 2022-06-08 | [e64d964](https://github.com/stamp-web/stamp-web-aurelia/commit/e64d964202e6b9930dda0712837682a71ad0d1db) | 104 | 18.59% |
103+
| 2023-01-04 | [359948b](https://github.com/stamp-web/stamp-web-aurelia/commit/359948b689f088ec8c8554044cab96c24ffe1a77) | 107 | 18.80% |
104+
| 2023-09-21 | | 123 | 20.27% |
105+
104106
## Optimizing for Browsers
105107

106108
To optimize the build for the latest browsers the command

package-lock.json

Lines changed: 2752 additions & 17079 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/resources/elements/stamps/stamp-replacement-table.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,30 @@
5353
<td>${ stamp.countryRef | byName:'countries' }</td>
5454
<td class="d-none d-lg-table-cell">${ stamp.rate + ' ' + stamp.description }</td>
5555
<td class="col-number">
56-
<input if.bind="editingRow === $index" type="text" class="form-control replacement-number-input" tabindex="0" value.bind="editingCatalogueNumber.number">
57-
<span if.bind="editingRow !== $index">
56+
<input if.bind="model.editingRow === $index" type="text" class="form-control replacement-number-input" tabindex="0" value.bind="editingCatalogueNumber.number">
57+
<span if.bind="model.editingRow !== $index">
5858
${ getReplacementCatalogueNumber(stamp).number }
5959
</span>
6060
</td>
6161
<td class="col-condition">
62-
<span class="condition-edit" if.bind="editingRow === $index">
62+
<span class="condition-edit" if.bind="model.editingRow === $index">
6363
<select-picker items.bind="conditions" disabled.bind="loading"
6464
value.two-way="editingCatalogueNumber.condition"
6565
config.bind="{ id: 'replacement-condition', tabIndex: 0, labelProperty: 'description', valueProperty: 'ordinal', filterSearch: false, caption: 'editor.condition-select' }">
6666
</select-picker>
6767
</span>
68-
<span if.bind="editingRow !== $index">
68+
<span if.bind="model.editingRow !== $index">
6969
${ getReplacementCatalogueNumber(stamp).condition|asEnum:'Condition'|t }
7070
</span>
7171
</td>
7272
<td class="col-catalogue-value">
73-
<span class="value-edit" if.bind="editingRow === $index">
73+
<span class="value-edit" if.bind="model.editingRow === $index">
7474
<input type="text" class="form-control replacement-value-input" disabled.bind="editingCatalogueNumber.unknown"
7575
keydown.delegate="advanceToNextRow($event)" tabindex="0" value.bind="editingCatalogueNumber.value | asNumber:true">
76-
<input type="checkbox" tabindex="1000" checked.bind="editingCatalogueNumber.unknown" click.trigger="changeUnknown(stamp)">
76+
<input type="checkbox" tabindex="0" checked.bind="editingCatalogueNumber.unknown" click.trigger="changeUnknown()">
7777
<span>${'editor.no-value-short'|t}</span>
7878
</span>
79-
<span if.bind="editingRow !== $index">
79+
<span if.bind="model.editingRow !== $index">
8080
<span show.bind="getReplacementCatalogueNumber(stamp).unknown" class="unknown">
8181
${'table.catalogue-value-unknown'|t}
8282
</span>
@@ -97,11 +97,11 @@
9797

9898
</div>
9999
<div class="stamp-replacement-footer">
100-
<button type="button" class="btn btn-primary ${editCount < 1 ? 'disabled': ''}" disabled.bind="editCount < 1" click.delegate="saveAll()">${'actions.save'|t}
100+
<button type="button" class="btn btn-primary ${model.editCount < 1 ? 'disabled': ''}" disabled.bind="model.editCount < 1" click.delegate="saveAll()">${'actions.save'|t}
101101
</button>
102102
<div class="filtering-message">
103-
<label>${ 'footer.filtering-total'|t}</label> <span class="badge ${!filteredStamps.length ? 'badge-default': 'badge-primary'}">${filteredStamps.length}</span>
104-
<label>${ 'footer.modified-total'|t}</label> <span class="badge ${!editCount ? 'badge-default': 'badge-success'}">${editCount}</span>
103+
<label>${ 'footer.filtering-total'|t}</label> <span>${filteredStamps.length}</span>
104+
<label>${ 'footer.modified-total'|t}</label> <span>${model.editCount}</span>
105105
</div>
106106
</div>
107107
</template>

src/resources/elements/stamps/stamp-replacement-table.js

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ const defaultImagePath = "https://drake-server.ddns.net/Thumbnails/";
3232
const logger = LogManager.getLogger('stamp-replacement-table');
3333

3434
@customElement('stamp-replacement-table')
35-
@bindable( {
35+
@bindable({
3636
name: 'stamps',
3737
defaultValue: []
3838
})
3939
export class StampReplacementTable {
4040

4141
model = {
4242
filterCatalogueRef: -1,
43-
replacementCatalogueRef: -1
43+
replacementCatalogueRef: -1,
44+
editCount: 0,
45+
editingRow: -1
4446
};
4547
catalogues = [];
4648
filteredStamps = [];
47-
editingRow = -1;
4849
conditions = Condition.symbols();
4950
editingCatalogueNumber;
50-
editCount = 0;
5151

5252

5353
static inject() {
@@ -64,23 +64,28 @@ export class StampReplacementTable {
6464
}
6565

6666
stampsChanged(newList, oldList) {
67-
if( newList !== oldList ) {
67+
if (newList !== oldList) {
6868
this.filterStamps();
6969
}
7070
}
7171

7272
editingRowChanged(newIndex) {
73-
this.editingCatalogueNumber = this.getReplacementCatalogueNumber( this.filteredStamps[newIndex]);
73+
// index may be empty
74+
if (this.model.editingRow < 0 || _.isEmpty(this.filteredStamps)) {
75+
return;
76+
}
77+
let stamp = this.filteredStamps[newIndex];
78+
this.editingCatalogueNumber = this.getReplacementCatalogueNumber(stamp);
7479
logger.debug(this.editingCatalogueNumber);
75-
if( this.editingCatalogueNumber ) {
76-
this._setupEditSubscribers(this.filteredStamps[newIndex], this.editingCatalogueNumber);
80+
if (this.editingCatalogueNumber) {
81+
this._setupEditSubscribers(stamp, this.editingCatalogueNumber);
7782
}
78-
_.debounce( () => {
83+
_.debounce(() => {
7984
$('.replacement-number-input').focus();
8085
}, 250)();
8186
}
8287

83-
attached( ) {
88+
attached() {
8489
this.loading = true;
8590
let cataloguePromise = this.catalogueService.find(this.catalogueService.getDefaultSearchOptions());
8691
let prefPromise = this.prefService.find(this.prefService.getDefaultSearchOptions());
@@ -93,7 +98,7 @@ export class StampReplacementTable {
9398

9499
this._editSubscribers = [];
95100
this._modelSubscribers = [];
96-
this._modelSubscribers.push(this.bindingEngine.propertyObserver(this, 'editingRow').subscribe(this.editingRowChanged.bind(this)));
101+
this._modelSubscribers.push(this.bindingEngine.propertyObserver(this.model, 'editingRow').subscribe(this.editingRowChanged.bind(this)));
97102
}
98103

99104
_processCatalogues(results) {
@@ -105,64 +110,67 @@ export class StampReplacementTable {
105110
this.thumbnailPath = LocationHelper.resolvePath(path, defaultImagePath);
106111
}
107112

108-
detached( ) {
113+
detached() {
109114
this._modelSubscribers.forEach(sub => {
110115
sub.dispose();
111116
});
112117
this._clearEditSubscribers();
113118
}
114119

115120

116-
117-
filterStamps( ) {
118-
this.filteredStamps.splice(0, this.filteredStamps.length);
119-
let self = this;
120-
_.each( this.stamps, stamp => {
121-
let index = _.findIndex( stamp.catalogueNumbers, { catalogueRef: self.model.filterCatalogueRef});
122-
if( index >= 0 ) {
123-
let s = _.clone(stamp, true);
121+
filterStamps() {
122+
this.filteredStamps = [];
123+
this.model.editCount = 0;
124+
this.model.editingRow = -1;
125+
//_.debounce(() => {
126+
_.each(this.stamps, stamp => {
127+
let index = _.findIndex(stamp.catalogueNumbers, (_cn) => {
128+
return _cn.catalogueRef === this.model.filterCatalogueRef;
129+
});
130+
if (index > -1) {
131+
let s = _.cloneDeep(stamp);
124132
let cn = s.catalogueNumbers[index];
125-
self._storeOriginalValues(cn);
126-
cn.catalogueRef = self.model.replacementCatalogueRef;
133+
this._storeOriginalValues(cn);
134+
cn.catalogueRef = this.model.replacementCatalogueRef;
127135
cn.replacing = true;
128-
self.filteredStamps.push( s );
136+
this.filteredStamps.push(s);
129137
}
130138
});
131-
if( this.filteredStamps.length > 0 ) {
132-
_.debounce(() => {
133-
this.editingRow = 0;
134-
})();
139+
if (this.filteredStamps.length > 0) {
140+
this.model.editingRow = 0;
135141
}
142+
// })();
143+
136144
}
137145

138146
select($index) {
139-
this.editingRow = $index;
147+
this.model.editingRow = $index;
140148
}
141149

142150
getCurrencyCode(cn) {
143-
if( cn ) {
144-
if( !cn.currencyCode ) {
145-
cn.currencyCode = _.find( this.catalogues, { id: cn.catalogueRef }).code;
151+
if (cn) {
152+
if (!cn.currencyCode) {
153+
cn.currencyCode = _.find(this.catalogues, {id: cn.catalogueRef}).code;
146154
}
147155
return cn.currencyCode;
148156
}
149157
}
150158

151159
getReplacementCatalogueNumber(stamp) {
152-
return _.find( stamp.catalogueNumbers, {replacing: true});
160+
return _.find(stamp.catalogueNumbers, {replacing: true});
153161
}
154162

155163
@computedFrom('model.filterCatalogueRef', 'model.replacementCatalogueRef')
156164
get filterReady() {
157-
return ( this.model.filterCatalogueRef >= 0 && this.model.replacementCatalogueRef >= 0 );
165+
return (this.model.filterCatalogueRef >= 0 && this.model.replacementCatalogueRef >= 0);
158166
}
159167

160168

161169
getImagePath(stamp) {
162170
let path = '';
163-
if( !stamp.wantList && !_.isEmpty(stamp.stampOwnerships && _.first(stamp.stampOwnerships).img)) {
171+
if (!stamp.wantList && !_.isEmpty(stamp.stampOwnerships && _.first(stamp.stampOwnerships).img)) {
164172
let img = _.first(stamp.stampOwnerships).img;
165-
if( img && img !== '' ) {
173+
if (img && img !== '') {
166174
var index = img.lastIndexOf('/');
167175
img = img.substring(0, index + 1) + "thumb-" + img.substring(index + 1);
168176
path = this.thumbnailPath + img;
@@ -184,24 +192,30 @@ export class StampReplacementTable {
184192
}
185193

186194
advanceToNextRow($event) {
187-
if( $event.keyCode === KeyCodes.VK_TAB && this.editingRow < this.filteredStamps.length - 2) {
188-
this.select(this.editingRow + 1);
195+
if ($event.keyCode === KeyCodes.VK_TAB && this.model.editingRow < this.filteredStamps.length - 1) {
196+
this.select(this.model.editingRow + 1);
189197
return false;
190198
}
191199
return true;
192200
}
193201

194202
saveAll() {
195-
let modified = _.filter(this.filteredStamps, { __modified__: true});
203+
let modified = _.filter(this.filteredStamps, {__modified__: true});
196204
let savePromises = [];
197205
_.each(modified, (stamp) => {
198206
savePromises.push(this.stampsService.save(stamp));
199207
});
200208
Promise.all(savePromises).then(result => {
201-
if( result ) {
209+
if (result) {
202210
_.each(result, s => { //eslint-disable-line no-unused-vars
203-
this.filterStamps();
211+
let index = _.findIndex(this.stamps, (s2) => {
212+
return s2.id === s.id;
213+
});
214+
if (index > -1) {
215+
this.stamps[index] = s;
216+
}
204217
});
218+
this.filterStamps();
205219
}
206220
});
207221
}
@@ -213,34 +227,38 @@ export class StampReplacementTable {
213227
this._editSubscribers.push(this.bindingEngine.propertyObserver(cn, 'condition').subscribe(this._checkForModifiedStamp.bind(this)));
214228
}
215229

216-
changeUnknown(stamp) {
217-
let cn = this.getReplacementCatalogueNumber(stamp);
218-
cn.unknown = (!cn.unknown && true);
219-
this._checkForModifiedStamp(stamp, cn);
230+
changeUnknown() {
231+
_.defer(() => {
232+
if (this.model.editingRow > -1) {
233+
let stamp = this.filteredStamps[this.model.editingRow];
234+
let cn = this.getReplacementCatalogueNumber(stamp);
235+
cn.unknown = (!cn.unknown && true);
236+
this._checkForModifiedStamp();
237+
}
238+
});
239+
220240
}
221241

222-
_clearEditSubscribers() {
223-
if( this._editSubscribers ) {
242+
_clearEditSubscribers() {
243+
if (this._editSubscribers) {
224244
this._editSubscribers.forEach(sub => {
225245
sub.dispose();
226246
});
227247
}
228248
this._editSubscribers = [];
229249
}
230250

231-
_checkForModifiedStamp(stamp, cn) {
232-
if( !stamp ) {
233-
stamp = this.filteredStamps[this.editingRow];
234-
}
235-
if( !cn) {
236-
cn = this.getReplacementCatalogueNumber(stamp);
251+
_checkForModifiedStamp() {
252+
if (this.model.editingRow < 0) {
253+
return;
237254
}
255+
let stamp = this.filteredStamps[this.model.editingRow];
256+
let cn = this.getReplacementCatalogueNumber(stamp);
238257
let currentModified = stamp.__modified__;
239258
let modified = this._markedAsModified(stamp, cn);
240-
if( modified !== currentModified ) {
241-
this.editCount += (modified) ? 1 : -1;
259+
if (modified !== currentModified) {
260+
this.model.editCount += (modified) ? 1 : -1;
242261
}
243-
244262
}
245263

246264
_storeOriginalValues(cn) {
@@ -254,20 +272,19 @@ export class StampReplacementTable {
254272
}
255273

256274
_markedAsModified(stamp, cn) {
257-
stamp.__modified__ = ( cn.__orig__.number !== cn.number ||
275+
stamp.__modified__ = (cn.__orig__.number !== cn.number ||
258276
cn.__orig__.condition !== cn.condition ||
259277
cn.__orig__.value !== cn.value ||
260-
cn.__orig__.unknown !== cn.unknown );
261-
return (stamp.__modified__ );
278+
cn.__orig__.unknown !== cn.unknown);
279+
return (stamp.__modified__);
262280
}
263281

264282
setAsModified(stamp) {
265283
stamp.__modified__ = true;
266-
this.editCount++;
284+
this.model.editCount++;
267285
}
268286

269287

270-
271288
}
272289

273290
/**

src/resources/elements/stamps/stamp-replacement-table.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ stamp-replacement-table {
150150
position: absolute;
151151
top: 50%;
152152
transform: translate(0, -50%);
153-
// line-height: calc(4rem - #{2 * $theme-padding-thin});
154153
padding-right: $theme-padding-thick;
155154
font-size: $theme-font-size-sm;
156-
.badge {
155+
156+
label + span:first-of-type {
157157
margin-right: $theme-margin-base;
158158
}
159159
}

0 commit comments

Comments
 (0)