From 4bd1253337f5fe581376cbb596c7cdd5cd38c4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vachon?= Date: Wed, 25 Mar 2015 16:56:14 -0400 Subject: [PATCH] Introduces dynamic routing --- Gruntfile.js | 3 +++ app/app.js | 3 ++- app/routing_view/routing_view.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/routing_view/routing_view.js diff --git a/Gruntfile.js b/Gruntfile.js index 5b9819d..4cc3f93 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -110,6 +110,7 @@ module.exports = function (grunt) { '<%= project.app %>/components/table/cell_host_address/cell_host_address.js', '<%= project.app %>/components/table/cell_host_status/cell_host_status.js', '<%= project.app %>/dashboard/dashboard.js', + '<%= project.app %>/routing_view/routing_view.js', '<%= project.app %>/single_table/single_table.js' ] }], @@ -143,6 +144,7 @@ module.exports = function (grunt) { '<%= project.build %>/components/table/cell_host_address/cell_host_address.js': '<%= project.app %>/components/table/cell_host_address/cell_host_address.js', '<%= project.build %>/components/table/cell_host_status/cell_host_status.js': '<%= project.app %>/components/table/cell_host_status/cell_host_status.js', '<%= project.build %>/dashboard/dashboard.js': '<%= project.app %>/dashboard/dashboard.js', + '<%= project.build %>/routing_view/routing_view.js': '<%= project.app %>/routing_view/routing_view.js', '<%= project.build %>/single_table/single_table.js' : '<%= project.app %>/single_table/single_table.js' }, { @@ -170,6 +172,7 @@ module.exports = function (grunt) { '<%= project.build %>/components/table/cell_host_address/cell_host_address.js', '<%= project.build %>/components/table/cell_host_status/cell_host_status.js', '<%= project.build %>/dashboard/dashboard.js', + '<%= project.build %>/routing_view/routing_view.js', '<%= project.build %>/single_table/single_table.js' ] } diff --git a/app/app.js b/app/app.js index ca4517f..f759bf5 100644 --- a/app/app.js +++ b/app/app.js @@ -19,7 +19,8 @@ angular.module('adagios', [ 'adagios.topbar', 'adagios.config', 'adagios.view.dashboard', - 'adagios.view.singleTable' + 'adagios.view.singleTable', + 'adagios.view' ]) .config(['$routeProvider', function ($routeProvider) { diff --git a/app/routing_view/routing_view.js b/app/routing_view/routing_view.js new file mode 100644 index 0000000..8c27ef4 --- /dev/null +++ b/app/routing_view/routing_view.js @@ -0,0 +1,30 @@ +'use strict'; + +angular.module('adagios.view', ['ngRoute', + 'adagios.config' + ]) + + .value('viewsTemplate', {}) + + .config(['$routeProvider', function ($routeProvider) { + $routeProvider.when('/view', { + controller: 'ViewCtrl', + template: '
Loading...
' + }); + }]) + + .controller('ViewCtrl', ['$scope', '$routeParams', 'viewsTemplate', + function ($scope, $routeParams, viewsTemplate) { + var templateName = viewsTemplate[$routeParams.view], + templateUrl = templateName + '/' + templateName + '.html'; + + $scope.templateUrl = templateUrl; + }]) + + .run(['readConfig', 'viewsTemplate', function (readConfig, viewsTemplate) { + var viewsConfig = readConfig.data; + + angular.forEach(viewsConfig, function (config, view) { + viewsTemplate[view] = config.template; + }); + }]);