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 = [ |
| 38 | // TODO: inject view IDs server side |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 39 | // {INJECTED-VIEW-IDS-START} |
| 40 | 'sample', |
| 41 | 'topo', |
| 42 | 'device', |
| 43 | // {INJECTED-VIEW-IDS-END} |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 44 | |
| 45 | // dummy entry |
| 46 | '' |
| 47 | ]; |
| 48 | |
| 49 | var viewDependencies = []; |
| 50 | |
| 51 | viewIds.forEach(function (id) { |
| 52 | if (id) { |
| 53 | viewDependencies.push('ov' + capitalize(id)); |
| 54 | } |
| 55 | }); |
| 56 | |
| 57 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
| 58 | |
| 59 | function capitalize(word) { |
| 60 | return word ? word[0].toUpperCase() + word.slice(1) : word; |
| 61 | } |
| 62 | |
| 63 | angular.module('onosApp', moduleDependencies) |
| 64 | |
| 65 | .controller('OnosCtrl', [ |
| 66 | '$log', '$route', '$routeParams', '$location', |
| 67 | 'KeyService', 'ThemeService', 'GlyphService', 'PanelService', |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 68 | 'FlashService', 'QuickHelpService', |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 69 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 70 | function ($log, $route, $routeParams, $location, |
| 71 | ks, ts, gs, ps, flash, qhs) { |
| 72 | var self = this; |
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 | self.$route = $route; |
| 75 | self.$routeParams = $routeParams; |
| 76 | self.$location = $location; |
| 77 | self.version = '1.1.0'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 78 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 79 | // initialize services... |
| 80 | ts.init(); |
| 81 | ks.installOn(d3.select('body')); |
| 82 | ks.bindQhs(qhs); |
| 83 | gs.init(); |
| 84 | ps.init(); |
| 85 | flash.initFlash(); |
| 86 | qhs.initQuickHelp(); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 87 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 88 | $log.log('OnosCtrl has been created'); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 89 | |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 90 | $log.debug('route: ', self.$route); |
| 91 | $log.debug('routeParams: ', self.$routeParams); |
| 92 | $log.debug('location: ', self.$location); |
| 93 | }]) |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 94 | |
| 95 | .config(['$routeProvider', function ($routeProvider) { |
| 96 | // If view ID not provided, route to the first view in the list. |
| 97 | $routeProvider |
| 98 | .otherwise({ |
| 99 | redirectTo: '/' + viewIds[0] |
| 100 | }); |
| 101 | |
| 102 | function viewCtrlName(vid) { |
| 103 | return 'Ov' + capitalize(vid) + 'Ctrl'; |
| 104 | } |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 105 | |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 106 | function viewTemplateUrl(vid) { |
Thomas Vachuska | a050989 | 2015-02-21 22:18:41 -0800 | [diff] [blame] | 107 | return 'app/view/' + vid + '/' + vid + '.html'; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Add routes for each defined view. |
| 111 | viewIds.forEach(function (vid) { |
| 112 | if (vid) { |
| 113 | $routeProvider.when('/' + vid, { |
| 114 | controller: viewCtrlName(vid), |
| 115 | controllerAs: 'ctrl', |
| 116 | templateUrl: viewTemplateUrl(vid) |
| 117 | }); |
| 118 | } |
| 119 | }); |
| 120 | }]); |
| 121 | }()); |