Skip to content

Commit

Permalink
Dynamically calculate mvea Model name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed Feb 22, 2023
1 parent 7c90beb commit 99da477
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
33 changes: 5 additions & 28 deletions app/webroot/js/comanage/components/mvea/mveas.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/

import MveaItem from './mvea-item.js';
import {
camelize
} from '../utils/helpers.js';

export default {
props: {
Expand All @@ -42,41 +45,15 @@ 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: `
<ul class="cm-mvea fields data-list">
<mvea-item
:txt="this.txt"
:core="this.core"
v-for='mvea in mveaModel'
:mvea="mvea">
v-for='mvea in mveaModel' :mvea="mvea">
</mvea-item>
</ul>
`
Expand Down
8 changes: 7 additions & 1 deletion app/webroot/js/comanage/components/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 99da477

Please sign in to comment.