]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/DiskSmart.js
disk: smart: code & indentation level cleanup
[proxmox-widget-toolkit.git] / src / window / DiskSmart.js
1 Ext.define('Proxmox.window.DiskSmart', {
2 extend: 'Ext.window.Window',
3 alias: 'widget.pmxSmartWindow',
4
5 modal: true,
6
7 layout: {
8 type: 'fit',
9 },
10 width: 800,
11 height: 500,
12 minWidth: 400,
13 minHeight: 300,
14 bodyPadding: 5,
15
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,
25 itemId: 'smartGrid',
26 reserveScrollbar: true,
27 columns: [
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 },
68 ],
69 },
70 {
71 xtype: 'component',
72 itemId: 'smartPlainText',
73 hidden: true,
74 autoScroll: true,
75 padding: 5,
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
103 initComponent: function() {
104 let me = this;
105
106 if (!me.baseurl) {
107 throw "no baseurl specified";
108 }
109 if (!me.dev) {
110 throw "no device specified";
111 }
112
113 me.title = `${gettext('S.M.A.R.T. Values')} (${me.dev})`;
114
115 me.store = Ext.create('Ext.data.Store', {
116 model: 'pmx-disk-smart',
117 proxy: {
118 type: 'proxmox',
119 url: `${me.baseurl}/smart?disk=${me.dev}`,
120 },
121 });
122
123 me.callParent();
124
125 let grid = me.down('#smartGrid'), plainText = me.down('#smartPlainText');
126
127 Proxmox.Utils.monStoreErrors(grid, me.store);
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());
137 }
138 grid.setVisible(!isPlainText);
139 plainText.setVisible(isPlainText);
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 });