new UI javascript file not picked up

new UI javascript file not picked up

de către René van Paassen-
Număr de răspunsuri: 3

Hello, 

I am trying to add a specific ui file. I created ui_practicon.js in amd/src, and added (as far as I can tell) a complete implementation of the interface, following the examples from the other ui_* files. For good measure, I also created min.js and min.js.map files, with uglifyjs in amd/build.

This seems to get picked up in the question editing form, and I can select the ui. 

However, on a question preview I get 

require.min.js:5 Uncaught Error: No define call for qtype_coderunner/ui_practicon
http://requirejs.org/docs/errors.html#nodefine
    at makeError (require.min.js:5)
    at Object.completeLoad (require.min.js:5)
    at HTMLScriptElement.onScriptLoad (require.min.js:5)

in the Javascript console. I have not yet been able to figure out where the javascript files are supposed to be loaded, and what I am doing wrong. Would appreciate some pointers. 

Ca răspuns la René van Paassen

Re: new UI javascript file not picked up

de către Richard Lobb-

Wow, you're a brave man.

Your source is in the right place (amd/src). I don't think you actually need the amd/build stuff as Moodle likes to do its own minimisation (alas).

The UI module (ui_praticon.js) should be of the form

define([dependencies], function(local_dependency_names) {
    function UIClassName(textareaId, width, height, templateParmas) {
        // ... constructor code
    }

    UIClassName.prototype.whateveryouwant = function() {...}

    // ... other methods

    return { Constructor: UIClassName };
});

The error message suggests that you haven't wrapped your code in a define. If that's not the problem, post your module here and I'll have a look at it.

Ca răspuns la Richard Lobb

Re: new UI javascript file not picked up

de către René van Paassen-

I found my fault; needed to clear the Moodle cache to make sure the JavaScript files are re-generated. 

Ca răspuns la René van Paassen

Re: new UI javascript file not picked up - control theory questions

de către René van Paassen-

I found out how to run this. Moodle is apparently transitioning to amd javascript, and in Moodle 3.8 all javascript is collected into one file and cached.

For Moodle 3.8 development, javascript caching has to be disabled, in config.php:

$CFG->cachejs = false;

After editing a javascript file, the compiled files have to be re-generated by running grunt.

I now have a modified coderunner version, with basically a confirmation feedback (in html) after check mode, right below the question. I modified renderer.php and allowed another output variable in combinator_grader_outcome.php

I added a user interface type called ui_practicon.js . In there I also triggered a MathJax re-run, in case MathJax is loaded (which apparently only happens when there is a formula in the main equation text), so that any equations near the question answer fields are rendered. It might be good to copy this to the ui_html.js template too. User interface fields are defined by JSON in the extra fields of the checks, I added these to the attributes of the main textarea.

Modified coderunner is on my github page at https://github.com/repagh/moodle-qtype_coderunner

Support for analysing and grading control theory answers (transfer function, state-space, matrix) and simple numerical and true-false answers as well, is on a separate repository: https://github.com/repagh/practicon. That code needs to run on the jobe backend, and needs python-control and slycot as well (to be found on github too!). I found I needed to increase memory for the jobe job, or run into mysterious error messages. 

The practicon repository contains two coderunner question templates. One for students leaving their answers right in Python3, as python variables (floats, transfer functions, state-space systems, etc.). 

The second question template uses the new ui_practicon.js, which can give the students answer fields to leave (paste) their results. The idea is that students use Matlab or Python + control module on their own computer to create their control theory answers. The parser accepts both Matlab-type and Python (list of list) type array/matrix input. 

I created this as future replacement for an older self-built solution we used here at TU Delft, and I hope it may be of interest to others too.