From 25165792c87ade45f27a8a4c5e47a475cd28e1e8 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 24 Sep 2019 09:29:57 +0200 Subject: [PATCH 1/4] #1680 left-menu descriptor scrollbar overlap --- front/core/components/popover/popover.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/front/core/components/popover/popover.js b/front/core/components/popover/popover.js index c999514cd..38f566135 100644 --- a/front/core/components/popover/popover.js +++ b/front/core/components/popover/popover.js @@ -75,9 +75,19 @@ export default class Popover extends Component { if (parent) this.parent = parent; let isDescriptorMoreMenu = parent && parent.attributes[0].nodeValue == 'more-button'; - const leftMenu = this.document.querySelector('div[class="menu left"]'); + let leftMenu = this.document.querySelector('div[class="menu left"]'); if (isDescriptorMoreMenu && leftMenu) { + let leftMenuWidth = leftMenu.offsetWidth; + let descriptorDiv = this.document.querySelector('vn-side-menu div'); + + let descriptorWidth = descriptorDiv.offsetWidth; + this.scrollbarWidth = leftMenuWidth - descriptorWidth; + let newWidth = leftMenuWidth - this.scrollbarWidth; + leftMenu.style.overflow = 'hidden'; + leftMenu.style.minWidth = `${newWidth}px`; + leftMenu.style.width = `${newWidth}px`; + this.restoreOverflow = true; } @@ -106,7 +116,12 @@ export default class Popover extends Component { if (this.restoreOverflow) { const leftMenu = this.document.querySelector('div[class="menu left"]'); + let leftMenuWidth = parseInt(leftMenu.style.width); + let newWidth = leftMenuWidth + this.scrollbarWidth; leftMenu.style.overflow = 'auto'; + leftMenu.style.minWidth = `${newWidth}px`; + leftMenu.style.width = `${newWidth}px`; + this.restoreOverflow = false; } this._shown = false; From 52a6221b59307b692273ecb2c296a82a02d95ec5 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 19 Sep 2019 15:51:39 +0200 Subject: [PATCH 2/4] recover getLeaves --- .../agency/back/methods/zone-geo/getLeaves.js | 169 ++++-------------- modules/agency/front/location/index.html | 15 +- modules/agency/front/location/index.js | 11 +- modules/ticket/front/sale/index.js | 5 +- 4 files changed, 53 insertions(+), 147 deletions(-) diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js index bfcef08ae..11487304e 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -1,28 +1,24 @@ -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - module.exports = Self => { Self.remoteMethod('getLeaves', { - description: 'Returns the first shipped and landed possible for params', - accepts: [{ - arg: 'zoneFk', - type: 'Number', - required: true, - }, - { - arg: 'parentFk', - type: 'Number', - default: 1, - required: false, - }, - { - arg: 'filter', - type: 'Object', - description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} - }], + description: 'Returns the nodes for a zone', + accepts: [ + { + arg: 'zoneFk', + type: 'Number', + required: true, + }, { + arg: 'parentFk', + type: 'Number', + description: 'Get the children of the specified father', + }, { + arg: 'search', + type: 'String', + description: 'Filter nodes whose name starts with', + } + ], returns: { - type: ['object'], + type: ['Object'], root: true }, http: { @@ -31,125 +27,30 @@ module.exports = Self => { } }); - Self.getLeaves = async(zoneFk, parentFk = null, filter) => { - let conn = Self.dataSource.connector; - let stmts = []; + Self.getLeaves = async(zoneFk, parentFk = null, search) => { + let [res] = await Self.rawSql( + `CALL zoneGeo_getLeaves(?, ?, ?)`, + [zoneFk, parentFk, search] + ); - stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.checkedChilds`); - stmts.push(new ParameterizedSQL( - `CREATE TEMPORARY TABLE tmp.checkedChilds ( - id INT, - name VARCHAR(100), - lft INT, - rgt INT, - depth BIGINT(22), - sons DECIMAL(10, 0), - isIncluded TINYINT - ) ENGINE = MEMORY`)); - - if (!parentFk) { - stmts.push(new ParameterizedSQL( - `INSERT INTO tmp.checkedChilds - SELECT - zg.id, - zg.name, - zg.lft, - zg.rgt, - zg.depth, - zg.sons, - zi.isIncluded - FROM zoneGeo zg - JOIN zoneIncluded zi ON zi.geoFk = zg.id - AND zoneFk = ?`, [zoneFk])); + let map = new Map(); + for (let node of res) { + if (!map.has(node.parentFk)) + map.set(node.parentFk, []); + map.get(node.parentFk).push(node); } - let stmt = new ParameterizedSQL( - `SELECT * FROM ( - SELECT - zg.id, - zg.name, - zg.lft, - zg.rgt, - zg.depth, - zg.sons, - IF(ch.id = zg.id, isIncluded, null) selected - FROM zoneGeo zg - JOIN tmp.checkedChilds ch - ON zg.lft <= ch.lft AND zg.rgt >= ch.rgt - UNION ALL - SELECT - zg.id, - zg.name, - zg.lft, - zg.rgt, - zg.depth, - zg.sons, - zi.isIncluded AS selected - FROM zoneGeo zg - LEFT JOIN zoneIncluded zi ON zi.geoFk = zg.id - AND zi.zoneFk = ? - WHERE (? IS NULL AND zg.parentFk IS NULL) - OR (? IS NOT NULL AND zg.parentFk = ?)) AS nst`, - [zoneFk, parentFk, parentFk, parentFk]); - - // Get nodes from depth greather than Origin - stmt.merge(conn.makeSuffix(filter)); - stmt.merge('GROUP BY nst.id'); - - const resultIndex = stmts.push(stmt) - 1; - - const sql = ParameterizedSQL.join(stmts, ';'); - const result = await Self.rawStmt(sql); - const nodes = result[resultIndex]; - - if (nodes.length == 0) - return nodes; - - // Get parent nodes - const minorDepth = nodes.reduce((a, b) => { - return b < a ? b : a; - }).depth; - - const parentNodes = nodes.filter(element => { - return element.depth === minorDepth; - }); - const leaves = Object.assign([], sortNodes(parentNodes)); - - nestLeaves(leaves); - - function nestLeaves(elements) { - elements.forEach(element => { - let childs = Object.assign([], getLeaves(element)); - if (childs.length > 0) { - element.childs = childs; - nestLeaves(element.childs); - } - }); + function setLeaves(nodes) { + if (!nodes) return; + for (let node of nodes) { + node.childs = map.get(node.id); + setLeaves(node.childs); + } } - function getLeaves(parent) { - let elements = nodes.filter(element => { - return element.lft > parent.lft && element.rgt < parent.rgt - && element.depth === parent.depth + 1; - }); - - return sortNodes(elements); - } + let leaves = map.get(parentFk); + setLeaves(leaves); return leaves; }; - - function sortNodes(nodes) { - return nodes.sort((a, b) => { - if (b.selected !== a.selected) { - if (a.selected == null) - return 1; - if (b.selected == null) - return -1; - return b.selected - a.selected; - } - - return a.name.localeCompare(b.name); - }); - } }; diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html index fb9bf863c..8773530ea 100644 --- a/modules/agency/front/location/index.html +++ b/modules/agency/front/location/index.html @@ -2,22 +2,25 @@ vn-id="model" url="/agency/api/ZoneGeos/getLeaves" filter="::$ctrl.filter" - params="{zoneFk: $ctrl.$stateParams.id}" auto-load="false"> + params="{zoneFk: $ctrl.$stateParams.id}" + auto-load="false">
- - + +
\ No newline at end of file diff --git a/modules/agency/front/location/index.js b/modules/agency/front/location/index.js index 9a28fd3d1..d09bb5891 100644 --- a/modules/agency/front/location/index.js +++ b/modules/agency/front/location/index.js @@ -1,18 +1,17 @@ import ngModule from '../module'; class Controller { - constructor($scope, $http, $stateParams) { + constructor($, $http, $stateParams) { this.$stateParams = $stateParams; - this.$scope = $scope; + this.$ = $; this.$http = $http; this.searchValue = ''; this.filter = {}; } - onSearch() { - this.$scope.$applyAsync(() => { - this.$scope.treeview.refresh(); - }); + onSearch(params) { + this.$.model.applyFilter(null, params); + this.$.$applyAsync(() => this.$.treeview.refresh()); } exprBuilder(param, value) { diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 4c4ba6d92..f262a5211 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -401,7 +401,10 @@ class Controller { newOrderFromTicket() { this.$http.post(`/api/Orders/newFromTicket`, {ticketFk: this.ticket.id}).then(res => { - this.$state.go('order.card.catalog', {id: res.data}); + const path = $state.href('order.card.catalog', {id: res.data}); + window.open(path, '_blank'); + + // this.$state.go('order.card.catalog', {id: res.data}); this.vnApp.showSuccess(this.$translate.instant('Order created')); }); } From 4b5807879871424a94515853fc9da487b7a79766 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 19 Sep 2019 17:30:16 +0200 Subject: [PATCH 3/4] Zone.getLeaves refactor & fixes --- modules/agency/back/methods/{zone-geo => zone}/getLeaves.js | 4 ++-- modules/agency/back/models/zone-geo.js | 3 --- modules/agency/back/models/zone.js | 1 + modules/agency/front/location/index.html | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) rename modules/agency/back/methods/{zone-geo => zone}/getLeaves.js (95%) delete mode 100644 modules/agency/back/models/zone-geo.js diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone/getLeaves.js similarity index 95% rename from modules/agency/back/methods/zone-geo/getLeaves.js rename to modules/agency/back/methods/zone/getLeaves.js index 11487304e..d919f97ac 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone/getLeaves.js @@ -29,7 +29,7 @@ module.exports = Self => { Self.getLeaves = async(zoneFk, parentFk = null, search) => { let [res] = await Self.rawSql( - `CALL zoneGeo_getLeaves(?, ?, ?)`, + `CALL zone_getLeaves(?, ?, ?)`, [zoneFk, parentFk, search] ); @@ -51,6 +51,6 @@ module.exports = Self => { let leaves = map.get(parentFk); setLeaves(leaves); - return leaves; + return leaves || []; }; }; diff --git a/modules/agency/back/models/zone-geo.js b/modules/agency/back/models/zone-geo.js deleted file mode 100644 index 987e2de71..000000000 --- a/modules/agency/back/models/zone-geo.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - require('../methods/zone-geo/getLeaves')(Self); -}; diff --git a/modules/agency/back/models/zone.js b/modules/agency/back/models/zone.js index c7ba642f3..2c540603d 100644 --- a/modules/agency/back/models/zone.js +++ b/modules/agency/back/models/zone.js @@ -1,6 +1,7 @@ module.exports = Self => { require('../methods/zone/clone')(Self); require('../methods/zone/editPrices')(Self); + require('../methods/zone/getLeaves')(Self); Self.validatesPresenceOf('warehouseFk', { message: `Warehouse cannot be blank` diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html index 8773530ea..53957faf7 100644 --- a/modules/agency/front/location/index.html +++ b/modules/agency/front/location/index.html @@ -1,6 +1,6 @@ From a319eed5f6240b003c5a37166dba35cad10c88db Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 19 Sep 2019 17:49:46 +0200 Subject: [PATCH 4/4] Zone.getLeaves() refactor --- modules/agency/back/methods/zone/getLeaves.js | 11 ++++++----- modules/agency/front/location/index.html | 3 +-- modules/agency/front/location/index.js | 4 +--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/agency/back/methods/zone/getLeaves.js b/modules/agency/back/methods/zone/getLeaves.js index d919f97ac..50ee54345 100644 --- a/modules/agency/back/methods/zone/getLeaves.js +++ b/modules/agency/back/methods/zone/getLeaves.js @@ -4,9 +4,10 @@ module.exports = Self => { description: 'Returns the nodes for a zone', accepts: [ { - arg: 'zoneFk', + arg: 'id', type: 'Number', - required: true, + http: {source: 'path'}, + required: true }, { arg: 'parentFk', type: 'Number', @@ -22,15 +23,15 @@ module.exports = Self => { root: true }, http: { - path: `/getLeaves`, + path: `/:id/getLeaves`, verb: 'GET' } }); - Self.getLeaves = async(zoneFk, parentFk = null, search) => { + Self.getLeaves = async(id, parentFk = null, search) => { let [res] = await Self.rawSql( `CALL zone_getLeaves(?, ?, ?)`, - [zoneFk, parentFk, search] + [id, parentFk, search] ); let map = new Map(); diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html index 53957faf7..c45fd5cd6 100644 --- a/modules/agency/front/location/index.html +++ b/modules/agency/front/location/index.html @@ -1,8 +1,7 @@
diff --git a/modules/agency/front/location/index.js b/modules/agency/front/location/index.js index d09bb5891..3e3decf23 100644 --- a/modules/agency/front/location/index.js +++ b/modules/agency/front/location/index.js @@ -2,11 +2,9 @@ import ngModule from '../module'; class Controller { constructor($, $http, $stateParams) { - this.$stateParams = $stateParams; this.$ = $; this.$http = $http; - this.searchValue = ''; - this.filter = {}; + this.$stateParams = $stateParams; } onSearch(params) {