Skip to content

Commit e64d964

Browse files
committed
Provide the ability to create Save and New on edit
When editing a stamp if you click Save and New it will create a new instance of a stamp based on the stamp you are saving (or editing). The values of the stamp will be set from the preferences (if defined) and initialized. Fixes #172
1 parent a798ac3 commit e64d964

File tree

6 files changed

+60
-59
lines changed

6 files changed

+60
-59
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ Webdriver for NodeJS is used for the integration tests. This project has been mo
9090

9191
## Test Statistics
9292

93-
The following is a list of test statistics for the project for date
93+
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
| --- |-----------------------------------------------------------------------------------------------------------|-----------------|---------------|
9797
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12.05% |
9898
| 2022-01-15 | [081fe3f](https://github.com/stamp-web/stamp-web-aurelia/commit/081fe3f31d5962c10777f4017e2c7a5dbe26e12e) | 86 | 12.20% |
9999
| 2022-01-15 | [38899a3](https://github.com/stamp-web/stamp-web-aurelia/commit/38899a32d69cd5c62ade7341a83708d4a8e1e726) | 94 | 13.29% |
100100
| 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%
101102

102103
## Optimizing for Browsers
103104

src/resources/elements/stamps/stamp-editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="editor-buttons">
1818
<button type="button" class="btn btn-secondary" click.delegate="cancel()">${'actions.cancel'|t}</button>
19-
<button type="button" class="btn btn-secondary" click.delegate="saveAndNew()" disabled.bind="invalid" if.bind="createMode">${'actions.save-and-new'|t}</button>
19+
<button type="button" class="btn btn-secondary" click.delegate="saveAndNew()" disabled.bind="invalid">${'actions.save-and-new'|t}</button>
2020
<button type="button" class="btn btn-primary" click.delegate="save()" disabled.bind="invalid">${'actions.save'|t}</button>
2121
</div>
2222
</div>

src/resources/elements/stamps/stamp-editor.js

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,21 @@ export class StampEditorComponent extends EventManaged {
330330
}
331331

332332
save(keepOpen) {
333-
let self = this;
334-
if (self.preprocess()) {
333+
if (this.preprocess()) {
335334
// patch for https://github.com/aurelia/validatejs/issues/68
336-
_.each(self.duplicateModel.catalogueNumbers, cn => {
335+
_.each(this.duplicateModel.catalogueNumbers, cn => {
337336
if (cn.__validationReporter__) {
338337
delete cn.__validationReporter__;
339338
}
340339
});
341-
self.stampService.save(self.duplicateModel).then(stamp => {
342-
if( self.duplicateModel.id <= 0 ) {
343-
self.eventBus.publish(EventNames.stampCount, { stamp: self.duplicateModel, increment: true });
344-
self.cacheSessionValues(self.duplicateModel);
340+
this.stampService.save(this.duplicateModel).then(stamp => {
341+
if( this.duplicateModel.id <= 0 ) {
342+
this.eventBus.publish(EventNames.stampCount, { stamp: this.duplicateModel, increment: true });
343+
this.cacheSessionValues(this.duplicateModel);
345344
}
346-
self.eventBus.publish(EventNames.stampSaved, { stamp: stamp, remainOpen: keepOpen });
345+
this.eventBus.publish(EventNames.stampSaved, { stamp: stamp, remainOpen: keepOpen });
347346
if( keepOpen) {
348-
self._resetModel();
347+
this._resetModel(this.duplicateModel);
349348
}
350349
}).catch(err => {
351350
logger.error(err);
@@ -379,34 +378,9 @@ export class StampEditorComponent extends EventManaged {
379378
return true;
380379
}
381380

382-
_resetModel() {
381+
_resetModel(theModel) {
383382
this._resetValidity();
384-
this.duplicateModel.id = 0;
385-
this.duplicateModel.rate = "";
386-
this.duplicateModel.description = "";
387-
this._resetCatalogueNumber(this.activeCatalogueNumber);
388-
this._resetOwnership(this.ownership);
389-
this.model = this.duplicateModel;
390-
}
391-
392-
_resetCatalogueNumber(cn) {
393-
cn.id = 0;
394-
cn.number = "";
395-
cn.unknown = false;
396-
cn.nospace = false;
397-
cn.value = 0;
398-
}
399-
400-
_resetOwnership(owner) {
401-
if( owner ) {
402-
owner.notes = undefined;
403-
owner.cert = false;
404-
owner.img = undefined;
405-
owner.certImg = undefined;
406-
owner.pricePaid = 0.0;
407-
owner.defects = 0;
408-
owner.deception = 0;
409-
}
383+
this.model = StampHelper.createEmptyStamp(theModel.wantList);
410384
}
411385

412386
_resetValidity() {
@@ -434,24 +408,24 @@ export class StampEditorComponent extends EventManaged {
434408
@computedFrom('duplicateModel')
435409
get ownership() {
436410
let self = this;
437-
if (!self.duplicateModel) {
411+
if (!this.duplicateModel) {
438412
return undefined;
439413
}
440-
let owners = self.duplicateModel.stampOwnerships;
414+
let owners = this.duplicateModel.stampOwnerships;
441415
let owner;
442-
if( self.duplicateModel.wantList === false ) {
416+
if( this.duplicateModel.wantList === false ) {
443417
let configureOwnership = () => {
444-
self.duplicateModel.stampOwnerships = [];
418+
this.duplicateModel.stampOwnerships = [];
445419
owner = createOwnership();
446-
if( owner && self.cachedValues.purchased ) {
447-
owner.purchased = self.cachedValues.purchased;
420+
if( owner && this.cachedValues.purchased ) {
421+
owner.purchased = this.cachedValues.purchased;
448422
}
449-
self.duplicateModel.stampOwnerships.push(owner);
423+
this.duplicateModel.stampOwnerships.push(owner);
450424
};
451425
if (!owners) {
452426
configureOwnership();
453-
} else if (self.duplicateModel.stampOwnerships.length > 0) {
454-
owner = _.first(self.duplicateModel.stampOwnerships);
427+
} else if (this.duplicateModel.stampOwnerships.length > 0) {
428+
owner = _.first(this.duplicateModel.stampOwnerships);
455429
} else {
456430
configureOwnership();
457431

src/util/common-models.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ export var StampHelper = function() {
294294
}
295295
}
296296
return path;
297+
},
298+
299+
createEmptyStamp: (wantList) => {
300+
return {
301+
id: 0,
302+
rate: '',
303+
description: '',
304+
wantList: wantList,
305+
countryRef: -1,
306+
catalogueNumbers: [],
307+
stampOwnerships: []
308+
};
297309
}
298310
};
299311
}();

src/views/stamps/stamp-list.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {SessionContext} from '../../services/session-context';
2525
import {EventNames, StorageKeys, EventManaged} from '../../events/event-managed';
2626
import {KeyCodes} from '../../events/key-codes';
2727
import {LocationHelper} from '../../util/location-helper';
28-
import {StampFilter, ConditionFilter, Condition, CurrencyCode} from '../../util/common-models';
28+
import {StampFilter, ConditionFilter, Condition, CurrencyCode, StampHelper} from '../../util/common-models';
2929
import {PredicateUtilities} from '../../util/object-utilities';
3030

3131
import {asCurrencyValueConverter} from '../../resources/value-converters/as-currency-formatted';
@@ -37,16 +37,6 @@ import _ from 'lodash';
3737

3838
const logger = LogManager.getLogger('stamp-list');
3939

40-
function createStamp(wantList) {
41-
return {
42-
id: 0,
43-
wantList: wantList,
44-
countryRef: -1,
45-
catalogueNumbers: [],
46-
stampOwnerships: []
47-
};
48-
}
49-
5040
@inject(Element, EventAggregator, Router, Stamps, Countries, Preferences, asCurrencyValueConverter, I18N, DialogService, PdfGenerator, ReportHelper)
5141
export class StampList extends EventManaged {
5242

@@ -320,7 +310,7 @@ export class StampList extends EventManaged {
320310

321311
showEditor(action) {
322312
if (action === 'create-stamp' || action === 'create-wantList') {
323-
this.editingStamp = createStamp((action === 'create-wantList'));
313+
this.editingStamp = StampHelper.createEmptyStamp((action === 'create-wantList'));
324314
this.panelContents = "stamp-editor";
325315
} else if (action === 'search-panel') {
326316
this.panelContents = action;

test/unit/util/common-models.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ describe('EnumeratedTypeHelper test suite', () => {
4949

5050
describe('StampHelper test suite', () => {
5151

52+
describe('createEmptyStamp test', () => {
53+
it('as wantlist', () => {
54+
let stamp = StampHelper.createEmptyStamp(true);
55+
expect(stamp.rate).toBe('');
56+
expect(stamp.description).toBe('');
57+
expect(stamp.id).toBe(0);
58+
expect(stamp.wantList).toBe(true);
59+
expect(stamp.countryRef).toBe(-1);
60+
expect(stamp.catalogueNumbers).toEqual([]);
61+
expect(stamp.stampOwnerships).toEqual([]);
62+
});
63+
64+
it('as stamp', () => {
65+
let stamp = StampHelper.createEmptyStamp(false);
66+
expect(stamp.rate).toBe('');
67+
expect(stamp.description).toBe('');
68+
expect(stamp.id).toBe(0);
69+
expect(stamp.wantList).toBe(false);
70+
expect(stamp.countryRef).toBe(-1);
71+
expect(stamp.catalogueNumbers).toEqual([]);
72+
expect(stamp.stampOwnerships).toEqual([]);
73+
});
74+
});
75+
5276
describe('calculateImagePath test', () => {
5377

5478
let countryServiceSpy;

0 commit comments

Comments
 (0)