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 | */ |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 23 | // injected refs |
| 24 | var $log; |
| 25 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 26 | // 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 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 38 | // 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 Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 44 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 45 | // secret sauce |
| 46 | var sauce = [ |
Simon Hunt | fedd175 | 2016-02-11 14:37:26 -0800 | [diff] [blame] | 47 | '6:69857666', |
| 48 | '9:826970', |
| 49 | '22:8069828667', |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 50 | '6:698570688669887967', |
| 51 | '7:6971806889847186', |
| 52 | '22:8369867682', |
| 53 | '13:736583', |
| 54 | '7:667186698384', |
Simon Hunt | fedd175 | 2016-02-11 14:37:26 -0800 | [diff] [blame] | 55 | '1:857780888778876787', |
| 56 | '20:70717066', |
Simon Hunt | b8d3798 | 2016-08-22 21:29:55 -0700 | [diff] [blame] | 57 | '24:886774868469', |
Viswanath KSP | 0cf084b | 2016-11-19 18:17:55 +0530 | [diff] [blame] | 58 | '17:7487696973687580739078', |
Viswanath KSP | 539427f | 2016-12-21 19:08:08 +0530 | [diff] [blame] | 59 | '14:70777086', |
| 60 | '17:7287687967' |
Simon Hunt | b8d3798 | 2016-08-22 21:29:55 -0700 | [diff] [blame] | 61 | // Add more sauce... |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 62 | ]; |
| 63 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 64 | var defaultView = 'topo', |
| 65 | viewDependencies = []; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 66 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 67 | viewIds = d3.map(viewMap).keys(); |
| 68 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 69 | viewIds.forEach(function (id) { |
| 70 | if (id) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 71 | viewDependencies.push('ov' + cap(id)); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 72 | } |
| 73 | }); |
| 74 | |
| 75 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 76 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 77 | function saucy(ee, ks) { |
| 78 | var map = ee.genMap(sauce); |
| 79 | Object.keys(map).forEach(function (k) { |
| 80 | ks.addSeq(k, map[k]); |
| 81 | }); |
| 82 | } |
| 83 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 84 | function cap(s) { |
| 85 | return s ? s[0].toUpperCase() + s.slice(1) : s; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | angular.module('onosApp', moduleDependencies) |
| 89 | |
| 90 | .controller('OnosCtrl', [ |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 91 | '$log', '$scope', '$route', '$routeParams', '$location', |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 92 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 93 | 'PanelService', 'FlashService', 'QuickHelpService', 'EeService', |
Simon Hunt | a1028c4 | 2017-02-07 20:08:03 -0800 | [diff] [blame] | 94 | 'WebSocketService', 'SpriteService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 95 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 96 | function (_$log_, $scope, $route, $routeParams, $location, |
Simon Hunt | a1028c4 | 2017-02-07 20:08:03 -0800 | [diff] [blame] | 97 | ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 98 | var self = this; |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 99 | $log = _$log_; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 100 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 101 | self.$route = $route; |
| 102 | self.$routeParams = $routeParams; |
| 103 | self.$location = $location; |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 104 | self.version = '1.5.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 105 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 106 | // shared object inherited by all views: |
| 107 | $scope.onos = {}; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 108 | $scope.onos['viewMap'] = viewMap; |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 109 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 110 | // initialize services... |
| 111 | ts.init(); |
| 112 | ks.installOn(d3.select('body')); |
| 113 | ks.bindQhs(qhs); |
| 114 | gs.init(); |
Simon Hunt | a1028c4 | 2017-02-07 20:08:03 -0800 | [diff] [blame] | 115 | ss.init(); |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 116 | vs.init(); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 117 | ps.init(); |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 118 | saucy(ee, ks); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 119 | flash.initFlash(); |
| 120 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 121 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 122 | wss.createWebSocket({ |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 123 | wsport: $location.search().wsport |
| 124 | }); |
| 125 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 126 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 127 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 128 | $log.debug('route: ', self.$route); |
| 129 | $log.debug('routeParams: ', self.$routeParams); |
| 130 | $log.debug('location: ', self.$location); |
| 131 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 132 | |
| 133 | .config(['$routeProvider', function ($routeProvider) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 134 | // If view ID not provided, route to the default view |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 135 | $routeProvider |
| 136 | .otherwise({ |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 137 | redirectTo: '/' + defaultView |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 138 | }); |
| 139 | |
| 140 | function viewCtrlName(vid) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 141 | return 'Ov' + cap(vid) + 'Ctrl'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 142 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 143 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 144 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 145 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // Add routes for each defined view. |
| 149 | viewIds.forEach(function (vid) { |
| 150 | if (vid) { |
| 151 | $routeProvider.when('/' + vid, { |
| 152 | controller: viewCtrlName(vid), |
| 153 | controllerAs: 'ctrl', |
Steven Burrows | f303c1e | 2017-03-13 12:26:22 +0000 | [diff] [blame] | 154 | templateUrl: viewTemplateUrl(vid), |
Simon Hunt | 9edd172 | 2017-03-10 17:43:26 -0800 | [diff] [blame] | 155 | |
| 156 | // Disable reload on $loc.hash() changes for bookmarked topo regions |
Steven Burrows | f303c1e | 2017-03-13 12:26:22 +0000 | [diff] [blame] | 157 | reloadOnSearch: (vid !== 'topo2') |
Simon Hunt | 9edd172 | 2017-03-10 17:43:26 -0800 | [diff] [blame] | 158 | // <SDH> assume this is not needed for ?regionId=... query string |
Steven Burrows | f303c1e | 2017-03-13 12:26:22 +0000 | [diff] [blame] | 159 | // <SBM> Yes this is still needed. Without it the page will reload when navigating between |
| 160 | // regions which loads the new regions without a clean transition to it. |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 161 | }); |
| 162 | } |
| 163 | }); |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 164 | }]) |
| 165 | |
| 166 | .directive('detectBrowser', ['$log', 'FnService', |
| 167 | function ($log, fs) { |
| 168 | return function (scope) { |
| 169 | var body = d3.select('body'), |
| 170 | browser = ''; |
| 171 | if (fs.isChrome()) { |
| 172 | browser = 'chrome'; |
| 173 | } else if (fs.isSafari()) { |
| 174 | browser = 'safari'; |
| 175 | } else if (fs.isFirefox()) { |
| 176 | browser = 'firefox'; |
| 177 | } |
| 178 | body.classed(browser, true); |
| 179 | scope.onos.browser = browser; |
| 180 | |
| 181 | if (fs.isMobile()) { |
| 182 | body.classed('mobile', true); |
| 183 | scope.onos.mobile = true; |
| 184 | } |
| 185 | |
| 186 | $log.debug('Detected browser is', fs.cap(browser)); |
| 187 | }; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 188 | }]); |
| 189 | }()); |