diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index e96d24cfc..64ee73d1c 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -23,7 +23,7 @@ module.exports = Self => { }, { arg: 'tagGroups', - type: [['Object']], + type: ['Object'], description: 'Filter by tag' }, ], @@ -55,45 +55,30 @@ 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 (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++}`; + for (const [i, tagGroup] of tagGroups.entries()) { + const values = tagGroup.values; + const tAlias = `it${i}`; - if (tag.tagFk) { - stmt.merge({ - sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id - AND ${tAlias}.tagFk = ? - 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 ?) - ) + if (tagGroup.tagFk) { + stmt.merge(`JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id AND (`); + for (const [i, tagValue] of values.entries()) { + stmt.merge({ + sql: `${i > 0 ? 'OR' : ''} (${tAlias}.tagFk = ? AND ${tAlias}.value LIKE ?)`, + params: [tagGroup.tagFk, `%${tagValue.value}%`], + }); + } + stmt.merge(`)`); } else { + const tagValue = values[0]; stmt.merge({ sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id AND ${tAlias}.value LIKE ?`, - params: [`%${tag.value}%`], + params: [`%${tagValue.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 54fcefb3c..822445a18 100644 --- a/modules/order/front/catalog-search-panel/index.html +++ b/modules/order/front/catalog-search-panel/index.html @@ -1,64 +1,37 @@ -
+
- - - Tags - - - + + + + ng-model="tagValue.value"> @@ -66,10 +39,19 @@ vn-none vn-tooltip="Remove tag" icon="delete" - ng-click="filter.tags.splice($index, 1)" + ng-click="filter.values.splice($index, 1)" tabindex="-1"> + + + + diff --git a/modules/order/front/catalog-search-panel/index.js b/modules/order/front/catalog-search-panel/index.js index 9f77e0dee..893971329 100644 --- a/modules/order/front/catalog-search-panel/index.js +++ b/modules/order/front/catalog-search-panel/index.js @@ -15,8 +15,8 @@ class Controller extends SearchPanel { set filter(value) { if (!value) value = {}; - if (!value.tags) - value.tags = [{}]; + if (!value.values) + value.values = [{}]; this.$.filter = value; } @@ -33,9 +33,13 @@ class Controller extends SearchPanel { return `ItemTags/filterItemTags/${selection.id}`; } - addTag() { - this.filter.tags.push({}); - this.popover.relocate(); + addValue() { + this.filter.values.push({}); + setTimeout(() => this.popover.relocate()); + } + + changeTag() { + } } diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 18f1af044..ebe8d4389 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -114,7 +114,7 @@ Id: {{$ctrl.itemId}} @@ -122,16 +122,20 @@ - Name - : {{$ctrl.itemName}} + class="colored"> +
+ + Name: + + {{$ctrl.itemName}} +
{{category.selection.name}} @@ -139,26 +143,24 @@ {{type.selection.name}}
- - - {{::tag.tagSelection.name}} - - : + + {{::tagGroup.tagSelection.name}}: - - "{{::tag.value}}" + + , + "{{::tagValue.value}}"
diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 053828483..eab7b0e15 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -206,19 +206,17 @@ class Controller extends Section { onSearchByTag(event) { const value = this.$.search.value; if (event.key !== 'Enter' || !value) return; - this.tags.push({ - value: value, - }); + this.tagGroups.push({values: [{value: value}]}); this.$.search.value = null; this.updateStateParams(); this.applyFilters(); } remove(index) { - this.tags.splice(index, 1); + this.tagGroups.splice(index, 1); this.updateStateParams(); - if (this.tags.length >= 0 || this.itemId || this.typeId) + if (this.tagGroups.length >= 0 || this.itemId || this.typeId) this.applyFilters(); } @@ -242,7 +240,7 @@ class Controller extends Section { if (this.typeId) newFilter.typeFk = this.typeId; - console.log(this.tagGroups); + newParams = { orderFk: this.$params.id, orderBy: this.getOrderBy(), @@ -262,8 +260,15 @@ class Controller extends Section { onPanelSubmit(filter) { this.$.popover.hide(); - if (filter.tags && filter.tags.length) { - this.tagGroups.push(filter.tags); + const values = filter.values; + const nonEmptyValues = values.filter(tagValue => { + return tagValue.value; + }); + + filter.values = nonEmptyValues; + + if (filter.tagFk && nonEmptyValues.length) { + this.tagGroups.push(filter); this.updateStateParams(); this.applyFilters(); } @@ -283,10 +288,10 @@ class Controller extends Section { if (this.typeId) params.typeId = this.typeId; - /* params.tags = undefined; - if (this.tags.length) { - const tags = []; - for (let tag of this.tags) { + params.tagGrops = undefined; + if (this.tagGrops.length) { + const tagGrops = []; + for (let tag of this.tagGrops) { const tagParam = {value: tag.value}; if (tag.tagSelection) { @@ -300,7 +305,7 @@ class Controller extends Section { } params.tags = JSON.stringify(tags); - } */ + } this.$state.go(this.$state.current.name, params); } @@ -362,6 +367,23 @@ class Controller extends Section { } } else return this.applyFilters(); } + + formatTooltip(tagGroup) { + const tagValues = tagGroup.values; + + let title = ''; + if (tagGroup.tagFk) { + const tagName = tagGroup.tagSelection.name; + title += `${tagName}: `; + } + + for (let [i, tagValue] of tagValues.entries()) { + if (i > 0) title += ', '; + title += `"${tagValue.value}"`; + } + + return `${title}`; + } } ngModule.vnComponent('vnOrderCatalog', { diff --git a/modules/order/front/catalog/locale/es.yml b/modules/order/front/catalog/locale/es.yml index 27d16fe2d..fc78755ae 100644 --- a/modules/order/front/catalog/locale/es.yml +++ b/modules/order/front/catalog/locale/es.yml @@ -1,2 +1,3 @@ Name: Nombre -Search by item id or name: Buscar por id de artículo o nombre \ No newline at end of file +Search by item id or name: Buscar por id de artículo o nombre +OR: O \ No newline at end of file