]> git.proxmox.com Git - proxmox-backup.git/commitdiff
ui: add support for notes on backup groups
authorStefan Reiter <s.reiter@proxmox.com>
Thu, 8 Jul 2021 14:45:28 +0000 (16:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 12 Jul 2021 05:13:44 +0000 (07:13 +0200)
Currently done a little bit hacky in a seperate API call following the
initial list_snapshots, as we previously didn't call list_groups at all
and instead calculated the groups from the snapshots.

This calls it async and updates the view with group comments when data
arrives. The editor is simply reused with the 'group-notes' API call,
since the semantics are the same.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
www/datastore/Content.js

index 101763aa4c6d5baa54ca3c4711fb1224c1d76811..29d58fc322cbe5b2c08fd863b24f1f61bc3b82f6 100644 (file)
@@ -125,6 +125,29 @@ Ext.define('PBS.DataStoreContent', {
            return groups;
        },
 
+       updateGroupNotes: function(view) {
+           Proxmox.Utils.API2Request({
+               url: `/api2/extjs/admin/datastore/${view.datastore}/groups`,
+               method: 'GET',
+               success: function(response) {
+                   let groups = response.result.data;
+                   let map = {};
+                   for (const group of groups) {
+                       map[`${group["backup-type"]}/${group["backup-id"]}`] = group["comment"];
+                   }
+                   view.getRootNode().cascade(node => {
+                       if (node.parentNode && node.parentNode.id === 'root') {
+                           node.set(
+                               'comment',
+                               map[`${node.data.backup_type}/${node.data.backup_id}`],
+                               { dirty: false },
+                           );
+                       }
+                   });
+               },
+           });
+       },
+
        onLoad: function(store, records, success, operation) {
            let me = this;
            let view = this.getView();
@@ -242,6 +265,8 @@ Ext.define('PBS.DataStoreContent', {
                children: children,
            });
 
+           this.updateGroupNotes(view);
+
            if (selected !== undefined) {
                let selection = view.getRootNode().findChildBy(function(item) {
                    let id = item.data.text;
@@ -358,19 +383,31 @@ Ext.define('PBS.DataStoreContent', {
            });
        },
 
-       onNotesEdit: function(view, data) {
+       onNotesEdit: function(view, data, isGroup) {
            let me = this;
 
-           let url = `/admin/datastore/${view.datastore}/notes`;
+           let url = `/admin/datastore/${view.datastore}/`;
+           url += isGroup ? 'group-notes' : 'notes';
+
+           let params;
+           if (isGroup) {
+               params = {
+                   "backup-type": data.backup_type,
+                   "backup-id": data.backup_id,
+               };
+           } else {
+               params = {
+                   "backup-type": data["backup-type"],
+                   "backup-id": data["backup-id"],
+                   "backup-time": (data['backup-time'].getTime()/1000).toFixed(0),
+               };
+           }
+
            Ext.create('PBS.window.NotesEdit', {
                url: url,
                autoShow: true,
                apiCallDone: () => me.reload(), // FIXME: do something more efficient?
-               extraRequestParams: {
-                   "backup-type": data["backup-type"],
-                   "backup-id": data["backup-id"],
-                   "backup-time": (data['backup-time'].getTime()/1000).toFixed(0),
-               },
+               extraRequestParams: params,
            });
        },
 
@@ -585,7 +622,7 @@ Ext.define('PBS.DataStoreContent', {
            flex: 1,
            renderer: (v, meta, record) => {
                let data = record.data;
-               if (!data || data.leaf || record.parentNode.id === 'root') {
+               if (!data || data.leaf) {
                    return '';
                }
                if (v === undefined || v === null) {
@@ -608,17 +645,17 @@ Ext.define('PBS.DataStoreContent', {
                        }
                        let view = tree.up();
                        let controller = view.controller;
-                       controller.onNotesEdit(view, rec.data);
+                       controller.onNotesEdit(view, rec.data, rec.parentNode.id === 'root');
                    });
                },
                dblclick: function(tree, el, row, col, ev, rec) {
                    let data = rec.data || {};
-                   if (data.leaf || rec.parentNode.id === 'root') {
+                   if (data.leaf) {
                        return;
                    }
                    let view = tree.up();
                    let controller = view.controller;
-                   controller.onNotesEdit(view, rec.data);
+                   controller.onNotesEdit(view, rec.data, rec.parentNode.id === 'root');
                },
            },
        },