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