From dedf6fe7bd2e7f2347cebbf3476d853ef06ac386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 31 Mar 2016 05:52:35 +0200 Subject: [PATCH] First contact load fix, group load and order (fix #312) Fixed direct link to contact and invalid contact access in group (fix #318) Fixed page loading with invalid group --- .../contactList/contactList_controller.js | 31 +++++++++++++------ js/filters/contactGroup_filter.js | 6 +++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/js/components/contactList/contactList_controller.js b/js/components/contactList/contactList_controller.js index d3358372c..1b3877907 100644 --- a/js/components/contactList/contactList_controller.js +++ b/js/components/contactList/contactList_controller.js @@ -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) { @@ -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 }); diff --git a/js/filters/contactGroup_filter.js b/js/filters/contactGroup_filter.js index 3ceb1ca1e..bb7b5287d 100644 --- a/js/filters/contactGroup_filter.js +++ b/js/filters/contactGroup_filter.js @@ -22,6 +22,10 @@ angular.module('contactsApp') } } } - return filter; + if(filter.length === 0) { + return contacts; + } else { + return filter; + } }; });