Skip to content

Commit

Permalink
Produce Reports with some prompts
Browse files Browse the repository at this point in the history
Does not fully resolve this feature but does go a long way into producing better reports.
#65

Fixes #195
  • Loading branch information
jadrake75 committed Nov 1, 2023
1 parent dcc8f89 commit fd3f25d
Show file tree
Hide file tree
Showing 20 changed files with 757 additions and 130 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The following is a list of test statistics for the project by date and commit
| 2023-01-04 | [359948b](https://github.com/stamp-web/stamp-web-aurelia/commit/359948b689f088ec8c8554044cab96c24ffe1a77) | 107 | 18.80% |
| 2023-09-21 | [4412730](https://github.com/stamp-web/stamp-web-aurelia/commit/441273055dc1af57257aba29f929923799563325) | 123 | 20.27% |
| 2023-10-08 | [054cb00](https://github.com/stamp-web/stamp-web-aurelia/commit/054cb004b15133867f98c10276397a1f2a1f88be) | 134 | 20.68% |
| 2023-11-01 | | 160 | 22.38% |

## Optimizing for Browsers

Expand Down
18 changes: 17 additions & 1 deletion resources/locales/en/stamp-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@
"description": "Description",
"details-title": "Details",
"filtering-catalogue": "Filtering Catalogue",
"generate-report": "Generate Report",
"grade": "Grade",
"grade-select": "Select grade",
"hide": "close",
"issue": "Year of Issue",
"includeCountries": "Include Countries",
"includeNotes": "Include Notes",
"name": "Name",
"modify-existing": "Modify existing values",
"modifyTimestamp": "Modified",
Expand All @@ -100,7 +103,8 @@
"seller-select": "Select a seller",
"stamp-collection": "Stamp collection",
"stamp-collection-select": "Select a stamp collection",
"switchToCreate-hint": "Switch to create stamp"
"switchToCreate-hint": "Switch to create stamp",
"update-image-paths": "Update image paths"
},
"filters": {
"filter": "Filter",
Expand Down Expand Up @@ -138,6 +142,7 @@
"nameRequired": "Name is required",
"numberRequired": "Number is required",
"numberInvalid": "Number exceeds the 25 character limit",
"stampCollectionRequired": "Stamp Collection is required",
"resolveErrors": "Resolve issues to continue",
"valueInvalid": "Value is not a number"
},
Expand Down Expand Up @@ -211,6 +216,17 @@
"paging-toolbar": {
"page": "Page"
},
"reports": {
"name": "Report Title",
"action": "Generate",
"condition": "Condition",
"country": "Country",
"defaultTitle": "Filtered Stamps",
"description": "Description",
"notes": "Notes",
"number": "Number",
"value": "Cat. Value"
},
"footer-statistics": {
"catalogue-value": "Report on catalogue value",
"purchased": "Report on price paid",
Expand Down
1 change: 1 addition & 0 deletions src/events/event-managed.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const EventNames = {
create: 'create',
manageEntity: 'manage-entity',
entityDelete: 'entity-delete',
generateReport: 'generate-report',
selectEntity: 'select-entity',
entityFilter: 'entity-filter',
loadingStarted: 'loading-started',
Expand Down
144 changes: 110 additions & 34 deletions src/reports/report-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import {LogManager} from 'aurelia-framework';
import {Condition, CurrencyCode} from '../util/common-models';
import {asCurrencyValueConverter} from '../resources/value-converters/as-currency-formatted';

import {I18N} from 'aurelia-i18n';
import * as reportStyles from './report-styles.json';

import _ from 'lodash';
Expand All @@ -25,14 +25,69 @@ const logger = LogManager.getLogger('report-helper');

export class ReportHelper {

countries = [];

static inject() {
return [ReportValueConverter];
return [ReportValueConverter, I18N];
}

constructor(reportValueConverter) {
constructor(reportValueConverter, i18next) {
this.converter = reportValueConverter;
this.i18next = i18next;
}

buildReport(stamps, countries, reportValue, options) {
let reportModel = _.get(options, 'model', {});
let title = _.get(reportModel, 'title', this.i18next.tr('reports.defaultTitle'));
let includeCountries = _.get(reportModel, 'includeCountries', false);
let includeNotes = _.get(reportModel, 'includeNotes', false);

let columns = [
{name: ' ', type: 'issues', value: 'stampOwnerships[0]'},
{name: this.i18next.tr('reports.number'), type: 'catalogueNumber', value: 'activeCatalogueNumber.number'},
{name: this.i18next.tr('reports.description'), type: 'text', value: 'rate', additional: ['description'], width: '*'},
{name: this.i18next.tr('reports.condition'), type: 'condition', value: 'activeCatalogueNumber.condition'},
{
name: this.i18next.tr('reports.value'),
type: 'currencyValue',
value: 'activeCatalogueNumber.value',
additional: ['activeCatalogueNumber.code']
}
];
if(includeCountries) {
columns.splice(1,0, {name: this.i18next.tr('reports.country'), type: 'country', value: 'countryRef'});
}
if(includeNotes) {
let index = includeCountries ? 4 : 3;
columns.splice(index,0, {name: this.i18next.tr('reports.notes'), type: 'notes', value: 'stampOwnerships[0]', width: '*'});
}

let tmodel = this.generateTableModel(stamps, countries,{
cols: columns
});
let styles = this.getStandardStyleDefinition();
let opts = {
content: []
};

opts.content.push(this.generateText(`Report: ${title}`, 'header'));
opts.content.push(this.generateText(`Total number of stamps: ${stamps.length}`, 'text'));
opts.content.push(this.generateText(`Total value: ${reportValue}`, 'text'));
opts.content.push({
table: tmodel, style: 'table', layout: {
hLineColor: (i, node) => {
return '#aaa';
},
vLineColor: (i, node) => {
return '#aaa';
}
}
});
opts.styles = styles;
return opts;
}


getStandardStyleDefinition() {
return reportStyles;
}
Expand All @@ -44,48 +99,69 @@ export class ReportHelper {
};
}

generateTableModel(stamps, config) {
generateTableModel(stamps, countries, config) {
let model = {
body: []
body: [],
widths: []
};
if (!_.isEmpty(config.cols)) {
let tr = [];

_.forEach(config.cols, col => {
tr.push({ text: col.name || col.type, style: 'tableHeader'});
model.widths.push(col.width || 'auto');
});
model.headerRows = 1;
model.widths = ['auto', '*', 'auto', 'auto'];
model.body.push(tr);
}

_.forEach(stamps, stamp => {
let row = [];
_.forEach(config.cols, col => {
let val = _.get(stamp, col.value);
switch (col.type) {
case 'catalogueNumber':
row.push(val);
break;
case 'condition':
row.push(this.converter.fromCondition(val));
break;
case 'currencyValue':
let currencyCode = _.get(stamp, col.code, 'EUR');
let v = this.converter.fromCurrencyValue(val, currencyCode);
row.push(v);
break;
case 'text':
_.forEach(col.additional, a => {
val += ' ' + _.get(stamp, a, '');
});
row.push(val);
break;
}
_.forEach(stamps, stamp => {
let row = [];
_.forEach(config.cols, col => {
row.push(this.generateTableCellValue(stamp, col, countries));
});
model.body.push(row);
});
model.body.push(row);
});
}
return model;
}

generateTableCellValue(stamp, col, countries) {
let val = _.get(stamp, col.value);
let result = '';
switch (col.type) {
case 'catalogueNumber':
result = val;
break;
case 'condition':
result = this.converter.fromCondition(val);
break;
case 'currencyValue':
let currencyCode = _.get(stamp, col.code, CurrencyCode.USD.key);
result = this.converter.fromCurrencyValue(val, currencyCode);
break;
case 'country':
let c = _.find(countries, {id: val});
result = c ? c.name : '';
break;
case 'issues':
if (val && val.deception > 0) {
result = '\u0394';
} else if (val && val.defects > 0) {
result = '\u00D7';
}
break;
case 'notes':
result = (val && val.notes) ? val.notes : '';
break;
case 'text':
_.forEach(col.additional, a => {
val += ' ' + _.get(stamp, a, '');
});
result = val;
break;
}
return result;
}
}

export class ReportValueConverter {
Expand All @@ -108,7 +184,7 @@ export class ReportValueConverter {
let value = '';
switch (condition) {
case Condition.MINT.ordinal:
case Condition.MINT_HH:
case Condition.MINT_HH.ordinal:
value = '*';
break;
case Condition.MINT_NH.ordinal:
Expand All @@ -119,7 +195,7 @@ export class ReportValueConverter {
break;
case Condition.USED.ordinal:
case Condition.CTO.ordinal:
value = 'u';
value = 'u'; // '\u00f8';
break;
case Condition.MANUSCRIPT.ordinal:
value = '~';
Expand Down
2 changes: 1 addition & 1 deletion src/resources/elements/editor-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="messaging" show.bind="errorMsg !== ''">
<i class="sw-icon-attention" ></i> ${errorMsg}
</div>
<button type="button" class="btn btn-primary editor-save" tabindex="5000" click.delegate="save()" disabled.bind="!valid">${'actions.save'|t}</button>
<button type="button" class="btn btn-primary editor-save" tabindex="5000" click.delegate="save()" disabled.bind="!valid">${saveText}</button>
<button type="button" class="btn btn-secondary editor-cancel" tabindex="5050" data-bs-dismiss="modal">${'actions.cancel'|t}</button>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/resources/elements/editor-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import {EventNames, EventManaged} from '../../events/event-managed';
@bindable('content')
@bindable('title')
@bindable('icon')
@bindable('saveText')

export class EditorDialog extends EventManaged {

static inject = [EventAggregator, I18N];

@bindable publishEvent = EventNames.save;
errorMsg = '';
subscriptions = [];
valid = true;
Expand All @@ -37,6 +40,7 @@ export class EditorDialog extends EventManaged {
this.i18n = i18n;
this.eventBus = eventBus;
this.setupSubscriptions();
this.saveText = this.saveText || this.i18n.tr('actions.save');
}

modelChanged() {
Expand Down Expand Up @@ -67,7 +71,7 @@ export class EditorDialog extends EventManaged {
}

save() {
this.eventBus.publish(EventNames.save, {model: this.model, aspects: this.aspects});
this.eventBus.publish(this.publishEvent, {model: this.model, aspects: this.aspects});

}
}
12 changes: 9 additions & 3 deletions src/resources/elements/editor-dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ editor-dialog {
background-color: $theme-appbar-bg;
color: $theme-appbar-color;
display: flex;

padding: $theme-padding-base;
padding: 0;
}
}

Expand All @@ -34,8 +33,15 @@ editor-dialog {
font-size: $theme-font-size-sm;
}

.checkbox {
.checkbox, input[type='checkbox'] {
height: 1.6rem;
margin-right: $theme-margin-thin;
}

label {
align-items: start;
padding-top: $theme-padding-thin + $theme-padding-thinner;
display: flex;
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/resources/elements/reports/report-builder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<require from="../../value-converters/empty-text"></require>
<form>
<div class="form-group row">
<label for="report-name" class="col-sm-3">${'reports.name'|t}</label>
<div class="col-sm-9">
<input id="report-name" tabindex="10" class="form-control" type="text" value.bind="model.title | emptyText">
</div>
</div>
<div class="form-group row">
<span class="col-sm-3"></span>
<label class="col-sm-9">
<input type="checkbox" tabindex="90" checked.bind="model.includeCountries">
<span>${'editor.includeCountries'|t}</span>
</label>
</div>
<div class="form-group row">
<span class="col-sm-3"></span>
<label class="col-sm-9">
<input type="checkbox" tabindex="90" checked.bind="model.includeNotes">
<span>${'editor.includeNotes'|t}</span>
</label>
</div>
</form>
</template>
32 changes: 32 additions & 0 deletions src/resources/elements/reports/report-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
Copyright 2023 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 _ from 'lodash';
import {EventNames} from "../../../events/event-managed";
import {inject} from "aurelia-framework";

@inject()
export class ReportBuilder {

model;

activate(options) {
this.model = options;
}

save() {
this.eventBus.publish(EventNames.generateReport, {model: this.model});
}
}
1 change: 1 addition & 0 deletions src/resources/elements/reports/report-builder.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../../../theme/_semantic.scss";
Loading

0 comments on commit fd3f25d

Please # to comment.