Skip to content

Commit 13a764a

Browse files
committed
Use angular-ui-router
Using States rather than routes. Had to apply a patch to angular-ui-router: angular-ui/ui-router#492 This should be fixed when angular-ui-router 0.3 comes out
1 parent fe0c002 commit 13a764a

File tree

7 files changed

+112
-12
lines changed

7 files changed

+112
-12
lines changed

app/public/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<link rel="stylesheet" href="css/bootstrap.css">
1010
<script src="lib/angular/angular.js"></script>
1111
<script src="lib/angular/angular-resource.js"></script>
12+
<script src="lib/angular-ui-router.js"></script>
1213

1314
<script src="podium/PodiumModule.js"></script>
1415
<script src="users/UserModule.js"></script>
@@ -21,6 +22,7 @@
2122

2223
</head>
2324
<body>
24-
<div ng-view></div>
25+
<div ui-view="header"></div>
26+
<div class="content" ui-view="content"></div>
2527
</body>
2628
</html>

app/public/lib/angular-ui-router.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ angular.module('ui.router.router').provider('$urlRouter', $UrlRouterProvider);
765765
$StateProvider.$inject = ['$urlRouterProvider', '$urlMatcherFactoryProvider', '$locationProvider'];
766766
function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $locationProvider) {
767767

768-
var root, states = {}, $state;
768+
var root, states = {}, $state, queue = {};
769769

770770
// Builds state properties from definition passed to registerState()
771771
var stateBuilder = {
@@ -902,6 +902,13 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
902902
return undefined;
903903
}
904904

905+
function queueState(parentName, state){
906+
if(!queue[parentName]){
907+
queue[parentName] = [];
908+
}
909+
queue[parentName].push(state);
910+
}
911+
905912

906913
function registerState(state) {
907914
// Wrap a new object around the state so we can store our private details easily.
@@ -915,6 +922,17 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
915922
if (!isString(name) || name.indexOf('@') >= 0) throw new Error("State must have a valid name");
916923
if (states[name]) throw new Error("State '" + name + "'' is already defined");
917924

925+
//get parent name
926+
var parentName =
927+
(name.indexOf('.') !== -1) ? name.substring(0, name.lastIndexOf('.'))
928+
: (isString(state.parent)) ? state.parent
929+
: '';
930+
931+
// If parent is not registered yet, add state to queue and register later
932+
if (parentName && !states[parentName]) {
933+
return queueState(parentName, state.self);
934+
}
935+
918936
for (var key in stateBuilder) {
919937
state[key] = stateBuilder[key](state);
920938
}
@@ -928,6 +946,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
928946
}
929947
}]);
930948
}
949+
950+
// Register any queued children
951+
if (queue[name]) {
952+
for (var i = 0; i < queue[name].length; i++) {
953+
registerState(queue[name][i]);
954+
}
955+
}
956+
931957
return state;
932958
}
933959

app/public/podium/PodiumController.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ podium.controller("PodiumCtrl" ["$scope", function($scope){
1919
}]);
2020

2121

22+
podium.controller("HeaderCtrl" ["$scope", function($scope){
23+
24+
}]);
25+
26+

app/public/podium/PodiumModule.js

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11
"use strict";
22

3-
var podium = angular.module("podium", ["users"]);
3+
var podium = angular.module("podium", [
4+
"users",
5+
"ui.router"
6+
]);
7+
8+
podium.config(["$stateProvider", "$routeProvider", function($stateProvider, $routeProvider) {
9+
10+
$stateProvider
11+
.state("main", {
12+
url: '',
13+
abstract: true,
14+
views: {
15+
'header': {
16+
templateUrl: 'podium/partials/header.html',
17+
controller: 'MainCtrl'
18+
}
19+
}
20+
})
21+
.state("main.home", {
22+
url: '/',
23+
views: {
24+
'content@': {
25+
templateUrl: 'podium/partials/main.html'
26+
}
27+
}
28+
})
29+
.state("main.list", {
30+
url: '/list',
31+
views: {
32+
'content@': {
33+
templateUrl: 'podium/partials/list.html'
34+
}
35+
}
36+
});
437

5-
podium.config(["$routeProvider", function($routeProvider) {
6-
$routeProvider
7-
.when("/", {templateUrl: "podium/partials/main.html", controller: "MainCtrl"})
8-
.when("/:content", {templateUrl: "podium/partials/main.html", controller: "MainCtrl" });
938
}]);
1039

40+
var users = angular.module("users", ["users.service", "ui.router"]);
41+
42+
users.config(["$stateProvider", "$routeProvider", function($stateProvider, $routeProvider){
43+
44+
$stateProvider
45+
.state("main.register", {
46+
url: '/register',
47+
views: {
48+
'content@': {
49+
templateUrl: 'users/partials/register.html',
50+
controller: 'RegisterCtrl'
51+
}
52+
}
53+
});
54+
55+
}]);

app/public/podium/partials/list.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>List</div>

app/public/podium/partials/main.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
<div ng-controller="MainCtrl" class="container">
2-
<ng-include src='"podium/partials/header.html"'></ng-include>
3-
4-
<ng-include src='"podium/partials/content.html"'></ng-include>
5-
2+
Main Partial
63
</div>

app/public/users/UserModule.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
"use strict";
22

3-
var users = angular.module("users", ["users.service"]);
3+
var users = angular.module("users", ["users.service", "ui.router"]);
4+
5+
users.config(["$stateProvider", "$routeProvider", function($stateProvider, $routeProvider){
6+
7+
$stateProvider
8+
.state("main.register", {
9+
url: '/register',
10+
views: {
11+
'content@': {
12+
templateUrl: 'users/partials/register.html',
13+
controller: 'RegisterCtrl'
14+
}
15+
}
16+
})
17+
.state("main.login", {
18+
url: '/login',
19+
views: {
20+
'content@': {
21+
templateUrl: 'users/partials/login.html',
22+
controller: 'LoginCtrl'
23+
}
24+
}
25+
})
26+
27+
}]);
428
/*
529
users.config(["$routeProvider", function($routeProvider){
630
$routeProvider

0 commit comments

Comments
 (0)