Changes to catalog filters
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
f56b0607ee
commit
9bbe50c62b
|
@ -23,7 +23,7 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'tagGroups',
|
arg: 'tagGroups',
|
||||||
type: [['Object']],
|
type: ['Object'],
|
||||||
description: 'Filter by tag'
|
description: 'Filter by tag'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -55,45 +55,30 @@ 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 (tagGroups) {
|
if (tagGroups) {
|
||||||
/* for (const [group, i] of tagGroups.entries()) {
|
for (const [i, tagGroup] of tagGroups.entries()) {
|
||||||
for (const tag of group)
|
const values = tagGroup.values;
|
||||||
console.log(tag);
|
const tAlias = `it${i}`;
|
||||||
}
|
|
||||||
*/
|
|
||||||
/* for (const tag of tags) {
|
|
||||||
const tAlias = `it${i++}`;
|
|
||||||
|
|
||||||
if (tag.tagFk) {
|
if (tagGroup.tagFk) {
|
||||||
|
stmt.merge(`JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id AND (`);
|
||||||
|
for (const [i, tagValue] of values.entries()) {
|
||||||
stmt.merge({
|
stmt.merge({
|
||||||
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
|
sql: `${i > 0 ? 'OR' : ''} (${tAlias}.tagFk = ? AND ${tAlias}.value LIKE ?)`,
|
||||||
AND ${tAlias}.tagFk = ?
|
params: [tagGroup.tagFk, `%${tagValue.value}%`],
|
||||||
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
|
|
||||||
AND ${tAlias}.value LIKE ?`,
|
|
||||||
params: [`%${tag.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: [`%${tagValue.value}%`],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
|
|
|
@ -1,64 +1,37 @@
|
||||||
<mg-ajax path="Tags" options="mgIndex as tags"></mg-ajax>
|
<mg-ajax path="Tags" options="mgIndex as tags"></mg-ajax>
|
||||||
<div class="vn-pa-lg" style="min-width: 10em">
|
<div class="vn-pa-lg" style="min-width: 18em">
|
||||||
<form name="form" ng-submit="$ctrl.onSearch()">
|
<form name="form" ng-submit="$ctrl.onSearch()">
|
||||||
<!-- <vn-horizontal>
|
|
||||||
<vn-autocomplete
|
|
||||||
vn-one
|
|
||||||
label="Tag"
|
|
||||||
ng-model="filter.tagFk"
|
|
||||||
selection="filter.tagSelection"
|
|
||||||
url="Tags"
|
|
||||||
show-field="name"
|
|
||||||
value-field="id"
|
|
||||||
required="true">
|
|
||||||
<tpl-item>{{name}}</tpl-item>
|
|
||||||
</vn-autocomplete>
|
|
||||||
</vn-horizontal>
|
|
||||||
<vn-horizontal>
|
|
||||||
<vn-textfield
|
|
||||||
vn-one
|
|
||||||
label="Value"
|
|
||||||
ng-model="filter.value"
|
|
||||||
required="true">
|
|
||||||
</vn-textfield>
|
|
||||||
</vn-horizontal> -->
|
|
||||||
|
|
||||||
|
|
||||||
<vn-horizontal class="vn-pt-sm">
|
<vn-horizontal class="vn-pt-sm">
|
||||||
<vn-one class="text-subtitle1" translate>
|
<vn-one class="text-subtitle1" translate>
|
||||||
Tags
|
Tags
|
||||||
</vn-one>
|
</vn-one>
|
||||||
<vn-icon-button
|
|
||||||
vn-none
|
|
||||||
vn-bind="+"
|
|
||||||
vn-tooltip="Add tag"
|
|
||||||
icon="add_circle"
|
|
||||||
ng-click="$ctrl.addTag()">
|
|
||||||
</vn-icon-button>
|
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal ng-repeat="itemTag in filter.tags">
|
<vn-horizontal>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-id="tag"
|
vn-id="tag"
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="itemTag.tagFk"
|
selection="filter.tagSelection"
|
||||||
|
ng-model="filter.tagFk"
|
||||||
data="tags.model"
|
data="tags.model"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
label="Tag"
|
label="Tag"
|
||||||
on-change="itemTag.value = null">
|
on-change="itemTag.value = null">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal ng-repeat="tagValue in filter.values">
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
ng-show="tag.selection.isFree !== false"
|
ng-show="tag.selection.isFree !== false"
|
||||||
vn-id="text"
|
vn-id="text"
|
||||||
label="Value"
|
label="Value"
|
||||||
ng-model="itemTag.value">
|
ng-model="tagValue.value">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-show="tag.selection.isFree === false"
|
ng-show="tag.selection.isFree === false"
|
||||||
url="{{$ctrl.getSourceTable(tag.selection)}}"
|
url="{{$ctrl.getSourceTable(tag.selection)}}"
|
||||||
label="Value"
|
label="Value"
|
||||||
ng-model="itemTag.value"
|
ng-model="tagValue.value"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="name">
|
value-field="name">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
@ -66,10 +39,19 @@
|
||||||
vn-none
|
vn-none
|
||||||
vn-tooltip="Remove tag"
|
vn-tooltip="Remove tag"
|
||||||
icon="delete"
|
icon="delete"
|
||||||
ng-click="filter.tags.splice($index, 1)"
|
ng-click="filter.values.splice($index, 1)"
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-icon-button
|
||||||
|
vn-none
|
||||||
|
vn-bind="+"
|
||||||
|
vn-tooltip="Add value"
|
||||||
|
icon="add_circle"
|
||||||
|
ng-click="$ctrl.addValue()">
|
||||||
|
</vn-icon-button>
|
||||||
|
</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>
|
||||||
|
|
|
@ -15,8 +15,8 @@ class Controller extends SearchPanel {
|
||||||
set filter(value) {
|
set filter(value) {
|
||||||
if (!value)
|
if (!value)
|
||||||
value = {};
|
value = {};
|
||||||
if (!value.tags)
|
if (!value.values)
|
||||||
value.tags = [{}];
|
value.values = [{}];
|
||||||
|
|
||||||
this.$.filter = value;
|
this.$.filter = value;
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,13 @@ class Controller extends SearchPanel {
|
||||||
return `ItemTags/filterItemTags/${selection.id}`;
|
return `ItemTags/filterItemTags/${selection.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTag() {
|
addValue() {
|
||||||
this.filter.tags.push({});
|
this.filter.values.push({});
|
||||||
this.popover.relocate();
|
setTimeout(() => this.popover.relocate());
|
||||||
|
}
|
||||||
|
|
||||||
|
changeTag() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
<vn-chip
|
<vn-chip
|
||||||
ng-if="$ctrl.itemId"
|
ng-if="$ctrl.itemId"
|
||||||
removable="true"
|
removable="true"
|
||||||
translate-attr="{title: 'Item'}"
|
vn-tooltip="Item id"
|
||||||
on-remove="$ctrl.removeItemId()"
|
on-remove="$ctrl.removeItemId()"
|
||||||
class="colored">
|
class="colored">
|
||||||
<span>Id: {{$ctrl.itemId}}</span>
|
<span>Id: {{$ctrl.itemId}}</span>
|
||||||
|
@ -122,16 +122,20 @@
|
||||||
<vn-chip
|
<vn-chip
|
||||||
ng-if="$ctrl.itemName"
|
ng-if="$ctrl.itemName"
|
||||||
removable="true"
|
removable="true"
|
||||||
translate-attr="{title: 'Item'}"
|
vn-tooltip="Item"
|
||||||
on-remove="$ctrl.removeItemName()"
|
on-remove="$ctrl.removeItemName()"
|
||||||
class="colored">
|
class="colored">
|
||||||
<span translate>Name</span>
|
<div>
|
||||||
<span>: {{$ctrl.itemName}}</span>
|
<span>
|
||||||
|
<span translate>Name</span>:
|
||||||
|
</span>
|
||||||
|
<span>{{$ctrl.itemName}}</span>
|
||||||
|
</div>
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
<vn-chip
|
<vn-chip
|
||||||
ng-if="category.selection"
|
ng-if="category.selection"
|
||||||
removable="true"
|
removable="true"
|
||||||
translate-attr="{title: 'Category'}"
|
vn-tooltip="Category"
|
||||||
on-remove="$ctrl.categoryId = null"
|
on-remove="$ctrl.categoryId = null"
|
||||||
class="colored">
|
class="colored">
|
||||||
<span translate>{{category.selection.name}}</span>
|
<span translate>{{category.selection.name}}</span>
|
||||||
|
@ -139,26 +143,24 @@
|
||||||
<vn-chip
|
<vn-chip
|
||||||
ng-if="type.selection"
|
ng-if="type.selection"
|
||||||
removable="true"
|
removable="true"
|
||||||
translate-attr="{title: 'Type'}"
|
vn-tooltip="Type"
|
||||||
on-remove="$ctrl.typeId = null"
|
on-remove="$ctrl.typeId = null"
|
||||||
class="colored">
|
class="colored">
|
||||||
<span translate>{{type.selection.name}}</span>
|
<span translate>{{type.selection.name}}</span>
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
<vn-chip
|
<vn-chip
|
||||||
ng-repeat="tag in $ctrl.tags"
|
ng-repeat="tagGroup in $ctrl.tagGroups"
|
||||||
removable="true"
|
removable="true"
|
||||||
translate-attr="{title: 'Tag'}"
|
|
||||||
on-remove="$ctrl.remove($index)"
|
on-remove="$ctrl.remove($index)"
|
||||||
|
vn-tooltip="{{::$ctrl.formatTooltip(tagGroup)}}"
|
||||||
class="colored">
|
class="colored">
|
||||||
<div>
|
<div>
|
||||||
<span ng-if="::tag.tagFk">
|
<span ng-if="::tagGroup.tagFk">
|
||||||
<span translate>
|
<span translate>{{::tagGroup.tagSelection.name}}</span>:
|
||||||
{{::tag.tagSelection.name}}
|
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="::tag.value">: </span>
|
<span ng-repeat="tagValue in tagGroup.values">
|
||||||
</span>
|
<span ng-if="$index > 0">,</span>
|
||||||
<span translate ng-if="::tag.value">
|
<span>"{{::tagValue.value}}"</span>
|
||||||
"{{::tag.value}}"
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
|
|
|
@ -206,19 +206,17 @@ class Controller extends Section {
|
||||||
onSearchByTag(event) {
|
onSearchByTag(event) {
|
||||||
const value = this.$.search.value;
|
const value = this.$.search.value;
|
||||||
if (event.key !== 'Enter' || !value) return;
|
if (event.key !== 'Enter' || !value) return;
|
||||||
this.tags.push({
|
this.tagGroups.push({values: [{value: value}]});
|
||||||
value: value,
|
|
||||||
});
|
|
||||||
this.$.search.value = null;
|
this.$.search.value = null;
|
||||||
this.updateStateParams();
|
this.updateStateParams();
|
||||||
this.applyFilters();
|
this.applyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(index) {
|
remove(index) {
|
||||||
this.tags.splice(index, 1);
|
this.tagGroups.splice(index, 1);
|
||||||
this.updateStateParams();
|
this.updateStateParams();
|
||||||
|
|
||||||
if (this.tags.length >= 0 || this.itemId || this.typeId)
|
if (this.tagGroups.length >= 0 || this.itemId || this.typeId)
|
||||||
this.applyFilters();
|
this.applyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +240,7 @@ 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(),
|
||||||
|
@ -262,8 +260,15 @@ class Controller extends Section {
|
||||||
|
|
||||||
onPanelSubmit(filter) {
|
onPanelSubmit(filter) {
|
||||||
this.$.popover.hide();
|
this.$.popover.hide();
|
||||||
if (filter.tags && filter.tags.length) {
|
const values = filter.values;
|
||||||
this.tagGroups.push(filter.tags);
|
const nonEmptyValues = values.filter(tagValue => {
|
||||||
|
return tagValue.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
filter.values = nonEmptyValues;
|
||||||
|
|
||||||
|
if (filter.tagFk && nonEmptyValues.length) {
|
||||||
|
this.tagGroups.push(filter);
|
||||||
this.updateStateParams();
|
this.updateStateParams();
|
||||||
this.applyFilters();
|
this.applyFilters();
|
||||||
}
|
}
|
||||||
|
@ -283,10 +288,10 @@ class Controller extends Section {
|
||||||
if (this.typeId)
|
if (this.typeId)
|
||||||
params.typeId = this.typeId;
|
params.typeId = this.typeId;
|
||||||
|
|
||||||
/* params.tags = undefined;
|
params.tagGrops = undefined;
|
||||||
if (this.tags.length) {
|
if (this.tagGrops.length) {
|
||||||
const tags = [];
|
const tagGrops = [];
|
||||||
for (let tag of this.tags) {
|
for (let tag of this.tagGrops) {
|
||||||
const tagParam = {value: tag.value};
|
const tagParam = {value: tag.value};
|
||||||
|
|
||||||
if (tag.tagSelection) {
|
if (tag.tagSelection) {
|
||||||
|
@ -300,7 +305,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);
|
||||||
}
|
}
|
||||||
|
@ -362,6 +367,23 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
} else return this.applyFilters();
|
} 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', {
|
ngModule.vnComponent('vnOrderCatalog', {
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
Name: Nombre
|
Name: Nombre
|
||||||
Search by item id or name: Buscar por id de artículo o nombre
|
Search by item id or name: Buscar por id de artículo o nombre
|
||||||
|
OR: O
|
Loading…
Reference in New Issue