blob: c7a5b656e2bc62205730e7c2b31e934cde583d6b [file] [log] [blame]
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function () {
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080018 'use strict';
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080019
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080020 var modules = [
21 'ngRoute',
22 'ngResource',
23 'ngAnimate',
Matteo Scandolo94992fd2016-01-27 13:51:07 -080024 'ngCookies',
Matteo Scandolo61bea662016-01-26 17:21:39 -080025 'cordRest',
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080026 'cordMast',
27 'cordFoot',
28 'cordNav',
29 'cordLogin',
30 'cordHome',
31 'cordUser',
32 'cordBundle'
Matteo Scandoloc6036502016-01-26 15:17:10 -080033 ];
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080034
Matteo Scandoloc6036502016-01-26 15:17:10 -080035 angular.module('cordGui', modules)
Matteo Scandolo35b7b212016-01-28 09:41:49 -080036 .config(function ($routeProvider, $httpProvider) {
37
38 $httpProvider.interceptors.push('SetCSRFToken');
39
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080040 $routeProvider
41 .when('/login', {
42 controller: 'CordLoginCtrl',
43 controllerAs: 'ctrl',
44 templateUrl: 'app/view/login/login.html'
45 })
46 .when('/home', {
47 controller: 'CordHomeCtrl',
48 controllerAs: 'ctrl',
49 templateUrl: 'app/view/home/home.html'
50 })
51 .when('/user', {
52 controller: 'CordUserCtrl',
53 controllerAs: 'ctrl',
54 templateUrl: 'app/view/user/user.html'
55 })
56 .when('/bundle', {
57 controller: 'CordBundleCtrl',
58 controllerAs: 'ctrl',
59 templateUrl: 'app/view/bundle/bundle.html'
60 })
61 .otherwise({
62 redirectTo: '/login'
63 });
Matteo Scandolo35b7b212016-01-28 09:41:49 -080064 })
Matteo Scandoloe0628502016-01-27 14:42:42 -080065 .controller('CordCtrl', function ($scope, $location, cordConfig) {
66 $scope.shared = {
67 url: 'http://' + $location.host() + ':' + $location.port()
68 };
69 $scope.shared.userActivity = cordConfig.userActivity;
70 $scope.page = {};
71 })
Matteo Scandolo61bea662016-01-26 17:21:39 -080072 .constant('cordConfig', {
73 url: '',
74 userActivity: {}, //check if really needed
Matteo Scandolo90621b32016-01-27 16:40:21 -080075 activeBundle: 1,
Matteo Scandolo61bea662016-01-26 17:21:39 -080076 bundles: [
77 {
78 "id": "family",
79 "name": "Family Bundle",
80 "desc": "Description for family bundle",
81 "functions": [
82 {
83 "id": "internet",
84 "name": "Internet",
85 "desc": "Basic internet connectivity.",
86 "params": {}
87 },
88 {
89 "id": "firewall",
90 "name": "Firewall",
91 "desc": "Normal firewall protection.",
92 "params": {}
93 },
94 {
95 "id": "url_filter",
96 "name": "Parental Control",
97 "desc": "Variable levels of URL filtering.",
98 "params": {
99 "level": "PG",
Matteo Scandolo39c65a52016-01-27 12:00:18 -0800100 "levels": [ "PG", "PG_13", "R" ]
Matteo Scandolo61bea662016-01-26 17:21:39 -0800101 }
102 }
103 ]
104 },
105 {
106 "id": "basic",
107 "name": "Basic Bundle",
108 "desc": "Description for basic bundle",
109 "functions": [
110 {
111 "id": "internet",
112 "name": "Internet",
113 "desc": "Basic internet connectivity.",
114 "params": {}
115 },
116 {
117 "id": "firewall",
118 "name": "Firewall",
119 "desc": "Normal firewall protection.",
120 "params": {}
121 }
122 ]
123 }
124 ]
125 })
Matteo Scandolo94992fd2016-01-27 13:51:07 -0800126 .run(function($rootScope, $location, cordConfig, User){
Matteo Scandolo61bea662016-01-26 17:21:39 -0800127 cordConfig.url = 'http://' + $location.host() + ':' + $location.port();
Matteo Scandolo94992fd2016-01-27 13:51:07 -0800128
129 // basic authentication
130 $rootScope.$on('$routeChangeStart', function(next, current) {
131 if(!User.isLoggedIn()){
132 $location.path('/login');
133 }
134 });
Matteo Scandolo61bea662016-01-26 17:21:39 -0800135 });
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -0800136}());