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 | e586b79 | 2015-03-26 13:59:38 -0700 | [diff] [blame] | 41 | 'host', |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 42 | 'app', |
Thomas Vachuska | ef64676 | 2015-03-17 15:19:03 -0700 | [diff] [blame] | 43 | 'sample', |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 44 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 45 | |
| 46 | // dummy entry |
| 47 | '' |
| 48 | ]; |
| 49 | |
| 50 | var viewDependencies = []; |
| 51 | |
| 52 | viewIds.forEach(function (id) { |
| 53 | if (id) { |
| 54 | viewDependencies.push('ov' + capitalize(id)); |
| 55 | } |
| 56 | }); |
| 57 | |
| 58 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 59 | |
| 60 | function capitalize(word) { |
| 61 | return word ? word[0].toUpperCase() + word.slice(1) : word; |
| 62 | } |
| 63 | |
| 64 | angular.module('onosApp', moduleDependencies) |
| 65 | |
| 66 | .controller('OnosCtrl', [ |
| 67 | '$log', '$route', '$routeParams', '$location', |
| 68 | 'KeyService', 'ThemeService', 'GlyphService', 'PanelService', |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 69 | 'FlashService', 'QuickHelpService', 'WebSocketService', |
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 | function ($log, $route, $routeParams, $location, |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 72 | ks, ts, gs, ps, flash, qhs, wss) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 73 | var self = this; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 74 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 75 | self.$route = $route; |
| 76 | self.$routeParams = $routeParams; |
| 77 | self.$location = $location; |
| 78 | self.version = '1.1.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 79 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 80 | // initialize services... |
| 81 | ts.init(); |
| 82 | ks.installOn(d3.select('body')); |
| 83 | ks.bindQhs(qhs); |
| 84 | gs.init(); |
| 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 | // TODO: register handler for user settings, etc. |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 90 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 91 | wss.createWebSocket({ |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 92 | wsport: $location.search().wsport |
| 93 | }); |
| 94 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 95 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 96 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 97 | $log.debug('route: ', self.$route); |
| 98 | $log.debug('routeParams: ', self.$routeParams); |
| 99 | $log.debug('location: ', self.$location); |
| 100 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 101 | |
| 102 | .config(['$routeProvider', function ($routeProvider) { |
| 103 | // If view ID not provided, route to the first view in the list. |
| 104 | $routeProvider |
| 105 | .otherwise({ |
| 106 | redirectTo: '/' + viewIds[0] |
| 107 | }); |
| 108 | |
| 109 | function viewCtrlName(vid) { |
| 110 | return 'Ov' + capitalize(vid) + 'Ctrl'; |
| 111 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 112 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 113 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 114 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // Add routes for each defined view. |
| 118 | viewIds.forEach(function (vid) { |
| 119 | if (vid) { |
| 120 | $routeProvider.when('/' + vid, { |
| 121 | controller: viewCtrlName(vid), |
| 122 | controllerAs: 'ctrl', |
| 123 | templateUrl: viewTemplateUrl(vid) |
| 124 | }); |
| 125 | } |
| 126 | }); |
| 127 | }]); |
| 128 | }()); |