Difference between revisions of "Widget:CodeExplorer"

From Coder Merlin
Line 242: Line 242:
                                 $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").
                                 $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").
                                     append(markupRuntimeStandardOutput(consoleToHTML(executionOutput)));
                                     append(markupRuntimeStandardOutput(consoleToHTML(executionOutput)));
                                break;
                            case "submit":
                                let standardOutput = (typeof responseObject == "object") ? responseObject.standardOutput : "";
                                let standardError = (typeof responseObject == "object" && typeof responseObject.standardError == "string") ? "error: " + responseObject.standardError : "";
                                if (typeof responseObject == "object" && responseObject.timedOut) {
                                    standardError += "error: timed out\n";
                                }
                                $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").append(consoleToHTML(standardOutput));
                                $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").
                                    append(markupWarningsAndErrorsHTML(consoleToHTML(standardError)));


                                 // Set compilation display
                                 // Set compilation display
                                 const $button = $("#codeEditorForm<!--{$exerciseID|validate:int}--> .merlin-code-explorer-show-compilation-button");
                                 const $button = $("#codeEditorForm<!--{$exerciseID|validate:int}--> .merlin-code-explorer-show-compilation-button");
                                 const $output = $button.parent().siblings(".merlin-code-explorer-combined-output:first");
                                 const $output = $button.parent().siblings(".merlin-code-explorer-combined-output:first");
                                console.log(compilationStatus);
                                 if (compilationStatus.terminationStatus == 0) {
                                 if (compilationStatus.terminationStatus == 0) {
                                     $output.slideUp();
                                     $output.slideUp();
Line 265: Line 254:
                                 }
                                 }


                                break;
                            case "submit":
                                let standardOutput = (typeof responseObject == "object") ? responseObject.standardOutput : "";
                                let standardError = (typeof responseObject == "object" && typeof responseObject.standardError == "string") ? "error: " + responseObject.standardError : "";
                                if (typeof responseObject == "object" && responseObject.timedOut) {
                                    standardError += "error: timed out\n";
                                }
                                $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").append(consoleToHTML(standardOutput));
                                $("#codeEditorExecutionOutput<!--{$exerciseID|validate:int}-->").
                                    append(markupWarningsAndErrorsHTML(consoleToHTML(standardError)));
                                 break;
                                 break;
                         }
                         }

Revision as of 23:24, 29 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
language
string: language for compiling and 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
|language=swift
|initialCode=func sayHello() {
    print("Hello, World!")
}
}}