From 42a57a31a2b19d6a2c1c81c21deb9b8941fb601a Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 5 Nov 2024 21:21:42 +0100 Subject: [PATCH 1/6] add route product price list for inline editing of product prices - same filters as original product list - allows editing purchasePrice, margin and sellingPrice - auto saves whenever a change occurs The initial search returns ES search objects, so the template is made to handle both ES and ED (which also means adjusting some components to handle both). ember-data records are fetched to be able to save the records with their changes, but also react on changes in the template. Data is shown the moment ES returns a response. ED records are loaded while the user can already see the table. Some helpers specified inside a model are moved out of it so these can be used by ES results too. --- app/components/fmt/unit-code.js | 16 +- app/components/fmt/unit-price.hbs | 10 +- app/components/fmt/unit-price.js | 39 ++--- app/components/main-menu.hbs | 7 +- app/components/product/category-tree.hbs | 7 + app/components/product/edit.js | 33 +--- .../main/products/{index.js => list.js} | 14 +- app/controllers/main/products/list/index.js | 14 ++ app/controllers/main/products/list/prices.js | 79 ++++++++++ app/helpers/constant.js | 6 + app/models/unit-price-specification.js | 8 +- app/router.js | 3 + .../main/products/{index.js => list.js} | 0 app/templates/main/products/list.hbs | 92 +++++++++++ .../main/products/{ => list}/index.hbs | 101 +----------- app/templates/main/products/list/prices.hbs | 144 ++++++++++++++++++ app/utils/product-price.js | 47 ++++++ package.json | 1 + 18 files changed, 446 insertions(+), 175 deletions(-) create mode 100644 app/components/product/category-tree.hbs rename app/controllers/main/products/{index.js => list.js} (92%) create mode 100644 app/controllers/main/products/list/index.js create mode 100644 app/controllers/main/products/list/prices.js create mode 100644 app/helpers/constant.js rename app/routes/main/products/{index.js => list.js} (100%) create mode 100644 app/templates/main/products/list.hbs rename app/templates/main/products/{ => list}/index.hbs (56%) create mode 100644 app/templates/main/products/list/prices.hbs create mode 100644 app/utils/product-price.js diff --git a/app/components/fmt/unit-code.js b/app/components/fmt/unit-code.js index 7b54778..34d6b65 100644 --- a/app/components/fmt/unit-code.js +++ b/app/components/fmt/unit-code.js @@ -1,15 +1,23 @@ import Component from '@glimmer/component'; export default class FmtUnitCodeComponent extends Component { + get label() { + if (typeof this.args.value === 'string') { + return this.args.value; + } else { + // ED unitPrice object + return this.args.value?.get('label'); + } + } get htmlLabel() { - if (this.args.value == 'm1') { + if (this.label == 'm1') { return 'm'; - } else if (this.args.value == 'm2') { + } else if (this.label == 'm2') { return 'm2'; - } else if (this.args.value == 'st') { + } else if (this.alabel == 'st') { return 'stuk'; } else { - return this.args.value; + return this.label; } } } diff --git a/app/components/fmt/unit-price.hbs b/app/components/fmt/unit-price.hbs index 12fc2af..4f9b49b 100644 --- a/app/components/fmt/unit-price.hbs +++ b/app/components/fmt/unit-price.hbs @@ -1,6 +1,4 @@ -{{#if this.currencyValueLoader.isResolved}} - - {{#if @showUnit}}/ {{/if}} -{{/if}} \ No newline at end of file + +{{#if @showUnit}}/ {{/if}} \ No newline at end of file diff --git a/app/components/fmt/unit-price.js b/app/components/fmt/unit-price.js index d7ec592..eeef3e9 100644 --- a/app/components/fmt/unit-price.js +++ b/app/components/fmt/unit-price.js @@ -1,36 +1,27 @@ import Component from '@glimmer/component'; -import { cached } from '@glimmer/tracking'; -import { TrackedAsyncData } from 'ember-async-data'; import { VAT_RATE } from '../../config'; import { calculatePriceTaxIncluded, calculatePriceTaxExcluded } from '../../utils/calculate-price'; - +import { get } from '@ember/object'; export default class FmtUnitPriceComponent extends Component { // Note: - // this.args.model maybe a Proxy object coming from ember-data + // this.args.model may be a unit-price-specification Proxy object coming from ember-data // or a plain javascript object coming as nested object from mu-search. - @cached - get currencyValueLoader() { + get currencyValue() { + // eslint-disable-next-line ember/no-get + return get(this.args.model, 'currencyValue'); + } + + get isTaxIncluded() { + // eslint-disable-next-line ember/no-get + return `${get(this.args.model, 'valueAddedTaxIncluded')}` === 'true'; // cover for mu-search where 'true' is a string + } + + get calculatedCurrencyValue() { if (this.args.showTaxIncluded) { - const loadData = async () => { - const model = await this.args.model; - return calculatePriceTaxIncluded( - model.currencyValue, - VAT_RATE, - `${model.valueAddedTaxIncluded}` === 'true', // cover for mu-search where 'true' is a string - ); - }; - return new TrackedAsyncData(loadData()); + return calculatePriceTaxIncluded(this.currencyValue, VAT_RATE, this.isTaxIncluded); } else { - const loadData = async () => { - const model = await this.args.model; - return calculatePriceTaxExcluded( - model.currencyValue, - VAT_RATE, - `${model.valueAddedTaxIncluded}` === 'true', // cover for mu-search where 'true' is a string - ); - }; - return new TrackedAsyncData(loadData()); + return calculatePriceTaxExcluded(this.currencyValue, VAT_RATE, this.isTaxIncluded); } } } diff --git a/app/components/main-menu.hbs b/app/components/main-menu.hbs index 40d5887..7fae1fb 100644 --- a/app/components/main-menu.hbs +++ b/app/components/main-menu.hbs @@ -12,11 +12,16 @@