Skip to content

Commit

Permalink
Do not copy ror to author_affiliation_settings;
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed Nov 18, 2024
1 parent 0f99897 commit 6a8601f
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 314 deletions.
3 changes: 2 additions & 1 deletion public/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ window.pkp = {
'user.affiliations.deleteModal.title': 'Are you sure?',
'user.affiliations.deleteModal.message': 'The institution <strong>{$institution}</strong> will be deleted.',
'user.affiliations.searchPhraseLabel': 'Type the institute name in {$language}',
'user.affiliations.searchPhraseNothingFound': 'Your search phrase could not be found'
'user.affiliations.searchPhraseNothingFound': 'Your search phrase could not be found',
'user.affiliations.primaryLocaleRequired': 'The primary language {$primaryLocale} is required',
},

tinyMCE: {
Expand Down
130 changes: 71 additions & 59 deletions src/components/Form/fields/FieldAffiliations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@
<TableBody>
<TableRow v-for="(row, indexRow) in currentValue" :key="indexRow">
<TableCell>
<span class="text-lg-semibold">
<span v-if="row.name[primaryLocale]" class="text-lg-semibold">
{{ row.name[primaryLocale] }}
</span>
<Icon
v-if="!row.name[primaryLocale]"
v-bind="{icon: 'exclamation-triangle'}"
/>
<span
v-if="!row.name[primaryLocale]"
class="text-lg-semibold text-negative"
>
{{
row.name[primaryLocale]
? row.name[primaryLocale]
: getAlternativeDisplayName(row.name)
t('user.affiliations.primaryLocaleRequired', {
primaryLocale: getLocaleDisplayName(primaryLocale),
})
}}
</span>
<a v-if="row.ror" :href="row.ror" target="_blank">
Expand All @@ -50,7 +60,7 @@
>
<div>
<label
v-if="supportedFormLocalesKeys.includes(localeName)"
v-if="supportedFormLocaleKeys.includes(localeName)"
:for="
'contributors-affiliations-' +
indexRow +
Expand All @@ -71,7 +81,7 @@
</div>
<div>
<input
v-if="supportedFormLocalesKeys.includes(localeName)"
v-if="supportedFormLocaleKeys.includes(localeName)"
:id="
'contributors-affiliations-' +
indexRow +
Expand All @@ -90,15 +100,10 @@
</div>
</TableCell>
<TableCell>
<Icon
class="h-5 w-5 text-primary"
icon="'MoreOptions'"
aria-hidden="true"
/>
<DropdownActions
v-if="!(indexRow === indexEditMode)"
v-bind="rowActionsArgs(indexRow)"
:class="'border-transparent'"
:class="'dropDownActions border-transparent'"
@action="rowActionsHandler"
/>
<button
Expand All @@ -119,7 +124,7 @@
>
{{
t('user.affiliations.searchPhraseLabel', {
language: getLocaleDisplayName('en'),
language: getLocaleDisplayName(defaultLocale),
})
}}
</label>
Expand Down Expand Up @@ -157,7 +162,7 @@
class="cursor-pointer border-transparent px-2 py-2 text-lg-normal text-primary hover:bg-hover hover:text-on-dark hover:enabled:underline"
@click="selectRorOrganization(organization)"
>
{{ organization.displayName }} | &nbsp;
{{ organization.displayName }} &nbsp;
<Icon :icon="'ror'" :class="'mr-2'" :inline="true" />
</a>
<a
Expand Down Expand Up @@ -195,7 +200,7 @@
>
<div>
<span
v-if="supportedFormLocalesKeys.includes(localeAddMode)"
v-if="supportedFormLocaleKeys.includes(localeAddMode)"
class="text-lg-normal"
>
{{
Expand All @@ -210,7 +215,7 @@
</div>
<div>
<input
v-if="supportedFormLocalesKeys.includes(localeAddMode)"
v-if="supportedFormLocaleKeys.includes(localeAddMode)"
:id="
'contributors-affiliations-newAffiliation' +
'-' +
Expand All @@ -231,6 +236,7 @@
<div v-if="showAddMode">
<button
class="pkpButton border-transparent py-2 text-lg-semibold text-primary hover:enabled:underline"
:disabled="!validate(newAffiliationPending)"
@click="addAffiliation"
>
{{ t('common.insert', {}) }}
Expand Down Expand Up @@ -277,7 +283,7 @@ const props = defineProps({
},
supportedFormLocales: {
type: Array,
default: () => {},
default: () => [],
},
value: {
type: Array,
Expand All @@ -288,27 +294,32 @@ const props = defineProps({
const authorId = props.authorId;
const primaryLocale = props.primaryLocale;
const supportedFormLocales = props.supportedFormLocales;
const supportedFormLocalesKeys = supportedFormLocales.map(function (language) {
return language.key;
});
const currentValue = props.value;
const apiResponse = ref([]);
const newAffiliationPending = ref({});
const searchPhrase = ref('');
const supportedFormLocaleKeys = supportedFormLocales.map(function (language) {
return language.key;
});
const defaultLocale = 'en';
const selectCustomOrganization = function () {
newAffiliationPending.value = getNewItemTemplate();
newAffiliationPending.value.name[primaryLocale] = searchPhrase.value;
apiResponse.value = [];
};
const selectRorOrganization = function (item) {
newAffiliationPending.value = getNewItemTemplate();
newAffiliationPending.value.ror = item.ror;
supportedFormLocalesKeys.forEach((locale) => {
newAffiliationPending.value.name[primaryLocale] = item.displayName;
supportedFormLocaleKeys.forEach((locale) => {
if (typeof item.name[locale] !== 'undefined') {
newAffiliationPending.value.name[locale] = item.name[locale];
}
});
apiResponse.value = [];
};
const addAffiliation = function () {
Expand Down Expand Up @@ -416,14 +427,14 @@ const closeEditMode = function () {
};
const translations = function (row) {
let names = row.name;
let total = supportedFormLocalesKeys.length;
let total = supportedFormLocaleKeys.length;
let translated = 0;
for (let key in names) {
if (supportedFormLocalesKeys.includes(key) && names[key].length > 0) {
Object.keys(names).forEach((key) => {
if (supportedFormLocaleKeys.includes(key) && names[key].length > 0) {
translated++;
}
}
});
if (total === translated) {
return t('user.affiliations.translationsAllAvailable', {});
Expand All @@ -434,6 +445,9 @@ const translations = function (row) {
});
}
};
const validate = function (item) {
return !!(item.ror || item.name[primaryLocale]);
};
watch(
currentValue,
Expand Down Expand Up @@ -472,67 +486,61 @@ async function searchPhraseChanged() {
}
function makeCurrentValueCompatible() {
Object.keys(currentValue).forEach((index) => {
supportedFormLocalesKeys.forEach((locale) => {
currentValue.forEach((value, index) => {
supportedFormLocaleKeys.forEach((locale) => {
if (!(locale in currentValue[index].name)) {
currentValue[index].name[locale] = '';
}
});
// position name for primaryLocale first
let namePrimaryLocale = {};
namePrimaryLocale[primaryLocale] = currentValue[index].name[primaryLocale];
let nameRest = Object.keys(currentValue[index].name)
.filter((key) => !primaryLocale.includes(key))
.reduce((obj, key) => {
obj[key] = currentValue[index].name[key];
return obj;
}, {});
currentValue[index].name = {...namePrimaryLocale, ...nameRest};
currentValue[index].name = sortNamesPrimaryFirst(
currentValue[index].name,
);
});
});
}
function getNewItemTemplate() {
let newItem = {
let names = {};
names[primaryLocale] = '';
supportedFormLocaleKeys.forEach((locale) => {
names[locale] = '';
});
names = sortNamesPrimaryFirst(names);
return {
id: null,
authorId: authorId,
ror: null,
name: {},
name: names,
};
supportedFormLocalesKeys.forEach((locale) => {
newItem.name[locale] = '';
});
return newItem;
}
function getLocaleDisplayName(locale) {
let displayName = locale;
supportedFormLocales.forEach((language) => {
if (language['key'] === locale) {
displayName = language['label'];
if (language.key === locale) {
displayName = language.label;
}
});
return displayName;
}
function getAlternativeDisplayName(names) {
let locale = '';
function sortNamesPrimaryFirst(names) {
let nameFirst = {};
let nameRest = {};
Object.keys(names).forEach((key) => {
if (names[key].length > 0) {
locale = key;
return false;
if (key === primaryLocale) {
nameFirst[primaryLocale] = names[key];
} else {
nameRest[key] = names[key];
}
});
if (locale.length > 0) {
return names[locale] + ' [' + getLocaleDisplayName(locale) + ']';
}
return '';
return {...nameFirst, ...nameRest};
}
</script>

Expand Down Expand Up @@ -561,6 +569,10 @@ function getAlternativeDisplayName(names) {
table td:nth-child(3) {
text-align: right;
}
.dropDownActions svg {
width: 1.5em;
}
}
.pkpFormField--affiliations__control .searchPhraseResults {
Expand Down
Loading

0 comments on commit 6a8601f

Please sign in to comment.