Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 2 | * Copyright 2014,2015 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', |
Thomas Vachuska | ef64676 | 2015-03-17 15:19:03 -0700 | [diff] [blame] | 41 | 'sample', |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 42 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 43 | |
| 44 | // dummy entry |
| 45 | '' |
| 46 | ]; |
| 47 | |
| 48 | var viewDependencies = []; |
| 49 | |
| 50 | viewIds.forEach(function (id) { |
| 51 | if (id) { |
| 52 | viewDependencies.push('ov' + capitalize(id)); |
| 53 | } |
| 54 | }); |
| 55 | |
| 56 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 57 | |
| 58 | function capitalize(word) { |
| 59 | return word ? word[0].toUpperCase() + word.slice(1) : word; |
| 60 | } |
| 61 | |
| 62 | angular.module('onosApp', moduleDependencies) |
| 63 | |
| 64 | .controller('OnosCtrl', [ |
| 65 | '$log', '$route', '$routeParams', '$location', |
| 66 | 'KeyService', 'ThemeService', 'GlyphService', 'PanelService', |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 67 | 'FlashService', 'QuickHelpService', 'WebSocketService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 68 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 69 | function ($log, $route, $routeParams, $location, |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 70 | ks, ts, gs, ps, flash, qhs, wss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 71 | var self = this; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 72 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 73 | self.$route = $route; |
| 74 | self.$routeParams = $routeParams; |
| 75 | self.$location = $location; |
| 76 | self.version = '1.1.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 77 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 78 | // initialize services... |
| 79 | ts.init(); |
| 80 | ks.installOn(d3.select('body')); |
| 81 | ks.bindQhs(qhs); |
| 82 | gs.init(); |
| 83 | ps.init(); |
| 84 | flash.initFlash(); |
| 85 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 86 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 87 | // TODO: register handler for user settings, etc. |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [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) { |
| 101 | // If view ID not provided, route to the first view in the list. |
| 102 | $routeProvider |
| 103 | .otherwise({ |
| 104 | redirectTo: '/' + viewIds[0] |
| 105 | }); |
| 106 | |
| 107 | function viewCtrlName(vid) { |
| 108 | return 'Ov' + capitalize(vid) + 'Ctrl'; |
| 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 | }); |
| 125 | }]); |
| 126 | }()); |