Filter changes
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-09-08 14:19:21 +02:00
parent 8daa3ae89c
commit f56b0607ee
4 changed files with 67 additions and 40 deletions

View File

@ -692,7 +692,9 @@ INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`)
VALUES VALUES
('YEL', 'Yellow', 1, 1), ('YEL', 'Yellow', 1, 1),
('BLU', 'Blue', 1, 2), ('BLU', 'Blue', 1, 2),
('RED', 'Red', 1, 3); ('RED', 'Red', 1, 3),
('SILVER', 'Silver', 1, 4),
('BROWN', 'Brown', 1, 5);
INSERT INTO `vn`.`origin`(`id`,`code`, `name`) INSERT INTO `vn`.`origin`(`id`,`code`, `name`)
VALUES VALUES

View File

@ -22,8 +22,8 @@ module.exports = Self => {
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
}, },
{ {
arg: 'tags', arg: 'tagGroups',
type: ['Object'], type: [['Object']],
description: 'Filter by tag' 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; let conn = Self.dataSource.connector;
const stmts = []; const stmts = [];
let stmt; let stmt;
@ -55,10 +55,15 @@ module.exports = Self => {
JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.itemCategory ic ON ic.id = it.categoryFk`); JOIN vn.itemCategory ic ON ic.id = it.categoryFk`);
console.log(tagGroups);
// Filter by tag // Filter by tag
if (tags) { if (tagGroups) {
let i = 1; /* for (const [group, i] of tagGroups.entries()) {
for (const tag of tags) { for (const tag of group)
console.log(tag);
}
*/
/* for (const tag of tags) {
const tAlias = `it${i++}`; const tAlias = `it${i++}`;
if (tag.tagFk) { if (tag.tagFk) {
@ -68,6 +73,19 @@ module.exports = Self => {
AND ${tAlias}.value LIKE ?`, AND ${tAlias}.value LIKE ?`,
params: [tag.tagFk, `%${tag.value}%`], 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 { } else {
stmt.merge({ stmt.merge({
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
@ -75,7 +93,7 @@ module.exports = Self => {
params: [`%${tag.value}%`], params: [`%${tag.value}%`],
}); });
} }
} } */
} }
stmt.merge(conn.makeWhere(filter.where)); stmt.merge(conn.makeWhere(filter.where));

View File

@ -70,18 +70,6 @@
tabindex="-1"> tabindex="-1">
</vn-icon-button> </vn-icon-button>
</vn-horizontal> </vn-horizontal>
<vn-horizontal class="vn-mt-lg"> <vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit> <vn-submit label="Search"></vn-submit>
</vn-horizontal> </vn-horizontal>

View File

@ -6,7 +6,8 @@ class Controller extends Section {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.itemTypes = []; this.itemTypes = [];
this._tags = []; // this._tags = [];
this._tagGroups = [];
// Static autocomplete data // Static autocomplete data
this.orderWays = [ this.orderWays = [
@ -54,8 +55,8 @@ class Controller extends Section {
if (this.$params.typeId) if (this.$params.typeId)
this.typeId = parseInt(this.$params.typeId); this.typeId = parseInt(this.$params.typeId);
if (this.$params.tags) /* if (this.$params.tags)
this.tags = JSON.parse(this.$params.tags); this.tags = JSON.parse(this.$params.tags); */
}); });
} }
@ -83,8 +84,8 @@ class Controller extends Section {
this.updateStateParams(); this.updateStateParams();
if (this.tags.length > 0) /* if (this.tags.length > 0)
this.applyFilters(); this.applyFilters(); */
if (value) if (value)
this.updateItemTypes(); this.updateItemTypes();
@ -104,11 +105,26 @@ class Controller extends Section {
this.updateStateParams(); this.updateStateParams();
if (value || this.tags.length > 0) /* if (value || this.tags.length > 0)
this.applyFilters(); */
if (value)
this.applyFilters(); 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; return this._tags;
} }
@ -119,7 +135,7 @@ class Controller extends Section {
if (value.length) if (value.length)
this.applyFilters(); this.applyFilters();
} } */
/** /**
* Get order way ASC/DESC * Get order way ASC/DESC
@ -150,7 +166,9 @@ class Controller extends Section {
* Apply order to model * Apply order to model
*/ */
applyOrder() { 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()}); this.$.model.addFilter(null, {orderBy: this.getOrderBy()});
} }
@ -224,11 +242,11 @@ class Controller extends Section {
if (this.typeId) if (this.typeId)
newFilter.typeFk = this.typeId; newFilter.typeFk = this.typeId;
console.log(this.tagGroups);
newParams = { newParams = {
orderFk: this.$params.id, orderFk: this.$params.id,
orderBy: this.getOrderBy(), orderBy: this.getOrderBy(),
tags: this.tags, tagGroups: this.tagGroups,
}; };
return model.applyFilter({where: newFilter}, newParams); return model.applyFilter({where: newFilter}, newParams);
@ -243,11 +261,12 @@ class Controller extends Section {
} }
onPanelSubmit(filter) { onPanelSubmit(filter) {
console.log(filter); this.$.popover.hide();
/* this.$.popover.hide(); if (filter.tags && filter.tags.length) {
this.tags.push(filter); this.tagGroups.push(filter.tags);
this.updateStateParams(); this.updateStateParams();
this.applyFilters(); */ this.applyFilters();
}
} }
/** /**
@ -264,7 +283,7 @@ class Controller extends Section {
if (this.typeId) if (this.typeId)
params.typeId = this.typeId; params.typeId = this.typeId;
params.tags = undefined; /* params.tags = undefined;
if (this.tags.length) { if (this.tags.length) {
const tags = []; const tags = [];
for (let tag of this.tags) { for (let tag of this.tags) {
@ -281,7 +300,7 @@ class Controller extends Section {
} }
params.tags = JSON.stringify(tags); params.tags = JSON.stringify(tags);
} } */
this.$state.go(this.$state.current.name, params); this.$state.go(this.$state.current.name, params);
} }