1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

potential solution for extending $stateProvider

and modularizing states
This commit is contained in:
Jared Tabor 2015-12-21 16:39:48 -08:00
parent 045f7b4a30
commit de7b6ba7bd
4 changed files with 83 additions and 52 deletions

View File

@ -70,6 +70,7 @@ import './job-templates/main';
import './shared/features/main';
import './login/authenticationServices/pendo/ng-pendo';
import footer from './footer/main';
import uiRouterHelper from './shared/uiRouterHelper/main';
/*#if DEBUG#*/
import {__deferLoadIfEnabled} from './debug';
@ -187,7 +188,8 @@ var tower = angular.module('Tower', [
'longDateFilter',
'pendolytics',
'ui.router',
'ncy-angular-breadcrumb'
'ncy-angular-breadcrumb',
uiRouterHelper.name
])
.constant('AngularScheduler.partials', urlPrefix + 'lib/angular-scheduler/lib/')
@ -204,9 +206,52 @@ var tower = angular.module('Tower', [
templateUrl: urlPrefix + 'partials/breadcrumb.html'
});
$urlRouterProvider.otherwise("/home");
// $urlRouterProvider.otherwise("/home");
$urlRouterProvider.otherwise(function($injector, $location){
var $state = $injector.get("$state");
$state.go('dashboard');
});
$stateProvider.
state('dashboard', {
url: '/home',
templateUrl: urlPrefix + 'partials/home.html',
controller: Home,
ncyBreadcrumb: {
label: "DASHBOARD"
},
resolve: {
graphData: ['$q', 'jobStatusGraphData', 'FeaturesService', function($q, jobStatusGraphData, FeaturesService) {
return $q.all({
jobStatus: jobStatusGraphData.get("month", "all"),
features: FeaturesService.get()
});
}]
}
}).
state('dashboardGroups', {
url: '/home/groups',
templateUrl: urlPrefix + 'partials/subhome.html',
controller: HomeGroups,
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
}).
state('dashboardHosts', {
url: '/home/hosts?has_active_failures',
templateUrl: urlPrefix + 'partials/subhome.html',
controller: HomeHosts,
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
}).
state('jobs', {
url: '/jobs',
templateUrl: urlPrefix + 'partials/jobs.html',
@ -775,45 +820,6 @@ var tower = angular.module('Tower', [
}
}).
state('dashboard', {
url: '/home',
templateUrl: urlPrefix + 'partials/home.html',
controller: Home,
ncyBreadcrumb: {
label: "DASHBOARD"
},
resolve: {
graphData: ['$q', 'jobStatusGraphData', 'FeaturesService', function($q, jobStatusGraphData, FeaturesService) {
return $q.all({
jobStatus: jobStatusGraphData.get("month", "all"),
features: FeaturesService.get()
});
}]
}
}).
state('dashboardGroups', {
url: '/home/groups',
templateUrl: urlPrefix + 'partials/subhome.html',
controller: HomeGroups,
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
}).
state('dashboardHosts', {
url: '/home/hosts?has_active_failures',
templateUrl: urlPrefix + 'partials/subhome.html',
controller: HomeHosts,
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
}).
state('license', {
url: '/license',
templateUrl: urlPrefix + 'partials/license.html',

View File

@ -12,11 +12,13 @@ import logoutRoute from './logout.route';
export default
angular.module('login', [authentication.name, loginModal.name])
.config(['$routeProvider', function($routeProvider) {
var url = loginRoute.url;
delete loginRoute.route;
$routeProvider.when(url, loginRoute);
url = logoutRoute.route;
delete logoutRoute.route;
$routeProvider.when(url, logoutRoute);
.run(['$stateExtender', function($stateExtender) {
$stateExtender.addState(loginRoute);
$stateExtender.addState(logoutRoute);
// var url = loginRoute.url;
// delete loginRoute.route;
// $routeProvider.when(url, loginRoute);
// url = logoutRoute.route;
// delete logoutRoute.route;
// $routeProvider.when(url, logoutRoute);
}]);

View File

@ -6,8 +6,10 @@ export default
[ 'AboutAnsibleHelpModal',
icon.name
])
.config(['$routeProvider', function($routeProvider) {
var url = route.route;
delete route.route;
$routeProvider.when(url, route);
.run(['$stateExtender', function($stateExtender) {
// var// $stateProvider = $injector.get("$state"),
// state = route.name;
// delete route.name;
$stateExtender.addState(route);
}]);

View File

@ -0,0 +1,21 @@
export default angular.module('uiRouterHelper',[
])
.provider('$stateExtender', function($stateProvider){
this.$get = function($state){
return {
addState: function(state) {
$stateProvider.state(state.name , {
url: state.route,
controller: state.controller,
templateUrl: state.templateUrl,
resolve: state.resolve
});
}
}
}
});