Skip to content

Commit

Permalink
gui, lib/config: Add default path for new folders (fixes #2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
imsodin committed Jun 3, 2017
1 parent 3f1fa04 commit 303ffda
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
39 changes: 36 additions & 3 deletions gui/default/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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 @@ -1340,16 +1355,27 @@ 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);
}
$scope.currentFolder.path = expandTilde(newvalue);
$http.get(urlbase + '/system/browse', {
params: { current: newvalue }
}).success(function (data) {
$scope.directoryList = data;
}).error($scope.emitHTTPError);
});

$scope.$watch('currentFolder.label', function (newvalue) {
if (!$scope.config.options || $scope.currentFolder.path) {
return;
}
var path = $scope.config.options.defaultFolderPath;
if (newvalue) {
path = pathJoin(path, newvalue);
} else {
path = pathJoin(path, $scope.currentFolder.id);
}
document.getElementById('folderPath').value = path;
});

$scope.loadFormIntoScope = function (form) {
console.log('loadFormIntoScope',form.$name);
switch (form.$name) {
Expand Down Expand Up @@ -1423,6 +1449,9 @@ angular.module('syncthing.core')
$scope.folderEditor.$setPristine();
$http.get(urlbase + '/svc/random/string?length=10').success(function (data) {
$scope.currentFolder.id = (data.random.substr(0, 5) + '-' + data.random.substr(5, 5)).toLowerCase();
if ($scope.config.options.defaultFolderPath) {
document.getElementById('folderPath').value = pathJoin($scope.config.options.defaultFolderPath, $scope.currentFolder.id);
}
$('#editFolder').modal();
});
};
Expand All @@ -1437,6 +1466,9 @@ angular.module('syncthing.core')
};
$scope.currentFolder.selectedDevices[device] = true;

if ($scope.config.options.defaultFolderPath) {
document.getElementById('folderPath').value = pathJoin($scope.config.options.defaultFolderPath, folderLabel);
}
$scope.editingExisting = false;
$scope.folderPathErrors = {};
$scope.folderEditor.$setPristine();
Expand Down Expand Up @@ -1807,4 +1839,5 @@ angular.module('syncthing.core')
window.localStorage["metricRates"] = $scope.metricRates;
} catch (exception) { }
}

});
2 changes: 1 addition & 1 deletion gui/default/syncthing/folder/editFolderModalView.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div class="form-group" ng-class="{'has-error': folderEditor.folderPath.$invalid && folderEditor.folderPath.$dirty}">
<label translate for="folderPath">Folder Path</label>
<input name="folderPath" ng-readonly="editingExisting" id="folderPath" class="form-control" type="text" ng-model="currentFolder.path" list="directory-list" required path-is-sub-dir/>
<input name="folderPath" ng-readonly="editingExisting" id="folderPath" class="form-control" type="text" ng-model="currentFolder.path" list="directory-list" ng-value="config.options.defaultFolderPath" required path-is-sub-dir/>
<datalist id="directory-list">
<option ng-repeat="directory in directoryList" value="{{ directory }}" />
</datalist>
Expand Down
1 change: 1 addition & 0 deletions lib/config/optionsconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type OptionsConfiguration struct {
KCPCongestionControl bool `xml:"kcpCongestionControl" json:"kcpCongestionControl" default:"true"`
KCPSendWindowSize int `xml:"kcpSendWindowSize" json:"kcpSendWindowSize" default:"128"`
KCPReceiveWindowSize int `xml:"kcpReceiveWindowSize" json:"kcpReceiveWindowSize" default:"128"`
DefaultFolderPath string `xml:"defaultFolderPath" json:"defaultFolderPath" default:""`

DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
Expand Down

0 comments on commit 303ffda

Please sign in to comment.