Merge pull request #497 from pateljannat/text-editor

feat: Text editor for course description and Lesson Content
This commit is contained in:
Jannat Patel
2023-04-07 21:25:03 +05:30
committed by GitHub
12 changed files with 50 additions and 28 deletions

View File

@@ -66,7 +66,7 @@
}, },
{ {
"fieldname": "body", "fieldname": "body",
"fieldtype": "Markdown Editor", "fieldtype": "Text Editor",
"ignore_xss_filter": 1, "ignore_xss_filter": 1,
"label": "Body", "label": "Body",
"reqd": 1 "reqd": 1
@@ -135,7 +135,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2022-12-28 16:01:42.191123", "modified": "2023-04-05 12:42:16.926753",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Course Lesson", "name": "Course Lesson",

View File

@@ -53,7 +53,7 @@ class CourseLesson(Document):
ex.course = None ex.course = None
ex.index_ = 0 ex.index_ = 0
ex.index_label = "" ex.index_label = ""
ex.save() ex.save(ignore_permissions=True)
def check_and_create_folder(self): def check_and_create_folder(self):
args = { args = {

View File

@@ -57,7 +57,7 @@
}, },
{ {
"fieldname": "description", "fieldname": "description",
"fieldtype": "Markdown Editor", "fieldtype": "Text Editor",
"label": "Description", "label": "Description",
"reqd": 1 "reqd": 1
}, },
@@ -260,7 +260,7 @@
} }
], ],
"make_attachments_public": 1, "make_attachments_public": 1,
"modified": "2023-02-23 09:45:54.826327", "modified": "2023-02-23 09:45:54.826328",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Course", "name": "LMS Course",

View File

@@ -5,7 +5,7 @@
{% if course.edit_mode and course.name %} {% if course.edit_mode and course.name %}
<button class="btn btn-md btn-secondary btn-chapter pull-right"> {{ _("New Chapter") }} </button> <button class="btn btn-sm btn-secondary btn-chapter pull-right"> {{ _("New Chapter") }} </button>
{% endif %} {% endif %}
{% if course.name and (course.edit_mode or chapters | length) %} {% if course.name and (course.edit_mode or chapters | length) %}

View File

@@ -50,3 +50,5 @@ lms.patches.v0_0.video_embed_link
lms.patches.v0_0.rename_exercise_doctype lms.patches.v0_0.rename_exercise_doctype
lms.patches.v0_0.add_question_type lms.patches.v0_0.add_question_type
lms.patches.v0_0.add_evaluator_to_assignment lms.patches.v0_0.add_evaluator_to_assignment
lms.patches.v0_0.convert_lesson_markdown_to_html #05-04-2023
lms.patches.v0_0.convert_course_description_to_html

View File

@@ -0,0 +1,12 @@
import frappe
from lms.lms.md import markdown_to_html
def execute():
courses = frappe.get_all("LMS Course", fields=["name", "description"])
for course in courses:
html = markdown_to_html(course.description)
frappe.db.set_value("LMS Course", course.name, "description", html)
frappe.reload_doc("lms", "doctype", "lms_course")

View File

@@ -0,0 +1,12 @@
import frappe
from lms.lms.md import markdown_to_html
def execute():
lessons = frappe.get_all("Course Lesson", fields=["name", "body"])
for lesson in lessons:
html = markdown_to_html(lesson.body)
frappe.db.set_value("Course Lesson", lesson.name, "body", html)
frappe.reload_doc("lms", "doctype", "course_lesson")

View File

