-
Notifications
You must be signed in to change notification settings - Fork 59
2.6.2 Instructor Tool uses the Course Blocks REST API #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,6 +250,111 @@ function InstructorToolBlock(runtime, element) { | |
| if (statusChanged) updateView(); | ||
| } | ||
|
|
||
| // Block types with answers we can export | ||
| var questionBlockTypes = ['pb-mcq', 'pb-rating', 'pb-answer']; | ||
|
|
||
| // Fetch this course's blocks from the REST API, and add them to the | ||
| // list of blocks in the Section/Question drop-down list. | ||
| function getCourseBlocks() { | ||
| $.ajax({ | ||
| type: 'GET', | ||
| url: $rootBlockId.data('course-blocks-api'), | ||
| data: { | ||
| course_id: $element.data('course-id'), | ||
| requested_fields: 'name,display_name,block_type,children', | ||
| student_view_data: questionBlockTypes.join(','), | ||
| all_blocks: true, | ||
| depth: 'all' | ||
| }, | ||
| success: updateBlockOptions, | ||
| dataType: 'json' | ||
| }); | ||
| } | ||
|
|
||
| // Appends the blocks returned by the Course Blocks API as options for | ||
| // the Section/Question drop-down list, arranged as a tree. | ||
| function updateBlockOptions(data) { | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pomegranited Nit: Move empty line up so it separates
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed with a3dd42f. |
||
| // Constructs an <option> element from the given block to add to the | ||
| // list of root blocks. | ||
| // | ||
| // Uses the block's: | ||
| // * question, name, or display name as the label. | ||
| // * depth in the course to indent the label, to make the tree | ||
| // structure more visible. | ||
| // * 'enabled' attribute to decide whether the <option> | ||
| // element is selectable, i.e. available as a download filter. | ||
| // | ||
| // Returns the <option> element so that it can be enabled later, | ||
| // if it's found to have a descendant that is enabled. | ||
| var appendBlock = function(block) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pomegranited You already added some nice comments explaining individual steps to the body of this function. It would be great to have a general comment that summarizes what this function does (and why it needs to return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed with a3dd42f. |
||
| var blockId = block.id.split('+block@').pop(), | ||
| padding = Array(2*block.depth).join(' '), | ||
| disabled = (block.enabled ? undefined : 'disabled'), | ||
| labelAttr, | ||
| label, | ||
| $option; | ||
|
|
||
| // Merge any fields exposed by student_view_data, so they can be | ||
| // candidates for the label attribute. | ||
| block = _.extend(block, block['student_view_data']); | ||
|
|
||
| // Find the best label attribute available for the block. | ||
| labelAttr = _.find( | ||
| ['question', 'name', 'display_name'], | ||
| function(attr) { | ||
| return block[attr]; | ||
| } | ||
| ); | ||
| label = padding + (block[labelAttr] || blockId); | ||
| $option = $('<option>', {value: blockId, html: label, disabled: disabled}); | ||
|
|
||
| $rootBlockId.append($option); | ||
| return $option; | ||
| }, | ||
|
|
||
| // Builds the tree of course blocks. | ||
| buildTree = function(block, ancestors) { | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pomegranited Same nit here: Empty line above start of function definition would be nice :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed with a3dd42f. |
||
| // Omit pb-choice blocks | ||
| if (block.type == 'pb-choice') return; | ||
|
|
||
| // Enable the exportable blocks, and their ancestors. | ||
| if (_.contains(questionBlockTypes, block.type)) { | ||
| block.enabled = true; | ||
|
|
||
| for (var i = ancestors.length; i > 0; --i) { | ||
| var ancestor = ancestors[i-1]; | ||
|
|
||
| // No need to continue; these ancestors are already enabled. | ||
| if (ancestor.enabled) break; | ||
|
|
||
| ancestor.enabled = true; | ||
| ancestor.element.removeAttr('disabled'); | ||
| } | ||
| } | ||
|
|
||
| block.depth = ancestors.length; | ||
| block.element = appendBlock(block); | ||
|
|
||
| // Recurse over all the child blocks, including the current block as an ancestor. | ||
| var childAncestors = ancestors.concat([block]); | ||
| _.each(block.children, function(child_id) { | ||
| buildTree(data.blocks[child_id], childAncestors); | ||
| }); | ||
| }, | ||
| root = data.blocks[data.root]; | ||
|
|
||
| // Label the root block as "All" | ||
| root.name = gettext('All'); | ||
|
|
||
| // Remove any existing options | ||
| $rootBlockId.empty(); | ||
|
|
||
| // Build the course blocks tree from the root. | ||
| buildTree(root, []); | ||
| } | ||
|
|
||
| function disableActions() { | ||
| $startButton.prop('disabled', true); | ||
| $cancelButton.prop('disabled', true); | ||
|
|
@@ -369,6 +474,7 @@ function InstructorToolBlock(runtime, element) { | |
|
|
||
| showSpinner(); | ||
| disableActions(); | ||
| getCourseBlocks(); | ||
| getStatus(); | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pomegranited Typos: "Fetch this course's blocks ..., and add the ??? to the list of blocks ..." (perhaps you meant to say "and add them"?)