blob: fc4683dbd0834492c591351f5f784e841a3e2f51 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
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
Simon Hunt40927332016-01-22 15:29:47 -080038 // view IDs.. injected via the servlet
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080039 var viewIds = [
Thomas Vachuskaa0509892015-02-21 22:18:41 -080040 // {INJECTED-VIEW-IDS-START}
Thomas Vachuskaa0509892015-02-21 22:18:41 -080041 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080042 // dummy entry
43 ''
44 ];
45
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',
59 '17:7487696973687580739078'
60 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080061 ];
62
Simon Hunt40927332016-01-22 15:29:47 -080063 var defaultView = 'topo',
64 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080065
66 viewIds.forEach(function (id) {
67 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080068 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080069 }
70 });
71
72 var moduleDependencies = coreDependencies.concat(viewDependencies);
73
Simon Huntf4ef6dd2016-02-03 17:05:14 -080074 function saucy(ee, ks) {
75 var map = ee.genMap(sauce);
76 Object.keys(map).forEach(function (k) {
77 ks.addSeq(k, map[k]);
78 });
79 }
80
Simon Hunt40927332016-01-22 15:29:47 -080081 function cap(s) {
82 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080083 }
84
85 angular.module('onosApp', moduleDependencies)
86
87 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070088 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070089 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080090 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070091 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080092
Simon Huntf4ef6dd2016-02-03 17:05:14 -080093 function (_$log_, $scope, $route, $routeParams, $location,
94 ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080095 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -080096 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080097
Thomas Vachuskaa0509892015-02-21 22:18:41 -080098 self.$route = $route;
99 self.$routeParams = $routeParams;
100 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800101 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800102
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700103 // shared object inherited by all views:
104 $scope.onos = {};
105
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800106 // initialize services...
107 ts.init();
108 ks.installOn(d3.select('body'));
109 ks.bindQhs(qhs);
110 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700111 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800112 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800113 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800114 flash.initFlash();
115 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800116
Simon Hunt20207df2015-03-10 18:30:14 -0700117 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700118 wsport: $location.search().wsport
119 });
120
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800121 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800122
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800123 $log.debug('route: ', self.$route);
124 $log.debug('routeParams: ', self.$routeParams);
125 $log.debug('location: ', self.$location);
126 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800127
128 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800129 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800130 $routeProvider
131 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800132 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800133 });
134
135 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800136 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800137 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800138
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800139 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800140 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800141 }
142
143 // Add routes for each defined view.
144 viewIds.forEach(function (vid) {
145 if (vid) {
146 $routeProvider.when('/' + vid, {
147 controller: viewCtrlName(vid),
148 controllerAs: 'ctrl',
149 templateUrl: viewTemplateUrl(vid)
150 });
151 }
152 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700153 }])
154
155 .directive('detectBrowser', ['$log', 'FnService',
156 function ($log, fs) {
157 return function (scope) {
158 var body = d3.select('body'),
159 browser = '';
160 if (fs.isChrome()) {
161 browser = 'chrome';
162 } else if (fs.isSafari()) {
163 browser = 'safari';
164 } else if (fs.isFirefox()) {
165 browser = 'firefox';
166 }
167 body.classed(browser, true);
168 scope.onos.browser = browser;
169
170 if (fs.isMobile()) {
171 body.classed('mobile', true);
172 scope.onos.mobile = true;
173 }
174
175 $log.debug('Detected browser is', fs.cap(browser));
176 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800177 }]);
178}());