From 26f77ca07e0ab325ad84817e35b26b665b83a426 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 16 Mar 2022 13:02:48 +0100 Subject: [PATCH 1/5] add panel-search --- .../route/back/methods/agency-term/filter.js | 50 +++++++++++++++++- .../front/agency-term-search-panel/index.html | 51 +++++++++++++++++++ .../front/agency-term-search-panel/index.js | 27 ++++++++++ .../agency-term-search-panel/locale/es.yml | 0 .../route/front/agency-term/index/index.html | 10 ++++ 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 modules/route/front/agency-term-search-panel/index.html create mode 100644 modules/route/front/agency-term-search-panel/index.js create mode 100644 modules/route/front/agency-term-search-panel/locale/es.yml diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 0bca9ddf7..854e8702f 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -1,4 +1,6 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -9,7 +11,31 @@ module.exports = Self => { arg: 'filter', type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} + }, + { + arg: 'search', + type: 'string', + description: `If it's and integer searchs by invoiceInFk, otherwise it searchs by the supplierName`, + }, + { + arg: 'agencyFk', + type: 'integer', + description: 'The agency route name', + }, + { + arg: 'agencyAgreement', + type: 'integer', + description: 'The agencyMode id', + }, + { + arg: 'from', + type: 'date', + description: 'The to date filter', + }, + { + arg: 'to', + type: 'date', + description: 'The to date filter', } ], returns: { @@ -29,6 +55,25 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {'fp.itemFk': {inq: value}} + : {'it.code': {like: `%${value}%`}}; + case 'agencyFk': + return {'it.categoryFk': value}; + case 'agencyAgreement': + return {'it.workerFk': value}; + case 'from': + case 'to': + param = `fp.${param}`; + return {[param]: value}; + } + }); + + filter = mergeFilters(filter, {where}); + const stmts = []; const stmt = new ParameterizedSQL( `SELECT * @@ -61,7 +106,8 @@ module.exports = Self => { ) a` ); - stmt.merge(conn.makeSuffix(filter)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makePagination(filter)); const agencyTerm = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); diff --git a/modules/route/front/agency-term-search-panel/index.html b/modules/route/front/agency-term-search-panel/index.html new file mode 100644 index 000000000..fb6641a52 --- /dev/null +++ b/modules/route/front/agency-term-search-panel/index.html @@ -0,0 +1,51 @@ +
+
+ + + + + + + + + + +
+ + + + + + + + +
+ + + +
+
diff --git a/modules/route/front/agency-term-search-panel/index.js b/modules/route/front/agency-term-search-panel/index.js new file mode 100644 index 000000000..4d21e6829 --- /dev/null +++ b/modules/route/front/agency-term-search-panel/index.js @@ -0,0 +1,27 @@ +import ngModule from '../module'; +import SearchPanel from 'core/components/searchbar/search-panel'; + +class Controller extends SearchPanel { + get from() { + return this._from; + } + + set from(value) { + this._from = value; + this.filter.scopeDays = null; + } + + get to() { + return this._to; + } + + set to(value) { + this._to = value; + this.filter.scopeDays = null; + } +} + +ngModule.vnComponent('vnAgencyTermSearchPanel', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/route/front/agency-term-search-panel/locale/es.yml b/modules/route/front/agency-term-search-panel/locale/es.yml new file mode 100644 index 000000000..e69de29bb diff --git a/modules/route/front/agency-term/index/index.html b/modules/route/front/agency-term/index/index.html index bb18af250..c33f012e7 100644 --- a/modules/route/front/agency-term/index/index.html +++ b/modules/route/front/agency-term/index/index.html @@ -5,6 +5,16 @@ data="agencyTerms" auto-load="true"> + + + + Date: Wed, 16 Mar 2022 14:42:19 +0100 Subject: [PATCH 2/5] correction panel-search --- .../route/back/methods/agency-term/filter.js | 24 +++++++++---------- .../front/agency-term-search-panel/index.html | 18 ++++++-------- .../front/agency-term-search-panel/index.js | 18 ++++---------- .../route/front/agency-term/index/index.html | 7 +++--- .../route/front/agency-term/index/index.js | 14 +++++------ modules/route/front/index.js | 1 + 6 files changed, 35 insertions(+), 47 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 854e8702f..ee79a04a7 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -18,19 +18,19 @@ module.exports = Self => { description: `If it's and integer searchs by invoiceInFk, otherwise it searchs by the supplierName`, }, { - arg: 'agencyFk', + arg: 'agencyModeFk', type: 'integer', - description: 'The agency route name', + description: 'The agency agencyModeFk id', }, { - arg: 'agencyAgreement', + arg: 'agencyFk', type: 'integer', - description: 'The agencyMode id', + description: 'The agencyFk id', }, { arg: 'from', type: 'date', - description: 'The to date filter', + description: 'The from date filter', }, { arg: 'to', @@ -59,16 +59,16 @@ module.exports = Self => { switch (param) { case 'search': return /^\d+$/.test(value) - ? {'fp.itemFk': {inq: value}} - : {'it.code': {like: `%${value}%`}}; + ? {'invoiceInFk': {inq: value}} + : {'supplierName': {like: `%${value}%`}}; + case 'agencyModeFk': + return {'agencyModeFk': value}; case 'agencyFk': - return {'it.categoryFk': value}; - case 'agencyAgreement': - return {'it.workerFk': value}; + return {'agencyFk': value}; case 'from': + return {'created': {gte: value}}; case 'to': - param = `fp.${param}`; - return {[param]: value}; + return {'created': {lte: value}}; } }); diff --git a/modules/route/front/agency-term-search-panel/index.html b/modules/route/front/agency-term-search-panel/index.html index fb6641a52..fec6bf5eb 100644 --- a/modules/route/front/agency-term-search-panel/index.html +++ b/modules/route/front/agency-term-search-panel/index.html @@ -1,6 +1,6 @@
-
- + + - + + value-field="id" + ng-model="filter.agencyModeFk"> + value-field="id" + ng-model="filter.agencyFk">
@@ -38,10 +38,6 @@ ng-model="filter.to" on-change="$ctrl.to = value"> - -
diff --git a/modules/route/front/agency-term-search-panel/index.js b/modules/route/front/agency-term-search-panel/index.js index 4d21e6829..7e9ab43d9 100644 --- a/modules/route/front/agency-term-search-panel/index.js +++ b/modules/route/front/agency-term-search-panel/index.js @@ -2,22 +2,14 @@ import ngModule from '../module'; import SearchPanel from 'core/components/searchbar/search-panel'; class Controller extends SearchPanel { - get from() { - return this._from; + get filter() { + return this.$.filter; } - set from(value) { - this._from = value; - this.filter.scopeDays = null; - } + set filter(value = {}) { + if (!value.tags) value.tags = [{}]; - get to() { - return this._to; - } - - set to(value) { - this._to = value; - this.filter.scopeDays = null; + this.$.filter = value; } } diff --git a/modules/route/front/agency-term/index/index.html b/modules/route/front/agency-term/index/index.html index c33f012e7..0d8ea40e7 100644 --- a/modules/route/front/agency-term/index/index.html +++ b/modules/route/front/agency-term/index/index.html @@ -1,7 +1,6 @@ @@ -9,7 +8,7 @@ @@ -46,10 +45,10 @@ Date - + Agency route - + Agency Agreement diff --git a/modules/route/front/agency-term/index/index.js b/modules/route/front/agency-term/index/index.js index ece7f18da..f73095e7a 100644 --- a/modules/route/front/agency-term/index/index.js +++ b/modules/route/front/agency-term/index/index.js @@ -12,19 +12,19 @@ class Controller extends Section { }, columns: [ { - field: 'agencyFk', + field: 'agencyModeFk', autocomplete: { url: 'AgencyModes', showField: 'name', - valueField: 'name' + valueField: 'id' } }, { - field: 'agencyAgreement', + field: 'agencyFk', autocomplete: { url: 'Agencies', showField: 'name', - valueField: 'name' + valueField: 'id' } }, { @@ -41,14 +41,14 @@ class Controller extends Section { exprBuilder(param, value) { switch (param) { - case 'agencyFk': - return {'a.agencyModeName': value}; + case 'agencyModeFk': + return {'a.agencyModeFk': value}; case 'supplierFk': return {'a.supplierName': value}; case 'routeFk': return {'a.routeFk': value}; case 'created': - case 'agencyAgreement': + case 'agencyFk': case 'packages': case 'm3': case 'kmTotal': diff --git a/modules/route/front/index.js b/modules/route/front/index.js index d5becd8dd..55cb745e1 100644 --- a/modules/route/front/index.js +++ b/modules/route/front/index.js @@ -13,4 +13,5 @@ import './log'; import './tickets'; import './agency-term/index'; import './agency-term/createInvoiceIn'; +import './agency-term-search-panel'; import './ticket-popup'; From 14eacec0ff8e30ff46fef2c65afebe6751cf8bb8 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 09:53:50 +0100 Subject: [PATCH 3/5] included test --- .../back/methods/route/specs/filter.spec.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index a4742c128..9b3c6edf4 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -1,4 +1,5 @@ const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('Route filter()', () => { let today = new Date(); @@ -17,29 +18,33 @@ describe('Route filter()', () => { expect(result[0].id).toEqual(1); }); - // #1428 cuadrar formato de horas - xit('should return the routes matching "from"', async() => { - let ctx = { - args: { - from: today, - } - }; + it('should return results matching "from" and "to"', async() => { + const tx = await models.Buy.beginTransaction({}); + const options = {transaction: tx}; - let result = await app.models.Route.filter(ctx); + try { + const from = new Date(); + from.setHours(0, 0, 0, 0); - expect(result.length).toEqual(7); - }); + const to = new Date(); + to.setHours(23, 59, 59, 999); - it('should return the routes matching "to"', async() => { - let ctx = { - args: { - to: today, - } - }; + const ctx = { + args: { + from: from, + to: to + } + }; - let result = await app.models.Route.filter(ctx); + const results = await models.Route.filter(ctx, options); - expect(result.length).toEqual(7); + expect(results.length).toBe(7); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } }); it('should return the routes matching "m3"', async() => { From c3fe2dc52b5aa5c68fc6b9f00eed517e19872c7b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 09:54:08 +0100 Subject: [PATCH 4/5] update filter test --- .../methods/agency-term/specs/filter.spec.js | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 69a7f987c..2f00b1de2 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -1,9 +1,12 @@ +const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('AgencyTerm filter()', () => { const authUserId = 9; + const today = new Date(); + today.setHours(2, 0, 0, 0); - it('should return all the tickets matching the filter', async() => { + it('should return all results matching the filter', async() => { const tx = await models.AgencyTerm.beginTransaction({}); try { @@ -23,4 +26,84 @@ describe('AgencyTerm filter()', () => { throw e; } }); + + it('should return results matching "search" searching by integer', async() => { + let ctx = { + args: { + search: 1, + } + }; + + let result = await app.models.AgencyTerm.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].routeFk).toEqual(1); + }); + + it('should return results matching "search" searching by string', async() => { + let ctx = { + args: { + search: 'Plants SL', + } + }; + + let result = await app.models.AgencyTerm.filter(ctx); + + expect(result.length).toEqual(2); + }); + + it('should return results matching "from" and "to"', async() => { + const tx = await models.Buy.beginTransaction({}); + const options = {transaction: tx}; + + try { + const from = new Date(); + from.setHours(0, 0, 0, 0); + + const to = new Date(); + to.setHours(23, 59, 59, 999); + + const ctx = { + args: { + from: from, + to: to + } + }; + + const results = await models.AgencyTerm.filter(ctx, options); + + expect(results.length).toBe(3); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return results matching "agencyModeFk"', async() => { + let ctx = { + args: { + agencyModeFk: 1, + } + }; + + let result = await app.models.AgencyTerm.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].routeFk).toEqual(1); + }); + + it('should return results matching "agencyFk"', async() => { + let ctx = { + args: { + agencyFk: 2, + } + }; + + let result = await app.models.AgencyTerm.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].routeFk).toEqual(2); + }); }); From 21198820fcaf6fa35d3dce2723461254e96b1b41 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 09:54:19 +0100 Subject: [PATCH 5/5] refactor translate --- modules/route/front/agency-term-search-panel/index.js | 2 -- modules/route/front/agency-term-search-panel/locale/es.yml | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/front/agency-term-search-panel/index.js b/modules/route/front/agency-term-search-panel/index.js index 7e9ab43d9..d5d8ea7a6 100644 --- a/modules/route/front/agency-term-search-panel/index.js +++ b/modules/route/front/agency-term-search-panel/index.js @@ -7,8 +7,6 @@ class Controller extends SearchPanel { } set filter(value = {}) { - if (!value.tags) value.tags = [{}]; - this.$.filter = value; } } diff --git a/modules/route/front/agency-term-search-panel/locale/es.yml b/modules/route/front/agency-term-search-panel/locale/es.yml index e69de29bb..74336a03b 100644 --- a/modules/route/front/agency-term-search-panel/locale/es.yml +++ b/modules/route/front/agency-term-search-panel/locale/es.yml @@ -0,0 +1,2 @@ +Search by invoiceIn id or autonomous name: Buscar por id de recibida o por nombre de autónomo +Search autonomous: Buscar autónomos \ No newline at end of file