Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui, lib/config: Add default path for new folders (fixes #2157) #4192

Closed
wants to merge 11 commits into from
38 changes: 36 additions & 2 deletions gui/default/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,21 @@ angular.module('syncthing.core')
$scope.neededTotal = data.total;
}

function pathJoin(base, name) {
base = expandTilde(base);
if (base[base.length - 1] !== $scope.system.pathSeparator) {
return base + $scope.system.pathSeparator + name;
}
return base + name;
}

function expandTilde(path) {
if (path && path.trim().charAt(0) === '~') {
return $scope.system.tilde + path.trim().substring(1);
}
return path;
}

$scope.neededPageChanged = function (page) {
$scope.neededCurrentPage = page;
refreshNeed($scope.neededFolder);
Expand Down Expand Up @@ -1343,16 +1358,28 @@ angular.module('syncthing.core')
$scope.directoryList = [];

$scope.$watch('currentFolder.path', function (newvalue) {
if (newvalue && newvalue.trim().charAt(0) === '~') {
$scope.currentFolder.path = $scope.system.tilde + newvalue.trim().substring(1);
if (!newvalue) {
return;
}
$scope.currentFolder.path = expandTilde(newvalue);
$http.get(urlbase + '/system/browse', {
params: { current: newvalue }
}).success(function (data) {
$scope.directoryList = data;
}).error($scope.emitHTTPError);
});

$scope.$watchGroup(['currentFolder.label', 'currentFolder.id'], function (newValues) {
if (!$scope.config.options || !$scope.config.options.defaultFolderPath || !$scope.folderEditor.folderPath.$pristine) {
return;
}
if (newValues[0]) {
$scope.currentFolder.path = pathJoin($scope.config.options.defaultFolderPath, newValues[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified using the or statement rather than branches.

return;
}
$scope.currentFolder.path = pathJoin($scope.config.options.defaultFolderPath, newValues[1]);
});

$scope.loadFormIntoScope = function (form) {
console.log('loadFormIntoScope',form.$name);
switch (form.$name) {
Expand All @@ -1370,6 +1397,13 @@ angular.module('syncthing.core')
};

$scope.editFolderModal = function () {
if (!$scope.editingExisting) {
if ($scope.config.options.defaultFolderPath) {
$scope.currentFolder.path = pathJoin($scope.config.options.defaultFolderPath, $scope.currentFolder.id);
} else {
$scope.currentFolder.path = "";
}
}
$scope.folderPathErrors = {};
$scope.folderEditor.$setPristine();
$('#editIgnores textarea').val("");
Expand Down
4 changes: 2 additions & 2 deletions gui/default/vendor/angular/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The files contained herein are:

- angular 1.2.9
- angular 1.3.0
- angular-translate 2.9.0.1
- angular-translate-loader-static-files 2.11.0
- angular-dirPagination 759009c
- angular-dirPagination 759009c
Loading