public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] ui: add support for notes on backup groups
Date: Thu,  8 Jul 2021 16:45:28 +0200	[thread overview]
Message-ID: <20210708144528.1405534-2-s.reiter@proxmox.com> (raw)
In-Reply-To: <20210708144528.1405534-1-s.reiter@proxmox.com>

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 | 59 ++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/www/datastore/Content.js b/www/datastore/Content.js
index 101763aa..29d58fc3 100644
--- a/www/datastore/Content.js
+++ b/www/datastore/Content.js
@@ -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');
 		},
 	    },
 	},
-- 
2.30.2





  reply	other threads:[~2021-07-08 14:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 14:45 [pbs-devel] [PATCH proxmox-backup 1/2] api: " Stefan Reiter
2021-07-08 14:45 ` Stefan Reiter [this message]
2021-07-12  6:32   ` [pbs-devel] [PATCH proxmox-backup 2/2] ui: " Thomas Lamprecht
2021-07-12  6:30 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] api: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210708144528.1405534-2-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal