Simon Hunt

GUI -- Reworked onos.js to only require the list of view IDs to be injected. Mod…

…ule dependencies and routing configuration are both derived from the list of IDs.

Change-Id: If7bd7fe5c5c42f5c557e39c8ccb53847f2527be9
...@@ -21,25 +21,42 @@ ...@@ -21,25 +21,42 @@
21 (function () { 21 (function () {
22 'use strict'; 22 'use strict';
23 23
24 - var moduleDependencies = [ 24 + // define core module dependencies here...
25 - // view modules... 25 + var coreDependencies = [
26 - // TODO: inject view dependencies server side
27 - // {INJECTED-VIEW-MODULE-DEPENDENCIES}
28 - // NOTE: 'ov' == 'Onos View'...
29 - 'ovSample',
30 - 'ovTopo',
31 - 'ovDevice',
32 - // (end of view modules)
33 -
34 - // core modules...
35 'ngRoute', 26 'ngRoute',
36 'onosUtil', 27 'onosUtil',
37 'onosSvg', 28 'onosSvg',
38 'onosRemote', 29 'onosRemote',
39 - 'onosMast' 30 + 'onosMast',
31 + 'onosNav'
40 ]; 32 ];
41 33
42 - var $log; 34 + // view IDs.. note the first view listed is loaded at startup
35 + var viewIds = [
36 + // TODO: inject view IDs server side
37 + // {INJECTED-VIEW-IDS}
38 + 'sample',
39 + 'topo',
40 + 'device',
41 + // (end of injected views)
42 +
43 + // dummy entry
44 + ''
45 + ];
46 +
47 + var viewDependencies = [];
48 +
49 + viewIds.forEach(function (id) {
50 + if (id) {
51 + viewDependencies.push('ov' + capitalize(id));
52 + }
53 + });
54 +
55 + var moduleDependencies = coreDependencies.concat(viewDependencies);
56 +
57 + function capitalize(word) {
58 + return word ? word[0].toUpperCase() + word.slice(1) : word;
59 + }
43 60
44 angular.module('onosApp', moduleDependencies) 61 angular.module('onosApp', moduleDependencies)
45 62
...@@ -47,10 +64,9 @@ ...@@ -47,10 +64,9 @@
47 '$log', '$route', '$routeParams', '$location', 64 '$log', '$route', '$routeParams', '$location',
48 'KeyService', 'ThemeService', 'GlyphService', 65 'KeyService', 'ThemeService', 'GlyphService',
49 66
50 - function (_$log_, $route, $routeParams, $location, ks, ts, gs) { 67 + function ($log, $route, $routeParams, $location, ks, ts, gs) {
51 var self = this; 68 var self = this;
52 69
53 - $log = _$log_;
54 self.$route = $route; 70 self.$route = $route;
55 self.$routeParams = $routeParams; 71 self.$routeParams = $routeParams;
56 self.$location = $location; 72 self.$location = $location;
...@@ -69,26 +85,28 @@ ...@@ -69,26 +85,28 @@
69 }]) 85 }])
70 86
71 .config(['$routeProvider', function ($routeProvider) { 87 .config(['$routeProvider', function ($routeProvider) {
72 - // TODO: figure out a way of handling contributed views... 88 + // If view ID not provided, route to the first view in the list.
73 $routeProvider 89 $routeProvider
74 - .when('/', {
75 - controller: 'OvSampleCtrl',
76 - controllerAs: 'ctrl',
77 - templateUrl: 'view/sample/sample.html'
78 - })
79 - .when('/topo', {
80 - controller: 'OvTopoCtrl',
81 - controllerAs: 'ctrl',
82 - templateUrl: 'view/topo/topo.html'
83 - })
84 - .when('/device', {
85 - controller: 'OvDeviceCtrl',
86 - controllerAs: 'ctrl',
87 - templateUrl: 'view/device/device.html'
88 - })
89 .otherwise({ 90 .otherwise({
90 - redirectTo: '/' 91 + redirectTo: '/' + viewIds[0]
91 - }) 92 + });
92 - }]);
93 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 + }]);
94 }()); 112 }());
......