blob: a5b99ad316d7d03f0be9b37db7e46db99bc631ef [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',
Thomas Vachuskabea68cf2017-11-03 13:05:18 -070064 '9:72696982',
Thomas Vachuska9ad62602018-04-04 18:09:20 -070065 '7:857165828967',
Thomas Vachuska25ffa032018-08-08 17:27:33 -070066 '11:8867696882678869759071',
67 '5:817384'
Simon Huntb8d37982016-08-22 21:29:55 -070068 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080069 ];
70
Simon Hunt40927332016-01-22 15:29:47 -080071 var defaultView = 'topo',
72 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080073
chengfan386620e2016-11-09 17:02:40 +080074 viewIds = d3.map(viewMap).keys();
75
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080076 viewIds.forEach(function (id) {
77 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080078 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080079 }
80 });
81
82 var moduleDependencies = coreDependencies.concat(viewDependencies);
83
Simon Huntf4ef6dd2016-02-03 17:05:14 -080084 function saucy(ee, ks) {
85 var map = ee.genMap(sauce);
86 Object.keys(map).forEach(function (k) {
87 ks.addSeq(k, map[k]);
88 });
89 }
90
Simon Hunt40927332016-01-22 15:29:47 -080091 function cap(s) {
92 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080093 }
94
95 angular.module('onosApp', moduleDependencies)
96
97 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070098 '$log', '$scope', '$route', '$routeParams', '$location',
Simon Huntc1656ed2017-06-21 16:47:04 -070099 'LionService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700100 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800101 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Simon Hunta1028c42017-02-07 20:08:03 -0800102 'WebSocketService', 'SpriteService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800103
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800104 function (_$log_, $scope, $route, $routeParams, $location,
Simon Huntc1656ed2017-06-21 16:47:04 -0700105 lion, ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800106 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800107 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800108
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800109 self.$route = $route;
110 self.$routeParams = $routeParams;
111 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800112 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800113
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700114 // shared object inherited by all views:
115 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800116 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700117
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800118 // initialize services...
Simon Huntc1656ed2017-06-21 16:47:04 -0700119 lion.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800120 ts.init();
121 ks.installOn(d3.select('body'));
122 ks.bindQhs(qhs);
123 gs.init();
Simon Hunta1028c42017-02-07 20:08:03 -0800124 ss.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700125 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800126 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800127 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800128 flash.initFlash();
129 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800130
Simon Hunt20207df2015-03-10 18:30:14 -0700131 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700132 wsport: $location.search().wsport
133 });
134
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800135 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800136
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800137 $log.debug('route: ', self.$route);
138 $log.debug('routeParams: ', self.$routeParams);
139 $log.debug('location: ', self.$location);
140 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800141
142 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800143 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800144 $routeProvider
145 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800146 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800147 });
148
149 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800150 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800151 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800152
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800153 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800154 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800155 }
156
157 // Add routes for each defined view.
158 viewIds.forEach(function (vid) {
159 if (vid) {
160 $routeProvider.when('/' + vid, {
161 controller: viewCtrlName(vid),
162 controllerAs: 'ctrl',
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000163 templateUrl: viewTemplateUrl(vid),
Simon Hunt9edd1722017-03-10 17:43:26 -0800164
165 // Disable reload on $loc.hash() changes for bookmarked topo regions
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000166 reloadOnSearch: (vid !== 'topo2')
Simon Hunt9edd1722017-03-10 17:43:26 -0800167 // <SDH> assume this is not needed for ?regionId=... query string
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000168 // <SBM> Yes this is still needed. Without it the page will reload when navigating between
169 // regions which loads the new regions without a clean transition to it.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800170 });
171 }
172 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700173 }])
174
175 .directive('detectBrowser', ['$log', 'FnService',
176 function ($log, fs) {
177 return function (scope) {
178 var body = d3.select('body'),
179 browser = '';
180 if (fs.isChrome()) {
181 browser = 'chrome';
182 } else if (fs.isSafari()) {
183 browser = 'safari';
184 } else if (fs.isFirefox()) {
185 browser = 'firefox';
186 }
187 body.classed(browser, true);
188 scope.onos.browser = browser;
189
190 if (fs.isMobile()) {
191 body.classed('mobile', true);
192 scope.onos.mobile = true;
193 }
194
195 $log.debug('Detected browser is', fs.cap(browser));
196 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800197 }]);
198}());