Skip to content

Commit

Permalink
Change submission language
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein committed Aug 1, 2024
1 parent 2123b86 commit 49d3017
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 6 deletions.
32 changes: 32 additions & 0 deletions src/components/Container/WorkflowPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import PkpHeader from '@/components/Header/Header.vue';
import LocalizeSubmission from '@/mixins/localizeSubmission.js';
import ajaxError from '@/mixins/ajaxError';
import dialog from '@/mixins/dialog.js';
import ChangeSubmissionLanguage from '@/pages/workflow/ChangeSubmissionLanguage.vue';
import SelectRevisionDecisionModal from '@/pages/workflow/SelectRevisionDecisionModal.vue';
import {useModal} from '@/composables/useModal';
export default {
name: 'WorkflowPage',
components: {
ChangeSubmissionLanguage,
ContributorsListPanel,
Composer,
Dropdown,
Expand All @@ -28,6 +30,8 @@ export default {
return {
activityLogLabel: '',
canAccessPublication: false,
canChangeSubmissionLanguage: false,
currentSubmissionLanguageLabel: '',
canEditPublication: false,
currentPublication: null,
decisionUrl: '',
Expand Down Expand Up @@ -311,6 +315,20 @@ export default {
).pkpHandler('$.pkp.controllers.modal.AjaxModalHandler', opts);
},
/**
* Open a modal displaying the change submission language form
*/
openChangeSubmissionLanguageModal() {
const {openSideModal} = useModal();
openSideModal(ChangeSubmissionLanguage, {
form: this.components[
pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE_METADATA
],
publicationId: this.workingPublication.id,
submissionId: this.submission.id,
});
},
/**
* Open a modal to prompt the user to confirm creation of
* a new version
Expand Down Expand Up @@ -734,6 +752,20 @@ export default {
}
}
.pkpSubmission__localeNotSupported {
margin: 0 -2rem;
padding: 1rem;
background: @primary;
font-size: @font-sml;
color: #fff;
text-align: center;
}
.pkpPublication__changeSubmissionLanguage {
display: block;
padding-bottom: 0.25rem;
}
// Integrate the grids in the publication tab
.pkpWorkflow__contributors,
#representations-grid {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Container/WorkflowPageOMP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ export default {
/**
* Update the work type to be an edited volume
* Update authors' isVolumeEditor to bool if null
*/
setAsEditedVolume() {
this.updateWorkType(this.getConstant('WORK_TYPE_EDITED_VOLUME'));
this.workingPublication.authors.forEach(
(author) => (author.isVolumeEditor = !!author.isVolumeEditor),
);
},
/**
Expand Down
7 changes: 1 addition & 6 deletions src/components/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,9 @@ export default {
missingValue = !value;
break;
case 'string':
case 'array':
if (!value.length) {
missingValue = true;
}
break;
case 'object':
// null values are stored as objects
if (!value) {
if (!value || (Array.isArray(value) && !value.length)) {
missingValue = true;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions src/components/Form/formHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export function shouldShowGroup(group, fields) {
if (typeof group.showWhen === 'string') {
return !!whenField.value;
}
if (Array.isArray(group.showWhen[1])) {
return group.showWhen[1].includes(whenField.value);
}
return whenField.value === group.showWhen[1];
}

Expand Down
52 changes: 52 additions & 0 deletions src/pages/workflow/ChangeSubmissionLanguage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<SideModalBody>
<template #pre-title>
{{ props.submissionId }}
</template>
<template #title>
{{ t('submission.list.changeSubmissionLanguage.title') }}
</template>
<template #description>
{{ store.publicationTitle }}
</template>
<div class="p-4">
<div class="bg-secondary p-4">
<div id="changeSubmissionLanguage" aria-live="polite">
<PkpForm
v-bind="store.form"
@set="store.set"
@success="store.success"
@cancel="store.closeSideModal"
></PkpForm>
</div>
</div>
</div>
</SideModalBody>
</template>

<script setup>
import {defineProps} from 'vue';
import PkpForm from '@/components/Form/Form.vue';
import SideModalBody from '@/components/Modal/SideModalBody.vue';
import {useChangeSubmissionLanguageStore} from '@/pages/workflow/changeSubmissionLanguageStore';
const props = defineProps({
form: {
type: Object,
required: true,
},
publicationId: {
type: Number,
required: true,
},
submissionId: {
type: Number,
required: true,
},
});
const store = useChangeSubmissionLanguageStore({
form: props.form,
publicationId: props.publicationId,
submissionId: props.submissionId,
});
</script>
96 changes: 96 additions & 0 deletions src/pages/workflow/changeSubmissionLanguageStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {inject} from 'vue';
import {defineComponentStore} from '@/utils/defineComponentStore';
import {useApiUrl} from '@/composables/useApiUrl';
import {useFetch} from '@/composables/useFetch';
import {useForm} from '@/composables/useForm';
import cloneDeep from 'clone-deep';

export const useChangeSubmissionLanguageStore = defineComponentStore(
'changeSubmissionLanguage',
(props) => {
/**
* Variables
*/

const {
apiUrl: {value: apiUrl},
} = useApiUrl(
`submissions/${props.submissionId}/publications/${props.publicationId}`,
);

const {
form: {value: form},
setValue,
} = useForm(cloneDeep(props.form));
// Set action api url
form.action = apiUrl + '/changeLocale';

const publicationTitle =
props.form.fields[2].value[props.form.primaryLocale];

const publicationProps = {};
// Get publication props
(async () => {
const {data, fetch} = useFetch(apiUrl, {
method: 'GET',
});
await fetch();
Object.assign(publicationProps, data.value ?? {});
delete publicationProps['locale'];
})();

const closeModal = inject('closeModal');

/**
* Functions
*/

function closeSideModal() {
closeModal();
}

/**
* Set form data
*/
const set = (_, data) => {
Object.keys(data).forEach((key) => (form[key] = data[key]));
const oldLocale = form.primaryLocale;
const newLocale = data.fields?.[0].value ?? oldLocale;
// Set fields when changing language
if (newLocale !== oldLocale) {
form.primaryLocale = newLocale;
form.fields.forEach((f) => {
if (publicationProps[f.name]) {
setValue(
f.name,
publicationProps[f.name][newLocale] ?? publicationProps[f.name],
);
// i18n.js t doesn't seem to support variable as tranlation key
// (i18nExtractKeys.vite.js: uiLocaleKeysBackend.json), using str.replace for now.
f.description = f.description.replace(
getLocaleName(oldLocale),
getLocaleName(newLocale),
);
}
});
}
};

/**
* Form success
*/
const success = () => {
location.reload();
};

return {closeSideModal, set, success, form, publicationTitle};

/**
* Aux functions
*/

function getLocaleName(locale) {
return form.fields[0].options.find(({value}) => value === locale).label;
}
},
);

0 comments on commit 49d3017

Please sign in to comment.