'use strict';

angular
    .module('flyNg.server', ['services', 'ngCookies'])

    .controller('ServerController', ['$scope', '$rootScope', '$location', '$cookies', '$log', 'management', function ($scope, $rootScope, $location, $cookies, $log, management) {
        $scope.management = management;
        const KEY = 'server-url';
        var url = decodeURI($cookies[KEY]);
        if (url) {
            management.server = {"url": url};
        } else {
            management.server = {"url": "localhost"};
        }
        loadServerData();

        $scope.updateServerUrl = function() {
            $cookies[KEY] = encodeURI(management.server.url);
            loadServerData();
        };

        function loadServerData() {
            management.load([]).then(
                function(response) {
                    var serverState = response.result['server-state'];
                    if (serverState == 'reload-required') {
                        management.server.state = 'running';
                    } else {
                        management.server.state = serverState;
                    }
                },
                function(reason) {
                    //management.server.state = 'not connected';
                    $location.path('/');
                }
            );
        }

    }]);

@@ -303,13 +303,11 @@
     
-const
+var
  KEY
@@ -323,16 +323,71 @@
 r-url';%0A
+        if (!angular.isUndefined($cookies%5BKEY%5D)) %7B%0A    
         
@@ -434,16 +434,47 @@
     
-if 
+%7D%0A        if (angular.isUndefined
 (url)
+)
  %7B%0A 
@@ -512,19 +512,27 @@
 %7B%22url%22: 
-url
+%22localhost%22
 %7D;%0A     
@@ -579,35 +579,27 @@
 r = %7B%22url%22: 
-%22localhost%22
+url
 %7D;%0A        %7D
@@ -1271,10 +1271,8 @@
     
-//
 mana

Fix default url