From 5a7afb30929410e092d847c487f4ea93e8fdcad4 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 24 Jun 2021 16:38:02 +0530 Subject: [PATCH] fix: added livecode editor in community --- community/hooks.py | 4 + .../exercise_submission.json | 49 +++-- community/plugins.py | 19 ++ .../templates/livecode/extension_footer.html | 168 ++++++++++++++++++ .../templates/livecode/extension_header.html | 8 + community/www/macros/livecode.html | 45 +++-- 6 files changed, 265 insertions(+), 28 deletions(-) create mode 100644 community/templates/livecode/extension_footer.html create mode 100644 community/templates/livecode/extension_header.html diff --git a/community/hooks.py b/community/hooks.py index eca23eac..5666dd53 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -187,6 +187,10 @@ update_website_context = 'community.widgets.update_website_context' ## subclass of community.community.plugins.PageExtension # community_lesson_page_extension = None +community_lesson_page_extensions = [ + "community.plugins.LiveCodeExtension" +] + ## Markdown Macros for Lessons community_markdown_macro_renderers = { "Exercise": "community.plugins.exercise_renderer", diff --git a/community/lms/doctype/exercise_submission/exercise_submission.json b/community/lms/doctype/exercise_submission/exercise_submission.json index bd662b11..125af148 100644 --- a/community/lms/doctype/exercise_submission/exercise_submission.json +++ b/community/lms/doctype/exercise_submission/exercise_submission.json @@ -6,12 +6,17 @@ "engine": "InnoDB", "field_order": [ "exercise", - "solution", + "status", + "batch", + "column_break_4", "exercise_title", "course", - "batch", "lesson", - "image" + "section_break_8", + "solution", + "image", + "test_results", + "comments" ], "fields": [ { @@ -21,12 +26,6 @@ "label": "Exercise", "options": "Exercise" }, - { - "fieldname": "solution", - "fieldtype": "Code", - "in_list_view": 1, - "label": "Solution" - }, { "fetch_from": "exercise.title", "fieldname": "exercise_title", @@ -61,11 +60,41 @@ "fieldtype": "Code", "label": "Image", "read_only": 1 + }, + { + "fieldname": "status", + "fieldtype": "Select", + "label": "Status", + "options": "Correct\nIncorrect" + }, + { + "fieldname": "test_results", + "fieldtype": "Small Text", + "label": "Test Results" + }, + { + "fieldname": "comments", + "fieldtype": "Small Text", + "label": "Comments" + }, + { + "fieldname": "solution", + "fieldtype": "Code", + "in_list_view": 1, + "label": "Solution" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_8", + "fieldtype": "Section Break" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-05-21 11:28:45.833018", + "modified": "2021-06-24 16:22:50.570845", "modified_by": "Administrator", "module": "LMS", "name": "Exercise Submission", diff --git a/community/plugins.py b/community/plugins.py index 76cfd4d0..eb9b74fc 100644 --- a/community/plugins.py +++ b/community/plugins.py @@ -67,6 +67,25 @@ class ProfileTab: """ raise NotImplementedError() +class LiveCodeExtension(PageExtension): + def render_header(self): + livecode_url = frappe.get_value("LMS Settings", None, "livecode_url") + context = { + "livecode_url": livecode_url + } + return frappe.render_template( + "templates/livecode/extension_header.html", + context) + + def render_footer(self): + livecode_url = frappe.get_value("LMS Settings", None, "livecode_url") + context = { + "livecode_url": livecode_url + } + return frappe.render_template( + "templates/livecode/extension_footer.html", + context) + def quiz_renderer(quiz_name): quiz = frappe.get_doc("LMS Quiz", quiz_name) context = dict(quiz=quiz) diff --git a/community/templates/livecode/extension_footer.html b/community/templates/livecode/extension_footer.html new file mode 100644 index 00000000..7079acb2 --- /dev/null +++ b/community/templates/livecode/extension_footer.html @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + diff --git a/community/templates/livecode/extension_header.html b/community/templates/livecode/extension_header.html new file mode 100644 index 00000000..1499d750 --- /dev/null +++ b/community/templates/livecode/extension_header.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/community/www/macros/livecode.html b/community/www/macros/livecode.html index a4ec142f..fdd67b4f 100644 --- a/community/www/macros/livecode.html +++ b/community/www/macros/livecode.html @@ -1,4 +1,3 @@ - {% macro LiveCodeEditorLarge(name, code) %}
@@ -16,8 +15,8 @@
- -

+        
+        

       
@@ -31,11 +30,20 @@
+ + {% if is_exercise %} - - {% if last_submitted %} - - {% endif %} + + {% if last_submitted %} + + {% endif %} {% endif %}
@@ -51,8 +59,8 @@
- -

+        
+        

       
@@ -64,14 +72,15 @@ {% macro LiveCodeEditorJS(name, code) %} - + @@ -81,7 +90,7 @@ if (!frappe.sys_defaults) { var livecodeEditors = []; var livecodeEditorsMap = {}; - $(function() { + $(function () { $(".livecode-editor").each((i, e) => { var name = e.id.replace("editor-", ""); var editor = new LiveCodeEditor(e, { @@ -91,12 +100,12 @@ if (!frappe.sys_defaults) { livecodeEditors.push(editor); livecodeEditorsMap[e.id] = editor; - $(e).find(".reset").on('click', function() { + $(e).find(".reset").on('click', function () { let code = $(e).find(".reset-code").html(); editor.codemirror.doc.setValue(code); }); - $(e).find(".submit").on('click', function() { + $(e).find(".submit").on('click', function () { let code = editor.codemirror.doc.getValue(); console.log("submit", name, code); frappe.call("community.lms.api.submit_solution", { @@ -116,7 +125,7 @@ if (!frappe.sys_defaults) { }); function updateSubmitTimes() { - $(".human-time").each(function(i, e) { + $(".human-time").each(function (i, e) { var d = $(e).data().timestamp; $(e).html(__("Submitted {0}", [comment_when(d)])); });