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