2018-06-07 21:47:19 +00:00
|
|
|
import ngModule from '../module';
|
2018-12-27 11:54:16 +00:00
|
|
|
import SearchPanel from 'core/components/searchbar/search-panel';
|
2018-06-07 21:47:19 +00:00
|
|
|
|
|
|
|
class Controller extends SearchPanel {
|
2019-10-28 16:31:33 +00:00
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
let model = 'Item';
|
|
|
|
let moreFields = ['id', 'description', 'name', 'isActive'];
|
|
|
|
|
|
|
|
let properties;
|
|
|
|
let validations = window.validations;
|
|
|
|
|
|
|
|
if (validations && validations[model])
|
|
|
|
properties = validations[model].properties;
|
|
|
|
else
|
|
|
|
properties = {};
|
|
|
|
|
|
|
|
this.moreFields = [];
|
|
|
|
for (let field of moreFields) {
|
|
|
|
let prop = properties[field];
|
|
|
|
this.moreFields.push({
|
|
|
|
name: field,
|
|
|
|
label: prop ? prop.description : field,
|
|
|
|
type: prop ? prop.type : null
|
|
|
|
});
|
|
|
|
}
|
2019-03-08 12:12:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
get filter() {
|
|
|
|
let filter = this.$.filter;
|
|
|
|
|
|
|
|
for (let fieldFilter of this.fieldFilters)
|
|
|
|
filter[fieldFilter.name] = fieldFilter.value;
|
|
|
|
|
|
|
|
return filter;
|
2019-03-08 12:12:13 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 21:47:19 +00:00
|
|
|
set filter(value) {
|
2019-01-16 14:29:01 +00:00
|
|
|
if (!value)
|
|
|
|
value = {};
|
|
|
|
if (!value.tags)
|
|
|
|
value.tags = [{}];
|
2018-06-07 21:47:19 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.fieldFilters = [];
|
|
|
|
for (let field of this.moreFields) {
|
|
|
|
if (value[field.name] != undefined) {
|
|
|
|
this.fieldFilters.push({
|
|
|
|
name: field.name,
|
|
|
|
value: value[field.name],
|
|
|
|
info: field
|
|
|
|
});
|
|
|
|
}
|
2019-02-14 10:24:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.$.filter = value;
|
2018-06-07 21:47:19 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
removeField(index, field) {
|
|
|
|
this.fieldFilters.splice(index, 1);
|
|
|
|
this.$.filter[field] = undefined;
|
|
|
|
}
|
2018-06-07 21:47:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnItemSearchPanel', {
|
2018-06-07 21:47:19 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|