Skip to content

Commit

Permalink
Always show groups
Browse files Browse the repository at this point in the history
Fix #727

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Nov 18, 2018
1 parent 0547f92 commit caefe3a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
34 changes: 34 additions & 0 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<property-select :prop-model="addressbookModel" :value.sync="addressbook" :is-first-property="true"
:is-last-property="true" :property="{}" class="property--addressbooks property--last" />

<!-- Groups always visible. -->
<property-groups :prop-model="groupsModel" :value.sync="groups" :contact="contact"
:is-read-only="isReadOnly" :is-first-property="true" :is-last-property="true"
class="property--addressbooks property--last" />

<!-- new property select -->
<add-new-prop v-if="!isReadOnly" :contact="contact" />
</section>
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 0 additions & 6 deletions src/components/ContactDetails/ContactDetailsProperty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/components/Properties/PropertyGroups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

<!-- multiselect taggable groups with a limit to 3 groups shown -->
<multiselect v-model="localValue" :options="groups" :placeholder="t('contacts', 'Add contact in group')"
:limit="3" :multiple="true" :taggable="true"
:close-on-select="false" :readonly="isReadOnly" tag-placeholder="create"
class="property__value" @input="updateValue" @tag="validateGroup"
@select="addContactToGroup" @remove="removeContactToGroup">
: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">

<!-- show how many groups are hidden and add tooltip -->
<span v-tooltip.auto="formatGroupsTitle" slot="limit" class="multiselect__limit">+{{ localValue.length - 3 }}</span>
Expand Down Expand Up @@ -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),
Expand All @@ -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()
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default class Contact {
let groupsProp = this.vCard.getFirstProperty('categories')
if (groupsProp) {
return groupsProp.getValues()
.filter(group => group !== '')
}
return []
}
Expand Down
3 changes: 0 additions & 3 deletions src/models/rfcProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit caefe3a

Please sign in to comment.