diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2016-03-31 05:52:35 +0200 |
---|---|---|
committer | skjnldsv <fremulon@protonmail.com> | 2016-04-05 16:25:16 +0200 |
commit | 74ff3b5339f43dca1dd7a83d84f30570a643cbb3 (patch) | |
tree | 5e93b2e398205ea4309a43fa92af82ed64caeb7b /js | |
parent | 621c7abf79fcd4d09c2f65ec62bcd01c0c4ae9ec (diff) |
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
Fix mobile merge and group contact load issue
Diffstat (limited to 'js')
-rw-r--r-- | js/components/contactList/contactList_controller.js | 57 | ||||
-rw-r--r-- | js/filters/contactGroup_filter.js | 2 |
2 files changed, 36 insertions, 23 deletions
diff --git a/js/components/contactList/contactList_controller.js b/js/components/contactList/contactList_controller.js index eeebab60..32eb9d5f 100644 --- a/js/components/contactList/contactList_controller.js +++ b/js/components/contactList/contactList_controller.js @@ -67,22 +67,37 @@ angular.module('contactsApp') }); }); + // Get contacts ContactService.getAll().then(function(contacts) { $scope.$apply(function() { ctrl.contacts = contacts; - // If desktop version, load first contact (see css for min-width media query) - if (!_.isEmpty(ctrl.contacts) && $(window).width() > 768) { - 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 not in mobile mode + if(ctrl.loading && $(window).width() > 768) { + ctrl.setSelectedId(ctrl.contactList[0].uid()); } ctrl.loading = false; - }); + unbindListWatch(); + } }); $scope.$watch('ctrl.routeParams.uid', function(newValue, oldValue) { // Used for mobile view to clear the url - if(typeof oldValue != 'undefined' && typeof newValue == 'undefined') { + if(typeof oldValue != 'undefined' && typeof newValue == 'undefined' && $(window).width() <= 768) { // no contact selected ctrl.show = true; return; @@ -115,21 +130,19 @@ angular.module('contactsApp') $scope.$watch('ctrl.routeParams.gid', function() { // we might have to wait until ng-repeat filled the contactList ctrl.contactList = []; - // watch for next contactList update - var unbindWatch = $scope.$watch('ctrl.contactList', function() { - if(ctrl.contactList && ctrl.contactList.length > 0 && $(window).width() > 768) { - $route.updateParams({ - gid: $routeParams.gid, - uid: ctrl.contactList[0].uid() - }); - } else { - $route.updateParams({ - gid: $routeParams.gid, - uid: undefined - }); - } - unbindWatch(); // unbind as we only want one update - }); + // not in mobile mode + if($(window).width() > 768) { + // watch for next contactList update + var unbindWatch = $scope.$watch('ctrl.contactList', function() { + if(ctrl.contactList && ctrl.contactList.length > 0) { + $route.updateParams({ + gid: $routeParams.gid, + uid: ctrl.contactList[0].uid() + }); + } + unbindWatch(); // unbind as we only want one update + }); + } }); ctrl.createContact = function() { diff --git a/js/filters/contactGroup_filter.js b/js/filters/contactGroup_filter.js index 3ceb1ca1..f9763369 100644 --- a/js/filters/contactGroup_filter.js +++ b/js/filters/contactGroup_filter.js @@ -22,6 +22,6 @@ angular.module('contactsApp') } } } - return filter; + return filter.length === 0 ? contacts : filter; }; }); |