You've already forked code_examples_server
mirror of
https://github.com/AdaCore/code_examples_server.git
synced 2026-02-12 12:45:18 -08:00
(WIP) work on checker
This commit is contained in:
@@ -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 ) {
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user