[pve-devel] [PATCH manager 4/5] ui: dc/Backup: add schedule simulator button

Dominik Csapak d.csapak at proxmox.com
Thu Nov 11 12:07:08 CET 2021


so that a user can simply simulate the schedule

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Makefile                    |   1 +
 www/manager6/dc/Backup.js                |  15 +++
 www/manager6/window/ScheduleSimulator.js | 118 +++++++++++++++++++++++
 3 files changed, 134 insertions(+)
 create mode 100644 www/manager6/window/ScheduleSimulator.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 489233f8..a92651a9 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -111,6 +111,7 @@ JSSRC= 							\
 	window/StartupEdit.js				\
 	window/DownloadUrlToStorage.js 			\
 	window/UploadToStorage.js 			\
+	window/ScheduleSimulator.js			\
 	window/Wizard.js				\
 	ha/Fencing.js					\
 	ha/GroupEdit.js					\
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index c25a127e..31600817 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -701,6 +701,21 @@ Ext.define('PVE.dc.BackupView', {
 		edit_btn,
 		detail_btn,
 		'-',
+		{
+		    xtype: 'proxmoxButton',
+		    selModel: null,
+		    text: gettext('Simulate Schedule'),
+		    handler: () => {
+			let record = sm.getSelection()[0];
+			let schedule;
+			if (record) {
+			    schedule = record.data.schedule;
+			}
+			Ext.create('PVE.window.ScheduleSimulator', {
+			    schedule,
+			}).show();
+		    },
+		},
 		run_btn,
 		'->',
 		noBackupJobWarning,
diff --git a/www/manager6/window/ScheduleSimulator.js b/www/manager6/window/ScheduleSimulator.js
new file mode 100644
index 00000000..14b32100
--- /dev/null
+++ b/www/manager6/window/ScheduleSimulator.js
@@ -0,0 +1,118 @@
+Ext.define('PVE.window.ScheduleSimulator', {
+    extend: 'Ext.window.Window',
+
+    title: gettext('Simulate Schedule'),
+
+    controller: {
+	xclass: 'Ext.app.ViewController',
+	close: function() { this.getView().close(); },
+	simulate: function() {
+	    let me = this;
+	    let schedule = me.lookup('schedule').getValue();
+	    if (!schedule) {
+		return;
+	    }
+	    let number = me.lookup('number').getValue() || 10;
+	    Proxmox.Utils.API2Request({
+		url: '/cluster/jobs/schedule-analyze',
+		method: 'GET',
+		params: {
+		    schedule,
+		    number,
+		},
+		failure: function(response, opts) {
+		    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+		},
+		success: function(response) {
+		    let schedules = response.result.data;
+		    me.lookup('grid').getStore().setData(schedules);
+		},
+	    });
+	},
+
+	scheduleChanged: function(field, value) {
+	    this.lookup('simulateBtn').setDisabled(!value);
+	},
+
+	renderTimestamp: function(value) {
+	    let date = new Date(value*1000);
+	    return date.toLocaleString();
+	},
+
+	init: function(view) {
+	    let me = this;
+	    if (view.schedule) {
+		me.lookup('schedule').setValue(view.schedule);
+	    }
+	},
+    },
+
+    bodyPadding: 10,
+    modal: true,
+    resizable: false,
+    width: 600,
+
+    layout: 'fit',
+
+    items: [
+	{
+	    xtype: 'inputpanel',
+	    column1: [
+		{
+		    xtype: 'pveCalendarEvent',
+		    reference: 'schedule',
+		    fieldLabel: gettext('Schedule'),
+		    listeners: {
+			change: 'scheduleChanged',
+		    },
+		},
+		{
+		    xtype: 'proxmoxintegerfield',
+		    minValue: 1,
+		    maxValue: 100,
+		    value: 10,
+		    reference: 'number',
+		    fieldLabel: gettext('Number'),
+		},
+		{
+		    xtype: 'button',
+		    reference: 'simulateBtn',
+		    text: gettext('Simulate'),
+		    handler: 'simulate',
+		    align: 'right',
+		    disabled: true,
+		},
+	    ],
+
+	    column2: [
+		{
+		    xtype: 'grid',
+		    reference: 'grid',
+		    emptyText: Proxmox.Utils.NoneText,
+		    scrollable: true,
+		    height: 300,
+		    columns: [
+			{
+			    text: gettext('Local Time'),
+			    renderer: 'renderTimestamp',
+			    dataIndex: 'timestamp',
+			    flex: 1,
+			},
+		    ],
+		    store: {
+			fields: ['timestamp'],
+			data: [],
+			sorter: 'timestamp',
+		    },
+		},
+	    ],
+	},
+    ],
+
+    buttons: [
+	{
+	    text: gettext('OK'),
+	    handler: 'close',
+	},
+    ],
+});
-- 
2.30.2






More information about the pve-devel mailing list