Skip to content

Commit

Permalink
Merge branch 'proof-builder' of https://github.com/maths/moodle-qtype…
Browse files Browse the repository at this point in the history
…_stack into proof-builder
  • Loading branch information
sangwinc committed Nov 13, 2023
2 parents cef7e2e + d6d07a2 commit 3db3a02
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
3 changes: 3 additions & 0 deletions corsscripts/stacksortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const stack_sortable = class {

_generate_state(proofSteps, inputId) {
let stateStore = document.getElementById(inputId);
if (stateStore == null) {
return {used: [], available: [...Object.keys(proofSteps)]}
}
return stateStore.value && stateStore.value != "" ? JSON.parse(stateStore.value) : {used: [], available: [...Object.keys(proofSteps)]};
}

Expand Down
3 changes: 2 additions & 1 deletion corsscripts/stacksortable.min.js

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

21 changes: 13 additions & 8 deletions doc/en/Developer/Development_track.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ Please note, this is the _last_ version of STACK which will support Moodle 3.x.

Create a working Parson's block

1. Incorporate prototype into parsons.block.php
2. Choose default options for Sortable.js and document them
3. Unit tests
4. Choose css : review proof styles in top-level css and choose/propose styles for Parsons
Essential
1. Choose and document default options for Sortable.js and document them
2. Unit tests
3. Choose css : review proof styles in top-level css and choose/propose styles for Parsons
Please choose one list above the other!
5. Choose Sortable.js version: add to core scripts and minify
6. Hashing keys
7. Nested list: `nestedSortable`
8. Do not require an input (teacher's might want to display).
4. Nested lists
5. double tap
6. Auto-size (i. internal best guess; ii. js iframe dynamic rescaling)
7. Confirm MathJax default
8. User button for vertical vs. horizontal

Later
1. Hashing keys


A. All functionality to be JSON strings (as in Sam's code)
B. Block to accept and produce Maxima proof expressions
Expand Down
8 changes: 5 additions & 3 deletions stack/cas/castext2/blocks/jsxgraph.block.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ public function compile($format, $options): ? MP_Node {
$height = $xpars['height'];
}

$astyle = "width:calc($width - 3px);height:calc($height - 3px);";
$innerwidth = substr($width, -1) === 'px' ? "$width - 3px" : "100% - 3px";
$innerheight = substr($width, -1) === 'px' ? "$height - 3px" : "100% - 3px";
$astyle = "width:calc($innerwidth);height:calc($innerheight);";

if (array_key_exists('aspect-ratio', $xpars)) {
$aspectratio = $xpars['aspect-ratio'];
// Unset the undefined dimension, if both are defined then we have a problem.
if (array_key_exists('height', $xpars)) {
$astyle = "height:calc($height - 3px);aspect-ratio:$aspectratio;";
$astyle = "height:calc($innerheight);aspect-ratio:$aspectratio;";
} else if (array_key_exists('width', $xpars)) {
$astyle = "width:calc($width - 3px);aspect-ratio:$aspectratio;";
$astyle = "width:calc($innerwidth);aspect-ratio:$aspectratio;";
}
}

Expand Down
34 changes: 28 additions & 6 deletions stack/cas/castext2/blocks/parsons.block.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public function compile($format, $options): ? MP_Node {
// Set default width and height here, we want to push forward to overwrite the iframe defaults
// if they are not provided in the block parameters
$width = array_key_exists('width', $xpars) ? $xpars['width'] : "100%";
// TODO: set default based on number of proof steps
/*$opt2 = [];
if ($options !== null) {
$opt2 = array_merge([], $options);
}
$opt2['in iframe'] = true;
/*foreach ($this->children as $item) {
// Assume that all code inside is JavaScript and that we do not
// want to do the markdown escaping or any other in it.
$c = $item->compile(castext2_parser_utils::RAWFORMAT, $opt2);
if ($c !== null) {
$num_steps = $c->;
};
};
$num_steps = $this->children[1]->compile(castext2_parser_utils::RAWFORMAT, $opt2)->arguments[2]->arguments[1];*/
//$num_steps = ($this->children[0]->compile(castext2_parser_utils::RAWFORMAT, $opt2))->value;
$height = array_key_exists('height', $xpars) ? $xpars['height'] : "400px";
$xpars['width'] = $width;
$xpars['height'] = $height;
Expand All @@ -93,7 +109,11 @@ public function compile($format, $options): ? MP_Node {
$r->items[] = new MP_String(json_encode($xpars));

// Plug in some style and scripts.
$r->items[] = new MP_String('<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>');
$mathjax = stack_get_mathjax_url();
$r->items[] = new MP_List([
new MP_String('script'),
new MP_String(json_encode(['type' => 'text/javascript', 'src' => $mathjax]))]);
//$r->items[] = new MP_String('<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>');
$r->items[] = new MP_List([
new MP_String('style'),
new MP_String(json_encode(['href' => $css]))
Expand All @@ -105,15 +125,17 @@ public function compile($format, $options): ? MP_Node {

// We need to define a size for the inner content.
$aspectratio = false;
$astyle = "width:calc($width - 3px);height:calc($height - 3px);";
$innerwidth = substr($width, -1) === 'px' ? "$width - 3px" : "100% - 3px";
$innerheight = substr($width, -1) === 'px' ? "$height - 3px" : "100% - 3px";
$astyle = "width:calc($innerwidth);height:calc($innerheight);";

if (array_key_exists('aspect-ratio', $xpars)) {
$aspectratio = $xpars['aspect-ratio'];
// Unset the undefined dimension, if both are defined then we have a problem.
if (array_key_exists('height', $xpars)) {
$astyle = "height:calc($height - 3px);aspect-ratio:$aspectratio;";
$astyle = "height:calc($innerheight);aspect-ratio:$aspectratio;";
} else if (array_key_exists('width', $xpars)) {
$astyle = "width:calc($width - 3px);aspect-ratio:$aspectratio;";
$astyle = "width:calc($innerwidth);aspect-ratio:$aspectratio;";
}
}

Expand Down Expand Up @@ -173,7 +195,7 @@ public function compile($format, $options): ? MP_Node {
$code .= 'stackSortable.generate_available();' . "\n";
// Typeset MathJax.
if (count($inputs) > 0) {
$code .= 'MathJax.typesetPromise();' . "\n";
$code .= 'MathJax.Hub.Typeset();' . "\n";
};
// Create the Sortable objects.
$code .= 'var opts = {...stackSortable.options, ...{onSort: () => {stackSortable.update_state(sortableUsed, sortableAvailable);}}}' . "\n";
Expand Down Expand Up @@ -204,7 +226,7 @@ public function validate_extract_attributes(): array {
}

public function validate_JSON_contents($contents) : bool {
//$contents = json_decode($json_contents, true);
// TODO : check steps are reasonable
$val_types = array_unique(array_map('gettype', array_values($contents)));
return array_keys($contents) === ["steps", "options"] || (count($val_types) == 1 && $val_types[0] == "string");
}
Expand Down

0 comments on commit 3db3a02

Please sign in to comment.