Skip to content

Commit

Permalink
First contact load fix, group load and order (fix #312)
Browse files Browse the repository at this point in the history
Fixed direct link to contact and invalid contact access in group (fix #318)
  • Loading branch information
skjnldsv authored and skjnldsv committed Mar 31, 2016
1 parent 3da03eb commit 69207c9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions js/components/contactList/contactList_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,32 @@ angular.module('contactsApp')
});
});

// Get contacts
ContactService.getAll().then(function(contacts) {
$scope.$apply(function() {
ctrl.contacts = contacts;
if (!_.isEmpty(ctrl.contacts)) {
ctrl.setSelectedId(_.sortBy(contacts, function(contact) {
return contact.fullName();
})[0].uid());
});
});

// Wait for ctrl.contactList to be updated, load the first contact and kill the watch
var unbindListWatch = $scope.$watch('ctrl.contactList', function() {
if(ctrl.contactList && ctrl.contactList.length > 0) {
// Check if a specific uid is requested
if($routeParams.uid) {
ctrl.contactList.forEach(function(contact) {
if(contact.uid() === $routeParams.uid) {
ctrl.setSelectedId($routeParams.uid);
ctrl.loading = false;
}
});
}
// No contact previously loaded, let's load the first of the list
if(ctrl.loading) {
ctrl.setSelectedId(ctrl.contactList[0].uid());
}
ctrl.loading = false;
});
unbindListWatch();
}
});

$scope.$watch('ctrl.routeParams.uid', function(newValue) {
Expand Down Expand Up @@ -111,11 +127,6 @@ angular.module('contactsApp')
gid: $routeParams.gid,
uid: ctrl.contactList[0].uid()
});
} else {
$route.updateParams({
gid: $routeParams.gid,
uid: undefined
});
}
unbindWatch(); // unbind as we only want one update
});
Expand Down

0 comments on commit 69207c9

Please sign in to comment.