diff --git a/api/app/responses/api.py b/api/app/responses/api.py index 593bceb5f..94500bb84 100644 --- a/api/app/responses/api.py +++ b/api/app/responses/api.py @@ -38,6 +38,8 @@ class ResponseAPI(ResponseMixin, restful.Resource): response_fields = { 'id': fields.Integer, + 'submission_id': fields.Integer, + 'version_id': fields.Integer, 'application_form_id': fields.Integer, 'user_id': fields.Integer, 'is_submitted': fields.Boolean, diff --git a/webapp/public/locales/en/translation.json b/webapp/public/locales/en/translation.json index b5d76a141..1e5102733 100644 --- a/webapp/public/locales/en/translation.json +++ b/webapp/public/locales/en/translation.json @@ -119,8 +119,14 @@ "View": "View", "Your Nominations": "Your Nominations", "Nominee": "Nominee", + "Your Submissions": "Your Submissions", + "Submission": "Submission", + "Your Revisions": "Your Revisions", + "Revision": "Revision", "Status": "Status", "New Nomination": "New Nomination", + "New Submission": "New Submission", + "New Revision": "New Revision", "Title": "Title", "Email": "Email", "Relation": "Relation", diff --git a/webapp/public/locales/fr/translation.json b/webapp/public/locales/fr/translation.json index e867a8096..4bfe24a2f 100644 --- a/webapp/public/locales/fr/translation.json +++ b/webapp/public/locales/fr/translation.json @@ -119,8 +119,14 @@ "View": "Afficher", "Your Nominations": "Vos nominations", "Nominee": "Candidat(e)", + "Your Submission": "Vos soumissions", + "Submission": "Soumission", + "Your Revisions": "Vos révisions", + "Revision": "Révision", "Status": "État", "New Nomination": "Nouvelle nomination", + "New Submission": "Nouvelle soumission", + "New Revision": "Nouvelle révision", "Title": "Titre", "Email": "Courriel", "Relation": "Relation", diff --git a/webapp/src/pages/applicationForm/components/ApplicationForm.js b/webapp/src/pages/applicationForm/components/ApplicationForm.js index c12bb1a44..534a1ed4c 100644 --- a/webapp/src/pages/applicationForm/components/ApplicationForm.js +++ b/webapp/src/pages/applicationForm/components/ApplicationForm.js @@ -21,6 +21,7 @@ import AnswerValue from '../../../components/answerValue' import FormSelectOther from "../../../components/form/FormSelectOther"; import FormMultiCheckboxOther from "../../../components/form/FormMultiCheckboxOther"; import FormCheckbox from "../../../components/form/FormCheckbox"; +import { eventService } from "../../../services/events"; const baseUrl = process.env.REACT_APP_API_URL; @@ -66,6 +67,22 @@ const answerByQuestionKey = (key, allQuestions, answers) => { return null; } +function ResponsesBySubmission(responses) { + var by_submissions = {}; + + responses.forEach(response => { + if (!(response.submission_id in by_submissions)){ + by_submissions[response.submission_id] = [response] + } else { + // add responses with the same submission id to the same array and sort by revision_id in descending order + by_submissions[response.submission_id].push(response) + by_submissions[response.submission_id].sort((a, b) => a.version_id < b.version_id ? 1 : -1) + } + } + ) + return by_submissions; +} + class FieldEditor extends React.Component { constructor(props) { super(props); @@ -1009,6 +1026,14 @@ class ApplicationListComponent extends Component { } } + componentDidMount() { + eventService.getEvent(this.props.formSpec.event_id).then(response => { + this.setState({ + isJournalEvent: response.event.event_type === 'JOURNAL' || response.event.event_type ==='CONTINUOUS_JOURNAL' + }); + })}; + + getCandidate = (allQuestions, response) => { const nominating_capacity = answerByQuestionKey("nominating_capacity", allQuestions, response.answers); if (nominating_capacity === "other") { @@ -1016,7 +1041,7 @@ class ApplicationListComponent extends Component { let lastname = answerByQuestionKey("nomination_lastname", allQuestions, response.answers); return firstname + " " + lastname; } - return this.props.t("Self Nomination"); + return this.state.isJournalEvent ? (this.props.submissionSelected ? this.props.t("Revision") + " " + response.version_id: this.props.t("Submission") + " " + response.submission_id) : this.props.t("Self Nomination"); } getStatus = (response) => { @@ -1028,8 +1053,8 @@ class ApplicationListComponent extends Component { } } - getAction = (response) => { - if (response.is_submitted) { + getAction = (response, submitted) => { + if (submitted) { return } else { @@ -1038,27 +1063,45 @@ class ApplicationListComponent extends Component { } render() { + const by_submissions = ResponsesBySubmission(this.props.responses); let allQuestions = _.flatMap(this.props.formSpec.sections, s => s.questions); + const title = this.state.isJournalEvent ? + (this.props.submissionSelected ? this.props.t("Your Revisions") : this.props.t("Your Submissions")) + : this.props.t("Your Nominations"); + let firstColumn = this.state.isJournalEvent ? (this.props.submissionSelected ? this.props.t("Revision") : this.props.t("Submission")) : this.props.t("Nominee"); return
-

{this.props.t("Your Nominations")}

- - - - - - - - - - {this.props.responses.map(response => { - return - - - - - })} - -
{this.props.t("Nominee")}{this.props.t("Status")}
{this.getCandidate(allQuestions, response)}{this.getStatus(response)}{this.getAction(response)}
+

{title}

+ + + + + + + + + {this.state.isJournalEvent && !this.props.submissionSelected && ( + + {Object.keys(by_submissions).map(submission_id => { + return + + + + + })} + + )} + {(!this.state.isJournalEvent || this.props.submissionSelected) && ( + + {this.props.responses.map(response => { + return + + + + + })} + + )} +
{firstColumn}{this.props.t("Status")}
{this.getCandidate(allQuestions, by_submissions[submission_id][0])}{this.getStatus(by_submissions[submission_id][0])}{this.getAction(by_submissions[submission_id], by_submissions[submission_id][0].is_submitted)}
{this.getCandidate(allQuestions, response)}{this.getStatus(response)}{this.getAction(response, response.is_submitted)}
} } @@ -1076,7 +1119,8 @@ class ApplicationForm extends Component { errorMessage: "", formSpec: null, responses: [], - selectedResponse: null + selectedResponse: null, + selectedSubmission: null } } @@ -1084,9 +1128,10 @@ class ApplicationForm extends Component { const eventId = this.props.event ? this.props.event.id : 0; Promise.all([ applicationFormService.getForEvent(eventId), - applicationFormService.getResponse(eventId) + applicationFormService.getResponse(eventId), + eventService.getEvent(eventId) ]).then(responses => { - let [formResponse, responseResponse] = responses; + let [formResponse, responseResponse, eventResponse] = responses; let selectFirstResponse = !formResponse.formSpec.nominations && responseResponse.response.length > 0; this.setState({ formSpec: formResponse.formSpec, @@ -1095,7 +1140,9 @@ class ApplicationForm extends Component { errorMessage: (formResponse.error + " " + responseResponse.error).trim(), isLoading: false, selectedResponse: selectFirstResponse ? responseResponse.response[0] : null, - responseSelected: selectFirstResponse + responseSelected: selectFirstResponse, + event_type: eventResponse.event.event_type, + isJournalEvent: eventResponse.event.event_type === 'JOURNAL' || eventResponse.event.event_type ==='CONTINUOUS_JOURNAL' }); }); } @@ -1109,7 +1156,15 @@ class ApplicationForm extends Component { newNomination = () => { this.setState({ - responseSelected: true + responseSelected: true, + submissionSelected: true + }); + } + + submissionSelected = (response_array) => { + this.setState({ + selectedSubmission: response_array, + submissionSelected: true }); } @@ -1121,7 +1176,9 @@ class ApplicationForm extends Component { formSpec, responses, selectedResponse, - responseSelected } = this.state; + responseSelected, + selectedSubmission, + submissionSelected } = this.state; if (isLoading) { return (); @@ -1131,10 +1188,22 @@ class ApplicationForm extends Component { return
{errorMessage}
; } - if (formSpec.nominations && responses.length > 0 && !responseSelected) { + if (!this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected) { return

- + +
+ } + else if (this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected && !submissionSelected) { + return
+
+ +
+ } + else if (this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected) { + return
+
+
} else {