blob: 07dada7b7bca9d29f4a93ce006e2c9fcc489d629 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -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 */
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080020(function () {
21 'use strict';
22
Simon Huntf4ef6dd2016-02-03 17:05:14 -080023 // injected refs
24 var $log;
25
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080026 // define core module dependencies here...
27 var coreDependencies = [
28 'ngRoute',
29 'onosMast',
30 'onosNav',
31 'onosUtil',
32 'onosSvg',
33 'onosRemote',
34 'onosLayer',
35 'onosWidget'
36 ];
37
chengfan386620e2016-11-09 17:02:40 +080038 // view ID to help page url map.. injected via the servlet
39 var viewMap = {
40 // {INJECTED-VIEW-DATA-START}
41 // {INJECTED-VIEW-DATA-END}
42 },
43 viewIds = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080044
Simon Huntf4ef6dd2016-02-03 17:05:14 -080045 // secret sauce
46 var sauce = [
Simon Huntfedd1752016-02-11 14:37:26 -080047 '6:69857666',
48 '9:826970',
49 '22:8069828667',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080050 '6:698570688669887967',
51 '7:6971806889847186',
52 '22:8369867682',
53 '13:736583',
54 '7:667186698384',
Simon Huntfedd1752016-02-11 14:37:26 -080055 '1:857780888778876787',
56 '20:70717066',
Simon Huntb8d37982016-08-22 21:29:55 -070057 '24:886774868469',
Viswanath KSP0cf084b2016-11-19 18:17:55 +053058 '17:7487696973687580739078',
Viswanath KSP539427f2016-12-21 19:08:08 +053059 '14:70777086',
Thomas Vachuska146e68f62017-08-01 14:08:04 -070060 '17:7287687967',
61 '11:65678869706783687184'
Simon Huntb8d37982016-08-22 21:29:55 -070062 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080063 ];
64
Simon Hunt40927332016-01-22 15:29:47 -080065 var defaultView = 'topo',
66 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080067
chengfan386620e2016-11-09 17:02:40 +080068 viewIds = d3.map(viewMap).keys();
69
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080070 viewIds.forEach(function (id) {
71 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080072 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073 }
74 });
75
76 var moduleDependencies = coreDependencies.concat(viewDependencies);
77
Simon Huntf4ef6dd2016-02-03 17:05:14 -080078 function saucy(ee, ks) {
79 var map = ee.genMap(sauce);
80 Object.keys(map).forEach(function (k) {
81 ks.addSeq(k, map[k]);
82 });
83 }
84
Simon Hunt40927332016-01-22 15:29:47 -080085 function cap(s) {
86 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080087 }
88
89 angular.module('onosApp', moduleDependencies)
90
91 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070092 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070093 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080094 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Simon Hunta1028c42017-02-07 20:08:03 -080095 'WebSocketService', 'SpriteService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080096
Simon Huntf4ef6dd2016-02-03 17:05:14 -080097 function (_$log_, $scope, $route, $routeParams, $location,
Simon Hunta1028c42017-02-07 20:08:03 -080098 ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080099 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800100 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800101
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800102 self.$route = $route;
103 self.$routeParams = $routeParams;
104 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800105 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800106
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700107 // shared object inherited by all views:
108 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800109 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700110
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800111 // initialize services...
112 ts.init();
113 ks.installOn(d3.select('body'));
114 ks.bindQhs(qhs);
115 gs.init();
Simon Hunta1028c42017-02-07 20:08:03 -0800116 ss.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700117 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800118 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800119 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800120 flash.initFlash();
121 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800122
Simon Hunt20207df2015-03-10 18:30:14 -0700123 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700124 wsport: $location.search().wsport
125 });
126
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800127 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800128
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800129 $log.debug('route: ', self.$route);
130 $log.debug('routeParams: ', self.$routeParams);
131 $log.debug('location: ', self.$location);
132 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800133
134 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800135 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800136 $routeProvider
137 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800138 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800139 });
140
141 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800142 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800143 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800144
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800145 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800146 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800147 }
148
149 // Add routes for each defined view.
150 viewIds.forEach(function (vid) {
151 if (vid) {
152 $routeProvider.when('/' + vid, {
153 controller: viewCtrlName(vid),
154 controllerAs: 'ctrl',
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000155 templateUrl: viewTemplateUrl(vid),
Simon Hunt9edd1722017-03-10 17:43:26 -0800156
157 // Disable reload on $loc.hash() changes for bookmarked topo regions
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000158 reloadOnSearch: (vid !== 'topo2')
Simon Hunt9edd1722017-03-10 17:43:26 -0800159 // <SDH> assume this is not needed for ?regionId=... query string
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000160 // <SBM> Yes this is still needed. Without it the page will reload when navigating between
161 // regions which loads the new regions without a clean transition to it.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800162 });
163 }
164 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700165 }])
166
167 .directive('detectBrowser', ['$log', 'FnService',
168 function ($log, fs) {
169 return function (scope) {
170 var body = d3.select('body'),
171 browser = '';
172 if (fs.isChrome()) {
173 browser = 'chrome';
174 } else if (fs.isSafari()) {
175 browser = 'safari';
176 } else if (fs.isFirefox()) {
177 browser = 'firefox';
178 }
179 body.classed(browser, true);
180 scope.onos.browser = browser;
181
182 if (fs.isMobile()) {
183 body.classed('mobile', true);
184 scope.onos.mobile = true;
185 }
186
187 $log.debug('Detected browser is', fs.cap(browser));
188 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800189 }]);
190}());