Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for tasks in courses #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mon_school/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"Image": "mon_school.mon_school.plugins.image_renderer",
"YouTubeVideo": "mon_school.mon_school.plugins.youtube_video_renderer",
"Widget": "mon_school.mon_school.plugins.widget_renderer",
"Task": "mon_school.mon_school.plugins.task_renderer",
}

# Install custom page renderers
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions mon_school/mon_school/doctype/course_task/course_task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2022, FOSS United and contributors
// For license information, please see license.txt

frappe.ui.form.on('Course Task', {
// refresh: function(frm) {

// }
});
113 changes: 113 additions & 0 deletions mon_school/mon_school/doctype/course_task/course_task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "format:{slug} ({course})",
"creation": "2022-01-25 11:37:35.969330",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"slug",
"title",
"course",
"column_break_4",
"description",
"section_break_6",
"inputs",
"button_label",
"section_break_10",
"javascript",
"column_break_12",
"test"
],
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"in_list_view": 1,
"in_preview": 1,
"label": "Title"
},
{
"fieldname": "course",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Course",
"options": "LMS Course"
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"label": "Description"
},
{
"default": "Verify",
"fieldname": "button_label",
"fieldtype": "Data",
"label": "Button Label"
},
{
"fieldname": "inputs",
"fieldtype": "Table",
"label": "Inputs",
"options": "Course Task Input"
},
{
"fieldname": "slug",
"fieldtype": "Data",
"label": "Slug"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_6",
"fieldtype": "Section Break"
},
{
"fieldname": "section_break_10",
"fieldtype": "Section Break"
},
{
"fieldname": "javascript",
"fieldtype": "Code",
"label": "Javascript"
},
{
"fieldname": "test",
"fieldtype": "Code",
"label": "Test"
},
{
"fieldname": "column_break_12",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-01-25 12:41:32.778631",
"modified_by": "Administrator",
"module": "Mon School",
"name": "Course Task",
"naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
8 changes: 8 additions & 0 deletions mon_school/mon_school/doctype/course_task/course_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, FOSS United and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document

class CourseTask(Document):
pass
8 changes: 8 additions & 0 deletions mon_school/mon_school/doctype/course_task/test_course_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, FOSS United and Contributors
# See license.txt

# import frappe
import unittest

class TestCourseTask(unittest.TestCase):
pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-01-25 11:42:57.632621",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"id",
"type",
"label"
],
"fields": [
{
"fieldname": "id",
"fieldtype": "Data",
"label": "ID"
},
{
"fieldname": "type",
"fieldtype": "Select",
"label": "Type",
"options": "Data"
},
{
"fieldname": "label",
"fieldtype": "Data",
"label": "Label"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-25 12:23:12.374844",
"modified_by": "Administrator",
"module": "Mon School",
"name": "Course Task Input",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, FOSS United and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document

class CourseTaskInput(Document):
pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2022, FOSS United and contributors
// For license information, please see license.txt

frappe.ui.form.on('Course Task Response', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-01-25 11:45:01.855293",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"task",
"user",
"status",
"message",
"response"
],
"fields": [
{
"fieldname": "task",
"fieldtype": "Link",
"label": "Task",
"options": "Course Task"
},
{
"fieldname": "user",
"fieldtype": "Link",
"label": "User",
"options": "User"
},
{
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Success\nFailed"
},
{
"fieldname": "message",
"fieldtype": "Data",
"label": "Message"
},
{
"fieldname": "response",
"fieldtype": "Code",
"label": "Response"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-01-25 11:51:58.485145",
"modified_by": "Administrator",
"module": "Mon School",
"name": "Course Task Response",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, FOSS United and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document

class CourseTaskResponse(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, FOSS United and Contributors
# See license.txt

# import frappe
import unittest

class TestCourseTaskResponse(unittest.TestCase):
pass
9 changes: 9 additions & 0 deletions mon_school/mon_school/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ def widget_renderer(widget_id):
t = html.escape(json.dumps(doc.template))
return f"<div class='widget' data-template='{t}'></div>"


def task_renderer(argument):
"""Renders a task.
"""
task = frappe.get_doc("Course Task", argument)
user = frappe.get_cached_doc("User", frappe.session.user)
context = dict(task=task, user=user)
return frappe.render_template("templates/task.html", context)

4 changes: 4 additions & 0 deletions mon_school/templates/livecode/extension_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
$(e).html(t);
});
});

$(function() {
monschool.run_load_hooks();
});
</script>

<style type="text/css">
Expand Down
25 changes: 25 additions & 0 deletions mon_school/templates/livecode/extension_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,28 @@
<script src="/assets/mon_school/codemirror/addon/edit/matchbrackets.js"></script>
<script src="/assets/mon_school/codemirror/addon/comment/comment.js"></script>

<script type="text/javascript">
// Hack to specify load hooks to be executed on page load.
// Traditionally, this is done using jquery as $(function() {...}).
// Since jquery is only included at the and of the page, it is not possible
// to include snippets to run on load in the middle of the page, which is usually
// the case when we are embedding custom scripts for tasks or exercises.
// This stores all the load hooks and executes all of them when run_load_hooks is
// called from them footer.
//
// USAGE:
// monschool.onload(function() {
// console.log("hello, world!");
// })
var monschool = {
load_hooks: [],
onload: function(fn) {
this.load_hooks.push(fn);
},
run_load_hooks: function() {
for (var i=0; i<this.load_hooks.length; i++) {
this.load_hooks[i]();
}
}
}
</script>
25 changes: 25 additions & 0 deletions mon_school/templates/task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="card">
<div class="task card-body">
<h3 class="task-title card-title">Task: {{task.title}} <span class="task-status"></span></h3>

<div class="task-description">{{task.description}}</div>

<form class="task-form" style="margin-top: 1em;">
{% for input in task.inputs %}
<div class="form-group">
<label for="task-{{task.slug}}-{{input.id}}">{{input.label}}</label>
<input type="text" id="task-{{task.slug}}-{{input.id}}" class="form-control" />
</div>
{% endfor %}

<div class="task-controls">
<button type="button" class="btn btn-secondary">{{task.button_label}}</button>
</div>
</form>
</div>
{% if task.javascript %}
<script type="text/javascript">
{{ task.javascript }}
</script>
{% endif %}
</div>