diff --git a/compile_server/app/static/editors.js b/compile_server/app/static/editors.js
index 6b4b15f..d2f0b6f 100644
--- a/compile_server/app/static/editors.js
+++ b/compile_server/app/static/editors.js
@@ -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
with an editable representation of an example.
// container: the
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 = $('').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 ) {
diff --git a/compile_server/app/views.py b/compile_server/app/views.py
index 66a48af..c63d1e8 100644
--- a/compile_server/app/views.py
+++ b/compile_server/app/views.py
@@ -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"""
diff --git a/compile_server/urls.py b/compile_server/urls.py
index 65571e8..6efc5b0 100644
--- a/compile_server/urls.py
+++ b/compile_server/urls.py
@@ -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),