fix: added livecode editor in community

This commit is contained in:
pateljannat
2021-06-24 16:38:02 +05:30
parent 56d8a72a7d
commit 5a7afb3092
6 changed files with 265 additions and 28 deletions

View File

@@ -1,4 +1,3 @@
{% macro LiveCodeEditorLarge(name, code) %}
<div class="livecode-editor livecode-editor-large" id="editor-{{name}}">
<div class="row">
@@ -16,8 +15,8 @@
</div>
</div>
<div class="col-lg-4 col-md-6 canvas-wrapper">
<canvas width="300" height="300"></canvas>
<pre class="output"></pre>
<canvas width="300" height="300"></canvas>
<pre class="output"></pre>
</div>
</div>
</div>
@@ -31,11 +30,20 @@
<div class="controls">
<button class="run">Run</button>
<button class="reset">Reset</button>
<a class="pull-right dropdown-item border rounded" style="width: 10rem;" href="#" id="navbarDropdown"
role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<span class="dropdown-item">Correct</span>
<span class="dropdown-item">Incorrect</span>
</div>
{% if is_exercise %}
<button class="submit pull-right btn-primary">Submit</button>
{% if last_submitted %}
<span class="pull-right" style="padding-right: 10px;"><span class="human-time" data-timestamp="{{last_submitted}}"></span></span>
{% endif %}
<button class="submit pull-right btn-primary">Submit</button>
{% if last_submitted %}
<span class="pull-right" style="padding-right: 10px;"><span class="human-time"
data-timestamp="{{last_submitted}}"></span></span>
{% endif %}
{% endif %}
</div>
<div style="display: none">
@@ -51,8 +59,8 @@
</div>
</div>
<div class="col-lg-4 col-md-6 canvas-wrapper">
<canvas width="300" height="300"></canvas>
<pre class="output"></pre>
<canvas width="300" height="300"></canvas>
<pre class="output"></pre>
</div>
</div>
</div>
@@ -64,14 +72,15 @@
{% macro LiveCodeEditorJS(name, code) %}
<script type="text/javascript" src="/assets/frappe/node_modules/moment/min/moment-with-locales.min.js"></script>
<script type="text/javascript" src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
<script type="text/javascript"
src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
<script type="text/javascript" src="/assets/frappe/js/frappe/utils/datetime.js"></script>
<script type="text/javascript">
// comment_when is failing because of this
if (!frappe.sys_defaults) {
frappe.sys_defaults = {}
}
// comment_when is failing because of this
if (!frappe.sys_defaults) {
frappe.sys_defaults = {}
}
</script>
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
@@ -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)]));
});