diff options
author | Jessica <jessica@Absolventas-MacBook-Pro.local> | 2018-08-03 15:09:18 +0200 |
---|---|---|
committer | Jessica <jessica@Absolventas-MacBook-Pro.local> | 2018-08-03 15:09:18 +0200 |
commit | 684be9212f93782356d411e2275c1138632d5b48 (patch) | |
tree | f6d7cf4ec214e067052fc72f6c11178840d8678d /src | |
parent | caee2123e68fc37559fdefad715f109f5e09c00c (diff) | |
parent | 3c82478309e5a2ca99cb5b8cbc556986627f8665 (diff) |
merged with upstream/vue
Diffstat (limited to 'src')
-rw-r--r-- | src/main.js | 5 | ||||
-rw-r--r-- | src/models/contact.js | 26 | ||||
-rw-r--r-- | src/models/rfcProps.js | 2 | ||||
-rw-r--r-- | src/router/index.js | 2 | ||||
-rw-r--r-- | src/services/parseVcf.js | 2 | ||||
-rw-r--r-- | src/store/FakeName.vcf | 13 | ||||
-rw-r--r-- | src/store/addressbooks.js | 3 | ||||
-rw-r--r-- | src/store/contacts.js | 7 | ||||
-rw-r--r-- | src/store/groups.js | 36 | ||||
-rw-r--r-- | src/store/index.js | 2 | ||||
-rw-r--r-- | src/views/Contacts.vue | 55 |
11 files changed, 123 insertions, 30 deletions
diff --git a/src/main.js b/src/main.js index 10a22e8b..79347034 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> @@ -33,8 +33,7 @@ Vue.prototype.n = n Vue.prototype.OC = OC Vue.prototype.OCA = OCA -/* eslint-disable-next-line no-new */ -new Vue({ +export default new Vue({ el: '#content', router, store, diff --git a/src/models/contact.js b/src/models/contact.js index 6f97f47e..a517f751 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> @@ -93,6 +93,30 @@ export default class Contact { } /** + * Return the groups + * + * @readonly + * @memberof Contact + */ + get groups() { + let prop = this.vCard.getFirstProperty('categories') + if (prop) { + return this.vCard.getFirstProperty('categories').getValues() + } + return [] + } + + /** + * Return the groups + * + * @readonly + * @memberof Contact + */ + get kind() { + return this.firstIfArray(this.vCard.getFirstPropertyValue('kind')) + } + + /** * Return the first email * * @readonly diff --git a/src/models/rfcProps.js b/src/models/rfcProps.js index 6d47790f..2e690a99 100644 --- a/src/models/rfcProps.js +++ b/src/models/rfcProps.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> diff --git a/src/router/index.js b/src/router/index.js index 4f542390..78ef278f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> diff --git a/src/services/parseVcf.js b/src/services/parseVcf.js index 7ed04a79..804f4846 100644 --- a/src/services/parseVcf.js +++ b/src/services/parseVcf.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> diff --git a/src/store/FakeName.vcf b/src/store/FakeName.vcf index 0f6c254a..4126c8a0 100644 --- a/src/store/FakeName.vcf +++ b/src/store/FakeName.vcf @@ -1,5 +1,15 @@ BEGIN:VCARD VERSION:3.0 +PRODID:-//Apple Inc.//AddressBook 10.0//EN +N:macOS;;;; +FN:macOS +KIND:group +MEMBER:urn:uuid:cd314b39-b71a-41cf-b4eb-5cb61dd6fa24 +REV:2017-07-27T05:56:33Z +UID:5acf667e-1cbf-48a8-87fe-546ee31a0b23 +END:VCARD +BEGIN:VCARD +VERSION:3.0 N:Cunningham;Liam;;Mr.; FN:Liam Cunningham NICKNAME:Begivaing81 @@ -8,7 +18,7 @@ GENDER:male ORG:Central Hardware; TITLE:Auditing clerk EMAIL;TYPE=HOME,INTERNET,pref:LiamCunningham@superrito.com -CATEGORIES:Tech +CATEGORIES:Tech,University TEL;TYPE=VOICE,HOME;VALUE=text:06-22957835 ADR;TYPE=HOME:;;Beilen;DR;9413 BA;Netherlands END:VCARD @@ -42,7 +52,6 @@ ADR;TYPE=HOME:;;Waillet;WNA;5377;Belgium END:VCARD BEGIN:VCARD VERSION:3.0 -UID:ed314b39-b71a-41cf-b4eb-5cb61dd6fa24 N:Myers;Michael;;Mr.; FN:Michael Myers NICKNAME:Vends1961 diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js index 64ce0f14..18fc245e 100644 --- a/src/store/addressbooks.js +++ b/src/store/addressbooks.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> @@ -172,6 +172,7 @@ const actions = { await context.commit('appendContactsToAddressbook', { addressbook, contacts }) await context.commit('appendContacts', contacts) await context.commit('sortContacts') + await context.commit('appendGroups', contacts) } } diff --git a/src/store/contacts.js b/src/store/contacts.js index 8b1e0ec6..72b5f821 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> @@ -29,6 +29,7 @@ const state = { sortedContacts: [], orderKey: 'displayName' } + const mutations = { /** @@ -89,6 +90,8 @@ const mutations = { */ async sortContacts(state) { state.sortedContacts = Object.values(state.contacts) + // exclude groups + .filter(contact => contact.kind !== 'group') .map(contact => { return { key: contact.key, value: contact[state.orderKey] } }) .sort((a, b) => { var nameA = a.value.toUpperCase() // ignore upper and lowercase @@ -108,12 +111,14 @@ const mutations = { } } + const getters = { getContacts: state => state.contacts, getSortedContacts: state => state.sortedContacts, getContact: (state) => (uid) => state.contacts[uid], getOrderKey: state => state.orderKey } + const actions = { deleteContact(context, contact) { context.commit('deleteContact', contact) diff --git a/src/store/groups.js b/src/store/groups.js index e91e9454..a273f616 100644 --- a/src/store/groups.js +++ b/src/store/groups.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> @@ -23,12 +23,44 @@ const state = { groups: [] } -const mutations = {} +const mutations = { + /** + * Extract all the groups from the provided contacts + * + * @param {Object} state + * @param {Contact[]} contacts + */ + appendGroups(state, contacts) { + // init groups list + let groups = Object.values(contacts) + .map(contact => contact.groups.map(group => { + return { + name: group, + contacts: [] + } + })[0]) + state.groups = state.groups.concat(groups) + .filter(function(group, index, self) { + return group && self.findIndex(search => search && search.name === group.name) === index + }) + // append keys to groups + Object.values(contacts) + .forEach(contact => { + if (contact.groups) { + contact.groups.forEach(group => { + state.groups.find(search => search.name === group).contacts.push(contact.key) + }) + } + }) + } +} + const getters = { getGroups(state) { return state.groups } } + const actions = {} export default { state, mutations, getters, actions } diff --git a/src/store/index.js b/src/store/index.js index 5607fc05..240dd7c4 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,4 +1,4 @@ -/* +/** * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index c0c73e9e..3cac74e5 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -42,7 +42,7 @@ <div id="app-content"> <div id="app-content-wrapper"> <!-- contacts list --> - <content-list :list="sortedContacts" :contacts="contacts" :loading="loading" /> + <content-list :list="contactsList" :contacts="contacts" :loading="loading" /> <!-- main contacts details --> <content-details :loading="loading" :uid="selectedContact" /> </div> @@ -105,6 +105,40 @@ export default { return this.$store.getters.getOrderKey }, + /** + * contacts list based on the selected group + * filters are pretty fast, so let's only intersect the groups + * contacts and the full sorted contacts List + */ + contactsList() { + if (this.selectedGroup === t('contacts', 'All contacts')) { + return this.sortedContacts + } + let group = this.groups.filter(group => group.name === this.selectedGroup)[0] + if (group) { + return this.sortedContacts.filter(contact => group.contacts.indexOf(contact.key) >= 0) + } + return [] + }, + + // generate groups menu from groups store + groupsMenu() { + return this.groups.map(group => { + return { + id: group.name.replace(' ', '_'), + key: group.name.replace(' ', '_'), + router: { + name: 'group', + params: { selectedGroup: group.name } + }, + text: group.name, + utils: { + counter: group.contacts.length + } + } + }) + }, + // building the main menu menu() { return { @@ -115,9 +149,10 @@ export default { icon: 'icon-add', action: this.newContact }, - items: this.allGroup.concat(this.groups) + items: this.allGroup.concat(this.groupsMenu) } }, + // default group for every contacts allGroup() { return [{ @@ -132,18 +167,6 @@ export default { utils: { counter: this.sortedContacts.length } - }, { - id: 'everyone2', - key: 'everyone2', - icon: 'icon-contacts-dark', - router: { - name: 'group', - params: { selectedGroup: t('contacts', 'All contacts2') } - }, - text: t('contacts', 'All contacts2'), - utils: { - counter: this.sortedContacts.length - } }] } }, @@ -190,7 +213,7 @@ export default { }, selectFirstContactIfNone() { - let inList = Object.keys(this.contacts).findIndex(key => key === this.selectedContact) > -1 + let inList = this.contactsList.findIndex(contact => contact.key === this.selectedContact) > -1 if (this.selectedContact === undefined || !inList) { if (this.selectedContact && !inList) { OC.Notification.showTemporary(t('contacts', 'Contact not found')) @@ -199,7 +222,7 @@ export default { name: 'contact', params: { selectedGroup: this.selectedGroup, - selectedContact: Object.values(this.contacts)[0].key + selectedContact: Object.values(this.contactsList)[0].key } }) } |