Skip to content

Commit

Permalink
Provide the ability to create Save and New on edit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jadrake75 committed Jun 8, 2022
1 parent a798ac3 commit e64d964
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 59 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ Webdriver for NodeJS is used for the integration tests. This project has been mo

## Test Statistics

The following is a list of test statistics for the project for date
The following is a list of test statistics for the project by date and commit

| Date | Commit | Number of Tests | Code Coverage |
| --- |-----------------------------------------------------------------------------------------------------------|-----------------|---------------|
| 2022-01-15 | [8ac447f](https://github.com/stamp-web/stamp-web-aurelia/commit/8ac447f580f29d1f0f8dd23e284c6f25448cf1d7) | 83 | 12.05% |
| 2022-01-15 | [081fe3f](https://github.com/stamp-web/stamp-web-aurelia/commit/081fe3f31d5962c10777f4017e2c7a5dbe26e12e) | 86 | 12.20% |
| 2022-01-15 | [38899a3](https://github.com/stamp-web/stamp-web-aurelia/commit/38899a32d69cd5c62ade7341a83708d4a8e1e726) | 94 | 13.29% |
| 2022-01-25 | [c17f067](https://github.com/stamp-web/stamp-web-aurelia/commit/c17f06784332adff83e0a2594a705de26285d30a) | 98 | 18.35%
| 2022-06-08 | [a798ac3](https://github.com/stamp-web/stamp-web-aurelia/commit/a798ac36ac61a06258729173d8fa5cacf6a0ff24) | 102 | 18.41%

## Optimizing for Browsers

Expand Down
2 changes: 1 addition & 1 deletion src/resources/elements/stamps/stamp-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="editor-buttons">
<button type="button" class="btn btn-secondary" click.delegate="cancel()">${'actions.cancel'|t}</button>
<button type="button" class="btn btn-secondary" click.delegate="saveAndNew()" disabled.bind="invalid" if.bind="createMode">${'actions.save-and-new'|t}</button>
<button type="button" class="btn btn-secondary" click.delegate="saveAndNew()" disabled.bind="invalid">${'actions.save-and-new'|t}</button>
<button type="button" class="btn btn-primary" click.delegate="save()" disabled.bind="invalid">${'actions.save'|t}</button>
</div>
</div>
Expand Down
64 changes: 19 additions & 45 deletions src/resources/elements/stamps/stamp-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,21 @@ export class StampEditorComponent extends EventManaged {
}

save(keepOpen) {
let self = this;
if (self.preprocess()) {
if (this.preprocess()) {
// patch for https://github.com/aurelia/validatejs/issues/68
_.each(self.duplicateModel.catalogueNumbers, cn => {
_.each(this.duplicateModel.catalogueNumbers, cn => {
if (cn.__validationReporter__) {
delete cn.__validationReporter__;
}
});
self.stampService.save(self.duplicateModel).then(stamp => {
if( self.duplicateModel.id <= 0 ) {
self.eventBus.publish(EventNames.stampCount, { stamp: self.duplicateModel, increment: true });
self.cacheSessionValues(self.duplicateModel);
this.stampService.save(this.duplicateModel).then(stamp => {
if( this.duplicateModel.id <= 0 ) {
this.eventBus.publish(EventNames.stampCount, { stamp: this.duplicateModel, increment: true });
this.cacheSessionValues(this.duplicateModel);
}
self.eventBus.publish(EventNames.stampSaved, { stamp: stamp, remainOpen: keepOpen });
this.eventBus.publish(EventNames.stampSaved, { stamp: stamp, remainOpen: keepOpen });
if( keepOpen) {
self._resetModel();
this._resetModel(this.duplicateModel);
}
}).catch(err => {
logger.error(err);
Expand Down Expand Up @@ -379,34 +378,9 @@ export class StampEditorComponent extends EventManaged {
return true;
}

_resetModel() {
_resetModel(theModel) {
this._resetValidity();
this.duplicateModel.id = 0;
this.duplicateModel.rate = "";
this.duplicateModel.description = "";
this._resetCatalogueNumber(this.activeCatalogueNumber);
this._resetOwnership(this.ownership);
this.model = this.duplicateModel;
}

_resetCatalogueNumber(cn) {
cn.id = 0;
cn.number = "";
cn.unknown = false;
cn.nospace = false;
cn.value = 0;
}

_resetOwnership(owner) {
if( owner ) {
owner.notes = undefined;
owner.cert = false;
owner.img = undefined;
owner.certImg = undefined;
owner.pricePaid = 0.0;
owner.defects = 0;
owner.deception = 0;
}
this.model = StampHelper.createEmptyStamp(theModel.wantList);
}

_resetValidity() {
Expand Down Expand Up @@ -434,24 +408,24 @@ export class StampEditorComponent extends EventManaged {
@computedFrom('duplicateModel')
get ownership() {
let self = this;
if (!self.duplicateModel) {
if (!this.duplicateModel) {
return undefined;
}
let owners = self.duplicateModel.stampOwnerships;
let owners = this.duplicateModel.stampOwnerships;
let owner;
if( self.duplicateModel.wantList === false ) {
if( this.duplicateModel.wantList === false ) {
let configureOwnership = () => {
self.duplicateModel.stampOwnerships = [];
this.duplicateModel.stampOwnerships = [];
owner = createOwnership();
if( owner && self.cachedValues.purchased ) {
owner.purchased = self.cachedValues.purchased;
if( owner && this.cachedValues.purchased ) {
owner.purchased = this.cachedValues.purchased;
}
self.duplicateModel.stampOwnerships.push(owner);
this.duplicateModel.stampOwnerships.push(owner);
};
if (!owners) {
configureOwnership();
} else if (self.duplicateModel.stampOwnerships.length > 0) {
owner = _.first(self.duplicateModel.stampOwnerships);
} else if (this.duplicateModel.stampOwnerships.length > 0) {
owner = _.first(this.duplicateModel.stampOwnerships);
} else {
configureOwnership();

Expand Down
12 changes: 12 additions & 0 deletions src/util/common-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ export var StampHelper = function() {
}
}
return path;
},

createEmptyStamp: (wantList) => {
return {
id: 0,
rate: '',
description: '',
wantList: wantList,
countryRef: -1,
catalogueNumbers: [],
stampOwnerships: []
};
}
};
}();
Expand Down
14 changes: 2 additions & 12 deletions src/views/stamps/stamp-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {SessionContext} from '../../services/session-context';
import {EventNames, StorageKeys, EventManaged} from '../../events/event-managed';
import {KeyCodes} from '../../events/key-codes';
import {LocationHelper} from '../../util/location-helper';
import {StampFilter, ConditionFilter, Condition, CurrencyCode} from '../../util/common-models';
import {StampFilter, ConditionFilter, Condition, CurrencyCode, StampHelper} from '../../util/common-models';
import {PredicateUtilities} from '../../util/object-utilities';

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

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

function createStamp(wantList) {
return {
id: 0,
wantList: wantList,
countryRef: -1,
catalogueNumbers: [],
stampOwnerships: []
};
}

@inject(Element, EventAggregator, Router, Stamps, Countries, Preferences, asCurrencyValueConverter, I18N, DialogService, PdfGenerator, ReportHelper)
export class StampList extends EventManaged {

Expand Down Expand Up @@ -320,7 +310,7 @@ export class StampList extends EventManaged {

showEditor(action) {
if (action === 'create-stamp' || action === 'create-wantList') {
this.editingStamp = createStamp((action === 'create-wantList'));
this.editingStamp = StampHelper.createEmptyStamp((action === 'create-wantList'));
this.panelContents = "stamp-editor";
} else if (action === 'search-panel') {
this.panelContents = action;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/util/common-models.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ describe('EnumeratedTypeHelper test suite', () => {

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

describe('createEmptyStamp test', () => {
it('as wantlist', () => {
let stamp = StampHelper.createEmptyStamp(true);
expect(stamp.rate).toBe('');
expect(stamp.description).toBe('');
expect(stamp.id).toBe(0);
expect(stamp.wantList).toBe(true);
expect(stamp.countryRef).toBe(-1);
expect(stamp.catalogueNumbers).toEqual([]);
expect(stamp.stampOwnerships).toEqual([]);
});

it('as stamp', () => {
let stamp = StampHelper.createEmptyStamp(false);
expect(stamp.rate).toBe('');
expect(stamp.description).toBe('');
expect(stamp.id).toBe(0);
expect(stamp.wantList).toBe(false);
expect(stamp.countryRef).toBe(-1);
expect(stamp.catalogueNumbers).toEqual([]);
expect(stamp.stampOwnerships).toEqual([]);
});
});

describe('calculateImagePath test', () => {

let countryServiceSpy;
Expand Down

0 comments on commit e64d964

Please sign in to comment.