blob: 97f3d068d286aed4788d7097c642c188109a86bd [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
Thomas Vachuska329af532015-03-10 02:08:33 -070087 // TODO: register handlers for initial messages: instances, settings, etc.
88
89 // TODO: opts?
90 wss.createWebSocket('core', {
91 wsport: $location.search().wsport
92 });
93
Thomas Vachuskaa0509892015-02-21 22:18:41 -080094 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080095
Thomas Vachuskaa0509892015-02-21 22:18:41 -080096 $log.debug('route: ', self.$route);
97 $log.debug('routeParams: ', self.$routeParams);
98 $log.debug('location: ', self.$location);
99 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800100
101 .config(['$routeProvider', function ($routeProvider) {
102 // If view ID not provided, route to the first view in the list.
103 $routeProvider
104 .otherwise({
105 redirectTo: '/' + viewIds[0]
106 });
107
108 function viewCtrlName(vid) {
109 return 'Ov' + capitalize(vid) + 'Ctrl';
110 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800111
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800112 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800113 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800114 }
115
116 // Add routes for each defined view.
117 viewIds.forEach(function (vid) {
118 if (vid) {
119 $routeProvider.when('/' + vid, {
120 controller: viewCtrlName(vid),
121 controllerAs: 'ctrl',
122 templateUrl: viewTemplateUrl(vid)
123 });
124 }
125 });
126 }]);
127}());