@@ -1561,7 +1561,7 @@ li {
outline: none; outline: none;
background-color: var(--bg-light-gray); background-color: var(--bg-light-gray);
border-radius: var(--border-radius); border-radius: var(--border-radius);
border: 1px dashed var(--gray-600); border: 1px solid var(--gray-300);
padding: 0.5rem 0.75rem; padding: 0.5rem 0.75rem;
color: var(--gray-900); color: var(--gray-900);
} }
@@ -1575,7 +1575,7 @@ li {
margin-top: 0.25rem; margin-top: 0.25rem;
background-color: var(--bg-light-gray); background-color: var(--bg-light-gray);
border-radius: var(--border-radius); border-radius: var(--border-radius);
border: 1px dashed var(--gray-600); border: 1px solid var(--gray-300);
padding: 0.5rem 0.75rem; padding: 0.5rem 0.75rem;
width: fit-content; width: fit-content;
} }

View File

@@ -176,7 +176,10 @@
id="quiz-id">{% if lesson.quiz_id %}{{ lesson.quiz_id }}{% endif %}</div> id="quiz-id">{% if lesson.quiz_id %}{{ lesson.quiz_id }}{% endif %}</div>
</div> </div>
<div id="body" {% if lesson.body %} data-body="{{ lesson.body }}" {% endif %}></div> {% if lesson.body %}
<div class="body-data hide"> {{ lesson.body }} </div>
{% endif %}
<div id="body"></div>
<div class="d-flex medium mx-0 mb-4"> <div class="d-flex medium mx-0 mb-4">
<div class="flex-grow-1" contenteditable="true" data-placeholder="{{ _('Assignment Question') }}" <div class="flex-grow-1" contenteditable="true" data-placeholder="{{ _('Assignment Question') }}"

View File

@@ -597,13 +597,8 @@ const make_editor = () => {
fields: [ fields: [
{ {
fieldname: "code_md", fieldname: "code_md",
fieldtype: "Code", fieldtype: "Text Editor",
options: "Markdown", default: $(".body-data").html(),
wrap: true,
max_lines: Infinity,
min_lines: 20,
default: $("#body").data("body"),
depends_on: 'eval:doc.type=="Markdown"',
}, },
], ],
body: $("#body").get(0), body: $("#body").get(0),

View File

@@ -201,7 +201,10 @@
<!-- Description --> <!-- Description -->
{% macro Description(course) %} {% macro Description(course) %}
{% if course.edit_mode %} {% if course.edit_mode %}
<div id="description" {% if course.description %} data-description="{{ course.description }}" {% endif %}></div> {% if course.description %}
<div class="description-data hide">{{ course.description }}</div>
{% endif %}
<div id="description"></div>
{% else %} {% else %}
<div class="course-description-section"> <div class="course-description-section">
{{ frappe.utils.md_to_html(course.description) }} {{ frappe.utils.md_to_html(course.description) }}
@@ -232,12 +235,12 @@
<!-- Save --> <!-- Save -->
{% macro Save(course) %} {% macro Save(course) %}
{% if course.edit_mode %} {% if course.edit_mode %}
<div class="mt-4 mb-16"> <div class="mb-16">
<button class="btn btn-primary btn-md btn-save-course"> <button class="btn btn-primary btn-sm btn-save-course">
{{ _("Save Course Details") }} {{ _("Save Course Details") }}
</button> </button>
{% if course.name %} {% if course.name %}
<a class="btn btn-secondary btn-md btn-exit-edit ml-2" href="/courses/{{ course.name }}"> <a class="btn btn-secondary btn-sm btn-exit-edit ml-2" href="/courses/{{ course.name }}">
{{ _("Back to Course") }} {{ _("Back to Course") }}
</a> </a>
{% endif %} {% endif %}

View File

@@ -396,13 +396,8 @@ const make_editor = () => {
fields: [ fields: [
{ {
fieldname: "code_md", fieldname: "code_md",
fieldtype: "Code", fieldtype: "Text Editor",
options: "Markdown", default: $(".description-data").html(),
wrap: true,
max_lines: Infinity,
min_lines: 20,
default: $("#description").data("description"),
depends_on: 'eval:doc.type=="Markdown"',
}, },
], ],
body: $("#description").get(0), body: $("#description").get(0),