blob: 01e910de21cde1b36a44e11ab469a7403d8b1444 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Thomas Vachuskaa0509892015-02-21 22:18:41 -08002 * Copyright 2014,2015 Open Networking Laboratory
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -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/*
18 ONOS GUI -- Main Application Module
19 */
20
21(function () {
22 'use strict';
23
24 // define core module dependencies here...
25 var coreDependencies = [
26 'ngRoute',
27 'onosMast',
28 'onosNav',
29 'onosUtil',
30 'onosSvg',
31 'onosRemote',
32 'onosLayer',
33 'onosWidget'
34 ];
35
36 // view IDs.. note the first view listed is loaded at startup
37 var viewIds = [
Thomas Vachuskaa0509892015-02-21 22:18:41 -080038 // {INJECTED-VIEW-IDS-START}
Thomas Vachuskaa0509892015-02-21 22:18:41 -080039 'topo',
40 'device',
Simon Hunt1002cd82015-04-23 14:44:03 -070041 'flow',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070042 'port',
Bri Prebilic Coleff3dc672015-05-06 12:59:38 -070043 'group',
Thomas Vachuskae586b792015-03-26 13:59:38 -070044 'host',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070045 'app',
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070046 'intent',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -070047 'cluster',
Bri Prebilic Cole9fb594a2015-04-14 09:15:54 -070048 'link',
Thomas Vachuskaa0509892015-02-21 22:18:41 -080049 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080050
51 // dummy entry
52 ''
53 ];
54
55 var viewDependencies = [];
56
57 viewIds.forEach(function (id) {
58 if (id) {
59 viewDependencies.push('ov' + capitalize(id));
60 }
61 });
62
63 var moduleDependencies = coreDependencies.concat(viewDependencies);
64
65 function capitalize(word) {
66 return word ? word[0].toUpperCase() + word.slice(1) : word;
67 }
68
69 angular.module('onosApp', moduleDependencies)
70
71 .controller('OnosCtrl', [
72 '$log', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070073 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
74 'PanelService', 'FlashService', 'QuickHelpService',
75 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080076
Thomas Vachuskaa0509892015-02-21 22:18:41 -080077 function ($log, $route, $routeParams, $location,
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070078 ks, ts, gs, vs, ps, flash, qhs, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080079 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080080
Thomas Vachuskaa0509892015-02-21 22:18:41 -080081 self.$route = $route;
82 self.$routeParams = $routeParams;
83 self.$location = $location;
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070084 self.version = '1.2.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080085
Thomas Vachuskaa0509892015-02-21 22:18:41 -080086 // initialize services...
87 ts.init();
88 ks.installOn(d3.select('body'));
89 ks.bindQhs(qhs);
90 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070091 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -080092 ps.init();
93 flash.initFlash();
94 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080095
Simon Hunt20207df2015-03-10 18:30:14 -070096 // TODO: register handler for user settings, etc.
Thomas Vachuska329af532015-03-10 02:08:33 -070097
Simon Hunt20207df2015-03-10 18:30:14 -070098 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -070099 wsport: $location.search().wsport
100 });
101
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800102 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800103
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800104 $log.debug('route: ', self.$route);
105 $log.debug('routeParams: ', self.$routeParams);
106 $log.debug('location: ', self.$location);
107 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800108
109 .config(['$routeProvider', function ($routeProvider) {
110 // If view ID not provided, route to the first view in the list.
111 $routeProvider
112 .otherwise({
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700113 redirectTo: '/topo'
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800114 });
115
116 function viewCtrlName(vid) {
117 return 'Ov' + capitalize(vid) + 'Ctrl';
118 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800119
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800120 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800121 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800122 }
123
124 // Add routes for each defined view.
125 viewIds.forEach(function (vid) {
126 if (vid) {
127 $routeProvider.when('/' + vid, {
128 controller: viewCtrlName(vid),
129 controllerAs: 'ctrl',
130 templateUrl: viewTemplateUrl(vid)
131 });
132 }
133 });
134 }]);
135}());