Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 1 | /* |
Simon Hunt | 8ead3a2 | 2015-01-06 11:00:15 -0800 | [diff] [blame] | 2 | * Copyright 2014,2015 Open Networking Laboratory |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -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 | /* |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 18 | ONOS GUI -- Main Application Module |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 19 | */ |
Simon Hunt | 1eecfa2 | 2014-12-16 14:46:29 -0800 | [diff] [blame] | 20 | |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 24 | // define core module dependencies here... |
| 25 | var coreDependencies = [ |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 26 | 'ngRoute', |
Bri Prebilic Cole | 093739a | 2015-01-23 10:22:50 -0800 | [diff] [blame^] | 27 | 'onosWidget', |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 28 | 'onosUtil', |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 29 | 'onosSvg', |
Bri Prebilic Cole | 4fab8af | 2015-01-15 16:40:47 -0800 | [diff] [blame] | 30 | 'onosRemote', |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 31 | 'onosMast', |
| 32 | 'onosNav' |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 33 | ]; |
| 34 | |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 35 | // view IDs.. note the first view listed is loaded at startup |
| 36 | var viewIds = [ |
| 37 | // TODO: inject view IDs server side |
| 38 | // {INJECTED-VIEW-IDS} |
| 39 | 'sample', |
| 40 | 'topo', |
| 41 | 'device', |
| 42 | // (end of injected views) |
| 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 | } |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 61 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 62 | angular.module('onosApp', moduleDependencies) |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 63 | |
| 64 | .controller('OnosCtrl', [ |
| 65 | '$log', '$route', '$routeParams', '$location', |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 66 | 'KeyService', 'ThemeService', 'GlyphService', |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 67 | |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 68 | function ($log, $route, $routeParams, $location, ks, ts, gs) { |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 69 | var self = this; |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 70 | |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 71 | self.$route = $route; |
| 72 | self.$routeParams = $routeParams; |
| 73 | self.$location = $location; |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 74 | self.version = '1.1.0'; |
| 75 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 76 | // initialize services... |
Yuta HIGUCHI | 4f39bcd | 2014-12-18 20:46:14 -0800 | [diff] [blame] | 77 | ts.init(); |
Simon Hunt | 420691a | 2014-12-16 20:16:28 -0800 | [diff] [blame] | 78 | ks.installOn(d3.select('body')); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 79 | gs.init(); |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 80 | |
| 81 | $log.log('OnosCtrl has been created'); |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 82 | |
| 83 | $log.debug('route: ', self.$route); |
| 84 | $log.debug('routeParams: ', self.$routeParams); |
| 85 | $log.debug('location: ', self.$location); |
| 86 | }]) |
| 87 | |
| 88 | .config(['$routeProvider', function ($routeProvider) { |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 89 | // If view ID not provided, route to the first view in the list. |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 90 | $routeProvider |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 91 | .otherwise({ |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 92 | redirectTo: '/' + viewIds[0] |
| 93 | }); |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 94 | |
Simon Hunt | cd258a1 | 2015-01-19 19:20:13 -0800 | [diff] [blame] | 95 | function viewCtrlName(vid) { |
| 96 | return 'Ov' + capitalize(vid) + 'Ctrl'; |
| 97 | } |
| 98 | function viewTemplateUrl(vid) { |
| 99 | return 'view/' + vid + '/' + vid + '.html'; |
| 100 | } |
| 101 | |
| 102 | // Add routes for each defined view. |
| 103 | viewIds.forEach(function (vid) { |
| 104 | if (vid) { |
| 105 | $routeProvider.when('/' + vid, { |
| 106 | controller: viewCtrlName(vid), |
| 107 | controllerAs: 'ctrl', |
| 108 | templateUrl: viewTemplateUrl(vid) |
| 109 | }); |
| 110 | } |
| 111 | }); |
| 112 | }]); |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 113 | }()); |