Added sketch pages.

This commit is contained in:
Anand Chitipothu
2021-03-09 12:36:55 +00:00
parent ff15e7058b
commit deea539c7d
6 changed files with 136 additions and 0 deletions

View File

@@ -54,4 +54,11 @@
border: 1px solid #ddd;
}
.sketch-header h1 {
font-size: 1.5em;
margin-bottom: 0px;
}
.sketch-header {
margin-bottom: 1em;
}

View File

@@ -20,3 +20,19 @@
</div>
</div>
{% endmacro %}
{% macro LiveCodeEditorJS(name, code) %}
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
<script type="text/javascript">
$(function() {
$(".canvas-editor").each((i, e) => {
var editor = new LiveCodeEditor(e, {
runtime: "python-canvas",
base_url: "{{ livecode_url }}",
codemirror: true
})
})
})
</script>
{% endmacro %}

View File

@@ -0,0 +1,26 @@
{% extends "templates/base.html" %}
{% from "www/macros/livecode.html" import LiveCodeEditor, LiveCodeEditorJS %}
{% block title %}Sketches{% endblock %}
{% block head_include %}
<meta name="description" content="Sketches" />
<meta name="keywords" content="sketches" />
<link rel="stylesheet" href="/assets/css/lms.css">
{% endblock %}
{% block content %}
<section class="top-section" style="padding: 1rem 0rem;">
<div class='container pb-5'>
<h1>Recent Sketches</h1>
</div>
<div class='container'>
{% for sketch in sketches %}
<div class="sketch-preview mb-5">
<span class="sketch-ts">{{ sketch.modified }}</span>
<a href="/sketches/sketch?sketch={{sketch.name}}">{{sketch.title}}</a>
By {{sketch.owner}}
</div>
{% endfor %}
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,16 @@
import frappe
def get_context(context):
context.no_cache = 1
context.sketches = get_sketches()
def get_sketches():
sketches = frappe.get_all(
"LMS Sketch",
fields=['name', 'title', 'owner', 'modified'],
order_by='modified desc',
page_length=100
)
for s in sketches:
s['owner'] = s['owner'].split("@")[0]
return sketches

View File

@@ -0,0 +1,44 @@
{% extends "templates/base.html" %}
{% from "www/macros/livecode.html" import LiveCodeEditor, LiveCodeEditorJS with context %}
{% block title %}{{sketch.title}}{% endblock %}
{% block head_include %}
<meta name="description" content="Sketch {{sketch.title}}" />
<meta name="keywords" content="sketch {{sketch.title}}" />
<style>
</style>
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="/assets/css/lms.css">
<script src="{{ livecode_url }}/static/codemirror/lib/codemirror.js"></script>
<script src="{{ livecode_url }}/static/codemirror/mode/python/python.js"></script>
<script src="{{ livecode_url }}/static/codemirror/keymap/sublime.js"></script>
<script src="{{ livecode_url }}/static/codemirror/addon/edit/matchbrackets.js"></script>
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
{% endblock %}
{% block content %}
<section class="top-section" style="padding: 1rem 0rem;">
<div class='container pb-5'>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item" aria-current="page"><a href="/sketches">Sketches</a></li>
</ol>
</nav>
<div class="sketch-header">
<h1 class="sketch-title">{{ sketch.title }}</h1>
<div class="sketch-owner-wrapper">By <span class="sketch-owner">{{sketch.owner}}</span></div>
</div>
{{LiveCodeEditor(sketch.name, sketch.code) }}
</section>
{% endblock %}
{%- block script %}
{{ super() }}
{{ LiveCodeEditorJS() }}
{%- endblock %}

View File

@@ -0,0 +1,27 @@
import frappe
def get_context(context):
context.no_cache = 1
course_name = get_queryparam("sketch", '/sketches')
context.sketch = get_sketch(course_name)
context.livecode_url = get_livecode_url()
def get_livecode_url():
doc = frappe.get_doc("LMS Settings")
return doc.livecode_url
def get_queryparam(name, redirect_when_not_found):
try:
return frappe.form_dict[name]
except KeyError:
frappe.local.flags.redirect_location = redirect_when_not_found
raise frappe.Redirect
def get_sketch(name):
try:
sketch = frappe.get_doc('LMS Sketch', name)
except frappe.exceptions.DoesNotExistError:
raise frappe.NotFound
sketch.owner = sketch.owner.split("@")[0]
return sketch