diff --git a/README.md b/README.md index 8d9145d..5de1a6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/resources/locales/en/stamp-web.json b/resources/locales/en/stamp-web.json index e64ffe2..c13808a 100644 --- a/resources/locales/en/stamp-web.json +++ b/resources/locales/en/stamp-web.json @@ -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", @@ -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", @@ -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" }, @@ -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", diff --git a/src/events/event-managed.js b/src/events/event-managed.js index 8c44acc..eaad609 100644 --- a/src/events/event-managed.js +++ b/src/events/event-managed.js @@ -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', diff --git a/src/reports/report-helper.js b/src/reports/report-helper.js index a6235d0..979424a 100644 --- a/src/reports/report-helper.js +++ b/src/reports/report-helper.js @@ -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'; @@ -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; } @@ -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 { @@ -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: @@ -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 = '~'; diff --git a/src/resources/elements/editor-dialog.html b/src/resources/elements/editor-dialog.html index da8bcf3..4d26ca9 100644 --- a/src/resources/elements/editor-dialog.html +++ b/src/resources/elements/editor-dialog.html @@ -13,7 +13,7 @@