blob: b6c82e6dd1a42323162438b82cbf10426669ff92 [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',
66 '11:8867696882678869759071'
Simon Huntb8d37982016-08-22 21:29:55 -070067 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080068 ];
69
Simon Hunt40927332016-01-22 15:29:47 -080070 var defaultView = 'topo',
71 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080072
chengfan386620e2016-11-09 17:02:40 +080073 viewIds = d3.map(viewMap).keys();
74
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080075 viewIds.forEach(function (id) {
76 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080077 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080078 }
79 });
80
81 var moduleDependencies = coreDependencies.concat(viewDependencies);
82
Simon Huntf4ef6dd2016-02-03 17:05:14 -080083 function saucy(ee, ks) {
84 var map = ee.genMap(sauce);
85 Object.keys(map).forEach(function (k) {
86 ks.addSeq(k, map[k]);
87 });
88 }
89
Simon Hunt40927332016-01-22 15:29:47 -080090 function cap(s) {
91 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080092 }
93
94 angular.module('onosApp', moduleDependencies)
95
96 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070097 '$log', '$scope', '$route', '$routeParams', '$location',
Simon Huntc1656ed2017-06-21 16:47:04 -070098 'LionService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070099 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800100 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Simon Hunta1028c42017-02-07 20:08:03 -0800101 'WebSocketService', 'SpriteService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800102
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800103 function (_$log_, $scope, $route, $routeParams, $location,
Simon Huntc1656ed2017-06-21 16:47:04 -0700104 lion, ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800105 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800106 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800107
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800108 self.$route = $route;
109 self.$routeParams = $routeParams;
110 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800111 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800112
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700113 // shared object inherited by all views:
114 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800115 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700116
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800117 // initialize services...
Simon Huntc1656ed2017-06-21 16:47:04 -0700118 lion.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800119 ts.init();
120 ks.installOn(d3.select('body'));
121 ks.bindQhs(qhs);
122 gs.init();
Simon Hunta1028c42017-02-07 20:08:03 -0800123 ss.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700124 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800125 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800126 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800127 flash.initFlash();
128 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800129
Simon Hunt20207df2015-03-10 18:30:14 -0700130 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700131 wsport: $location.search().wsport
132 });
133
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800134 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800135
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800136 $log.debug('route: ', self.$route);
137 $log.debug('routeParams: ', self.$routeParams);
138 $log.debug('location: ', self.$location);
139 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800140
141 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800142 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800143 $routeProvider
144 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800145 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800146 });
147
148 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800149 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800150 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800151
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800152 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800153 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800154 }
155
156 // Add routes for each defined view.
157 viewIds.forEach(function (vid) {
158 if (vid) {
159 $routeProvider.when('/' + vid, {
160 controller: viewCtrlName(vid),
161 controllerAs: 'ctrl',
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000162 templateUrl: viewTemplateUrl(vid),
Simon Hunt9edd1722017-03-10 17:43:26 -0800163
164 // Disable reload on $loc.hash() changes for bookmarked topo regions
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000165 reloadOnSearch: (vid !== 'topo2')
Simon Hunt9edd1722017-03-10 17:43:26 -0800166 // <SDH> assume this is not needed for ?regionId=... query string
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000167 // <SBM> Yes this is still needed. Without it the page will reload when navigating between
168 // regions which loads the new regions without a clean transition to it.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800169 });
170 }
171 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700172 }])
173
174 .directive('detectBrowser', ['$log', 'FnService',
175 function ($log, fs) {
176 return function (scope) {
177 var body = d3.select('body'),
178 browser = '';
179 if (fs.isChrome()) {
180 browser = 'chrome';
181 } else if (fs.isSafari()) {
182 browser = 'safari';
183 } else if (fs.isFirefox()) {
184 browser = 'firefox';
185 }
186 body.classed(browser, true);
187 scope.onos.browser = browser;
188
189 if (fs.isMobile()) {
190 body.classed('mobile', true);
191 scope.onos.mobile = true;
192 }
193
194 $log.debug('Detected browser is', fs.cap(browser));
195 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800196 }]);
197}());