From e4b45562105d6b72d3d74e0d79319fc931fad22f Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 6 Apr 2023 18:01:12 +0530 Subject: [PATCH] feat: text editor for description --- lms/lms/doctype/course_lesson/course_lesson.py | 2 +- lms/lms/doctype/lms_course/lms_course.json | 4 ++-- lms/lms/widgets/CourseOutline.html | 2 +- lms/patches.txt | 3 ++- .../v0_0/convert_course_description_to_html.py | 12 ++++++++++++ lms/public/css/style.css | 4 ++-- lms/www/batch/learn.html | 5 ++++- lms/www/batch/learn.js | 9 ++------- lms/www/courses/course.html | 11 +++++++---- lms/www/courses/course.js | 9 ++------- 10 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 lms/patches/v0_0/convert_course_description_to_html.py diff --git a/lms/lms/doctype/course_lesson/course_lesson.py b/lms/lms/doctype/course_lesson/course_lesson.py index cf3f8c9d..1379088c 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.py +++ b/lms/lms/doctype/course_lesson/course_lesson.py @@ -53,7 +53,7 @@ class CourseLesson(Document): ex.course = None ex.index_ = 0 ex.index_label = "" - ex.save() + ex.save(ignore_permissions=True) def check_and_create_folder(self): args = { diff --git a/lms/lms/doctype/lms_course/lms_course.json b/lms/lms/doctype/lms_course/lms_course.json index 0b6a450c..839cf40a 100644 --- a/lms/lms/doctype/lms_course/lms_course.json +++ b/lms/lms/doctype/lms_course/lms_course.json @@ -57,7 +57,7 @@ }, { "fieldname": "description", - "fieldtype": "Markdown Editor", + "fieldtype": "Text Editor", "label": "Description", "reqd": 1 }, @@ -260,7 +260,7 @@ } ], "make_attachments_public": 1, - "modified": "2023-02-23 09:45:54.826327", + "modified": "2023-02-23 09:45:54.826328", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", diff --git a/lms/lms/widgets/CourseOutline.html b/lms/lms/widgets/CourseOutline.html index d42a6da7..5a765218 100644 --- a/lms/lms/widgets/CourseOutline.html +++ b/lms/lms/widgets/CourseOutline.html @@ -5,7 +5,7 @@ {% if course.edit_mode and course.name %} - + {% endif %} {% if course.name and (course.edit_mode or chapters | length) %} diff --git a/lms/patches.txt b/lms/patches.txt index e9e9e212..3666aef5 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -50,4 +50,5 @@ lms.patches.v0_0.video_embed_link lms.patches.v0_0.rename_exercise_doctype lms.patches.v0_0.add_question_type lms.patches.v0_0.add_evaluator_to_assignment -lms.patches.v0_0.convert_lesson_markdown_to_html #05-04-2023 \ No newline at end of file +lms.patches.v0_0.convert_lesson_markdown_to_html #05-04-2023 +lms.patches.v0_0.convert_course_description_to_html \ No newline at end of file diff --git a/lms/patches/v0_0/convert_course_description_to_html.py b/lms/patches/v0_0/convert_course_description_to_html.py new file mode 100644 index 00000000..30311f55 --- /dev/null +++ b/lms/patches/v0_0/convert_course_description_to_html.py @@ -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") diff --git a/lms/public/css/style.css b/lms/public/css/style.css index 872e9430..61271c10 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1561,7 +1561,7 @@ li { outline: none; background-color: var(--bg-light-gray); border-radius: var(--border-radius); - border: 1px dashed var(--gray-600); + border: 1px solid var(--gray-300); padding: 0.5rem 0.75rem; color: var(--gray-900); } @@ -1575,7 +1575,7 @@ li { margin-top: 0.25rem; background-color: var(--bg-light-gray); border-radius: var(--border-radius); - border: 1px dashed var(--gray-600); + border: 1px solid var(--gray-300); padding: 0.5rem 0.75rem; width: fit-content; } diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index 373ae966..f106a366 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -176,7 +176,10 @@ id="quiz-id">{% if lesson.quiz_id %}{{ lesson.quiz_id }}{% endif %} -
+ {% if lesson.body %} +
{{ lesson.body }}
+ {% endif %} +
{ fields: [ { fieldname: "code_md", - fieldtype: "Code", - options: "Markdown", - wrap: true, - max_lines: Infinity, - min_lines: 20, - default: $("#body").data("body"), - depends_on: 'eval:doc.type=="Markdown"', + fieldtype: "Text Editor", + default: $(".body-data").html(), }, ], body: $("#body").get(0), diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index 87fe4c31..83844def 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -201,7 +201,10 @@ {% macro Description(course) %} {% if course.edit_mode %} -
+ {% if course.description %} +
{{ course.description }}
+ {% endif %} +
{% else %}
{{ frappe.utils.md_to_html(course.description) }} @@ -232,12 +235,12 @@ {% macro Save(course) %} {% if course.edit_mode %} -
- {% if course.name %} - + {{ _("Back to Course") }} {% endif %} diff --git a/lms/www/courses/course.js b/lms/www/courses/course.js index b8eef4e4..cd049384 100644 --- a/lms/www/courses/course.js +++ b/lms/www/courses/course.js @@ -396,13 +396,8 @@ const make_editor = () => { fields: [ { fieldname: "code_md", - fieldtype: "Code", - options: "Markdown", - wrap: true, - max_lines: Infinity, - min_lines: 20, - default: $("#description").data("description"), - depends_on: 'eval:doc.type=="Markdown"', + fieldtype: "Text Editor", + default: $(".description-data").html(), }, ], body: $("#description").get(0),