Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Merge 17b65cc into 50a265e
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmnetp committed Sep 13, 2019
2 parents 50a265e + 17b65cc commit d957792
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
4 changes: 4 additions & 0 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,10 @@ def add__or_update_assignment_question():
question_type
],
status="success",
question_id=question_name,
points=points,
autograde=autograde,
which_to_grade=which_to_grade,
)
)
except Exception as ex:
Expand Down
51 changes: 30 additions & 21 deletions static/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,11 @@ function configure_tree_picker(
}
}
if (!data.instance.ignore_check) {
walk_jstree(data.instance, data.node, function (instance, node) {
walk_jstree(data.instance, data.node, async function (instance, node) {
if (jstree_node_depth(instance, node) == leaf_depth) {
// Add each checked item to the assignment list with default values.
checked_func(node); // checked_func is either updateReading or updateAssignmentRaw
let resp = await checked_func(node); // checked_func is either updateReading or updateAssignmentRaw
add_to_table(resp);
}
});
}
Expand All @@ -1023,12 +1024,11 @@ function jstree_node_depth(instance, node) {
}

// Given a jstree node, invoke f on node and all its children.
function walk_jstree(instance, node, f) {
f(instance, node);
$(node.children).each(function (index, value) {
console.log(index, value)
walk_jstree(instance, instance.get_node(value), f);
});
async function walk_jstree(instance, node, f) {
await f(instance, node);
for (let value of node.children) {
await walk_jstree(instance, instance.get_node(value), f);
}
}

// Given an editable element (a hyperlink) in a bootstrap table, return the containing row.
Expand Down Expand Up @@ -1304,30 +1304,39 @@ function assignmentInfo() {

// Update a reading.
// This should be serialized is the walk_jstree function to make sure the order is correct
function updateReading(subchapter_id, activities_required, points, autograde, which_to_grade) {
async function updateReading(subchapter_id, activities_required, points, autograde, which_to_grade) {
let assignid = getAssignmentId();
if (!assignid || assignid == 'undefined') {
alert("No assignment selected");
return;
}
$.getJSON('add__or_update_assignment_question', {
let res = await $.ajax({url: 'add__or_update_assignment_question',
data: {
assignment: assignid,
question: subchapter_id,
activities_required: activities_required,
points: points,
autograde: autograde,
which_to_grade: which_to_grade,
}).done(function (response_JSON) {
$('#totalPoints').html('Total points: ' + response_JSON['total']);
// See if this question already exists in the table. Only append if it doesn't exist.
if (readings_table.bootstrapTable('getRowByUniqueId', subchapter_id) === null) {
appendToReadingsTable(subchapter_id, response_JSON['activity_count'], response_JSON['activities_required'], points, autograde,
response_JSON['autograde_possible_values'], which_to_grade,
response_JSON['which_to_grade_possible_values']);
}
}).fail(function () {
alert(`Your added question ${subchapter_id} was not saved to the database for assignment ${assignid}, please file a bug report describing exactly what you were doing.`)
});
},
dataType: 'json'});

return res;
}

function add_to_table (response_JSON) {
$('#totalPoints').html('Total points: ' + response_JSON['total']);
// See if this question already exists in the table. Only append if it doesn't exist.
if (readings_table.bootstrapTable('getRowByUniqueId', response_JSON['question_id']) === null) {
appendToReadingsTable(response_JSON['question_id'],
response_JSON['activity_count'],
response_JSON['activities_required'],
response_JSON['points'],
response_JSON['autograde'],
response_JSON['autograde_possible_values'],
response_JSON['which_to_grade'],
response_JSON['which_to_grade_possible_values']);
}
}


Expand Down
2 changes: 1 addition & 1 deletion views/admin/assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ <h4 class="modal-title" id="editModalHeader">Edit Question</h4>

configure_tree_picker(readings_picker, eBookConfig.toc.reading_picker, $('#search-tree-readings-picker'), 2,
// Called when a node is checked.
function (node) { updateReading(node.id, -1, 1, 'interact', 'best_answer'); },
async function (node) { let res = await updateReading(node.id, -1, 1, 'interact', 'best_answer'); return res },
// Called when a node is unchecked.
function (node) { remove_reading(node.id); }
);
Expand Down

0 comments on commit d957792

Please sign in to comment.