From 6094b957848aa65627722749e36b336c0a5f6d13 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sun, 30 Jan 2022 17:43:39 +0100 Subject: [PATCH] gui: Fix and align folder editing states (fixes #8145) (#8147) --- .../syncthing/core/syncthingController.js | 20 ++++++++++++------- .../syncthing/core/uniqueFolderDirective.js | 2 +- .../syncthing/folder/editFolderModalView.html | 14 ++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 44e912f7f..65b0c05d7 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -754,7 +754,7 @@ angular.module('syncthing.core') } function shouldSetDefaultFolderPath() { - return $scope.config.defaults.folder.path && $scope.folderEditor.folderPath.$pristine && $scope.currentFolder._editing == "add"; + return $scope.config.defaults.folder.path && $scope.folderEditor.folderPath.$pristine && $scope.editingFolderNew(); } function resetRemoteNeed() { @@ -1977,7 +1977,7 @@ angular.module('syncthing.core') }).one('hidden.bs.modal', function () { var p = $q.when(); // If the modal was closed default patterns should still apply - if ($scope.currentFolder._editing == "add-ignores" && !$scope.ignores.saved && $scope.ignores.defaultLines) { + if ($scope.currentFolder._editing == "new-ignores" && !$scope.ignores.saved && $scope.ignores.defaultLines) { p = saveFolderAddIgnores($scope.currentFolder.id, true); } p.then(function () { @@ -1997,10 +1997,11 @@ angular.module('syncthing.core') case "existing": title = $translate.instant("Edit Folder"); break; - case "add": + case "new": + case "new-pending": title = $translate.instant("Add Folder"); break; - case "add-ignores": + case "new-ignores": title = $translate.instant("Set Ignores on Added Folder"); break; } @@ -2025,6 +2026,10 @@ angular.module('syncthing.core') return $scope.currentFolder._editing == 'existing'; } + $scope.editingFolderNew = function() { + return $scope.has(['new', 'new-pending'], currentFolder._editing); + } + function editFolder(initialTab) { if ($scope.currentFolder.path.length > 1 && $scope.currentFolder.path.slice(-1) === $scope.system.pathSeparator) { $scope.currentFolder.path = $scope.currentFolder.path.slice(0, -1); @@ -2153,6 +2158,7 @@ angular.module('syncthing.core') var folderID = (data.random.substr(0, 5) + '-' + data.random.substr(5, 5)).toLowerCase(); addFolderInit(folderID).then(function() { // Triggers the watch that sets the path + $scope.currentFolder._editing = "new"; $scope.currentFolder.label = $scope.currentFolder.label; editFolderModal(); }); @@ -2170,6 +2176,7 @@ angular.module('syncthing.core') break; } } + $scope.currentFolder._editing = "new-pending"; editFolderModal(); }); }; @@ -2177,7 +2184,6 @@ angular.module('syncthing.core') function addFolderInit(folderID) { return $http.get(urlbase + '/config/defaults/folder').then(function (response) { $scope.currentFolder = response.data; - $scope.currentFolder._editing = "add"; $scope.currentFolder.id = folderID; initShareEditing('folder'); $scope.currentSharing.unrelated = $scope.currentSharing.unrelated.concat($scope.currentSharing.shared); @@ -2204,7 +2210,7 @@ angular.module('syncthing.core') }; $scope.saveFolder = function () { - if ($scope.currentFolder._editing == "add-ignores") { + if ($scope.currentFolder._editing == "new-ignores") { // On modal being hidden without clicking save, the defaults will be saved. $scope.ignores.saved = true; saveFolderAddIgnores($scope.currentFolder.id); @@ -2293,7 +2299,7 @@ angular.module('syncthing.core') // load default ignores, then let the user edit them. $scope.saveConfig().then(function() { editFolderLoadingIgnores(); - $scope.currentFolder._editing = "add-ignores"; + $scope.currentFolder._editing = "new-ignores"; $('.nav-tabs a[href="#folder-ignores"]').tab('show'); return editFolderGetIgnores(); }).then(function(data) { diff --git a/gui/default/syncthing/core/uniqueFolderDirective.js b/gui/default/syncthing/core/uniqueFolderDirective.js index 240bd3707..d8e9f8bd2 100644 --- a/gui/default/syncthing/core/uniqueFolderDirective.js +++ b/gui/default/syncthing/core/uniqueFolderDirective.js @@ -4,7 +4,7 @@ angular.module('syncthing.core') require: 'ngModel', link: function (scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function (viewValue) { - if (scope.currentFolder._editing != "add") { + if (scope.currentFolder._editing != "new") { // we shouldn't validate ctrl.$setValidity('uniqueFolder', true); } else if (scope.folders.hasOwnProperty(viewValue)) { diff --git a/gui/default/syncthing/folder/editFolderModalView.html b/gui/default/syncthing/folder/editFolderModalView.html index cce101696..c716acf0b 100644 --- a/gui/default/syncthing/folder/editFolderModalView.html +++ b/gui/default/syncthing/folder/editFolderModalView.html @@ -2,11 +2,11 @@ -
-
+
+