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

first version of keeping track of verification status

parent cc3b59a5
No related branches found
No related tags found
1 merge request!45Feature/comp 214 verification of last years answers
......@@ -30,15 +30,19 @@ def open_survey() -> Any:
survey = db.session.scalar(select(Survey).where(Survey.year == year))
if survey is None or survey.survey == {}:
# TODO remove this at some point, its just convenient for now while we are changing the survey model a lot
# or is it really?? we can also keep the surveys on disk, which makes it really easy to diff, etc
p = Path(__file__).with_name('survey_model.json')
with p.open('r') as f:
survey = json.load(f)
# TODO add some magic strings in the json (like the year) and interpolate them here
# TODO add some magic strings in the json (like the year, url validation regex, maybe countries list) and interpolate them here
data: Optional[dict] = None
page = 0
unvalidated: List[str] = [] # or should we keep track of what _was_ validated?
unverified: List[str] = [] # or should we keep track of what _was_ validated? nah in that case we also
# need to track what needs validation, easier to just encode that in the 'unvalidated' list
# the only difference it really makes is when question identifiers change etc, in which
# case there may be copied data without a question
response = db.session.scalar(
select(SurveyResponse).where(SurveyResponse.survey_year == year).where(SurveyResponse.nren_id == nren.id)
......@@ -50,16 +54,19 @@ def open_survey() -> Any:
if response:
data = response.answers["data"]
page = response.answers["page"]
unvalidated = response.answers["unvalidated"]
unverified = response.answers["unverified"]
elif previous_response:
# TODO add a 'migration' hook here for updating data per year
# TODO i suppose we also need to remove the data that isnt asked anymore because
# i dont think the frontend will remove it
data = previous_response.answers["data"]
unvalidated = ["TODO everything?"]
unverified = ["TODO everything that was copied?"]
open_survey: dict = {
"model": survey,
"data": data,
"page": page,
"unvalidated": unvalidated
"unverified": ['budget']
}
return jsonify(open_survey)
......@@ -91,7 +98,7 @@ def save_survey() -> Any:
response.answers = {
"data": save_survey["data"],
"page": save_survey["page"],
"unvalidated": save_survey["unvalidated"]
"unverified": save_survey["unverified"]
}
db.session.commit()
......
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useRef } from "react";
import { Model, Serializer } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/modern.min.css";
......@@ -12,6 +12,36 @@ Serializer.addProperty("question", "hideCheckboxLabels:boolean");
function SurveyComponent() {
const [surveyModel, setSurveyModel] = useState<Model>();
const unverifiedQuestions = useRef<string[]>();
function setVerifyButton(questionName: string, state: string) {
const idx = unverifiedQuestions.current?.indexOf(questionName);
if (idx == undefined || idx == -1) {
return;
}
if (state == "verified" || state == "verified!") {
unverifiedQuestions.current?.splice(idx, 1);
}
const btn = document.createElement("button");
btn.type = "button";
btn.className = "dialogBox-btn verify";
btn.innerHTML = state;
btn.onclick = function() {
setVerifyButton(questionName, "verified")
}
const selector = '[data-name="' + questionName + '"]';
const header = document.querySelector(selector)!.querySelector('h5')!;
const old = header.querySelector(".verify");
if (old) {
old.replaceWith(btn);
} else {
header.appendChild(btn);
}
}
// const surveyComplete = useCallback((sender) => {
// console.log(sender.data);
......@@ -21,6 +51,8 @@ function SurveyComponent() {
{
const response = await fetch('/api/survey/open');
const json = await response.json();
unverifiedQuestions.current = json["unverified"];
const survey = new Model(json['model']);
if (json['data'] !== null)
......@@ -58,7 +90,7 @@ function SurveyComponent() {
const saveData = {
data: sender.data,
page: 2,
unvalidated: []
unverified: []
}
xhr.send(JSON.stringify(saveData));
});
......@@ -69,20 +101,13 @@ function SurveyComponent() {
});
survey.onGetQuestionTitleActions.add((_, opt) => {
// opt.question TODO check what we can do with this..
console.log(opt.question.title, opt.question.value, opt.question.validators);
opt.titleActions = [
{
title: 'Validate pre-filled value',
innerCss: 'validate-pre-filled-value',
action: () => {
console.log('verified!')
},
},
];
survey.onAfterRenderQuestion.add(function(survey, options){
setVerifyButton(options.question.name, 'unverified');
});
survey.onValueChanged.add(function(survey, options) {
setVerifyButton(options.question.name, 'verified!');
});
survey.onUpdateQuestionCssClasses.add(function(_, options) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment