Skip to content

Commit

Permalink
Merge pull request #649 from nextcloud/no-duplicate-types-vue
Browse files Browse the repository at this point in the history
Do not display dupisate types
  • Loading branch information
skjnldsv authored Sep 27, 2018
2 parents 6d848dc + d0db189 commit 96f0afd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
49 changes: 44 additions & 5 deletions src/components/ContactDetails/ContactDetailsProperty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:is="componentInstance" :select-type.sync="selectType" :prop-model="propModel"
:value.sync="value" :is-first-property="isFirstProperty" :property="property"
:is-last-property="isLastProperty" :class="{'property--last': isLastProperty}" :contact="contact"
@delete="deleteProp" />
:options="sortedModelOptions" @delete="deleteProp" />
</template>

<script>
Expand Down Expand Up @@ -109,10 +109,20 @@ export default {
return true
},

// the type of the prop e.g. FN
/**
* Return the type of the prop e.g. FN
*
* @returns {String}
*/
propName() {
return this.property.name
},
/**
* Return the type or property
*
* @see src/models/rfcProps
* @returns {String}
*/
propType() {
// if we have a force type set, use it!
if (this.propModel && this.propModel.force) {
Expand All @@ -121,12 +131,42 @@ export default {
return this.property.getDefaultType()
},

// template to use
/**
* RFC template matching this property
*
* @see src/models/rfcProps
* @returns {Object}
*/
propModel() {
return this.properties[this.propName]
},

// select type handler
/**
* Remove duplicate name amongst options
* but make sure to include the selected one
* in the final list
*
* @returns {Array<Object>}
*/
sortedModelOptions() {
if (this.propModel.options) {
return this.propModel.options.reduce((list, option) => {
if (!list.find(search => search.name === option.name)) {
list.push(option)
}
return list
}, this.selectType ? [this.selectType] : [])
}
return []
},

/**
* Returns the closest match to the selected type
* or return the default selected as a new object if
* none exists
*
* @returns Object|undefined
*/
selectType: {
get() {
if (this.propModel && this.propModel.options && this.type) {
Expand Down Expand Up @@ -165,7 +205,6 @@ export default {
name: selectedType
}
}
return false
},
set(data) {
// ical.js take types as arrays
Expand Down
6 changes: 5 additions & 1 deletion src/components/Properties/PropertyDateTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="property__row">
<!-- type selector -->
<multiselect v-if="propModel.options" v-model="localType"
:options="propModel.options" :searchable="false" :placeholder="t('contacts', 'Select type')"
:options="options" :searchable="false" :placeholder="t('contacts', 'Select type')"
class="multiselect-vue property__label" track-by="id" label="name"
@input="updateType" />

Expand Down Expand Up @@ -148,6 +148,10 @@ export default {
default: '',
required: true
},
options: {
type: Array,
default: () => []
},
property: {
type: Object,
default: () => {},
Expand Down
6 changes: 5 additions & 1 deletion src/components/Properties/PropertyMultipleText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="property__row">
<!-- type selector -->
<multiselect v-if="propModel.options" v-model="localType"
:options="propModel.options" :searchable="false" :placeholder="t('contacts', 'Select type')"
:options="options" :searchable="false" :placeholder="t('contacts', 'Select type')"
class="multiselect-vue property__label" track-by="id" label="name"
@input="updateType" />

Expand Down Expand Up @@ -96,6 +96,10 @@ export default {
default: () => [],
required: true
},
options: {
type: Array,
default: () => []
},
property: {
type: Object,
default: () => {},
Expand Down
6 changes: 5 additions & 1 deletion src/components/Properties/PropertyText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="property__row">
<!-- type selector -->
<multiselect v-if="propModel.options" v-model="localType"
:options="propModel.options" :searchable="false" :placeholder="t('contacts', 'Select type')"
:options="options" :searchable="false" :placeholder="t('contacts', 'Select type')"
class="multiselect-vue property__label" track-by="id" label="name"
@input="updateType" />

Expand Down Expand Up @@ -76,6 +76,10 @@ export default {
default: '',
required: true
},
options: {
type: Array,
default: () => []
},
isFirstProperty: {
type: Boolean,
default: true
Expand Down

0 comments on commit 96f0afd

Please sign in to comment.