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)
Fixed page loading with invalid group
  • Loading branch information
skjnldsv authored and skjnldsv committed Mar 31, 2016
1 parent 3da03eb commit dedf6fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 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 && $routeParams.gid) {
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
6 changes: 5 additions & 1 deletion js/filters/contactGroup_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ angular.module('contactsApp')
}
}
}
return filter;
if(filter.length === 0) {
return contacts;
} else {
return filter;
}
};
});

0 comments on commit dedf6fe

Please sign in to comment.