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 608A269F14
 for <pbs-devel@lists.proxmox.com>; Fri, 12 Mar 2021 16:06:59 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 4A88034528
 for <pbs-devel@lists.proxmox.com>; Fri, 12 Mar 2021 16:06:29 +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 BC82134520
 for <pbs-devel@lists.proxmox.com>; Fri, 12 Mar 2021 16:06:28 +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 5AE7B446CE
 for <pbs-devel@lists.proxmox.com>; Fri, 12 Mar 2021 16:06:28 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Fri, 12 Mar 2021 16:06:27 +0100
Message-Id: <20210312150627.24552-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.188 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 v2] ui: tape: convert slot
 selection on transfer to combogrid
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: Fri, 12 Mar 2021 15:06:59 -0000

this is much handier than number field, and the user can instantly
see which one is an import/export slot

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* combined the two uses into an extra widget, saves some code

 www/tape/ChangerStatus.js | 59 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/www/tape/ChangerStatus.js b/www/tape/ChangerStatus.js
index 599e6320..68316345 100644
--- a/www/tape/ChangerStatus.js
+++ b/www/tape/ChangerStatus.js
@@ -11,6 +11,29 @@ Ext.define('pbs-slot-model', {
     idProperty: 'entry-id',
 });
 
+Ext.define('PBS.TapeManagement.FreeSlotSelector', {
+    extend: 'Proxmox.form.ComboGrid',
+    alias: 'widget.pbsFreeSlotSelector',
+
+    valueField: 'id',
+    displayField: 'id',
+
+    listConfig: {
+	columns: [
+	    {
+		dataIndex: 'id',
+		text: gettext('ID'),
+		flex: 1,
+	    },
+	    {
+		dataIndex: 'type',
+		text: gettext('Type'),
+		flex: 1,
+	    },
+	],
+    },
+});
+
 Ext.define('PBS.TapeManagement.ChangerStatus', {
     extend: 'Ext.panel.Panel',
     alias: 'widget.pbsChangerStatus',
@@ -40,9 +63,12 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 			fieldLabel: gettext('From Slot'),
 		    },
 		    {
-			xtype: 'proxmoxintegerfield',
+			xtype: 'pbsFreeSlotSelector',
 			name: 'to',
 			fieldLabel: gettext('To Slot'),
+			store: {
+			    data: me.free_slots,
+			},
 		    },
 		],
 		listeners: {
@@ -73,9 +99,12 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 			fieldLabel: gettext('From Slot'),
 		    },
 		    {
-			xtype: 'proxmoxintegerfield',
+			xtype: 'pbsFreeSlotSelector',
 			name: 'to',
 			fieldLabel: gettext('To Slot'),
+			store: {
+			    data: me.free_slots.concat(me.free_ie_slots),
+			},
 		    },
 		],
 		listeners: {
@@ -340,6 +369,14 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 	    me.reload_full(false);
 	},
 
+	free_slots: [],
+
+	updateFreeSlots: function(free_slots, free_ie_slots) {
+	    let me = this;
+	    me.free_slots = free_slots;
+	    me.free_ie_slots = free_ie_slots;
+	},
+
 	reload_full: async function(use_cache) {
 	    let me = this;
 	    let view = me.getView();
@@ -399,6 +436,9 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 		    drive_entries[entry['changer-drivenum'] || 0] = entry;
 		}
 
+		let free_slots = [];
+		let free_ie_slots = [];
+
 		for (let entry of status.result.data) {
 		    let type = entry['entry-kind'];
 
@@ -414,6 +454,19 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 			entry['is-labeled'] = false;
 		    }
 
+		    if (!entry['label-text'] && type !== 'drive') {
+			if (type === 'slot') {
+			    free_slots.push({
+				id: entry['entry-id'],
+				type,
+			    });
+			} else {
+			    free_ie_slots.push({
+				id: entry['entry-id'],
+				type,
+			    });
+			}
+		    }
 		    data[type].push(entry);
 		}
 
@@ -433,6 +486,8 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 		// manually fire selectionchange to update button status
 		me.lookup('drives').getSelectionModel().fireEvent('selectionchange', me);
 
+		me.updateFreeSlots(free_slots, free_ie_slots);
+
 		if (!use_cache) {
 		    Proxmox.Utils.setErrorMask(view);
 		}
-- 
2.20.1