Skip to content

Commit 94e11d7

Browse files
committed
Merge pull request #70 from openstax/try-another-button
Try another button
2 parents f627276 + a31688f commit 94e11d7

File tree

8 files changed

+70
-11
lines changed

8 files changed

+70
-11
lines changed

api/tasks/4.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"is_completed": true,
1010
"correct_answer_id": "id2",
1111
"answer_id": "id1",
12+
"has_recovery": true,
1213
"free_response": "four",
1314
"feedback_html": "Two apples and then <span data-math='2'>2</span> more apples is <strong>four</strong>",
1415
"content": {

src/api.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ apiHelper = (Actions, listenAction, successAction, httpMethod, pathMaker) ->
7171
msg = jqXhr.responseText
7272
Actions.FAILED(statusCode, msg, args...)
7373

74-
7574
$.ajax(url, opts)
7675
.then(resolved, rejected)
7776

@@ -131,6 +130,9 @@ start = ->
131130
apiHelper TaskStepActions, TaskStepActions.complete, TaskStepActions.loaded, 'PUT', (id) ->
132131
url: "/api/steps/#{id}/completed"
133132

133+
apiHelper TaskStepActions, TaskStepActions.loadRecovery, TaskStepActions.loadedRecovery, 'PUT', (id) ->
134+
url: "/api/steps/#{id}/recovery"
135+
134136
apiHelper TaskStepActions, TaskStepActions.setFreeResponseAnswer, TaskStepActions.saved, 'PATCH', (id, free_response) ->
135137
url: "/api/steps/#{id}"
136138
payload: {free_response}

src/components/task-step/exercise-multiple-choice.cjsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ _ = require 'underscore'
22
React = require 'react'
33
katex = require 'katex'
44
{TaskStepActions, TaskStepStore} = require '../../flux/task-step'
5+
{TaskActions} = require '../../flux/task'
56
ArbitraryHtmlAndMath = require '../html'
67
StepMixin = require './step-mixin'
78
Question = require '../question'
9+
BS = require 'react-bootstrap'
810

911

1012
ExerciseFreeResponse = React.createClass
@@ -98,13 +100,32 @@ ExerciseReview = React.createClass
98100
onContinue: ->
99101
@props.onNextStep()
100102

103+
tryAnother: ->
104+
task_id = TaskStepStore.getTaskId(@getId())
105+
TaskStepActions.loadRecovery(@getId())
106+
TaskActions.load(task_id)
107+
108+
canTryAnother: ->
109+
step = TaskStepStore.get(@getId())
110+
return step.has_recovery and step.correct_answer_id isnt step.answer_id
111+
112+
renderFooterButtons: ->
113+
isDisabledClass = 'disabled' unless @isContinueEnabled()
114+
continueButton = <BS.Button bsStyle="primary" className={isDisabledClass} onClick={@onContinue}>Continue</BS.Button>
115+
tryAnotherButton = <BS.Button bsStyle="primary" onClick={@tryAnother}>Try Another</BS.Button> if @canTryAnother()
116+
<span>
117+
{tryAnotherButton}
118+
{continueButton}
119+
</span>
120+
101121

102122
module.exports = React.createClass
103123
displayName: 'Exercise'
104124

105125
render: ->
106126
{id} = @props
107-
{content, free_response, is_completed} = TaskStepStore.get(id)
127+
step = TaskStepStore.get(id)
128+
{id, content, free_response, is_completed} = step
108129
# TODO: Assumes 1 question.
109130
question = content.questions[0]
110131

src/components/task-step/step-mixin.cjsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
React = require 'react'
22
BS = require 'react-bootstrap'
33

4-
{TaskStepStore} = require '../../flux/task-step'
4+
{TaskActions} = require '../../flux/task'
55
{TaskStepActions, TaskStepStore} = require '../../flux/task-step'
66
LoadableMixin = require '../loadable-mixin'
77

@@ -14,10 +14,18 @@ module.exports =
1414
store: TaskStepStore
1515
actions: TaskStepActions
1616

17-
renderLoaded: ->
17+
renderGenericFooter: ->
1818
isDisabledClass = 'disabled' unless @isContinueEnabled()
19+
continueButton = <BS.Button bsStyle="primary" className={isDisabledClass} onClick={@onContinue}>Continue</BS.Button>
20+
<span>
21+
{continueButton}
22+
</span>
1923

20-
footer = <BS.Button bsStyle="primary" className={isDisabledClass} onClick={@onContinue}>Continue</BS.Button>
24+
renderLoaded: ->
25+
if @renderFooterButtons
26+
footer = @renderFooterButtons()
27+
else
28+
footer = @renderGenericFooter()
2129

2230
<BS.Panel bsStyle="default" className="task-step" footer={footer}>
2331
{@renderBody()}

src/components/task/index.cjsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = React.createClass
2727
currentStep = 0
2828
else
2929
# Otherwise, start at the Overview page
30-
currentStep = -1
30+
currentStep = @getDefaultCurrentStep()
3131

3232
{currentStep}
3333

@@ -38,7 +38,10 @@ module.exports = React.createClass
3838
currentStep = -1
3939
for step, i in steps
4040
unless step.is_completed
41-
currentStep = i
41+
if i is 0
42+
currentStep = -1
43+
else
44+
currentStep = i
4245
break
4346

4447
currentStep

src/flux/helpers.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ CrudConfig = ->
6868
saved: (result, id) ->
6969
# id = result.id
7070
@_asyncStatus[id] = LOADED # TODO: Maybe make this SAVED
71+
72+
# If the specific type needs to do something else to the object:
73+
obj = @_saved?(result, id)
74+
result = obj if obj
75+
7176
if result
7277
@_local[id] = result
7378
@_local[result.id] = result
@@ -79,7 +84,6 @@ CrudConfig = ->
7984
delete @_changed[id]
8085
delete @_errors[id]
8186
# If the specific type needs to do something else to the object:
82-
@_saved?(result, id)
8387
@emitChange()
8488

8589
create: (localId, attributes = {}) ->

src/flux/task-step.coffee

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ flux = require 'flux-react'
55

66
TaskStepConfig =
77

8+
_loaded: (obj, id) ->
9+
if not obj.task_id
10+
obj.task_id = @_local[id]?.task_id
11+
obj
12+
13+
_saved: (obj, id) ->
14+
obj.task_id = @_local[id].task_id
15+
obj
16+
817
complete: (id) ->
918
@_change(id, {is_completed: true})
1019
@emitChange()
1120

12-
completed: (empty, step) ->
13-
# First arg is null and ignored because it was a PUT ./completed
14-
1521
setAnswerId: (id, answer_id) ->
1622
@_change(id, {answer_id})
1723
@emitChange()
@@ -20,6 +26,13 @@ TaskStepConfig =
2026
@_change(id, {free_response})
2127
@emitChange()
2228

29+
loadRecovery: (id) ->
30+
@emitChange()
31+
32+
loadedRecovery: (obj, id) ->
33+
@clearChanged()
34+
@emitChange()
35+
2336
exports:
2437
isAnswered: (id) ->
2538
step = @_get(id)
@@ -29,6 +42,10 @@ TaskStepConfig =
2942
isAnswered = false
3043
isAnswered
3144

45+
getTaskId: (id) ->
46+
step = @_get(id)
47+
step.task_id
48+
3249
getFreeResponse: (id) ->
3350
step = @_get(id)
3451
step.free_response

src/flux/task.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ TaskConfig =
1919
delete obj.steps
2020
@_steps[id] = steps
2121
for step in steps
22+
#HACK: set the task_id so we have a link back to the task from the step
23+
step.task_id = id
2224
TaskStepActions.loaded(step, step.id)
25+
obj
2326

2427
# explicit return obj to load onto @_local
2528
obj

0 commit comments

Comments
 (0)