Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
9ae190a5
Commit
9ae190a5
authored
2 years ago
by
Remco Tukker
Browse files
Options
Downloads
Patches
Plain Diff
first version of keeping track of verification status
parent
cc3b59a5
No related branches found
No related tags found
1 merge request
!45
Feature/comp 214 verification of last years answers
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/routes/survey.py
+13
-6
13 additions, 6 deletions
compendium_v2/routes/survey.py
survey-frontend/src/SurveyComponent.tsx
+39
-14
39 additions, 14 deletions
survey-frontend/src/SurveyComponent.tsx
with
52 additions
and
20 deletions
compendium_v2/routes/survey.py
+
13
−
6
View file @
9ae190a5
...
...
@@ -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
"
]
unv
alidat
ed
=
response
.
answers
[
"
unv
alidat
ed
"
]
unv
erifi
ed
=
response
.
answers
[
"
unv
erifi
ed
"
]
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
"
]
unv
alidat
ed
=
[
"
TODO everything?
"
]
unv
erifi
ed
=
[
"
TODO everything
that was copied
?
"
]
open_survey
:
dict
=
{
"
model
"
:
survey
,
"
data
"
:
data
,
"
page
"
:
page
,
"
unv
alidated
"
:
unvalidated
"
unv
erified
"
:
[
'
budget
'
]
}
return
jsonify
(
open_survey
)
...
...
@@ -91,7 +98,7 @@ def save_survey() -> Any:
response
.
answers
=
{
"
data
"
:
save_survey
[
"
data
"
],
"
page
"
:
save_survey
[
"
page
"
],
"
unv
alidat
ed
"
:
save_survey
[
"
unv
alidat
ed
"
]
"
unv
erifi
ed
"
:
save_survey
[
"
unv
erifi
ed
"
]
}
db
.
session
.
commit
()
...
...
This diff is collapsed.
Click to expand it.
survey-frontend/src/SurveyComponent.tsx
+
39
−
14
View file @
9ae190a5
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
,
unv
alidat
ed
:
[]
unv
erifi
ed
:
[]
}
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment