Skip to content
Snippets Groups Projects
Commit 02ceea02 authored by Remco Tukker's avatar Remco Tukker
Browse files

make sure the survey cannot be saved without validation after the survey has been completed

parent a2dcdf80
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -23,3 +23,15 @@ export enum VerificationStatus {
Edited = "edited" // a question for which last years answer was edited
}
export enum ResponseStatus {
not_started = "not started",
started = "started",
completed = "completed",
checked = "checked"
}
export enum SurveyStatus {
closed = "closed",
open = "open",
published = "published"
}
......@@ -61,7 +61,7 @@ function SurveyContainerComponent({ loadFrom }) {
}
survey.data = json['data'];
survey.clearIncorrectValues(true); // TODO test if this really removes all old values and such
survey.clearIncorrectValues(true);
survey.currentPageNo = json['page'];
survey.mode = json['mode'];
......@@ -170,6 +170,9 @@ function SurveyContainerComponent({ loadFrom }) {
}
addEventListener("pagehide", pageHideListener);
addEventListener("beforeunload", beforeUnloadListener, { capture: true });
for (const questionName in json["verification_status"]) {
surveyModel.verificationStatus.set(questionName, json["verification_status"][questionName]);
}
surveyModel.data = json['data'];
surveyModel.clearIncorrectValues(true);
surveyModel.mode = json['mode'];
......
......@@ -3,6 +3,7 @@ import Accordion from 'react-bootstrap/Accordion';
import Button from 'react-bootstrap/Button';
import Table from 'react-bootstrap/Table';
import { useNavigate } from 'react-router-dom';
import { ResponseStatus, SurveyStatus } from "./Schema";
async function fetchSurveys(): Promise<Survey[]> {
......@@ -11,7 +12,7 @@ async function fetchSurveys(): Promise<Survey[]> {
const userList = await response.json();
return userList
} catch (error) {
console.log('handle this better..');
console.log('failed fetching survey list..');
return [];
}
}
......@@ -58,7 +59,7 @@ function SurveyManagementComponent() {
});
}
const newSurveyAllowed = surveys.length > 0 && surveys.every(s => s.status == 'published');
const newSurveyAllowed = surveys.length > 0 && surveys.every(s => s.status == SurveyStatus.published);
const navigate = useNavigate();
......@@ -83,15 +84,15 @@ function SurveyManagementComponent() {
Try Survey
</Button>
{survey.status !== 'published' &&
<Button onClick={() => postSurveyStatus(survey.year, 'open')} disabled={survey.status != 'closed'} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
<Button onClick={() => postSurveyStatus(survey.year, 'open')} disabled={survey.status != SurveyStatus.closed} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
title="Allow the NRENs to respond to this survey. Only 1 survey may be open at a time, and published surveys cannot be opened anymore.">
Mark as Open
</Button>}
<Button onClick={() => postSurveyStatus(survey.year, 'close')} disabled={survey.status != 'open'} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
<Button onClick={() => postSurveyStatus(survey.year, 'close')} disabled={survey.status != SurveyStatus.open} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
title="Do not allow the NRENs to respond to this survey anymore. Only surveys with status open can be closed.">
Mark as closed
</Button>
<Button onClick={() => postSurveyStatus(survey.year, 'publish')} disabled={(survey.status != 'closed' && survey.status != 'published') || !survey.responses.every(r => r.status == 'checked')} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
<Button onClick={() => postSurveyStatus(survey.year, 'publish')} disabled={(survey.status != SurveyStatus.closed && survey.status != SurveyStatus.published) || !survey.responses.every(r => r.status == ResponseStatus.checked)} style={{ pointerEvents: 'auto', marginLeft: '.5rem' }}
title="Publish or re-publish all survey responses to the compendium website. This is only possible if the survey is closed or published already, and all responses are checked.">
Publish results
</Button>
......
......@@ -2,6 +2,7 @@ import React, { useContext, useEffect, useState, useCallback } from "react";
import ProgressBar from './ProgressBar';
import { Container, Row } from "react-bootstrap";
import { userContext } from "./providers/UserProvider";
import { ResponseStatus } from "./Schema";
function SurveyNavigationComponent({ surveyModel, surveyActions, year, nren, children }) {
......@@ -61,8 +62,8 @@ function SurveyNavigationComponent({ surveyModel, surveyActions, year, nren, chi
<div className="survey-edit-buttons-block">
{!editing && !lockedBy && surveyModel.editAllowed && renderActionButton(startEditing, 'startEdit')}
{!editing && lockedBy && lockedBy == loggedInUser.name && renderActionButton('Discard any unsaved changes and release your lock', 'releaseLock')}
{editing && renderActionButton(save, 'save')}
{editing && renderActionButton(saveAndStopEdit, 'saveAndStopEdit')}
{editing && responseStatus == ResponseStatus.started && renderActionButton(save, 'save')}
{editing && responseStatus == ResponseStatus.started && renderActionButton(saveAndStopEdit, 'saveAndStopEdit')}
{editing && (pageNo === surveyModel.visiblePages.length - 1) && renderActionButton(completeSurvey, 'complete')}
{(pageNo !== surveyModel.visiblePages.length - 1) && renderButton('Next Section', incrementPageNo)}
{/* {renderActionButton('Validate Page', 'validatePage')} */}
......@@ -94,8 +95,8 @@ function SurveyNavigationComponent({ surveyModel, surveyActions, year, nren, chi
<Row className="survey-content">
{!editing && (
<div className="survey-edit-explainer">
{!lockedBy && surveyModel.editAllowed && <span>The survey is in read-only mode; click the “Start editing“ button to start editing the answers.</span>}
{!lockedBy && !surveyModel.editAllowed && <span>The survey is in read-only mode and can not be edited by you.</span>}
{!lockedBy && surveyModel.editAllowed && 'The survey is in read-only mode; click the “Start editing“ button to start editing the answers.'}
{!lockedBy && !surveyModel.editAllowed && 'The survey is in read-only mode and can not be edited by you.'}
{lockedBy && lockedBy != loggedInUser.name && 'The survey is in READONLY mode and currently being edited by: ' + lockedBy + '. To start editing the survey, ask them to complete their edits.'}
{lockedBy && lockedBy == loggedInUser.name && 'The survey is in READONLY mode because you started editing in another tab, browser or device. To start editing the survey, either complete those edits or click the "Discard any unsaved changes" button.'}
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment