[pbs-devel] [PATCH backup] ui: add datastore copy/paste functionality for adding remotes

Oguz Bektas o.bektas at proxmox.com
Mon Dec 14 15:59:27 CET 2020


add "Show Datastore Information" button on datastore summary. when
clicked it shows
- host x509 fingerprint
- hostname
- datastore name
and encodes this info to json base64.

the b64 blob can be then pasted in the "Remotes" menu when adding a
remote. when pasted, it fills the encoded information in the form.

code was largely adapted from the cluster join functionality in PVE.

Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 www/Makefile                      |  2 +
 www/datastore/Summary.js          | 35 +++++++++++-
 www/window/DataStoreRemoteInfo.js | 88 +++++++++++++++++++++++++++++++
 www/window/RemoteEdit.js          | 55 +++++++++++++++++--
 4 files changed, 175 insertions(+), 5 deletions(-)
 create mode 100644 www/window/DataStoreRemoteInfo.js

diff --git a/www/Makefile b/www/Makefile
index ec9f469d..0d65c958 100644
--- a/www/Makefile
+++ b/www/Makefile
@@ -34,6 +34,7 @@ JSSRC=							\
 	window/BackupGroupChangeOwner.js		\
 	window/CreateDirectory.js			\
 	window/DataStoreEdit.js				\
+	window/DataStoreRemoteInfo.js			\
 	window/FileBrowser.js				\
 	window/NotesEdit.js				\
 	window/RemoteEdit.js				\
@@ -66,6 +67,7 @@ JSSRC=							\
 	datastore/Content.js				\
 	datastore/OptionView.js				\
 	datastore/Panel.js				\
+	datastore/Summary.js				\
 	datastore/DataStoreListSummary.js		\
 	datastore/DataStoreList.js			\
 	ServerStatus.js					\
