Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed Nov 9, 2023
1 parent a6ae955 commit c43adaf
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 17 deletions.
15 changes: 9 additions & 6 deletions econplayground/assignment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ def append_graph_form_fields(

return actions

def unsubmit(self, request, step):
step_name = 'step_{}_{}'.format(step.assignment.pk, step.pk)
del request.session[step_name]
return HttpResponseRedirect(reverse('step_detail', kwargs={
'assignment_pk': step.assignment.pk,
'pk': step.pk,
}))

def post(self, request, *args, **kwargs):
"""
This method handles what happens when students submit their
Expand All @@ -291,12 +299,7 @@ def post(self, request, *args, **kwargs):
unsubmit = request.POST.get('unsubmit')

if unsubmit == 'true':
step_name = 'step_{}_{}'.format(step.assignment.pk, step.pk)
del request.session[step_name]
return HttpResponseRedirect(reverse('step_detail', kwargs={
'assignment_pk': step.assignment.pk,
'pk': step.pk,
}))
return self.unsubmit(request, step)

question = step.question

Expand Down
14 changes: 9 additions & 5 deletions econplayground/templates/assignment/step_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ <h1>Step {{object.pk}}</h1>

{% block js %}
<script>
if (!window.EconPlayground) {
window.EconPlayground = {};
}
if (!window.EconPlayground) {
window.EconPlayground = {};
}

{% if object.question and object.question.graph %}
{% if object.question and object.question.graph %}
window.GRAPH_ID = {{object.question.graph.pk}};
{% endif %}
{% endif %}

{% if submission is not None %}
window.EconPlayground.submitted = true;
{% endif %}
</script>
<script src="{% static 'js/build/stepGraphViewer.js' %}"></script>
{% endblock %}
Expand Down
3 changes: 2 additions & 1 deletion media/js/src/GraphForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default function GraphForm({ gType, updateGraph, props }) {
const commonViewerProps = {
isInstructor: false,
displayLabels: true,
displaySliders: true
displaySliders: true,
disabled: props.submitted
};

let graphForm = null;
Expand Down
8 changes: 7 additions & 1 deletion media/js/src/StepGraphViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export default class StepGraphViewer extends Component {
this.graphId = window.GRAPH_ID;
}

let submitted = false;
if (window.EconPlayground && window.EconPlayground.submitted) {
submitted = true;
}

this.state = {
initialState: {},
actions: []
actions: [],
submitted: submitted
};
this.state = Object.assign(this.state, defaultGraph);
}
Expand Down
22 changes: 21 additions & 1 deletion media/js/src/editors/DemandSupplyEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class DemandSupplyEditor extends React.Component {
showOverride2Button={true}
override2Label='Horizontal'
override2Value={0}
disabled={this.props.disabled}
handler={handleFormUpdate.bind(this)} />
<RangeEditor
itemlabel="\text{Blue line slope}"
Expand All @@ -36,6 +37,7 @@ export default class DemandSupplyEditor extends React.Component {
showOverride2Button={true}
override2Label='Horizontal'
override2Value={0}
disabled={this.props.disabled}
handler={handleFormUpdate.bind(this)} />
{this.props.gType === 13 && (
<>
Expand All @@ -51,6 +53,7 @@ export default class DemandSupplyEditor extends React.Component {
showOverride2Button={true}
override2Label='Horizontal'
override2Value={0}
disabled={this.props.disabled}
handler={handleFormUpdate.bind(this)} />
<RangeEditor
itemlabel="\text{Right graph: Blue line slope}"
Expand All @@ -64,6 +67,7 @@ export default class DemandSupplyEditor extends React.Component {
showOverride2Button={true}
override2Label='Horizontal'
override2Value={0}
disabled={this.props.disabled}
handler={handleFormUpdate.bind(this)} />
</>
)}
Expand All @@ -82,6 +86,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gLine1Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col">
Expand All @@ -91,6 +96,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gLine2Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
</div>
Expand All @@ -102,6 +108,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gXAxisLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col">
Expand All @@ -111,6 +118,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gYAxisLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
</div>
Expand All @@ -122,6 +130,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersectionLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col">
Expand All @@ -131,6 +140,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersectionHorizLineLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col">
Expand All @@ -140,6 +150,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersectionVertLineLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
</div>
Expand All @@ -158,6 +169,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gLine3Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-6">
Expand All @@ -167,6 +179,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gLine4Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-6">
Expand All @@ -176,6 +189,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gXAxis2Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-6">
Expand All @@ -185,6 +199,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gYAxis2Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-4">
Expand All @@ -194,6 +209,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersection2Label}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-4">
Expand All @@ -203,6 +219,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersection2HorizLineLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
<div className="col-4">
Expand All @@ -212,6 +229,7 @@ export default class DemandSupplyEditor extends React.Component {
value={this.props.gIntersection2VertLineLabel}
valueEditable={true}
isInstructor={true}
disabled={this.props.disabled}
updateGraph={this.props.updateGraph} />
</div>
</div>
Expand Down Expand Up @@ -274,5 +292,7 @@ DemandSupplyEditor.propTypes = {
displayLabels: PropTypes.bool.isRequired,
displaySliders: PropTypes.bool.isRequired,
isInstructor: PropTypes.bool.isRequired,
showAUC: PropTypes.bool.isRequired
showAUC: PropTypes.bool.isRequired,

disabled: PropTypes.bool
};
4 changes: 3 additions & 1 deletion media/js/src/form-components/EditableControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class EditableControl extends React.Component {
className="form-control"
type="text"
maxLength="60"
disabled={this.props.disabled}
value={this.props.value}
onChange={handleFormUpdate.bind(this)} />
</label>
Expand All @@ -35,5 +36,6 @@ EditableControl.propTypes = {
name: PropTypes.string.isRequired,
isInstructor: PropTypes.bool.isRequired,
value: PropTypes.string,
valueEditable: PropTypes.bool.isRequired
valueEditable: PropTypes.bool.isRequired,
disabled: PropTypes.bool
};
12 changes: 10 additions & 2 deletions media/js/src/form-components/RangeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class RangeEditor extends React.Component {
step={this.props.step || 0.01}
min={this.props.min}
max={this.props.max}
disabled={this.props.disabled}
/>
{this.props.showMinMax && (
<div className="d-inline position-absolute r-0">
Expand All @@ -59,6 +60,7 @@ export default class RangeEditor extends React.Component {
data-id={this.props.dataId}
type="button"
onClick={this.props.handler}
disabled={this.props.disabled}
value={
btnStep(
this.props.value,
Expand All @@ -76,6 +78,7 @@ export default class RangeEditor extends React.Component {
data-id={this.props.dataId}
type="button"
onClick={this.props.handler}
disabled={this.props.disabled}
value={
btnStep(
this.props.value,
Expand All @@ -93,6 +96,7 @@ export default class RangeEditor extends React.Component {
data-id={this.props.dataId}
type="button"
onClick={this.props.handler}
disabled={this.props.disabled}
value={
btnStep(
this.props.value,
Expand All @@ -110,6 +114,7 @@ export default class RangeEditor extends React.Component {
data-id={this.props.dataId}
type="button"
onClick={this.props.handler}
disabled={this.props.disabled}
value={
btnStep(
this.props.value,
Expand All @@ -129,6 +134,7 @@ export default class RangeEditor extends React.Component {
value={this.props.value}
step={Number(this.props.step) || 0.01}
onChange={this.props.handler}
disabled={this.props.disabled}
min={this.props.min}
max={this.props.max}>
</input>
Expand Down Expand Up @@ -185,7 +191,8 @@ RangeEditor.defaultProps = {
override2Label: '',
override2Value: 0,
showMinMax: false,
showValue: true
showValue: true,
disabled: false
};

RangeEditor.propTypes = {
Expand All @@ -206,5 +213,6 @@ RangeEditor.propTypes = {
showMinMax: PropTypes.bool,
note: PropTypes.string,
showNote: PropTypes.bool,
showValue: PropTypes.bool
showValue: PropTypes.bool,
disabled: PropTypes.bool
};

0 comments on commit c43adaf

Please sign in to comment.