Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change submission language #280

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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">
<PkpForm
jardakotesovec marked this conversation as resolved.
Show resolved Hide resolved
v-bind="store.form"
@set="store.setCustom"
@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>
115 changes: 115 additions & 0 deletions src/pages/workflow/changeSubmissionLanguageStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {inject, ref} from 'vue';
import {defineComponentStore} from '@/utils/defineComponentStore';
import {useApiUrl} from '@/composables/useApiUrl';
import {useFetch} from '@/composables/useFetch';
import {useForm} from '@/composables/useForm';
import {useLocalize} from '@/composables/useLocalize';
import cloneDeep from 'clone-deep';

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

const {t, tk} = useLocalize();

const DescriptionLocaleKeys = {
title: tk(
'submission.list.changeSubmissionLanguage.metadataDescription.title',
),
abstract: tk(
'submission.list.changeSubmissionLanguage.metadataDescription.abstract',
),
};

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

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

// Set initial value
const publicationTitle = ref(getValue('title'));

const publicationProps = {};
// Get publication props
getData();

const closeModal = inject('closeModal');

/**
* Functions
*/

function closeSideModal() {
closeModal();
}

/**
* Set form data
*/
const setCustom = (_, data) => {
set(_, data);
const oldLocale = form.primaryLocale;
const newLocale = getValue('locale');
// Set fields when changing language
jardakotesovec marked this conversation as resolved.
Show resolved Hide resolved
if (newLocale !== oldLocale) {
form.primaryLocale = newLocale;
form.fields.forEach((field) => {
if (publicationProps[field.name]) {
setValue(
field.name,
publicationProps[field.name][newLocale] ??
publicationProps[field.name],
);
field.description = t(DescriptionLocaleKeys[field.name], {
language: getLocaleName(newLocale),
});
}
});
}
};

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

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

/**
* Aux functions
*/

async function getData() {
const {data, fetch} = useFetch(publicationApiUrl, {
method: 'GET',
});
await fetch();

Object.assign(publicationProps, data.value ?? {});
delete publicationProps['locale'];

publicationTitle.value = data.value.title[props.form.primaryLocale];
}

function getLocaleName(locale) {
return form.fields
.find(({name}) => name === 'locale')
.options.find(({value}) => value === locale).label;
}
jardakotesovec marked this conversation as resolved.
Show resolved Hide resolved
},
);