Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 058d87e

Browse files
committed
Add custom route and controller to favorites view
1 parent 4566ac1 commit 058d87e

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

www/js/app.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,13 @@
4141
})
4242

4343
// Each tab has its own nav history stack:
44-
4544
.state('tab.map', {
46-
url: '/map{map:(?:/[^/]+)?}',
45+
url: '/map',
4746
views: {
4847
'tab-map': {
4948
templateUrl: 'templates/tab-map.html',
5049
controller: 'MapCtrl'
5150
}
52-
},
53-
resolve: {
54-
mapData: function ($stateParams, Favorites) {
55-
var mapId = parseInt($stateParams.map.substring(1));
56-
if (isNaN(mapId)) {
57-
return null;
58-
}
59-
return Favorites.fetchById(mapId);
60-
}
6151
}
6252
})
6353

@@ -79,7 +69,28 @@
7969
controller: 'FavoritesCtrl'
8070
}
8171
}
82-
});
72+
})
73+
74+
// Each tab has its own nav history stack:
75+
.state('tab.favorites-view', {
76+
url: '/favorites/:mapData',
77+
views: {
78+
'tab-favorites': {
79+
templateUrl: 'templates/tab-favorites-view.html',
80+
controller: 'FavoritesViewCtrl'
81+
}
82+
},
83+
resolve: {
84+
mapData: function ($stateParams, Favorites) {
85+
var mapId = parseInt($stateParams.mapData);
86+
if (isNaN(mapId)) {
87+
return null;
88+
}
89+
return Favorites.fetchById(mapId);
90+
}
91+
}
92+
})
93+
;
8394

8495
// if none of the above states are matched, use this as the fallback
8596
$urlRouterProvider.otherwise('/tab/map');

www/js/controllers.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@
1616

1717
angular.module('starter.controllers', [])
1818

19-
.controller('MapCtrl', function ($scope, mapData, $ionicPlatform, Settings, Favorites, Image, Faker, Id) {
20-
21-
var highDefUi;
22-
23-
$scope.$on('$ionicView.enter', function(event, data) {
24-
// if we want to see a starred item
25-
if (mapData) {
26-
$scope.mapData = mapData;
27-
$scope.starred = true;
28-
}
29-
});
19+
.controller('MapCtrl', function ($scope, $ionicPlatform, Settings, Favorites, Image, Faker, Id) {
3020

3121
$scope.generate = function () {
3222
// generate map tiles
@@ -187,6 +177,9 @@
187177
}
188178
};
189179
})
180+
.controller('FavoritesViewCtrl', function ($scope, mapData) {
181+
$scope.mapData = mapData;
182+
})
190183
;
191184

192185

www/templates/tab-favorites-view.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<ion-view view-title="{{mapData.name}}" ng-init="init()">
2+
<ion-content class="padding" scroll="false">
3+
<div class="canvas-container">
4+
<map map-data="mapData"></map>
5+
</div>
6+
</ion-content>
7+
</ion-view>

www/templates/tab-favorites.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ion-list>
1010
<ion-item ng-repeat="item in items"
1111
class="item-thumbnail-left"
12-
href="#/tab/map/{{item.id}}">
12+
href="#/tab/favorites/{{item.id}}">
1313
<img ng-src="{{item.thumbnailImageUri}}">
1414
<h2>{{item.name}}</h2>
1515
<p>{{item.catchPhrase}}</p>

0 commit comments

Comments
 (0)