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 32F8062512
 for <pve-devel@lists.proxmox.com>; Wed, 16 Sep 2020 14:51:03 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 9E00724407
 for <pve-devel@lists.proxmox.com>; Wed, 16 Sep 2020 14:51:01 +0200 (CEST)
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 5F4F4240FA
 for <pve-devel@lists.proxmox.com>; Wed, 16 Sep 2020 14:50:52 +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 1E6D1453CB
 for <pve-devel@lists.proxmox.com>; Wed, 16 Sep 2020 14:50:52 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 16 Sep 2020 14:50:38 +0200
Message-Id: <20200916125041.4151-18-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200916125041.4151-1-f.ebner@proxmox.com>
References: <20200916125041.4151-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.056 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. [me.store, sencha.com]
Subject: [pve-devel] [PATCH v2 manager 17/20] group backups by backup groups
 in backup view
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: Wed, 16 Sep 2020 12:51:03 -0000

It was necessary to make the component not stateful, because of an ExtJS bug
where groupFn is not being preserved when the state is restored, see:
https://forum.sencha.com/forum/showthread.php?469145-Uncaught-TypeError-me-_groupFn-is-not-a-function

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

new in v2

Couldn't find a way to make this work with stateful: true...
Not using Ext.create and only passing along the Object with the properties
for the grouper doesn't seem to help either.

 www/manager6/storage/BackupView.js  | 24 ++++++++++++++++++++++--
 www/manager6/storage/ContentView.js |  1 +
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/www/manager6/storage/BackupView.js b/www/manager6/storage/BackupView.js
index 2669d2ca..ad377de6 100644
--- a/www/manager6/storage/BackupView.js
+++ b/www/manager6/storage/BackupView.js
@@ -3,8 +3,12 @@ Ext.define('PVE.storage.BackupView', {
 
     alias: 'widget.pveStorageBackupView',
 
-    stateful: true,
-    stateId: 'grid-storage-content-backup',
+    features: [
+	{
+	    ftype: 'grouping',
+	    groupHeaderTpl: '{name} ({rows.length} Backup{[values.rows.length > 1 ? "s" : ""]})',
+	},
+    ],
 
     initComponent: function() {
 	var me = this;
@@ -69,6 +73,22 @@ Ext.define('PVE.storage.BackupView', {
 	    },
 	];
 
+	me.grouper = Ext.create('Ext.util.Grouper', {
+	    groupFn: function(val) {
+		let name = val.data.text;
+		let vmid = val.data.vmid;
+		if (!vmid) {
+		    return 'other';
+		}
+		if (name.startsWith('vzdump-lxc-')) {
+		    return 'CT/' + vmid;
+		} else if (name.startsWith('vzdump-qemu-')) {
+		    return 'VM/' + vmid;
+		}
+		return 'other';
+	    },
+	});
+
 	me.callParent();
     },
 });
diff --git a/www/manager6/storage/ContentView.js b/www/manager6/storage/ContentView.js
index 0f1bbc0c..e563d3a3 100644
--- a/www/manager6/storage/ContentView.js
+++ b/www/manager6/storage/ContentView.js
@@ -232,6 +232,7 @@ Ext.define('PVE.storage.ContentView', {
 	var baseurl = "/nodes/" + nodename + "/storage/" + storage + "/content";
 	var store = me.store = Ext.create('Ext.data.Store', {
 	    model: 'pve-storage-content',
+	    grouper: me.grouper,
 	    proxy: {
                 type: 'proxmox',
 		url: '/api2/json' + baseurl,
-- 
2.20.1