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