blob: 2e62744a13d24fa8ae6baeeb5d344b797a941e8a [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
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',
58 '17:7487696973687580739078'
59 // Add more sauce...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080060 ];
61
Simon Hunt40927332016-01-22 15:29:47 -080062 var defaultView = 'topo',
63 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080064
chengfan386620e2016-11-09 17:02:40 +080065 viewIds = d3.map(viewMap).keys();
66
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080067 viewIds.forEach(function (id) {
68 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080069 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080070 }
71 });
72
73 var moduleDependencies = coreDependencies.concat(viewDependencies);
74
Simon Huntf4ef6dd2016-02-03 17:05:14 -080075 function saucy(ee, ks) {
76 var map = ee.genMap(sauce);
77 Object.keys(map).forEach(function (k) {
78 ks.addSeq(k, map[k]);
79 });
80 }
81
Simon Hunt40927332016-01-22 15:29:47 -080082 function cap(s) {
83 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080084 }
85
86 angular.module('onosApp', moduleDependencies)
87
88 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070089 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070090 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080091 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070092 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080093
Simon Huntf4ef6dd2016-02-03 17:05:14 -080094 function (_$log_, $scope, $route, $routeParams, $location,
95 ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080096 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -080097 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080098
Thomas Vachuskaa0509892015-02-21 22:18:41 -080099 self.$route = $route;
100 self.$routeParams = $routeParams;
101 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800102 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800103
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700104 // shared object inherited by all views:
105 $scope.onos = {};
chengfan386620e2016-11-09 17:02:40 +0800106 $scope.onos['viewMap'] = viewMap;
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700107
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800108 // initialize services...
109 ts.init();
110 ks.installOn(d3.select('body'));
111 ks.bindQhs(qhs);
112 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700113 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800114 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800115 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800116 flash.initFlash();
117 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800118
Simon Hunt20207df2015-03-10 18:30:14 -0700119 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700120 wsport: $location.search().wsport
121 });
122
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800123 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800124
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800125 $log.debug('route: ', self.$route);
126 $log.debug('routeParams: ', self.$routeParams);
127 $log.debug('location: ', self.$location);
128 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800129
130 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800131 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800132 $routeProvider
133 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800134 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800135 });
136
137 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800138 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800139 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800140
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800141 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800142 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800143 }
144
145 // Add routes for each defined view.
146 viewIds.forEach(function (vid) {
147 if (vid) {
148 $routeProvider.when('/' + vid, {
149 controller: viewCtrlName(vid),
150 controllerAs: 'ctrl',
151 templateUrl: viewTemplateUrl(vid)
152 });
153 }
154 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700155 }])
156
157 .directive('detectBrowser', ['$log', 'FnService',
158 function ($log, fs) {
159 return function (scope) {
160 var body = d3.select('body'),
161 browser = '';
162 if (fs.isChrome()) {
163 browser = 'chrome';
164 } else if (fs.isSafari()) {
165 browser = 'safari';
166 } else if (fs.isFirefox()) {
167 browser = 'firefox';
168 }
169 body.classed(browser, true);
170 scope.onos.browser = browser;
171
172 if (fs.isMobile()) {
173 body.classed('mobile', true);
174 scope.onos.mobile = true;
175 }
176
177 $log.debug('Detected browser is', fs.cap(browser));
178 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800179 }]);
180}());