Skip to content

Commit

Permalink
Merge branch 'release-2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oat-github-bot committed Jul 31, 2024
2 parents 34e7e66 + 96c6a13 commit 40b47fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-item-runner-qti",
"version": "2.3.4",
"version": "2.4.0",
"displayName": "TAO Item Runner QTI",
"description": "TAO QTI Item Runner modules",
"files": [
Expand Down
36 changes: 29 additions & 7 deletions src/qtiCommonRenderer/renderers/interactions/OrderInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,31 @@ const _setInstructions = function (interaction) {
};

const resetResponse = function (interaction) {
const isSingleOrder = interaction.attr('order') === 'single';
const $container = containerHelper.get(interaction);
const initialOrder = _.keys(interaction.getChoices());
const $choiceArea = $('.choice-area', $container).append($('.result-area>li', $container));
const $choices = $choiceArea.children('.qti-choice');
const $resultArea = $('.result-area', $container);
const $resultItems = $('.result-area>li', $container);

$container.find('.qti-choice.active').each(function deactivateChoice() {
interactUtils.tapOn(this);
});

$choices.detach().sort(function (choice1, choice2) {
return _.indexOf(initialOrder, $(choice1).data('serial')) - _.indexOf(initialOrder, $(choice2).data('serial'));
});
$choiceArea.prepend($choices);
if (isSingleOrder) {
// if it's a single order interaction, sort the items in result-area in initial order
$resultItems.detach().sort(function (item1, item2) {
return _.indexOf(initialOrder, $(item1).data('serial')) - _.indexOf(initialOrder, $(item2).data('serial'));
});
$resultArea.empty();
$resultArea.append($resultItems);
} else {
const $choiceArea = $('.choice-area', $container).append($('.result-area>li', $container));
const $choices = $choiceArea.children('.qti-choice');
$choices.detach().sort(function (choice1, choice2) {
return _.indexOf(initialOrder, $(choice1).data('serial')) - _.indexOf(initialOrder, $(choice2).data('serial'));
});
$choiceArea.prepend($choices);
}
};

/**
Expand All @@ -134,11 +146,18 @@ const render = function (interaction) {
choiceSelector = `${$choiceArea.selector} >li:not(.deactivated)`,
resultSelector = `${$resultArea.selector} >li`,
$dragContainer = $container.find('.drag-container'),
isSingleOrder = interaction.attr('order') === 'single',
orientation =
interaction.attr('orientation') && orientationSelectionEnabled
? interaction.attr('orientation')
: 'vertical';

if (isSingleOrder) {
const $choices = $choiceArea.children('.qti-choice');
$container.addClass('test-preview');
$resultArea.append($choices);
}

let $activeChoice = null,
scaleX,
scaleY,
Expand Down Expand Up @@ -554,13 +573,16 @@ const setResponse = function (interaction, response) {
const $container = containerHelper.get(interaction);
const $choiceArea = $('.choice-area', $container);
const $resultArea = $('.result-area', $container);
const isSingleOrder = interaction.attr('order') === 'single';

if (response === null || _.isEmpty(response)) {
resetResponse(interaction);
} else {
try {
_.forEach(pciResponse.unserialize(response, interaction), function (identifier) {
$resultArea.append($choiceArea.find(`[data-identifier="${identifier}"]`));
$resultArea.append(
(isSingleOrder ? $resultArea : $choiceArea).find(`[data-identifier="${identifier}"]`)
);
});
} catch (e) {
throw new Error(`wrong response format in argument : ${e}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div {{#if attributes.id}}id="{{attributes.id}}"{{/if}} class="qti-interaction qti-blockInteraction qti-orderInteraction{{#if horizontal}} qti-horizontal{{else}} qti-vertical{{/if}}{{#if attributes.class}} {{attributes.class}}{{/if}}"
<div {{#if attributes.id}}id="{{attributes.id}}"{{/if}} class="qti-interaction qti-blockInteraction qti-orderInteraction{{#if horizontal}} qti-horizontal{{else}} qti-vertical{{/if}}{{#if attributes.class}} {{attributes.class}}{{/if}}{{#equal attributes.order 'single'}} qti-single{{/equal}}"
data-serial="{{serial}}"
data-qti-class="orderInteraction"
data-orientation="{{#if horizontal}}horizontal{{else}}vertical{{/if}}"{{#if attributes.xml:lang}} lang="{{attributes.xml:lang}}"{{/if}}>
Expand Down

0 comments on commit 40b47fe

Please sign in to comment.