[pve-devel] [PATCH manager v3] ui: dc/Auth: add sync button
Dominik Csapak
d.csapak at proxmox.com
Wed Apr 29 14:32:35 CEST 2020
opens a window with the parameters for the sync and two buttons:
'preview' and 'sync'
both open the taskviewer, but the 'preview' one sets the 'dry-run'
parameter so that it does not get written out to the user.cfg
loads the realm config and prefills the selection with values from
the config, and shows a hint about where to set the defaults
if none are set
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v2:
* drop the '(from Config)' and '(Default)' options
* show a hint about where to set default options
* show window after closing the task of a preview
www/manager6/Makefile | 1 +
www/manager6/dc/AuthView.js | 21 ++++
www/manager6/dc/SyncWindow.js | 186 ++++++++++++++++++++++++++++++++++
3 files changed, 208 insertions(+)
create mode 100644 www/manager6/dc/SyncWindow.js
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 057a4211..ff93b224 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -232,6 +232,7 @@ JSSRC= \
dc/RoleView.js \
dc/RoleEdit.js \
dc/ACLView.js \
+ dc/SyncWindow.js \
dc/AuthView.js \
dc/AuthEditBase.js \
dc/AuthEditAD.js \
diff --git a/www/manager6/dc/AuthView.js b/www/manager6/dc/AuthView.js
index a2486fef..3e5a8517 100644
--- a/www/manager6/dc/AuthView.js
+++ b/www/manager6/dc/AuthView.js
@@ -73,6 +73,19 @@ Ext.define('PVE.dc.AuthView', {
me.openEditWindow(rec.data.type, rec.data.realm);
},
+ open_sync_window: function() {
+ let me = this;
+ let rec = me.getSelection()[0];
+ if (!rec) {
+ return;
+ }
+ Ext.create('PVE.dc.SyncWindow', {
+ realm: rec.data.realm,
+ listeners: {
+ destroy: () => me.reload(),
+ },
+ }).show();
+ },
initComponent: function() {
var me = this;
@@ -107,6 +120,14 @@ Ext.define('PVE.dc.AuthView', {
enableFn: (rec) => PVE.Utils.authSchema[rec.data.type].add,
callback: () => me.reload(),
},
+ '-',
+ {
+ xtype: 'proxmoxButton',
+ text: gettext('Sync'),
+ disabled: true,
+ enableFn: (rec) => Boolean(PVE.Utils.authSchema[rec.data.type].syncipanel),
+ handler: () => me.open_sync_window(),
+ },
],
listeners: {
activate: () => me.reload(),
diff --git a/www/manager6/dc/SyncWindow.js b/www/manager6/dc/SyncWindow.js
new file mode 100644
index 00000000..351a3f0f
--- /dev/null
+++ b/www/manager6/dc/SyncWindow.js
@@ -0,0 +1,186 @@
+Ext.define('PVE.dc.SyncWindow', {
+ extend: 'Ext.window.Window',
+
+ title: gettext('Realm Sync'),
+
+ width: 600,
+ bodyPadding: 10,
+ modal: true,
+ resizable: false,
+
+ controller: {
+ xclass: 'Ext.app.ViewController',
+
+ control: {
+ 'form': {
+ validitychange: function(field, valid) {
+ let me = this;
+ me.lookup('preview_btn').setDisabled(!valid);
+ me.lookup('sync_btn').setDisabled(!valid);
+ },
+ },
+ 'button': {
+ click: function(btn) {
+ this.sync_realm(btn.reference === 'preview_btn');
+ },
+ },
+ },
+
+ sync_realm: function(is_preview) {
+ let me = this;
+ let view = me.getView();
+ let ipanel = me.lookup('ipanel');
+ let params = ipanel.getValues();
+ params['dry-run'] = is_preview ? 1 : 0;
+ Proxmox.Utils.API2Request({
+ url: `/access/domains/${view.realm}/sync`,
+ waitMsgTarget: view,
+ method: 'POST',
+ params,
+ failure: function(response) {
+ view.show();
+ Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+ },
+ success: function(response) {
+ view.hide();
+ Ext.create('Proxmox.window.TaskViewer', {
+ upid: response.result.data,
+ listeners: {
+ destroy: function() {
+ if (is_preview) {
+ view.show();
+ } else {
+ view.close();
+ }
+ },
+ },
+ }).show();
+ },
+ });
+ },
+ },
+
+ items: [
+ {
+ xtype: 'form',
+ reference: 'form',
+ border: false,
+ fieldDefaults: {
+ labelWidth: 100,
+ anchor: '100%',
+ },
+ items: [{
+ xtype: 'inputpanel',
+ reference: 'ipanel',
+ column1: [
+ {
+ xtype: 'proxmoxKVComboBox',
+ name: 'scope',
+ fieldLabel: gettext('Scope'),
+ value: '',
+ deleteEmpty: false,
+ allowBlank: false,
+ comboItems: [
+ ['users', gettext('Users')],
+ ['groups', gettext('Groups')],
+ ['both', gettext('Users and Groups')],
+ ],
+ },
+ {
+ xtype: 'proxmoxKVComboBox',
+ value: '',
+ deleteEmpty: false,
+ allowBlank: false,
+ comboItems: [
+ ['1', Proxmox.Utils.yesText],
+ ['0', Proxmox.Utils.noText],
+ ],
+ name: 'full',
+ fieldLabel: gettext('Full'),
+ },
+ ],
+
+ column2: [
+ {
+ xtype: 'proxmoxKVComboBox',
+ value: '1',
+ deleteEmpty: false,
+ allowBlank: false,
+ comboItems: [
+ ['1', Proxmox.Utils.yesText],
+ ['0', Proxmox.Utils.noText],
+ ],
+ name: 'enable-new',
+ fieldLabel: gettext('Enable new'),
+ },
+ {
+ xtype: 'proxmoxKVComboBox',
+ value: '',
+ deleteEmpty: false,
+ allowBlank: false,
+ comboItems: [
+ ['1', Proxmox.Utils.yesText],
+ ['0', Proxmox.Utils.noText],
+ ],
+ name: 'purge',
+ fieldLabel: gettext('Purge'),
+ },
+ ],
+
+ columnB: [
+ {
+ xtype: 'displayfield',
+ reference: 'defaulthint',
+ value: gettext('Default sync options can be set by editing the realm.'),
+ userCls: 'pmx-hint',
+ hidden: true
+ },
+ ],
+ }],
+ },
+ ],
+
+ buttons: [
+ {
+ text: gettext('Preview'),
+ reference: 'preview_btn',
+ },
+ {
+ text: gettext('Sync'),
+ reference: 'sync_btn',
+ },
+ ],
+
+ initComponent: function() {
+ let me = this;
+
+ if (!me.realm) {
+ throw "no realm defined";
+ }
+
+ me.callParent();
+
+ Proxmox.Utils.API2Request({
+ url: `/access/domains/${me.realm}`,
+ waitMsgTarget: me,
+ method: 'GET',
+ failure: function(response) {
+ Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+ me.close();
+ },
+ success: function(response) {
+ let default_options = response.result.data['sync-defaults-options'];
+ if (default_options) {
+ let options = PVE.Parser.parsePropertyString(default_options);
+ let ipanel = me.lookup('ipanel');
+ ipanel.setValues(options);
+ } else {
+ me.lookup('defaulthint').setVisible(true);
+ }
+
+ // check validity for button state
+ me.lookup('form').isValid();
+ },
+ });
+ },
+});
--
2.20.1
More information about the pve-devel
mailing list