mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +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());
|
console.log('Showing', contact.getId());
|
||||||
contact.show();
|
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() {
|
ContactList.prototype.showUncategorized = function() {
|
||||||
console.log('ContactList.showUncategorized');
|
console.log('ContactList.showUncategorized');
|
||||||
for(var contact in this.contacts) {
|
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].getListItemElement().show();
|
||||||
this.contacts[contact].setThumbnail();
|
this.contacts[contact].setThumbnail();
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,10 +96,10 @@ class GroupController extends Controller {
|
|||||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||||
);
|
);
|
||||||
if($obj) {
|
if($obj) {
|
||||||
if(!isset($obj->CATEGORIES)) {
|
if(!$obj->inGroup($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($obj->CATEGORIES->removeGroup($name)) {
|
if($obj->removeFromGroup($name)) {
|
||||||
$backend->updateContact(null, $id, $obj, array('noCollection' => true, 'isBatch' => true));
|
$backend->updateContact(null, $id, $obj, array('noCollection' => true, 'isBatch' => true));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -195,12 +195,10 @@ class GroupController extends Controller {
|
|||||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||||
);
|
);
|
||||||
if($obj) {
|
if($obj) {
|
||||||
if(!isset($obj->CATEGORIES)) {
|
if($obj->addToGroup($categoryname)) {
|
||||||
$obj->add('CATEGORIES');
|
|
||||||
}
|
|
||||||
$obj->CATEGORIES->addGroup($categoryname);
|
|
||||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
||||||
$tagMgr->tagAs($contactId, $categoryId);
|
$tagMgr->tagAs($contactId, $categoryId);
|
||||||
}
|
}
|
||||||
@ -243,10 +241,11 @@ class GroupController extends Controller {
|
|||||||
);
|
);
|
||||||
if($obj) {
|
if($obj) {
|
||||||
if(!isset($obj->CATEGORIES)) {
|
if(!isset($obj->CATEGORIES)) {
|
||||||
$obj->add('CATEGORIES');
|
return $response;
|
||||||
}
|
}
|
||||||
$obj->CATEGORIES->removeGroup($categoryname);
|
if($obj->removeFromGroup($categoryname)) {
|
||||||
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
$backend->updateContact(null, $contactId, $obj, array('noCollection' => true));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$response->debug('Error parsing contact: ' . $contactId);
|
$response->debug('Error parsing contact: ' . $contactId);
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,19 @@ class GroupProperty extends CompoundProperty {
|
|||||||
* \Sabre\VObject\Property
|
* \Sabre\VObject\Property
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function addGroup($name) {
|
public function addGroup($name) {
|
||||||
$name = trim($name);
|
$name = trim($name);
|
||||||
if($this->hasGroup($name)) {
|
if($this->hasGroup($name)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
$groups = $this->getParts();
|
$groups = $this->getParts();
|
||||||
|
// Remove empty elements
|
||||||
|
$groups = array_filter($groups, 'strlen');
|
||||||
$groups[] = $name;
|
$groups[] = $name;
|
||||||
$this->setParts($groups);
|
$this->setParts($groups);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,6 +295,9 @@ class VCard extends VObject\Component\VCard {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all group names in the vCards properties
|
* Get all group names in the vCards properties
|
||||||
|
*
|
||||||
|
* NOTE: Not to confuse with CATEGORIES groups
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function propertyGroups() {
|
public function propertyGroups() {
|
||||||
@ -309,4 +312,63 @@ class VCard extends VObject\Component\VCard {
|
|||||||
return $this->groups;
|
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