Skip to content
Snippets Groups Projects
Commit 20a06936 authored by smmercuri's avatar smmercuri
Browse files

Code check

parent 6b0aa542
Branches
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -34,7 +34,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
], ],
'local' => [ 'local' => [
'css' => 'cors://sortable.min.css', 'css' => 'cors://sortable.min.css',
'js' => 'cors://sortable.min.js', 'js' => 'cors://sortablecore.min.js',
], ],
]; ];
...@@ -59,14 +59,14 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -59,14 +59,14 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Number of available rows. // Number of available rows.
$rows = null; $rows = null;
// Tranpose // Tranpose.
$transpose = false; $transpose = false;
// Item height // Item height.
$item_height = null; $itemheight = null;
// Item width // Item width.
$item_width = null; $itemwidth = null;
foreach ($this->params as $key => $value) { foreach ($this->params as $key => $value) {
if ($key === 'clone') { if ($key === 'clone') {
...@@ -78,9 +78,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -78,9 +78,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
} else if ($key === 'transpose') { } else if ($key === 'transpose') {
$transpose = ($value === 'true'); $transpose = ($value === 'true');
} else if ($key === 'item-height') { } else if ($key === 'item-height') {
$item_height = $value; $itemheight = $value;
} else if ($key === 'item-width') { } else if ($key === 'item-width') {
$item_width = $value; $itemwidth = $value;
} else if ($key !== 'input') { } else if ($key !== 'input') {
$xpars[$key] = $value; $xpars[$key] = $value;
} else { } else {
...@@ -157,24 +157,16 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -157,24 +157,16 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Identify default proof mode based on block header params // Identify default proof mode based on block header params
// Note that proof mode behaves the same as the general mode, but we just // Note that proof mode behaves the same as the general mode, but we just
// need to redefine columns // need to redefine columns.
$proofmode = ($columns === null && $rows === null); $proofmode = ($columns === null && $rows === null);
$gridmode = !$proofmode; $gridmode = !$proofmode;
$fixedgridmode = ($columns !== null && $rows !== null);
$columns = $proofmode ? '1' : $columns; $columns = $proofmode ? '1' : $columns;
// Add correctly oriented container divs for the proof lists to be accessed by sortable. // Add correctly oriented container divs for the proof lists to be accessed by sortable.
$orientation = $transpose ? 'row' : 'col'; $orientation = $transpose ? 'row' : 'col';
$tmprows = $transpose ? $columns : $rows; $tmprows = $transpose ? $columns : $rows;
$columns = $transpose ? $rows : $columns; $columns = $transpose ? $rows : $columns;
$rows = $tmprows; $rows = $tmprows;
/*$outer = $orientation === 'horizontal' ? 'row' : 'col';
$inner = $orientation === 'horizontal' ? 'col' : 'row';
$innerui = '<ul class="list-group ' . $inner . '" id="usedList"></ul>
<ul class="list-group ' . $inner . '" id="availableList"></ul>';
$r->items[] = new MP_String("<button type='button' class='parsons-button' id='orientation'>
<i class='fa fa-refresh'></i></button>");
*/
$r->items[] = new MP_String("<button type='button' class='parsons-button' id='resize'> $r->items[] = new MP_String("<button type='button' class='parsons-button' id='resize'>
<i class='fa fa-expand'></i></button>"); <i class='fa fa-expand'></i></button>");
if ($clone === 'true') { if ($clone === 'true') {
...@@ -184,11 +176,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -184,11 +176,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
<i class="fa fa-times-circle "></i></div>'); <i class="fa fa-times-circle "></i></div>');
} }
/*$r->items[] = new MP_String('<div class="container" id="sortableContainer" style="' . $astyle . '">
<div class=row>' . $innerui . '
</div>
</div>');*/
$r->items[] = new MP_String('<div class="container row" id="containerRow" style="' . $astyle . '"></div>'); $r->items[] = new MP_String('<div class="container row" id="containerRow" style="' . $astyle . '"></div>');
// JS script. // JS script.
...@@ -204,9 +191,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -204,9 +191,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
stack_cors_link('stacksortable.min.js') . "';\n"; stack_cors_link('stacksortable.min.js') . "';\n";
$r->items[] = new MP_String($importcode); $r->items[] = new MP_String($importcode);
// Add flip orientation listener to the orientation button.
// TO-DO: automatically set orientation based on device?
//$r->items[] = new MP_String('add_orientation_listener("orientation", "usedList", "availableList");' . "\n");
// Add the resize button listener. // Add the resize button listener.
$r->items[] = new MP_String('document.getElementById("resize").addEventListener( $r->items[] = new MP_String('document.getElementById("resize").addEventListener(
"click", () => {stack_js.resize_containing_frame("' . $width . '", get_iframe_height() + "px");});' . "\n"); "click", () => {stack_js.resize_containing_frame("' . $width . '", get_iframe_height() + "px");});' . "\n");
...@@ -230,21 +214,24 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -230,21 +214,24 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
} }
$r->items[] = new MP_String(";\n"); $r->items[] = new MP_String(";\n");
// Parse steps and Sortable options separately if they exist. Invalid JSON will be identified by preprocess_steps function. // Define default headers.
if ($proofmode) { if ($proofmode) {
$code = 'var headers = ["' . stack_string('stackBlock_parsons_used_header') . '"];' . "\n"; $code = 'var headers = ["' . stack_string('stackBlock_parsons_used_header') . '"];' . "\n";
} else { } else {
$code = 'var headers = [' . implode(', ', range(1, intval($columns))) . '];' . "\n"; $code = 'var headers = [' . implode(', ', range(1, intval($columns))) . '];' . "\n";
} }
$code .= 'var available_header = "' . stack_string('stackBlock_parsons_available_header') . '";' . "\n"; $code .= 'var available_header = "' . stack_string('stackBlock_parsons_available_header') . '";' . "\n";
// Parse steps, Sortable options, headers and index separately if they exist.
// Invalid JSON will be identified by preprocess_steps function.
$code .= 'var sortableUserOpts = {};' . "\n"; $code .= 'var sortableUserOpts = {};' . "\n";
$code .= 'var valid, index;' . "\n"; $code .= 'var valid, index;' . "\n";
$code .= '[proofSteps, sortableUserOpts, headers, available_header, index, valid] = $code .= '[proofSteps, sortableUserOpts, headers, available_header, index, valid] =
preprocess_steps(proofSteps, sortableUserOpts, headers, available_header, index);' . "\n"; preprocess_steps(proofSteps, sortableUserOpts, headers, available_header, index);' . "\n";
// If the author's JSON has invalid format throw an error. // If the author's JSON has invalid format throw an error.
//$code .= 'if (valid === false) $code .= 'if (valid === false)
// {stack_js.display_error("' . stack_string('stackBlock_parsons_contents') . '");}' . "\n"; {stack_js.display_error("' . stack_string('stackBlock_parsons_contents') . '");}' . "\n";
// Link up to STACK inputs. // Link up to STACK inputs.
if (count($inputs) > 0) { if (count($inputs) > 0) {
...@@ -257,9 +244,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -257,9 +244,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Instantiate STACK sortable helper class. // Instantiate STACK sortable helper class.
$code .= 'const stackSortable = new stack_sortable(proofSteps, id, sortableUserOpts, "' . $code .= 'const stackSortable = new stack_sortable(proofSteps, id, sortableUserOpts, "' .
$clone .'", "' . $columns .'", "' . $rows . '", "' . $orientation . '", index, "' . $gridmode . '", "' . $item_height . '", $clone .'", "' . $columns .'", "' . $rows . '", "' . $orientation . '", index, "' . $gridmode . '",
"' . $item_width . '");' . "\n"; "' . $itemheight . '", "' . $itemwidth . '");' . "\n";
// Generate the two lists in HTML. // Generate the two lists, headers and index in HTML.
$code .= 'stackSortable.add_reorientation_button();' . "\n"; $code .= 'stackSortable.add_reorientation_button();' . "\n";
$code .= 'stackSortable.create_row_col_divs();' . "\n"; $code .= 'stackSortable.create_row_col_divs();' . "\n";
$code .= 'if (index !== undefined) {stackSortable.add_index(index);};' . "\n"; $code .= 'if (index !== undefined) {stackSortable.add_index(index);};' . "\n";
...@@ -270,11 +257,13 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -270,11 +257,13 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Create the Sortable objects. // Create the Sortable objects.
// First, instantiate with default options first in order to extract all possible options for validation. // First, instantiate with default options first in order to extract all possible options for validation.
$code .= 'var sortableUsed = $code .= 'var sortableUsed =
stackSortable.ids.used.map((idList) => idList.map((usedId) => Sortable.create(document.getElementById(usedId), stackSortable.options.used)));' . "\n"; stackSortable.ids.used.map((idList) =>
idList.map((usedId) => Sortable.create(document.getElementById(usedId), stackSortable.options.used)));' . "\n";
$code .= 'var possibleOptionKeys = Object.keys(sortableUsed[0][0].options).concat(SUPPORTED_CALLBACK_FUNCTIONS);' . "\n"; $code .= 'var possibleOptionKeys = Object.keys(sortableUsed[0][0].options).concat(SUPPORTED_CALLBACK_FUNCTIONS);' . "\n";
// Now set appropriate options. // Now set appropriate options.
$code .= 'sortableUsed.forEach((usedList) => Object.entries(stackSortable.options.used).forEach(([key, val]) => usedList[0].option(key, val)));' . "\n"; $code .= 'sortableUsed.forEach((usedList) => Object.entries(stackSortable.options.used).forEach(
([key, val]) => usedList[0].option(key, val)));' . "\n";
$code .= 'var sortableAvailable = Sortable.create(availableList, stackSortable.options.available);' . "\n"; $code .= 'var sortableAvailable = Sortable.create(availableList, stackSortable.options.available);' . "\n";
// Add the onSort option in order to link up to input and overwrite user onSort if passed. // Add the onSort option in order to link up to input and overwrite user onSort if passed.
$code .= 'sortableUsed.forEach((sortableList) => $code .= 'sortableUsed.forEach((sortableList) =>
...@@ -299,9 +288,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -299,9 +288,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
} }
// Add double-click events for proof. // Add double-click events for proof.
//if ($proofmode) { if ($proofmode) {
// $code .= 'stackSortable.add_dblclick_listeners(sortableUsed, sortableAvailable);' . "\n"; $code .= 'stackSortable.add_dblclick_listeners(sortableUsed, sortableAvailable);' . "\n";
//} }
// Typeset MathJax. MathJax 2 uses Queue, whereas 3 works with promises. // Typeset MathJax. MathJax 2 uses Queue, whereas 3 works with promises.
$code .= ($mathjaxversion === "2") ? $code .= ($mathjaxversion === "2") ?
...@@ -345,7 +334,8 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -345,7 +334,8 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
): bool { ): bool {
// TO-DO : matching validations: (1) check values of transpose ('true' or 'false'); (2) check values of rows/columns // TO-DO : matching validations: (1) check values of transpose ('true' or 'false'); (2) check values of rows/columns
// (only string containing ints); (3) check rows is not passed without columns; (4) check length of headers // (only string containing ints); (3) check rows is not passed without columns; (4) check length of headers
// matches columns (think this has to be in js); (5) check index length matches length of rows if rows passed (again js probably). // matches columns (think this has to be in js); (5) check index length matches length of rows if rows passed
// (again js probably).
// Basically, check that the dimensions have units we know. // Basically, check that the dimensions have units we know.
// Also that the references make sense. // Also that the references make sense.
...@@ -445,7 +435,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block { ...@@ -445,7 +435,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
$valids = [ $valids = [
'width', 'height', 'aspect-ratio', 'version', 'overridecss', 'width', 'height', 'aspect-ratio', 'version', 'overridecss',
'overridejs', 'input', 'clone', 'columns', 'rows', 'transpose', 'item-height', 'overridejs', 'input', 'clone', 'columns', 'rows', 'transpose', 'item-height',
'item-width' 'item-width',
]; ];
$err[] = stack_string('stackBlock_parsons_param', [ $err[] = stack_string('stackBlock_parsons_param', [
'param' => implode(', ', $valids), 'param' => implode(', ', $valids),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment