Skip to content

Commit

Permalink
Change submission language
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhein committed Mar 6, 2024
1 parent bba26a3 commit c79ca20
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 0 deletions.
150 changes: 150 additions & 0 deletions src/components/Container/ChangeSubmissionLanguage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<template>
<p>{{ t('submission.list.changeLangDescription') }}</p>
<div class="pkpPublication" aria-live="polite">
<pkp-form
v-bind="form"
@set="updateFormData"
@success="changeLanguage"
></pkp-form>
</div>
</template>

<script type="text/javascript">
import PkpForm from '@/components/Form/Form.vue';
import ajaxError from '@/mixins/ajaxError';
export default {
name: 'ChangeSubmissionLanguage',
components: {
PkpForm,
},
mixins: [ajaxError],
props: {
contributors: {
type: Array,
required: true,
},
contributorsApiUrl: {
type: String,
required: true,
},
form: {
type: Object,
required: true,
},
submissionApiUrl: {
type: String,
required: true,
},
submissionLocale: {
type: String,
required: true,
},
},
emits: ['set', 'updated:contributors', 'updated:locale'],
data() {
return {
isSubmit: false,
};
},
methods: {
/**
* Change submission language and update contributor props
*/
async changeLanguage() {
const oldLocale = this.submissionLocale;
const newLocale = this.form.primaryLocale;
if (newLocale === oldLocale) {
return Promise.resolve();
}
this.isSubmit = true;
const self = this;
return editContributors().then(submitLang(), $.noop);
async function editContributors() {
const editedContributors = self.contributors
.map((a) => [a.id, edit(a)])
.filter((a) => Object.keys(a[1]).length > 0);
if (editedContributors.length > 0) {
return $.when(
...editedContributors.map(([id, contributor]) => {
return send(`${self.contributorsApiUrl}/${id}`, contributor);
}),
).then(() => {
self.$emit(
'updated:contributors',
self.contributors.map((c) =>
Object.assign(
c,
editedContributors.find(([id]) => id === c.id)[1],
),
),
);
});
}
return Promise.resolve();
function edit(author) {
// Only edit if given name empty
if (author['givenName'][newLocale] !== '') return {};
return ['givenName', 'familyName', 'preferredPublicName'].reduce(
(editedProps, prop) => {
if (author[prop][newLocale] === '') {
editedProps[prop] = {[newLocale]: author[prop][oldLocale]};
}
return editedProps;
},
{},
);
}
}
async function submitLang() {
return send(self.submissionApiUrl, {locale: newLocale}, (_) =>
self.$emit('updated:locale', newLocale),
);
}
async function send(url, data, success = $.noop) {
return $.ajax({
url: url,
method: 'POST',
headers: {
'X-Csrf-Token': pkp.currentUser.csrfToken,
'X-Http-Method-Override': 'PUT',
},
data: data,
success(r) {
success(r);
},
error(r) {
self.ajaxErrorCallback(r);
},
});
}
},
/**
* Update form data
*/
updateFormData(formId, data) {
this.$emit('set', formId, data);
const newLocale = data.fields?.[0].value ?? this.form.primaryLocale;
if (newLocale !== this.form.primaryLocale && !this.isSubmit) {
this.$emit('set', formId, {
primaryLocale: newLocale,
visibleLocales: [newLocale],
});
}
},
},
};
</script>
<style lang="less">
// Hide formlocales of change language metadata form
#changeSubmissionLanguage form .pkpFormLocales {
display: none;
}
</style>
57 changes: 57 additions & 0 deletions src/components/Container/WorkflowPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script type="text/javascript">
import Page from './Page.vue';
import ChangeSubmissionLanguage from '@/components/Container/ChangeSubmissionLanguage.vue';
import ContributorsListPanel from '@/components/ListPanel/contributors/ContributorsListPanel.vue';
import PublicationSectionJats from '@/pages/workflow/PublicationSectionJats.vue';
import Composer from '@/components/Composer/Composer.vue';
Expand All @@ -13,6 +14,7 @@ import dialog from '@/mixins/dialog.js';
export default {
name: 'WorkflowPage',
components: {
ChangeSubmissionLanguage,
ContributorsListPanel,
Composer,
Dropdown,
Expand All @@ -26,6 +28,8 @@ export default {
return {
activityLogLabel: '',
canAccessPublication: false,
canChangeLang: false,
changeLangButtonLabel: '',
canEditPublication: false,
currentPublication: null,
decisionUrl: '',
Expand Down Expand Up @@ -57,6 +61,7 @@ export default {
workingPublication: null,
isModalOpenedSelectRevisionDecision: false,
isModalOpenedSelectRevisionRecommendation: false,
isModalOpenedChangeSubmissionLanguage: false,
};
},
computed: {
Expand Down Expand Up @@ -601,6 +606,49 @@ export default {
setContributors(contributors) {
this.workingPublication.authors = [...contributors];
},
/**
* Update new primary locale to forms
* Update change submission locale form
* Update submission locale
* Update working publication
* Update label
* Close modal
*
* @param {String} locale
*/
updateChangesSubmissionLanguage(locale) {
Object.keys(this.components).forEach((formId) => {
if (typeof this.components[formId].primaryLocale !== 'undefined') {
this.set(formId, {primaryLocale: locale, visibleLocales: [locale]});
} else if (
typeof this.components[formId].form?.primaryLocale !== 'undefined'
) {
this.components[formId].form.primaryLocale = locale;
this.components[formId].form.visibleLocales = [locale];
}
});
const form =
this.components[pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE_METADATA];
const showWhen = form.supportedFormLocales
.filter(({key}) => key !== locale)
.map(({key}) => key);
form.groups.forEach((g) => {
if (typeof g.showWhen !== 'undefined') g.showWhen[1] = showWhen;
});
form.fields[0].value = locale;
this.components[pkp.const.FORM_CHANGE_SUBMISSION_LANGUAGE_METADATA] = {
...form,
};
this.submission.locale = locale;
this.setWorkingPublicationById(this.workingPublication.id);
this.changeLangButtonLabel = form.supportedFormLocales.find(
({key}) => key === locale,
).label;
this.isModalOpenedChangeSubmissionLanguage = false;
},
},
};
</script>
Expand Down Expand Up @@ -722,6 +770,15 @@ export default {
}
}
.pkpSubmission__localeNotSupported {
margin: 0 -2rem;
padding: 1rem;
background: @primary;
font-size: @font-sml;
color: #fff;
text-align: center;
}
// 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
3 changes: 3 additions & 0 deletions src/components/Form/FormPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ export default {
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
38 changes: 38 additions & 0 deletions src/docs/components/WorkflowPage/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Data

This is a root component. Learn about [page hydration](#/pages/pages).

| Key | Description |
| --- | --- |
| `activityLogLabel` | Label for the activity log |
| `canAccessPublication` | Can the current user access the publication details? Default: `false` |
| `canEditPublication` | Can the current user edit the publication details? Default: `false` |
| `components` | Key/value map of nested components, such as forms. |
| `currentPublication` | The submission's current publication. |
| `editorialHistoryUrl` | URL to get the activity log modal. |
| `publicationFormIds` | Array containing all of the keys in `components` that match a publication form. These forms will be updated when changing versions. |
| `publicationList` | Array containing the `id`, `datePublished`, `status` and `version` of every publication for this submission. |
| `publicationTabsLabel` | Label for the publication details tabs. |
| `publishLabel` | Label for the publish button. |
| `publishUrl` | URL to get the publish modal. |
| `representationsGridUrl` | URL to get the galley/publication formats grid. |
| `schedulePublicationLabel` | Label for the schedule for publication button. |
| `statusLabel` | Label for the working publication's current status. |
| `submission` | Object containing details about this submission. |
| `submissionApiUrl` | URL for the submissions REST API endpoint. |
| `submissionLibraryLabel` | Label for the submission library button. |
| `submissionLibraryUrl` | URL to get the submission library. |
| `submissionSupportedLocales` | Array containing supported submission locale keys |
| `supportsReferences` | Should the form for references be shown? |
| `unpublishConfirmLabel` | Confirmation message before unpublishing a publication. |
| `unpublishLabel` | Label for the unpublish button. |
| `unscheduleConfirmLabel` | Confirmation message before scheduling for publication. |
| `versionLabel` | Label for the current version. |
| `versionConfirmMessage` | Confirmation message before creating a new version. |
| `versionConfirmTitle` | Title of the confirmation modal before creating a new version. |
| `workingPublication` | Object representing the working publication. This is the version that is currently being shown. |

## Usage

The `WorkflowPage` extends the [Page](#/component/Page) component. Use this app to show the submission workflow.

0 comments on commit c79ca20

Please sign in to comment.