Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First contact load fix, direct access to contact, contact not in group, group load and order - fix #312 #323

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 35 additions & 22 deletions js/components/contactList/contactList_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to move this functionality to the angular routing (probably ui-router) in the future.
But good for now.

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;
Expand Down Expand Up @@ -115,21 +130,19 @@ angular.module('contactsApp')
$scope.$watch('ctrl.routeParams.gid', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this else clause removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was causing issues. It was replaced by this test:

if (ctrl.contactList[i].uid() === ev.uid) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// 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() {
Expand Down
2 changes: 1 addition & 1 deletion js/filters/contactGroup_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ angular.module('contactsApp')
}
}
}
return filter;
return filter.length === 0 ? contacts : filter;
};
});