]> git.proxmox.com Git - proxmox-backup.git/blame - www/NavigationTree.js
tools/logrotate: fix compression logic
[proxmox-backup.git] / www / NavigationTree.js
CommitLineData
7ece65a0
DC
1Ext.define('pbs-datastore-list', {
2 extend: 'Ext.data.Model',
3 fields: ['name', 'comment'],
4 proxy: {
5 type: 'proxmox',
6 url: "/api2/json/admin/datastore",
7 },
8 idProperty: 'store',
9});
10
b0ee976f
DM
11Ext.define('PBS.store.NavigationStore', {
12 extend: 'Ext.data.TreeStore',
13
14 storeId: 'NavigationStore',
15
16 root: {
17 expanded: true,
18 children: [
84b9eced
TL
19 {
20 text: gettext('Dashboard'),
21 iconCls: 'fa fa-tachometer',
22 path: 'pbsDashboard',
264c1958 23 leaf: true,
84b9eced 24 },
b0ee976f
DM
25 {
26 text: gettext('Configuration'),
27 iconCls: 'fa fa-gears',
28 path: 'pbsSystemConfiguration',
29 expanded: true,
30 children: [
88acc861
DC
31 {
32 text: gettext('User Management'),
33 iconCls: 'fa fa-user',
34 path: 'pbsUserView',
264c1958 35 leaf: true,
88acc861 36 },
0542cfdf
DC
37 {
38 text: gettext('Permissions'),
39 iconCls: 'fa fa-unlock',
40 path: 'pbsACLView',
264c1958 41 leaf: true,
0542cfdf 42 },
9e2a4653
DC
43 {
44 text: gettext('Remotes'),
45 iconCls: 'fa fa-server',
46 path: 'pbsRemoteView',
47 leaf: true,
48 },
b0ee976f
DM
49 {
50 text: gettext('Subscription'),
51 iconCls: 'fa fa-support',
52 path: 'pbsSubscription',
264c1958
TL
53 leaf: true,
54 },
55 ],
b0ee976f
DM
56 },
57 {
58 text: gettext('Administration'),
59 iconCls: 'fa fa-wrench',
60 path: 'pbsServerAdministration',
7f17f744
DC
61 expanded: true,
62 leaf: false,
63 children: [
64 {
65 text: gettext('Disks'),
66 iconCls: 'fa fa-hdd-o',
67 path: 'pmxDiskList',
68 leaf: false,
69 children: [
70 {
71 text: Proxmox.Utils.directoryText,
72 iconCls: 'fa fa-folder',
73 path: 'pbsDirectoryList',
74 leaf: true,
75 },
2ea501ff
DC
76 {
77 text: "ZFS",
78 iconCls: 'fa fa-th-large',
79 path: 'pbsZFSList',
80 leaf: true,
81 },
264c1958
TL
82 ],
83 },
84 ],
98bb3b90
DC
85 },
86 {
58f950c5 87 text: gettext('Datastore'),
98bb3b90 88 iconCls: 'fa fa-archive',
7ece65a0 89 id: 'datastores',
98bb3b90 90 expanded: true,
7ece65a0 91 expandable: false,
264c1958 92 leaf: false,
7ece65a0
DC
93 children: [
94 {
95 text: gettext('Add Datastore'),
96 iconCls: 'fa fa-plus-circle',
97 leaf: true,
98 id: 'addbutton',
99 },
100 ],
98bb3b90 101 },
264c1958
TL
102 ],
103 },
b0ee976f
DM
104});
105
106Ext.define('PBS.view.main.NavigationTree', {
107 extend: 'Ext.list.Tree',
108 xtype: 'navigationtree',
109
ca23a97f
DM
110 controller: {
111 xclass: 'Ext.app.ViewController',
112
113 init: function(view) {
ca23a97f
DM
114 view.rstore = Ext.create('Proxmox.data.UpdateStore', {
115 autoStart: true,
116 interval: 15 * 1000,
d757021f 117 storeId: 'pbs-datastore-list',
ca23a97f 118 storeid: 'pbs-datastore-list',
264c1958 119 model: 'pbs-datastore-list',
ca23a97f
DM
120 });
121
122 view.rstore.on('load', this.onLoad, this);
123 view.on('destroy', view.rstore.stopUpdate);
124 },
125
126 onLoad: function(store, records, success) {
98bb3b90 127 if (!success) return;
ca23a97f
DM
128 var view = this.getView();
129
130 let root = view.getStore().getRoot();
131
7ece65a0 132 records.sort((a, b) => a.id.localeCompare(b.id));
8277f4ac 133
7ece65a0 134 var list = root.findChild('id', 'datastores', false);
ca23a97f
DM
135 var length = records.length;
136 var lookup_hash = {};
7ece65a0
DC
137 let j = 0;
138 for (let i = 0; i < length; i++) {
264c1958 139 let name = records[i].id;
ca23a97f 140 lookup_hash[name] = true;
7ece65a0
DC
141
142 while (name.localeCompare(list.getChildAt(j).data.text) > 0 &&
143 (j + 1) < list.childNodes.length) {
144 j++;
145 }
146
147 if (list.getChildAt(j).data.text.localeCompare(name) !== 0) {
148 list.insertChild(j, {
ca23a97f 149 text: name,
c0ac2074 150 path: `DataStore-${name}`,
bc9c306c 151 iconCls: 'fa fa-database',
264c1958 152 leaf: true,
ca23a97f
DM
153 });
154 }
155 }
156
157 var erase_list = [];
158 list.eachChild(function(node) {
264c1958 159 let name = node.data.text;
7ece65a0 160 if (!lookup_hash[name] && node.data.id !== 'addbutton') {
ca23a97f
DM
161 erase_list.push(node);
162 }
163 });
164
7ece65a0 165 Ext.Array.forEach(erase_list, function(node) { list.removeChild(node, true); });
2565fdd0
DC
166
167 if (view.pathToSelect !== undefined) {
168 let path = view.pathToSelect;
169 delete view.pathToSelect;
170 view.select(path, true);
171 }
7ece65a0
DC
172 },
173 },
174
175 listeners: {
176 itemclick: function(tl, info) {
177 if (info.node.data.id === 'datastores') {
178 return false;
179 }
180 if (info.node.data.id === 'addbutton') {
181 let me = this;
182 Ext.create('PBS.DataStoreEdit', {
183 listeners: {
184 destroy: function() {
185 me.rstore.reload();
186 },
187 },
188 }).show();
189 return false;
190 }
191 return true;
264c1958 192 },
ca23a97f
DM
193 },
194
2565fdd0 195 select: function(path, silent) {
b0ee976f 196 var me = this;
2565fdd0
DC
197 if (me.rstore.isLoaded()) {
198 if (silent) {
199 me.suspendEvents(false);
200 }
201 var item = me.getStore().findRecord('path', path, 0, false, true, true);
202 me.setSelection(item);
203 if (silent) {
204 me.resumeEvents(true);
205 }
206 } else {
207 me.pathToSelect = path;
208 }
b0ee976f
DM
209 },
210
211 animation: false,
212 expanderOnly: true,
213 expanderFirst: false,
214 store: 'NavigationStore',
264c1958 215 ui: 'nav',
b0ee976f 216});