diff --git a/school/lms/doctype/course_lesson/course_lesson.js b/school/lms/doctype/course_lesson/course_lesson.js index 3b3f13ef..453aaa58 100644 --- a/school/lms/doctype/course_lesson/course_lesson.js +++ b/school/lms/doctype/course_lesson/course_lesson.js @@ -9,7 +9,7 @@ frappe.ui.form.on('Course Lesson', { frm.get_field('help').html(`

You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.

-
+
Content Type
@@ -18,7 +18,7 @@ frappe.ui.form.on('Course Lesson', {
-
+
Video
@@ -27,7 +27,7 @@ frappe.ui.form.on('Course Lesson', {
-
+
YouTube Video
@@ -36,7 +36,7 @@ frappe.ui.form.on('Course Lesson', {
-
+
Exercise
@@ -45,13 +45,60 @@ frappe.ui.form.on('Course Lesson', {
-
+
Quiz
{{ Quiz("lms_quiz_name") }}
+ +
+
+ Assignment +
+
+ {{ Assignment("id-filetype") }} +
+
+ +
+ +
+
+ Supported File Types for Assignment +
+
+ Syntax +
+
+ +
+
+ .doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document +
+
+ Document +
+
+ +
+
+ .pdf +
+
+ PDF +
+
+ +
+
+ .png, .jpg, .jpeg +
+
+ Image +
+
`); } }); diff --git a/school/lms/doctype/lesson_assignment/lesson_assignment.py b/school/lms/doctype/lesson_assignment/lesson_assignment.py index 1c569c92..7c6b963b 100644 --- a/school/lms/doctype/lesson_assignment/lesson_assignment.py +++ b/school/lms/doctype/lesson_assignment/lesson_assignment.py @@ -10,15 +10,19 @@ class LessonAssignment(Document): @frappe.whitelist() def upload_assignment(assignment, lesson, identifier): - lesson_work = frappe.get_doc({ + args = { "doctype": "Lesson Assignment", "lesson": lesson, "user": frappe.session.user, - "assignment": assignment, "id": identifier - }) - lesson_work.save(ignore_permissions=True) - return lesson_work.name + } + lesson_work = frappe.db.exists(args) + if lesson_work: + frappe.db.set_value("Lesson Assignment", lesson_work[0], "assignment", assignment) + else: + args.update({"assignment": assignment}) + lesson_work = frappe.get_doc(args) + lesson_work.save(ignore_permissions=True) @frappe.whitelist() def get_assignment(lesson): @@ -28,6 +32,10 @@ def get_assignment(lesson): "user": frappe.session.user }, ["lesson", "user", "id", "assignment"]) + if len(assignments): + for assignment in assignments: + assignment.file_name = frappe.db.get_value("File", {"file_url": assignment.assignment}, "file_name") + return assignments diff --git a/school/plugins.py b/school/plugins.py index 40c3a2a8..e320ee20 100644 --- a/school/plugins.py +++ b/school/plugins.py @@ -121,8 +121,16 @@ def youtube_video_renderer(video_id): def video_renderer(src): return "".format(src) -def assignment_renderer(id): - return frappe.render_template("templates/assignment.html", {"id": id}) +def assignment_renderer(detail): + supported_types = { + "Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "PDF": ".pdf", + "Image": ".png, .jpg, .jpeg", + "Video": "video/*" + } + file_type = detail.split("-")[1] + accept = supported_types[file_type] if file_type else "" + return frappe.render_template("templates/assignment.html", {"id": detail.split("-")[0], "accept": accept}) def show_custom_signup(): if frappe.db.get_single_value("LMS Settings", "terms_of_use"): diff --git a/school/public/css/style.css b/school/public/css/style.css index 80848fc8..f4edb3ec 100644 --- a/school/public/css/style.css +++ b/school/public/css/style.css @@ -1458,3 +1458,8 @@ pre { .no-discussions { width: 80% !important; } + +.preview-work { + width: 50%; + justify-content: space-between; +} diff --git a/school/templates/assignment.html b/school/templates/assignment.html index d0355355..ff543469 100644 --- a/school/templates/assignment.html +++ b/school/templates/assignment.html @@ -1,10 +1,10 @@
- +
Submit Work
-
+
-
Clear
+
Change
diff --git a/school/www/batch/learn.js b/school/www/batch/learn.js index 3eda5e90..7fc66b84 100644 --- a/school/www/batch/learn.js +++ b/school/www/batch/learn.js @@ -263,25 +263,14 @@ const upload_file = (file, target) => { let response = JSON.parse(xhr.responseText) create_lesson_work(response.message, target); } else if (xhr.status === 403) { - file.failed = true; let response = JSON.parse(xhr.responseText); - file.error_message = `Not permitted. ${response._error_message || ''}`; + frappe.msgprint(`Not permitted. ${response._error_message || ''}`); } else if (xhr.status === 413) { - file.failed = true; - file.error_message = 'Size exceeds the maximum allowed file size.'; + frappe.msgprint('Size exceeds the maximum allowed file size.'); } else { - file.failed = true; - file.error_message = xhr.status === 0 ? 'XMLHttpRequest Error' : `${xhr.status} : ${xhr.statusText}`; - - let error = null; - try { - error = JSON.parse(xhr.responseText); - } catch(e) { - // pass - } - frappe.request.cleanup({}, error); + frappe.msgprint(xhr.status === 0 ? 'XMLHttpRequest Error' : `${xhr.status} : ${xhr.statusText}`); } } } @@ -291,7 +280,7 @@ const upload_file = (file, target) => { let form_data = new FormData(); if (file.file_obj) { - form_data.append('file', file.file_obj, file.name); + form_data.append('file', file.file_obj, `${frappe.session.user}-${file.name}`); form_data.append('folder', `${$(".title").attr("data-lesson")} ${$(".title").attr("data-course")}`) } @@ -312,7 +301,6 @@ const create_lesson_work = (file, target) => { target.siblings(".preview-work").removeClass("hide"); target.siblings(".preview-work").find("a").attr("href", file.file_url).text(file.file_name) target.addClass("hide"); - target.next(".clear-work").removeClass("hide"); } }); }; @@ -352,10 +340,10 @@ const add_files = (files) => { const clear_work = (e) => { const target = $(e.currentTarget); - target.siblings(".attach-file").removeClass("hide").val(null); - target.siblings(".preview-work").addClass("hide"); - target.siblings(".submit-work").removeClass("hide"); - target.addClass("hide"); + const parent = target.closest(".preview-work"); + parent.addClass("hide"); + parent.siblings(".attach-file").removeClass("hide").val(null); + parent.siblings(".submit-work").removeClass("hide"); } const fetch_assignments = () => { @@ -367,8 +355,13 @@ const fetch_assignments = () => { }, callback: (data) => { if (data.message && data.message.length) { - for (let assignment in data.message) { - console.log(assignment.id) + const assignments = data.message; + for (let i in assignments) { + let target = $(`#${assignments[i]["id"]}`); + target.addClass("hide"); + target.siblings(".submit-work").addClass("hide"); + target.siblings(".preview-work").removeClass("hide"); + target.siblings(".preview-work").find("a").attr("href", assignments[i]["assignment"]).text(assignments[i]["file_name"]); } } } diff --git a/school/www/profiles/profile.html b/school/www/profiles/profile.html index 64e73b81..63c75951 100644 --- a/school/www/profiles/profile.html +++ b/school/www/profiles/profile.html @@ -244,7 +244,7 @@ {% endif %} {% if member.mobile_no and not member.hide_private %} - + {{ member.mobile_no }} {% endif %}