]>
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 | |
f1baa7f4 TL |
22 | controller: { |
23 | xclass: 'Ext.app.ViewController', | |
24 | ||
25 | init: function(view) { | |
26 | if (!view.datastore) { | |
27 | throw "no datastore specified"; | |
28 | } | |
29 | ||
e8f0ad19 | 30 | this.data_store = Ext.create('Ext.data.Store', { |
33839735 | 31 | model: 'pbs-data-store-snapshots', |
e8f0ad19 DM |
32 | sorters: 'backup-group', |
33 | groupField: 'backup-group', | |
34 | }); | |
35 | ||
f1baa7f4 TL |
36 | view.title = gettext('Data Store Content: ') + view.datastore; |
37 | ||
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 | ||
83 | records.forEach(function(item) { | |
e8f0ad19 DM |
84 | let group = item.data["backup-type"] + "/" + item.data["backup-id"]; |
85 | let children = groups[group].children; | |
86 | ||
87 | let data = item.data; | |
88 | data.text = Ext.Date.format(data["backup-time"], 'Y-m-d H:i:s'); | |
89 | data.leaf = true; | |
90 | ||
91 | children.push(data); | |
92 | }); | |
93 | ||
94 | let children = []; | |
95 | Ext.Object.each(groups, function(key, group) { | |
96 | let last_backup = 0; | |
97 | group.children.forEach(function(item) { | |
98 | if (item["backup-time"] > last_backup) { | |
99 | last_backup = item["backup-time"]; | |
100 | group["backup-time"] = last_backup; | |
101 | group.files = item.files; | |
102 | group.size = item.size; | |
103 | } | |
104 | }); | |
105 | group.count = group.children.length; | |
106 | children.push(group) | |
107 | }) | |
108 | ||
109 | view.setRootNode({ | |
110 | expanded: true, | |
111 | children: children | |
112 | }); | |
113 | ||
114 | }); | |
115 | ||
f1baa7f4 TL |
116 | }, |
117 | }, | |
118 | ||
507c39c5 DM |
119 | initComponent: function() { |
120 | var me = this; | |
9d4ebe3d | 121 | |
b1127fd0 DM |
122 | var sm = Ext.create('Ext.selection.RowModel', {}); |
123 | ||
124 | var prune_btn = new Proxmox.button.Button({ | |
125 | text: gettext('Prune'), | |
126 | disabled: true, | |
127 | selModel: sm, | |
128 | enableFn: function(record) { | |
129 | return !record.data.leaf; | |
130 | }, | |
131 | handler: function() { | |
132 | let rec = sm.getSelection()[0]; | |
133 | if (!(rec && rec.data)) return; | |
134 | let data = rec.data; | |
135 | if (data.leaf) return; | |
136 | ||
137 | console.log(data); | |
138 | ||
139 | console.log("PRUNE GROUP: " + me.datastore); | |
140 | ||
141 | if (!me.datastore) return; | |
142 | ||
143 | let win = Ext.create('PBS.DataStorePrune', { | |
144 | datastore: me.datastore, | |
145 | backup_type: data.backup_type, | |
146 | backup_id: data.backup_id, | |
147 | }); | |
148 | win.on('destroy', me.getController().reload, me.getController()); | |
149 | win.show(); | |
150 | ||
151 | } | |
152 | }); | |
153 | ||
507c39c5 | 154 | Ext.apply(me, { |
b1127fd0 | 155 | selModel: sm, |
507c39c5 DM |
156 | columns: [ |
157 | { | |
e8f0ad19 DM |
158 | xtype: 'treecolumn', |
159 | header: gettext("Backup Group"), | |
160 | dataIndex: 'text', | |
507c39c5 DM |
161 | flex: 1 |
162 | }, | |
163 | { | |
164 | xtype: 'datecolumn', | |
e8f0ad19 | 165 | header: gettext('Backup Time'), |
507c39c5 | 166 | sortable: true, |
e8f0ad19 | 167 | dataIndex: 'backup-time', |
507c39c5 | 168 | format: 'Y-m-d H:i:s', |
e8f0ad19 DM |
169 | width: 150 |
170 | }, | |
171 | { | |
172 | header: gettext("Size"), | |
173 | sortable: true, | |
174 | dataIndex: 'size', | |
175 | renderer: Proxmox.Utils.format_size, | |
507c39c5 DM |
176 | }, |
177 | { | |
178 | xtype: 'numbercolumn', | |
179 | format: '0', | |
e8f0ad19 | 180 | header: gettext("Count"), |
507c39c5 | 181 | sortable: true, |
e8f0ad19 | 182 | dataIndex: 'count', |
507c39c5 | 183 | }, |
e8f0ad19 DM |
184 | { |
185 | header: gettext("Files"), | |
186 | sortable: false, | |
187 | dataIndex: 'files', | |
188 | flex: 4 | |
189 | } | |
507c39c5 DM |
190 | ], |
191 | ||
192 | tbar: [ | |
193 | { | |
194 | text: gettext('Reload'), | |
195 | iconCls: 'fa fa-refresh', | |
196 | handler: 'reload', | |
197 | }, | |
b1127fd0 | 198 | prune_btn |
507c39c5 DM |
199 | ], |
200 | }); | |
201 | ||
202 | me.callParent(); | |
9d4ebe3d | 203 | }, |
ca23a97f | 204 | }); |