blob: 2de0090ef4c5ee0818f665920ac7f0171dffc39a [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',
Thomas Vachuskae586b792015-03-26 13:59:38 -070042 'host',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070043 'app',
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070044 'intent',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -070045 'cluster',
Bri Prebilic Cole9fb594a2015-04-14 09:15:54 -070046 'link',
Thomas Vachuskaa0509892015-02-21 22:18:41 -080047 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080048
49 // dummy entry
50 ''
51 ];
52
53 var viewDependencies = [];
54
55 viewIds.forEach(function (id) {
56 if (id) {
57 viewDependencies.push('ov' + capitalize(id));
58 }
59 });
60
61 var moduleDependencies = coreDependencies.concat(viewDependencies);
62
63 function capitalize(word) {
64 return word ? word[0].toUpperCase() + word.slice(1) : word;
65 }
66
67 angular.module('onosApp', moduleDependencies)
68
69 .controller('OnosCtrl', [
70 '$log', '$route', '$routeParams', '$location',
71 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
Thomas Vachuska329af532015-03-10 02:08:33 -070072 'FlashService', 'QuickHelpService', 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073
Thomas Vachuskaa0509892015-02-21 22:18:41 -080074 function ($log, $route, $routeParams, $location,
Thomas Vachuska329af532015-03-10 02:08:33 -070075 ks, ts, gs, ps, flash, qhs, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080076 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077
Thomas Vachuskaa0509892015-02-21 22:18:41 -080078 self.$route = $route;
79 self.$routeParams = $routeParams;
80 self.$location = $location;
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070081 self.version = '1.2.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080082
Thomas Vachuskaa0509892015-02-21 22:18:41 -080083 // initialize services...
84 ts.init();
85 ks.installOn(d3.select('body'));
86 ks.bindQhs(qhs);
87 gs.init();
88 ps.init();
89 flash.initFlash();
90 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080091
Simon Hunt20207df2015-03-10 18:30:14 -070092 // TODO: register handler for user settings, etc.
Thomas Vachuska329af532015-03-10 02:08:33 -070093
Simon Hunt20207df2015-03-10 18:30:14 -070094 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -070095 wsport: $location.search().wsport
96 });
97
Thomas Vachuskaa0509892015-02-21 22:18:41 -080098 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080099
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800100 $log.debug('route: ', self.$route);
101 $log.debug('routeParams: ', self.$routeParams);
102 $log.debug('location: ', self.$location);
103 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800104
105 .config(['$routeProvider', function ($routeProvider) {
106 // If view ID not provided, route to the first view in the list.
107 $routeProvider
108 .otherwise({
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -0700109 redirectTo: '/topo'
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800110 });
111
112 function viewCtrlName(vid) {
113 return 'Ov' + capitalize(vid) + 'Ctrl';
114 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800115
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800116 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800117 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800118 }
119
120 // Add routes for each defined view.
121 viewIds.forEach(function (vid) {
122 if (vid) {
123 $routeProvider.when('/' + vid, {
124 controller: viewCtrlName(vid),
125 controllerAs: 'ctrl',
126 templateUrl: viewTemplateUrl(vid)
127 });
128 }
129 });
130 }]);
131}());