]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
2e5d489a4448614cb07ffafbae23e0d7942512f4
[ceph.git] /
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', { static: false })
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         prop: 'value',
53         cellTemplate: this.valueTpl,
54         flexGrow: 1
55       }
56     ];
57   }
58
59   getCounters(context: CdTableFetchDataContext) {
60     this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
61       (resp: object[]) => {
62         this.counters = resp;
63       },
64       (error) => {
65         if (error.status === 404) {
66           error.preventDefault();
67           this.counters = null;
68         } else {
69           context.error();
70         }
71       }
72     );
73   }
74 }