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
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
5ec107188c
commit
8eedba8a66
|
@ -10,7 +10,6 @@
|
||||||
panel="vn-ticket-search-panel"
|
panel="vn-ticket-search-panel"
|
||||||
info="Search ticket by id or alias"
|
info="Search ticket by id or alias"
|
||||||
model="model"
|
model="model"
|
||||||
filter="$ctrl.filterParams"
|
|
||||||
fetch-params="$ctrl.fetchParams($params)">
|
fetch-params="$ctrl.fetchParams($params)">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
</vn-portal>
|
</vn-portal>
|
||||||
|
|
|
@ -3,24 +3,6 @@ import ModuleMain from 'salix/components/module-main';
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
export default class Ticket extends ModuleMain {
|
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) {
|
fetchParams($params) {
|
||||||
const excludedParams = [
|
const excludedParams = [
|
||||||
'from',
|
'from',
|
||||||
|
@ -33,28 +15,21 @@ export default class Ticket extends ModuleMain {
|
||||||
'scopeDays'
|
'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 => {
|
const hasExcludedParams = excludedParams.some(param => {
|
||||||
return $params && $params[param] != undefined;
|
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;
|
const hasParams = Object.entries($params).length;
|
||||||
|
|
||||||
if (!hasParams || !hasExcludedParams)
|
if (!hasParams || !hasExcludedParams)
|
||||||
$params.scopeDays = 1;
|
$params.scopeDays = 1;
|
||||||
|
|
||||||
|
@ -65,7 +40,6 @@ export default class Ticket extends ModuleMain {
|
||||||
const to = new Date(from.getTime());
|
const to = new Date(from.getTime());
|
||||||
to.setDate(to.getDate() + $params.scopeDays);
|
to.setDate(to.getDate() + $params.scopeDays);
|
||||||
to.setHours(23, 59, 59, 999);
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
Object.assign($params, {from, to});
|
Object.assign($params, {from, to});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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'
|
||||||
|
|
Loading…
Reference in New Issue