blob: 050001921a59d986eba1e66bf995aaf15c47fb40 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Jian Li1f544732015-12-30 23:36:37 -08002 * Copyright 2014-2016 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
Simon Huntf4ef6dd2016-02-03 17:05:14 -080024 // injected refs
25 var $log;
26
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080027 // define core module dependencies here...
28 var coreDependencies = [
29 'ngRoute',
30 'onosMast',
31 'onosNav',
32 'onosUtil',
33 'onosSvg',
34 'onosRemote',
35 'onosLayer',
36 'onosWidget'
37 ];
38
Simon Hunt40927332016-01-22 15:29:47 -080039 // view IDs.. injected via the servlet
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080040 var viewIds = [
Thomas Vachuskaa0509892015-02-21 22:18:41 -080041 // {INJECTED-VIEW-IDS-START}
Thomas Vachuskaa0509892015-02-21 22:18:41 -080042 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080043 // dummy entry
44 ''
45 ];
46
Simon Huntf4ef6dd2016-02-03 17:05:14 -080047 // secret sauce
48 var sauce = [
Simon Huntfedd1752016-02-11 14:37:26 -080049 '6:69857666',
50 '9:826970',
51 '22:8069828667',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080052 '6:698570688669887967',
53 '7:6971806889847186',
54 '22:8369867682',
55 '13:736583',
56 '7:667186698384',
Simon Huntfedd1752016-02-11 14:37:26 -080057 '1:857780888778876787',
58 '20:70717066',
59 '24:886774868469'
Simon Huntf4ef6dd2016-02-03 17:05:14 -080060 ];
61
Simon Hunt40927332016-01-22 15:29:47 -080062 var defaultView = 'topo',
63 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080064
65 viewIds.forEach(function (id) {
66 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080067 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080068 }
69 });
70
71 var moduleDependencies = coreDependencies.concat(viewDependencies);
72
Simon Huntf4ef6dd2016-02-03 17:05:14 -080073 function saucy(ee, ks) {
74 var map = ee.genMap(sauce);
75 Object.keys(map).forEach(function (k) {
76 ks.addSeq(k, map[k]);
77 });
78 }
79
Simon Hunt40927332016-01-22 15:29:47 -080080 function cap(s) {
81 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080082 }
83
84 angular.module('onosApp', moduleDependencies)
85
86 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070087 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070088 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080089 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070090 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080091
Simon Huntf4ef6dd2016-02-03 17:05:14 -080092 function (_$log_, $scope, $route, $routeParams, $location,
93 ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080094 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -080095 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080096
Thomas Vachuskaa0509892015-02-21 22:18:41 -080097 self.$route = $route;
98 self.$routeParams = $routeParams;
99 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800100 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800101
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700102 // shared object inherited by all views:
103 $scope.onos = {};
104
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800105 // initialize services...
106 ts.init();
107 ks.installOn(d3.select('body'));
108 ks.bindQhs(qhs);
109 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700110 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800111 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800112 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800113 flash.initFlash();
114 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800115
Simon Hunt20207df2015-03-10 18:30:14 -0700116 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700117 wsport: $location.search().wsport
118 });
119
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800120 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800121
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800122 $log.debug('route: ', self.$route);
123 $log.debug('routeParams: ', self.$routeParams);
124 $log.debug('location: ', self.$location);
125 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800126
127 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800128 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800129 $routeProvider
130 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800131 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800132 });
133
134 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800135 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800136 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800137
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800138 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800139 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800140 }
141
142 // Add routes for each defined view.
143 viewIds.forEach(function (vid) {
144 if (vid) {
145 $routeProvider.when('/' + vid, {
146 controller: viewCtrlName(vid),
147 controllerAs: 'ctrl',
148 templateUrl: viewTemplateUrl(vid)
149 });
150 }
151 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700152 }])
153
154 .directive('detectBrowser', ['$log', 'FnService',
155 function ($log, fs) {
156 return function (scope) {
157 var body = d3.select('body'),
158 browser = '';
159 if (fs.isChrome()) {
160 browser = 'chrome';
161 } else if (fs.isSafari()) {
162 browser = 'safari';
163 } else if (fs.isFirefox()) {
164 browser = 'firefox';
165 }
166 body.classed(browser, true);
167 scope.onos.browser = browser;
168
169 if (fs.isMobile()) {
170 body.classed('mobile', true);
171 scope.onos.mobile = true;
172 }
173
174 $log.debug('Detected browser is', fs.cap(browser));
175 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800176 }]);
177}());