Skip to content

Commit

Permalink
SNRGY-3693 chart widget: use new /device-groups endpoint option
Browse files Browse the repository at this point in the history
  • Loading branch information
franzmueller committed Dec 12, 2024
1 parent e93e5d1 commit b202ba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export class DeviceGroupsService {
offset: number,
feature: string,
order: string,
filterGenericDuplicateCriteria = false,
): Observable<{result: DeviceGroupModel[]; total: number}> {
return this._getDeviceGroups({limit, search: query, offset, sort: feature + '.' + order});
return this._getDeviceGroups({limit, search: query, offset, sort: feature + '.' + order, filterGenericDuplicateCriteria});
}

getDeviceGroup(id: string, filterGenericDuplicateCriteria = false): Observable<DeviceGroupModel | null> {
Expand Down Expand Up @@ -85,6 +86,7 @@ export class DeviceGroupsService {
attrValues?: string[];
criertia?: DeviceGroupCriteriaModel[];
p?: string;
filterGenericDuplicateCriteria?: boolean;
}): Observable<{result: DeviceGroupModel[]; total: number}> {
let params = new HttpParams();
if (options.limit !== undefined) {
Expand Down Expand Up @@ -117,6 +119,9 @@ export class DeviceGroupsService {
if (options.p !== undefined) {
params = params.set('p', options.p);
}
if (options.filterGenericDuplicateCriteria !== undefined) {
params = params.set('filter_generic_duplicate_criteria', options.filterGenericDuplicateCriteria);
}

return this.http.get<DeviceGroupModel[] | null>(environment.deviceRepoUrl + '/device-groups', { observe: 'response', params }).pipe(
map(resp => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,30 +463,23 @@ export class DataSourceSelectorComponent implements OnInit {
}

getDeviceGroups() {
return this.deviceGroupsService.getDeviceGroups('', 10000, 0, 'name', 'asc').pipe(
return this.deviceGroupsService.getDeviceGroups('', 10000, 0, 'name', 'asc', true).pipe(
mergeMap(deviceGroups => {
this.deviceGroups = deviceGroups.result;
const ascpectIds: Map<string, null> = new Map();
const functionIds: Map<string, null> = new Map();
const deviceClassids: Map<string, null> = new Map();
const innerObs: Observable<any>[] = [];
this.deviceGroups.forEach(dg => {
const criteria: DeviceGroupCriteriaModel[] = [];
dg.criteria?.forEach(c => {
ascpectIds.set(c.aspect_id, null);
functionIds.set(c.function_id, null);
deviceClassids.set(c.device_class_id, null);
if (criteria.findIndex(c2 => c.aspect_id === c2.aspect_id && c.function_id === c2.function_id) === -1) {
// filters interaction and device class, irrelevant for widget
c.interaction = '';
c.device_class_id = '';
criteria.push(c);
}
});
innerObs.push(this.deviceGroupsService.getDeviceGroup(dg.id, true).pipe(map(newDg => {
const criteria: DeviceGroupCriteriaModel[] = [];
newDg?.criteria?.forEach(c => {
if (criteria.findIndex(c2 => c.aspect_id === c2.aspect_id && c.function_id === c2.function_id && c.device_class_id === c2.device_class_id) === -1) {
// filters interaction, irrelevant for widget
c.interaction = '';
criteria.push(c);
}
});
dg.criteria = criteria;
})));
dg.criteria = criteria;
});
this.dataSourceOptions.set('Device Groups', this.deviceGroups);
innerObs.push(this.deviceGroupsService.getAspectListByIds(Array.from(ascpectIds.keys())).pipe(map(aspects => this.aspects = aspects)));
Expand Down

0 comments on commit b202ba1

Please sign in to comment.