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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
11b41196
Commit
11b41196
authored
Jul 9, 2023
by
Remco Tukker
Browse files
Options
Downloads
Patches
Plain Diff
basic save button
parent
38c251c4
No related branches found
No related tags found
1 merge request
!49
Feature/comp 219 save button
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
compendium_v2/routes/survey.py
+5
-5
5 additions, 5 deletions
compendium_v2/routes/survey.py
compendium_v2/static/survey-bundle.js
+1
-1
1 addition, 1 deletion
compendium_v2/static/survey-bundle.js
survey-frontend/src/SurveyComponent.tsx
+38
-30
38 additions, 30 deletions
survey-frontend/src/SurveyComponent.tsx
with
44 additions
and
36 deletions
compendium_v2/routes/survey.py
+
5
−
5
View file @
11b41196
...
...
@@ -41,7 +41,7 @@ def get_nrens() -> Any:
@common.require_accepts_json
def
open_survey
(
nren_name
)
->
Any
:
# just a hardcoded year
and nren
for development for now
# just a hardcoded year for development for now
nren
=
db
.
session
.
execute
(
select
(
NREN
).
filter
(
NREN
.
name
==
nren_name
)).
scalar_one
()
year
=
1989
last_year
=
2022
...
...
@@ -87,12 +87,12 @@ def open_survey(nren_name) -> Any:
return
jsonify
(
open_survey
)
@routes.route
(
'
/save
'
,
methods
=
[
'
POST
'
])
@routes.route
(
'
/save
/<string:nren_name>
'
,
methods
=
[
'
POST
'
])
@common.require_accepts_json
def
save_survey
()
->
Any
:
def
save_survey
(
nren_name
)
->
Any
:
# just a hardcoded year
and nren
for development for now
nren
=
db
.
session
.
execute
(
select
(
NREN
).
order_by
(
NREN
.
id
).
limit
(
1
)).
scalar_one
()
# just a hardcoded year for development for now
nren
=
db
.
session
.
execute
(
select
(
NREN
).
filter
(
NREN
.
name
==
nren_name
)).
scalar_one
()
year
=
1989
survey
=
db
.
session
.
scalar
(
select
(
Survey
).
where
(
Survey
.
year
==
year
))
if
survey
is
None
:
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/static/survey-bundle.js
+
1
−
1
View file @
11b41196
This diff is collapsed.
Click to expand it.
survey-frontend/src/SurveyComponent.tsx
+
38
−
30
View file @
11b41196
...
...
@@ -49,12 +49,12 @@ function SurveyComponent({ nrenName }) {
}
const
selector
=
'
[data-name="
'
+
question
.
name
+
'
"]
'
;
const
header
=
document
.
querySelector
(
selector
)
!
.
querySelector
(
'
h5
'
)
!
;
const
old
=
header
.
querySelector
(
"
.verification
"
);
const
header
=
document
.
querySelector
(
selector
)
?
.
querySelector
(
'
h5
'
);
const
old
=
header
?
.
querySelector
(
"
.verification
"
);
if
(
old
)
{
old
.
replaceWith
(
btn
);
}
else
{
header
.
appendChild
(
btn
);
header
?
.
appendChild
(
btn
);
}
}
...
...
@@ -62,6 +62,25 @@ function SurveyComponent({ nrenName }) {
// console.log(sender.data);
// }, []);
function
saveSurveyData
(
survey
,
success
?,
failure
?)
{
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"
POST
"
,
"
/api/survey/save/
"
+
nrenName
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json; charset=utf-8
"
);
xhr
.
onload
=
xhr
.
onerror
=
()
=>
{
if
(
xhr
.
status
==
200
&&
success
)
{
success
();
}
else
if
(
xhr
.
status
!=
200
&&
failure
)
{
failure
();
}
}
const
saveData
=
{
data
:
survey
.
data
,
page
:
survey
.
currentPageNo
,
verification_status
:
Object
.
fromEntries
(
verificationStatus
.
current
)
}
xhr
.
send
(
JSON
.
stringify
(
saveData
));
}
async
function
getModel
()
{
const
response
=
await
fetch
(
'
/api/survey/open/
'
+
nrenName
);
const
json
=
await
response
.
json
();
...
...
@@ -107,36 +126,25 @@ function SurveyComponent({ nrenName }) {
innerCss
:
"
sv-btn sv-btn--navigation sv-footer__complete-btn
"
});
survey
.
onComplete
.
add
((
sender
,
options
)
=>
{
console
.
log
(
sender
.
data
);
survey
.
addNavigationItem
({
id
:
"
sv-nav-compendium-save
"
,
title
:
"
Save
"
,
action
:
(
context
)
=>
{
console
.
log
(
context
);
saveSurveyData
(
survey
);
// notification doesnt show up in the right place, maybe fix with CSS. Also see settings.notifications.lifetime if you want to fix this
// but probably easier/better to just use react popup everywhere instead
// survey.notify('Saved!', "success");
},
innerCss
:
"
sv-btn sv-btn--navigation sv-footer__complete-btn
"
});
survey
.
onComplete
.
add
((
sender
,
options
)
=>
{
options
.
showSaveInProgress
();
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"
POST
"
,
"
/api/survey/save
"
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json; charset=utf-8
"
);
xhr
.
onload
=
xhr
.
onerror
=
function
()
{
if
(
xhr
.
status
==
200
)
{
// Display the "Success" message (pass a string value to display a custom message)
options
.
showSaveSuccess
();
// Alternatively, you can clear all messages:
// options.clearSaveMessages();
}
else
{
// Display the "Error" message (pass a string value to display a custom message)
options
.
showSaveError
();
}
};
const
saveData
=
{
data
:
sender
.
data
,
page
:
sender
.
currentPageNo
,
verification_status
:
Object
.
fromEntries
(
verificationStatus
.
current
)
}
xhr
.
send
(
JSON
.
stringify
(
saveData
));
saveSurveyData
(
sender
,
()
=>
options
.
showSaveSuccess
(),
()
=>
options
.
showSaveError
());
});
survey
.
onPartialSend
.
add
((
sender
,
options
)
=>
{
console
.
log
(
sender
.
data
)
// TODO same as above
survey
.
onPartialSend
.
add
((
sender
)
=>
{
saveSurveyData
(
sender
);
});
survey
.
onAfterRenderQuestion
.
add
(
function
(
survey
,
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
sign in
to comment