blob: a937af56de3fabf01fa08949e58f18d564748cb5 [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',
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080028 'cordLogin',
29 'cordHome',
30 'cordUser',
31 'cordBundle'
Matteo Scandoloc6036502016-01-26 15:17:10 -080032 ];
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -080033
Matteo Scandoloc6036502016-01-26 15:17:10 -080034 angular.module('cordGui', modules)
Matteo Scandolo35b7b212016-01-28 09:41:49 -080035 .config(function ($routeProvider, $httpProvider) {
36
37 $httpProvider.interceptors.push('SetCSRFToken');
38
Matteo Scandolo9fb53f72016-01-26 11:34:15 -080039 $routeProvider
40 .when('/login', {
41 controller: 'CordLoginCtrl',
42 controllerAs: 'ctrl',
43 templateUrl: 'app/view/login/login.html'
44 })
45 .when('/home', {
46 controller: 'CordHomeCtrl',
47 controllerAs: 'ctrl',
48 templateUrl: 'app/view/home/home.html'
49 })
50 .when('/user', {
51 controller: 'CordUserCtrl',
52 controllerAs: 'ctrl',
53 templateUrl: 'app/view/user/user.html'
54 })
55 .when('/bundle', {
56 controller: 'CordBundleCtrl',
57 controllerAs: 'ctrl',
58 templateUrl: 'app/view/bundle/bundle.html'
59 })
60 .otherwise({
61 redirectTo: '/login'
62 });
Matteo Scandolo35b7b212016-01-28 09:41:49 -080063 })
Matteo Scandoloe0628502016-01-27 14:42:42 -080064 .controller('CordCtrl', function ($scope, $location, cordConfig) {
65 $scope.shared = {
66 url: 'http://' + $location.host() + ':' + $location.port()
67 };
68 $scope.shared.userActivity = cordConfig.userActivity;
69 $scope.page = {};
70 })
Matteo Scandolo61bea662016-01-26 17:21:39 -080071 .constant('cordConfig', {
72 url: '',
73 userActivity: {}, //check if really needed
Matteo Scandolo90621b32016-01-27 16:40:21 -080074 activeBundle: 1,
Matteo Scandolo61bea662016-01-26 17:21:39 -080075 bundles: [
76 {
77 "id": "family",
78 "name": "Family Bundle",
79 "desc": "Description for family bundle",
80 "functions": [
81 {
82 "id": "internet",
83 "name": "Internet",
84 "desc": "Basic internet connectivity.",
85 "params": {}
86 },
87 {
88 "id": "firewall",
89 "name": "Firewall",
90 "desc": "Normal firewall protection.",
91 "params": {}
92 },
93 {
94 "id": "url_filter",
95 "name": "Parental Control",
96 "desc": "Variable levels of URL filtering.",
97 "params": {
98 "level": "PG",
Matteo Scandolo39c65a52016-01-27 12:00:18 -080099 "levels": [ "PG", "PG_13", "R" ]
Matteo Scandolo61bea662016-01-26 17:21:39 -0800100 }
101 }
102 ]
103 },
104 {
105 "id": "basic",
106 "name": "Basic Bundle",
107 "desc": "Description for basic bundle",
108 "functions": [
109 {
110 "id": "internet",
111 "name": "Internet",
112 "desc": "Basic internet connectivity.",
113 "params": {}
114 },
115 {
116 "id": "firewall",
117 "name": "Firewall",
118 "desc": "Normal firewall protection.",
119 "params": {}
120 }
121 ]
122 }
123 ]
124 })
Matteo Scandolo94992fd2016-01-27 13:51:07 -0800125 .run(function($rootScope, $location, cordConfig, User){
Matteo Scandolo61bea662016-01-26 17:21:39 -0800126 cordConfig.url = 'http://' + $location.host() + ':' + $location.port();
Matteo Scandolo94992fd2016-01-27 13:51:07 -0800127
128 // basic authentication
129 $rootScope.$on('$routeChangeStart', function(next, current) {
130 if(!User.isLoggedIn()){
131 $location.path('/login');
132 }
133 });
Matteo Scandolo61bea662016-01-26 17:21:39 -0800134 });
Matteo Scandolo4eb4ccb2016-01-26 11:02:16 -0800135}());