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