From f56b0607eec39848fdae366be15a230592e8eab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 8 Sep 2020 14:19:21 +0200 Subject: [PATCH] Filter changes --- db/dump/fixtures.sql | 8 ++- .../order/back/methods/order/catalogFilter.js | 32 ++++++++--- .../front/catalog-search-panel/index.html | 12 ---- modules/order/front/catalog/index.js | 55 +++++++++++++------ 4 files changed, 67 insertions(+), 40 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 22fa2076a8..16d66c0106 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -690,9 +690,11 @@ INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`,`workerFk INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`) VALUES - ('YEL', 'Yellow', 1, 1), - ('BLU', 'Blue', 1, 2), - ('RED', 'Red', 1, 3); + ('YEL', 'Yellow', 1, 1), + ('BLU', 'Blue', 1, 2), + ('RED', 'Red', 1, 3), + ('SILVER', 'Silver', 1, 4), + ('BROWN', 'Brown', 1, 5); INSERT INTO `vn`.`origin`(`id`,`code`, `name`) VALUES diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index 114cd27864..e96d24cfce 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -22,8 +22,8 @@ module.exports = Self => { description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' }, { - arg: 'tags', - type: ['Object'], + arg: 'tagGroups', + type: [['Object']], description: 'Filter by tag' }, ], @@ -37,7 +37,7 @@ module.exports = Self => { }, }); - Self.catalogFilter = async(orderFk, orderBy, filter, tags) => { + Self.catalogFilter = async(orderFk, orderBy, filter, tagGroups) => { let conn = Self.dataSource.connector; const stmts = []; let stmt; @@ -55,10 +55,15 @@ module.exports = Self => { JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk`); + console.log(tagGroups); // Filter by tag - if (tags) { - let i = 1; - for (const tag of tags) { + if (tagGroups) { + /* for (const [group, i] of tagGroups.entries()) { + for (const tag of group) + console.log(tag); + } + */ + /* for (const tag of tags) { const tAlias = `it${i++}`; if (tag.tagFk) { @@ -68,6 +73,19 @@ module.exports = Self => { AND ${tAlias}.value LIKE ?`, params: [tag.tagFk, `%${tag.value}%`], }); + // Convertir: + JOIN vn.itemTag it1 ON it1.itemFk = i.id + AND ( + (it1.tagFk = ? AND it1.value LIKE ?) + OR (it1.tagFk = ? AND it1.value LIKE ?) + OR (it1.tagFk = ? AND it1.value LIKE ?) + ) + JOIN vn.itemTag it2 ON it2.itemFk = i.id + AND ( + (it2.tagFk = ? AND it2.value LIKE ?) + OR (it2.tagFk = ? AND it2.value LIKE ?) + OR (it2.tagFk = ? AND it2.value LIKE ?) + ) } else { stmt.merge({ sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id @@ -75,7 +93,7 @@ module.exports = Self => { params: [`%${tag.value}%`], }); } - } + } */ } stmt.merge(conn.makeWhere(filter.where)); diff --git a/modules/order/front/catalog-search-panel/index.html b/modules/order/front/catalog-search-panel/index.html index 4cca58ade1..54fcefb3cd 100644 --- a/modules/order/front/catalog-search-panel/index.html +++ b/modules/order/front/catalog-search-panel/index.html @@ -70,18 +70,6 @@ tabindex="-1"> - - - - - - - - - - - - diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 8b83f131a4..0538284839 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -6,7 +6,8 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.itemTypes = []; - this._tags = []; + // this._tags = []; + this._tagGroups = []; // Static autocomplete data this.orderWays = [ @@ -54,8 +55,8 @@ class Controller extends Section { if (this.$params.typeId) this.typeId = parseInt(this.$params.typeId); - if (this.$params.tags) - this.tags = JSON.parse(this.$params.tags); + /* if (this.$params.tags) + this.tags = JSON.parse(this.$params.tags); */ }); } @@ -83,8 +84,8 @@ class Controller extends Section { this.updateStateParams(); - if (this.tags.length > 0) - this.applyFilters(); + /* if (this.tags.length > 0) + this.applyFilters(); */ if (value) this.updateItemTypes(); @@ -104,11 +105,26 @@ class Controller extends Section { this.updateStateParams(); - if (value || this.tags.length > 0) + /* if (value || this.tags.length > 0) + this.applyFilters(); */ + if (value) this.applyFilters(); } - get tags() { + get tagGroups() { + return this._tagGroups; + } + + set tagGroups(value) { + this._tagGroups = value; + + this.updateStateParams(); + + if (value.length) + this.applyFilters(); + } + + /* get tags() { return this._tags; } @@ -119,7 +135,7 @@ class Controller extends Section { if (value.length) this.applyFilters(); - } + } */ /** * Get order way ASC/DESC @@ -150,7 +166,9 @@ class Controller extends Section { * Apply order to model */ applyOrder() { - if (this.typeId || this.tags.length > 0) + /* if (this.typeId || this.tags.length > 0) + this.$.model.addFilter(null, {orderBy: this.getOrderBy()}); */ + if (this.typeId) this.$.model.addFilter(null, {orderBy: this.getOrderBy()}); } @@ -224,11 +242,11 @@ class Controller extends Section { if (this.typeId) newFilter.typeFk = this.typeId; - + console.log(this.tagGroups); newParams = { orderFk: this.$params.id, orderBy: this.getOrderBy(), - tags: this.tags, + tagGroups: this.tagGroups, }; return model.applyFilter({where: newFilter}, newParams); @@ -243,11 +261,12 @@ class Controller extends Section { } onPanelSubmit(filter) { - console.log(filter); - /* this.$.popover.hide(); - this.tags.push(filter); - this.updateStateParams(); - this.applyFilters(); */ + this.$.popover.hide(); + if (filter.tags && filter.tags.length) { + this.tagGroups.push(filter.tags); + this.updateStateParams(); + this.applyFilters(); + } } /** @@ -264,7 +283,7 @@ class Controller extends Section { if (this.typeId) params.typeId = this.typeId; - params.tags = undefined; + /* params.tags = undefined; if (this.tags.length) { const tags = []; for (let tag of this.tags) { @@ -281,7 +300,7 @@ class Controller extends Section { } params.tags = JSON.stringify(tags); - } + } */ this.$state.go(this.$state.current.name, params); }