From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 6354568F3E
 for <pbs-devel@lists.proxmox.com>; Mon,  1 Mar 2021 12:22:46 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 56C4D1E992
 for <pbs-devel@lists.proxmox.com>; Mon,  1 Mar 2021 12:22:46 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 900C41E969
 for <pbs-devel@lists.proxmox.com>; Mon,  1 Mar 2021 12:22:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5EEE345825
 for <pbs-devel@lists.proxmox.com>; Mon,  1 Mar 2021 12:22:44 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Mon,  1 Mar 2021 12:22:40 +0100
Message-Id: <20210301112243.15842-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210301112243.15842-1-d.csapak@proxmox.com>
References: <20210301112243.15842-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.205 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [PATCH proxmox-backup 2/5] ui: MainView: adapt router
 to add changer/drive entries
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 01 Mar 2021 11:22:46 -0000

by generalizing the isDataStorePath logic to a 'parseRouterPath'.

We still have to keep the isDataStore logic for tabpanel handling,
If we add tabs to changer-/drivestatus panels, we have to adapt
that too.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/MainView.js | 70 +++++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/www/MainView.js b/www/MainView.js
index 6ed86b77..e6257f35 100644
--- a/www/MainView.js
+++ b/www/MainView.js
@@ -17,17 +17,28 @@ Ext.define('PBS.MainView', {
 	    },
 	},
 
-	beforeChangePath: function(path, subpath, action) {
-	    var me = this;
-
+	parseRouterPath: function(path) {
 	    let xtype = path;
-	    let datastore;
-	    let isDataStore = PBS.Utils.isDataStorePath(path);
-	    if (isDataStore) {
+	    let config = {};
+	    if (PBS.Utils.isDataStorePath(path)) {
+		config.datastore = PBS.Utils.getDataStoreFromPath(path);
 		xtype = 'pbsDataStorePanel';
-		datastore = PBS.Utils.getDataStoreFromPath(path);
+	    } else if (path.indexOf('Changer-') === 0) {
+		config.changer = path.slice('Changer-'.length);
+		xtype = 'pbsChangerStatus';
+	    } else if (path.indexOf('Drive-') === 0) {
+		config.drive = path.slice('Drive-'.length);
+		xtype = 'pbsDriveStatus';
 	    }
 
+	    return [xtype, config];
+	},
+
+	beforeChangePath: function(path, subpath, action) {
+	    var me = this;
+
+	    let [xtype, config] = me.parseRouterPath(path);
+
 	    if (!Ext.ClassManager.getByAlias(`widget.${xtype}`)) {
 		console.warn(`xtype ${xtype} not found`);
 		action.stop();
@@ -36,27 +47,26 @@ Ext.define('PBS.MainView', {
 
 	    var lastpanel = me.lookupReference('contentpanel').getLayout().getActiveItem();
 	    if (lastpanel && lastpanel.xtype === xtype) {
-		if (isDataStore) {
-		    if (datastore === lastpanel.datastore) {
-			action.stop();
+		for (const [prop, value] of Object.entries(config)) {
+		    if (lastpanel[prop] !== value) {
+			action.resume();
 			return;
 		    }
-		} else {
-		    // we have the right component already,
-		    // we just need to select the correct tab
-		    // default to the first
-		    subpath = subpath || 0;
-		    if (lastpanel.getActiveTab) {
-			// we assume lastpanel is a tabpanel
-			if (lastpanel.getActiveTab().getItemId() !== subpath) {
-			    // set the active tab
-			    lastpanel.setActiveTab(subpath);
-			}
-			// else we are already there
+		}
+		// we have the right component already,
+		// we just need to select the correct tab
+		// default to the first
+		subpath = subpath || 0;
+		if (lastpanel.getActiveTab) {
+		    // we assume lastpanel is a tabpanel
+		    if (lastpanel.getActiveTab().getItemId() !== subpath) {
+			// set the active tab
+			lastpanel.setActiveTab(subpath);
 		    }
-		    action.stop();
-		    return;
+		    // else we are already there
 		}
+		action.stop();
+		return;
 	    }
 
 	    action.resume();
@@ -79,12 +89,10 @@ Ext.define('PBS.MainView', {
 		me.redirectTo(newpath);
 	    };
 
-	    let xtype = path;
+	    let [xtype, config] = me.parseRouterPath(path);
 	    var obj;
-	    let datastore;
 	    if (PBS.Utils.isDataStorePath(path)) {
-		datastore = PBS.Utils.getDataStoreFromPath(path);
-		if (lastpanel && lastpanel.xtype === 'pbsDataStorePanel' && !subpath) {
+		if (lastpanel && lastpanel.xtype === xtype && !subpath) {
 		    let activeTab = lastpanel.getActiveTab();
 		    let newpath = path;
 		    if (lastpanel.items.indexOf(activeTab) !== 0) {
@@ -93,18 +101,16 @@ Ext.define('PBS.MainView', {
 		    }
 		    me.redirectTo(newpath);
 		}
-		xtype = 'pbsDataStorePanel';
 	    }
-	    obj = contentpanel.add({
+	    obj = contentpanel.add(Ext.apply(config, {
 		xtype,
-		datastore,
 		nodename: 'localhost',
 		border: false,
 		activeTab: subpath || 0,
 		listeners: {
 		    tabchange: tabChangeListener,
 		},
-	    });
+	    }));
 
 	    var treelist = me.lookupReference('navtree');
 
-- 
2.20.1