blob: 2fffb2400f4908added400fb0427eb9feb65342f [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
24 // define core module dependencies here...
25 var coreDependencies = [
26 'ngRoute',
27 'onosMast',
28 'onosNav',
29 'onosUtil',
30 'onosSvg',
31 'onosRemote',
32 'onosLayer',
33 'onosWidget'
34 ];
35
Simon Hunt40927332016-01-22 15:29:47 -080036 // view IDs.. injected via the servlet
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080037 var viewIds = [
Thomas Vachuskaa0509892015-02-21 22:18:41 -080038 // {INJECTED-VIEW-IDS-START}
Thomas Vachuskaa0509892015-02-21 22:18:41 -080039 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080040 // dummy entry
41 ''
42 ];
43
Simon Hunt40927332016-01-22 15:29:47 -080044 var defaultView = 'topo',
45 viewDependencies = [];
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080046
47 viewIds.forEach(function (id) {
48 if (id) {
Simon Hunt40927332016-01-22 15:29:47 -080049 viewDependencies.push('ov' + cap(id));
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080050 }
51 });
52
53 var moduleDependencies = coreDependencies.concat(viewDependencies);
54
Simon Hunt40927332016-01-22 15:29:47 -080055 function cap(s) {
56 return s ? s[0].toUpperCase() + s.slice(1) : s;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080057 }
58
59 angular.module('onosApp', moduleDependencies)
60
61 .controller('OnosCtrl', [
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070062 '$log', '$scope', '$route', '$routeParams', '$location',
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070063 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
64 'PanelService', 'FlashService', 'QuickHelpService',
65 'WebSocketService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080066
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070067 function ($log, $scope, $route, $routeParams, $location,
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070068 ks, ts, gs, vs, ps, flash, qhs, wss) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -080069 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080070
Thomas Vachuskaa0509892015-02-21 22:18:41 -080071 self.$route = $route;
72 self.$routeParams = $routeParams;
73 self.$location = $location;
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -070074 self.version = '1.3.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080075
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -070076 // shared object inherited by all views:
77 $scope.onos = {};
78
Thomas Vachuskaa0509892015-02-21 22:18:41 -080079 // initialize services...
80 ts.init();
81 ks.installOn(d3.select('body'));
82 ks.bindQhs(qhs);
83 gs.init();
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070084 vs.init();
Thomas Vachuskaa0509892015-02-21 22:18:41 -080085 ps.init();
86 flash.initFlash();
87 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080088
Simon Hunt20207df2015-03-10 18:30:14 -070089 wss.createWebSocket({
Thomas Vachuska329af532015-03-10 02:08:33 -070090 wsport: $location.search().wsport
91 });
92
Thomas Vachuskaa0509892015-02-21 22:18:41 -080093 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080094
Thomas Vachuskaa0509892015-02-21 22:18:41 -080095 $log.debug('route: ', self.$route);
96 $log.debug('routeParams: ', self.$routeParams);
97 $log.debug('location: ', self.$location);
98 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080099
100 .config(['$routeProvider', function ($routeProvider) {
Simon Hunt40927332016-01-22 15:29:47 -0800101 // If view ID not provided, route to the default view
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800102 $routeProvider
103 .otherwise({
Simon Hunt40927332016-01-22 15:29:47 -0800104 redirectTo: '/' + defaultView
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800105 });
106
107 function viewCtrlName(vid) {
Simon Hunt40927332016-01-22 15:29:47 -0800108 return 'Ov' + cap(vid) + 'Ctrl';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800109 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800110
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800111 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800112 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800113 }
114
115 // Add routes for each defined view.
116 viewIds.forEach(function (vid) {
117 if (vid) {
118 $routeProvider.when('/' + vid, {
119 controller: viewCtrlName(vid),
120 controllerAs: 'ctrl',
121 templateUrl: viewTemplateUrl(vid)
122 });
123 }
124 });
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700125 }])
126
127 .directive('detectBrowser', ['$log', 'FnService',
128 function ($log, fs) {
129 return function (scope) {
130 var body = d3.select('body'),
131 browser = '';
132 if (fs.isChrome()) {
133 browser = 'chrome';
134 } else if (fs.isSafari()) {
135 browser = 'safari';
136 } else if (fs.isFirefox()) {
137 browser = 'firefox';
138 }
139 body.classed(browser, true);
140 scope.onos.browser = browser;
141
142 if (fs.isMobile()) {
143 body.classed('mobile', true);
144 scope.onos.mobile = true;
145 }
146
147 $log.debug('Detected browser is', fs.cap(browser));
148 };
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800149 }]);
150}());