From d8b0fa44979ebb04913b72a839613c850f42c349 Mon Sep 17 00:00:00 2001 From: smmercuri Date: Thu, 26 Oct 2023 12:42:28 +0100 Subject: [PATCH] parsons block wo input --- amd/src/parsons.js | 41 ---------------- stack/cas/castext2/blocks/parsons.block.php | 52 +++++---------------- 2 files changed, 11 insertions(+), 82 deletions(-) delete mode 100644 amd/src/parsons.js diff --git a/amd/src/parsons.js b/amd/src/parsons.js deleted file mode 100644 index 8d8ed81a1ae..00000000000 --- a/amd/src/parsons.js +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - -/** - * A javascript module to handle the real-time validation of the input the student types - * into STACK questions. - * - * The overall way this works is as follows: - * - * - right at the end of this file are the init methods, which set things up. - * - The work common to all input types is done by StackInput. - * - Sending the Ajax request. - * - Updating the validation display. - * - The work specific to different input types (getting the content of the inputs) is done by - * the classes like - * - StackSimpleInput - * - StackTextareaInput - * - StackMatrixInput - * objects of these types need to implement the two methods addEventHandlers and getValue(). - * - * @module qtype_stack/input - * @copyright 2018 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -function helloWorld() { - print("Hello, world"); -} \ No newline at end of file diff --git a/stack/cas/castext2/blocks/parsons.block.php b/stack/cas/castext2/blocks/parsons.block.php index da674b1ae8c..123245a5902 100644 --- a/stack/cas/castext2/blocks/parsons.block.php +++ b/stack/cas/castext2/blocks/parsons.block.php @@ -164,6 +164,7 @@ public function compile($format, $options): ? MP_Node { // For binding we need to import the binding libraries. $r->items[] = new MP_String("\nimport {stack_js} from '" . stack_cors_link('stackjsiframe.min.js') . "';\n"); $r->items[] = new MP_String("import {Sortable} from '" . stack_cors_link('sortable.min.js') . "';\n"); + $r->items[] = new MP_String("import {stack_sortable} from '" . stack_cors_link('stacksortable.js') . "';\n"); // TODO : this should be the sortablejs "binding" library. // TODO : note that this sortablejs "binding" library will likely be much simpler, it may just require supplementing sortablejs with the refresh code // in Sam's code @@ -202,32 +203,14 @@ public function compile($format, $options): ? MP_Node { } //$r->items[] = new MP_String(';' . "\n"); - + // TOOD : abstract some of these as functions to stacksortable.js $r->items[] = new MP_String('var state;' . "\n"); $r->items[] = new MP_String('state = {used: [], available: []};' . "\n"); $r->items[] = new MP_String('state.available = [...Object.keys(proofSteps)];' . "\n"); - $r->items[] = new MP_String('let usedList = document.getElementById("usedList");' . "\n"); - $r->items[] = new MP_String('for (const key in state.used) {' . "\n"); - $r->items[] = new MP_String('let li = document.createElement("li");' . "\n"); - $r->items[] = new MP_String('li.innerText = proofSteps[state.used[key]];' . "\n"); - $r->items[] = new MP_String('li.setAttribute("data-id",key);' . "\n"); - $r->items[] = new MP_String('li.className = "list-group-item";' . "\n"); - $r->items[] = new MP_String('usedList.appendChild(li);' . "\n"); - $r->items[] = new MP_String('};' . "\n"); - $r->items[] = new MP_String('let existsAvailable = (typeof state.available === "object");' . "\n"); - $r->items[] = new MP_String('let availableList = document.getElementById("availableList");' . "\n"); - $r->items[] = new MP_String('if (existsAvailable) {' . "\n"); - $r->items[] = new MP_String('for (const key in state.available) {' . "\n"); - $r->items[] = new MP_String('let li = document.createElement("li");' . "\n"); - $r->items[] = new MP_String('li.innerText = proofSteps[state.available[key]];' . "\n"); - $r->items[] = new MP_String('li.setAttribute("data-id",key);' . "\n"); - $r->items[] = new MP_String('li.className = "list-group-item";' . "\n"); - $r->items[] = new MP_String('availableList.appendChild(li);' . "\n"); - $r->items[] = new MP_String('};' . "\n"); - $r->items[] = new MP_String('}' . "\n"); - - $r->items[] = new MP_String('MathJax.typesetPromise();'); + $r->items[] = new MP_String('stack_sortable.generate_available(proofSteps, state, "availableList");' . "\n"); + + $r->items[] = new MP_String('MathJax.typesetPromise();' . "\n"); $r->items[] = new MP_String('function updateState(newUsed, newAvailable, log_new_state = false) {' . "\n"); $r->items[] = new MP_String('const newState = {used: [], available: []};' . "\n"); $r->items[] = new MP_String('newState.used = newUsed.toArray();' . "\n"); @@ -235,25 +218,12 @@ public function compile($format, $options): ? MP_Node { $r->items[] = new MP_String('state = newState;' . "\n"); $r->items[] = new MP_String('};' . "\n"); - $r->items[] = new MP_String('var sortableUsed = Sortable.create(usedList, {' . "\n"); - $r->items[] = new MP_String('animation: 50,' . "\n"); - $r->items[] = new MP_String('ghostClass: "list-group-item-info",' . "\n"); - $r->items[] = new MP_String('group: "shared", ' . "\n"); - $r->items[] = new MP_String('onSort: (evt) => {' . "\n"); - $r->items[] = new MP_String('updateState(sortableUsed, sortableAvailable, true);' . "\n"); - $r->items[] = new MP_String('},' . "\n"); - $r->items[] = new MP_String('});' . "\n"); - $r->items[] = new MP_String('var sortableAvailable = Sortable.create(availableList, {' . "\n"); - $r->items[] = new MP_String('animation: 50,' . "\n"); - $r->items[] = new MP_String('ghostClass: "list-group-item-info",' . "\n"); - $r->items[] = new MP_String('group: "shared",' . "\n"); - $r->items[] = new MP_String('onSort: (evt) => {' . "\n"); - $r->items[] = new MP_String('updateState(sortableUsed, sortableAvailable, false);' . "\n"); - $r->items[] = new MP_String('},' . "\n"); - $r->items[] = new MP_String('});' . "\n"); - // TODO : edon't need divid? - // Plug in the div id = board id thing. - //$r->items[] = new MP_String('var divid = "parsons"; var BOARDID = divid;'); + //r->items[] = new MP_String('stack_sortable.create(document.getElementById("usedList"), document.getElementById("availableList"));' . "\n"); + $r->items[] = new MP_String('var opt3 = {ghostClass: "list-group-item-info", group: "shared", onSort: (evt) => {updateState(sortableUsed,sortableAvailable);}}' . "\n"); + + $r->items[] = new MP_String('var sortableUsed = Sortable.create(usedList, opt3);' . "\n"); + $r->items[] = new MP_String('var sortableAvailable = Sortable.create(availableList, opt3);' . "\n"); + if (count($inputs) > 0) {