Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 2 | * Copyright 2014-2016 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 | |
| 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 Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 36 | // view IDs.. injected via the servlet |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 37 | var viewIds = [ |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 38 | // {INJECTED-VIEW-IDS-START} |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 39 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 40 | // dummy entry |
| 41 | '' |
| 42 | ]; |
| 43 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 44 | var defaultView = 'topo', |
| 45 | viewDependencies = []; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 46 | |
| 47 | viewIds.forEach(function (id) { |
| 48 | if (id) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 49 | viewDependencies.push('ov' + cap(id)); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 50 | } |
| 51 | }); |
| 52 | |
| 53 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 54 | |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 55 | function cap(s) { |
| 56 | return s ? s[0].toUpperCase() + s.slice(1) : s; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | angular.module('onosApp', moduleDependencies) |
| 60 | |
| 61 | .controller('OnosCtrl', [ |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 62 | '$log', '$scope', '$route', '$routeParams', '$location', |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 63 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
| 64 | 'PanelService', 'FlashService', 'QuickHelpService', |
| 65 | 'WebSocketService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 66 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 67 | function ($log, $scope, $route, $routeParams, $location, |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 68 | ks, ts, gs, vs, ps, flash, qhs, wss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 69 | var self = this; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 70 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 71 | self.$route = $route; |
| 72 | self.$routeParams = $routeParams; |
| 73 | self.$location = $location; |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 74 | self.version = '1.3.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 75 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 76 | // shared object inherited by all views: |
| 77 | $scope.onos = {}; |
| 78 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 79 | // initialize services... |
| 80 | ts.init(); |
| 81 | ks.installOn(d3.select('body')); |
| 82 | ks.bindQhs(qhs); |
| 83 | gs.init(); |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 84 | vs.init(); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 85 | ps.init(); |
| 86 | flash.initFlash(); |
| 87 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 88 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 89 | wss.createWebSocket({ |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 90 | wsport: $location.search().wsport |
| 91 | }); |
| 92 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 93 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 94 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 95 | $log.debug('route: ', self.$route); |
| 96 | $log.debug('routeParams: ', self.$routeParams); |
| 97 | $log.debug('location: ', self.$location); |
| 98 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 99 | |
| 100 | .config(['$routeProvider', function ($routeProvider) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 101 | // If view ID not provided, route to the default view |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 102 | $routeProvider |
| 103 | .otherwise({ |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 104 | redirectTo: '/' + defaultView |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 105 | }); |
| 106 | |
| 107 | function viewCtrlName(vid) { |
Simon Hunt | 4092733 | 2016-01-22 15:29:47 -0800 | [diff] [blame] | 108 | return 'Ov' + cap(vid) + 'Ctrl'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 109 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 110 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 111 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 112 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 113 | } |
| 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 Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 125 | }]) |
| 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 Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 149 | }]); |
| 150 | }()); |