From 3811d55a63036fc97bad2e17711d90f85f6ebee8 Mon Sep 17 00:00:00 2001 From: Sean Payne Date: Fri, 12 Sep 2014 13:42:36 -0700 Subject: [PATCH 1/2] Moved 'Friends' tab to the left side. Also changed icons. --- www/templates/tabs.html | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/www/templates/tabs.html b/www/templates/tabs.html index e60f41b..6ec560a 100644 --- a/www/templates/tabs.html +++ b/www/templates/tabs.html @@ -5,20 +5,18 @@ --> - - - - - - - - + + + + + + - - + + From 38cd58af186104c33948ba07ea762743efd4bb53 Mon Sep 17 00:00:00 2001 From: Sean Payne Date: Fri, 12 Sep 2014 14:00:59 -0700 Subject: [PATCH 2/2] Added handler for errors while loading Friends list. Added error handler & displayed pop-up message when there is an error while loading the Friends list. Refactored the $http request to use the fluent method calls "success" and "error" for readability. --- www/js/api_services.js | 15 ++++++++++----- www/js/controllers.js | 27 +++++++++++++++++++-------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/www/js/api_services.js b/www/js/api_services.js index 37590fd..c541c29 100644 --- a/www/js/api_services.js +++ b/www/js/api_services.js @@ -14,11 +14,16 @@ angular.module('starter.services', []) } Friends.all = function() { - return $http.get(apiServerUrl).then(function(response) { - console.log("Got some data"); - friends = response.data; - return new Friends(response.data); - }); + return $http.get(apiServerUrl) + .success(function(data) { + console.log("Success: Got some data"); + friends = data; + return new Friends(data); + }) + .error(function(data) { + console.log("Error: " + data); + throw new Error("Server returned an error"); + }); } Friends.getByMeetupId = function(meetupId) { diff --git a/www/js/controllers.js b/www/js/controllers.js index 408b27c..04830b0 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -31,7 +31,7 @@ angular.module('starter.controllers', ['ngStorage']) }); }) -.controller('FriendsCtrl', function($rootScope, $scope, $localStorage, $ionicLoading, Friends) { +.controller('FriendsCtrl', function($rootScope, $scope, $localStorage, $ionicLoading, Friends, $ionicViewService, $ionicPopup) { // Make the local storage available to the view $scope.$storage = $localStorage; @@ -47,13 +47,24 @@ angular.module('starter.controllers', ['ngStorage']) template: '' }); - var promise = Friends.all(); - promise.then(function(data) { - // Inject friends data into the root scope - $rootScope.friends = data; - // Hide the busy indicator - busy.hide(); - }); + var promise = Friends.all() + .then(function(data) { + // Inject friends data into the root scope + $rootScope.friends = data.data; + // Hide the busy indicator + busy.hide(); + }) + .catch(function(data){ + // Catch an error and go to the last view + $ionicViewService.getBackView().go(); + // Hide the busy indicator + busy.hide(); + // Display an error popup + $ionicPopup.alert({ + title: 'Error', + template: 'An error occurred while trying to retrieve the friends list.' + }); + }); }) .controller('FriendDetailCtrl', function($scope, $stateParams, $localStorage, Friends) {