]> git.proxmox.com Git - proxmox-backup.git/commitdiff
ui: DataStoreContent: keep selection and expansion on reload
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 23 Jul 2020 11:03:51 +0000 (13:03 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Jul 2020 10:51:34 +0000 (12:51 +0200)
when clicking reload, we keep the existing selection
(if it still exists), and the previous expanded elements expanded

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
www/DataStoreContent.js

index e32c6160882188c79824fb6507cc73d064466fd8..5f407e98d5145f1748de772532b1551f23bc6b76 100644 (file)
@@ -141,6 +141,30 @@ Ext.define('PBS.DataStoreContent', {
 
            let groups = this.getRecordGroups(records);
 
+           let selected;
+           let expanded = {};
+
+           view.getSelection().some(function(item) {
+               let id = item.data.text;
+               if (item.data.leaf) {
+                   id = item.parentNode.data.text + id;
+               }
+               selected = id;
+               return true;
+           });
+
+           view.getRootNode().cascadeBy({
+               before: item => {
+                   if (item.isExpanded() && !item.data.leaf) {
+                       let id = item.data.text;
+                       expanded[id] = true;
+                       return true;
+                   }
+                   return false;
+               },
+               after: () => {},
+           });
+
            for (const item of records) {
                let group = item.data["backup-type"] + "/" + item.data["backup-id"];
                let children = groups[group].children;
@@ -152,6 +176,8 @@ Ext.define('PBS.DataStoreContent', {
                data.cls = 'no-leaf-icons';
                data.matchesFilter = true;
 
+               data.expanded = !!expanded[data.text];
+
                data.children = [];
                for (const file of data.files) {
                    file.text = file.filename,
@@ -166,7 +192,7 @@ Ext.define('PBS.DataStoreContent', {
            }
 
            let children = [];
-           for (const [_key, group] of Object.entries(groups)) {
+           for (const [name, group] of Object.entries(groups)) {
                let last_backup = 0;
                let crypt = {
                    none: 0,
@@ -189,6 +215,7 @@ Ext.define('PBS.DataStoreContent', {
                group.matchesFilter = true;
                crypt.count = group.count;
                group['crypt-mode'] = PBS.Utils.calculateCryptMode(crypt);
+               group.expanded = !!expanded[name];
                children.push(group);
            }
 
@@ -196,6 +223,19 @@ Ext.define('PBS.DataStoreContent', {
                expanded: true,
                children: children
            });
+
+           if (selected !== undefined) {
+               let selection = view.getRootNode().findChildBy(function(item) {
+                   let id = item.data.text;
+                   if (item.data.leaf) {
+                       id = item.parentNode.data.text + id;
+                   }
+                   return selected === id;
+               }, undefined, true);
+               view.setSelection(selection);
+               view.getView().focusRow(selection);
+           }
+
            Proxmox.Utils.setErrorMask(view, false);
            if (view.getStore().getFilters().length > 0) {
                let searchBox = me.lookup("searchbox");