diff --git a/front/core/components/contextmenu/index.js b/front/core/components/contextmenu/index.js index 061d4cf09..b931c9539 100755 --- a/front/core/components/contextmenu/index.js +++ b/front/core/components/contextmenu/index.js @@ -1,4 +1,5 @@ import ngModule from '../../module'; +import {buildFilter} from 'vn-loopback/util/filter'; import './style.scss'; export default class Contextmenu { @@ -137,27 +138,80 @@ export default class Contextmenu { * Filter by current field selection */ filterBySelection() { - const filter = {where: {}}; - filter['where'][this.fieldName] = this.fieldValue; + let where = {[this.fieldName]: this.fieldValue}; + if (this.exprBuilder) { + where = buildFilter(where, (param, value) => + this.exprBuilder({param, value}) + ); + } - this.model.addFilter(filter); + this.model.addFilter({where}); } /** * Exclude by current field selection */ excludeSelection() { - const filter = {where: {}}; - filter['where'][this.fieldName] = {neq: this.fieldValue}; + let where = {[this.fieldName]: {neq: this.fieldValue}}; + if (this.exprBuilder) { + where = buildFilter(where, (param, value) => + this.exprBuilder({param, value}) + ); + } + console.log(where); - this.model.addFilter(filter); + this.model.addFilter({where}); + } + + removeFilter() { + const userFilter = this.model.userFilter; + const userParams = this.model.userParams; + const where = userFilter.where; + + let filterKey = this.fieldName; + if (this.exprBuilder) { + const param = this.exprBuilder({ + param: filterKey, + value: null + }); + [filterKey] = Object.keys(param); + } + + const whereKeys = Object.keys(where); + for (let key of whereKeys) + removeProp(where, filterKey, key); + + function removeProp(instance, findProp, prop) { + if (prop == findProp) + delete instance[prop]; + + if (prop === 'and') { + for (let [index, param] of instance[prop].entries()) { + if (param === undefined) + console.log('param undefined'); + + const [key] = Object.keys(param); + if (key == findProp) + instance[prop].splice(index, 1); + + if (instance[prop] instanceof Array) { + if (!instance[prop][index]) return; + const [firstKey] = Object.keys(instance[prop][index]); + removeProp(instance[prop][index], filterKey, firstKey); + } + } + } + } + + this.model.applyFilter(userFilter, userParams); } /** * Removes all applied filters */ - removeFilter() { - this.model.removeFilter(); + removeAllFilters() { + const userParams = this.model.userParams; + this.model.applyFilter(null, userParams); } } @@ -168,7 +222,8 @@ ngModule.vnComponent('vnContextmenu', { template: require('./index.html'), bindings: { targets: ' { switch (param) { case 'search': return /^\d+$/.test(value) - ? {'id': {inq: value}} - : {'nickname': {like: `%${value}%`}}; + ? {'t.id': {inq: value}} + : {'t.nickname': {like: `%${value}%`}}; case 'from': - return {'shipped': {gte: value}}; + return {'t.shipped': {gte: value}}; case 'to': - return {'shipped': {lte: value}}; + return {'t.shipped': {lte: value}}; case 'nickname': - return {'nickname': {like: `%${value}%`}}; + return {'t.nickname': {like: `%${value}%`}}; case 'refFk': - return {'refFk': value}; + return {'t.refFk': value}; case 'salesPersonFk': - return {'salesPersonFk': value}; + return {'c.salesPersonFk': value}; case 'provinceFk': - return {'provinceFk': value}; + return {'a.provinceFk': value}; case 'stateFk': - return {'stateFk': value}; + return {'ts.stateFk': value}; case 'mine': case 'myTeam': return {'c.salesPersonFk': {inq: teamIds}}; @@ -162,13 +162,13 @@ module.exports = Self => { case 'pending': if (value) { return {and: [ - {'alertLevel': 0}, - {'alertLevelCode': {neq: 'OK'}}, - {'alertLevelCode': {neq: 'BOARDING'}} + {'st.alertLevel': 0}, + {'st.code': {neq: 'OK'}}, + {'st.code': {neq: 'BOARDING'}} ]}; } else { return {and: [ - {'alertLevel': {gt: 0}} + {'st.alertLevel': {gt: 0}} ]}; } case 'id': @@ -190,7 +190,6 @@ module.exports = Self => { `CREATE TEMPORARY TABLE tmp.filter (INDEX (id)) ENGINE = MEMORY - SELECT * FROM ( SELECT t.id, t.shipped, @@ -214,7 +213,8 @@ module.exports = Self => { c.salesPersonFk, z.hour zoneLanding, HOUR(z.hour) zoneHour, - MINUTE(z.hour) zoneMinute + MINUTE(z.hour) zoneMinute, + CAST(z.hour AS CHAR) AS hour FROM ticket t LEFT JOIN zone z ON z.id = t.zoneFk LEFT JOIN address a ON a.id = t.addressFk @@ -225,7 +225,7 @@ module.exports = Self => { LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN client c ON c.id = t.clientFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk - LEFT JOIN account.user u ON u.id = wk.userFk) t`); + LEFT JOIN account.user u ON u.id = wk.userFk`); if (args.orderFk) { stmt.merge({ diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index 07857c381..d7349e5e9 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -16,7 +16,7 @@ Id Salesperson - Date + Date Hour Alias Province @@ -24,7 +24,7 @@ Agency Warehouse Invoice - Closure + Closure Total @@ -151,7 +151,8 @@ - + Remove filter + + Remove all filters + \ No newline at end of file diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 59e5d949d..a47b0acc9 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -92,6 +92,38 @@ export default class Controller extends Section { this.selectedTicket = ticket; this.$.summary.show(); } + + exprBuilder(param, value) { + switch (param) { + case 'stateFk': + return {'ts.stateFk': value}; + case 'salesPersonFk': + return {'c.salesPersonFk': value}; + case 'provinceFk': + return {'a.provinceFk': value}; + case 'hour': + return {'z.hour': value}; + case 'shipped': + return {'t.shipped': { + between: this.dateRange(value)} + }; + case 'id': + case 'refFk': + case 'nickname': + case 'agencyModeFk': + case 'warehouseFk': + return {[`t.${param}`]: value}; + } + } + + dateRange(value) { + const minHour = new Date(value); + minHour.setHours(0, 0, 0, 0); + const maxHour = new Date(value); + maxHour.setHours(23, 59, 59, 59); + + return [minHour, maxHour]; + } } ngModule.component('vnTicketIndex', { diff --git a/modules/ticket/front/index/locale/es.yml b/modules/ticket/front/index/locale/es.yml index acc8adc80..10eaba350 100644 --- a/modules/ticket/front/index/locale/es.yml +++ b/modules/ticket/front/index/locale/es.yml @@ -6,4 +6,5 @@ Closure: Cierre You cannot make a payment on account from multiple clients: No puedes realizar un pago a cuenta de clientes diferentes Filter by selection: Filtro por selección Exclude selection: Excluir selección -Remove filter: Eliminar filtro \ No newline at end of file +Remove filter: Quitar filtro por selección +Remove all filters: Eliminar todos los filtros \ No newline at end of file