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