Skip to content

Commit

Permalink
Merge branch 'release-1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
shaveko committed Dec 27, 2022
2 parents 091a450 + 231b566 commit 99d43b9
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 134 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-item-runner-qti",
"version": "1.8.0",
"version": "1.9.0",
"displayName": "TAO Item Runner QTI",
"description": "TAO QTI Item Runner modules",
"files": [
Expand All @@ -12,7 +12,7 @@
},
"scripts": {
"test": "npx qunit-testrunner",
"test:keepAlive": "npx qunit-testrunner --keepalive",
"test:keepAlive": "npx qunit-testrunner --keepalive --port 5300",
"test:cov": "npm run build:cov && npx qunit-testrunner --cov",
"coverage": "nyc report",
"coverage:html": "nyc report --reporter=lcov && open-cli coverage/lcov-report/index.html",
Expand Down Expand Up @@ -52,7 +52,7 @@
"@oat-sa/prettier-config": "^0.1.1",
"@oat-sa/rollup-plugin-wildcard-external": "^0.1.0",
"@oat-sa/tao-core-libs": "^0.5.1",
"@oat-sa/tao-core-sdk": "^1.21.1",
"@oat-sa/tao-core-sdk": "^1.22.0",
"@oat-sa/tao-core-shared-libs": "^1.4.1",
"@oat-sa/tao-core-ui": "^1.64.1",
"@oat-sa/tao-item-runner": "^0.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import ckEditor from 'ckeditor';
import ckConfigurator from 'taoQtiItem/qtiCommonRenderer/helpers/ckConfigurator';
import patternMaskHelper from 'taoQtiItem/qtiCommonRenderer/helpers/patternMask';
import tooltip from 'ui/tooltip';
import converter from 'util/converter';
import loggerFactory from 'core/logger';

/**
Expand Down Expand Up @@ -322,19 +323,20 @@ function getResponse(interaction) {
values = [];

$container.find('input').each(function (i) {
const $el = $(this);
const editorValue = $(this).val();

if (attributes.placeholderText && $el.val() === attributes.placeholderText) {
if (attributes.placeholderText && value === attributes.placeholderText) {
values[i] = '';
} else {
const convertedValue = converter.convert(editorValue);
if (baseType === 'integer') {
values[i] = parseInt($el.val(), numericBase);
values[i] = parseInt(convertedValue, numericBase);
values[i] = isNaN(values[i]) ? '' : values[i];
} else if (baseType === 'float') {
values[i] = parseFloat($el.val());
values[i] = parseFloat(convertedValue);
values[i] = isNaN(values[i]) ? '' : values[i];
} else if (baseType === 'string') {
values[i] = $el.val();
values[i] = convertedValue;
}
}
});
Expand All @@ -345,11 +347,11 @@ function getResponse(interaction) {
value = '';
} else {
if (baseType === 'integer') {
value = parseInt(_getTextareaValue(interaction), numericBase);
value = parseInt(converter.convert(_getTextareaValue(interaction)), numericBase);
} else if (baseType === 'float') {
value = parseFloat(_getTextareaValue(interaction));
value = converter.convert(_getTextareaValue(interaction));
} else if (baseType === 'string') {
value = _getTextareaValue(interaction, true);
value = converter.convert(_getTextareaValue(interaction, true));
}
}

Expand Down
111 changes: 62 additions & 49 deletions src/qtiCommonRenderer/renderers/interactions/TextEntryInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2014-2022 Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*/

/**
* @author Sam Sipasseuth <[email protected]>
* @author Bertrand Chevrier <[email protected]>
* @author Andrey Shaveko <[email protected]>
*/

import $ from 'jquery';
import _ from 'lodash';
import __ from 'i18n';
Expand All @@ -31,28 +33,35 @@ import pciResponse from 'taoQtiItem/qtiCommonRenderer/helpers/PciResponse';
import patternMaskHelper from 'taoQtiItem/qtiCommonRenderer/helpers/patternMask';
import locale from 'util/locale';
import tooltip from 'ui/tooltip';
import loggerFactory from 'core/logger';
import converter from 'util/converter';

/**
* Create a logger
*/
const logger = loggerFactory('taoQtiItem/qtiCommonRenderer/renderers/interactions/TextEntryInteraction.js');

/**
* Hide the tooltip for the text input
* @param {jQuery} $input
*/
var hideTooltip = function hideTooltip($input) {
function hideTooltip($input) {
if ($input.data('$tooltip')) {
$input.data('$tooltip').hide();
}
};
}

/**
* Create/Show tooltip for the text input
* @param {jQuery} $input
* @param {String} theme
* @param {String} message
*/
var showTooltip = function showTooltip($input, theme, message) {
function showTooltip($input, theme, message) {
if ($input.data('$tooltip')) {
$input.data('$tooltip').updateTitleContent(message);
} else {
var textEntryTooltip = tooltip.create($input, message, {
const textEntryTooltip = tooltip.create($input, message, {
theme: theme,
trigger: 'manual'
});
Expand All @@ -61,7 +70,7 @@ var showTooltip = function showTooltip($input, theme, message) {
}

$input.data('$tooltip').show();
};
}

/**
* Init rendering, called after template injected into the DOM
Expand All @@ -70,15 +79,13 @@ var showTooltip = function showTooltip($input, theme, message) {
*
* @param {object} interaction
*/
var render = function render(interaction) {
var attributes = interaction.getAttributes(),
baseType = interaction.getResponseDeclaration().attr('baseType'),
$input = interaction.getContainer(),
expectedLength,
updateMaxCharsTooltip,
updatePatternMaskTooltip,
patternMask = interaction.attr('patternMask'),
maxChars = parseInt(patternMaskHelper.parsePattern(patternMask, 'chars'), 10);
function render(interaction) {
const attributes = interaction.getAttributes();
const baseType = interaction.getResponseDeclaration().attr('baseType');
const $input = interaction.getContainer();
const patternMask = interaction.attr('patternMask');
const maxChars = parseInt(patternMaskHelper.parsePattern(patternMask, 'chars'), 10);
let expectedLength;

// Setting up baseType
switch (baseType) {
Expand Down Expand Up @@ -106,9 +113,10 @@ var render = function render(interaction) {
}

if (maxChars) {
updateMaxCharsTooltip = function updateMaxCharsTooltip() {
var count = $input.val().length;
var message, messageType;
const updateMaxCharsTooltip = () => {
const count = $input.val().length;
let message;
let messageType;

if (count) {
message = __('%d/%d', count, maxChars);
Expand Down Expand Up @@ -143,8 +151,8 @@ var render = function render(interaction) {
hideTooltip($input);
});
} else if (attributes.patternMask) {
updatePatternMaskTooltip = function updatePatternMaskTooltip() {
var regex = new RegExp(attributes.patternMask);
const updatePatternMaskTooltip = () => {
const regex = new RegExp(attributes.patternMask);

hideTooltip($input);

Expand Down Expand Up @@ -174,11 +182,11 @@ var render = function render(interaction) {
containerHelper.triggerResponseChangeEvent(interaction);
});
}
};
}

var resetResponse = function resetResponse(interaction) {
function resetResponse(interaction) {
interaction.getContainer().val('');
};
}

/**
* Set the response to the rendered interaction.
Expand All @@ -194,17 +202,19 @@ var resetResponse = function resetResponse(interaction) {
* @param {object} interaction
* @param {object} response
*/
var setResponse = function setResponse(interaction, response) {
var responseValue;
function setResponse(interaction, response) {
let responseValue;

try {
responseValue = pciResponse.unserialize(response, interaction);
} catch (e) {}
} catch (e) {
logger.warn(`setResponse error ${e}`);
}

if (responseValue && responseValue.length) {
interaction.getContainer().val(responseValue[0]);
}
};
}

/**
* Return the response of the rendered interaction
Expand All @@ -218,35 +228,38 @@ var setResponse = function setResponse(interaction, response) {
* @param {object} interaction
* @returns {object}
*/
var getResponse = function getResponse(interaction) {
var ret = { base: {} },
value,
$input = interaction.getContainer(),
attributes = interaction.getAttributes(),
baseType = interaction.getResponseDeclaration().attr('baseType'),
numericBase = attributes.base || 10;

if ($input.hasClass('invalid') || (attributes.placeholderText && $input.val() === attributes.placeholderText)) {
function getResponse(interaction) {
const ret = { base: {} };
const $input = interaction.getContainer();
const attributes = interaction.getAttributes();
const baseType = interaction.getResponseDeclaration().attr('baseType');
const numericBase = attributes.base || 10;

const inputValue = $input.val();
let value;

if ($input.hasClass('invalid') || (attributes.placeholderText && inputValue === attributes.placeholderText)) {
//invalid response or response equals to the placeholder text are considered empty
value = '';
} else {
const convertedValue = converter.convert(inputValue.trim());
if (baseType === 'integer') {
value = locale.parseInt($input.val(), numericBase);
value = locale.parseInt(convertedValue, numericBase);
} else if (baseType === 'float') {
value = locale.parseFloat($input.val());
value = locale.parseFloat(convertedValue);
} else if (baseType === 'string') {
value = $input.val();
value = convertedValue;
}
}

ret.base[baseType] = isNaN(value) && typeof value === 'number' ? '' : value;

return ret;
};
}

var destroy = function destroy(interaction) {
function destroy(interaction) {
$('input.qti-textEntryInteraction').each(function(index, el) {
var $input = $(el);
const $input = $(el);
if ($input.data('$tooltip')) {
$input.data('$tooltip').dispose();
$input.removeData('$tooltip');
Expand All @@ -262,38 +275,38 @@ var destroy = function destroy(interaction) {

//remove all references to a cache container
containerHelper.reset(interaction);
};
}

/**
* Set the interaction state. It could be done anytime with any state.
*
* @param {Object} interaction - the interaction instance
* @param {Object} state - the interaction state
*/
var setState = function setState(interaction, state) {
function setState(interaction, state) {
if (_.isObject(state)) {
if (state.response) {
interaction.resetResponse();
interaction.setResponse(state.response);
}
}
};
}

/**
* Get the interaction state.
*
* @param {Object} interaction - the interaction instance
* @returns {Object} the interaction current state
*/
var getState = function getState(interaction) {
var state = {};
var response = interaction.getResponse();
function getState(interaction) {
const state = {};
const response = interaction.getResponse();

if (response) {
state.response = response;
}
return state;
};
}

export default {
qtiClass: 'textEntryInteraction',
Expand Down
1 change: 1 addition & 0 deletions test/qtiCommonRenderer/interactions/extendedText/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<div id="item-container-8"></div>
<div id="item-container-9"></div>
<div id="item-container-10"></div>
<div id="item-container-11"></div>
</div>

<div id="outside-container"></div>
Expand Down
Loading

0 comments on commit 99d43b9

Please sign in to comment.