Skip to content

Commit

Permalink
Change submission language
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein committed Jul 30, 2024
1 parent 2123b86 commit 9d48823
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 7 deletions.
34 changes: 33 additions & 1 deletion src/components/Container/WorkflowPage.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<script type="text/javascript">
import Page from './Page.vue';
import ChangeSubmissionLanguage from '@/pages/workflow/ChangeSubmissionLanguage.vue';
import ContributorsListPanel from '@/components/ListPanel/contributors/ContributorsListPanel.vue';
import PublicationSectionJats from '@/pages/workflow/PublicationSectionJats.vue';
import Composer from '@/components/Composer/Composer.vue';
import Dropdown from '@/components/Dropdown/Dropdown.vue';
import Modal from '@/components/Modal/Modal.vue';
import PkpHeader from '@/components/Header/Header.vue';
import {useModal} from '@/composables/useModal';
import LocalizeSubmission from '@/mixins/localizeSubmission.js';
import ajaxError from '@/mixins/ajaxError';
import dialog from '@/mixins/dialog.js';
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 @@ -57,6 +61,7 @@ export default {
versionConfirmMessage: '',
versionConfirmTitle: '',
workingPublication: null,
openSideModal: null,
};
},
computed: {
Expand Down Expand Up @@ -311,6 +316,19 @@ 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
],
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
46 changes: 46 additions & 0 deletions src/pages/workflow/ChangeSubmissionLanguage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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,
},
submissionId: {
type: Number,
required: true,
},
});
const store = useChangeSubmissionLanguageStore({
form: props.form,
});
</script>
90 changes: 90 additions & 0 deletions src/pages/workflow/changeSubmissionLanguageStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {inject} from 'vue';
import {defineComponentStore} from '@/utils/defineComponentStore';
import {useForm} from '@/composables/useForm';
import cloneDeep from 'clone-deep';

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

const {
form: {value: form},
setValue,
} = useForm(cloneDeep(props.form));

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

// Get multilingual props
const formMProps = form.fields.reduce((pp, f) => {
if (f.isMultilingual) {
pp[f.name] = f.value;
}
return pp;
}, {});

const closeModal = inject('closeModal');

/**
* Make form monolingual
*/
form.fields.forEach((f) => {
if (f.isMultilingual) {
f.isMultilingual = false;
f.value = f.value[form.primaryLocale];
}
});

/**
* 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 multilingual form fields when changing language
if (newLocale !== oldLocale) {
form.primaryLocale = newLocale;
form.fields.forEach((f) => {
if (formMProps[f.name]) {
setValue(f.name, formMProps[f.name][newLocale]);
// 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),
);
}
});
}
};

/**
* Change submission language
*/
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 9d48823

Please sign in to comment.