Skip to content

Commit

Permalink
Merge pull request #32 from EmpowrOrg/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dri94 authored Sep 16, 2022
2 parents 2b6fe43 + 4a8bafb commit acc88aa
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 53 deletions.
4 changes: 2 additions & 2 deletions swiftplugin/swiftplugin/static/html/swiftplugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1 class="mb-2" id="assignment-title">Title</h1>
aria-labelledby="yoursolution2-tab">
<div class="row code-solution-row">
<textarea id="code-area" rows="25" class="col-sm-12 col-md-6 col-lg-12">Layout 2</textarea>
<div class="col-md-6 instructions-container bg-info">
<div class="col-md-6 instructions-container">
<div class="mt-4">
<h1 class="mb-2">Instructions</h1>
<p id="assigment-instructions-text"></p>
Expand All @@ -34,7 +34,7 @@ <h1 class="mb-2">Instructions</h1>
href="javascript:void(0);">Submit Code
</a>
</div>
<h1 class="mt-2 mb-2">Output</h1>
<h1 id="response-title" class="mt-2 mb-2">Output</h1>
<div class="code-bottom mb-4">
<div id="response-area">
<p class="response-txt" id="response-txt" readonly></p>
Expand Down
106 changes: 63 additions & 43 deletions swiftplugin/swiftplugin/static/js/src/swiftplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,13 @@


function SwiftPluginXBlock(runtime, element) {
function updateResponse(response) {
if (response.response.output) {
const compilation_response = response.response.output
let output_response;
if (response.diff) {
const diff_response = response.diff
output_response = compilation_response + '</br>' + diff_response
} else {
output_response = compilation_response
}
document.getElementById('response-txt').innerHTML = output_response;
} else if (response.response.error) {
document.getElementById('response-txt').innerHTML = response.response.error;
}
}

function handleError(response) {
console.log("error")
console.log(response)
const compilation_response = response.response
const diff_response = response.diff
const output_response = compilation_response + '</br>' + diff_response
document.getElementById('response-txt').innerHTML = output_response;
}

function updateProblemDescription(response) {
const myAssigmentTextArea = document.getElementById("assigment-instructions-text");
const converter = new showdown.Converter();
const html = converter.makeHtml(response.problem_description);
myAssigmentTextArea.innerHTML = html;
}

function updateProblemTitle(response) {
const myAssigmentTextArea = document.getElementById("assignment-title");
const converter = new showdown.Converter();
const html = converter.makeHtml(response.problem_title);
myAssigmentTextArea.innerHTML = html;
}

function updateProblemSolution(response) {
solutionCodeMirror.setValue(response.problem_solution)
}

const handlerUrl = runtime.handlerUrl(element, 'get_button_handler');
const handlerUrlDescription = runtime.handlerUrl(element, 'get_problem_description');
//const handlerUrlSolution = runtime.handlerUrl(element, 'get_problem_solution');
//const handlerUrlHasSolution = runtime.handlerUrl(element, 'has_problem_solution');
const handlerUrlTitle = runtime.handlerUrl(element, 'get_problem_title');
const handlerUrlLanguage = runtime.handlerUrl(element, 'get_problem_language');
const showButtonsUrl = runtime.handlerUrl(element, 'show_buttons');

var myCodeMirror = null;
//var solutionCodeMirror = null;
Expand Down Expand Up @@ -80,6 +38,8 @@ function SwiftPluginXBlock(runtime, element) {

const solution_btn = document.getElementById('btn-solution')

const response_title = document.getElementById('response-title')

function init_description() {
$.ajax({
type: "POST",
Expand Down Expand Up @@ -119,6 +79,23 @@ function SwiftPluginXBlock(runtime, element) {
init_description();
init_title();
init_language();
init_buttons();
}

function init_buttons() {
$.ajax({
type: "POST",
url: showButtonsUrl,
data: JSON.stringify({}),
success: function (data) {
console.log(data)
const is_run_hidden = data.show_run_button === false
const is_submit_hidden = data.show_submit_button === false
run_btn.hidden = is_run_hidden
submit_btn.hidden = is_submit_hidden
response_title.hidden = is_submit_hidden && is_run_hidden
}
});
}

function init_language() {
Expand Down Expand Up @@ -169,6 +146,49 @@ function SwiftPluginXBlock(runtime, element) {
}*/


function updateResponse(response) {
if (response.response.output) {
const compilation_response = response.response.output
let output_response;
if (response.diff) {
const diff_response = response.diff
output_response = compilation_response + '</br>' + diff_response
} else {
output_response = compilation_response
}
document.getElementById('response-txt').innerHTML = output_response;
} else if (response.response.error) {
document.getElementById('response-txt').innerHTML = response.response.error;
}
}

function handleError(response) {
console.log("error")
console.log(response)
const compilation_response = response.response
const diff_response = response.diff
const output_response = compilation_response + '</br>' + diff_response
document.getElementById('response-txt').innerHTML = output_response;
}

function updateProblemDescription(response) {
const myAssigmentTextArea = document.getElementById("assigment-instructions-text");
const converter = new showdown.Converter();
const html = converter.makeHtml(response.problem_description);
myAssigmentTextArea.innerHTML = html;
}

function updateProblemTitle(response) {
const myAssigmentTextArea = document.getElementById("assignment-title");
const converter = new showdown.Converter();
const html = converter.makeHtml(response.problem_title);
myAssigmentTextArea.innerHTML = html;
}

function updateProblemSolution(response) {
solutionCodeMirror.setValue(response.problem_solution)
}

$(function ($) {
/* Here's where you'd do things on page load. */
on_init()
Expand Down
26 changes: 18 additions & 8 deletions swiftplugin/swiftplugin/swiftplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
import json


def get_server_url(url: str):
if url.startswith("http"):
return url
else:
return "https://" + url


class SwiftPluginXBlock(
StudioEditableXBlockMixin,
XBlock):
Expand Down Expand Up @@ -191,18 +198,21 @@ def get_problem_language(self, data, suffix=''):
# 'has_solution_defined': self.problem_solution and self.problem_solution.strip()
# }

@XBlock.json_handler
def show_buttons(self, data, suffix=''):
show_run_button = bool(self.api_url_run and self.api_url_run.isspace())
show_submit_button = bool(self.api_url_submit and self.api_url_submit.isspace())
return {
'show_run_button': show_run_button,
'show_submit_button': show_submit_button,
}

def handle_run_request(self):
r = requests.post(self.get_server_run_url(), json=self.build_request_body())
r = requests.post(get_server_url(self.api_url_run), json=self.build_request_body())
return r.json()

def get_server_run_url(self):
if self.api_url_run.startswith("http"):
return self.api_url_run
else:
return "http://" + self.api_url_run

def handle_submit_request(self):
r = requests.post(self.api_url_submit, json=self.build_request_body())
r = requests.post(get_server_url(self.api_url_submit), json=self.build_request_body())
return r.json()

def build_request_body(self):
Expand Down

0 comments on commit acc88aa

Please sign in to comment.