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'