diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2022-09-30 16:12:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 16:12:02 +0200 |
commit | bf89263633bbf007a02cf75943abadd2f7291ef4 (patch) | |
tree | d708280facbf144402e1e44d8472eb7a2f4ae93f | |
parent | cf516677800006ffe062bdcf32c8d36eb7dad40b (diff) | |
parent | 8313fff49af3bd8f98ff1e010f89679f1a57588b (diff) |
Merge pull request #3001 from nextcloud/backport/3000/stable5.0
[stable5.0] Refactor manger property select logic
-rw-r--r-- | src/components/ContactDetails.vue | 2 | ||||
-rw-r--r-- | src/components/ContactDetails/ContactDetailsProperty.vue | 40 | ||||
-rw-r--r-- | src/components/Properties/PropertySelect.vue | 2 | ||||
-rw-r--r-- | src/mixins/OrgChartsMixin.js | 12 | ||||
-rw-r--r-- | src/models/rfcProps.js | 21 | ||||
-rw-r--r-- | src/utils/chartUtils.js | 9 |
6 files changed, 49 insertions, 37 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 089571fb..c1305141 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -218,6 +218,7 @@ duplication, we created a fake propModel and property with our own options here) --> <PropertySelect v-masonry-tile :prop-model="addressbookModel" + :options="addressbooksOptions" :value.sync="addressbook" :is-first-property="true" :is-last-property="true" @@ -481,7 +482,6 @@ export default { * Store getters filtered and mapped to usable object * This is the list of addressbooks that are available to write * - * @return {Array} * @return {{id: string, name: string}[]} */ addressbooksOptions() { diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue index feb8c06c..fe33352a 100644 --- a/src/components/ContactDetails/ContactDetailsProperty.vue +++ b/src/components/ContactDetails/ContactDetailsProperty.vue @@ -37,7 +37,7 @@ :local-contact="localContact" :prop-name="propName" :prop-type="propType" - :options="propName === 'x-managersname' ? contactsOptions : sortedModelOptions" + :options="sortedModelOptions" :is-read-only="isReadOnly" @delete="onDelete" @resize="onResize" @@ -182,7 +182,17 @@ export default { * @return {object[]} */ sortedModelOptions() { - if (this.propModel.options) { + if (!this.propModel.options) { + return [] + } + + if (typeof this.propModel.options === 'function') { + return this.propModel.options({ + contact: this.contact, + $store: this.$store, + selectType: this.selectType, + }) + } else { return this.propModel.options.reduce((list, option) => { if (!list.find(search => search.name === option.name)) { list.push(option) @@ -190,7 +200,6 @@ export default { return list }, this.selectType ? [this.selectType] : []) } - return [] }, /** @@ -213,31 +222,6 @@ export default { }, /** - * Return the options of contacts for x-managersname select - * - * @return {object[]} - */ - contactsOptions() { - if (this.propName !== 'x-managersname') { - return [] - } - - // Only allow contacts of the same address book - const otherContacts = this.otherContacts(this.contact) - // Reduce to an object to eliminate duplicates - return Object.values(otherContacts.reduce((prev, { key, value }) => { - const contact = this.$store.getters.getContact(key) - return { - ...prev, - [contact.uid]: { - id: contact.key, - name: contact.displayName, - }, - } - }, this.selectType ? { [this.selectType.value]: this.selectType } : {})) - }, - - /** * Returns the closest match to the selected type * or return the default selected as a new object if * none exists diff --git a/src/components/Properties/PropertySelect.vue b/src/components/Properties/PropertySelect.vue index 8efe6c82..f357f3ba 100644 --- a/src/components/Properties/PropertySelect.vue +++ b/src/components/Properties/PropertySelect.vue @@ -39,7 +39,7 @@ </div> <Multiselect v-model="matchedOptions" - :options="propModel.options || options" + :options="options" :placeholder="t('contacts', 'Select option')" :disabled="isSingleOption || isReadOnly" class="property__value" diff --git a/src/mixins/OrgChartsMixin.js b/src/mixins/OrgChartsMixin.js index a16050da..d3877b77 100644 --- a/src/mixins/OrgChartsMixin.js +++ b/src/mixins/OrgChartsMixin.js @@ -19,16 +19,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import { otherContacts } from '../utils/chartUtils' + export default { methods: { // The current component root otherContacts(self) { - return this.$store.getters.getSortedContacts.filter( - ({ key }) => { - const contact = this.$store.getters.getContact(key) - return contact.addressbook.id === self.addressbook.id && contact.uid !== self.uid - } - ) + return otherContacts({ + $store: this.$store, + self, + },) }, }, } diff --git a/src/models/rfcProps.js b/src/models/rfcProps.js index 13ec5bb0..861d74b0 100644 --- a/src/models/rfcProps.js +++ b/src/models/rfcProps.js @@ -21,6 +21,7 @@ */ import { VCardTime } from 'ical.js' import { loadState } from '@nextcloud/initial-state' +import { otherContacts } from '../utils/chartUtils' import ActionCopyNtoFN from '../components/Actions/ActionCopyNtoFN' import ActionToggleYear from '../components/Actions/ActionToggleYear' @@ -226,7 +227,25 @@ const properties = { readableName: t('contacts', 'Manager'), icon: 'icon-category-monitoring', default: false, - options: [], + options({ contact, $store, selectType }) { + // Only allow contacts of the same address book + const contacts = otherContacts({ + $store, + self: contact, + }) + + // Reduce to an object to eliminate duplicates + return Object.values(contacts.reduce((prev, { key }) => { + const contact = $store.getters.getContact(key) + return { + ...prev, + [contact.uid]: { + id: contact.key, + name: contact.displayName, + }, + } + }, selectType ? { [selectType.value]: selectType } : {})) + }, }, 'x-socialprofile': { multiple: true, diff --git a/src/utils/chartUtils.js b/src/utils/chartUtils.js index 7d48a38a..fe312908 100644 --- a/src/utils/chartUtils.js +++ b/src/utils/chartUtils.js @@ -26,3 +26,12 @@ export const transformNode = (contact) => { expanded: !contact.managersName, } } + +export const otherContacts = ({ $store, self }) => { + return $store.getters.getSortedContacts.filter( + ({ key }) => { + const contact = $store.getters.getContact(key) + return contact.addressbook.id === self.addressbook.id && contact.uid !== self.uid + } + ) +} |