diff --git a/src/app/modules/reporting/report/report-object/report-object.component.html b/src/app/modules/reporting/report/report-object/report-object.component.html index 2e3bb782..7afd36fc 100644 --- a/src/app/modules/reporting/report/report-object/report-object.component.html +++ b/src/app/modules/reporting/report/report-object/report-object.component.html @@ -41,7 +41,7 @@ Device diff --git a/src/app/modules/reporting/report/report-object/report-object.component.ts b/src/app/modules/reporting/report/report-object/report-object.component.ts index 17c524f9..0bfa2517 100644 --- a/src/app/modules/reporting/report/report-object/report-object.component.ts +++ b/src/app/modules/reporting/report/report-object/report-object.component.ts @@ -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; } @@ -46,7 +47,7 @@ class TimeUnit { }) -export class ReportObjectComponent implements OnInit { +export class ReportObjectComponent implements OnInit, OnChanges { @Input() name = ''; @Input() data: ReportObjectModel | undefined; @@ -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'), @@ -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( @@ -103,10 +103,10 @@ export class ReportObjectComponent implements OnInit { this.queryService = service; this.queryServiceChanged(service); } - }) + }); }); } - }) + }); } } } @@ -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: '' @@ -157,15 +157,15 @@ export class ReportObjectComponent implements OnInit { } } - queryDeviceChanged(device: DeviceInstanceModel) { + queryDeviceChanged(device: DeviceInstanceModel): Observable { 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); } @@ -185,10 +185,12 @@ 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] = []; } @@ -196,7 +198,7 @@ export class ReportObjectComponent implements OnInit { } } this.dialog.open(QueryPreviewDialogComponent, { - data: { jsonData: response, dataCount: response['Key '+ 0].length }, + data: {jsonData: response, dataCount: response['Key ' + 0].length}, }); } }); @@ -256,7 +258,7 @@ export class ReportObjectComponent implements OnInit { } } - getDeviceName(device: DeviceInstanceModel){ + getDeviceName(device: DeviceInstanceModel) { return device.display_name || device.name; }