blob: 3272cefad62a72b461731b08f1788204fdb48b37 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
39 // {INJECTED-VIEW-IDS}
40 // (end of injected views)
41
42 // dummy entry
43 ''
44 ];
45
46 var viewDependencies = [];
47
48 viewIds.forEach(function (id) {
49 if (id) {
50 viewDependencies.push('ov' + capitalize(id));
51 }
52 });
53
54 var moduleDependencies = coreDependencies.concat(viewDependencies);
55
56 function capitalize(word) {
57 return word ? word[0].toUpperCase() + word.slice(1) : word;
58 }
59
60 angular.module('onosApp', moduleDependencies)
61
62 .controller('OnosCtrl', [
63 '$log', '$route', '$routeParams', '$location',
64 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
65
66 function ($log, $route, $routeParams, $location, ks, ts, gs, ps) {
67 var self = this;
68
69 self.$route = $route;
70 self.$routeParams = $routeParams;
71 self.$location = $location;
72 self.version = '1.1.0';
73
74 // initialize services...
75 ts.init();
76 ks.installOn(d3.select('body'));
77 gs.init();
78 ps.init();
79
80 $log.log('OnosCtrl has been created');
81
82 $log.debug('route: ', self.$route);
83 $log.debug('routeParams: ', self.$routeParams);
84 $log.debug('location: ', self.$location);
85 }])
86
87 .config(['$routeProvider', function ($routeProvider) {
88 // If view ID not provided, route to the first view in the list.
89 $routeProvider
90 .otherwise({
91 redirectTo: '/' + viewIds[0]
92 });
93
94 function viewCtrlName(vid) {
95 return 'Ov' + capitalize(vid) + 'Ctrl';
96 }
97 function viewTemplateUrl(vid) {
98 return 'view/' + vid + '/' + vid + '.html';
99 }
100
101 // Add routes for each defined view.
102 viewIds.forEach(function (vid) {
103 if (vid) {
104 $routeProvider.when('/' + vid, {
105 controller: viewCtrlName(vid),
106 controllerAs: 'ctrl',
107 templateUrl: viewTemplateUrl(vid)
108 });
109 }
110 });
111 }]);
112}());