Resolved issue #252. Page will now refresh the protocol if it is changed

This commit is contained in:
Ryan Sullivan
2014-05-28 11:26:38 -04:00
parent 5369a62fd5
commit 832ed556d9
2 changed files with 31 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/*jslint browser: true, continue: true, plusplus: true */ /*jslint browser: true, continue: true, plusplus: true */
/*global $: false, angular: false */ /*global $: false, angular: false */
'use strict'; 'use-strict';
var syncthing = angular.module('syncthing', []); var syncthing = angular.module('syncthing', []);
var urlbase = 'rest'; var urlbase = 'rest';
@@ -16,6 +16,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$scope.myID = ''; $scope.myID = '';
$scope.nodes = []; $scope.nodes = [];
$scope.configInSync = true; $scope.configInSync = true;
$scope.protocolChanged = false;
$scope.errors = []; $scope.errors = [];
$scope.seenError = ''; $scope.seenError = '';
$scope.model = {}; $scope.model = {};
@@ -122,7 +123,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
} }
return state; return state;
} };
$scope.repoClass = function (repo) { $scope.repoClass = function (repo) {
if (typeof $scope.model[repo] === 'undefined') { if (typeof $scope.model[repo] === 'undefined') {
@@ -141,7 +142,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
return 'primary'; return 'primary';
} }
return 'info'; return 'info';
} };
$scope.syncPercentage = function (repo) { $scope.syncPercentage = function (repo) {
if (typeof $scope.model[repo] === 'undefined') { 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.workingOptions = angular.copy($scope.config.Options);
$scope.config.workingGUI = angular.copy($scope.config.GUI); $scope.config.workingGUI = angular.copy($scope.config.GUI);
$('#settings').modal({backdrop: 'static', keyboard: true}); $('#settings').modal({backdrop: 'static', keyboard: true});
} };
$scope.saveSettings = function () { $scope.saveSettings = function () {
// Make sure something changed // Make sure something changed
var changed = ! angular.equals($scope.config.Options, $scope.config.workingOptions) || var changed = ! angular.equals($scope.config.Options, $scope.config.workingOptions) ||
! angular.equals($scope.config.GUI, $scope.config.workingGUI); ! angular.equals($scope.config.GUI, $scope.config.workingGUI);
if(changed){ 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.Options = angular.copy($scope.config.workingOptions);
$scope.config.GUI = angular.copy($scope.config.workingGUI); $scope.config.GUI = angular.copy($scope.config.workingGUI);
@@ -278,6 +285,19 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$('#restarting').modal({backdrop: 'static', keyboard: false}); $('#restarting').modal({backdrop: 'static', keyboard: false});
$http.post(urlbase + '/restart'); $http.post(urlbase + '/restart');
$scope.configInSync = true; $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.shutdown = function () { $scope.shutdown = function () {
@@ -402,7 +422,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
$scope.repoList = function () { $scope.repoList = function () {
return repoList($scope.repos); return repoList($scope.repos);
} };
$scope.editRepo = function (nodeCfg) { $scope.editRepo = function (nodeCfg) {
$scope.currentRepo = angular.copy(nodeCfg); $scope.currentRepo = angular.copy(nodeCfg);
@@ -544,7 +564,7 @@ function repoMap(l) {
function repoList(m) { function repoList(m) {
var l = []; var l = [];
for (var id in m) { for (var id in m) {
l.push(m[id]) l.push(m[id]);
} }
l.sort(repoCompare); l.sort(repoCompare);
return l; return l;
@@ -633,7 +653,7 @@ syncthing.filter('chunkID', function () {
if (!parts) if (!parts)
return ""; return "";
return parts.join('-'); return parts.join('-');
} };
}); });
syncthing.filter('shortPath', function () { syncthing.filter('shortPath', function () {
@@ -645,13 +665,13 @@ syncthing.filter('shortPath', function () {
return input; return input;
} }
return ".../" + parts.slice(parts.length-2).join("/"); return ".../" + parts.slice(parts.length-2).join("/");
} };
}); });
syncthing.filter('clean', function () { syncthing.filter('clean', function () {
return function (input) { return function (input) {
return encodeURIComponent(input).replace(/%/g, ''); return encodeURIComponent(input).replace(/%/g, '');
} };
}); });
syncthing.directive('optionEditor', function () { syncthing.directive('optionEditor', function () {