]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / performance-counter / table-performance-counter / table-performance-counter.component.ts
1 import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4
5 import { PerformanceCounterService } from '../../../shared/api/performance-counter.service';
6 import { CdTableColumn } from '../../../shared/models/cd-table-column';
7 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
8
9 /**
10 * Display the specified performance counters in a datatable.
11 */
12 @Component({
13 selector: 'cd-table-performance-counter',
14 templateUrl: './table-performance-counter.component.html',
15 styleUrls: ['./table-performance-counter.component.scss']
16 })
17 export class TablePerformanceCounterComponent implements OnInit {
18 columns: Array<CdTableColumn> = [];
19 counters: Array<object> = [];
20
21 @ViewChild('valueTpl')
22 public valueTpl: TemplateRef<any>;
23
24 /**
25 * The service type, e.g. 'rgw', 'mds', 'mon', 'osd', ...
26 */
27 @Input()
28 serviceType: string;
29
30 /**
31 * The service identifier.
32 */
33 @Input()
34 serviceId: string;
35
36 constructor(private performanceCounterService: PerformanceCounterService, private i18n: I18n) {}
37
38 ngOnInit() {
39 this.columns = [
40 {
41 name: this.i18n('Name'),
42 prop: 'name',
43 flexGrow: 1
44 },
45 {
46 name: this.i18n('Description'),
47 prop: 'description',
48 flexGrow: 1
49 },
50 {
51 name: this.i18n('Value'),
52 cellTemplate: this.valueTpl,
53 flexGrow: 1
54 }
55 ];
56 }
57
58 getCounters(context: CdTableFetchDataContext) {
59 this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
60 (resp: object[]) => {
61 this.counters = resp;
62 },
63 (error) => {
64 if (error.status === 404) {
65 error.preventDefault();
66 this.counters = null;
67 } else {
68 context.error();
69 }
70 }
71 );
72 }
73 }