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 0EAF1695CE
 for <pbs-devel@lists.proxmox.com>; Tue,  2 Mar 2021 12:20:13 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 006402BAEE
 for <pbs-devel@lists.proxmox.com>; Tue,  2 Mar 2021 12:19:43 +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))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id A68352BAB9
 for <pbs-devel@lists.proxmox.com>; Tue,  2 Mar 2021 12:19:41 +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 6AFEF44F7B
 for <pbs-devel@lists.proxmox.com>; Tue,  2 Mar 2021 12:19:41 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue,  2 Mar 2021 12:19:39 +0100
Message-Id: <20210302111940.17276-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210302111940.17276-1-d.csapak@proxmox.com>
References: <20210302111940.17276-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.201 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
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [drive.name]
Subject: [pbs-devel] [PATCH proxmox-backup 4/5] ui: tape/DriveStatus: add
 state to Info panel
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: Tue, 02 Mar 2021 11:20:13 -0000

and optimize the updateData function a bit

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/tape/DriveStatus.js | 51 +++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/www/tape/DriveStatus.js b/www/tape/DriveStatus.js
index 2663ded9..c9e9ea02 100644
--- a/www/tape/DriveStatus.js
+++ b/www/tape/DriveStatus.js
@@ -228,7 +228,16 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
     bodyPadding: 15,
 
     viewModel: {
-	data: {},
+	data: {
+	    drive: {},
+	},
+
+	formulas: {
+	    driveState: function(get) {
+		let drive = get('drive');
+		return PBS.Utils.renderDriveState(drive.state, {});
+	    },
+	},
     },
 
     items: [
@@ -237,7 +246,7 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	    title: gettext('Name'),
 	    bind: {
 		data: {
-		    text: '{name}',
+		    text: '{drive.name}',
 		},
 	    },
 	},
@@ -246,7 +255,7 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	    title: gettext('Vendor'),
 	    bind: {
 		data: {
-		    text: '{vendor}',
+		    text: '{drive.vendor}',
 		},
 	    },
 	},
@@ -255,7 +264,7 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	    title: gettext('Model'),
 	    bind: {
 		data: {
-		    text: '{model}',
+		    text: '{drive.model}',
 		},
 	    },
 	},
@@ -264,7 +273,7 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	    title: gettext('Serial'),
 	    bind: {
 		data: {
-		    text: '{serial}',
+		    text: '{drive.serial}',
 		},
 	    },
 	},
@@ -273,22 +282,34 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	    title: gettext('Path'),
 	    bind: {
 		data: {
-		    text: '{path}',
+		    text: '{drive.path}',
+		},
+	    },
+	},
+	{
+	    xtype: 'pmxInfoWidget',
+	    title: gettext('State'),
+	    bind: {
+		data: {
+		    text: '{driveState}',
 		},
 	    },
 	},
     ],
 
-    updateData: function(record) {
+    updateData: function(store) {
 	let me = this;
+	if (!store) {
+	    return;
+	}
+	let record = store.findRecord('name', me.drive, 0, false, true, true);
 	if (!record) {
 	    return;
 	}
 
 	let vm = me.getViewModel();
-	for (const [key, value] of Object.entries(record.data)) {
-	    vm.set(key, value);
-	}
+	vm.set('drive', record.data);
+	vm.notify();
     },
 
     initComponent: function() {
@@ -298,13 +319,9 @@ Ext.define('PBS.TapeManagement.DriveInfoPanel', {
 	}
 
 	let tapeStore = Ext.ComponentQuery.query('navigationtree')[0].tapestore;
-	me.mon(tapeStore, 'load', function() {
-	    let driveRecord = tapeStore.findRecord('name', me.drive, 0, false, true, true);
-	    me.updateData(driveRecord);
-	});
-	if (!tapeStore.isLoading) {
-	    let driveRecord = tapeStore.findRecord('name', me.drive, 0, false, true, true);
-	    me.updateData(driveRecord);
+	me.mon(tapeStore, 'load', me.updateData, me);
+	if (tapeStore.isLoaded()) {
+	    me.updateData(tapeStore);
 	}
 
 	me.callParent();
-- 
2.20.1