Commits

Mischa Dasberg  committed e87f50f

Removed configuration service from run() method and moved the call to the walliCtrl.

  • Participants
  • Parent commits 8d41d2b

Comments (0)

Files changed (11)

File client/walli/app/js/walli.js

 "use strict";
 
 angular.module('walli', ['ngResource', 'ngSanitize', 'ngCookies', 'ngRoute', 'core']);
-angular.module('walli').run(['$rootScope', '$filter', 'configurationService', function($rootScope, $filter, configurationService) {
-    $rootScope.configuration = configurationService.get();
-}]);
-angular.module('walli').config(function ($routeProvider) {
-    $routeProvider.
-        when('/', {
-            templateUrl: 'partials/welcome.html'
-        }).
-        when('/projects/new', {
-            controller: 'projectCreateCtrl',
-            templateUrl: 'partials/project/project.html'
-        }).
-        when('/projects/:projectId', {
-            controller: 'projectUpdateCtrl',
-            templateUrl: 'partials/project/project.html'
-        }).
-        when('/sources/new', {
-            controller: 'sourceCreateCtrl',
-            templateUrl: 'partials/source/source.html'
-        }).
-        when('/sources/:sourceId', {
-            controller: 'sourceUpdateCtrl',
-            templateUrl: 'partials/source/source.html'
-        }).
-        when('/users/new', {
-            controller: 'userCreateCtrl',
-            templateUrl: 'partials/user/user.html'
-        }).
-        when('/users/:userId', {
-            controller: 'userEditCtrl',
-            templateUrl: 'partials/user/user.html'
-        }).
-        when('/settings', {
-            templateUrl: 'partials/settings.html'
-        }).
-        when('/configurations/new', {
-            controller: 'configurationCreateCtrl',
-            templateUrl: 'partials/configuration/setting.html'
-        }).
-        when('/configurations/:configurationId', {
-            controller: 'configurationUpdateCtrl',
-            templateUrl: 'partials/configuration/setting.html'
-        }).
-        when('/settings/:setting', {
-            templateUrl: 'partials/settings/setting.html'
-        }).
-        when('/login', {
-            templateUrl: 'partials/user/login.html'
-        }).
-        when('/projects/:projectId/overview', {
-            controller: 'overviewCtrl',
-            templateUrl: 'partials/overview/overview.html'
-        }).
-        otherwise({
-            redirectTo: '/'
-        });
-});
+
+angular.module('walli').
+    config(function ($routeProvider) {
+        $routeProvider.
+            when('/', {
+                templateUrl: 'partials/welcome.html'
+            }).
+            when('/projects/new', {
+                controller: 'projectCreateCtrl',
+                templateUrl: 'partials/project/project.html'
+            }).
+            when('/projects/:projectId', {
+                controller: 'projectUpdateCtrl',
+                templateUrl: 'partials/project/project.html'
+            }).
+            when('/sources/new', {
+                controller: 'sourceCreateCtrl',
+                templateUrl: 'partials/source/source.html'
+            }).
+            when('/sources/:sourceId', {
+                controller: 'sourceUpdateCtrl',
+                templateUrl: 'partials/source/source.html'
+            }).
+            when('/users/new', {
+                controller: 'userCreateCtrl',
+                templateUrl: 'partials/user/user.html'
+            }).
+            when('/users/:userId', {
+                controller: 'userEditCtrl',
+                templateUrl: 'partials/user/user.html'
+            }).
+            when('/settings', {
+                templateUrl: 'partials/settings.html'
+            }).
+            when('/configurations/new', {
+                controller: 'configurationCreateCtrl',
+                templateUrl: 'partials/configuration/setting.html'
+            }).
+            when('/configurations/:configurationId', {
+                controller: 'configurationUpdateCtrl',
+                templateUrl: 'partials/configuration/setting.html'
+            }).
+            when('/settings/:setting', {
+                templateUrl: 'partials/settings/setting.html'
+            }).
+            when('/login', {
+                templateUrl: 'partials/user/login.html'
+            }).
+            when('/projects/:projectId/overview', {
+                controller: 'overviewCtrl',
+                templateUrl: 'partials/overview/overview.html'
+            }).
+            otherwise({
+                redirectTo: '/'
+            });
+    });

