From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 5CCDD1FF2A0
	for <inbox@lore.proxmox.com>; Mon, 15 Jul 2024 12:16:53 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B50C41A9;
	Mon, 15 Jul 2024 12:17:19 +0200 (CEST)
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Mon, 15 Jul 2024 12:16:02 +0200
Message-Id: <20240715101602.274244-25-c.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20240715101602.274244-1-c.ebner@proxmox.com>
References: <20240715101602.274244-1-c.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.021 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [RFC proxmox-backup 24/24] www: sync edit: allow to set
 sync direction for sync jobs
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

Adds a radio button which allows to set the sync direction when
creating/editing a sync job.

Forces to provide a remote in case of push direction and switch
fetching of the groups for selection in filters from remote to
local.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 www/window/SyncJobEdit.js | 60 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/www/window/SyncJobEdit.js b/www/window/SyncJobEdit.js
index 6543995e8..6b291cdb4 100644
--- a/www/window/SyncJobEdit.js
+++ b/www/window/SyncJobEdit.js
@@ -144,6 +144,57 @@ Ext.define('PBS.window.SyncJobEdit', {
 			submitAutoScaledSizeUnit: true,
 			// NOTE: handle deleteEmpty in onGetValues due to bandwidth field having a cbind too
 		    },
+		    {
+			xtype: 'radiogroup',
+			fieldLabel: gettext('Sync Direction'),
+			defaultType: 'radiofield',
+			items: [
+			    {
+				boxLabel: 'Pull',
+				name: 'sync-direction',
+				inputValue: 'pull',
+				checked: true,
+			    },
+			    {
+				boxLabel: 'Push',
+				name: 'sync-direction',
+				inputValue: 'push',
+			    },
+			],
+			listeners: {
+			    change: function(_group, radio) {
+				let me = this;
+				let form = me.up('pbsSyncJobEdit');
+				let remoteField = form.down('field[name=remote]');
+				let remoteNsField = form.down('field[name=remote-ns]');
+				let remoteStoreField = form.down('field[name=remote-store]');
+				let locationField = form.down('field[name=location]');
+				let groupFilter = form.down('pbsGroupFilter');
+
+				let isSyncDirectionPull = radio['sync-direction'] === 'pull';
+				locationField.setDisabled(!isSyncDirectionPull);
+
+				if (isSyncDirectionPull) {
+				    remoteField.setFieldLabel(gettext("Source Remote"));
+				    remoteNsField.setFieldLabel(gettext("Source Namespace"));
+				    remoteStoreField.setFieldLabel(gettext("Source Store"));
+				    let remote = remoteField.getValue();
+				    let remoteStore = remoteStoreField.getValue();
+				    let remoteNs = remoteNsField.getValue();
+				    groupFilter.setRemoteNamespace(remote, remoteStore, remoteNs);
+				} else {
+				    remoteField.setDisabled(false);
+				    remoteField.setFieldLabel(gettext("Target Remote"));
+				    remoteNsField.setFieldLabel(gettext("Target Namespace"));
+				    remoteStoreField.setFieldLabel(gettext("Target Store"));
+				    locationField.setValue("remote");
+				    let localStore = form.down('field[name=store]').getValue();
+				    let localNamespace = form.down('field[name=ns]').getValue();
+				    groupFilter.setLocalNamespace(localStore, localNamespace);
+				}
+			    },
+			},
+		    },
 		],
 
 		column2: [
@@ -238,7 +289,14 @@ Ext.define('PBS.window.SyncJobEdit', {
 				let remoteNamespaceField = me.up('pbsSyncJobEdit').down('field[name=remote-ns]');
 				remoteNamespaceField.setRemote(remote);
 				remoteNamespaceField.setRemoteStore(value);
-				me.up('tabpanel').down('pbsGroupFilter').setRemoteDatastore(remote, value);
+
+				let syncDirection = me.up('pbsSyncJobEdit').down('field[name=sync-direction]').getValue();
+				if (syncDirection === 'pull') {
+				    me.up('tabpanel').down('pbsGroupFilter').setRemoteDatastore(remote, value);
+				} else {
+				    let localStore = me.up('pbsSyncJobEdit').down('field[name=store]').getValue();
+				    me.up('tabpanel').down('pbsGroupFilter').setLocalDatastore(localStore);
+				}
 			    },
 			},
 		    },
-- 
2.39.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel