blob: c1338f6b40c7d6fe5c1215e7bc0b9752eb5bf147 [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}
39 'sample',
40 'topo',
41 'device',
42 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080043
44 // dummy entry
45 ''
46 ];
47
48 var viewDependencies = [];
49
50 viewIds.forEach(function (id) {
51 if (id) {
52 viewDependencies.push('ov' + capitalize(id));
53 }
54 });
55
56 var moduleDependencies = coreDependencies.concat(viewDependencies);
57
58 function capitalize(word) {
59 return word ? word[0].toUpperCase() + word.slice(1) : word;
60 }
61
62 angular.module('onosApp', moduleDependencies)
63
64 .controller('OnosCtrl', [
65 '$log', '$route', '$routeParams', '$location',
66 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
Thomas Vachuska329af532015-03-10 02:08:33 -070067 'FlashService', 'QuickHelpService', 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080068
Thomas Vachuskaa0509892015-02-21 22:18:41 -080069 function ($log, $route, $routeParams, $location,
Thomas Vachuska329af532015-03-10 02:08:33 -070070 ks, ts, gs, ps, flash, qhs, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080071 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080072
Thomas Vachuskaa0509892015-02-21 22:18:41 -080073 self.$route = $route;
74 self.$routeParams = $routeParams;
75 self.$location = $location;
76 self.version = '1.1.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077
Thomas Vachuskaa0509892015-02-21 22:18:41 -080078 // initialize services...
79 ts.init();
80 ks.installOn(d3.select('body'));
81 ks.bindQhs(qhs);
82 gs.init();
83 ps.init();
84 flash.initFlash();
85 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080086
Simon Hunt20207df2015-03-10 18:30:14 -070087 // TODO: register handler for user settings, etc.
Thomas Vachuska329af532015-03-10 02:08:33 -070088
Simon Hunt20207df2015-03-10 18:30:14 -070089 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -070090 wsport: $location.search().wsport
91 });
92
Thomas Vachuskaa0509892015-02-21 22:18:41 -080093 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080094
Thomas Vachuskaa0509892015-02-21 22:18:41 -080095 $log.debug('route: ', self.$route);
96 $log.debug('routeParams: ', self.$routeParams);
97 $log.debug('location: ', self.$location);
98 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080099
100 .config(['$routeProvider', function ($routeProvider) {
101 // If view ID not provided, route to the first view in the list.
102 $routeProvider
103 .otherwise({
104 redirectTo: '/' + viewIds[0]
105 });
106
107 function viewCtrlName(vid) {
108 return 'Ov' + capitalize(vid) + 'Ctrl';
109 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800110
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800111 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800112 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800113 }
114
115 // Add routes for each defined view.
116 viewIds.forEach(function (vid) {
117 if (vid) {
118 $routeProvider.when('/' + vid, {
119 controller: viewCtrlName(vid),
120 controllerAs: 'ctrl',
121 templateUrl: viewTemplateUrl(vid)
122 });
123 }
124 });
125 }]);
126}());