From c9725bb829dfedfdf179babb033f256fee9e5536 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 28 Oct 2020 18:25:47 +0100 Subject: [PATCH] ui: datastore: show comment, allow to edit notes the "comment" is the first line of the "notes" field from a manifest, show it in the grid and allow editing the full notes. Hack the click event listener a bit together for the right aligned edit action button, but it works out well and is efficient (only one event listener is much cheaper than per-buttons ones). Signed-off-by: Thomas Lamprecht --- www/DataStoreContent.js | 60 +++++++++++++++++++++++++++++++++++++++++ www/Makefile | 15 ++++++----- www/css/ext6-pbs.css | 7 +++++ www/window/NotesEdit.js | 38 ++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 www/window/NotesEdit.js diff --git a/www/DataStoreContent.js b/www/DataStoreContent.js index 7b4e9eae..9da18845 100644 --- a/www/DataStoreContent.js +++ b/www/DataStoreContent.js @@ -8,6 +8,7 @@ Ext.define('pbs-data-store-snapshots', { type: 'date', dateFormat: 'timestamp', }, + 'comment', 'files', 'owner', 'verification', @@ -342,6 +343,22 @@ Ext.define('PBS.DataStoreContent', { }); }, + onNotesEdit: function(view, data) { + let me = this; + + let url = `/admin/datastore/${view.datastore}/notes`; + 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), + }, + }); + }, + onForget: function(view, rI, cI, item, e, rec) { let me = this; view = this.getView(); @@ -512,6 +529,49 @@ Ext.define('PBS.DataStoreContent', { dataIndex: 'text', flex: 1, }, + { + text: gettext('Comment'), + dataIndex: 'comment', + flex: 1, + renderer: (v, meta, record) => { + let data = record.data; + if (!data || data.leaf || record.parentNode.id === 'root') { + return ''; + } + if (v === undefined || v === null) { + v = ''; + } + v = Ext.String.htmlEncode(v); + let icon = 'fa fa-fw fa-pencil'; + + return `${v} + `; + }, + listeners: { + afterrender: function(component) { + // a bit of a hack, but relatively easy, cheap and works out well. + // more efficient to use one handler for the whole column than for each icon + component.on('click', function(tree, cell, rowI, colI, e, rec) { + let el = e.target; + if (el.tagName !== "I" || !el.classList.contains("fa-pencil")) { + return; + } + let view = tree.up(); + let controller = view.controller; + controller.onNotesEdit(view, rec.data); + }); + }, + dblclick: function(tree, el, row, col, ev, rec) { + let data = rec.data || {}; + if (data.leaf || rec.parentNode.id === 'root') { + return; + } + let view = tree.up(); + let controller = view.controller; + controller.onNotesEdit(view, rec.data); + }, + }, + }, { header: gettext('Actions'), xtype: 'actioncolumn', diff --git a/www/Makefile b/www/Makefile index 75d389d9..cba8bed5 100644 --- a/www/Makefile +++ b/www/Makefile @@ -17,17 +17,18 @@ JSSRC= \ config/ACLView.js \ config/SyncView.js \ config/VerifyView.js \ + window/ACLEdit.js \ + window/BackupFileDownloader.js \ + window/CreateDirectory.js \ + window/DataStoreEdit.js \ + window/FileBrowser.js \ + window/NotesEdit.js \ + window/RemoteEdit.js \ + window/SyncJobEdit.js \ window/UserEdit.js \ window/UserPassword.js \ window/VerifyJobEdit.js \ - window/RemoteEdit.js \ - window/SyncJobEdit.js \ - window/ACLEdit.js \ - window/DataStoreEdit.js \ - window/CreateDirectory.js \ window/ZFSCreate.js \ - window/FileBrowser.js \ - window/BackupFileDownloader.js \ dashboard/DataStoreStatistics.js \ dashboard/LongestTasks.js \ dashboard/RunningTasks.js \ diff --git a/www/css/ext6-pbs.css b/www/css/ext6-pbs.css index d81d6619..6325c076 100644 --- a/www/css/ext6-pbs.css +++ b/www/css/ext6-pbs.css @@ -213,6 +213,13 @@ p.logs { cursor: default; } +span.snapshot-comment-column { + text-overflow: ellipsis; + overflow: hidden; + display: inline-block; + width: calc(100% - 18px); +} + .x-action-col-icon.good:before { color: #21BF4B; } diff --git a/www/window/NotesEdit.js b/www/window/NotesEdit.js new file mode 100644 index 00000000..47a63d9e --- /dev/null +++ b/www/window/NotesEdit.js @@ -0,0 +1,38 @@ +Ext.define('PBS.window.NotesEdit', { + extend: 'Proxmox.window.Edit', + mixins: ['Proxmox.Mixin.CBind'], + + title: gettext('Notes'), + + width: 600, + height: '400px', + resizable: true, + layout: 'fit', + + autoLoad: true, + + defaultButton: undefined, + + notesFieldName: 'notes', + + setValues: function(values) { + let me = this; + if (typeof values === "string") { + let v = values; + values = {}; + values[me.notesFieldName] = v; + } + me.callParent([values]); + }, + + items: { + xtype: 'textarea', + name: 'notes', + cbind: { + name: '{notesFieldName}', + }, + height: '100%', + value: '', + hideLabel: true, + }, +}); -- 2.39.2