From 4545a5c8fae74c759feb17e9704a48d7e8b097ae Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 24 Sep 2021 12:51:20 +0200 Subject: [PATCH] fix(filter): single search results don't use scopeDates --- .../monitor/front/index/tickets/index.html | 3 +-- modules/monitor/front/index/tickets/index.js | 27 +++++++++++++++---- modules/ticket/front/main/index.html | 3 +-- modules/ticket/front/main/index.js | 26 +++++++++++------- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index 82adf2765..cbbea81a8 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -1,6 +1,5 @@ - diff --git a/modules/monitor/front/index/tickets/index.js b/modules/monitor/front/index/tickets/index.js index d8832d1b5..23febd6c6 100644 --- a/modules/monitor/front/index/tickets/index.js +++ b/modules/monitor/front/index/tickets/index.js @@ -6,13 +6,30 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); - this.filterParams = this.fetchParams({ - scopeDays: 1 - }); + this.filterParams = this.fetchParams(); } - fetchParams($params) { - if (!Object.entries($params).length) + $onInit() { + if (!this.$params.q) { + this.$.$applyAsync( + () => this.$.model.applyFilter(null, this.filterParams)); + } + } + + fetchParams($params = {}) { + const excludedParams = [ + 'search', + 'clientFk', + 'orderFk', + 'refFk', + 'scopeDays' + ]; + + const hasExcludedParams = excludedParams.some(param => { + return $params && $params[param]; + }); + const hasParams = Object.entries($params).length; + if (!hasParams || !hasExcludedParams) $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html index 590d33887..82b5e58cd 100644 --- a/modules/ticket/front/main/index.html +++ b/modules/ticket/front/main/index.html @@ -10,8 +10,7 @@ panel="vn-ticket-search-panel" info="Search ticket by id or alias" model="model" - fetch-params="$ctrl.fetchParams($params)" - suggested-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 78334ba97..b67b6512e 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -2,16 +2,22 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Ticket extends ModuleMain { - constructor() { - super(); - - this.filterParams = { - scopeDays: 1 - }; - } - fetchParams($params) { - if (!Object.entries($params).length) + const excludedParams = [ + 'from', + 'to', + 'search', + 'clientFk', + 'orderFk', + 'refFk', + 'scopeDays' + ]; + + const hasExcludedParams = excludedParams.some(param => { + return $params && $params[param]; + }); + const hasParams = Object.entries($params).length; + if (!hasParams || !hasExcludedParams) $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { @@ -25,6 +31,8 @@ export default class Ticket extends ModuleMain { Object.assign($params, {from, to}); } + this.filterParams = $params; + return $params; } }