refs #5609 feat: solo muestra error cuando hay 'from' sin 'to y viceversa
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-05-19 13:34:07 +02:00
parent 5ec107188c
commit 8eedba8a66
3 changed files with 11 additions and 38 deletions

View File

@ -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)">
</vn-searchbar>
</vn-portal>

View File

@ -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});
}

View File

@ -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'