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

[Feature] CON-234 - Graphic Gap Match with text (gapText) choices #149

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/qtiItem/core/interactions/GraphicGapMatchInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
init: function init(serial, attributes) {
this._super(serial, attributes);
this.gapImgs = {};
this.gapTexts = {};
},
addGapImg: function addGapImg(gapImg) {
if (Element.isA(gapImg, 'gapImg')) {
Expand All @@ -50,6 +51,28 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
getGapImg: function getGapImg(serial) {
return this.gapImgs[serial];
},
addGapText: function addGapText(gapText) {
if (Element.isA(gapText, 'gapText')) {
gapText.setRootElement(this.getRootElement() || null);
this.gapTexts[gapText.getSerial()] = gapText;
}
},
removeGapText: function removeGapImg(gapText) {
var serial = '';
if (typeof gapText === 'string') {
serial = gapText;
} else if (Element.isA(gapText, 'gapText')) {
serial = gapText.getSerial();
}
delete this.gapTexts[serial];
return this;
},
getGapTexts: function getGapTexts() {
return _.clone(this.gapTexts);
},
getGapText: function getGapText(serial) {
return this.gapTexts[serial];
},
getChoiceByIdentifier: function getChoiceByIdentifier(identifier) {
var choice = this._super(identifier);
if (!choice) {
Expand All @@ -68,6 +91,10 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
elts[serial] = this.gapImgs[serial];
elts = _.extend(elts, this.gapImgs[serial].getComposingElements());
}
for (serial in this.gapTexts) {
elts[serial] = this.gapTexts[serial];
elts = _.extend(elts, this.gapTexts[serial].getComposingElements());
}
return elts;
},
find: function find(serial) {
Expand All @@ -76,6 +103,9 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
if (this.gapImgs[serial]) {
found = { parent: this, element: this.gapImgs[serial] };
}
if (this.gapTexts[serial]) {
found = { parent: this, element: this.gapTexts[serial] };
}
}
return found;
},
Expand All @@ -84,7 +114,8 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
args = rendererConfig.getOptionsFromArguments(arguments),
renderer = args.renderer || this.getRenderer(),
defaultData = {
gapImgs: []
gapImgs: [],
gapTexts: [],
};

//note: no choice shuffling option available for graphic gap match
Expand All @@ -94,32 +125,49 @@ var GraphicGapMatchInteraction = GraphicInteraction.extend({
defaultData.gapImgs.push(gapImgs[serial].render({}, null, '', renderer));
}
}

var gapTexts = this.getGapTexts();
for (serial in gapTexts) {
if (Element.isA(gapTexts[serial], 'choice')) {
defaultData.gapTexts.push(gapTexts[serial].render({}, null, '', renderer));
}
}
return this._super(_.merge(defaultData, args.data), args.placeholder, args.subclass, renderer);
},
toArray: function toArray() {
var serial,
gapImgs,
gapTexts,
arr = this._super();
arr.gapImgs = {};
gapImgs = this.getGapImgs();
for (serial in gapImgs) {
arr.gapImgs[serial] = gapImgs[serial].toArray();
}
gapTexts = this.getGapTexts();
for (serial in gapTexts) {
arr.gapTexts[serial] = gapTexts[serial].toArray();
}
return arr;
},
getNormalMaximum: function getNormalMaximum() {
var calculatePossiblePairs = function calculatePossiblePairs(graphicGapInteraction) {
var pairs = [];
var matchSet1 = maxScore.getMatchMaxOrderedChoices(graphicGapInteraction.getGapImgs());
var matchSet2 = maxScore.getMatchMaxOrderedChoices(graphicGapInteraction.getChoices());
var matchSet3 = maxScore.getMatchMaxOrderedChoices(graphicGapInteraction.getGapTexts());

_.forEach(matchSet1, function(choice1) {
_.forEach(matchSet2, function(choice2) {
pairs.push([choice1.id, choice2.id]);
});
});

_.forEach(matchSet3, function(choice3) {
_.forEach(matchSet2, function(choice2) {
pairs.push([choice3.id, choice2.id]);
});
});

return pairs;
};
return maxScore.associateInteractionBased(this, {
Expand Down
2 changes: 1 addition & 1 deletion src/qtiRunner/core/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var _dependencies = {
choiceInteraction: ['simpleChoice'],
gapMatchInteraction: ['gap', 'gapText'],
graphicAssociateInteraction: ['associableHotspot'],
graphicGapMatchInteraction: ['associableHotspot', 'gapImg'],
graphicGapMatchInteraction: ['associableHotspot', 'gapImg', 'gapText'],
graphicOrderInteraction: ['hotspotChoice'],
hotspotInteraction: ['hotspotChoice'],
hottextInteraction: ['hottext'],
Expand Down