From d38986070449a798325332f2171469d50ffc1e85 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 18 May 2023 14:11:18 +0200 Subject: [PATCH 1/6] refs #5609 eliminadas peticiones duplicadas --- front/core/components/searchbar/searchbar.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index aefa89b5b..c74146817 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -203,7 +203,7 @@ export default class Searchbar extends Component { doSearch(filter, source) { if (filter === this.filter && !this.isIndex) return; - let promise = this.onSearch({$params: filter}); + let promise = this.onSearch({$params: filter}, source); promise = promise || this.$q.resolve(); promise.then(data => this.onFilter(filter, source, data)); this.toBar(filter); @@ -259,12 +259,6 @@ export default class Searchbar extends Component { this.filter = filter; - if (source == 'removeBar') { - delete params[this.toRemove]; - delete this.model.userParams[this.toRemove]; - this.model.refresh(); - } - if (!filter && this.model) this.model.clear(); if (source != 'state') @@ -279,7 +273,7 @@ export default class Searchbar extends Component { return {id: params.$row.id}; } - onSearch(args) { + onSearch(args, source) { if (!this.model) return; let filter = args.$params; @@ -325,6 +319,12 @@ export default class Searchbar extends Component { for (let param in stateFilter.tableQ) params[param] = stateFilter.tableQ[param]; + if (source == 'removeBar') { + delete params[this.toRemove]; + delete this.model.userParams[this.toRemove]; + delete stateFilter[this.toRemove]; + } + const newParams = Object.assign(stateFilter, params); return this.model.applyParams(newParams) .then(() => this.model.data); From ec02972efbd806f3cd63ed482e9d700c4969540e Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 18 May 2023 14:11:29 +0200 Subject: [PATCH 2/6] refs #5609 mostrar filtro por defecto --- modules/ticket/front/main/index.html | 3 ++- modules/ticket/front/main/index.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html index 82b5e58cd..913222f75 100644 --- a/modules/ticket/front/main/index.html +++ b/modules/ticket/front/main/index.html @@ -10,10 +10,11 @@ panel="vn-ticket-search-panel" info="Search ticket by id or alias" model="model" + filter="$ctrl.filterParams" fetch-params="$ctrl.fetchParams($params)"> - \ No newline at end of file + diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index 3f9482fc4..837db07be 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -2,6 +2,24 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Ticket extends ModuleMain { + constructor($element, $) { + super($element, $); + + if (!this.$state.q) { + const today = Date.vnNew(); + today.setHours(0, 0, 0, 0); + + const tomorrow = Date.vnNew(); + tomorrow.setHours(23, 59, 59, 59); + tomorrow.setDate(tomorrow.getDate() + 1); + + this.filterParams = { + from: today, + to: tomorrow + }; + } + } + fetchParams($params) { const excludedParams = [ 'from', @@ -17,6 +35,10 @@ export default class Ticket extends ModuleMain { const hasExcludedParams = excludedParams.some(param => { return $params && $params[param] != undefined; }); + // const seachPanelParams = Object.entries($params); + // const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); + // const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); + const hasParams = Object.entries($params).length; if (!hasParams || !hasExcludedParams) $params.scopeDays = 1; From 5ec107188c03e614a9877f876acaa69fcda5a360 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 19 May 2023 10:30:36 +0200 Subject: [PATCH 3/6] refs #5609 feat: no deja buscar si no tiene un filtro de fecha --- modules/ticket/front/main/index.js | 21 ++++++++++++++++++--- modules/ticket/front/main/locale/es.yml | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 modules/ticket/front/main/locale/es.yml diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index 837db07be..fb1ef1b3e 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; +const UserError = require('vn-loopback/util/user-error'); export default class Ticket extends ModuleMain { constructor($element, $) { @@ -35,9 +36,23 @@ export default class Ticket extends ModuleMain { const hasExcludedParams = excludedParams.some(param => { return $params && $params[param] != undefined; }); - // const seachPanelParams = Object.entries($params); - // const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); - // const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); + + const seachPanelParams = Object.entries($params); + const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); + const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); + const hasScopeDays = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'scopeDays'); + + if (!hasFromParam) + delete this.filterParams.from; + + if (!hasToParam) + delete this.filterParams.to; + + if (!hasScopeDays) + delete this.filterParams.scopeDays; + + if ((!hasFromParam || !hasToParam) && !hasScopeDays) + throw new UserError(`The filter 'From' and 'To' or 'Days onward' must be filled in`); const hasParams = Object.entries($params).length; if (!hasParams || !hasExcludedParams) diff --git a/modules/ticket/front/main/locale/es.yml b/modules/ticket/front/main/locale/es.yml new file mode 100644 index 000000000..f14a9d946 --- /dev/null +++ b/modules/ticket/front/main/locale/es.yml @@ -0,0 +1 @@ +The filter 'From' and 'To' or 'Days onward' must be filled in: El filtro 'Desde' y 'Hasta' o 'Dias adelante' debe estar rellenado From 8eedba8a66fb6e5d5c282514ff10eca386b65f0c Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 19 May 2023 13:34:07 +0200 Subject: [PATCH 4/6] refs #5609 feat: solo muestra error cuando hay 'from' sin 'to y viceversa --- modules/ticket/front/main/index.html | 1 - modules/ticket/front/main/index.js | 46 ++++++------------------- modules/ticket/front/main/locale/es.yml | 2 +- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html index 913222f75..e1e6c4e47 100644 --- a/modules/ticket/front/main/index.html +++ b/modules/ticket/front/main/index.html @@ -10,7 +10,6 @@ panel="vn-ticket-search-panel" info="Search ticket by id or alias" model="model" - filter="$ctrl.filterParams" fetch-params="$ctrl.fetchParams($params)"> diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index fb1ef1b3e..6f7c152a4 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -3,24 +3,6 @@ import ModuleMain from 'salix/components/module-main'; const UserError = require('vn-loopback/util/user-error'); export default class Ticket extends ModuleMain { - constructor($element, $) { - super($element, $); - - if (!this.$state.q) { - const today = Date.vnNew(); - today.setHours(0, 0, 0, 0); - - const tomorrow = Date.vnNew(); - tomorrow.setHours(23, 59, 59, 59); - tomorrow.setDate(tomorrow.getDate() + 1); - - this.filterParams = { - from: today, - to: tomorrow - }; - } - } - fetchParams($params) { const excludedParams = [ 'from', @@ -33,28 +15,21 @@ export default class Ticket extends ModuleMain { 'scopeDays' ]; + const seachPanelParams = Object.entries($params); + const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); + const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); + + if ((hasFromParam && !hasToParam) || (!hasFromParam && hasToParam)) { + if (!hasToParam) console.log($params); + throw new UserError(`Date range must have 'from' and 'to'`); + } + const hasExcludedParams = excludedParams.some(param => { return $params && $params[param] != undefined; }); - const seachPanelParams = Object.entries($params); - const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); - const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); - const hasScopeDays = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'scopeDays'); - - if (!hasFromParam) - delete this.filterParams.from; - - if (!hasToParam) - delete this.filterParams.to; - - if (!hasScopeDays) - delete this.filterParams.scopeDays; - - if ((!hasFromParam || !hasToParam) && !hasScopeDays) - throw new UserError(`The filter 'From' and 'To' or 'Days onward' must be filled in`); - const hasParams = Object.entries($params).length; + if (!hasParams || !hasExcludedParams) $params.scopeDays = 1; @@ -65,7 +40,6 @@ export default class Ticket extends ModuleMain { const to = new Date(from.getTime()); to.setDate(to.getDate() + $params.scopeDays); to.setHours(23, 59, 59, 999); - Object.assign($params, {from, to}); } diff --git a/modules/ticket/front/main/locale/es.yml b/modules/ticket/front/main/locale/es.yml index f14a9d946..8db264e45 100644 --- a/modules/ticket/front/main/locale/es.yml +++ b/modules/ticket/front/main/locale/es.yml @@ -1 +1 @@ -The filter 'From' and 'To' or 'Days onward' must be filled in: El filtro 'Desde' y 'Hasta' o 'Dias adelante' debe estar rellenado +Date range must have 'from' and 'to': El rango de fechas debe tener 'desde' y 'hasta' From 3119ae4471d25bb4d497f3aeddd6f4ab11d53cae Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 23 May 2023 15:12:20 +0200 Subject: [PATCH 5/6] refs #5609 delete: console.log --- modules/ticket/front/main/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index 6f7c152a4..c49418cfc 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -19,10 +19,8 @@ export default class Ticket extends ModuleMain { const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); - if ((hasFromParam && !hasToParam) || (!hasFromParam && hasToParam)) { - if (!hasToParam) console.log($params); + if ((hasFromParam && !hasToParam) || (!hasFromParam && hasToParam)) throw new UserError(`Date range must have 'from' and 'to'`); - } const hasExcludedParams = excludedParams.some(param => { return $params && $params[param] != undefined; From 68c33efd9a1a0f15e95491335946514a5f46e2e3 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 24 May 2023 07:33:01 +0200 Subject: [PATCH 6/6] refs #5609 fix: front test --- front/core/components/searchbar/searchbar.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index 9998e7a7c..2e00c2905 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -197,7 +197,7 @@ describe('Component vnSearchbar', () => { controller.doSearch(filter, 'any'); $scope.$apply(); - expect(controller.onSearch).toHaveBeenCalledWith({$params: filter}); + expect(controller.onSearch).toHaveBeenCalledWith({$params: filter}, 'any'); expect(controller.onFilter).toHaveBeenCalledWith(filter, 'any', undefined); }); });