-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}, | ||
); |