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