From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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 2D65F76798
 for <pve-devel@lists.proxmox.com>; Fri, 23 Apr 2021 12:15:23 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 2EC1D277E0
 for <pve-devel@lists.proxmox.com>; Fri, 23 Apr 2021 12:15:21 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 A7DE62765F
 for <pve-devel@lists.proxmox.com>; Fri, 23 Apr 2021 12:15:15 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E3AB743508
 for <pve-devel@lists.proxmox.com>; Fri, 23 Apr 2021 12:15:05 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 23 Apr 2021 12:14:59 +0200
Message-Id: <20210423101501.27300-10-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210423101501.27300-1-f.ebner@proxmox.com>
References: <20210423101501.27300-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH widget-toolkit 09/11] disk list: add wipe disk
 button
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 23 Apr 2021 10:15:23 -0000

which shows a confirm dialog with the most relevant information before actually
issuing the API call.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 src/panel/DiskList.js | 81 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/src/panel/DiskList.js b/src/panel/DiskList.js
index c6f1638..b155139 100644
--- a/src/panel/DiskList.js
+++ b/src/panel/DiskList.js
@@ -44,6 +44,8 @@ Ext.define('Proxmox.DiskList', {
     extend: 'Ext.tree.Panel',
     alias: 'widget.pmxDiskList',
 
+    supportsWipeDisk: false,
+
     rootVisible: false,
 
     emptyText: gettext('No Disks found'),
@@ -113,6 +115,34 @@ Ext.define('Proxmox.DiskList', {
 	    });
 	},
 
+	wipeDisk: function() {
+	    let me = this;
+	    let view = me.getView();
+	    let selection = view.getSelection();
+	    if (!selection || selection.length < 1) return;
+
+	    let rec = selection[0];
+	    Proxmox.Utils.API2Request({
+		url: `${view.exturl}/wipedisk`,
+		waitMsgTarget: view,
+		method: 'PUT',
+		params: { disk: rec.data.name },
+		failure: function(response, options) {
+		    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+		},
+		success: function(response, options) {
+		    var upid = response.result.data;
+		    var win = Ext.create('Proxmox.window.TaskProgress', {
+		        upid: upid,
+			taskDone: function() {
+			    me.reload();
+			},
+		    });
+		    win.show();
+		},
+	    });
+	},
+
 	init: function(view) {
 	    let nodename = view.nodename || 'localhost';
 	    view.baseurl = `/api2/json/nodes/${nodename}/disks`;
@@ -336,6 +366,57 @@ Ext.define('Proxmox.DiskList', {
 	    },
 	];
 
+	if (me.supportsWipeDisk) {
+	    tbar.push('-');
+	    tbar.push({
+		xtype: 'proxmoxButton',
+		text: gettext('Wipe Disk'),
+		parentXType: 'treepanel',
+		dangerous: true,
+		confirmMsg: function(rec) {
+		    const data = rec.data;
+
+		    let mainMessage = Ext.String.format(
+			gettext('Are you sure you want to wipe {0}?'),
+			data.devpath,
+		    );
+		    mainMessage += `<br> ${gettext('All data on the device will be lost!')}`;
+
+		    const type = me.renderDiskType(data["disk-type"]);
+
+		    let usage;
+		    if (data.children.length > 0) {
+			const partitionUsage = data.children.map(
+			    partition => me.renderDiskUsage(partition.used),
+			).join(', ');
+			usage = `${gettext('Partitions')} (${partitionUsage})`;
+		    } else {
+			usage = me.renderDiskUsage(data.used, undefined, rec);
+		    }
+
+		    const size = Proxmox.Utils.format_size(data.size);
+		    const serial = Ext.String.htmlEncode(data.serial);
+
+		    let additionalInfo = `${gettext('Type')}: ${type}<br>`;
+		    additionalInfo += `${gettext('Usage')}: ${usage}<br>`;
+		    additionalInfo += `${gettext('Size')}: ${size}<br>`;
+		    additionalInfo += `${gettext('Serial')}: ${serial}`;
+
+		    return `${mainMessage}<br><br>${additionalInfo}`;
+		},
+		disabled: true,
+		enableFn: function(rec) {
+		    // TODO enable for partitions once they can be selected for ZFS,LVM,etc. creation
+		    if (!rec || rec.data.parent) {
+			return false;
+		    } else {
+			return true;
+		    }
+		},
+		handler: 'wipeDisk',
+	    });
+	}
+
 	me.tbar = tbar;
 
 	me.callParent();
-- 
2.20.1