]>
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'), | |
41 | dataIndex: 'raw', | |
42 | renderer: Ext.String.htmlEncode, | |
43 | }, | |
44 | { | |
45 | text: gettext('Normalized'), | |
46 | dataIndex: 'value', | |
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 DC |
76 | style: { |
77 | 'background-color': 'white', | |
78 | 'white-space': 'pre', | |
79 | 'font-family': 'monospace', | |
80 | }, | |
81 | }, | |
82 | ], | |
83 | ||
84 | buttons: [ | |
85 | { | |
86 | text: gettext('Reload'), | |
87 | name: 'reload', | |
88 | handler: function() { | |
89 | var me = this; | |
90 | me.up('window').store.reload(); | |
91 | }, | |
92 | }, | |
93 | { | |
94 | text: gettext('Close'), | |
95 | name: 'close', | |
96 | handler: function() { | |
97 | var me = this; | |
98 | me.up('window').close(); | |
99 | }, | |
100 | }, | |
101 | ], | |
102 | ||
402991a7 | 103 | initComponent: function() { |
511c7843 | 104 | let me = this; |
402991a7 DC |
105 | |
106 | if (!me.baseurl) { | |
107 | throw "no baseurl specified"; | |
108 | } | |
511c7843 | 109 | if (!me.dev) { |
402991a7 DC |
110 | throw "no device specified"; |
111 | } | |
112 | ||
511c7843 | 113 | me.title = `${gettext('S.M.A.R.T. Values')} (${me.dev})`; |
53ecc2ad | 114 | |
402991a7 DC |
115 | me.store = Ext.create('Ext.data.Store', { |
116 | model: 'pmx-disk-smart', | |
117 | proxy: { | |
118 | type: 'proxmox', | |
511c7843 | 119 | url: `${me.baseurl}/smart?disk=${me.dev}`, |
402991a7 DC |
120 | }, |
121 | }); | |
122 | ||
123 | me.callParent(); | |
7eb1fb18 | 124 | |
511c7843 | 125 | let grid = me.down('#smartGrid'), plainText = me.down('#smartPlainText'); |
402991a7 DC |
126 | |
127 | Proxmox.Utils.monStoreErrors(grid, me.store); | |
511c7843 TL |
128 | me.mon(me.store, 'load', function(_store, records, success) { |
129 | if (!success || records.length <= 0) { | |
130 | return; // FIXME: clear displayed info? | |
131 | } | |
132 | let isPlainText = records[0].data.type === 'text'; | |
133 | if (isPlainText) { | |
134 | plainText.setHtml(Ext.String.htmlEncode(records[0].data.text)); | |
135 | } else { | |
136 | grid.setStore(records[0].attributes()); | |
402991a7 | 137 | } |
511c7843 TL |
138 | grid.setVisible(!isPlainText); |
139 | plainText.setVisible(isPlainText); | |
402991a7 DC |
140 | }); |
141 | ||
142 | me.store.load(); | |
143 | }, | |
144 | }, function() { | |
145 | Ext.define('pmx-disk-smart', { | |
146 | extend: 'Ext.data.Model', | |
147 | fields: [ | |
148 | { name: 'health' }, | |
149 | { name: 'type' }, | |
150 | { name: 'text' }, | |
151 | ], | |
152 | hasMany: { model: 'pmx-smart-attribute', name: 'attributes' }, | |
153 | }); | |
154 | Ext.define('pmx-smart-attribute', { | |
155 | extend: 'Ext.data.Model', | |
156 | fields: [ | |
157 | { name: 'id', type: 'number' }, 'name', 'value', 'worst', 'threshold', 'flags', 'fail', 'raw', | |
158 | ], | |
159 | idProperty: 'name', | |
160 | }); | |
161 | }); |