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

View Submission and Revision Applicant Table #1114

Open
wants to merge 4 commits into
base: response_version_db
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions api/app/responses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions webapp/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
129 changes: 99 additions & 30 deletions webapp/src/pages/applicationForm/components/ApplicationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1009,14 +1026,22 @@ 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") {
let firstname = answerByQuestionKey("nomination_firstname", allQuestions, response.answers);
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) => {
Expand All @@ -1028,8 +1053,8 @@ class ApplicationListComponent extends Component {
}
}

getAction = (response) => {
if (response.is_submitted) {
getAction = (response, submitted) => {
if (submitted) {
return <button className="btn btn-warning btn-sm" onClick={() => this.props.click(response)}>{this.props.t("View")}</button>
}
else {
Expand All @@ -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 <div>
<h4>{this.props.t("Your Nominations")}</h4>
<table class="table">
<thead>
<tr>
<th scope="col">{this.props.t("Nominee")}</th>
<th scope="col">{this.props.t("Status")}</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{this.props.responses.map(response => {
return <tr key={"response_" + response.id}>
<td>{this.getCandidate(allQuestions, response)}</td>
<td>{this.getStatus(response)}</td>
<td>{this.getAction(response)}</td>
</tr>
})}
</tbody>
</table>
<h4>{title}</h4>
<table class="table">
<thead>
<tr>
<th scope="col">{firstColumn}</th>
<th scope="col">{this.props.t("Status")}</th>
<th scope="col"></th>
</tr>
</thead>
{this.state.isJournalEvent && !this.props.submissionSelected && (
<tbody>
{Object.keys(by_submissions).map(submission_id => {
return <tr key={"response_" + submission_id}>
<td>{this.getCandidate(allQuestions, by_submissions[submission_id][0])}</td>
<td>{this.getStatus(by_submissions[submission_id][0])}</td>
<td>{this.getAction(by_submissions[submission_id], by_submissions[submission_id][0].is_submitted)}</td>
</tr>
})}
</tbody>
)}
{(!this.state.isJournalEvent || this.props.submissionSelected) && (
<tbody>
{this.props.responses.map(response => {
return <tr key={"response_" + response.response_id}>
<td>{this.getCandidate(allQuestions, response)}</td>
<td>{this.getStatus(response)}</td>
<td>{this.getAction(response, response.is_submitted)}</td>
</tr>
})}
</tbody>
)}
</table>
</div>
}
}
Expand All @@ -1076,17 +1119,19 @@ class ApplicationForm extends Component {
errorMessage: "",
formSpec: null,
responses: [],
selectedResponse: null
selectedResponse: null,
selectedSubmission: null
}
}

componentDidMount() {
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,
Expand All @@ -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'
});
});
}
Expand All @@ -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
});
}

Expand All @@ -1121,7 +1176,9 @@ class ApplicationForm extends Component {
formSpec,
responses,
selectedResponse,
responseSelected } = this.state;
responseSelected,
selectedSubmission,
submissionSelected } = this.state;

if (isLoading) {
return (<Loading />);
Expand All @@ -1131,10 +1188,22 @@ class ApplicationForm extends Component {
return <div className={"alert alert-danger alert-container"}>{errorMessage}</div>;
}

if (formSpec.nominations && responses.length > 0 && !responseSelected) {
if (!this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected) {
return <div>
<ApplicationList responses={responses} formSpec={formSpec} click={this.responseSelected} /><br />
<button className="btn btn-primary" onClick={() => this.newNomination()}>{this.props.t("New Nomination") + " "} &gt;</button>
<button className="btn btn-primary" onClick={() => this.newNomination()}>{this.props.t("New Nomination")} &gt;</button>
</div>
}
else if (this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected && !submissionSelected) {
return <div>
<ApplicationList responses={responses} submissionSelected={submissionSelected} formSpec={formSpec} click={this.submissionSelected} /><br />
<button className="btn btn-primary" onClick={() => this.newNomination()}>{this.props.t("New Submission")} &gt;</button>
</div>
}
else if (this.state.isJournalEvent && formSpec.nominations && responses.length > 0 && !responseSelected) {
return <div>
<ApplicationList responses={selectedSubmission} submissionSelected={submissionSelected} formSpec={formSpec} click={this.responseSelected} /><br />
<button className="btn btn-primary" onClick={() => this.newNomination()}>{this.props.t("New Revision")} &gt;</button>
</div>
}
else {
Expand Down