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 | |
| 36 | // view IDs.. note the first view listed is loaded at startup |
| 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 | 'topo', |
| 40 | 'device', |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 41 | 'flow', |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 42 | 'port', |
Bri Prebilic Cole | ff3dc67 | 2015-05-06 12:59:38 -0700 | [diff] [blame] | 43 | 'group', |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 44 | 'meter', |
Thomas Vachuska | e586b79 | 2015-03-26 13:59:38 -0700 | [diff] [blame] | 45 | 'host', |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 46 | 'app', |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 47 | 'intent', |
Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 48 | 'cluster', |
Bri Prebilic Cole | 9fb594a | 2015-04-14 09:15:54 -0700 | [diff] [blame] | 49 | 'link', |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 50 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 51 | |
| 52 | // dummy entry |
| 53 | '' |
| 54 | ]; |
| 55 | |
| 56 | var viewDependencies = []; |
| 57 | |
| 58 | viewIds.forEach(function (id) { |
| 59 | if (id) { |
| 60 | viewDependencies.push('ov' + capitalize(id)); |
| 61 | } |
| 62 | }); |
| 63 | |
| 64 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 65 | |
| 66 | function capitalize(word) { |
| 67 | return word ? word[0].toUpperCase() + word.slice(1) : word; |
| 68 | } |
| 69 | |
| 70 | angular.module('onosApp', moduleDependencies) |
| 71 | |
| 72 | .controller('OnosCtrl', [ |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 73 | '$log', '$scope', '$route', '$routeParams', '$location', |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 74 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
| 75 | 'PanelService', 'FlashService', 'QuickHelpService', |
| 76 | 'WebSocketService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 77 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 78 | function ($log, $scope, $route, $routeParams, $location, |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 79 | ks, ts, gs, vs, ps, flash, qhs, wss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 80 | var self = this; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 81 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 82 | self.$route = $route; |
| 83 | self.$routeParams = $routeParams; |
| 84 | self.$location = $location; |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 85 | self.version = '1.3.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 86 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 87 | // shared object inherited by all views: |
| 88 | $scope.onos = {}; |
| 89 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 90 | // initialize services... |
| 91 | ts.init(); |
| 92 | ks.installOn(d3.select('body')); |
| 93 | ks.bindQhs(qhs); |
| 94 | gs.init(); |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 95 | vs.init(); |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 96 | ps.init(); |
| 97 | flash.initFlash(); |
| 98 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 99 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 100 | // TODO: register handler for user settings, etc. |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 101 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 102 | wss.createWebSocket({ |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 103 | wsport: $location.search().wsport |
| 104 | }); |
| 105 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 106 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 107 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 108 | $log.debug('route: ', self.$route); |
| 109 | $log.debug('routeParams: ', self.$routeParams); |
| 110 | $log.debug('location: ', self.$location); |
| 111 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 112 | |
| 113 | .config(['$routeProvider', function ($routeProvider) { |
| 114 | // If view ID not provided, route to the first view in the list. |
| 115 | $routeProvider |
| 116 | .otherwise({ |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 117 | redirectTo: '/topo' |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 118 | }); |
| 119 | |
| 120 | function viewCtrlName(vid) { |
| 121 | return 'Ov' + capitalize(vid) + 'Ctrl'; |
| 122 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 123 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 124 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 125 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // Add routes for each defined view. |
| 129 | viewIds.forEach(function (vid) { |
| 130 | if (vid) { |
| 131 | $routeProvider.when('/' + vid, { |
| 132 | controller: viewCtrlName(vid), |
| 133 | controllerAs: 'ctrl', |
| 134 | templateUrl: viewTemplateUrl(vid) |
| 135 | }); |
| 136 | } |
| 137 | }); |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 138 | }]) |
| 139 | |
| 140 | .directive('detectBrowser', ['$log', 'FnService', |
| 141 | function ($log, fs) { |
| 142 | return function (scope) { |
| 143 | var body = d3.select('body'), |
| 144 | browser = ''; |
| 145 | if (fs.isChrome()) { |
| 146 | browser = 'chrome'; |
| 147 | } else if (fs.isSafari()) { |
| 148 | browser = 'safari'; |
| 149 | } else if (fs.isFirefox()) { |
| 150 | browser = 'firefox'; |
| 151 | } |
| 152 | body.classed(browser, true); |
| 153 | scope.onos.browser = browser; |
| 154 | |
| 155 | if (fs.isMobile()) { |
| 156 | body.classed('mobile', true); |
| 157 | scope.onos.mobile = true; |
| 158 | } |
| 159 | |
| 160 | $log.debug('Detected browser is', fs.cap(browser)); |
| 161 | }; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 162 | }]); |
| 163 | }()); |