Browse Source

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

Ryan Sullivan 11 years ago
parent
commit
832ed556d9
2 changed files with 29 additions and 9 deletions
  1. 0 0
      auto/gui.files.go
  2. 29 9
      gui/app.js

File diff suppressed because it is too large
+ 0 - 0
auto/gui.files.go


+ 29 - 9
gui/app.js

@@ -1,7 +1,7 @@
 /*jslint browser: true, continue: true, plusplus: true */
 /*global $: false, angular: false */
 
-'use strict';
+'use-strict';
 
 var syncthing = angular.module('syncthing', []);
 var urlbase = 'rest';
@@ -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,19 @@ 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.shutdown = function () {
@@ -402,7 +422,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 +564,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 +653,7 @@ syncthing.filter('chunkID', function () {
         if (!parts)
             return "";
         return parts.join('-');
-    }
+    };
 });
 
 syncthing.filter('shortPath', function () {
@@ -645,13 +665,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 () {

Some files were not shown because too many files changed in this diff