blob: b48a88fcc71cb59e0feb767a62295299686ef9bf [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',
65 '7:857165828967'
Simon Huntb8d37982016-08-22 21:29:55 -070066 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080067 ];
68
Simon Hunt40927332016-01-22 15:29:47 -080069 var defaultView = 'topo',
70 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080071
chengfan386620e2016-11-09 17:02:40 +080072 viewIds = d3.map(viewMap).keys();
73
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080074 viewIds.forEach(function (id) {
75 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080076 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077 }
78 });
79
80 var moduleDependencies = coreDependencies.concat(viewDependencies);
81
Simon Huntf4ef6dd2016-02-03 17:05:14 -080082 function saucy(ee, ks) {
83 var map = ee.genMap(sauce);
84 Object.keys(map).forEach(function (k) {
85 ks.addSeq(k, map[k]);
86 });
87 }
88
Simon Hunt40927332016-01-22 15:29:47 -080089 function cap(s) {
90 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080091 }
92
93 angular.module('onosApp', moduleDependencies)
94
95 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070096 '$log', '$scope', '$route', '$routeParams', '$location',
Simon Huntc1656ed2017-06-21 16:47:04 -070097 'LionService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070098 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080099 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Simon Hunta1028c42017-02-07 20:08:03 -0800100 'WebSocketService', 'SpriteService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800101
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800102 function (_$log_, $scope, $route, $routeParams, $location,
Simon Huntc1656ed2017-06-21 16:47:04 -0700103 lion, ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800104 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800105 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800106
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800107 self.$route = $route;
108 self.$routeParams = $routeParams;
109 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800110 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800111
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700112 // shared object inherited by all views:
113 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800114 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700115
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800116 // initialize services...
Simon Huntc1656ed2017-06-21 16:47:04 -0700117 lion.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800118 ts.init();
119 ks.installOn(d3.select('body'));
120 ks.bindQhs(qhs);
121 gs.init();
Simon Hunta1028c42017-02-07 20:08:03 -0800122 ss.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700123 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800124 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800125 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800126 flash.initFlash();
127 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800128
Simon Hunt20207df2015-03-10 18:30:14 -0700129 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700130 wsport: $location.search().wsport
131 });
132
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800133 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800134
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800135 $log.debug('route: ', self.$route);
136 $log.debug('routeParams: ', self.$routeParams);
137 $log.debug('location: ', self.$location);
138 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800139
140 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800141 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800142 $routeProvider
143 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800144 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800145 });
146
147 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800148 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800149 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800150
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800151 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800152 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800153 }
154
155 // Add routes for each defined view.
156 viewIds.forEach(function (vid) {
157 if (vid) {
158 $routeProvider.when('/' + vid, {
159 controller: viewCtrlName(vid),
160 controllerAs: 'ctrl',
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000161 templateUrl: viewTemplateUrl(vid),
Simon Hunt9edd1722017-03-10 17:43:26 -0800162
163 // Disable reload on $loc.hash() changes for bookmarked topo regions
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000164 reloadOnSearch: (vid !== 'topo2')
Simon Hunt9edd1722017-03-10 17:43:26 -0800165 // <SDH> assume this is not needed for ?regionId=... query string
Steven Burrowsf303c1e2017-03-13 12:26:22 +0000166 // <SBM> Yes this is still needed. Without it the page will reload when navigating between
167 // regions which loads the new regions without a clean transition to it.
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800168 });
169 }
170 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700171 }])
172
173 .directive('detectBrowser', ['$log', 'FnService',
174 function ($log, fs) {
175 return function (scope) {
176 var body = d3.select('body'),
177 browser = '';
178 if (fs.isChrome()) {
179 browser = 'chrome';
180 } else if (fs.isSafari()) {
181 browser = 'safari';
182 } else if (fs.isFirefox()) {
183 browser = 'firefox';
184 }
185 body.classed(browser, true);
186 scope.onos.browser = browser;
187
188 if (fs.isMobile()) {
189 body.classed('mobile', true);
190 scope.onos.mobile = true;
191 }
192
193 $log.debug('Detected browser is', fs.cap(browser));
194 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800195 }]);
196}());