| /* |
| * Copyright 2014-present Open Networking Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /* |
| ONOS GUI -- Main Application Module |
| */ |
| (function () { |
| 'use strict'; |
| |
| // injected refs |
| var $log; |
| |
| // define core module dependencies here... |
| var coreDependencies = [ |
| 'ngRoute', |
| 'onosMast', |
| 'onosNav', |
| 'onosUtil', |
| 'onosSvg', |
| 'onosRemote', |
| 'onosLayer', |
| 'onosWidget' |
| ]; |
| |
| // view ID to help page url map.. injected via the servlet |
| var viewMap = { |
| // {INJECTED-VIEW-DATA-START} |
| // {INJECTED-VIEW-DATA-END} |
| }, |
| viewIds = []; |
| |
| // secret sauce |
| var sauce = [ |
| '6:69857666', |
| '9:826970', |
| '22:8069828667', |
| '6:698570688669887967', |
| '7:6971806889847186', |
| '22:8369867682', |
| '13:736583', |
| '7:667186698384', |
| '1:857780888778876787', |
| '20:70717066', |
| '24:886774868469', |
| '17:7487696973687580739078', |
| '14:70777086', |
| '17:7287687967', |
| '11:65678869706783687184', |
| '1:80777778', |
| '9:72696982' |
| // Add more sauce... |
| ]; |
| |
| var defaultView = 'topo', |
| viewDependencies = []; |
| |
| viewIds = d3.map(viewMap).keys(); |
| |
| viewIds.forEach(function (id) { |
| if (id) { |
| viewDependencies.push('ov' + cap(id)); |
| } |
| }); |
| |
| var moduleDependencies = coreDependencies.concat(viewDependencies); |
| |
| function saucy(ee, ks) { |
| var map = ee.genMap(sauce); |
| Object.keys(map).forEach(function (k) { |
| ks.addSeq(k, map[k]); |
| }); |
| } |
| |
| function cap(s) { |
| return s ? s[0].toUpperCase() + s.slice(1) : s; |
| } |
| |
| angular.module('onosApp', moduleDependencies) |
| |
| .controller('OnosCtrl', [ |
| '$log', '$scope', '$route', '$routeParams', '$location', |
| 'LionService', |
| 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
| 'PanelService', 'FlashService', 'QuickHelpService', 'EeService', |
| 'WebSocketService', 'SpriteService', |
| |
| function (_$log_, $scope, $route, $routeParams, $location, |
| lion, ks, ts, gs, vs, ps, flash, qhs, ee, wss, ss) { |
| var self = this; |
| $log = _$log_; |
| |
| self.$route = $route; |
| self.$routeParams = $routeParams; |
| self.$location = $location; |
| self.version = '1.5.0'; |
| |
| // shared object inherited by all views: |
| $scope.onos = {}; |
| $scope.onos['viewMap'] = viewMap; |
| |
| // initialize services... |
| lion.init(); |
| ts.init(); |
| ks.installOn(d3.select('body')); |
| ks.bindQhs(qhs); |
| gs.init(); |
| ss.init(); |
| vs.init(); |
| ps.init(); |
| saucy(ee, ks); |
| flash.initFlash(); |
| qhs.initQuickHelp(); |
| |
| wss.createWebSocket({ |
| wsport: $location.search().wsport |
| }); |
| |
| $log.log('OnosCtrl has been created'); |
| |
| $log.debug('route: ', self.$route); |
| $log.debug('routeParams: ', self.$routeParams); |
| $log.debug('location: ', self.$location); |
| }]) |
| |
| .config(['$routeProvider', function ($routeProvider) { |
| // If view ID not provided, route to the default view |
| $routeProvider |
| .otherwise({ |
| redirectTo: '/' + defaultView |
| }); |
| |
| function viewCtrlName(vid) { |
| return 'Ov' + cap(vid) + 'Ctrl'; |
| } |
| |
| function viewTemplateUrl(vid) { |
| return 'app/view/' + vid + '/' + vid + '.html'; |
| } |
| |
| // Add routes for each defined view. |
| viewIds.forEach(function (vid) { |
| if (vid) { |
| $routeProvider.when('/' + vid, { |
| controller: viewCtrlName(vid), |
| controllerAs: 'ctrl', |
| templateUrl: viewTemplateUrl(vid), |
| |
| // Disable reload on $loc.hash() changes for bookmarked topo regions |
| reloadOnSearch: (vid !== 'topo2') |
| // <SDH> assume this is not needed for ?regionId=... query string |
| // <SBM> Yes this is still needed. Without it the page will reload when navigating between |
| // regions which loads the new regions without a clean transition to it. |
| }); |
| } |
| }); |
| }]) |
| |
| .directive('detectBrowser', ['$log', 'FnService', |
| function ($log, fs) { |
| return function (scope) { |
| var body = d3.select('body'), |
| browser = ''; |
| if (fs.isChrome()) { |
| browser = 'chrome'; |
| } else if (fs.isSafari()) { |
| browser = 'safari'; |
| } else if (fs.isFirefox()) { |
| browser = 'firefox'; |
| } |
| body.classed(browser, true); |
| scope.onos.browser = browser; |
| |
| if (fs.isMobile()) { |
| body.classed('mobile', true); |
| scope.onos.mobile = true; |
| } |
| |
| $log.debug('Detected browser is', fs.cap(browser)); |
| }; |
| }]); |
| }()); |