Allow xblocks to be added as advanced problem types

This commit is contained in:
Andy Armstrong
2014-06-11 13:21:46 -04:00
parent 3a5ba4ba83
commit 04fcebaf47
7 changed files with 205 additions and 25 deletions

View File

@@ -212,6 +212,7 @@ define([
"js/spec/video/transcripts/videolist_spec", "js/spec/video/transcripts/message_manager_spec",
"js/spec/video/transcripts/file_uploader_spec",
"js/spec/models/component_template_spec",
"js/spec/models/explicit_url_spec",
"js/spec/utils/drag_and_drop_spec",

View File

@@ -13,19 +13,31 @@ define(["backbone"], function (Backbone) {
templates: []
},
parse: function (response) {
// Returns true only for templates that both have no boilerplate and are of
// the overall type of the menu. This allows other component types to be added
// and they will get sorted alphabetically rather than just at the top.
// e.g. The ORA openassessment xblock is listed as an advanced problem.
var isPrimaryBlankTemplate = function(template) {
return !template.boilerplate_name && template.category === response.type;
};
this.type = response.type;
this.templates = response.templates;
this.display_name = response.display_name;
// Sort the templates.
this.templates.sort(function (a, b) {
// The entry without a boilerplate always goes first
if (!a.boilerplate_name || (a.display_name < b.display_name)) {
// The blank problem for the current type goes first
if (isPrimaryBlankTemplate(a)) {
return -1;
} else if (isPrimaryBlankTemplate(b)) {
return 1;
} else if (a.display_name > b.display_name) {
return 1;
} else if (a.display_name < b.display_name) {
return -1;
}
else {
return (a.display_name > b.display_name) ? 1 : 0;
}
return 0;
});
}
});

View File

@@ -0,0 +1,79 @@
define(["js/models/component_template"],
function (ComponentTemplate) {
describe("ComponentTemplates", function() {
var mockTemplateJSON = {
"templates": [
{
"category": "problem",
"boilerplate_name": "formularesponse.yaml",
"display_name": "Math Expression Input"
}, {
"category": "problem",
"boilerplate_name": null,
"display_name": "Blank Advanced Problem"
}, {
"category": "problem",
"boilerplate_name": "checkboxes.yaml",
"display_name": "Checkboxes"
}, {
"category": "problem",
"boilerplate_name": "multiple_choice.yaml",
"display_name": "Multiple Choice"
}, {
"category": "problem",
"boilerplate_name": "drag_and_drop.yaml",
"display_name": "Drag and Drop"
}, {
"category": "problem",
"boilerplate_name": "problem_with_hint.yaml",
"display_name": "Problem with Adaptive Hint"
}, {
"category": "problem",
"boilerplate_name": "imageresponse.yaml",
"display_name": "Image Mapped Input"
}, {
"category": "openassessment",
"boilerplate_name": null,
"display_name": "Peer Assessment"
}, {
"category": "problem",
"boilerplate_name": "an_easy_problem.yaml",
"display_name": "An Easy Problem"
}, {
"category": "word_cloud",
"boilerplate_name": null,
"display_name": "Word Cloud"
}, { // duplicate display name to verify sort behavior
"category": "word_cloud",
"boilerplate_name": "alternate_word_cloud.yaml",
"display_name": "Word Cloud"
}],
"type": "problem"
};
it('orders templates correctly', function () {
var lastTemplate = null,
firstComparison = true,
componentTemplate = new ComponentTemplate(),
template, templateName, i;
componentTemplate.parse(mockTemplateJSON);
for (i=0; i < componentTemplate.templates.length; i++) {
template = componentTemplate.templates[i];
templateName = template['display_name'];
if (lastTemplate) {
if (!firstComparison || lastTemplate['boilerplate_name']) {
expect(lastTemplate['display_name'] < templateName).toBeTruthy();
}
firstComparison = false;
} else {
// If the first template is blank, make sure that it has the correct category
if (!template['boilerplate_name']) {
expect(template['category']).toBe('problem');
}
lastTemplate = template;
}
}
});
});
});