Skip to content

Commit

Permalink
fix missing service slection changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsco committed Nov 26, 2024
1 parent 069ef50 commit 9acffc7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<mat-form-field fxFlex color="accent" appearance="outline">
<mat-label>Device</mat-label>
<senergy-select-search [options]="allDevices" [getOptionViewValue]="getDeviceName"
ngDefaultControl (ngModelChange)="queryDeviceChanged($event)" [(ngModel)]="queryDevice"
ngDefaultControl (ngModelChange)="queryDeviceChanged($event).subscribe()" [(ngModel)]="queryDevice"
[multiple]="false">
</senergy-select-search>
<mat-error senergyError label="Device"></mat-error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
* limitations under the License.
*/

import { Component, Input, OnInit, SimpleChanges } from '@angular/core';
import { ReportObjectModel } from '../../shared/reporting.model';
import { QueriesRequestTimeModel } from '../../../../widgets/shared/export-data.model';
import { DeviceTypeService } from '../../../metadata/device-types-overview/shared/device-type.service';
import { DeviceInstanceModel } from '../../../devices/device-instances/shared/device-instances.model';
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {ReportObjectModel} from '../../shared/reporting.model';
import {QueriesRequestTimeModel} from '../../../../widgets/shared/export-data.model';
import {DeviceTypeService} from '../../../metadata/device-types-overview/shared/device-type.service';
import {DeviceInstanceModel} from '../../../devices/device-instances/shared/device-instances.model';
import {
DeviceTypeContentModel,
DeviceTypeContentVariableModel,
DeviceTypeModel,
DeviceTypeServiceModel
} from '../../../metadata/device-types-overview/shared/device-type.model';
import { ExportDataService } from '../../../../widgets/shared/export-data.service';
import { MatDialog } from '@angular/material/dialog';
import { QueryPreviewDialogComponent } from './query-preview/query-preview-dialog.component';
import { map, Observable, of } from 'rxjs';
import {ExportDataService} from '../../../../widgets/shared/export-data.service';
import {MatDialog} from '@angular/material/dialog';
import {QueryPreviewDialogComponent} from './query-preview/query-preview-dialog.component';
import {map, Observable, of} from 'rxjs';

class TimeUnit {
constructor(unit: string, desc: string) {
this.unit = unit;
this.desc = desc;
}

unit: string;
desc: string;
}
Expand All @@ -46,7 +47,7 @@ class TimeUnit {
})


export class ReportObjectComponent implements OnInit {
export class ReportObjectComponent implements OnInit, OnChanges {

@Input() name = '';
@Input() data: ReportObjectModel | undefined;
Expand All @@ -61,7 +62,7 @@ export class ReportObjectComponent implements OnInit {
queryDeviceType: DeviceTypeModel = {} as DeviceTypeModel;
queryPreview = '';
fieldGroupTypes = ['mean', 'sum', 'count', 'median', 'min', 'max', 'first', 'last', 'difference-first', 'difference-last', 'difference-min', 'difference-max', 'difference-count', 'difference-mean', 'difference-sum', 'difference-median', 'time-weighted-mean-linear', 'time-weighted-mean-locf'];
groupingTime = { number: '12', unit: 'months' };
groupingTime = {number: '12', unit: 'months'};
timeUnits = [
new TimeUnit('ms', 'Milliseconds'),
new TimeUnit('s', 'Seconds'),
Expand All @@ -72,8 +73,7 @@ export class ReportObjectComponent implements OnInit {
new TimeUnit('months', 'Months'),
new TimeUnit('y', 'Years'),
];
timeframe = { number: '1', unit: 'months' };

timeframe = {number: '1', unit: 'months'};


constructor(
Expand Down Expand Up @@ -103,10 +103,10 @@ export class ReportObjectComponent implements OnInit {
this.queryService = service;
this.queryServiceChanged(service);
}
})
});
});
}
})
});
}
}
}
Expand All @@ -131,8 +131,8 @@ export class ReportObjectComponent implements OnInit {
delete this.data?.fields;
delete this.data?.length;
this.data.query = {
columns: [{ name: 'energy.value', groupType: 'difference-last' }],
time: { last: '12months' } as QueriesRequestTimeModel,
columns: [{name: 'energy.value', groupType: 'difference-last'}],
time: {last: '12months'} as QueriesRequestTimeModel,
groupTime: '1months',
deviceId: '',
serviceId: ''
Expand All @@ -157,15 +157,15 @@ export class ReportObjectComponent implements OnInit {
}
}

queryDeviceChanged(device: DeviceInstanceModel) {
queryDeviceChanged(device: DeviceInstanceModel): Observable<DeviceTypeModel | null> {
if (this.data !== undefined && this.data.query !== undefined) {
this.data.query.deviceId = device.id;
this.deviceTypeService.getDeviceType(device.device_type_id).subscribe((resp: DeviceTypeModel | null) => {
return this.deviceTypeService.getDeviceType(device.device_type_id).pipe(map((resp: DeviceTypeModel | null) => {
if (resp !== null) {
this.queryDeviceType = resp;
}
return this.queryDeviceType;
});
}));
}
return of(null);
}
Expand All @@ -185,18 +185,20 @@ export class ReportObjectComponent implements OnInit {
if (this.data !== undefined && this.data.query !== undefined) {
this.exportDataService.queryTimescaleV2([this.data.query]).subscribe((resp) => {
if (resp !== undefined) {
let response: any = {};
for (let key in resp[0].data[0]) {
let value = resp[0].data[0][key];
for (let keyInner in value) {
const response: any = {};
// eslint-disable-next-line guard-for-in
for (const key in resp[0].data[0]) {
const value = resp[0].data[0][key];
// eslint-disable-next-line guard-for-in
for (const keyInner in value) {
if (key === '0') {
response['Key ' + keyInner] = [];
}
response['Key ' + keyInner].push(value[keyInner]);
}
}
this.dialog.open(QueryPreviewDialogComponent, {
data: { jsonData: response, dataCount: response['Key '+ 0].length },
data: {jsonData: response, dataCount: response['Key ' + 0].length},
});
}
});
Expand Down Expand Up @@ -256,7 +258,7 @@ export class ReportObjectComponent implements OnInit {
}
}

getDeviceName(device: DeviceInstanceModel){
getDeviceName(device: DeviceInstanceModel) {
return device.display_name || device.name;
}

Expand Down

0 comments on commit 9acffc7

Please sign in to comment.