mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Refactor groups management. Fix #370
- Moved adding/removing groups to OCA\Contacts\VObject\VCard - CATEGORIES property wasn't removed when empty - When removing all groups from contact, it wasn't assigned to ungrouped. - When adding contact(s) to group it wasn't removed from ungrouped until you changed to other group and back.
This commit is contained in:
parent
a742486150
commit
c738174937
@ -673,6 +673,10 @@ OC.Contacts = OC.Contacts || {
|
||||
console.log('Showing', contact.getId());
|
||||
contact.show();
|
||||
}
|
||||
if(self.currentgroup === 'uncategorized') {
|
||||
console.log('Hiding', contact.getId());
|
||||
contact.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2012,7 +2012,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
ContactList.prototype.showUncategorized = function() {
|
||||
console.log('ContactList.showUncategorized');
|
||||
for(var contact in this.contacts) {
|
||||
if(this.contacts[contact].getPreferredValue('CATEGORIES', []).length === 0) {
|
||||
if(this.contacts[contact].getPreferredValue('CATEGORIES', []).clean('').length === 0) {
|
||||
this.contacts[contact].getListItemElement().show();
|
||||
this.contacts[contact].setThumbnail();
|
||||
} else {
|
||||
|
@ -96,10 +96,10 @@ class GroupController extends Controller {
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
if(!$obj->inGroup($name)) {
|
||||
continue;
|
||||
}
|
||||
if($obj->CATEGORIES->removeGroup($name)) {
|
||||
if($obj->removeFromGroup($name)) {
|
||||
$backend->updateContact(null, $id, $obj, array('noCollection' => true, 'isBatch' => true));
|
||||
}
|
||||
} else {
|
||||
@ -195,11 +195,9 @@ class GroupController extends Controller {
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
$obj->add('CATEGORIES');
|
||||
if($obj->addToGroup($categoryname)) {
|
||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||
}
|
||||
$obj->CATEGORIES->addGroup($categoryname);
|
||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||
}
|
||||
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
||||
$tagMgr->tagAs($contactId, $categoryId);
|
||||
@ -243,10 +241,11 @@ class GroupController extends Controller {
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
$obj->add('CATEGORIES');
|
||||
return $response;
|
||||
}
|
||||
if($obj->removeFromGroup($categoryname)) {
|
||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||
}
|
||||
$obj->CATEGORIES->removeGroup($categoryname);
|
||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||
} else {
|
||||
$response->debug('Error parsing contact: ' . $contactId);
|
||||
}
|
||||
|
@ -37,15 +37,19 @@ class GroupProperty extends CompoundProperty {
|
||||
* \Sabre\VObject\Property
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function addGroup($name) {
|
||||
$name = trim($name);
|
||||
if($this->hasGroup($name)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$groups = $this->getParts();
|
||||
// Remove empty elements
|
||||
$groups = array_filter($groups, 'strlen');
|
||||
$groups[] = $name;
|
||||
$this->setParts($groups);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -295,6 +295,9 @@ class VCard extends VObject\Component\VCard {
|
||||
|
||||
/**
|
||||
* Get all group names in the vCards properties
|
||||
*
|
||||
* NOTE: Not to confuse with CATEGORIES groups
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function propertyGroups() {
|
||||
@ -309,4 +312,63 @@ class VCard extends VObject\Component\VCard {
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if vcard has group (CATEGORIES) $name
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function inGroup($name) {
|
||||
if(!isset($this->CATEGORIES)) {
|
||||
false;
|
||||
}
|
||||
|
||||
return $this->CATEGORIES->hasGroup($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add group (CATEGORIES) $name to vcard
|
||||
*
|
||||
* Return true if contact wasn't already in group
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function addToGroup($name) {
|
||||
if(!isset($this->CATEGORIES)) {
|
||||
$this->add('CATEGORIES');
|
||||
}
|
||||
|
||||
return $this->CATEGORIES->addGroup($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove group (CATEGORIES) $name from vcard
|
||||
*
|
||||
* Return true if vcard has been updated.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function removeFromGroup($name) {
|
||||
|
||||
if(!isset($this->CATEGORIES)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$updated = $this->CATEGORIES->removeGroup($name);
|
||||
// getParts() returns an array with an empty element if
|
||||
// CATEGORIES is empty
|
||||
$groups = $this->CATEGORIES->getParts();
|
||||
// Remove empty elements
|
||||
$groups = array_filter($groups, 'strlen');
|
||||
if(count($groups) === 0) {
|
||||
unset($this->{'CATEGORIES'});
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user