From 26f77ca07e0ab325ad84817e35b26b665b83a426 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 16 Mar 2022 13:02:48 +0100 Subject: [PATCH] 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"> + + + +