1 import { DatePipe } from '@angular/common';
2 import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
4 import { HostService } from '~/app/shared/api/host.service';
5 import { OsdService } from '~/app/shared/api/osd.service';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdDevice } from '~/app/shared/models/devices';
11 selector: 'cd-device-list',
12 templateUrl: './device-list.component.html',
13 styleUrls: ['./device-list.component.scss']
15 export class DeviceListComponent implements OnChanges, OnInit {
21 @ViewChild('deviceLocation', { static: true })
22 locationTemplate: TemplateRef<any>;
23 @ViewChild('lifeExpectancy', { static: true })
24 lifeExpectancyTemplate: TemplateRef<any>;
25 @ViewChild('lifeExpectancyTimestamp', { static: true })
26 lifeExpectancyTimestampTemplate: TemplateRef<any>;
28 devices: CdDevice[] = null;
29 columns: CdTableColumn[] = [];
30 translationMapping = {
36 private hostService: HostService,
37 private datePipe: DatePipe,
38 private osdService: OsdService
43 { prop: 'devid', name: $localize`Device ID`, minWidth: 200 },
46 name: $localize`State of Health`,
48 cellTransformation: CellTemplate.badge,
49 customTemplateConfig: {
51 good: { value: $localize`Good`, class: 'badge-success' },
52 warning: { value: $localize`Warning`, class: 'badge-warning' },
53 bad: { value: $localize`Bad`, class: 'badge-danger' },
54 stale: { value: $localize`Stale`, class: 'badge-info' },
55 unknown: { value: $localize`Unknown`, class: 'badge-dark' }
60 prop: 'life_expectancy_weeks',
61 name: $localize`Life Expectancy`,
62 cellTemplate: this.lifeExpectancyTemplate
65 prop: 'life_expectancy_stamp',
66 name: $localize`Prediction Creation Date`,
67 cellTemplate: this.lifeExpectancyTimestampTemplate,
71 { prop: 'location', name: $localize`Device Name`, cellTemplate: this.locationTemplate },
72 { prop: 'readableDaemons', name: $localize`Daemons` }
77 const updateDevicesFn = (devices: CdDevice[]) => (this.devices = devices);
79 this.hostService.getDevices(this.hostname).subscribe(updateDevicesFn);
80 } else if (this.osdId !== null) {
81 this.osdService.getDevices(this.osdId).subscribe(updateDevicesFn);