]>
Commit | Line | Data |
---|---|---|
7ece65a0 DC |
1 | Ext.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 |
11 | Ext.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 | ||
106 | Ext.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 DC |
165 | Ext.Array.forEach(erase_list, function(node) { list.removeChild(node, true); }); |
166 | }, | |
167 | }, | |
168 | ||
169 | listeners: { | |
170 | itemclick: function(tl, info) { | |
171 | if (info.node.data.id === 'datastores') { | |
172 | return false; | |
173 | } | |
174 | if (info.node.data.id === 'addbutton') { | |
175 | let me = this; | |
176 | Ext.create('PBS.DataStoreEdit', { | |
177 | listeners: { | |
178 | destroy: function() { | |
179 | me.rstore.reload(); | |
180 | }, | |
181 | }, | |
182 | }).show(); | |
183 | return false; | |
184 | } | |
185 | return true; | |
264c1958 | 186 | }, |
ca23a97f DM |
187 | }, |
188 | ||
b0ee976f DM |
189 | select: function(path) { |
190 | var me = this; | |
191 | var item = me.getStore().findRecord('path', path, 0, false, true, true); | |
192 | me.setSelection(item); | |
193 | }, | |
194 | ||
195 | animation: false, | |
196 | expanderOnly: true, | |
197 | expanderFirst: false, | |
198 | store: 'NavigationStore', | |
264c1958 | 199 | ui: 'nav', |
b0ee976f | 200 | }); |