]>
Commit | Line | Data |
---|---|---|
402991a7 DC |
1 | Ext.define('Proxmox.window.DiskSmart', { |
2 | extend: 'Ext.window.Window', | |
3 | alias: 'widget.pmxSmartWindow', | |
4 | ||
5 | modal: true, | |
6 | ||
7eb1fb18 | 7 | layout: { |
ff7ee784 | 8 | type: 'fit', |
7eb1fb18 TL |
9 | }, |
10 | width: 800, | |
11 | height: 500, | |
12 | minWidth: 400, | |
13 | minHeight: 300, | |
14 | bodyPadding: 5, | |
7eb1fb18 | 15 | |
402991a7 DC |
16 | items: [ |
17 | { | |
18 | xtype: 'gridpanel', | |
19 | layout: { | |
20 | type: 'fit', | |
21 | }, | |
22 | emptyText: gettext('No S.M.A.R.T. Values'), | |
23 | scrollable: true, | |
24 | flex: 1, | |
511c7843 | 25 | itemId: 'smartGrid', |
402991a7 DC |
26 | reserveScrollbar: true, |
27 | columns: [ | |
7eb1fb18 TL |
28 | { |
29 | text: 'ID', | |
30 | dataIndex: 'id', | |
31 | width: 50, | |
32 | }, | |
33 | { | |
34 | text: gettext('Attribute'), | |
35 | dataIndex: 'name', | |
36 | flex: 1, | |
37 | renderer: Ext.String.htmlEncode, | |
38 | }, | |
39 | { | |
40 | text: gettext('Value'), | |
aacb9ea1 | 41 | dataIndex: 'real-value', |
7eb1fb18 TL |
42 | renderer: Ext.String.htmlEncode, |
43 | }, | |
44 | { | |
45 | text: gettext('Normalized'), | |
aacb9ea1 | 46 | dataIndex: 'real-normalized', |
7eb1fb18 TL |
47 | width: 60, |
48 | }, | |
49 | { | |
50 | text: gettext('Threshold'), | |
51 | dataIndex: 'threshold', | |
52 | width: 60, | |
53 | }, | |
54 | { | |
55 | text: gettext('Worst'), | |
56 | dataIndex: 'worst', | |
57 | width: 60, | |
58 | }, | |
59 | { | |
60 | text: gettext('Flags'), | |
61 | dataIndex: 'flags', | |
62 | }, | |
63 | { | |
64 | text: gettext('Failing'), | |
65 | dataIndex: 'fail', | |
66 | renderer: Ext.String.htmlEncode, | |
67 | }, | |
402991a7 DC |
68 | ], |
69 | }, | |
70 | { | |
71 | xtype: 'component', | |
511c7843 | 72 | itemId: 'smartPlainText', |
402991a7 | 73 | hidden: true, |
ff7ee784 TL |
74 | autoScroll: true, |
75 | padding: 5, | |
402991a7 | 76 | style: { |
402991a7 DC |
77 | 'white-space': 'pre', |
78 | 'font-family': 'monospace', | |
79 | }, | |
80 | }, | |
81 | ], | |
82 | ||
83 | buttons: [ | |
84 | { | |
85 | text: gettext('Reload'), | |
86 | name: 'reload', | |
87 | handler: function() { | |
88 | var me = this; | |
89 | me.up('window').store.reload(); | |
90 | }, | |
91 | }, | |
92 | { | |
93 | text: gettext('Close'), | |
94 | name: 'close', | |
95 | handler: function() { | |
96 | var me = this; | |
97 | me.up('window').close(); | |
98 | }, | |
99 | }, | |
100 | ], | |
101 | ||
402991a7 | 102 | initComponent: function() { |
511c7843 | 103 | let me = this; |
402991a7 DC |
104 | |
105 | if (!me.baseurl) { | |
106 | throw "no baseurl specified"; | |
107 | } | |
511c7843 | 108 | if (!me.dev) { |
402991a7 DC |
109 | throw "no device specified"; |
110 | } | |
111 | ||
511c7843 | 112 | me.title = `${gettext('S.M.A.R.T. Values')} (${me.dev})`; |
53ecc2ad | 113 | |
402991a7 DC |
114 | me.store = Ext.create('Ext.data.Store', { |
115 | model: 'pmx-disk-smart', | |
116 | proxy: { | |
117 | type: 'proxmox', | |
511c7843 | 118 | url: `${me.baseurl}/smart?disk=${me.dev}`, |
402991a7 DC |
119 | }, |
120 | }); | |
121 | ||
122 | me.callParent(); | |
7eb1fb18 | 123 | |
511c7843 | 124 | let grid = me.down('#smartGrid'), plainText = me.down('#smartPlainText'); |
402991a7 DC |
125 | |
126 | Proxmox.Utils.monStoreErrors(grid, me.store); | |
511c7843 TL |
127 | me.mon(me.store, 'load', function(_store, records, success) { |
128 | if (!success || records.length <= 0) { | |
129 | return; // FIXME: clear displayed info? | |
130 | } | |
131 | let isPlainText = records[0].data.type === 'text'; | |
132 | if (isPlainText) { | |
133 | plainText.setHtml(Ext.String.htmlEncode(records[0].data.text)); | |
134 | } else { | |
135 | grid.setStore(records[0].attributes()); | |
402991a7 | 136 | } |
511c7843 TL |
137 | grid.setVisible(!isPlainText); |
138 | plainText.setVisible(isPlainText); | |
402991a7 DC |
139 | }); |
140 | ||
141 | me.store.load(); | |
142 | }, | |
143 | }, function() { | |
144 | Ext.define('pmx-disk-smart', { | |
145 | extend: 'Ext.data.Model', | |
146 | fields: [ | |
147 | { name: 'health' }, | |
148 | { name: 'type' }, | |
149 | { name: 'text' }, | |
150 | ], | |
151 | hasMany: { model: 'pmx-smart-attribute', name: 'attributes' }, | |
152 | }); | |
153 | Ext.define('pmx-smart-attribute', { | |
154 | extend: 'Ext.data.Model', | |
155 | fields: [ | |
aacb9ea1 MH |
156 | { name: 'id', type: 'number' }, 'name', 'value', 'worst', 'threshold', 'flags', 'fail', |
157 | 'raw', 'normalized', | |
158 | { | |
159 | name: 'real-value', | |
160 | // FIXME remove with next major release (PBS 3.0) | |
7e66b73c | 161 | calculate: data => data.raw ?? data.value, |
aacb9ea1 MH |
162 | }, |
163 | { | |
164 | name: 'real-normalized', | |
165 | // FIXME remove with next major release (PBS 3.0) | |
7e66b73c | 166 | calculate: data => data.normalized ?? data.value, |
aacb9ea1 | 167 | }, |
402991a7 DC |
168 | ], |
169 | idProperty: 'name', | |
170 | }); | |
171 | }); |