From 2553de3e2b74919d23f950ed7785bc48b64f231e Mon Sep 17 00:00:00 2001 From: Nicolas Setton Date: Mon, 4 Sep 2017 13:16:18 -0400 Subject: [PATCH 1/5] Goto line 1 in editors after refresh Fixes an issue where the initial content was selected. --- compile_server/app/static/editors.js | 4 +++- design/notes.txt | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compile_server/app/static/editors.js b/compile_server/app/static/editors.js index 2a642e4..dc1e38e 100644 --- a/compile_server/app/static/editors.js +++ b/compile_server/app/static/editors.js @@ -66,7 +66,8 @@ function fill_editor(container, example_name) { editor.session.setMode("ace/mode/ada"); // ... and their contents - editor.insert(resource.contents) + editor.setValue(resource.contents) + editor.gotoLine(1) editor.initial_contents = resource.contents editor.filename = resource.basename @@ -84,6 +85,7 @@ function fill_editor(container, example_name) { reset_button.on('click', function (x){ reset_button.editors.forEach(function (x){ x.setValue(x.initial_contents) + x.gotoLine(1) }) }) diff --git a/design/notes.txt b/design/notes.txt index 9857713..013d756 100644 --- a/design/notes.txt +++ b/design/notes.txt @@ -9,7 +9,6 @@ Notes just for myself Frontend -* fix selection after clicking the "reset" button * nicer display when an example was not found * grab the bits that are currently served by CDNs From f96b572b68c7da63c7a6537bc9c20f671a7783ec Mon Sep 17 00:00:00 2001 From: Nicolas Setton Date: Mon, 4 Sep 2017 13:20:30 -0400 Subject: [PATCH 2/5] Add missing pyyaml requirement --- REQUIREMENTS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/REQUIREMENTS.txt b/REQUIREMENTS.txt index 6e5370e..f5de22c 100644 --- a/REQUIREMENTS.txt +++ b/REQUIREMENTS.txt @@ -1,2 +1,3 @@ django djangorestframework +pyyaml From b011b1252d7b279b5f7d9551d1e8cb7778a9d4aa Mon Sep 17 00:00:00 2001 From: Nicolas Setton Date: Mon, 4 Sep 2017 14:01:38 -0400 Subject: [PATCH 3/5] Add a page which lists all the examples. And slightly improve the decision as to which file(s) to import as an example. --- .../app/management/commands/fill_examples.py | 16 ++++++++++------ compile_server/app/static/editors.js | 1 - compile_server/app/templates/code_page.html | 1 + compile_server/app/templates/examples_list.html | 16 ++++++++++++++++ compile_server/app/views.py | 5 ++++- compile_server/urls.py | 6 +++++- design/notes.txt | 1 - 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 compile_server/app/templates/examples_list.html diff --git a/compile_server/app/management/commands/fill_examples.py b/compile_server/app/management/commands/fill_examples.py index 0cb46fa..4a26c74 100644 --- a/compile_server/app/management/commands/fill_examples.py +++ b/compile_server/app/management/commands/fill_examples.py @@ -7,6 +7,9 @@ from django.core.management.base import BaseCommand from compile_server.app.models import Resource, Example +included_extensions = ['.ads', '.adb'] +# The extensions for the files that we want to show in the examples + class Command(BaseCommand): @@ -26,7 +29,7 @@ class Command(BaseCommand): Example.objects.all().delete() if options.get('dir', None): - d = options.get('dir')[0] + d = os.path.abspath(options.get('dir')[0]) # For now, consider all files in the directory to be part of the # example @@ -56,11 +59,12 @@ class Command(BaseCommand): resources = [] for file in glob.glob(os.path.join(d, '*')): - with open(file, 'rB') as f: - r = Resource(basename=os.path.basename(file), - contents=f.read()) - r.save() - resources.append(r) + if any([file.endswith(ext) for ext in included_extensions]): + with open(file, 'rB') as f: + r = Resource(basename=os.path.basename(file), + contents=f.read()) + r.save() + resources.append(r) e = Example(description=metadata['description'], name=metadata['name']) diff --git a/compile_server/app/static/editors.js b/compile_server/app/static/editors.js index dc1e38e..6b4b15f 100644 --- a/compile_server/app/static/editors.js +++ b/compile_server/app/static/editors.js @@ -92,7 +92,6 @@ function fill_editor(container, example_name) { check_button = $('