blob: 23e777cdd5e96ae5c065a3761392ffc9cee78731 [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',
Simon Hunt54442fa2015-01-26 14:17:38 -080027 'onosMast',
28 'onosNav',
Simon Huntef31fb22014-12-19 13:16:44 -080029 'onosUtil',
Simon Hunt6cc53692015-01-07 11:33:45 -080030 'onosSvg',
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080031 'onosRemote',
Simon Hunt54442fa2015-01-26 14:17:38 -080032 'onosLayer',
33 'onosWidget'
Simon Huntef31fb22014-12-19 13:16:44 -080034 ];
35
Simon Huntcd258a12015-01-19 19:20:13 -080036 // view IDs.. note the first view listed is loaded at startup
37 var viewIds = [
38 // TODO: inject view IDs server side
39 // {INJECTED-VIEW-IDS}
40 'sample',
41 'topo',
42 'device',
43 // (end of injected views)
44
45 // dummy entry
46 ''
47 ];
48
49 var viewDependencies = [];
50
51 viewIds.forEach(function (id) {
52 if (id) {
53 viewDependencies.push('ov' + capitalize(id));
54 }
55 });
56
57 var moduleDependencies = coreDependencies.concat(viewDependencies);
58
59 function capitalize(word) {
60 return word ? word[0].toUpperCase() + word.slice(1) : word;
61 }
Simon Huntef31fb22014-12-19 13:16:44 -080062
Simon Hunt6cc53692015-01-07 11:33:45 -080063 angular.module('onosApp', moduleDependencies)
Simon Huntef31fb22014-12-19 13:16:44 -080064
65 .controller('OnosCtrl', [
66 '$log', '$route', '$routeParams', '$location',
Simon Hunt54442fa2015-01-26 14:17:38 -080067 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
Simon Huntef31fb22014-12-19 13:16:44 -080068
Simon Hunt54442fa2015-01-26 14:17:38 -080069 function ($log, $route, $routeParams, $location, ks, ts, gs, ps) {
Simon Hunt6cc53692015-01-07 11:33:45 -080070 var self = this;
Simon Huntdc6362a2014-12-18 19:55:23 -080071
Simon Huntef31fb22014-12-19 13:16:44 -080072 self.$route = $route;
73 self.$routeParams = $routeParams;
74 self.$location = $location;
Simon Huntdc6362a2014-12-18 19:55:23 -080075 self.version = '1.1.0';
76
Simon Hunt6cc53692015-01-07 11:33:45 -080077 // initialize services...
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -080078 ts.init();
Simon Hunt420691a2014-12-16 20:16:28 -080079 ks.installOn(d3.select('body'));
Simon Hunt6cc53692015-01-07 11:33:45 -080080 gs.init();
Simon Hunt54442fa2015-01-26 14:17:38 -080081 ps.init();
Simon Huntdc6362a2014-12-18 19:55:23 -080082
83 $log.log('OnosCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -080084
85 $log.debug('route: ', self.$route);
86 $log.debug('routeParams: ', self.$routeParams);
87 $log.debug('location: ', self.$location);
88 }])
89
90 .config(['$routeProvider', function ($routeProvider) {
Simon Huntcd258a12015-01-19 19:20:13 -080091 // If view ID not provided, route to the first view in the list.
Simon Huntef31fb22014-12-19 13:16:44 -080092 $routeProvider
Simon Huntef31fb22014-12-19 13:16:44 -080093 .otherwise({
Simon Huntcd258a12015-01-19 19:20:13 -080094 redirectTo: '/' + viewIds[0]
95 });
Simon Huntc2202d52014-12-16 13:30:15 -080096
Simon Huntcd258a12015-01-19 19:20:13 -080097 function viewCtrlName(vid) {
98 return 'Ov' + capitalize(vid) + 'Ctrl';
99 }
100 function viewTemplateUrl(vid) {
101 return 'view/' + vid + '/' + vid + '.html';
102 }
103
104 // Add routes for each defined view.
105 viewIds.forEach(function (vid) {
106 if (vid) {
107 $routeProvider.when('/' + vid, {
108 controller: viewCtrlName(vid),
109 controllerAs: 'ctrl',
110 templateUrl: viewTemplateUrl(vid)
111 });
112 }
113 });
114 }]);
Simon Huntc2202d52014-12-16 13:30:15 -0800115}());