Difference between revisions of "Widget:CodeExplorer"

From Coder Merlin
Tag: Reverted
Tag: Reverted
Line 177: Line 177:
                     let requestString = JSON.stringify(requestObject);
                     let requestString = JSON.stringify(requestObject);


                     let response = $.ajax({
                     let response;
                        type: "POST",
                    function issueRequest() {
                        url,  
                        response = $.ajax({
                        headers: {
                            type: "POST",
                            "username": username,
                            url,  
                            "sessionID": sessionID
                            headers: {
                        },
                                "username": username,
                        data: requestString,
                                "sessionID": sessionID
                        dataType: "json",
                            },
                        contentType : "application/json",
                            data: requestString,
                        timeout: 30000,
                            dataType: "json",
                        error: function(jqXHR, textStatus, errorThrown) {
                            contentType : "application/json",
                            // Display error
                            timeout: 30000,
                            $("#codeEditorCompilerOutput<!--{$exerciseID|validate:int}-->").append("<span class='merlin-code-explorer-combined-output-error'>" +  
                            error: function(jqXHR, textStatus, errorThrown) {
                                "Internal error: " + textStatus + "<br/>" + errorThrown + "<br/>" +  
                                // Display error
                                "</span><br/>");
                                $("#codeEditorCompilerOutput<!--{$exerciseID|validate:int}-->").append("<span class='merlin-code-explorer-combined-output-error'>" +  
                                    "Internal error: " + textStatus + "<br/>" + errorThrown + "<br/>" +  
                                    "</span><br/>");


                            // Re-enable buttons
                                // Re-enable buttons
                            executeButton.attr("disabled", false);
                                executeButton.attr("disabled", false);
                            executeButton.css("background-color", executeButtonBackgroundColor);
                                executeButton.css("background-color", executeButtonBackgroundColor);
                            if (isSubmitEnabled) {
                                if (isSubmitEnabled) {
                                submitButton.attr("disabled", false);
                                    submitButton.attr("disabled", false);
                                submitButton.css("background-color", submitButtonBackgroundColor);
                                    submitButton.css("background-color", submitButtonBackgroundColor);
                            }     
                                }     


                            // Disable animation
                                // Disable animation
                            controlPanel.className = "merlin-code-explorer-control-panel";
                                controlPanel.className = "merlin-code-explorer-control-panel";
                         }
                            }
                    });
                         });
                    }
                    issueRequest();


                     console.log(response);
                     console.log(response);

Revision as of 08:34, 11 January 2023

Parameters:

userName
string: The current user's username
sessionID
string: The ID of the current user's session
experienceID
string: The experienceID of the page from which the widget is invoked
codeExplorerGroupID
string: The code explorer group. If empty, the submit button will be disabled.
exerciseID
integer: exercise id for editor, must be unique per page
width
integer|string: percentage (as string, e.g. "100%" or integer size in pixels), null for no change (full width)
height
integer|string: percentage (as string, e.g. "100%" or integer size in pixels), null for no change (~10 lines)
lineNumbers
boolean: true to display line numbers
theme
string: name of theme (which must be loaded via css)
readOnly
boolean: true if editing should be disabled
mode
string: language for highlighting (which must be loaded via js)
initialCode
string: initial code to place in editor

Example:

{{#widget:CodeExplorer
|userName=john-williams
|sessionID=qh0ubrrme911kcg7db0i0ec6lct94h7f
|experienceID=W1020.23
|codeExplorerGroupID=WTRS-8527
|exerciseID=10
|width=null
|height=null
|lineNumbers=true
|theme=vibrant-ink
|readOnly=false
|mode=swift
|initialCode=func sayHello() {
    print("Hello, World!")
}
}}