blob: 0f049e99d62749e18caf40d2a4b0cb182671b5e7 [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
Thomas Vachuskaa0509892015-02-21 22:18:41 -08002 * Copyright 2014,2015 Open Networking Laboratory
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08003 *
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 Vachuskaa0509892015-02-21 22:18:41 -080038 // {INJECTED-VIEW-IDS-START}
39 'sample',
40 'topo',
41 'device',
42 // {INJECTED-VIEW-IDS-END}
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080043
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 }
61
62 angular.module('onosApp', moduleDependencies)
63
64 .controller('OnosCtrl', [
65 '$log', '$route', '$routeParams', '$location',
66 'KeyService', 'ThemeService', 'GlyphService', 'PanelService',
Thomas Vachuskaa0509892015-02-21 22:18:41 -080067 'FlashService', 'QuickHelpService',
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080068
Thomas Vachuskaa0509892015-02-21 22:18:41 -080069 function ($log, $route, $routeParams, $location,
70 ks, ts, gs, ps, flash, qhs) {
71 var self = this;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080072
Thomas Vachuskaa0509892015-02-21 22:18:41 -080073 self.$route = $route;
74 self.$routeParams = $routeParams;
75 self.$location = $location;
76 self.version = '1.1.0';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080077
Thomas Vachuskaa0509892015-02-21 22:18:41 -080078 // initialize services...
79 ts.init();
80 ks.installOn(d3.select('body'));
81 ks.bindQhs(qhs);
82 gs.init();
83 ps.init();
84 flash.initFlash();
85 qhs.initQuickHelp();
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080086
Thomas Vachuskaa0509892015-02-21 22:18:41 -080087 $log.log('OnosCtrl has been created');
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080088
Thomas Vachuskaa0509892015-02-21 22:18:41 -080089 $log.debug('route: ', self.$route);
90 $log.debug('routeParams: ', self.$routeParams);
91 $log.debug('location: ', self.$location);
92 }])
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080093
94 .config(['$routeProvider', function ($routeProvider) {
95 // If view ID not provided, route to the first view in the list.
96 $routeProvider
97 .otherwise({
98 redirectTo: '/' + viewIds[0]
99 });
100
101 function viewCtrlName(vid) {
102 return 'Ov' + capitalize(vid) + 'Ctrl';
103 }
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800104
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800105 function viewTemplateUrl(vid) {
Thomas Vachuskaa0509892015-02-21 22:18:41 -0800106 return 'app/view/' + vid + '/' + vid + '.html';
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -0800107 }
108
109 // Add routes for each defined view.
110 viewIds.forEach(function (vid) {
111 if (vid) {
112 $routeProvider.when('/' + vid, {
113 controller: viewCtrlName(vid),
114 controllerAs: 'ctrl',
115 templateUrl: viewTemplateUrl(vid)
116 });
117 }
118 });
119 }]);
120}());