From 99da477a9eef7553af5a3f73ebb474537ba12e8e Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 22 Feb 2023 14:46:29 +0200 Subject: [PATCH] Dynamically calculate mvea Model name --- .../js/comanage/components/mvea/mveas.js | 33 +++---------------- .../js/comanage/components/utils/helpers.js | 8 ++++- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/app/webroot/js/comanage/components/mvea/mveas.js b/app/webroot/js/comanage/components/mvea/mveas.js index 6e60fc271..878488970 100644 --- a/app/webroot/js/comanage/components/mvea/mveas.js +++ b/app/webroot/js/comanage/components/mvea/mveas.js @@ -25,6 +25,9 @@ */ import MveaItem from './mvea-item.js'; +import { + camelize +} from '../utils/helpers.js'; export default { props: { @@ -42,32 +45,7 @@ export default { }, computed: { mveaModel: function() { - switch(this.core.mveaType) { - case 'names': - return this.mveas.Names; - break; - case 'email_addresses': - return this.mveas.EmailAddresses; - break; - case 'identifiers': - return this.mveas.Identifiers; - break; - case 'ad_hoc_attributes': - return this.mveas.AdHocAttributes; - break; - case 'addresses': - return this.mveas.Addresses; - break; - case 'telephone_numbers': - return this.mveas.TelephoneNumbers; - break; - case 'urls': - return this.mveas.Urls; - break; - case 'pronouns': - return this.mveas.Pronouns; - break; - } + return this.mveas?.[camelize(this.core.mveaType)] } }, template: ` @@ -75,8 +53,7 @@ export default { + v-for='mvea in mveaModel' :mvea="mvea"> ` diff --git a/app/webroot/js/comanage/components/utils/helpers.js b/app/webroot/js/comanage/components/utils/helpers.js index 299cf2888..aeed98b1e 100644 --- a/app/webroot/js/comanage/components/utils/helpers.js +++ b/app/webroot/js/comanage/components/utils/helpers.js @@ -44,6 +44,12 @@ const constructLanguageString = (abbreviation) => { return `${regionNameEngish.of(abbreviation)} (${regionNameLocale.of(abbreviation)})`; } +// Snake case to Camel case +const camelize = (word) => { + return word.split("_").map(word => (word[0].toUpperCase() + word.slice(1))).join('') +} + export { - constructLanguageString + constructLanguageString, + camelize } \ No newline at end of file