Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Works on my machine
zesje
Commits
594fd748
Commit
594fd748
authored
5 years ago
by
jtimotei
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix for changing labeltype to T/F
parent
c3c3a587
No related branches found
No related tags found
1 merge request
!31
Layout side panel
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/components/PaneMCQ.jsx
+22
-18
22 additions, 18 deletions
client/components/PaneMCQ.jsx
client/views/Exam.jsx
+51
-55
51 additions, 55 deletions
client/views/Exam.jsx
with
73 additions
and
73 deletions
client/components/PaneMCQ.jsx
+
22
−
18
View file @
594fd748
...
...
@@ -10,7 +10,7 @@ class PanelMCQ extends React.Component {
this
.
onChangeNPA
=
this
.
onChangeNPA
.
bind
(
this
)
this
.
onChangeLabelType
=
this
.
onChangeLabelType
.
bind
(
this
)
this
.
generateLabels
=
this
.
generateLabels
.
bind
(
this
)
this
.
update
MCO
=
this
.
update
MCO
.
bind
(
this
)
this
.
update
NumberOptions
=
this
.
update
NumberOptions
.
bind
(
this
)
this
.
state
=
{
isMCQ
:
false
,
...
...
@@ -27,7 +27,7 @@ class PanelMCQ extends React.Component {
problemId
:
prob
.
id
,
isMCQ
:
prob
.
mc_options
.
length
>
0
,
nrPossibleAnswers
:
prob
.
mc_options
.
length
||
2
,
chosenLabelType
:
prob
.
labelType
||
2
,
chosenLabelType
:
PanelMCQ
.
deriveLabelType
(
prob
.
mc_options
)
,
}
}
...
...
@@ -36,11 +36,11 @@ class PanelMCQ extends React.Component {
static
deriveLabelType
(
options
)
{
if
(
options
.
length
===
0
)
{
return
0
return
2
}
else
if
(
options
.
length
===
2
&&
((
options
[
0
].
label
===
'
T
'
&&
options
[
1
].
label
===
'
F
'
)
||
(
options
[
0
].
label
===
'
F
'
&&
options
[
1
].
label
===
'
T
'
)))
{
return
1
}
else
if
(
options
[
0
].
label
.
match
(
/
[
a-z
]
/
))
{
}
else
if
(
options
[
0
].
label
.
match
(
/
[
A-Z
]
/
))
{
return
2
}
else
if
(
parseInt
(
options
[
0
].
label
))
{
return
3
...
...
@@ -49,19 +49,14 @@ class PanelMCQ extends React.Component {
}
}
update
MCO
()
{
update
NumberOptions
()
{
let
difference
=
this
.
state
.
nrPossibleAnswers
-
this
.
props
.
problem
.
mc_options
.
length
if
(
difference
>
0
)
{
let
startingAt
=
this
.
props
.
problem
.
mc_options
.
length
let
labels
=
this
.
generateLabels
(
difference
,
startingAt
)
this
.
props
.
generateMCOs
(
labels
)
return
this
.
props
.
generateMCOs
(
labels
)
}
else
if
(
difference
<
0
)
{
this
.
props
.
deleteMCOs
(
-
difference
)
}
if
(
this
.
state
.
chosenLabelType
!==
this
.
props
.
problem
.
labelType
)
{
let
labels
=
this
.
generateLabels
(
this
.
state
.
nrPossibleAnswers
,
0
)
this
.
props
.
updateMCOs
(
labels
)
return
this
.
props
.
deleteMCOs
(
-
difference
)
}
}
...
...
@@ -74,7 +69,7 @@ class PanelMCQ extends React.Component {
}
this
.
setState
({
nrPossibleAnswers
:
value
},
this
.
update
MCO
)
},
this
.
update
NumberOptions
)
}
}
...
...
@@ -82,13 +77,22 @@ class PanelMCQ extends React.Component {
onChangeLabelType
(
e
)
{
let
value
=
parseInt
(
e
.
target
.
value
)
if
(
!
isNaN
(
value
))
{
this
.
setState
({
chosenLabelType
:
value
},
this
.
updateMCO
)
if
(
parseInt
(
value
)
===
1
)
{
this
.
setState
({
nrPossibleAnswers
:
2
},
this
.
updateMCO
)
nrPossibleAnswers
:
2
,
chosenLabelType
:
value
},
()
=>
{
this
.
updateNumberOptions
()
let
labels
=
this
.
generateLabels
(
this
.
state
.
nrPossibleAnswers
,
0
)
this
.
props
.
updateLabels
(
labels
)
})
}
else
{
this
.
setState
({
chosenLabelType
:
value
},
()
=>
{
let
labels
=
this
.
generateLabels
(
this
.
state
.
nrPossibleAnswers
,
0
)
this
.
props
.
updateLabels
(
labels
)
})
}
}
}
...
...
This diff is collapsed.
Click to expand it.
client/views/Exam.jsx
+
51
−
55
View file @
594fd748
...
...
@@ -59,8 +59,7 @@ class Exams extends React.Component {
}),
widthMCO
:
24
,
heightMCO
:
38
,
isMCQ
:
problem
.
mc_options
&&
problem
.
mc_options
.
length
!==
0
,
// is the problem a mc question - used to display PanelMCQ
labelType
:
PanelMCQ
.
deriveLabelType
(
problem
.
mc_options
)
isMCQ
:
problem
.
mc_options
&&
problem
.
mc_options
.
length
!==
0
// is the problem a mc question - used to display PanelMCQ
}
}
})
...
...
@@ -125,14 +124,26 @@ class Exams extends React.Component {
}
updateFeedbackAtIndex
=
(
feedback
,
problemWidget
,
idx
)
=>
{
let
fb
=
[...
problemWidget
.
problem
.
feedback
]
if
(
idx
===
-
1
)
{
problemWidget
.
problem
.
feedback
.
push
(
feedback
)
fb
.
push
(
feedback
)
}
else
{
if
(
feedback
.
deleted
)
problemWidget
.
problem
.
feedback
.
splice
(
idx
,
1
)
else
problemWidget
.
problem
.
feedback
[
idx
]
=
feedback
if
(
feedback
.
deleted
)
fb
.
splice
(
idx
,
1
)
else
fb
[
idx
]
=
feedback
}
this
.
setState
({
widgets
:
this
.
state
.
widgets
this
.
setState
(
prevState
=>
{
return
{
widgets
:
update
(
prevState
.
widgets
,
{
[
problemWidget
.
id
]:
{
'
problem
'
:
{
'
feedback
'
:
{
$set
:
fb
}
}
}
})
}
})
}
...
...
@@ -319,15 +330,15 @@ class Exams extends React.Component {
}
deleteMCO
=
(
widget
,
index
)
=>
{
deleteMCO
=
(
widgetId
,
index
,
nrMCOs
)
=>
{
let
widget
=
this
.
state
.
widgets
[
widgetId
]
if
(
nrMCOs
<=
0
||
!
widget
.
problem
.
mc_options
.
length
)
return
;
let
option
=
widget
.
problem
.
mc_options
[
index
]
api
.
del
(
'
mult-choice/
'
+
option
.
id
)
return
api
.
del
(
'
mult-choice/
'
+
option
.
id
)
.
catch
(
err
=>
{
console
.
log
(
err
)
err
.
json
().
then
(
res
=>
{
this
.
setState
({
deletingMCWidget
:
false
})
Notification
.
error
(
'
Could not delete multiple choice option
'
+
(
res
.
message
?
'
:
'
+
res
.
message
:
''
))
// update to try and get a consistent state
...
...
@@ -335,32 +346,33 @@ class Exams extends React.Component {
})
})
.
then
(
res
=>
{
let
index
=
widget
.
problem
.
feedback
.
findIndex
(
e
=>
{
return
e
.
id
===
res
.
feedback_id
})
let
feedback
=
widget
.
problem
.
feedback
[
index
]
feedback
.
deleted
=
true
this
.
updateFeedbackAtIndex
(
feedback
,
widget
,
index
)
}
)
this
.
updateFeedback
(
feedback
)
this
.
setState
((
prevState
)
=>
{
return
{
widgets
:
update
(
prevState
.
widgets
,
{
[
widget
.
id
]:
{
problem
:
{
mc_options
:
{
$splice
:
[[
index
,
1
]]
}
}
}
})
}
},
()
=>
{
this
.
deleteMCO
(
widgetId
,
index
,
nrMCOs
-
1
)
})
})
}
deleteMCOs
=
(
widget
,
startIndex
,
nrMCOs
)
=>
{
let
options
=
[...
widget
.
problem
.
mc_options
]
options
.
splice
(
index
,
1
)
options
.
splice
(
startIndex
,
nrMCOs
)
// remove the mc options from the state
// note that this can happen before they are removed in the DB due to async calls
this
.
setState
((
prevState
)
=>
{
return
{
widgets
:
update
(
prevState
.
widgets
,
{
[
widget
.
id
]:
{
problem
:
{
mc_options
:
{
$set
:
options
}
}
}
}),
deletingMCWidget
:
false
}
})
this
.
deleteMCO
(
widget
.
id
,
startIndex
,
nrMCOs
)
}
/**
...
...
@@ -591,14 +603,13 @@ class Exams extends React.Component {
let
len
=
problem
.
mc_options
.
length
if
(
nrMCOs
>=
len
)
{
this
.
setState
({
deletingMCWidget
:
true
})
}
else
{
for
(
let
i
=
0
;
i
<
nrMCOs
;
i
++
)
{
this
.
deleteMCO
(
selectedWidget
,
len
-
1
-
i
)
}
}
else
if
(
nrMCOs
>
0
)
{
this
.
deleteMCOs
(
selectedWidget
,
len
-
nrMCOs
,
nrMCOs
)
}
}
}
updateMCOs
=
{
(
labels
)
=>
{
problem
.
mc_options
.
map
((
option
,
index
)
=>
{
updateLabels
=
{
(
labels
)
=>
{
labels
.
map
((
label
,
index
)
=>
{
let
option
=
problem
.
mc_options
[
index
]
const
formData
=
new
window
.
FormData
()
formData
.
append
(
'
name
'
,
option
.
widget
.
name
)
formData
.
append
(
'
x
'
,
option
.
widget
.
x
+
option
.
cbOffsetX
)
...
...
@@ -635,21 +646,6 @@ class Exams extends React.Component {
})
})
})
// this.setState(prevState => ({
// widgets: update(prevState.widgets, {
// [selectedWidget.id]: {
// 'problem': {
// 'mc_options': {
// $set : options
// },
// 'labelType': {
// $set: PanelMCQ.deriveLabelType(options)
// }
// }
// }
// })
// }))
}
}
/>
)
:
null
}
<
this
.
PanelExamActions
/>
...
...
@@ -874,7 +870,7 @@ class Exams extends React.Component {
this
.
state
.
widgets
[
this
.
state
.
selectedWidgetId
].
problem
.
name
}
"`
}
confirmText
=
'Delete multiple choice options'
onCancel
=
{
()
=>
this
.
setState
({
deletingMCWidget
:
false
})
}
onConfirm
=
{
()
=>
this
.
deleteMC
Widget
(
this
.
state
.
selectedWidgetId
)
}
onConfirm
=
{
()
=>
this
.
deleteMC
O
(
this
.
state
.
selectedWidgetId
,
0
)
}
/>
</
div
>
}
...
...
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