Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 3 | * |
| 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 Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 24 | // injected refs |
| 25 | var $log; |
| 26 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 27 | // 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 Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 39 | // view IDs.. injected via the servlet |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 40 | var viewIds = [ |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 41 | // {INJECTED-VIEW-IDS-START} |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 42 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 43 | // dummy entry |
| 44 | '' |
| 45 | ]; |
| 46 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 47 | // secret sauce |
| 48 | var sauce = [ |
Simon Hunt | fedd175 | 2016-02-11 14:37:26 -0800 | [diff] [blame] | 49 | '6:69857666', |
| 50 | '9:826970', |
| 51 | '22:8069828667', |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 52 | '6:698570688669887967', |
| 53 | '7:6971806889847186', |
| 54 | '22:8369867682', |
| 55 | '13:736583', |
| 56 | '7:667186698384', |
Simon Hunt | fedd175 | 2016-02-11 14:37:26 -0800 | [diff] [blame] | 57 | '1:857780888778876787', |
| 58 | '20:70717066', |
| 59 | '24:886774868469' |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 60 | ]; |
| 61 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 62 | var defaultView = 'topo', |
| 63 | viewDependencies = []; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 64 | |
| 65 | viewIds.forEach(function (id) { |
| 66 | if (id) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 67 | viewDependencies.push('ov' + cap(id)); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 68 | } |
| 69 | }); |
| 70 | |
| 71 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 72 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 73 | function saucy(ee, ks) { |
| 74 | var map = ee.genMap(sauce); |
| 75 | Object.keys(map).forEach(function (k) { |
| 76 | ks.addSeq(k, map[k]); |
| 77 | }); |
| 78 | } |
| 79 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 80 | function cap(s) { |
| 81 | return s ? s[0].toUpperCase() + s.slice(1) : s; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | angular.module('onosApp', moduleDependencies) |
| 85 | |
| 86 | .controller('OnosCtrl', [ |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 87 | '$log', '$scope', '$route', '$routeParams', '$location', |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 88 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 89 | 'PanelService', 'FlashService', 'QuickHelpService', 'EeService', |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 90 | 'WebSocketService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 91 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 92 | function (_$log_, $scope, $route, $routeParams, $location, |
| 93 | ks, ts, gs, vs, ps, flash, qhs, ee, wss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 94 | var self = this; |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 95 | $log = _$log_; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 96 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 97 | self.$route = $route; |
| 98 | self.$routeParams = $routeParams; |
| 99 | self.$location = $location; |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 100 | self.version = '1.5.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 101 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 102 | // shared object inherited by all views: |
| 103 | $scope.onos = {}; |
| 104 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 105 | // initialize services... |
| 106 | ts.init(); |
| 107 | ks.installOn(d3.select('body')); |
| 108 | ks.bindQhs(qhs); |
| 109 | gs.init(); |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 110 | vs.init(); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 111 | ps.init(); |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 112 | saucy(ee, ks); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 113 | flash.initFlash(); |
| 114 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 115 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 116 | wss.createWebSocket({ |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 117 | wsport: $location.search().wsport |
| 118 | }); |
| 119 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 120 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 121 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 122 | $log.debug('route: ', self.$route); |
| 123 | $log.debug('routeParams: ', self.$routeParams); |
| 124 | $log.debug('location: ', self.$location); |
| 125 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 126 | |
| 127 | .config(['$routeProvider', function ($routeProvider) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 128 | // If view ID not provided, route to the default view |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 129 | $routeProvider |
| 130 | .otherwise({ |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 131 | redirectTo: '/' + defaultView |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 132 | }); |
| 133 | |
| 134 | function viewCtrlName(vid) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 135 | return 'Ov' + cap(vid) + 'Ctrl'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 136 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 137 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 138 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 139 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // Add routes for each defined view. |
| 143 | viewIds.forEach(function (vid) { |
| 144 | if (vid) { |
| 145 | $routeProvider.when('/' + vid, { |
| 146 | controller: viewCtrlName(vid), |
| 147 | controllerAs: 'ctrl', |
| 148 | templateUrl: viewTemplateUrl(vid) |
| 149 | }); |
| 150 | } |
| 151 | }); |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 152 | }]) |
| 153 | |
| 154 | .directive('detectBrowser', ['$log', 'FnService', |
| 155 | function ($log, fs) { |
| 156 | return function (scope) { |
| 157 | var body = d3.select('body'), |
| 158 | browser = ''; |
| 159 | if (fs.isChrome()) { |
| 160 | browser = 'chrome'; |
| 161 | } else if (fs.isSafari()) { |
| 162 | browser = 'safari'; |
| 163 | } else if (fs.isFirefox()) { |
| 164 | browser = 'firefox'; |
| 165 | } |
| 166 | body.classed(browser, true); |
| 167 | scope.onos.browser = browser; |
| 168 | |
| 169 | if (fs.isMobile()) { |
| 170 | body.classed('mobile', true); |
| 171 | scope.onos.mobile = true; |
| 172 | } |
| 173 | |
| 174 | $log.debug('Detected browser is', fs.cap(browser)); |
| 175 | }; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 176 | }]); |
| 177 | }()); |