From 73e2e2a79452db005bfe318a7a997556cc49228a Mon Sep 17 00:00:00 2001 From: tomasz1986 Date: Fri, 28 Jan 2022 09:15:56 +0100 Subject: [PATCH] gui: Make device ID read-only and hide "nearby devices" when adding a new pending device (fixes #8083) (#8091) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gui: Make ID read-only and hide nearby devices when adding pending devices (fixes #8083) Currently, there is no distinction between adding "new" and "pending" devices. For this reason, the user is always presented with a list of "nearby devices" to choose from. This commit adds such distinction to the code, and in the case of "pending" device, both the device ID is made read-only and the nearby devices list is hidden. As a by-product of the function rename and clean-up, this commit also hides the non-functional "remove" button that is shown when editing device defaults. Signed-off-by: Tomasz WilczyƄski --- .../syncthing/core/syncthingController.js | 11 ++++++- .../syncthing/core/validDeviceidDirective.js | 25 ++++++--------- .../syncthing/device/editDeviceModalView.html | 31 +++++++------------ 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index ff4143fca..bc045e56f 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -1614,6 +1614,11 @@ angular.module('syncthing.core') return $scope.currentDevice._editing == 'existing'; } + $scope.editingDeviceNew = function() { + // The "new-pending" value is intentionally disregarded here. + return $scope.currentDevice._editing == 'new'; + } + $scope.editDeviceExisting = function (deviceCfg) { $scope.currentDevice = $.extend({}, deviceCfg); $scope.currentDevice._editing = "existing"; @@ -1683,7 +1688,11 @@ angular.module('syncthing.core') $scope.currentDevice = p.data; $scope.currentDevice.name = name; $scope.currentDevice.deviceID = deviceID; - $scope.currentDevice._editing = "add"; + if (deviceID) { + $scope.currentDevice._editing = "new-pending"; + } else { + $scope.currentDevice._editing = "new"; + } initShareEditing('device'); $scope.currentSharing.unrelated = $scope.folderList(); editDeviceModal(); diff --git a/gui/default/syncthing/core/validDeviceidDirective.js b/gui/default/syncthing/core/validDeviceidDirective.js index 8c0456488..0a84ffe06 100644 --- a/gui/default/syncthing/core/validDeviceidDirective.js +++ b/gui/default/syncthing/core/validDeviceidDirective.js @@ -4,23 +4,18 @@ angular.module('syncthing.core') require: 'ngModel', link: function (scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function (viewValue) { - if (scope.currentDevice._editing != "add") { - // we shouldn't validate - ctrl.$setValidity('validDeviceid', true); - } else { - $http.get(urlbase + '/svc/deviceid?id=' + viewValue).success(function (resp) { - if (resp.error) { - ctrl.$setValidity('validDeviceid', false); - } else { - ctrl.$setValidity('validDeviceid', true); - } - }); - //Prevents user from adding a duplicate ID - if (scope.devices.hasOwnProperty(viewValue)) { - ctrl.$setValidity('unique', false); + $http.get(urlbase + '/svc/deviceid?id=' + viewValue).success(function (resp) { + if (resp.error) { + ctrl.$setValidity('validDeviceid', false); } else { - ctrl.$setValidity('unique', true); + ctrl.$setValidity('validDeviceid', true); } + }); + //Prevents user from adding a duplicate ID + if (scope.devices.hasOwnProperty(viewValue)) { + ctrl.$setValidity('unique', false); + } else { + ctrl.$setValidity('unique', true); } return viewValue; }); diff --git a/gui/default/syncthing/device/editDeviceModalView.html b/gui/default/syncthing/device/editDeviceModalView.html index 6ae453821..4a0cb9da6 100644 --- a/gui/default/syncthing/device/editDeviceModalView.html +++ b/gui/default/syncthing/device/editDeviceModalView.html @@ -10,19 +10,20 @@
-
-
- -
- -
+
+ +
{{currentDevice.deviceID}}
+
+
+
+
-

+

You can also select one of these nearby devices:
  • @@ -31,7 +32,7 @@
-

+

The device ID to enter here can be found in the "Actions > Show ID" dialog on the other device. Spaces and dashes are optional (ignored). When adding a new device, keep in mind that this device must be added on the other side too. @@ -40,14 +41,6 @@ A device with that ID is already added.

-
-
{{currentDevice.deviceID}}
-
- -
-
@@ -172,7 +165,7 @@ -
+