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