blob: 844fd46f45b9fe0b0e9b3ba3c7c396cce114edf3 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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 */
Steven Burrows0f26ac82017-08-07 22:36:36 +010020
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080021(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
chengfan386620e2016-11-09 17:02:40 +080039 // view ID to help page url map.. injected via the servlet
40 var viewMap = {
41 // {INJECTED-VIEW-DATA-START}
42 // {INJECTED-VIEW-DATA-END}
43 },
44 viewIds = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080045
Simon Huntf4ef6dd2016-02-03 17:05:14 -080046 // secret sauce
47 var sauce = [
Simon Huntfedd1752016-02-11 14:37:26 -080048 '6:69857666',
49 '9:826970',
50 '22:8069828667',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080051 '6:698570688669887967',
52 '7:6971806889847186',
53 '22:8369867682',
54 '13:736583',
55 '7:667186698384',
Simon Huntfedd1752016-02-11 14:37:26 -080056 '1:857780888778876787',
57 '20:70717066',
Simon Huntb8d37982016-08-22 21:29:55 -070058 '24:886774868469',
Viswanath KSP0cf084b2016-11-19 18:17:55 +053059 '17:7487696973687580739078',
Viswanath KSP539427f2016-12-21 19:08:08 +053060 '14:70777086',
Thomas Vachuska9e4bf032017-08-01 10:05:09 -070061 '17:7287687967',
62 '11:65678869706783687184',
63 '1:80777778',
64 '9:72696982'
Simon Huntb8d37982016-08-22 21:29:55 -070065 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080066 ];
67
Simon Hunt40927332016-01-22 15:29:47 -080068 var defaultView = 'topo',
69 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080070
chengfan386620e2016-11-09 17:02:40 +080071 viewIds = d3.map(viewMap).keys();
72
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073 viewIds.forEach(function (id) {
74 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080075 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080076 }
77 });
78
79 var moduleDependencies = coreDependencies.concat(viewDependencies);
80
Simon Huntf4ef6dd2016-02-03 17:05:14 -080081 function saucy(ee, ks) {
82 var map = ee.genMap(sauce);
83 Object.keys(map).forEach(function (k) {
84 ks.addSeq(k, map[k]);
85 });
86 }
87
Simon Hunt40927332016-01-22 15:29:47 -080088 function cap(s) {
89 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080090 }
91
92 angular.module('onosApp', moduleDependencies)
93
94 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070095 '$log', '$scope', '$route', '$routeParams', '$location',
Simon Huntc1656ed2017-06-21 16:47:04 -070096 'LionService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070097 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080098 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Simon Hunta1028c42017-02-07 20:08:03 -080099 'WebSocketService', 'SpriteService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800100
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800101 function (_$log_, $scope, $route, $routeParams, $location,
Simon Huntc1656ed2017-06-21 16:47:04 -0700102 lion, ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800103 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800104 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800105
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800106 self.$route = $route;
107 self.$routeParams = $routeParams;
108 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800109 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800110
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700111 // shared object inherited by all views:
112 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800113 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700114
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800115 // initialize services...
Simon Huntc1656ed2017-06-21 16:47:04 -0700116 lion.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800117 ts.init();
118 ks.installOn(d3.select('body'));
119 ks.bindQhs(qhs);
120 gs.init();
Simon Hunta1028c42017-02-07 20:08:03 -0800121 ss.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700122 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800123 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800124 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800125 flash.initFlash();
126 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800127
Simon Hunt20207df2015-03-10 18:30:14 -0700128 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700129 wsport: $location.search().wsport
130 });
131
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800132 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800133
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800134 $log.debug('route: ', self.$route);
135 $log.debug('routeParams: ', self.$routeParams);
136 $log.debug('location: ', self.$location);
137 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800138
139 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800140 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800141 $routeProvider
142 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800143 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800144 });
145
146 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800147 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800148 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800149
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800150 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800151 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800152 }
153
154 // Add routes for each defined view.
155 viewIds.forEach(function (vid) {
156 if (vid) {
157 $routeProvider.when('/' + vid, {
158 controller: viewCtrlName(vid),
159 controllerAs: 'ctrl',
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000160 templateUrl: viewTemplateUrl(vid),
Simon Hunt9edd1722017-03-10 17:43:26 -0800161
162 // Disable reload on $loc.hash() changes for bookmarked topo regions
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000163 reloadOnSearch: (vid !== 'topo2')
Simon Hunt9edd1722017-03-10 17:43:26 -0800164 // <SDH> assume this is not needed for ?regionId=... query string
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000165 // <SBM> Yes this is still needed. Without it the page will reload when navigating between
166 // regions which loads the new regions without a clean transition to it.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800167 });
168 }
169 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700170 }])
171
172 .directive('detectBrowser', ['$log', 'FnService',
173 function ($log, fs) {
174 return function (scope) {
175 var body = d3.select('body'),
176 browser = '';
177 if (fs.isChrome()) {
178 browser = 'chrome';
179 } else if (fs.isSafari()) {
180 browser = 'safari';
181 } else if (fs.isFirefox()) {
182 browser = 'firefox';
183 }
184 body.classed(browser, true);
185 scope.onos.browser = browser;
186
187 if (fs.isMobile()) {
188 body.classed('mobile', true);
189 scope.onos.mobile = true;
190 }
191
192 $log.debug('Detected browser is', fs.cap(browser));
193 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800194 }]);
195}());