Skip to content

Commit

Permalink
Support phonetic name as sort key
Browse files Browse the repository at this point in the history
Signed-off-by: Tomohiro Masubuchi <bucchi79@gmail.com>
  • Loading branch information
t-bucchi committed Aug 9, 2020
1 parent 8b8a200 commit 59f23ed
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/components/Settings/SettingsSortContacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export default {
label: t('contacts', 'Last name'),
key: 'lastName',
},
{
label: t('contacts', 'Phonetic first name'),
key: 'phoneticFirstName',
},
{
label: t('contacts', 'Phonetic last name'),
key: 'phoneticLastName',
},
{
label: t('contacts', 'Display name'),
key: 'displayName',
Expand Down
31 changes: 31 additions & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export default class Contact {
if (orderKey && n && !isEmpty(n)) {
switch (orderKey) {
case 'firstName':
case 'phoneticFirstName':
// Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.
// -> John Stevenson
return n.slice(0, 2).reverse().join(' ')
Expand Down Expand Up @@ -459,6 +460,36 @@ export default class Contact {
return this.displayName
}

/**
* Return the phonetic first name if exists
* Returns the first name or displayName otherwise
*
* @readonly
* @memberof Contact
* @returns {string} phoneticFirstName|firstName|displayName
*/
get phoneticFirstName() {
if (this.vCard.hasProperty('x-phonetic-first-name')) {
return this.vCard.getFirstPropertyValue('x-phonetic-first-name')
}
return this.firstName
}

/**
* Return the phonetic last name if exists
* Returns the displayName otherwise
*
* @readonly
* @memberof Contact
* @returns {string} lastName|displayName
*/
get phoneticLastName() {
if (this.vCard.hasProperty('x-phonetic-last-name')) {
return this.vCard.getFirstPropertyValue('x-phonetic-last-name')
}
return this.lastName
}

/**
* Return all the properties as Property objects
*
Expand Down
3 changes: 2 additions & 1 deletion src/store/addressbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ const actions = {
*/
async getContactsFromAddressBook(context, { addressbook }) {
return addressbook.dav
.findAllAndFilterBySimpleProperties(['EMAIL', 'UID', 'CATEGORIES', 'FN', 'ORG', 'N'])
.findAllAndFilterBySimpleProperties(['EMAIL', 'UID', 'CATEGORIES', 'FN', 'ORG', 'N',
'X-PHONETIC-FIRST-NAME', 'X-PHONETIC-LAST-NAME'])
.then((response) => {
// We don't want to lose the url information
// so we need to parse one by one
Expand Down

0 comments on commit 59f23ed

Please sign in to comment.