diff --git a/www/datastore/Summary.js b/www/datastore/Summary.js
index 25a7b6e5..ecbba863 100644
--- a/www/datastore/Summary.js
+++ b/www/datastore/Summary.js
@@ -185,7 +185,40 @@ Ext.define('PBS.DataStoreSummary', {
 	padding: 5,
     },
 
-    tbar: ['->', { xtype: 'proxmoxRRDTypeSelector' }],
+    tbar: [
+	{
+	    xtype: 'button',
+	    text: gettext('Show Datastore Information'),
+	    handler: function() {
+		let me = this;
+		let panel = me.up('panel');
+		Proxmox.Utils.API2Request({
+		    url: '/api2/extjs/nodes/localhost/status',
+		    method: 'GET',
+		    waitMsgTarget: panel,
+		    failure: function(e) {
+			console.log(e);
+		    },
+		    success: function(response) {
+			let fingerprint = response.result.data.info.fingerprint;
+			let hostname = window.location.hostname;
+			let datastore = panel.datastore;
+			Ext.create('PBS.DataStoreRemoteInfoWindow', {
+			    remoteInfo: {
+				ipAddress: hostname,
+				fingerprint: fingerprint,
+				datastore: datastore,
+			    },
+			}).show();
+		    },
+		});
+	    },
+	},
+	'->',
+	{
+	    xtype: 'proxmoxRRDTypeSelector',
+	},
+    ],
 
     items: [
 	{
diff --git a/www/window/DataStoreRemoteInfo.js b/www/window/DataStoreRemoteInfo.js
new file mode 100644
index 00000000..df8dd4e8
--- /dev/null
+++ b/www/window/DataStoreRemoteInfo.js
@@ -0,0 +1,88 @@
+Ext.define('PBS.DataStoreRemoteInfoWindow', {
+	extend: 'Ext.window.Window',
+	modal: true,
+	width: 600,
+	title: gettext('Datastore Remote Information'),
+	mixins: ['Proxmox.Mixin.CBind'],
+	remoteInfo: {
+	    ipAddress: undefined,
+	    fingerprint: undefined,
+	    datastore: undefined,
+	},
+	layout: 'form',
+	bodyPadding: '10 0',
+	items: [
+	{
+	    xtype: 'container',
+	    layout: 'form',
+	    border: false,
+	    padding: '0 10 10 10',
+	    items: [
+		{
+		    xtype: 'textfield',
+		    fieldLabel: gettext('x509 Fingerprint'),
+		    inputId: 'fingerprintField',
+		    cbind: {
+			value: '{remoteInfo.fingerprint}',
+		    },
+		    editable: false,
+		},
+		{
+		    xtype: 'textfield',
+		    fieldLabel: gettext('Hostname'),
+		    editable: true,
+		    inputId: 'hostnameField',
+		    cbind: {
+			value: '{remoteInfo.ipAddress}',
+		    },
+		},
+		{
+		    xtype: 'textfield',
+		    fieldLabel: gettext('Datastore Name'),
+		    inputId: 'datastoreField',
+		    cbind: {
+			value: '{remoteInfo.datastore}',
+		    },
+		    editable: false,
+		},
+		{
+		    xtype: 'textarea',
+		    inputId: 'SerializedRemoteInfo',
+		    fieldLabel: gettext('Remote Information'),
+		    grow: true,
+		    editable: false,
+		    cbind: {
+			remoteInfo: '{remoteInfo}',
+		    },
+		    listeners: {
+			afterrender: function(field) {
+			    var jsons = Ext.JSON.encode(field.remoteInfo);
+			    var base64s = Ext.util.Base64.encode(jsons);
+			    field.setValue(base64s)
+			},
+		    },
+		},
+	    ],
+	},
+	],
+	buttons: [
+	    {
+		xtype: 'button',
+		iconCls: 'fa fa-clipboard',
+		handler: function(b) {
+		    var el = document.getElementById('SerializedRemoteInfo');
+		    el.select();
+		    document.execCommand("copy");
+		},
+		text: gettext('Copy'),
+	    },
+	    {
+		text: gettext('Ok'),
+		handler: function() {
+		    this.up('window').close();
+		},
+	    },
+	],
+});
+
+
diff --git a/www/window/RemoteEdit.js b/www/window/RemoteEdit.js
index 4a4d8114..30cffda4 100644
--- a/www/window/RemoteEdit.js
+++ b/www/window/RemoteEdit.js
@@ -11,6 +11,39 @@ Ext.define('PBS.window.RemoteEdit', {
 
     fieldDefaults: { labelWidth: 120 },
 
+    viewModel: {
+	parent: null,
+	data: {
+	    info: {
+		ipAddress: '',
+		fingerprint: '',
+		datastore: '',
+	    },
+	},
+    },
+
+    controller: {
+	xclass: 'Ext.app.ViewController',
+	control: {
+	    'textarea[name=serializedinfo]': {
+		change: 'deserializeInfo',
+	    },
+	},
+        deserializeInfo: function(field, value) {
+	    let vm = this.getViewModel();
+	    let jsons = Ext.util.Base64.decode(value);
+	    let remoteInfo = Ext.JSON.decode(jsons, true);
+
+	    let info = {
+	        ipAddress: remoteInfo.ipAddress,
+	        fingerprint: remoteInfo.fingerprint,
+	        datastore: remoteInfo.datastore,
+	    };
+
+	    vm.set('info', info);
+	},
+    },
+
     cbindData: function(initialConfig) {
 	let me = this;
 
@@ -26,7 +59,7 @@ Ext.define('PBS.window.RemoteEdit', {
 	};
     },
 
-    items: {
+    items: [{
 	xtype: 'inputpanel',
 	column1: [
 	    {
@@ -47,6 +80,9 @@ Ext.define('PBS.window.RemoteEdit', {
 		submitValue: false,
 		vtype: 'HostPort',
 		fieldLabel: gettext('Host'),
+		bind: {
+		    value: '{info.ipAddress}',
+		},
 		listeners: {
 		    change: function(field, newvalue) {
 			let host = newvalue;
@@ -86,7 +122,6 @@ Ext.define('PBS.window.RemoteEdit', {
 		name: 'port',
 	    },
 	],
-
 	column2: [
 	    {
 		xtype: 'proxmoxtextfield',
@@ -105,7 +140,6 @@ Ext.define('PBS.window.RemoteEdit', {
 		},
 	    },
 	],
-
 	columnB: [
 	    {
 		xtype: 'proxmoxtextfield',
@@ -114,6 +148,10 @@ Ext.define('PBS.window.RemoteEdit', {
 		    deleteEmpty: '{!isCreate}',
 		},
 		fieldLabel: gettext('Fingerprint'),
+		bind: {
+		    value: '{info.fingerprint}',
+		},
+
 	    },
 	    {
 		xtype: 'proxmoxtextfield',
@@ -124,7 +162,16 @@ Ext.define('PBS.window.RemoteEdit', {
 		fieldLabel: gettext('Comment'),
 	    },
 	],
-    },
+	},
+	{
+	    xtype: 'textarea',
+	    name: 'serializedinfo',
+	    fieldLabel: gettext('Remote Info Blob'),
+	    submitValue: false,
+	    emptyText: gettext('Paste encoded Remote Information here'),
+	    value: '',
+	},
+    ],
 
     setValues: function(values) {
 	let me = this;
-- 
2.20.1




More information about the pbs-devel mailing list