blob: ad73fc81f58ea82799a1d2ac99f367c67eace222 [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',
Thomas Vachuskae586b792015-03-26 13:59:38 -070041 'host',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070042 'app',
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070043 'intent',
Thomas Vachuskaef646762015-03-17 15:19:03 -070044 'sample',
Thomas Vachuskaa0509892015-02-21 22:18:41 -080045 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080046
47 // dummy entry
48 ''
49 ];
50
51 var viewDependencies = [];
52
53 viewIds.forEach(function (id) {
54 if (id) {
55 viewDependencies.push('ov' + capitalize(id));
56 }
57 });
58
59 var moduleDependencies = coreDependencies.concat(viewDependencies);
60
61 function capitalize(word) {
62 return word ? word[0].toUpperCase() + word.slice(1) : word;
63 }
64
65 angular.module('onosApp', moduleDependencies)
66
67 .controller('OnosCtrl', [
68 '$log', '$route', '$routeParams', '$location',
69 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
Thomas Vachuska329af532015-03-10 02:08:33 -070070 'FlashService', 'QuickHelpService', 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080071
Thomas Vachuskaa0509892015-02-21 22:18:41 -080072 function ($log, $route, $routeParams, $location,
Thomas Vachuska329af532015-03-10 02:08:33 -070073 ks, ts, gs, ps, flash, qhs, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080074 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080075
Thomas Vachuskaa0509892015-02-21 22:18:41 -080076 self.$route = $route;
77 self.$routeParams = $routeParams;
78 self.$location = $location;
79 self.version = '1.1.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080080
Thomas Vachuskaa0509892015-02-21 22:18:41 -080081 // initialize services...
82 ts.init();
83 ks.installOn(d3.select('body'));
84 ks.bindQhs(qhs);
85 gs.init();
86 ps.init();
87 flash.initFlash();
88 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080089
Simon Hunt20207df2015-03-10 18:30:14 -070090 // TODO: register handler for user settings, etc.
Thomas Vachuska329af532015-03-10 02:08:33 -070091
Simon Hunt20207df2015-03-10 18:30:14 -070092 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -070093 wsport: $location.search().wsport
94 });
95
Thomas Vachuskaa0509892015-02-21 22:18:41 -080096 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080097
Thomas Vachuskaa0509892015-02-21 22:18:41 -080098 $log.debug('route: ', self.$route);
99 $log.debug('routeParams: ', self.$routeParams);
100 $log.debug('location: ', self.$location);
101 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800102
103 .config(['$routeProvider', function ($routeProvider) {
104 // If view ID not provided, route to the first view in the list.
105 $routeProvider
106 .otherwise({
107 redirectTo: '/' + viewIds[0]
108 });
109
110 function viewCtrlName(vid) {
111 return 'Ov' + capitalize(vid) + 'Ctrl';
112 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800113
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800114 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800115 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800116 }
117
118 // Add routes for each defined view.
119 viewIds.forEach(function (vid) {
120 if (vid) {
121 $routeProvider.when('/' + vid, {
122 controller: viewCtrlName(vid),
123 controllerAs: 'ctrl',
124 templateUrl: viewTemplateUrl(vid)
125 });
126 }
127 });
128 }]);
129}());