]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; |
2 | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill'; | |
4 | ||
5 | import { IscsiService } from '../../../shared/api/iscsi.service'; | |
6 | import { DimlessPipe } from '../../../shared/pipes/dimless.pipe'; | |
7 | import { IscsiBackstorePipe } from '../../../shared/pipes/iscsi-backstore.pipe'; | |
8 | ||
9 | @Component({ | |
10 | selector: 'cd-iscsi', | |
11 | templateUrl: './iscsi.component.html', | |
12 | styleUrls: ['./iscsi.component.scss'] | |
13 | }) | |
14 | export class IscsiComponent implements OnInit { | |
15 | @ViewChild('statusColorTpl') | |
16 | statusColorTpl: TemplateRef<any>; | |
17 | @ViewChild('iscsiSparklineTpl') | |
18 | iscsiSparklineTpl: TemplateRef<any>; | |
19 | @ViewChild('iscsiPerSecondTpl') | |
20 | iscsiPerSecondTpl: TemplateRef<any>; | |
21 | @ViewChild('iscsiRelativeDateTpl') | |
22 | iscsiRelativeDateTpl: TemplateRef<any>; | |
23 | ||
24 | gateways = []; | |
25 | gatewaysColumns: any; | |
26 | images = []; | |
27 | imagesColumns: any; | |
28 | ||
29 | constructor( | |
30 | private iscsiService: IscsiService, | |
31 | private dimlessPipe: DimlessPipe, | |
32 | private iscsiBackstorePipe: IscsiBackstorePipe, | |
33 | private i18n: I18n | |
34 | ) {} | |
35 | ||
36 | ngOnInit() { | |
37 | this.gatewaysColumns = [ | |
38 | { | |
39 | name: this.i18n('Name'), | |
40 | prop: 'name' | |
41 | }, | |
42 | { | |
43 | name: this.i18n('State'), | |
44 | prop: 'state', | |
45 | cellTemplate: this.statusColorTpl | |
46 | }, | |
47 | { | |
48 | name: this.i18n('# Targets'), | |
49 | prop: 'num_targets' | |
50 | }, | |
51 | { | |
52 | name: this.i18n('# Sessions'), | |
53 | prop: 'num_sessions' | |
54 | } | |
55 | ]; | |
56 | this.imagesColumns = [ | |
57 | { | |
58 | name: this.i18n('Pool'), | |
59 | prop: 'pool' | |
60 | }, | |
61 | { | |
62 | name: this.i18n('Image'), | |
63 | prop: 'image' | |
64 | }, | |
65 | { | |
66 | name: this.i18n('Backstore'), | |
67 | prop: 'backstore', | |
68 | pipe: this.iscsiBackstorePipe | |
69 | }, | |
70 | { | |
71 | name: this.i18n('Read Bytes'), | |
72 | prop: 'stats_history.rd_bytes', | |
73 | cellTemplate: this.iscsiSparklineTpl | |
74 | }, | |
75 | { | |
76 | name: this.i18n('Write Bytes'), | |
77 | prop: 'stats_history.wr_bytes', | |
78 | cellTemplate: this.iscsiSparklineTpl | |
79 | }, | |
80 | { | |
81 | name: this.i18n('Read Ops'), | |
82 | prop: 'stats.rd', | |
83 | pipe: this.dimlessPipe, | |
84 | cellTemplate: this.iscsiPerSecondTpl | |
85 | }, | |
86 | { | |
87 | name: this.i18n('Write Ops'), | |
88 | prop: 'stats.wr', | |
89 | pipe: this.dimlessPipe, | |
90 | cellTemplate: this.iscsiPerSecondTpl | |
91 | }, | |
92 | { | |
93 | name: this.i18n('A/O Since'), | |
94 | prop: 'optimized_since', | |
95 | cellTemplate: this.iscsiRelativeDateTpl | |
96 | } | |
97 | ]; | |
98 | } | |
99 | ||
100 | refresh() { | |
101 | this.iscsiService.overview().subscribe((overview: Array<any>) => { | |
102 | this.gateways = overview['gateways']; | |
103 | this.images = overview['images']; | |
104 | this.images.map((image) => { | |
105 | if (image.stats_history) { | |
106 | image.stats_history.rd_bytes = image.stats_history.rd_bytes.map((i) => i[1]); | |
107 | image.stats_history.wr_bytes = image.stats_history.wr_bytes.map((i) => i[1]); | |
108 | } | |
109 | image.cdIsBinary = true; | |
110 | return image; | |
111 | }); | |
112 | }); | |
113 | } | |
114 | } |