blob: 9d344337168daebbfa3fdf2ab1a577a9c0a5670e [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Jian Li1f544732015-12-30 23:36:37 -08002 * Copyright 2014-2016 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 */
20
21(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
Simon Hunt40927332016-01-22 15:29:47 -080039 // view IDs.. injected via the servlet
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080040 var viewIds = [
Thomas Vachuskaa0509892015-02-21 22:18:41 -080041 // {INJECTED-VIEW-IDS-START}
Thomas Vachuskaa0509892015-02-21 22:18:41 -080042 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080043 // dummy entry
44 ''
45 ];
46
Simon Huntf4ef6dd2016-02-03 17:05:14 -080047 // secret sauce
48 var sauce = [
49 '20:70717066',
50 '24:886774868469',
51 '6:698570688669887967',
52 '7:6971806889847186',
53 '22:8369867682',
54 '13:736583',
55 '7:667186698384',
56 '1:857780888778876787'
57 ];
58
Simon Hunt40927332016-01-22 15:29:47 -080059 var defaultView = 'topo',
60 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080061
62 viewIds.forEach(function (id) {
63 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080064 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080065 }
66 });
67
68 var moduleDependencies = coreDependencies.concat(viewDependencies);
69
Simon Huntf4ef6dd2016-02-03 17:05:14 -080070 function saucy(ee, ks) {
71 var map = ee.genMap(sauce);
72 Object.keys(map).forEach(function (k) {
73 ks.addSeq(k, map[k]);
74 });
75 }
76
Simon Hunt40927332016-01-22 15:29:47 -080077 function cap(s) {
78 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080079 }
80
81 angular.module('onosApp', moduleDependencies)
82
83 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070084 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070085 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
Simon Huntf4ef6dd2016-02-03 17:05:14 -080086 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070087 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080088
Simon Huntf4ef6dd2016-02-03 17:05:14 -080089 function (_$log_, $scope, $route, $routeParams, $location,
90 ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080091 var self = this;
Simon Huntf4ef6dd2016-02-03 17:05:14 -080092 $log = _$log_;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080093
Thomas Vachuskaa0509892015-02-21 22:18:41 -080094 self.$route = $route;
95 self.$routeParams = $routeParams;
96 self.$location = $location;
Simon Huntf4ef6dd2016-02-03 17:05:14 -080097 self.version = '1.5.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080098
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070099 // shared object inherited by all views:
100 $scope.onos = {};
101
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800102 // initialize services...
103 ts.init();
104 ks.installOn(d3.select('body'));
105 ks.bindQhs(qhs);
106 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700107 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800108 ps.init();
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800109 saucy(ee, ks);
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800110 flash.initFlash();
111 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800112
Simon Hunt20207df2015-03-10 18:30:14 -0700113 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -0700114 wsport: $location.search().wsport
115 });
116
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800117 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800118
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800119 $log.debug('route: ', self.$route);
120 $log.debug('routeParams: ', self.$routeParams);
121 $log.debug('location: ', self.$location);
122 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800123
124 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800125 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800126 $routeProvider
127 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800128 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800129 });
130
131 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800132 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800133 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800134
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800135 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800136 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800137 }
138
139 // Add routes for each defined view.
140 viewIds.forEach(function (vid) {
141 if (vid) {
142 $routeProvider.when('/' + vid, {
143 controller: viewCtrlName(vid),
144 controllerAs: 'ctrl',
145 templateUrl: viewTemplateUrl(vid)
146 });
147 }
148 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700149 }])
150
151 .directive('detectBrowser', ['$log', 'FnService',
152 function ($log, fs) {
153 return function (scope) {
154 var body = d3.select('body'),
155 browser = '';
156 if (fs.isChrome()) {
157 browser = 'chrome';
158 } else if (fs.isSafari()) {
159 browser = 'safari';
160 } else if (fs.isFirefox()) {
161 browser = 'firefox';
162 }
163 body.classed(browser, true);
164 scope.onos.browser = browser;
165
166 if (fs.isMobile()) {
167 body.classed('mobile', true);
168 scope.onos.mobile = true;
169 }
170
171 $log.debug('Detected browser is', fs.cap(browser));
172 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800173 }]);
174}());