From caefe3ac654348185e72306da965b393cc5bcf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Sun, 18 Nov 2018 17:49:27 +0100 Subject: [PATCH] Always show groups Fix #727 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/ContactDetails.vue | 34 +++++++++++++++++++ .../ContactDetails/ContactDetailsProperty.vue | 6 ---- src/components/Properties/PropertyGroups.vue | 16 +++++---- src/models/contact.js | 1 + src/models/rfcProps.js | 3 -- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 7ed646394..b08b1abe4 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -109,6 +109,11 @@ + + + @@ -283,6 +288,35 @@ export default { } }, + groupsModel() { + return { + readableName: t('contacts', 'Groups') + // icon: 'icon-address-book' + } + }, + + /** + * Usable groups object linked to the local contact + * + * @param {string[]} data An array of groups + * @returns {Array} + */ + groups: { + get: function() { + return this.contact.groups + }, + set: function(data) { + console.log(data); + let property = this.contact.vCard.getFirstProperty('categories') + if (!property) { + // Ical.js store comma separated by an Array of array of string + property = this.contact.vCard.addPropertyWithValue('categories', [data]) + } + property.setValues(data) + this.updateContact() + } + }, + /** * Store getters filtered and mapped to usable object * diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue index 4191ef16e..f5de4fd54 100644 --- a/src/components/ContactDetails/ContactDetailsProperty.vue +++ b/src/components/ContactDetails/ContactDetailsProperty.vue @@ -38,7 +38,6 @@ import Contact from 'Models/contact' import PropertyText from 'Components/Properties/PropertyText' import PropertyMultipleText from 'Components/Properties/PropertyMultipleText' import PropertyDateTime from 'Components/Properties/PropertyDateTime' -import propertyGroups from 'Components/Properties/PropertyGroups' import PropertySelect from 'Components/Properties/PropertySelect' export default { @@ -68,11 +67,6 @@ export default { computed: { // dynamically load component based on property type componentInstance() { - // groups - if (this.propName === 'categories') { - return propertyGroups - } - // dynamic matching if (this.property.isMultiValue && this.propType === 'text') { return PropertyMultipleText diff --git a/src/components/Properties/PropertyGroups.vue b/src/components/Properties/PropertyGroups.vue index 15677320c..70407a009 100644 --- a/src/components/Properties/PropertyGroups.vue +++ b/src/components/Properties/PropertyGroups.vue @@ -28,10 +28,11 @@ + :multiple="true" :taggable="true" :close-on-select="false" + :readonly="isReadOnly" :tag-width="60" + tag-placeholder="create" class="property__value" + @input="updateValue" @tag="validateGroup" @select="addContactToGroup" + @remove="removeContactToGroup"> +{{ localValue.length - 3 }} @@ -98,7 +99,7 @@ export default { /** * Debounce and send update event to parent */ - updateValue: debounce(function(e) { + updateValue: debounce(function() { // https://vuejs.org/v2/guide/components-custom-events.html#sync-Modifier this.$emit('update:value', this.localValue) }, 500), @@ -108,11 +109,12 @@ export default { * * @param {String} groupName the group name */ - addContactToGroup(groupName) { - this.$store.dispatch('addContactToGroup', { + async addContactToGroup(groupName) { + await this.$store.dispatch('addContactToGroup', { contact: this.contact, groupName }) + this.updateValue() }, /** diff --git a/src/models/contact.js b/src/models/contact.js index c2a5bfcc0..3f985b902 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -166,6 +166,7 @@ export default class Contact { let groupsProp = this.vCard.getFirstProperty('categories') if (groupsProp) { return groupsProp.getValues() + .filter(group => group !== '') } return [] } diff --git a/src/models/rfcProps.js b/src/models/rfcProps.js index 3f7efe534..3a21b2501 100644 --- a/src/models/rfcProps.js +++ b/src/models/rfcProps.js @@ -88,9 +88,6 @@ const properties = { { id: 'OTHER', name: t('contacts', 'Other') } ] }, - categories: { - readableName: t('contacts', 'Groups') - }, bday: { readableName: t('contacts', 'Birthday'), icon: 'icon-calendar-dark',