(WIP) work on checker

This commit is contained in:
Nicolas Setton
2017-09-04 20:16:02 -04:00
parent b011b1252d
commit 54a1ce7b4f
3 changed files with 36 additions and 12 deletions

View File

@@ -1,3 +1,35 @@
function query_check_result(editors, container) {
files = []
editors.forEach(function(e){
files.push({'basename': e.basename,
'contents': e.getValue()})
})
data = {"files": files}
// request the examples
$.ajax({
url: "/check_program/",
data: JSON.stringify(data),
type: "POST",
dataType : "json",
contentType: 'application/json; charset=UTF-8',
})
.done(function( json ) {
alert(json)
})
.fail(function( xhr, status, errorThrown ) {
//
alert( "could not run the example" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
})
}
// Fills a <div> with an editable representation of an example.
// container: the <div> in question
// example_name: the name of the example to load
@@ -69,7 +101,7 @@ function fill_editor(container, example_name) {
editor.setValue(resource.contents)
editor.gotoLine(1)
editor.initial_contents = resource.contents
editor.filename = resource.basename
editor.basename = resource.basename
// TODO: place the cursor at 1,1
@@ -92,6 +124,7 @@ function fill_editor(container, example_name) {
check_button = $('<button type="button" class="btn btn-primary">').text("Check").appendTo(toolbar)
check_button.editors = editors
check_button.on('click', function (x){
query_check_result(check_button.editors, container)
})
})
.fail(function( xhr, status, errorThrown ) {

View File

@@ -40,15 +40,6 @@ class ResourceSet(viewsets.ModelViewSet):
serializer_class = ResourceSerializer
@api_view(['POST'])
def check_program(request):
received_json = json.loads(request.body)
p = Program(code=received_json['program'])
serializer = ProgramSerializer(p)
return Response(serializer.data)
@api_view(['GET'])
def examples(request):
"""Return a list of example names and their description"""

View File

@@ -18,7 +18,7 @@ from django.contrib import admin
from rest_framework import routers
from compile_server.app import views
from compile_server.app import views, checker
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
@@ -30,7 +30,7 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
# Check one program
url(r'^check_program/', views.check_program),
url(r'^check_program/', checker.check_program),
# Get a list of the examples
url(r'^examples/', views.examples),