File client/walli/app/js/walliCtrl.js

 angular.module('walli').controller('walliCtrl', [
     '$scope',
     'notificationService',
-    'versionService', function ($scope, notificationService, versionService) {
+    'configurationService',
+    'versionService', function ($scope, notificationService, configurationService, versionService) {
         $scope.notificationService = notificationService;
 
         $scope.version = versionService.version;
             $('.nav-collapse').collapse('hide');
         };
 
+        $scope.configurations = configurationService.query({});
+
+        $scope.configuration = function (name) {
+            var config;
+            angular.forEach($scope.configurations, function (configuration) {
+                if (configuration.name === name) {
+                    config = configuration.value;
+                }
+            });
+            return config;
+        };
+
         $scope.$on('project', function (event, project) {
             $scope.project = project;
 

File client/walli/app/partials/overview/jenkins.html

                     <li data-ng-hide="online"><span class="btn btn-xs btn-red">offline</span></li>
                 </ul>
             </div>
-            <div class="box-content boxed" data-ng-show="online" refresh="configuration.refreshTimeout">
+            <div class="box-content boxed" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
                 <datatable config="buildStatusesConfig" class="table table-normal"/>
             </div>
         </div>

File client/walli/app/partials/overview/sonar.html

 
         </div>
 
-        <div class="box-content padded" data-ng-show="online" refresh="configuration.refreshTimeout">
+        <div class="box-content padded" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
             <div class="tab-content">
                 <div class="tab-pane" ng-class="{active: codeQualityView() === 'overview'}"
                      style="text-align: center">

File client/walli/app/partials/overview/vcss.html

                     </li>
                 </ul>
             </div>
-            <div class="box-content padded" data-ng-show="online" refresh="configuration.refreshTimeout">
+            <div class="box-content padded" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
                 <div class="row">
                     <chart identifier="source + 'Activity'"
                            data="commitActivityData"
                     </li>
                 </ul>
             </div>
-            <div class="box-content padded" data-ng-show="online" refresh="configuration.refreshTimeout">
+            <div class="box-content padded" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
                 <div class="row">
                     <chart identifier="source + 'Activity'"
                            data="commitActivityData"
                     </li>
                 </ul>
             </div>
-            <div class="box-content padded" data-ng-show="online" refresh="configuration.refreshTimeout">
+            <div class="box-content padded" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
                 <div class="row">
                     <chart identifier="source + 'Activity'"
                            data="commitActivityData"
                     </li>
                 </ul>
             </div>
-            <div class="box-content padded" data-ng-show="online" refresh="configuration.refreshTimeout">
+            <div class="box-content padded" data-ng-show="online" refresh="{{configuration('refreshTimeout')}}">
                 <div class="row">
                     <chart identifier="source + 'Activity'"
                            data="commitActivityData"

File client/walli/test/mocks/stub-data.js

             {"id": 2, "username": "walli", "firstName": "Walli", "lastName": "Dashboard", "email": "walli@walli.org", "password": "password", "admin": false}
         ],
         proxy: {"name": "proxy"},
-        authentication: {"status":true},
-        configuration: {
-            "refreshTimeout": "30000"
-        }
+        authentication: {"status": true},
+        configurations: [
+            {"id": 1, "name": "refreshTimeout", "value": "3000"},
+            {"id": 2, "name": "buildBy", "value": "walli"}
+        ]
+
     }
 };

File client/walli/test/unit/services/authenticationServiceSpec.js

             return [200, {}, {}];
         });
 
-        var service = authenticationService.login({"username": "test", "password": "Test"});
+        authenticationService.login({"username": "test", "password": "Test"});
         $httpBackend.flush();
     }));
