From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/5] ui: NavigationTree: add entries for changers/drives
Date: Mon, 1 Mar 2021 12:22:41 +0100 [thread overview]
Message-ID: <20210301112243.15842-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210301112243.15842-1-d.csapak@proxmox.com>
and only check TapeManagement once in the init function
we now have 2 updatestores that update individually
(one for datastores, one for drives/changers)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
www/NavigationTree.js | 103 ++++++++++++++++++++++++++++++++++++------
1 file changed, 89 insertions(+), 14 deletions(-)
diff --git a/www/NavigationTree.js b/www/NavigationTree.js
index e37447ce..8f9b366c 100644
--- a/www/NavigationTree.js
+++ b/www/NavigationTree.js
@@ -8,6 +8,16 @@ Ext.define('pbs-datastore-list', {
idProperty: 'store',
});
+Ext.define('pbs-tape-drive-list', {
+ extend: 'Ext.data.Model',
+ fields: ['name', 'changer'],
+ proxy: {
+ type: 'proxmox',
+ url: "/api2/json/tape/drive",
+ },
+ idProperty: 'name',
+});
+
Ext.define('PBS.store.NavigationStore', {
extend: 'Ext.data.TreeStore',
@@ -101,34 +111,99 @@ Ext.define('PBS.view.main.NavigationTree', {
view.rstore = Ext.create('Proxmox.data.UpdateStore', {
autoStart: true,
interval: 15 * 1000,
- storeId: 'pbs-datastore-list',
storeid: 'pbs-datastore-list',
model: 'pbs-datastore-list',
});
view.rstore.on('load', this.onLoad, this);
view.on('destroy', view.rstore.stopUpdate);
+
+ if (PBS.TapeManagement !== undefined) {
+ view.tapestore = Ext.create('Proxmox.data.UpdateStore', {
+ autoStart: true,
+ interval: 2 * 1000,
+ storeid: 'pbs-tape-drive-list',
+ model: 'pbs-tape-drive-list',
+ });
+
+ let root = view.getStore().getRoot();
+ root.insertChild(3, {
+ text: "Tape Backup",
+ iconCls: 'pbs-icon-tape',
+ id: 'tape_management',
+ path: 'pbsTapeManagement',
+ expanded: true,
+ children: [],
+ });
+
+ view.tapestore.on('load', this.onTapeDriveLoad, this);
+ view.on('destroy', view.tapestore.stopUpdate);
+ }
},
- onLoad: function(store, records, success) {
+ onTapeDriveLoad: function(store, records, success) {
if (!success) return;
- var view = this.getView();
+ let view = this.getView();
let root = view.getStore().getRoot();
- if (PBS.TapeManagement !== undefined) {
- if (!root.findChild('id', 'tape_management', false)) {
- root.insertChild(3, {
- text: "Tape Backup",
- iconCls: 'pbs-icon-tape',
- id: 'tape_management',
- path: 'pbsTapeManagement',
- expanded: true,
- children: [],
- });
+ records.sort((a, b) => a.data.name.localeCompare(b.data.name));
+ let list = root.findChild('id', 'tape_management', false);
+ let newSet = {};
+
+ for (const drive of records) {
+ let path, text, iconCls;
+ if (drive.data.changer !== undefined) {
+ text = drive.data.changer;
+ path = `Changer-${text}`;
+ iconCls = 'fa fa-circle';
+ } else {
+ text = drive.data.name;
+ path = `Drive-${text}`;
+ iconCls = 'fa fa-square';
+ }
+ newSet[path] = {
+ text,
+ path,
+ iconCls,
+ leaf: true,
+ };
+ }
+
+ let paths = Object.keys(newSet).sort();
+
+ let oldIdx = 0;
+ for (let newIdx = 0; newIdx < paths.length; newIdx++) {
+ let newPath = paths[newIdx];
+ // find index to insert
+ while (oldIdx < list.childNodes.length && newPath > list.getChildAt(oldIdx).data.path) {
+ oldIdx++;
+ }
+
+ if (oldIdx >= list.childNodes.length || list.getChildAt(oldIdx).data.path !== newPath) {
+ list.insertChild(oldIdx, newSet[newPath]);
}
}
+ list.eachChild((child) => {
+ if (!newSet[child.data.path]) {
+ list.removeChild(child, true);
+ }
+ });
+
+ if (view.pathToSelect !== undefined) {
+ let path = view.pathToSelect;
+ delete view.pathToSelect;
+ view.select(path, true);
+ }
+ },
+
+ onLoad: function(store, records, success) {
+ if (!success) return;
+ var view = this.getView();
+
+ let root = view.getStore().getRoot();
+
records.sort((a, b) => a.id.localeCompare(b.id));
var list = root.findChild('id', 'datastores', false);
@@ -191,7 +266,7 @@ Ext.define('PBS.view.main.NavigationTree', {
select: function(path, silent) {
var me = this;
- if (me.rstore.isLoaded()) {
+ if (me.rstore.isLoaded() && (!PBS.TapeManagement || me.tapestore.isLoaded())) {
if (silent) {
me.suspendEvents(false);
}
--
2.20.1
next prev parent reply other threads:[~2021-03-01 11:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 11:22 [pbs-devel] [PATCH proxmox-backup 1/5] ui: tape: add DriveStatus panel Dominik Csapak
2021-03-01 11:22 ` [pbs-devel] [PATCH proxmox-backup 2/5] ui: MainView: adapt router to add changer/drive entries Dominik Csapak
2021-03-01 11:22 ` Dominik Csapak [this message]
2021-03-01 11:22 ` [pbs-devel] [PATCH proxmox-backup 4/5] ui: tape: ChangerStatus: remove changerselector combobox Dominik Csapak
2021-03-01 11:22 ` [pbs-devel] [PATCH proxmox-backup 5/5] ui: tape/ChangerStatus: handle vanishing view during reload Dominik Csapak
2021-03-01 11:39 ` [pbs-devel] applied: [PATCH proxmox-backup 1/5] ui: tape: add DriveStatus panel Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210301112243.15842-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox