Skip to content
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

2.6.2 Instructor Tool uses the Course Blocks REST API #129

Merged
merged 2 commits into from Nov 10, 2016

Conversation

pomegranited
Copy link
Member

@pomegranited pomegranited commented Nov 9, 2016

Moves the logic that populates the Instructor Tool's drop-down list of course blocks out of the server-side and into the client, using the Course Blocks API as the data source.

Discussions: In #119, @ormsbee raised concerns about performance and maintainability of the old server-side mechanism for traversing the course blocks via the runtime object's parents.

Sandbox URL:

Partner information: DavidsonX

Testing instructions:

  1. Ensure your devstack is updated to current master.
  2. Install the previous version of Problem Builder, v2.6.1.
  3. Create a course, and import course.99Ob05.tar.gz.
  4. Visit the Features > Instructor Tool unit, and note the list of course block options available for "Section/Question".
  5. Install this branch's version of Problem Builder.
  6. Visit the Features > Instructor Tool unit, and note that the list of course block options has not changed.

Alternatively, you can compare the sandbox from this PR with the one for v2.6.1, https://github.com/edx/edx-platform/pull/13938.

Author notes and concerns:

  1. This change removes the python tests related to the course block tree creation, since that logic has been removed from the server-side. However, we don't currently have any JS/Jasmine tests for this xblock, and so no JS tests have been added to test the new client-side code.

Reviewers

@pomegranited pomegranited changed the title Use the Course Blocks API instead of traversing runtime parent blocks 2.6.2 Use the Course Blocks API instead of traversing runtime parent blocks Nov 9, 2016
@pomegranited pomegranited changed the title 2.6.2 Use the Course Blocks API instead of traversing runtime parent blocks 2.6.2 Instructor Tool uses the Course Blocks REST API Nov 9, 2016
Copy link
Member

@itsjeyd itsjeyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited These changes look great overall, I just had a few small comments/questions.

I'll test when you're done addressing them and the sandbox is up-to-date.

});
}
function updateBlockOptions(data) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Nit: Move empty line up so it separates getCourseBlocks and updateBlockOptions functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with a3dd42f.

@@ -172,3 +172,10 @@ def validate_field_data(self, validation, data):
Validate this block's field data.
"""
super(SliderBlock, self).validate_field_data(validation, data)

def student_view_data(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Since SliderBlock isn't an eligible block type, I'm wondering why it would need to define student_view_data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsjeyd So my question is, why isn't SliderBlock an eligible block type? And MRQBlock too for that matter? But I didn't have enough time to look into that..

I'm happy to remove this change though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted with 78f09e6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited

So my question is, why isn't SliderBlock an eligible block type? And MRQBlock too for that matter?

IIRC, we implemented these data exports for Harvard GSE, and at the time they only wanted support for specific question types. MRQ was not one of them, and sliders didn't exist yet :)

return $option;
},
buildTree = function(block, ancestors) {

Copy link
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with a3dd42f.


// Find the best label attribute available for the block
labelAttr = _.find(['question', 'name', 'display_name'],
function(attr) {return block[attr]}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Nit: This would be even more readable when formatted like this:

            labelAttr = _.find(
                ['question', 'name', 'display_name'],
                function(attr) { return block[attr] }
            ),

Or like this:

            labelAttr = _.find(
                ['question', 'name', 'display_name'],
                function(attr) {
                    return block[attr]
                }
            ),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with a3dd42f.

}
function updateBlockOptions(data) {

var appendBlock = function(block) {
Copy link
Member

Choose a reason for hiding this comment

The 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 $option).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with a3dd42f.

Copy link
Member

@itsjeyd itsjeyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those additional comments look great, @pomegranited! Thanks for adding them. Found a couple typos that will need to be fixed, but other than that the code is good to go.

@@ -253,8 +253,9 @@ function InstructorToolBlock(runtime, element) {
// 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 adds the to the
// list of blocks in the Section/Question drop-down list.
Copy link
Member

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"?)

function updateBlockOptions(data) {

// Constructs an <option> element for the given block to the drop-down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited "... to add to the drop-down ..."?

@itsjeyd
Copy link
Member

itsjeyd commented Nov 9, 2016

@pomegranited Thanks for the updates. The code is good to squash. I'll test when the new sandbox is ready.

Copy link
Member

@itsjeyd itsjeyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited This is looking great! I have two more comments based on looking at the recent updates and testing on the sandbox, but they should be quick to address and this good to go once you've done that (I won't need to review again) 👍

  • I tested this: Course trees are the same on the different sandboxes.
  • I read through the code
  • I checked for accessibility issues N/A (refactoring)
  • Includes documentation N/A (refactoring)

)
patched_loader.render_template.assert_called_once_with('templates/html/instructor_tool.html', {
'block_choices': block_choices,
'course_blocks_api': '/api/courses/v1/blocks/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Instead of hard coding the API URL here, you could just import COURSE_BLOCKS_API from problem_builder.instructor_tool.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsjeyd I've been smacked on the wrist for doing that before for some reason.. But I totally agree. Fixed here.

And since I squashed the commits, I also added a comment to the COURSE_BLOCKS_API declaration to explain why the trailing slash is important. Seemed excessive to go into detail about the content switch proxy, but at least made a note.

// if it's found to have a descendant that is enabled.
var appendBlock = function(block) {
var blockId = block.id.split('+block@').pop(),
padding = Array(block.depth).join('&nbsp;'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Can you increase the padding to two spaces? That's what the original implementation used (see instructor_tool.html#L35), and I think the tree looks slightly better/more readable with two spaces.

Sorry for not pointing this out sooner, I really had to see the two versions side-by-side to get a sense of the difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsjeyd Ahh good catch! Sorry I missed that too. Fixed here.

…d drop-down.

* Removes the python course tree traversal logic, and replaces it with Javascript.
* Adds student_view_data() to downloadable block types to reveal the "question"
  text to the Course Blocks API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants