From 73ee790f8d20ddf11b013ed2ce7e9f09c1a369e9 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 12 Apr 2022 14:27:06 +0200 Subject: [PATCH 01/10] removed isFarmer property --- modules/supplier/back/methods/supplier/getSummary.js | 7 +------ .../back/methods/supplier/specs/getSummary.spec.js | 8 -------- modules/supplier/front/summary/index.html | 5 ----- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/modules/supplier/back/methods/supplier/getSummary.js b/modules/supplier/back/methods/supplier/getSummary.js index 67f5267b6..c29a2a058 100644 --- a/modules/supplier/back/methods/supplier/getSummary.js +++ b/modules/supplier/back/methods/supplier/getSummary.js @@ -100,12 +100,7 @@ module.exports = Self => { }, ] }; - let supplier = await Self.app.models.Supplier.findOne(filter); - const farmerCode = 2; - if (supplier.sageWithholdingFk == farmerCode) - supplier.isFarmer = true; - - return supplier; + return Self.app.models.Supplier.findOne(filter); }; }; diff --git a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js index 21e56882f..30713f517 100644 --- a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js +++ b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js @@ -25,12 +25,4 @@ describe('Supplier getSummary()', () => { expect(payMethod.name).toEqual('PayMethod one'); }); - - it(`should get if supplier is farmer by sageWithholdingFk`, async() => { - const supplier = await app.models.Supplier.findById(2); - const supplierSummary = await app.models.Supplier.getSummary(2); - - expect(supplier.isFarmer).toBeUndefined(); - expect(supplierSummary.isFarmer).toEqual(true); - }); }); diff --git a/modules/supplier/front/summary/index.html b/modules/supplier/front/summary/index.html index 51ebde695..086cd844d 100644 --- a/modules/supplier/front/summary/index.html +++ b/modules/supplier/front/summary/index.html @@ -83,11 +83,6 @@ label="Account" value="{{::$ctrl.summary.account}}"> - - From 8e87ab62a879554c6d5a6b53202d3fe9e692d415 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 12 Apr 2022 14:40:25 +0200 Subject: [PATCH 02/10] feat(entry_latest-buys): add multi-check-dummy --- .../core/components/multi-check/locale/en.yml | 1 + .../core/components/multi-check/locale/es.yml | 3 +++ .../components/multi-check/multi-check.html | 21 +++++++++++++++- .../components/multi-check/multi-check.js | 25 ++++++++++++++++++- front/core/components/multi-check/style.scss | 12 +++++++++ .../back/methods/entry/editLatestBuys.js | 21 +++++++++++++--- modules/entry/front/latest-buys/index.html | 4 ++- modules/entry/front/latest-buys/index.js | 14 ++++++++--- 8 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 front/core/components/multi-check/locale/en.yml create mode 100644 front/core/components/multi-check/locale/es.yml diff --git a/front/core/components/multi-check/locale/en.yml b/front/core/components/multi-check/locale/en.yml new file mode 100644 index 000000000..ea52dcf8f --- /dev/null +++ b/front/core/components/multi-check/locale/en.yml @@ -0,0 +1 @@ +SelectAllRows: Select the {{rows}} row(s) \ No newline at end of file diff --git a/front/core/components/multi-check/locale/es.yml b/front/core/components/multi-check/locale/es.yml new file mode 100644 index 000000000..5365c3392 --- /dev/null +++ b/front/core/components/multi-check/locale/es.yml @@ -0,0 +1,3 @@ +SelectAllRows: Seleccionar las {{rows}} fila(s) +All: Se han seleccionado +row(s) have been selected.: fila(s). \ No newline at end of file diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html index fb950aaff..17b7598c3 100644 --- a/front/core/components/multi-check/multi-check.html +++ b/front/core/components/multi-check/multi-check.html @@ -2,4 +2,23 @@ ng-model="$ctrl.checked" indeterminate="$ctrl.isIndeterminate" translate-attr="{title: 'Check all'}"> - \ No newline at end of file + + + + + + All + + {{$ctrl.rows}} + + row(s) have been selected. + + {{$ctrl.AllRowsCount}} + + + \ No newline at end of file diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index afa1bc3c4..42ceb1887 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -138,6 +138,27 @@ export default class MultiCheck extends FormInput { }); } + countRows() { + if (!this.model || !this.model.data) return; + const data = this.model.data; + const params = { + filter: { + where: this.model.userParams, + limit: null + } + }; + + this.$http.get(this.model.url, {params}) + .then(res => { + this.AllRows = res.data; + this.AllRowsCount = this.$t('SelectAllRows', { + rows: res.data.length + }); + }); + this.rows = data.length; + this.checkedDummy = data.length; + } + /** * Toggles checked property on * all instances @@ -158,7 +179,9 @@ ngModule.vnComponent('vnMultiCheck', { checkField: '@?', checkAll: '=?', checked: '=?', - disabled: ' { type: ['Object'], required: true, description: `the buys which will be modified` + }, + { + arg: 'filter', + type: ['object'], + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' }], returns: { type: 'Object', @@ -30,8 +35,9 @@ module.exports = Self => { } }); - Self.editLatestBuys = async(field, newValue, lines, options) => { + Self.editLatestBuys = async(field, newValue, lines, filter, options) => { let tx; + console.log(filter); const myOptions = {}; if (typeof options == 'object') @@ -64,8 +70,16 @@ module.exports = Self => { const models = Self.app.models; const model = models[modelName]; - try { + let result; + console.log(filter); + + if (filter) { + result = await model.upsertWithWhere(filter, value, myOptions); + if (tx) await tx.commit(); + return result; + } + const promises = []; const targets = lines.map(line => { @@ -74,11 +88,10 @@ module.exports = Self => { const value = {}; value[field] = newValue; - for (let target of targets) promises.push(model.upsertWithWhere({id: target}, value, myOptions)); - const result = await Promise.all(promises); + result = await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 4eeeeedce..3b9c12860 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -31,7 +31,9 @@ + check-field="$checked" + check-dummy="$ctrl.checkDummy" + checked-dummy="$ctrl.checkedDummy"> Picture diff --git a/modules/entry/front/latest-buys/index.js b/modules/entry/front/latest-buys/index.js index 385e7e4b6..477aa6ad7 100644 --- a/modules/entry/front/latest-buys/index.js +++ b/modules/entry/front/latest-buys/index.js @@ -89,11 +89,13 @@ export default class Controller extends Section { get checked() { const buys = this.$.model.data || []; - const checkedBuys = []; + let checkedBuys = []; for (let buy of buys) { if (buy.$checked) checkedBuys.push(buy); } + if (this.checkedDummy) + checkedBuys = this.checkedDummy; return checkedBuys; } @@ -149,11 +151,12 @@ export default class Controller extends Section { const rowsToEdit = []; for (let row of this.checked) rowsToEdit.push({id: row.id, itemFk: row.itemFk}); - + console.log(this.editFilter); const data = { field: this.editedColumn.field, newValue: this.editedColumn.newValue, - lines: rowsToEdit + lines: rowsToEdit, + filter: this.editFilter }; return this.$http.post('Buys/editLatestBuys', data) @@ -162,6 +165,11 @@ export default class Controller extends Section { this.$.model.refresh(); }); } + + checkDummy() { + console.log('editFilter', this.model.userParams); + this.editFilter = this.model.userParams; + } } ngModule.component('vnEntryLatestBuys', { From f2ee987dec9924f261159d55302c956ce9c4c0ca Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 13 Apr 2022 08:15:47 +0200 Subject: [PATCH 03/10] fix multi-check --- .../components/multi-check/multi-check.html | 6 +++--- .../components/multi-check/multi-check.js | 15 +++++++++++--- .../back/methods/entry/editLatestBuys.js | 16 +++++++-------- modules/entry/front/latest-buys/index.html | 4 ++-- modules/entry/front/latest-buys/index.js | 20 +++++++++---------- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html index 17b7598c3..2c83d08e1 100644 --- a/front/core/components/multi-check/multi-check.html +++ b/front/core/components/multi-check/multi-check.html @@ -5,19 +5,19 @@ - + All {{$ctrl.rows}} row(s) have been selected. - + {{$ctrl.AllRowsCount}} diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index 42ceb1887..21f403838 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -106,6 +106,9 @@ export default class MultiCheck extends FormInput { this.toggle(); this.emit('change', value); + + if (!value) + this.checkedDummyCount = null; } /** @@ -156,7 +159,13 @@ export default class MultiCheck extends FormInput { }); }); this.rows = data.length; - this.checkedDummy = data.length; + } + + checkDummy() { + if (this.checkedDummyCount) + return this.checkedDummyCount = null; + + this.checkedDummyCount = 15; // console.log } /** @@ -180,8 +189,8 @@ ngModule.vnComponent('vnMultiCheck', { checkAll: '=?', checked: '=?', disabled: ' { }, { arg: 'filter', - type: ['object'], + type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' }], returns: { @@ -37,7 +37,7 @@ module.exports = Self => { Self.editLatestBuys = async(field, newValue, lines, filter, options) => { let tx; - console.log(filter); + console.log('filter', filter); const myOptions = {}; if (typeof options == 'object') @@ -72,22 +72,22 @@ module.exports = Self => { const model = models[modelName]; try { let result; - console.log(filter); + + const promises = []; + const value = {}; + value[field] = newValue; if (filter) { - result = await model.upsertWithWhere(filter, value, myOptions); + promises.push(model.upsertWithWhere(filter, value, myOptions)); + result = await Promise.all(promises); if (tx) await tx.commit(); return result; } - const promises = []; - const targets = lines.map(line => { return line[identifier]; }); - const value = {}; - value[field] = newValue; for (let target of targets) promises.push(model.upsertWithWhere({id: target}, value, myOptions)); diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 3b9c12860..b5773b04b 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -32,8 +32,8 @@ checked="$ctrl.checkAll" model="model" check-field="$checked" - check-dummy="$ctrl.checkDummy" - checked-dummy="$ctrl.checkedDummy"> + check-dummy-enabled="true" + checked-dummy-count="$ctrl.checkedDummyCount"> Picture diff --git a/modules/entry/front/latest-buys/index.js b/modules/entry/front/latest-buys/index.js index 477aa6ad7..7210649aa 100644 --- a/modules/entry/front/latest-buys/index.js +++ b/modules/entry/front/latest-buys/index.js @@ -89,13 +89,11 @@ export default class Controller extends Section { get checked() { const buys = this.$.model.data || []; - let checkedBuys = []; + const checkedBuys = []; for (let buy of buys) { if (buy.$checked) checkedBuys.push(buy); } - if (this.checkedDummy) - checkedBuys = this.checkedDummy; return checkedBuys; } @@ -144,6 +142,9 @@ export default class Controller extends Section { } get totalChecked() { + if (this.checkedDummyCount) + return this.checkedDummyCount; + return this.checked.length; } @@ -151,25 +152,22 @@ export default class Controller extends Section { const rowsToEdit = []; for (let row of this.checked) rowsToEdit.push({id: row.id, itemFk: row.itemFk}); - console.log(this.editFilter); + const data = { field: this.editedColumn.field, newValue: this.editedColumn.newValue, - lines: rowsToEdit, - filter: this.editFilter + lines: rowsToEdit }; + if (this.checkedDummyCount && this.checkedDummyCount > 0) + data.filter = this.$.model.userParams; + return this.$http.post('Buys/editLatestBuys', data) .then(() => { this.uncheck(); this.$.model.refresh(); }); } - - checkDummy() { - console.log('editFilter', this.model.userParams); - this.editFilter = this.model.userParams; - } } ngModule.component('vnEntryLatestBuys', { From 04f993e227694802cd919d6b664f0e4a34b779c3 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 13 Apr 2022 13:55:18 +0200 Subject: [PATCH 04/10] fix --- back/methods/collection/setSaleQuantity.js | 2 +- front/core/components/multi-check/multi-check.js | 2 +- modules/entry/back/methods/entry/editLatestBuys.js | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/back/methods/collection/setSaleQuantity.js b/back/methods/collection/setSaleQuantity.js index 82451b8be..95145e9a0 100644 --- a/back/methods/collection/setSaleQuantity.js +++ b/back/methods/collection/setSaleQuantity.js @@ -28,7 +28,7 @@ module.exports = Self => { const args = ctx.args; const models = Self.app.models; - const sale = await models.Sale.findById(args.saleId,); + const sale = await models.Sale.findById(args.saleId); return await sale.updateAttribute('quantity', args.quantity); }; }; diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index 21f403838..9e709d4e1 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -165,7 +165,7 @@ export default class MultiCheck extends FormInput { if (this.checkedDummyCount) return this.checkedDummyCount = null; - this.checkedDummyCount = 15; // console.log + this.checkedDummyCount = this.rows; } /** diff --git a/modules/entry/back/methods/entry/editLatestBuys.js b/modules/entry/back/methods/entry/editLatestBuys.js index 08e84fd1f..636efb8b4 100644 --- a/modules/entry/back/methods/entry/editLatestBuys.js +++ b/modules/entry/back/methods/entry/editLatestBuys.js @@ -37,7 +37,6 @@ module.exports = Self => { Self.editLatestBuys = async(field, newValue, lines, filter, options) => { let tx; - console.log('filter', filter); const myOptions = {}; if (typeof options == 'object') @@ -78,9 +77,11 @@ module.exports = Self => { value[field] = newValue; if (filter) { - promises.push(model.upsertWithWhere(filter, value, myOptions)); - result = await Promise.all(promises); + const valueData = await model.find(filter, myOptions); + result = await valueData.updateAttribute(field, newValue, myOptions); + if (tx) await tx.commit(); + return result; } From 8432815cb7d780b51c1bceb823173fcf7fcbc862 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 13 Apr 2022 14:58:46 +0200 Subject: [PATCH 05/10] refactor --- modules/entry/back/methods/entry/editLatestBuys.js | 13 ++++--------- .../entry/back/methods/entry/latestBuysFilter.js | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/modules/entry/back/methods/entry/editLatestBuys.js b/modules/entry/back/methods/entry/editLatestBuys.js index 636efb8b4..58d33e183 100644 --- a/modules/entry/back/methods/entry/editLatestBuys.js +++ b/modules/entry/back/methods/entry/editLatestBuys.js @@ -76,19 +76,14 @@ module.exports = Self => { const value = {}; value[field] = newValue; - if (filter) { - const valueData = await model.find(filter, myOptions); - result = await valueData.updateAttribute(field, newValue, myOptions); - - if (tx) await tx.commit(); - - return result; - } + if (filter) + lines = await models.Entry.latestBuysFilter(null, filter, myOptions);// ctx? + // get lines + console.log(lines.length); const targets = lines.map(line => { return line[identifier]; }); - for (let target of targets) promises.push(model.upsertWithWhere({id: target}, value, myOptions)); diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 04570533c..6399faa52 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -86,7 +86,7 @@ module.exports = Self => { } ], returns: { - type: ['Object'], + type: ['object'], root: true }, http: { From 69530d3019375f1826943a9edceff856d24c87c9 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 19 Apr 2022 14:12:31 +0200 Subject: [PATCH 06/10] fix filter --- front/core/components/multi-check/multi-check.html | 2 +- front/core/components/multi-check/multi-check.js | 11 ++++++----- modules/entry/back/methods/entry/editLatestBuys.js | 13 +++++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html index 2c83d08e1..8954a9b77 100644 --- a/front/core/components/multi-check/multi-check.html +++ b/front/core/components/multi-check/multi-check.html @@ -18,7 +18,7 @@ row(s) have been selected. - {{$ctrl.AllRowsCount}} + {{$ctrl.AllRowsText}} \ No newline at end of file diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index 9e709d4e1..841e98b2a 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -151,21 +151,22 @@ export default class MultiCheck extends FormInput { } }; + this.rows = data.length; + this.$http.get(this.model.url, {params}) .then(res => { - this.AllRows = res.data; - this.AllRowsCount = this.$t('SelectAllRows', { - rows: res.data.length + this.AllRowsCount = res.data.length; + this.AllRowsText = this.$t('SelectAllRows', { + rows: this.AllRowsCount }); }); - this.rows = data.length; } checkDummy() { if (this.checkedDummyCount) return this.checkedDummyCount = null; - this.checkedDummyCount = this.rows; + this.checkedDummyCount = this.AllRowsCount; } /** diff --git a/modules/entry/back/methods/entry/editLatestBuys.js b/modules/entry/back/methods/entry/editLatestBuys.js index 58d33e183..cae4c1d10 100644 --- a/modules/entry/back/methods/entry/editLatestBuys.js +++ b/modules/entry/back/methods/entry/editLatestBuys.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('editLatestBuys', { + Self.remoteMethodCtx('editLatestBuys', { description: 'Updates a column for one or more buys', accessType: 'WRITE', accepts: [{ @@ -35,7 +35,7 @@ module.exports = Self => { } }); - Self.editLatestBuys = async(field, newValue, lines, filter, options) => { + Self.editLatestBuys = async(ctx, field, newValue, lines, filter, options) => { let tx; const myOptions = {}; @@ -76,11 +76,12 @@ module.exports = Self => { const value = {}; value[field] = newValue; - if (filter) - lines = await models.Entry.latestBuysFilter(null, filter, myOptions);// ctx? - // get lines + if (filter) { + ctx.args.filter = {where: filter, limit: null}; + lines = await models.Buy.latestBuysFilter(ctx, null, myOptions);// ctx? + } + // get lines - console.log(lines.length); const targets = lines.map(line => { return line[identifier]; }); From 433afb8fe8dee54cd44c0cbd28eb5c3bb2576633 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 19 Apr 2022 15:21:28 +0200 Subject: [PATCH 07/10] change tooltip client descriptor btnFive --- modules/client/front/descriptor/index.html | 2 +- modules/client/front/descriptor/locale/es.yml | 1 + .../back/methods/entry/editLatestBuys.js | 7 ++-- .../entry/specs/editLatestBuys.spec.js | 32 +++++++++++++++++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index de7a86d3b..cad226416 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -105,7 +105,7 @@
diff --git a/modules/client/front/descriptor/locale/es.yml b/modules/client/front/descriptor/locale/es.yml index e6aca9665..71723e654 100644 --- a/modules/client/front/descriptor/locale/es.yml +++ b/modules/client/front/descriptor/locale/es.yml @@ -3,5 +3,6 @@ View consumer report: Ver informe de consumo From date: Fecha desde To date: Fecha hasta Go to user: Ir al usuario +Go to supplier: Ir al proveedor Client invoices list: Listado de facturas del cliente Pay method: Forma de pago \ No newline at end of file diff --git a/modules/entry/back/methods/entry/editLatestBuys.js b/modules/entry/back/methods/entry/editLatestBuys.js index cae4c1d10..90f1454b4 100644 --- a/modules/entry/back/methods/entry/editLatestBuys.js +++ b/modules/entry/back/methods/entry/editLatestBuys.js @@ -70,17 +70,14 @@ module.exports = Self => { const models = Self.app.models; const model = models[modelName]; try { - let result; - const promises = []; const value = {}; value[field] = newValue; if (filter) { ctx.args.filter = {where: filter, limit: null}; - lines = await models.Buy.latestBuysFilter(ctx, null, myOptions);// ctx? + lines = await models.Buy.latestBuysFilter(ctx, null, myOptions); } - // get lines const targets = lines.map(line => { return line[identifier]; @@ -88,7 +85,7 @@ module.exports = Self => { for (let target of targets) promises.push(model.upsertWithWhere({id: target}, value, myOptions)); - result = await Promise.all(promises); + const result = await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index b17b0ab21..2413c18f6 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -6,7 +6,7 @@ describe('Buy editLatestsBuys()', () => { const options = {transaction: tx}; try { - let ctx = { + const ctx = { args: { search: 'Ranged weapon longbow 2m' } @@ -18,7 +18,35 @@ describe('Buy editLatestsBuys()', () => { const newValue = 99; const lines = [{itemFk: original.itemFk, id: original.id}]; - await models.Buy.editLatestBuys(field, newValue, lines, options); + await models.Buy.editLatestBuys(ctx, field, newValue, lines, null, options); + + const [result] = await models.Buy.latestBuysFilter(ctx, null, options); + + expect(result[field]).toEqual(newValue); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should change the value of a given column for filter', async() => { + const tx = await models.Buy.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {typeFk: 1}; + const ctx = { + args: { + filter: filter + } + }; + + const field = 'size'; + const newValue = 88; + + await models.Buy.editLatestBuys(ctx, field, newValue, null, filter, options); const [result] = await models.Buy.latestBuysFilter(ctx, null, options); From ea2e38af4eb45697061372da7ca8973778855b34 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 20 Apr 2022 08:24:12 +0200 Subject: [PATCH 08/10] support front filter and front test for component --- .../components/multi-check/multi-check.html | 2 +- .../components/multi-check/multi-check.js | 12 +++-- .../multi-check/multi-check.spec.js | 53 ++++++++++++++++++- .../back/methods/entry/latestBuysFilter.js | 3 ++ 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html index 8954a9b77..eaa4577f0 100644 --- a/front/core/components/multi-check/multi-check.html +++ b/front/core/components/multi-check/multi-check.html @@ -18,7 +18,7 @@ row(s) have been selected. - {{$ctrl.AllRowsText}} + {{$ctrl.allRowsText}} \ No newline at end of file diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index 841e98b2a..ba40acd06 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -143,10 +143,12 @@ export default class MultiCheck extends FormInput { countRows() { if (!this.model || !this.model.data) return; + const data = this.model.data; + const modelParams = this.model.userParams; const params = { filter: { - where: this.model.userParams, + modelParams: modelParams, limit: null } }; @@ -155,9 +157,9 @@ export default class MultiCheck extends FormInput { this.$http.get(this.model.url, {params}) .then(res => { - this.AllRowsCount = res.data.length; - this.AllRowsText = this.$t('SelectAllRows', { - rows: this.AllRowsCount + this.allRowsCount = res.data.length; + this.allRowsText = this.$t('SelectAllRows', { + rows: this.allRowsCount }); }); } @@ -166,7 +168,7 @@ export default class MultiCheck extends FormInput { if (this.checkedDummyCount) return this.checkedDummyCount = null; - this.checkedDummyCount = this.AllRowsCount; + this.checkedDummyCount = this.allRowsCount; } /** diff --git a/front/core/components/multi-check/multi-check.spec.js b/front/core/components/multi-check/multi-check.spec.js index c8069da3c..ee8a95c88 100644 --- a/front/core/components/multi-check/multi-check.spec.js +++ b/front/core/components/multi-check/multi-check.spec.js @@ -4,10 +4,12 @@ import crudModel from 'core/mocks/crud-model'; describe('Component vnMultiCheck', () => { let controller; let $element; + let $httpBackend; beforeEach(ngModule('vnCore')); - beforeEach(inject($componentController => { + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; $element = angular.element(`
`); controller = $componentController('vnMultiCheck', {$element: $element}); controller._model = crudModel; @@ -26,6 +28,14 @@ describe('Component vnMultiCheck', () => { expect(controller._checked).toEqual(crudModel); expect(controller.toggle).toHaveBeenCalledWith(); }); + + it(`should set checkedDummyCount to null`, () => { + jest.spyOn(controller, 'toggle'); + controller.checkedDummyCount = 12; + controller.checked = null; + + expect(controller.checkedDummyCount).toBeNull(); + }); }); describe('toggle()', () => { @@ -132,4 +142,45 @@ describe('Component vnMultiCheck', () => { expect(thirdRow.checked).toBeTruthy(); }); }); + + describe('countRows()', () => { + it(`should count visible rows and all rows of model`, () => { + const data = controller.model.data; + controller.model.url = 'modelUrl/filter'; + const response = { + data: [ + {id: 1, name: 'My item 1'}, + {id: 2, name: 'My item 2'}, + {id: 3, name: 'My item 3'}, + {id: 4, name: 'My item 4'}, + {id: 5, name: 'My item 5'}, + {id: 6, name: 'My item 6'} + ] + }; + + controller.countRows(); + + $httpBackend.expectGET('modelUrl/filter').respond(response); + + expect(controller.rows).toEqual(data.length); + expect(controller.AllRowsCount).toEqual(response.length); + }); + }); + + describe('checkDummy()', () => { + it(`should set checkedDummyCount allRowsCount`, () => { + controller.checkedDummyCount = null; + controller.allRowsCount = 123; + controller.checkDummy(); + + expect(controller.checkedDummyCount).toEqual(controller.allRowsCount); + }); + + it(`should set checkedDummyCount to null`, () => { + controller.checkedDummyCount = 123; + controller.checkDummy(); + + expect(controller.checkedDummyCount).toBeNull(); + }); + }); }); diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 6399faa52..9693670c8 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -98,6 +98,9 @@ module.exports = Self => { Self.latestBuysFilter = async(ctx, filter, options) => { const myOptions = {}; + if (filter && filter.modelParams) + ctx.args = filter.modelParams; + if (typeof options == 'object') Object.assign(myOptions, options); From 62f7b80ed4f3590067db4a1b53b5ff4e67eabc2d Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 20 Apr 2022 08:55:43 +0200 Subject: [PATCH 09/10] quit $ --- e2e/helpers/selectors.js | 2 +- front/core/components/multi-check/multi-check.js | 1 + modules/entry/back/methods/entry/editLatestBuys.js | 8 ++++---- modules/entry/front/latest-buys/index.html | 6 +++--- modules/entry/front/latest-buys/index.js | 4 ++-- modules/entry/front/latest-buys/index.spec.js | 8 ++++---- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 799eb8fe7..8cbc91f6f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -1133,7 +1133,7 @@ export default { entryLatestBuys: { firstBuy: 'vn-entry-latest-buys tbody > tr:nth-child(1)', allBuysCheckBox: 'vn-entry-latest-buys thead vn-check', - secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.$checked"]', + secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.checked"]', editBuysButton: 'vn-entry-latest-buys vn-button[icon="edit"]', fieldAutocomplete: 'vn-autocomplete[ng-model="$ctrl.editedColumn.field"]', newValueInput: 'vn-textfield[ng-model="$ctrl.editedColumn.newValue"]', diff --git a/front/core/components/multi-check/multi-check.js b/front/core/components/multi-check/multi-check.js index ba40acd06..e60d16519 100644 --- a/front/core/components/multi-check/multi-check.js +++ b/front/core/components/multi-check/multi-check.js @@ -135,6 +135,7 @@ export default class MultiCheck extends FormInput { areAllUnchecked() { if (!this.model || !this.model.data) return; + this.checkedDummyCount = null; const data = this.model.data; return data.every(item => { return item[this.checkField] === false; diff --git a/modules/entry/back/methods/entry/editLatestBuys.js b/modules/entry/back/methods/entry/editLatestBuys.js index 90f1454b4..72bee98ae 100644 --- a/modules/entry/back/methods/entry/editLatestBuys.js +++ b/modules/entry/back/methods/entry/editLatestBuys.js @@ -4,19 +4,19 @@ module.exports = Self => { accessType: 'WRITE', accepts: [{ arg: 'field', - type: 'String', + type: 'string', required: true, description: `the column to edit` }, { arg: 'newValue', - type: 'Any', + type: 'any', required: true, description: `The new value to save` }, { arg: 'lines', - type: ['Object'], + type: ['object'], required: true, description: `the buys which will be modified` }, @@ -26,7 +26,7 @@ module.exports = Self => { description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' }], returns: { - type: 'Object', + type: 'object', root: true }, http: { diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index b5773b04b..a4d6f7e83 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -29,9 +29,9 @@ @@ -128,7 +128,7 @@ }"> diff --git a/modules/entry/front/latest-buys/index.js b/modules/entry/front/latest-buys/index.js index 7210649aa..44c29cb11 100644 --- a/modules/entry/front/latest-buys/index.js +++ b/modules/entry/front/latest-buys/index.js @@ -6,7 +6,7 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); this.editedColumn; - this.$checkAll = false; + this.checkAll = false; this.smartTableOptions = { activeButtons: { @@ -91,7 +91,7 @@ export default class Controller extends Section { const buys = this.$.model.data || []; const checkedBuys = []; for (let buy of buys) { - if (buy.$checked) + if (buy.checked) checkedBuys.push(buy); } diff --git a/modules/entry/front/latest-buys/index.spec.js b/modules/entry/front/latest-buys/index.spec.js index e9392a797..76e122d80 100644 --- a/modules/entry/front/latest-buys/index.spec.js +++ b/modules/entry/front/latest-buys/index.spec.js @@ -31,10 +31,10 @@ describe('Entry', () => { describe('get checked', () => { it(`should return a set of checked lines`, () => { controller.$.model.data = [ - {$checked: true, id: 1}, - {$checked: true, id: 2}, - {$checked: true, id: 3}, - {$checked: false, id: 4}, + {checked: true, id: 1}, + {checked: true, id: 2}, + {checked: true, id: 3}, + {checked: false, id: 4}, ]; let result = controller.checked; From 946f1c1cb5f8addf4ac30138d95af60a7f613601 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 10 May 2022 12:02:50 +0200 Subject: [PATCH 10/10] refactor test --- .../multi-check/multi-check.spec.js | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/front/core/components/multi-check/multi-check.spec.js b/front/core/components/multi-check/multi-check.spec.js index ee8a95c88..1c0adb9d8 100644 --- a/front/core/components/multi-check/multi-check.spec.js +++ b/front/core/components/multi-check/multi-check.spec.js @@ -5,11 +5,13 @@ describe('Component vnMultiCheck', () => { let controller; let $element; let $httpBackend; + let $httpParamSerializer; beforeEach(ngModule('vnCore')); - beforeEach(inject(($componentController, _$httpBackend_) => { + beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; $element = angular.element(`
`); controller = $componentController('vnMultiCheck', {$element: $element}); controller._model = crudModel; @@ -145,39 +147,44 @@ describe('Component vnMultiCheck', () => { describe('countRows()', () => { it(`should count visible rows and all rows of model`, () => { - const data = controller.model.data; controller.model.url = 'modelUrl/filter'; - const response = { - data: [ - {id: 1, name: 'My item 1'}, - {id: 2, name: 'My item 2'}, - {id: 3, name: 'My item 3'}, - {id: 4, name: 'My item 4'}, - {id: 5, name: 'My item 5'}, - {id: 6, name: 'My item 6'} - ] + const data = controller.model.data; + const filter = { + limit: null }; + const serializedParams = $httpParamSerializer({filter}); + + const response = [ + {id: 1, name: 'My item 1'}, + {id: 2, name: 'My item 2'}, + {id: 3, name: 'My item 3'}, + {id: 4, name: 'My item 4'}, + {id: 5, name: 'My item 5'}, + {id: 6, name: 'My item 6'} + ]; controller.countRows(); - - $httpBackend.expectGET('modelUrl/filter').respond(response); + $httpBackend.expectGET(`modelUrl/filter?${serializedParams}`).respond(response); + $httpBackend.flush(); expect(controller.rows).toEqual(data.length); - expect(controller.AllRowsCount).toEqual(response.length); + expect(controller.allRowsCount).toEqual(response.length); + expect(controller.allRowsCount).toBeGreaterThan(controller.rows); }); }); describe('checkDummy()', () => { - it(`should set checkedDummyCount allRowsCount`, () => { + const allRows = 1234; + it(`should set the checked dummy count to all rows count if there was no count yet`, () => { controller.checkedDummyCount = null; - controller.allRowsCount = 123; + controller.allRowsCount = allRows; controller.checkDummy(); expect(controller.checkedDummyCount).toEqual(controller.allRowsCount); }); - it(`should set checkedDummyCount to null`, () => { - controller.checkedDummyCount = 123; + it(`should remove the dummy count if there was an existing one`, () => { + controller.checkedDummyCount = allRows; controller.checkDummy(); expect(controller.checkedDummyCount).toBeNull();