-    it("should login", inject(function ($httpBackend, authenticationService) {
+    it("should logout", inject(function ($httpBackend, authenticationService) {
         $httpBackend.when('DELETE', '/api/authentication').respond(function(method, url, data, headers){
             return [200, {}, {}];
         });
 
-        var service = authenticationService.logout();
+        authenticationService.logout();
         $httpBackend.flush();
     }));
 });

File client/walli/test/unit/services/configurationServiceSpec.js

 
 /* jasmine specs for the configuration service. */
 describe('The configurationService', function () {
-    var configurationService; // object under test
-    var $httpBackend;
+    beforeEach(module('walli'));
 
-    beforeEach(module('walli', function() {
-        var $injector = angular.injector(['ngMock', 'ng', 'walli']);
+    it("should get all the configurations", inject(function ($httpBackend, configurationService) {
+        $httpBackend.when('GET', '/api/configurations?format=json').respond(stubs.services.configurations, { 'Content-type': 'application/json' });
 
-        $injector.invoke(function(_configurationService_, _$httpBackend_) {
-            configurationService = _configurationService_;
-            $httpBackend = _$httpBackend_;
+        var service = configurationService.query({});
+        $httpBackend.flush();
+
+        expect(angular.equals(service, stubs.services.configurations)).toBeTruthy();
+        expect(service.length).toBe(2);
+    }));
+    it("should get a specific configuration", inject(function ($httpBackend, configurationService) {
+        $httpBackend.when('GET', '/api/configurations/1?format=json').respond(stubs.services.configurations[0], { 'Content-type': 'application/json' });
+
+        var service = configurationService.get({id:1});
+        $httpBackend.flush();
+
+        expect(angular.equals(service, stubs.services.configurations[0])).toBeTruthy();
+    }));
+    it("should create a configuration", inject(function ($httpBackend, configurationService) {
+        $httpBackend.when('POST', '/api/configurations?format=json').respond(function(method, url, data, headers){
+            var configuration = angular.fromJson(data);
+            configuration.id = 3;
+            stubs.services.configurations.push(configuration);
+            return [200, {}, {}];
         });
 
-        $httpBackend.expect('GET', '/api/configurations?format=json')
-            .respond(stubs.services.configuration, { 'Content-type': 'application/json' });
+        var service = configurationService.save({"name": "something", "value": "else"});
+        $httpBackend.flush();
+
+        expect(stubs.services.configurations.length).toBe(3);
     }));
+    it("should update a configuration", inject(function ($httpBackend, configurationService) {
+        $httpBackend.when('PUT', '/api/configurations/3?format=json').respond(function(method, url, data, headers){
+            var configuration = angular.fromJson(data);
+            configuration.id = 3;
+            stubs.services.configurations[2] = configuration;
+            return [200, {}, {}];
+        });
 
-    it("should get all the configuration values", inject(function () {
-        $httpBackend.expect('GET', '/api/configurations?format=json').respond(stubs.services.configuration, { 'Content-type': 'application/json' });
+        var service = configurationService.update({"id": 3, "name": "something", "value": "else"});
+        $httpBackend.flush();
+
+        expect(stubs.services.configurations.length).toBe(3);
+        expect(stubs.services.configurations[2].value).toBe("else");
+    }));
+    it("should delete a configuration", inject(function ($httpBackend, configurationService) {
+        $httpBackend.when('DELETE', '/api/configurations/3?format=json').respond(function(method, url, data, headers){
+            stubs.services.configurations.pop();
+            return [200, {}, {}];
+        });
 
-        var response = configurationService.get();
+        var service = configurationService.destroy({"id": 3});
         $httpBackend.flush();
 
-        expect(angular.equals(response, stubs.services.configuration)).toBeTruthy();
-        expect(response.refreshTimeout).toBe("30000");
+        expect(stubs.services.configurations.length).toBe(2);
     }));
 });

File client/walli/test/unit/services/sourceServiceSpec.js

 
 /* jasmine specs for the source service. */
 describe('The sourceService', function () {
-    beforeEach(module('walli.mocks'));
+    beforeEach(module('walli'));
 
     it("should get all the sources", inject(function ($httpBackend, sourceService) {
         $httpBackend.when('GET', '/api/sources?format=json').respond(stubs.services.sources, { 'Content-type': 'application/json' });

File client/walli/test/unit/services/userServiceSpec.js

 
 /* jasmine specs for the user service. */
 describe('The userService', function () {
-    beforeEach(module('walli.mocks'));
+    beforeEach(module('walli'));
 
     it("should get all the users", inject(function ($httpBackend, userService) {
         $httpBackend.when('GET', '/api/users?format=json').respond(stubs.services.users, { 'Content-type': 'application/json' });

File client/walli/test/unit/setup.js

-// This is more of a hack: the beforeEach will be executed *before* each spec, and such all specs
-// will have this mock of the configurationService.
-angular.module('walli.mocks', ['walli']);
-
-beforeEach(module('walli.mocks', function($provide) {
-    // Provide a mock for the configurationService, which is called from a module.run() block.
-    // See http://stackoverflow.com/a/16065800/1523342
-    return $provide.decorator('configurationService', function() {
-        return {
-            get: function() {
-                return { "refreshTimeout": "3000" };
-            }
-        }
-    });
-}));