blob: b7be490a4080b06aa46c34661abf6f0a41579063 [file] [log] [blame]
Simon Huntc2202d52014-12-16 13:30:15 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Simon Huntc2202d52014-12-16 13:30:15 -08003 *
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/*
Simon Huntdc6362a2014-12-18 19:55:23 -080018 ONOS GUI -- Main Application Module
Simon Huntc2202d52014-12-16 13:30:15 -080019 */
Simon Hunt1eecfa22014-12-16 14:46:29 -080020
Simon Huntc2202d52014-12-16 13:30:15 -080021(function () {
22 'use strict';
23
Simon Huntcd258a12015-01-19 19:20:13 -080024 // define core module dependencies here...
25 var coreDependencies = [
Simon Huntef31fb22014-12-19 13:16:44 -080026 'ngRoute',
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080027 'onosWidget',
Simon Huntef31fb22014-12-19 13:16:44 -080028 'onosUtil',
Simon Hunt6cc53692015-01-07 11:33:45 -080029 'onosSvg',
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080030 'onosRemote',
Simon Huntcd258a12015-01-19 19:20:13 -080031 'onosMast',
32 'onosNav'
Simon Huntef31fb22014-12-19 13:16:44 -080033 ];
34
Simon Huntcd258a12015-01-19 19:20:13 -080035 // view IDs.. note the first view listed is loaded at startup
36 var viewIds = [
37 // TODO: inject view IDs server side
38 // {INJECTED-VIEW-IDS}
39 'sample',
40 'topo',
41 'device',
42 // (end of injected views)
43
44 // dummy entry
45 ''
46 ];
47
48 var viewDependencies = [];
49
50 viewIds.forEach(function (id) {
51 if (id) {
52 viewDependencies.push('ov' + capitalize(id));
53 }
54 });
55
56 var moduleDependencies = coreDependencies.concat(viewDependencies);
57
58 function capitalize(word) {
59 return word ? word[0].toUpperCase() + word.slice(1) : word;
60 }
Simon Huntef31fb22014-12-19 13:16:44 -080061
Simon Hunt6cc53692015-01-07 11:33:45 -080062 angular.module('onosApp', moduleDependencies)
Simon Huntef31fb22014-12-19 13:16:44 -080063
64 .controller('OnosCtrl', [
65 '$log', '$route', '$routeParams', '$location',
Simon Hunt6cc53692015-01-07 11:33:45 -080066 'KeyService', 'ThemeService', 'GlyphService',
Simon Huntef31fb22014-12-19 13:16:44 -080067
Simon Huntcd258a12015-01-19 19:20:13 -080068 function ($log, $route, $routeParams, $location, ks, ts, gs) {
Simon Hunt6cc53692015-01-07 11:33:45 -080069 var self = this;
Simon Huntdc6362a2014-12-18 19:55:23 -080070
Simon Huntef31fb22014-12-19 13:16:44 -080071 self.$route = $route;
72 self.$routeParams = $routeParams;
73 self.$location = $location;
Simon Huntdc6362a2014-12-18 19:55:23 -080074 self.version = '1.1.0';
75
Simon Hunt6cc53692015-01-07 11:33:45 -080076 // initialize services...
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -080077 ts.init();
Simon Hunt420691a2014-12-16 20:16:28 -080078 ks.installOn(d3.select('body'));
Simon Hunt6cc53692015-01-07 11:33:45 -080079 gs.init();
Simon Huntdc6362a2014-12-18 19:55:23 -080080
81 $log.log('OnosCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -080082
83 $log.debug('route: ', self.$route);
84 $log.debug('routeParams: ', self.$routeParams);
85 $log.debug('location: ', self.$location);
86 }])
87
88 .config(['$routeProvider', function ($routeProvider) {
Simon Huntcd258a12015-01-19 19:20:13 -080089 // If view ID not provided, route to the first view in the list.
Simon Huntef31fb22014-12-19 13:16:44 -080090 $routeProvider
Simon Huntef31fb22014-12-19 13:16:44 -080091 .otherwise({
Simon Huntcd258a12015-01-19 19:20:13 -080092 redirectTo: '/' + viewIds[0]
93 });
Simon Huntc2202d52014-12-16 13:30:15 -080094
Simon Huntcd258a12015-01-19 19:20:13 -080095 function viewCtrlName(vid) {
96 return 'Ov' + capitalize(vid) + 'Ctrl';
97 }
98 function viewTemplateUrl(vid) {
99 return 'view/' + vid + '/' + vid + '.html';
100 }
101
102 // Add routes for each defined view.
103 viewIds.forEach(function (vid) {
104 if (vid) {
105 $routeProvider.when('/' + vid, {
106 controller: viewCtrlName(vid),
107 controllerAs: 'ctrl',
108 templateUrl: viewTemplateUrl(vid)
109 });
110 }
111 });
112 }]);
Simon Huntc2202d52014-12-16 13:30:15 -0800113}());