]>
Commit | Line | Data |
---|---|---|
33839735 | 1 | Ext.define('pbs-data-store-snapshots', { |
ca23a97f | 2 | extend: 'Ext.data.Model', |
d9c38ddc | 3 | fields: [ |
d9c38ddc | 4 | 'backup-type', |
507c39c5 DM |
5 | 'backup-id', |
6 | { | |
e8f0ad19 | 7 | name: 'backup-time', |
507c39c5 DM |
8 | type: 'date', |
9 | dateFormat: 'timestamp' | |
10 | }, | |
d9c38ddc | 11 | 'files', |
e8f0ad19 | 12 | { name: 'size', type: 'int' }, |
33839735 | 13 | ] |
ca23a97f DM |
14 | }); |
15 | ||
16 | Ext.define('PBS.DataStoreContent', { | |
e8f0ad19 | 17 | extend: 'Ext.tree.Panel', |
ca23a97f DM |
18 | alias: 'widget.pbsDataStoreContent', |
19 | ||
e8f0ad19 | 20 | rootVisible: false, |
507c39c5 | 21 | |
c0ac2074 DC |
22 | title: gettext('Content'), |
23 | ||
f1baa7f4 TL |
24 | controller: { |
25 | xclass: 'Ext.app.ViewController', | |
26 | ||
27 | init: function(view) { | |
28 | if (!view.datastore) { | |
29 | throw "no datastore specified"; | |
30 | } | |
31 | ||
e8f0ad19 | 32 | this.data_store = Ext.create('Ext.data.Store', { |
33839735 | 33 | model: 'pbs-data-store-snapshots', |
e8f0ad19 DM |
34 | sorters: 'backup-group', |
35 | groupField: 'backup-group', | |
36 | }); | |
37 | ||
f1baa7f4 TL |
38 | Proxmox.Utils.monStoreErrors(view, view.store, true); |
39 | this.reload(); // initial load | |
40 | }, | |
41 | ||
42 | reload: function() { | |
43 | var view = this.getView(); | |
44 | ||
e8f0ad19 DM |
45 | let url = `/api2/json/admin/datastore/${view.datastore}/snapshots`; |
46 | this.data_store.setProxy({ | |
f1baa7f4 TL |
47 | type: 'proxmox', |
48 | url: url | |
49 | }); | |
e8f0ad19 | 50 | |
e8f0ad19 | 51 | this.data_store.load(function(records, operation, success) { |
e8f0ad19 DM |
52 | let groups = {}; |
53 | ||
54 | records.forEach(function(item) { | |
55 | var btype = item.data["backup-type"]; | |
56 | let group = btype + "/" + item.data["backup-id"]; | |
57 | ||
58 | if (groups[group] !== undefined) | |
59 | return; | |
60 | ||
61 | var cls = ''; | |
62 | if (btype === 'vm') { | |
63 | cls = 'fa-desktop'; | |
64 | } else if (btype === 'ct') { | |
65 | cls = 'fa-cube'; | |
66 | } else if (btype === 'host') { | |
67 | cls = 'fa-building'; | |
68 | } else { | |
69 | return btype + '/' + value; | |
70 | } | |
71 | ||
72 | groups[group] = { | |
73 | text: group, | |
74 | leaf: false, | |
75 | iconCls: "fa " + cls, | |
76 | expanded: false, | |
b1127fd0 DM |
77 | backup_type: item.data["backup-type"], |
78 | backup_id: item.data["backup-id"], | |
e8f0ad19 DM |
79 | children: [] |
80 | }; | |
81 | }); | |
82 | ||
aeee4329 DM |
83 | let backup_time_to_string = function(backup_time) { |
84 | let pad = function(number) { | |
85 | if (number < 10) { | |
86 | return '0' + number; | |
87 | } | |
88 | return number; | |
89 | }; | |
90 | return backup_time.getUTCFullYear() + | |
91 | '-' + pad(backup_time.getUTCMonth() + 1) + | |
92 | '-' + pad(backup_time.getUTCDate()) + | |
93 | 'T' + pad(backup_time.getUTCHours()) + | |
94 | ':' + pad(backup_time.getUTCMinutes()) + | |
95 | ':' + pad(backup_time.getUTCSeconds()) + | |
96 | 'Z'; | |
97 | }; | |
98 | ||
e8f0ad19 | 99 | records.forEach(function(item) { |
e8f0ad19 DM |
100 | let group = item.data["backup-type"] + "/" + item.data["backup-id"]; |
101 | let children = groups[group].children; | |
102 | ||
103 | let data = item.data; | |
aeee4329 | 104 | |
e8f0ad19 | 105 | data.text = Ext.Date.format(data["backup-time"], 'Y-m-d H:i:s'); |
aeee4329 | 106 | data.text = group + '/' + backup_time_to_string(data["backup-time"]); |
e8f0ad19 | 107 | data.leaf = true; |
aeee4329 | 108 | data.cls = 'no-leaf-icons'; |
e8f0ad19 DM |
109 | |
110 | children.push(data); | |
111 | }); | |
112 | ||
113 | let children = []; | |
114 | Ext.Object.each(groups, function(key, group) { | |
115 | let last_backup = 0; | |
116 | group.children.forEach(function(item) { | |
117 | if (item["backup-time"] > last_backup) { | |
118 | last_backup = item["backup-time"]; | |
119 | group["backup-time"] = last_backup; | |
120 | group.files = item.files; | |
121 | group.size = item.size; | |
122 | } | |
123 | }); | |
124 | group.count = group.children.length; | |
125 | children.push(group) | |
126 | }) | |
127 | ||
128 | view.setRootNode({ | |
129 | expanded: true, | |
130 | children: children | |
131 | }); | |
132 | ||
133 | }); | |
134 | ||
f1baa7f4 | 135 | }, |
5f448992 DM |
136 | |
137 | onPrune: function() { | |
138 | var view = this.getView(); | |
139 | ||
140 | let rec = view.selModel.getSelection()[0]; | |
141 | if (!(rec && rec.data)) return; | |
142 | let data = rec.data; | |
143 | if (data.leaf) return; | |
144 | ||
145 | if (!view.datastore) return; | |
146 | ||
147 | let win = Ext.create('PBS.DataStorePrune', { | |
148 | datastore: view.datastore, | |
149 | backup_type: data.backup_type, | |
150 | backup_id: data.backup_id, | |
151 | }); | |
152 | win.on('destroy', this.reload, this); | |
153 | win.show(); | |
154 | } | |
f1baa7f4 TL |
155 | }, |
156 | ||
507c39c5 DM |
157 | initComponent: function() { |
158 | var me = this; | |
9d4ebe3d | 159 | |
b1127fd0 DM |
160 | var sm = Ext.create('Ext.selection.RowModel', {}); |
161 | ||
162 | var prune_btn = new Proxmox.button.Button({ | |
163 | text: gettext('Prune'), | |
164 | disabled: true, | |
165 | selModel: sm, | |
5f448992 DM |
166 | enableFn: function(record) { return !record.data.leaf; }, |
167 | handler: 'onPrune', | |
b1127fd0 DM |
168 | }); |
169 | ||
507c39c5 | 170 | Ext.apply(me, { |
b1127fd0 | 171 | selModel: sm, |
507c39c5 DM |
172 | columns: [ |
173 | { | |
e8f0ad19 DM |
174 | xtype: 'treecolumn', |
175 | header: gettext("Backup Group"), | |
176 | dataIndex: 'text', | |
507c39c5 DM |
177 | flex: 1 |
178 | }, | |
179 | { | |
180 | xtype: 'datecolumn', | |
e8f0ad19 | 181 | header: gettext('Backup Time'), |
507c39c5 | 182 | sortable: true, |
e8f0ad19 | 183 | dataIndex: 'backup-time', |
507c39c5 | 184 | format: 'Y-m-d H:i:s', |
e8f0ad19 DM |
185 | width: 150 |
186 | }, | |
187 | { | |
188 | header: gettext("Size"), | |
189 | sortable: true, | |
190 | dataIndex: 'size', | |
191 | renderer: Proxmox.Utils.format_size, | |
507c39c5 DM |
192 | }, |
193 | { | |
194 | xtype: 'numbercolumn', | |
195 | format: '0', | |
e8f0ad19 | 196 | header: gettext("Count"), |
507c39c5 | 197 | sortable: true, |
e8f0ad19 | 198 | dataIndex: 'count', |
507c39c5 | 199 | }, |
e8f0ad19 DM |
200 | { |
201 | header: gettext("Files"), | |
202 | sortable: false, | |
203 | dataIndex: 'files', | |
aeee4329 | 204 | flex: 2 |
e8f0ad19 | 205 | } |
507c39c5 DM |
206 | ], |
207 | ||
208 | tbar: [ | |
209 | { | |
210 | text: gettext('Reload'), | |
211 | iconCls: 'fa fa-refresh', | |
212 | handler: 'reload', | |
213 | }, | |
b1127fd0 | 214 | prune_btn |
507c39c5 DM |
215 | ], |
216 | }); | |
217 | ||
218 | me.callParent(); | |
9d4ebe3d | 219 | }, |
ca23a97f | 220 | }); |