Skip to content

Commit

Permalink
Refactor chart asset filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer committed Jan 27, 2025
1 parent 80761ce commit 187fb35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*
*/

import { Component } from '@angular/core';
import { Component, EventEmitter, Output } from '@angular/core';
import { SpDataExplorerOverviewDirective } from '../data-explorer-overview.directive';
import { MatTableDataSource } from '@angular/material/table';
import {
Dashboard,
DataExplorerWidgetModel,
DataViewDataExplorerService,
} from '@streampipes/platform-services';
Expand All @@ -41,6 +42,11 @@ import { MatDialog } from '@angular/material/dialog';
export class SpDataExplorerDataViewOverviewComponent extends SpDataExplorerOverviewDirective {
dataSource = new MatTableDataSource<DataExplorerWidgetModel>();
displayedColumns: string[] = [];
charts: DataExplorerWidgetModel[] = [];
filteredCharts: DataExplorerWidgetModel[] = [];

@Output()
resourceCountEmitter: EventEmitter<number> = new EventEmitter();

constructor(
private dataViewService: DataViewDataExplorerService,
Expand All @@ -61,12 +67,13 @@ export class SpDataExplorerDataViewOverviewComponent extends SpDataExplorerOverv

getDataViews(): void {
this.dataViewService.getAllWidgets().subscribe(widgets => {
widgets = widgets.sort((a, b) =>
this.charts = widgets.sort((a, b) =>
a.baseAppearanceConfig.widgetTitle.localeCompare(
b.baseAppearanceConfig.widgetTitle,
),
);
this.dataSource.data = widgets;
this.resourceCountEmitter.emit(this.charts.length);
this.applyChartFilters();
});
}

Expand Down Expand Up @@ -110,4 +117,15 @@ export class SpDataExplorerDataViewOverviewComponent extends SpDataExplorerOverv
}
});
}

applyChartFilters(elementIds: Set<string> = new Set<string>()): void {
this.filteredCharts = this.charts.filter(a => {
if (elementIds.size === 0) {
return true;
} else {
return elementIds.has(a.elementId);
}
});
this.dataSource.data = this.filteredCharts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<sp-asset-browser
filteredAssetLinkType="data-view"
filteredAssetLinkType="chart"
allResourcesAlias="Charts"
[resourceCount]="resourceCount"
(filterIdsEmitter)="applyChartFilters($event)"
Expand All @@ -44,7 +44,9 @@
</button>
</div>
<div fxFlex="100" fxLayout="column">
<sp-data-explorer-overview-table></sp-data-explorer-overview-table>
<sp-data-explorer-overview-table
(resourceCountEmitter)="resourceCount = $event"
></sp-data-explorer-overview-table>
</div>
</sp-basic-view>
</sp-asset-browser>

0 comments on commit 187fb35

Please sign in to comment.