Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/app/components/ui/filter-popup/filter-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ export class FilterPopupComponent implements OnInit, AfterViewInit, OnDestroy {
}
}

initialize(widget: IWidgetDesc, filter: any, dataSource: string) {
initialize(widget: IWidgetDesc, filter: any, dataSource: string) {
this.widget = widget;
// this.source = filter;
// this.dataSource = dataSource;
this.model.filter = filter;

// Check for related filters
if (!filter.isDate && this.isRelatedFilters/* && Filters.filtersChanged*/) {
const hasActive = this.fs.items.some(f => f.source === widget.name && (f.value || f.isInterval));

if (!filter.isDate && this.isRelatedFilters && hasActive) {
this.requestRelatedFilters(filter);
} else {
this.prepareFilters();
Expand All @@ -162,7 +163,7 @@ export class FilterPopupComponent implements OnInit, AfterViewInit, OnDestroy {
return;
}
const related = [];
const filters = this.fs.items;
const filters = this.fs.items.filter(f => f.source === this.widget.name);
// Get active filters
const activeFilters = filters.filter(f => !f.isInterval && ((f.targetProperty !== this.model.filter?.targetProperty) && f.value !== ''));
const res: IRelatedFiltersRequestData[] = [];
Expand Down Expand Up @@ -418,7 +419,7 @@ export class FilterPopupComponent implements OnInit, AfterViewInit, OnDestroy {
}
delete this.model.filter?.fromIdx;
delete this.model.filter?.toIdx;
this.clearSelectedItems();
this.clearSelectedItems();
this.fs.applyFilter(this.model.filter);
this.restoreValuesOnClose = false;
this.close();
Expand Down Expand Up @@ -472,7 +473,7 @@ export class FilterPopupComponent implements OnInit, AfterViewInit, OnDestroy {
this.model.filter.fromIdx = 0;
this.model.filter.toIdx = 1;
}
}
}

this.fs.applyFilter(this.model.filter);
this.fs.filtersChanged = true;
Expand Down
63 changes: 38 additions & 25 deletions src/app/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class FilterService {
this.isFiltersOnToolbarExists = false;
for (let i = 0; i < filterArray.length; i++) {
this.items.push(filterArray[i]);
const flt = this.items[this.items.length - 1];

const flt = this.items[this.items.length - 1];
// Check for date filters
flt.isDate = flt.controlClass === DATE_PICKER_CLASS || flt.targetPropertyDataType === '%DeepSee.Time.DayMonthYear';
if (flt.isDate) {
Expand Down Expand Up @@ -374,30 +374,31 @@ export class FilterService {
* @returns {Array} Model filters
*/
getWidgetModelFilters(widgetName) {
const res: any[] = [];
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].type === 'hidden') {
continue;
}
if (this.items[i].location === 'click') {
continue;
}
if (widgetName === 'emptyWidget') {
if (this.items[i].source === '' || this.items[i].location === 'dashboard') {
res.push({idx: i, label: this.items[i].label, text: this.items[i].valueDisplay, info: this.items[i].info});
continue;
}
}
if (this.items[i].location === 'dashboard') {
const res: any[] = [];
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].type === 'hidden') continue;
if (this.items[i].location === 'click') continue;
if (widgetName === 'emptyWidget') {
if (this.items[i].source === '' || this.items[i].location === 'dashboard') {
res.push({
...this.items[i],
idx: i,
text: this.items[i].valueDisplay,
});
continue;
}
if ((this.items[i].source === '*') || (this.items[i].sourceArray?.indexOf(widgetName) !== -1)) {
res.push({idx: i, label: this.items[i].label, text: this.items[i].valueDisplay, info: this.items[i].info});

}
}
return res;
if (this.items[i].location === 'dashboard') continue;
if ((this.items[i].source === '*') || (this.items[i].sourceArray?.indexOf(widgetName) !== -1)) {
res.push({
...this.items[i],
idx: i,
text: this.items[i].valueDisplay,
});
}
}
return res;
}

/**
* Returns list of filters USED by widget (note: this filters can be displayed on another widgets, to get displayed filters use getWidgetModelFilters)
Expand Down Expand Up @@ -503,6 +504,7 @@ export class FilterService {
isInterval: e.isInterval,
fromIdx: e.fromIdx,
toIdx: e.toIdx,
source: e.source,
valueDisplay: e.valueDisplay
} as unknown as IFilter;
});
Expand Down Expand Up @@ -572,9 +574,14 @@ export class FilterService {
for (let i = 0; i < widgets._filters.length; i++) {
const flt = widgets._filters[i];

const exists = this.items.filter((el) => {
return el.targetProperty === flt.targetProperty;
})[0];
const exists = this.items.find((el) =>
el.targetProperty === flt.targetProperty &&
(
(el.source && flt.source && el.source === flt.source) ||
(el.sourceArray && flt.source && el.sourceArray.includes(flt.source)) ||
(el.target && flt.target && el.target === flt.target)
)
);
if (exists) {
// Check for single value
exists.value = flt.value;
Expand Down Expand Up @@ -631,6 +638,12 @@ export class FilterService {
}
}
}

this.items.forEach(flt => {
if (flt.value || flt.isInterval) {
this.applyFilter(flt, true);
}
});
}

private updateFiltersParameterInURL() {
Expand Down