Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
20a06936
Commit
20a06936
authored
1 year ago
by
smmercuri
Browse files
Options
Downloads
Patches
Plain Diff
Code check
parent
6b0aa542
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stack/cas/castext2/blocks/parsons.block.php
+43
-53
43 additions, 53 deletions
stack/cas/castext2/blocks/parsons.block.php
with
43 additions
and
53 deletions
stack/cas/castext2/blocks/parsons.block.php
+
43
−
53
View file @
20a06936
...
...
@@ -34,7 +34,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
],
'local'
=>
[
'css'
=>
'cors://sortable.min.css'
,
'js'
=>
'cors://sortable.min.js'
,
'js'
=>
'cors://sortable
core
.min.js'
,
],
];
...
...
@@ -59,14 +59,14 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Number of available rows.
$rows
=
null
;
// Tranpose
// Tranpose
.
$transpose
=
false
;
// Item height
$item
_
height
=
null
;
// Item height
.
$itemheight
=
null
;
// Item width
$item
_
width
=
null
;
// Item width
.
$itemwidth
=
null
;
foreach
(
$this
->
params
as
$key
=>
$value
)
{
if
(
$key
===
'clone'
)
{
...
...
@@ -78,9 +78,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
}
else
if
(
$key
===
'transpose'
)
{
$transpose
=
(
$value
===
'true'
);
}
else
if
(
$key
===
'item-height'
)
{
$item
_
height
=
$value
;
$itemheight
=
$value
;
}
else
if
(
$key
===
'item-width'
)
{
$item
_
width
=
$value
;
$itemwidth
=
$value
;
}
else
if
(
$key
!==
'input'
)
{
$xpars
[
$key
]
=
$value
;
}
else
{
...
...
@@ -157,24 +157,16 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Identify default proof mode based on block header params
// 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
);
$gridmode
=
!
$proofmode
;
$fixedgridmode
=
(
$columns
!==
null
&&
$rows
!==
null
);
$columns
=
$proofmode
?
'1'
:
$columns
;
// Add correctly oriented container divs for the proof lists to be accessed by sortable.
$orientation
=
$transpose
?
'row'
:
'col'
;
$tmprows
=
$transpose
?
$columns
:
$rows
;
$columns
=
$transpose
?
$rows
:
$columns
;
$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'>
<i class='fa fa-expand'></i></button>"
);
if
(
$clone
===
'true'
)
{
...
...
@@ -184,11 +176,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
<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>'
);
// JS script.
...
...
@@ -204,9 +191,6 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
stack_cors_link
(
'stacksortable.min.js'
)
.
"';
\n
"
;
$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.
$r
->
items
[]
=
new
MP_String
(
'document.getElementById("resize").addEventListener(
"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 {
}
$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
)
{
$code
=
'var headers = ["'
.
stack_string
(
'stackBlock_parsons_used_header'
)
.
'"];'
.
"
\n
"
;
}
else
{
$code
=
'var headers = ['
.
implode
(
', '
,
range
(
1
,
intval
(
$columns
)))
.
'];'
.
"
\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 valid, index;'
.
"
\n
"
;
$code
.
=
'[proofSteps, sortableUserOpts, headers, available_header, index, valid] =
preprocess_steps(proofSteps, sortableUserOpts, headers, available_header, index);'
.
"
\n
"
;
// If the author's JSON has invalid format throw an error.
//
$code .= 'if (valid === false)
//
{stack_js.display_error("' . stack_string('stackBlock_parsons_contents') . '");}' . "\n";
$code
.
=
'if (valid === false)
{stack_js.display_error("'
.
stack_string
(
'stackBlock_parsons_contents'
)
.
'");}'
.
"
\n
"
;
// Link up to STACK inputs.
if
(
count
(
$inputs
)
>
0
)
{
...
...
@@ -257,9 +244,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Instantiate STACK sortable helper class.
$code
.
=
'const stackSortable = new stack_sortable(proofSteps, id, sortableUserOpts, "'
.
$clone
.
'", "'
.
$columns
.
'", "'
.
$rows
.
'", "'
.
$orientation
.
'", index, "'
.
$gridmode
.
'",
"'
.
$item_height
.
'",
"'
.
$item
_
width
.
'");'
.
"
\n
"
;
// Generate the two lists in HTML.
$clone
.
'", "'
.
$columns
.
'", "'
.
$rows
.
'", "'
.
$orientation
.
'", index, "'
.
$gridmode
.
'",
"'
.
$item
height
.
'", "'
.
$item
width
.
'");'
.
"
\n
"
;
// Generate the two lists
, headers and index
in HTML.
$code
.
=
'stackSortable.add_reorientation_button();'
.
"
\n
"
;
$code
.
=
'stackSortable.create_row_col_divs();'
.
"
\n
"
;
$code
.
=
'if (index !== undefined) {stackSortable.add_index(index);};'
.
"
\n
"
;
...
...
@@ -270,11 +257,13 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
// Create the Sortable objects.
// First, instantiate with default options first in order to extract all possible options for validation.
$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
"
;
// 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
"
;
// Add the onSort option in order to link up to input and overwrite user onSort if passed.
$code
.
=
'sortableUsed.forEach((sortableList) =>
...
...
@@ -299,9 +288,9 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
}
// Add double-click events for proof.
//
if ($proofmode) {
//
$code .= 'stackSortable.add_dblclick_listeners(sortableUsed, sortableAvailable);' . "\n";
//
}
if
(
$proofmode
)
{
$code
.
=
'stackSortable.add_dblclick_listeners(sortableUsed, sortableAvailable);'
.
"
\n
"
;
}
// Typeset MathJax. MathJax 2 uses Queue, whereas 3 works with promises.
$code
.
=
(
$mathjaxversion
===
"2"
)
?
...
...
@@ -345,7 +334,8 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
)
:
bool
{
// 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
// 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.
// Also that the references make sense.
...
...
@@ -445,7 +435,7 @@ class stack_cas_castext2_parsons extends stack_cas_castext2_block {
$valids
=
[
'width'
,
'height'
,
'aspect-ratio'
,
'version'
,
'overridecss'
,
'overridejs'
,
'input'
,
'clone'
,
'columns'
,
'rows'
,
'transpose'
,
'item-height'
,
'item-width'
'item-width'
,
];
$err
[]
=
stack_string
(
'stackBlock_parsons_param'
,
[
'param'
=>
implode
(
', '
,
$valids
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment