GUI -- Reworked onos.js to only require the list of view IDs to be injected. Module dependencies and routing configuration are both derived from the list of IDs.

Change-Id: If7bd7fe5c5c42f5c557e39c8ccb53847f2527be9
diff --git a/web/gui/src/main/webapp/app/onos.js b/web/gui/src/main/webapp/app/onos.js
index 53cb436..46f4314 100644
--- a/web/gui/src/main/webapp/app/onos.js
+++ b/web/gui/src/main/webapp/app/onos.js
@@ -21,25 +21,42 @@
 (function () {
     'use strict';
 
-    var moduleDependencies = [
-        // view modules...
-        // TODO: inject view dependencies server side
-        // {INJECTED-VIEW-MODULE-DEPENDENCIES}
-        // NOTE: 'ov' == 'Onos View'...
-        'ovSample',
-        'ovTopo',
-        'ovDevice',
-        // (end of view modules)
-
-        // core modules...
+    // define core module dependencies here...
+    var coreDependencies = [
         'ngRoute',
         'onosUtil',
         'onosSvg',
         'onosRemote',
-        'onosMast'
+        'onosMast',
+        'onosNav'
     ];
 
-    var $log;
+    // view IDs.. note the first view listed is loaded at startup
+    var viewIds = [
+        // TODO: inject view IDs server side
+        // {INJECTED-VIEW-IDS}
+        'sample',
+        'topo',
+        'device',
+        // (end of injected views)
+
+        // dummy entry
+        ''
+    ];
+
+    var viewDependencies = [];
+
+    viewIds.forEach(function (id) {
+        if (id) {
+            viewDependencies.push('ov' + capitalize(id));
+        }
+    });
+
+    var moduleDependencies = coreDependencies.concat(viewDependencies);
+
+    function capitalize(word) {
+        return word ? word[0].toUpperCase() + word.slice(1) : word;
+    }
 
     angular.module('onosApp', moduleDependencies)
 
@@ -47,10 +64,9 @@
             '$log', '$route', '$routeParams', '$location',
             'KeyService', 'ThemeService', 'GlyphService',
 
-        function (_$log_, $route, $routeParams, $location, ks, ts, gs) {
+        function ($log, $route, $routeParams, $location, ks, ts, gs) {
             var self = this;
 
-            $log = _$log_;
             self.$route = $route;
             self.$routeParams = $routeParams;
             self.$location = $location;
@@ -69,26 +85,28 @@
         }])
 
         .config(['$routeProvider', function ($routeProvider) {
-            // TODO: figure out a way of handling contributed views...
+            // If view ID not provided, route to the first view in the list.
             $routeProvider
-                .when('/', {
-                    controller: 'OvSampleCtrl',
-                    controllerAs: 'ctrl',
-                    templateUrl: 'view/sample/sample.html'
-                })
-                .when('/topo', {
-                    controller: 'OvTopoCtrl',
-                    controllerAs: 'ctrl',
-                    templateUrl: 'view/topo/topo.html'
-                })
-                .when('/device', {
-                    controller: 'OvDeviceCtrl',
-                    controllerAs: 'ctrl',
-                    templateUrl: 'view/device/device.html'
-                })
                 .otherwise({
-                    redirectTo: '/'
-                })
-        }]);
+                    redirectTo: '/' + viewIds[0]
+                });
 
+            function viewCtrlName(vid) {
+                return 'Ov' + capitalize(vid) + 'Ctrl';
+            }
+            function viewTemplateUrl(vid) {
+                return 'view/' + vid + '/' + vid + '.html';
+            }
+
+            // Add routes for each defined view.
+            viewIds.forEach(function (vid) {
+                if (vid) {
+                    $routeProvider.when('/' + vid, {
+                        controller: viewCtrlName(vid),
+                        controllerAs: 'ctrl',
+                        templateUrl: viewTemplateUrl(vid)
+                    });
+                }
+            });
+        }]);
 }());