Skip to content

Commit

Permalink
Add custom route and controller to favorites view
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Mar 2, 2015
1 parent 4566ac1 commit 058d87e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
35 changes: 23 additions & 12 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,13 @@
})

// Each tab has its own nav history stack:

.state('tab.map', {
url: '/map{map:(?:/[^/]+)?}',
url: '/map',
views: {
'tab-map': {
templateUrl: 'templates/tab-map.html',
controller: 'MapCtrl'
}
},
resolve: {
mapData: function ($stateParams, Favorites) {
var mapId = parseInt($stateParams.map.substring(1));
if (isNaN(mapId)) {
return null;
}
return Favorites.fetchById(mapId);
}
}
})

Expand All @@ -79,7 +69,28 @@
controller: 'FavoritesCtrl'
}
}
});
})

// Each tab has its own nav history stack:
.state('tab.favorites-view', {
url: '/favorites/:mapData',
views: {
'tab-favorites': {
templateUrl: 'templates/tab-favorites-view.html',
controller: 'FavoritesViewCtrl'
}
},
resolve: {
mapData: function ($stateParams, Favorites) {
var mapId = parseInt($stateParams.mapData);
if (isNaN(mapId)) {
return null;
}
return Favorites.fetchById(mapId);
}
}
})
;

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/map');
Expand Down
15 changes: 4 additions & 11 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@

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

.controller('MapCtrl', function ($scope, mapData, $ionicPlatform, Settings, Favorites, Image, Faker, Id) {

var highDefUi;

$scope.$on('$ionicView.enter', function(event, data) {
// if we want to see a starred item
if (mapData) {
$scope.mapData = mapData;
$scope.starred = true;
}
});
.controller('MapCtrl', function ($scope, $ionicPlatform, Settings, Favorites, Image, Faker, Id) {

$scope.generate = function () {
// generate map tiles
Expand Down Expand Up @@ -187,6 +177,9 @@
}
};
})
.controller('FavoritesViewCtrl', function ($scope, mapData) {
$scope.mapData = mapData;
})
;


Expand Down
7 changes: 7 additions & 0 deletions www/templates/tab-favorites-view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ion-view view-title="{{mapData.name}}" ng-init="init()">
<ion-content class="padding" scroll="false">
<div class="canvas-container">
<map map-data="mapData"></map>
</div>
</ion-content>
</ion-view>
2 changes: 1 addition & 1 deletion www/templates/tab-favorites.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ion-list>
<ion-item ng-repeat="item in items"
class="item-thumbnail-left"
href="#/tab/map/{{item.id}}">
href="#/tab/favorites/{{item.id}}">
<img ng-src="{{item.thumbnailImageUri}}">
<h2>{{item.name}}</h2>
<p>{{item.catchPhrase}}</p>
Expand Down

0 comments on commit 058d87e

Please sign in to comment.