diff --git a/front/core/components/contextmenu/index.js b/front/core/components/contextmenu/index.js index a99009d50..5f8a165a5 100755 --- a/front/core/components/contextmenu/index.js +++ b/front/core/components/contextmenu/index.js @@ -5,40 +5,6 @@ export default class Contextmenu { this.element = $element[0]; this.$ = $; this.$transclude = $transclude; - // this.displayMode = 'relative'; - - // Foreach element, apply an addEventListener??? - /* - document.body.addEventListener('contextmenu', event => { - if (!event.defaultPrevented) - event.preventDefault(); - - const target = event.target; - const rect = target.getBoundingClientRect(); - - console.log('ScreenY', event.pageY); - console.log('OffsetY', event.pageX); - - const parent = $.contextmenu; - parent.style.top = event.pageY + 'px'; - parent.style.left = event.pageX + 'px'; - - $.menu.show(parent); - }); */ - } - - $onInit() { - /* const transcludeElement = this.element.querySelector('vn-menu'); - const content = angular.element(transcludeElement); - - this.$transclude(($clone, $scope) => { - this.$contentScope = $scope; - // $scope.$target = 'hola??'; - const list = angular.element(''); - list.append($clone); - - content.append(list); - }, null, 'menu'); */ } get targets() { @@ -51,103 +17,143 @@ export default class Contextmenu { if (!value) return; for (let selector of value) { - const target = document.querySelector(selector);// Find elements + const target = document.querySelector(selector); if (!target) continue; target.addEventListener('contextmenu', event => { + this.target = event.target; + if (!event.defaultPrevented) event.preventDefault(); + if (!this.isFilterEnabled()) return; + const parent = this.$.contextmenu; parent.style.top = event.pageY + 'px'; parent.style.left = event.pageX + 'px'; - this.eventTarget = event.target; - - /* const menu = this.element.querySelector('vn-menu'); - const list = document.createElement('vn-list'); - menu.append(list); - - const transcludeElement = this.element.querySelector('vn-list'); - const content = angular.element(transcludeElement); - console.log(transcludeElement); - - this.$transclude(($clone, $scope) => { - this.$contentScope = $scope; - $scope.$target = 'hola??'; - console.log($clone); - content.append($clone); - }, null, 'menu'); */ - this.$.menu.show(parent); }); } } - /* const transcludeElement = this.element.querySelector('vn-list'); - const content = angular.element(transcludeElement); - console.log(transcludeElement); + get row() { + if (!this.target) return null; - this.$transclude(($clone, $scope) => { - this.$contentScope = $scope; - $scope.$target = 'hola??'; - content.append($clone); - }); */ + return this.target.closest('vn-tr, .vn-tr'); + } + get rowIndex() { + if (!this.row) return null; + const table = this.row.closest('vn-table, .vn-table'); + const tBody = table.querySelector('vn-tbody, .vn-tbody'); + const rows = tBody.querySelectorAll('vn-tr, .vn-tr'); + + return Array.from(rows).findIndex( + rowItem => rowItem == this.row + ); + } + + get rowData() { + const model = this.model; + const rowData = model.data[this.rowIndex]; + + return rowData; + } + + get cell() { + if (!this.target) return null; + + return this.target.closest('vn-td, .vn-td'); + } + + get cellIndex() { + if (!this.row) return null; + + const cells = this.row.querySelectorAll('vn-td, .vn-td'); + return Array.from(cells).findIndex( + cellItem => cellItem == this.cell + ); + } + + get rowHeader() { + if (!this.row) return null; + + const table = this.row.closest('vn-table, .vn-table'); + const headerCells = table && table.querySelectorAll('vn-thead vn-th'); + const headerCell = headerCells && headerCells[this.cellIndex]; + + return headerCell; + } + + /** + * Selected model field name + * + * @return {string} + */ + get fieldName() { + if (!this.rowHeader) return null; + + return this.rowHeader.getAttribute('field'); + } + + /** + * Selected field value + * + * @return {any} + */ + get fieldValue() { + return this.rowData[this.fieldName]; + } + + /** + * Returns true if filter is not disabled + * + * @return {Boolean} + */ + isFilterEnabled() { + if (!this.rowHeader) return true; + const isEnabled = this.rowHeader.getAttribute('filter-enabled'); + + return isEnabled != 'false'; + } + + /** + * Returns true if filter + * by selection is allowed + * + * @return {Boolean} + */ + isFilterAllowed() { + if (!this.target) return false; + const isTableCell = this.target.closest('vn-td, .vn-td'); + + return isTableCell && this.fieldName; + } + + /** + * Filter by current field selection + */ filterBySelection() { - // const target = $event.target; - const model = this.model; - const target = this.eventTarget; - console.log(target); - - const table = target.closest('.vn-table'); - const headerCols = table.querySelectorAll('vn-thead vn-th'); - - const row = target.closest('.vn-tr'); - const col = target.closest('vn-td'); - - const rowIndex = row.getAttribute('data-index'); - - const columns = Array.from(row.querySelectorAll('vn-td')); - - const fieldIndex = columns.findIndex(column => column == col); - const fieldName = headerCols[fieldIndex].getAttribute('field'); - - const rowData = model.data[rowIndex]; - const filter = {where: {}}; - filter['where'][fieldName] = rowData[fieldName]; - console.log(filter); + filter['where'][this.fieldName] = this.fieldValue; - model.addFilter(filter); + this.model.addFilter(filter); } + /** + * Exclude by current field selection + */ excludeSelection() { - const model = this.model; - const target = this.eventTarget; - - const table = target.closest('.vn-table'); - const headerCols = table.querySelectorAll('vn-thead vn-th'); - - const row = target.closest('.vn-tr'); - const col = target.closest('vn-td'); - - const rowIndex = row.getAttribute('data-index'); - - const columns = Array.from(row.querySelectorAll('vn-td')); - - const fieldIndex = columns.findIndex(column => column == col); - const fieldName = headerCols[fieldIndex].getAttribute('field'); - - const rowData = model.data[rowIndex]; - const filter = {where: {}}; - filter['where'][fieldName] = {neq: rowData[fieldName]}; - console.log(filter); + filter['where'][this.fieldName] = {neq: this.fieldValue}; - model.addFilter(filter); + this.model.addFilter(filter); } + /** + * Removes all applied filters + */ removeFilter() { this.model.removeFilter(); } diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index a7c545562..f191247cf 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -186,84 +186,46 @@ module.exports = Self => { let stmt; stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter'); - - /* stmt = new ParameterizedSQL( - `CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - ENGINE = MEMORY - SELECT - t.id, - t.shipped, - t.nickname, - t.refFk, - t.routeFk, - t.warehouseFk, - t.clientFk, - a.provinceFk, - p.name AS province, - w.name AS warehouse, - am.name AS agencyMode, - am.id AS agencyModeFk, - st.name AS state, - wk.lastName AS salesPerson, - ts.stateFk as stateFk, - ts.alertLevel as alertLevel, - ts.code as alertLevelCode, - u.nickname userNickname, - c.salesPersonFk, - z.hour zoneLanding, - HOUR(z.hour) zoneHour, - MINUTE(z.hour) zoneMinute - FROM ticket t - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - LEFT JOIN warehouse w ON w.id = t.warehouseFk - LEFT JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - 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`); */ stmt = new ParameterizedSQL( `CREATE TEMPORARY TABLE tmp.filter (INDEX (id)) ENGINE = MEMORY - SELECT id, shipped, nickname, refFk, routeFk, warehouseFk - (SELECT - t.id, - t.shipped, - t.nickname, - t.refFk, - t.routeFk, - t.warehouseFk, - t.clientFk, - a.provinceFk, - p.name AS province, - w.name AS warehouse, - am.name AS agencyMode, - am.id AS agencyModeFk, - st.name AS state, - wk.lastName AS salesPerson, - ts.stateFk as stateFk, - ts.alertLevel as alertLevel, - ts.code as alertLevelCode, - u.nickname userNickname, - c.salesPersonFk, - z.hour zoneLanding, - HOUR(z.hour) zoneHour, - MINUTE(z.hour) zoneMinute - FROM ticket t - LEFT JOIN zone z ON z.id = t.zoneFk - LEFT JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - LEFT JOIN warehouse w ON w.id = t.warehouseFk - LEFT JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - 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)`); + SELECT * FROM ( + SELECT + t.id, + t.shipped, + CAST(DATE(t.shipped) AS CHAR) AS shippedDate, + t.nickname, + t.refFk, + t.routeFk, + t.warehouseFk, + t.clientFk, + a.provinceFk, + p.name AS province, + w.name AS warehouse, + am.name AS agencyMode, + am.id AS agencyModeFk, + st.name AS state, + wk.lastName AS salesPerson, + ts.stateFk as stateFk, + ts.alertLevel as alertLevel, + ts.code as alertLevelCode, + u.nickname userNickname, + c.salesPersonFk, + z.hour zoneLanding, + HOUR(z.hour) zoneHour, + MINUTE(z.hour) zoneMinute + FROM ticket t + LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN address a ON a.id = t.addressFk + LEFT JOIN province p ON p.id = a.provinceFk + LEFT JOIN warehouse w ON w.id = t.warehouseFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + 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`); if (args.orderFk) { stmt.merge({ diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index a10ec6b06..ee6e53a12 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -15,14 +15,14 @@ Id - Salesperson - Date + Salesperson + Date Hour Alias - Province + Province State Agency - Warehouse + Warehouse Invoice Closure Total @@ -153,15 +153,19 @@ - Filter by selection - Exclude selection - Remove filter - - Filter by selection 2 - Exclude selection 2 - Remove filter 2 - + + Filter by selection + + + Exclude selection + + + Remove filter + \ No newline at end of file diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index bb56f9cbf..59e5d949d 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -92,61 +92,6 @@ export default class Controller extends Section { this.selectedTicket = ticket; this.$.summary.show(); } - - filterBySelection(target) { - // const target = $event.target; - const model = this.$.model; - console.log(target); - const table = target.closest('.vn-table'); - const headerCols = table.querySelectorAll('vn-thead vn-th'); - - const row = target.closest('.vn-tr'); - const col = target.closest('vn-td'); - - const rowIndex = row.getAttribute('data-index'); - - const columns = Array.from(row.querySelectorAll('vn-td')); - - const fieldIndex = columns.findIndex(column => column == col); - const fieldName = headerCols[fieldIndex].getAttribute('field'); - - const rowData = model.data[rowIndex]; - - const filter = {where: {}}; - filter['where'][fieldName] = rowData[fieldName]; - console.log(filter); - - model.addFilter(filter); - } - - excludeSelection($event, target) { - const model = this.$.model; - - const table = target.closest('.vn-table'); - const headerCols = table.querySelectorAll('vn-thead vn-th'); - - const row = target.closest('.vn-tr'); - const col = target.closest('vn-td'); - - const rowIndex = row.getAttribute('data-index'); - - const columns = Array.from(row.querySelectorAll('vn-td')); - - const fieldIndex = columns.findIndex(column => column == col); - const fieldName = headerCols[fieldIndex].getAttribute('field'); - - const rowData = model.data[rowIndex]; - - const filter = {where: {}}; - filter['where'][fieldName] = {neq: rowData[fieldName]}; - console.log(filter); - - model.addFilter(filter); - } - - removeFilter() { - this.$.model.removeFilter(); - } } ngModule.component('vnTicketIndex', {