Merge pull request #307 from KayoticSully/master

GUI will switch between http and https protocols on restart (fixes #252)
This commit is contained in:
Jakob Borg 2014-05-28 20:09:38 +02:00
commit 2e8b639a34
3 changed files with 32 additions and 9 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ stcli.exe
*.sublime*
discosrv
stpidx
.jshintrc

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$scope.myID = '';
$scope.nodes = [];
$scope.configInSync = true;
$scope.protocolChanged = false;
$scope.errors = [];
$scope.seenError = '';
$scope.model = {};
@ -122,7 +123,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
}
return state;
}
};
$scope.repoClass = function (repo) {
if (typeof $scope.model[repo] === 'undefined') {
@ -141,7 +142,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
return 'primary';
}
return 'info';
}
};
$scope.syncPercentage = function (repo) {
if (typeof $scope.model[repo] === 'undefined') {
@ -255,13 +256,19 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$scope.config.workingOptions = angular.copy($scope.config.Options);
$scope.config.workingGUI = angular.copy($scope.config.GUI);
$('#settings').modal({backdrop: 'static', keyboard: true});
}
};
$scope.saveSettings = function () {
// Make sure something changed
var changed = ! angular.equals($scope.config.Options, $scope.config.workingOptions) ||
! angular.equals($scope.config.GUI, $scope.config.workingGUI);
if(changed){
// see if protocol will need to be changed on restart
if($scope.config.GUI.UseTLS !== $scope.config.workingGUI.UseTLS){
$scope.protocolChanged = true;
}
// Apply new settings locally
$scope.config.Options = angular.copy($scope.config.workingOptions);
$scope.config.GUI = angular.copy($scope.config.workingGUI);
@ -278,6 +285,21 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$('#restarting').modal({backdrop: 'static', keyboard: false});
$http.post(urlbase + '/restart');
$scope.configInSync = true;
// Switch webpage protocol if needed
if($scope.protocolChanged){
var protocol = 'http';
if($scope.config.GUI.UseTLS){
protocol = 'https';
}
setTimeout(function(){
window.location.protocol = protocol;
}, 1000);
$scope.protocolChanged = false;
}
};
$scope.shutdown = function () {
@ -402,7 +424,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$scope.repoList = function () {
return repoList($scope.repos);
}
};
$scope.editRepo = function (nodeCfg) {
$scope.currentRepo = angular.copy(nodeCfg);
@ -544,7 +566,7 @@ function repoMap(l) {
function repoList(m) {
var l = [];
for (var id in m) {
l.push(m[id])
l.push(m[id]);
}
l.sort(repoCompare);
return l;
@ -633,7 +655,7 @@ syncthing.filter('chunkID', function () {
if (!parts)
return "";
return parts.join('-');
}
};
});
syncthing.filter('shortPath', function () {
@ -645,13 +667,13 @@ syncthing.filter('shortPath', function () {
return input;
}
return ".../" + parts.slice(parts.length-2).join("/");
}
};
});
syncthing.filter('clean', function () {
return function (input) {
return encodeURIComponent(input).replace(/%/g, '');
}
};
});
syncthing.directive('optionEditor', function () {