Skip to content

Commit

Permalink
Merge pull request #653 from oat-sa/release-2.22.0
Browse files Browse the repository at this point in the history
Release 2.22.0
  • Loading branch information
llecaque committed Apr 19, 2016
2 parents 94edefe + 372582a commit 4324800
Show file tree
Hide file tree
Showing 30 changed files with 649 additions and 166 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'label' => 'QTI item model',
'description' => 'TAO QTI item model',
'license' => 'GPL-2.0',
'version' => '2.21.0',
'version' => '2.22.0',
'author' => 'Open Assessment Technologies',
'requires' => array(
'taoItems' => '>=2.13',
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function update($initialVersion){
$this->setVersion('2.20.0');
}

$this->skip('2.20.0', '2.21.0');
$this->skip('2.20.0', '2.22.0');
}

}
2 changes: 1 addition & 1 deletion views/css/item-creator.css.map

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

2 changes: 1 addition & 1 deletion views/css/qti-runner.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions views/css/qti-runner.css.map

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions views/js/controllers.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/controllers.min.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define([
{ "mime" : "application/msword", "label" : __("Microsoft Word") },
{ "mime" : "application/vnd.ms-excel", "label" : __("Microsoft Excel") },
{ "mime" : "application/vnd.ms-powerpoint", "label" : __("Microsoft Powerpoint") }
]
];
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ define([
'tpl!taoQtiItem/qtiCommonRenderer/tpl/interactions/uploadInteraction',
'taoQtiItem/qtiCommonRenderer/helpers/container',
'taoQtiItem/qtiCommonRenderer/helpers/instructions/instructionManager',
'taoQtiItem/qtiCommonRenderer/helpers/uploadMime',
'ui/progressbar',
'ui/previewer',
'ui/modal',
'ui/waitForMedia',
'filereader'
], function ($, _, __, context, tpl, containerHelper, instructionMgr) {
], function ($, _, __, context, tpl, containerHelper, instructionMgr, uploadHelper) {
'use strict';

//FIXME this response is global to the app, it must be linked to the interaction!
Expand All @@ -55,6 +56,18 @@ define([
var filesize = file.size;
var filetype = file.type;

if (!validateFileType(file, interaction)) {
instructionMgr.removeInstructions(interaction);
var expectedType = _.find(uploadHelper.getMimeTypes(), {mime : interaction.attr('type')}),
message = __('Wrong type of file. Expected %s', expectedType ? expectedType.label : interaction.attr('type'));

instructionMgr.appendInstruction(interaction, message, function () {
this.setLevel('error');
});
instructionMgr.validateInstructions(interaction);
return;
}

$container.find('.file-name').empty()
.append(filename);

Expand Down Expand Up @@ -164,6 +177,21 @@ define([

};

/**
* Validate type of selected file
* @param file
* @param interaction
* @returns {boolean}
*/
function validateFileType (file, interaction) {
var expectedType = interaction.attr('type'),
result = true;
if (expectedType) {
result = expectedType === file.type;
}
return result;
}

var _resetGui = function (interaction) {
var $container = containerHelper.get(interaction);
$container.find('.file-name').text(__('No file selected'));
Expand Down Expand Up @@ -226,8 +254,6 @@ define([
};

var resetResponse = function (interaction) {

var $container = containerHelper.get(interaction);
_resetGui(interaction);
};

Expand Down Expand Up @@ -326,10 +352,12 @@ define([
* This way we could cover a lot more types. How could this be matched with the preview templates
* in tao/views/js/ui/previewer.js
*/
var getCustomData = function (interaction, data) {
return _.merge(data || {}, {
isPreviewable: interaction.attr('type') && interaction.attr('type').indexOf('image') === 0
function getCustomData (interaction, data) {
data = _.merge(data || {}, {
isPreviewable: interaction.attr('type') && interaction.attr('type').indexOf('image') === 0,
accept : interaction.attr('type') || undefined
});
return data;
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="progressbar"></div>
<span class="btn-info small col-4"></span>
<span class="file-name placeholder col-8 truncate"></span>
<input type="file"/>
<input type="file" {{#if accept}}accept="{{accept}}"{{/if}}/>
</div>
<div class="file-upload-preview lft {{#if isPreviewable}}{{{visible-file-upload-preview}}}{{/if}}">
<p class="nopreview">{{__ 'No preview available'}}</p>
Expand Down
22 changes: 19 additions & 3 deletions views/js/qtiCreator/editor/MathEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define([

config = config || {};

this.mathML = config.mathML || '';
this.setMathML(config.mathML || '');
this.tex = config.tex || '';
this.display = config.display || 'inline';

Expand All @@ -26,7 +26,9 @@ define([

MathEditor.prototype.setMathML = function(mathMLstr){

this.mathML = _stripMathTags(mathMLstr);
mathMLstr = _stripMathTags(mathMLstr);
mathMLstr = _stripComments(mathMLstr);
this.mathML = mathMLstr;

return this;//for chaining purpose
};
Expand Down Expand Up @@ -84,9 +86,16 @@ define([
jaxQueue.Push(
["Typeset", MathJax.Hub, this.$buffer[0]],
function(){
var $script = _this.$buffer.find('script');

_this.processing = false;

args.target.html(_this.$buffer.html());

if ($script.length){
_this.mathML = _stripMathTags($script.html());
}

_this.$buffer.empty();
}
);
Expand Down Expand Up @@ -156,6 +165,13 @@ define([
return mathMLstr;
};

var _stripComments = function(mathMLstr) {
mathMLstr = mathMLstr.replace(/<!--.*?-->/g, '');
mathMLstr = mathMLstr.replace(/&lt;!--.*?--&gt;/g, '');

return mathMLstr;
};

var _getJaxByElement = function($element){

if($element instanceof $ && $element.length){
Expand Down Expand Up @@ -185,7 +201,7 @@ define([
var mathML = '';

try{
mathML = texJax.root.toMathML('');
mathML = _stripComments(texJax.root.toMathML(''));
}catch(err){
if(!err.restart){
throw err;
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/test/MathEditor/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>QtiElements Test - QTI item model information model definition </title>
<title>MathJax Editor Test</title>
<link rel="stylesheet" type="text/css" href="/tao/views/js/lib/qunit/qunit.css">
<script type="text/javascript" src="/tao/views/js/lib/require.js"></script>
<script type="text/javascript" src="/tao/views/js/lib/qunit/qunit.js"></script>
Expand Down
133 changes: 128 additions & 5 deletions views/js/qtiCreator/test/MathEditor/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ function($, MathEditor, mathJax) {
display: data.display
});

if (typeof mathJax === 'undefined') {
assert.ok(false, 'MathJax is not available');
QUnit.start();

} else {
if (isMathJaxAvailable()) {
mathEditor.setTex(data.input);
mathEditor.renderFromTex();

Expand All @@ -58,6 +54,133 @@ function($, MathEditor, mathJax) {
}
});

QUnit.module('Matheditor MathML rendering');


var texWithSpecialChars = [
{ title: 'lower than', input: 'w < y' },
{ title: 'lower than equal', input: 'x \\leq y' },
{ title: 'times', input: 'x * y' }
];

QUnit
.cases(texWithSpecialChars)
.asyncTest('Latex to MathML conversion strips MathJax-generated comments', 2, function test(data, assert) {
var mathjaxRenderingDelayMs = 750,

$buffer = $('.mj-buffer'),
$target = $('.mj-target'),

mathEditor = new MathEditor({
buffer: $buffer,
target: $target
});

if (isMathJaxAvailable()) {
mathEditor.setTex(data.input);
mathEditor.renderFromTex();

setTimeout(function checkMathJaxOutput() {
assert.ok(doesntContainsComments(mathEditor.mathML),
'Error in MathEditor.mathML, expected striped comments in ' + data.input +
' but got: ' + mathEditor.mathML);
assert.ok(doesntContainsComments($target.html()),
'Error in MathML output, expected striped comments in ' + data.input +
' but got: ' + $target.html());

QUnit.start();
}, mathjaxRenderingDelayMs);
}
});


var mathMLWithComments = [
{ title: 'plain comment', input: '<mstyle displaystyle="true" scriptlevel="0"><mrow class="MJX-TeXAtom-ORD"><mi>x</mi><mo>&#x2264;<!-- ≤ --></mo><mi>w</mi></mrow></mstyle>'},
{ title: 'html-encoded comment', input: '<mstyle displaystyle="true" scriptlevel="0"><mrow class="MJX-TeXAtom-ORD"><mi>x</mi><mo>&#x2264;&lt;!-- ≤ --&gt;</mo><mi>w</mi></mrow></mstyle>'}
];

QUnit
.cases(mathMLWithComments)
.asyncTest('MathML rendering strips comments', 2, function test(data, assert) {
var mathjaxRenderingDelayMs = 750,

$buffer = $('.mj-buffer'),
$target = $('.mj-target'),

mathEditor = new MathEditor({
buffer: $buffer,
target: $target
});

if (isMathJaxAvailable()) {
mathEditor.setMathML(data.input);
mathEditor.renderFromMathML();

setTimeout(function checkMathJaxOutput() {
assert.ok(doesntContainsComments(mathEditor.mathML),
'Error in MathEditor.mathML, expected striped comments in ' + data.input +
' but got: ' + mathEditor.mathML);
assert.ok(doesntContainsComments($target.html()),
'Error in MathML output, expected striped comments in ' + data.input +
' but got: ' + $target.html());

QUnit.start();
}, mathjaxRenderingDelayMs);
}
});

function doesntContainsComments(string) {
return string.match(/<!--.*?-->/) === null && string.match(/&lt;!--.*?--&gt;/) === null;
}


var mathMLWithSpecialChars = [
{ title: 'inferior',
input: '<mstyle><mrow><mi>x</mi><mo><</mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&lt;</mo><mi>y</mi></mrow></mstyle>' },
{ title: 'superior',
input: '<mstyle><mrow><mi>x</mi><mo>></mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&gt;</mo><mi>y</mi></mrow></mstyle>' },
{ title: 'both',
input: '<mstyle><mrow><mi>x</mi><mo>></mo><mi>y</mi><mo><</mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&gt;</mo><mi>y</mi><mo>&lt;</mo><mi>y</mi></mrow></mstyle>' }
];

QUnit
.cases(mathMLWithSpecialChars)
.asyncTest('MathML rendering encodes special chars', 1, function test(data, assert) {
var mathjaxRenderingDelayMs = 750,

$buffer = $('.mj-buffer'),
$target = $('.mj-target'),

mathEditor = new MathEditor({
buffer: $buffer,
target: $target
});

if (isMathJaxAvailable()) {
mathEditor.setMathML(data.input);
mathEditor.renderFromMathML();

setTimeout(function checkMathJaxOutput() {
assert.strictEqual(mathEditor.mathML, data.output);

QUnit.start();
}, mathjaxRenderingDelayMs);
}
});

function isMathJaxAvailable() {
if (typeof mathJax === 'undefined') {
QUnit.assert.ok(false, 'MathJax is not available');
QUnit.start();

return false;
}
return true;
}

});


12 changes: 5 additions & 7 deletions views/js/qtiCreator/widgets/interactions/helpers/answerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ define([
editMapping = (_.indexOf(['MAP_RESPONSE', 'MAP_RESPONSE_POINT'], template) >= 0),
defineCorrect = answerStateHelper.defineCorrect(response);

if(!template){
if(rp.processingType === 'custom'){
template = 'CUSTOM';
}else{
throw 'invalid response template';
}
if(!template || rp.processingType === 'custom'){
template = 'CUSTOM';
}

widget.$responseForm.html(responseFormTpl({
Expand Down Expand Up @@ -139,7 +135,9 @@ define([
});

modalFeedbackRule.initFeedbacksPanel($('.feedbackRule-panel', widget.$responseForm), response);


widget.$responseForm.trigger('initResponseForm');

formElement.initWidget(widget.$responseForm);
},
isCorrectDefined : function(widget){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define([
'taoQtiItem/qtiCreator/widgets/states/factory',
'taoQtiItem/qtiCreator/widgets/interactions/blockInteraction/states/Question',
'taoQtiItem/qtiCreator/widgets/helpers/formElement',
'taoQtiItem/qtiCreator/helper/uploadMime',
'taoQtiItem/qtiCommonRenderer/helpers/uploadMime',
'tpl!taoQtiItem/qtiCreator/tpl/forms/interactions/upload'
], function(_, __, stateFactory, Question, formElement, uploadHelper, formTpl){

Expand Down
7 changes: 3 additions & 4 deletions views/js/qtiItem/core/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ define([

if (ns && ns.name) {
body = raw.replace(/<(\/)?([^!<])/g, '<$1' + ns.name + ':$2');
body = body.replace(/(>)([\W]+)(<\/)/g, function (match, p1, p2, p3) {
return [p1, _.escape(p2), p3].join('');
});

tag = ns.name + ':' + tag;
}

body = body.replace(/<!--.*?-->/g, ''); // remove Mathjax-generated comments
body = body.replace(/&lt;!--.*?--&gt;/g, ''); // fix for broken items because of Mathjax comments

var defaultData = {
block : (this.attr('display') === 'block') ? true : false,
body : body,
Expand Down
Loading

0 comments on commit 4324800

Please sign in to comment.