From 85903d53858f17de8d48ece2e2c24b7b0db31c3c Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 1 Jun 2023 22:44:32 +0530 Subject: [PATCH] feat: my class tab --- .../lms_assignment_submission.py | 45 ++++++--- lms/public/css/style.css | 4 + .../assignment_submission.html | 98 ++++++++++++++----- .../assignment_submission.js | 38 ++++--- .../assignment_submission.py | 4 +- lms/www/classes/class.html | 6 +- lms/www/classes/index.html | 25 ++++- lms/www/classes/index.py | 21 +++- lms/www/classes/progress.html | 4 +- 9 files changed, 183 insertions(+), 62 deletions(-) diff --git a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py index 92360694..d1ca029b 100644 --- a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py +++ b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py @@ -24,26 +24,39 @@ class LMSAssignmentSubmission(Document): @frappe.whitelist() -def upload_assignment(assignment_attachment, assignment, lesson=None): +def upload_assignment( + assignment_attachment, + assignment, + lesson=None, + status="Not Graded", + comments=None, + submission=None, +): if frappe.session.user == "Guest": return - args = { - "doctype": "LMS Assignment Submission", - "member": frappe.session.user, - "assignment": assignment, - } - if frappe.db.exists(args): - del args["doctype"] - frappe.db.set_value( - "LMS Assignment Submission", args, "assignment_attachment", assignment_attachment - ) - return frappe.db.get_value("LMS Assignment Submission", args, "name") + if submission: + doc = frappe.get_doc("LMS Assignment Submission", submission) else: - args.update({"assignment_attachment": assignment_attachment}) - doc = frappe.get_doc(args) - doc.save(ignore_permissions=True) - return doc.name + doc = frappe.get_doc( + { + "doctype": "LMS Assignment Submission", + "assignment": assignment, + "lesson": lesson, + "member": frappe.session.user, + } + ) + print(doc.assignment) + print(comments) + doc.update( + { + "assignment_attachment": assignment_attachment, + "status": status, + "comments": comments, + } + ) + doc.save(ignore_permissions=True) + return doc.name @frappe.whitelist() diff --git a/lms/public/css/style.css b/lms/public/css/style.css index 30299073..5842cea7 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1916,6 +1916,10 @@ li { justify-content: flex-end !important; } +.modal-footer .btn-primary { + margin-left: 0.5rem +} + .modal-header .modal-title { color: var(--gray-900); line-height: 1.5rem; diff --git a/lms/www/assignment_submission/assignment_submission.html b/lms/www/assignment_submission/assignment_submission.html index a1278bd9..6afb2192 100644 --- a/lms/www/assignment_submission/assignment_submission.html +++ b/lms/www/assignment_submission/assignment_submission.html @@ -16,25 +16,32 @@
-
-
- {{ assignment.title }} +
+
+
+ {{ assignment.title }} +
+ {% if submission.status %} + {% set color = "green" if submission.status == "Pass" else "red" if submission.status == "Fail" else "orange" %} +
+ {{ submission.status }} +
+ {% endif %}
- {% if submission.status %} - {% set color = "green" if submission.status == "Pass" else "red" if submission.status == "Fail" else "orange" %} -
- {{ submission.status }} + - {% endif %}
- {% if submission.status == "Not Graded" %} +
-
- {% endif %}
@@ -42,17 +49,19 @@ {% macro SubmissionForm(assignment) %}
+ {% if submission.name and is_moderator %}
- {{ _("Student") }} + {{ _("Student Name") }}
{{ submission.member_name }}
+ {% endif %}
- +
{{ assignment.question }} @@ -64,18 +73,61 @@ {{ _("Upload assignment as {0}").format(assignment.type) }} -
- {% if submission.status == "Not Graded" and submission.member == frappe.session.user %} - - {{ _("Clear") }} + +
+ {{ _("Browse").format(assignment.type) }} +
+
+ + {% if submission.assignment_attachment %} {{ submission.assignment_attachment }} {% endif %} + + + {{ _("Clear") }} - {% endif %} -
- {{ _("Browse").format(assignment.type) }} -
-
+ {% if is_moderator %} +
+
+ {{ _("Status") }} +
+
+ +
+ + + +
+
+
+ +
+
+ {{ _("Comments by Mentor") }} +
+ +
+ {% endif %} + + {% if submission and submission.member == frappe.session.user and submission.comments %} +
+
+ {{ _("Comments by Mentor") }} +
+
+ {{ submission.comments }} +
+
+ {% endif %} +
{% endmacro %} \ No newline at end of file diff --git a/lms/www/assignment_submission/assignment_submission.js b/lms/www/assignment_submission/assignment_submission.js index 5da67659..a46f054f 100644 --- a/lms/www/assignment_submission/assignment_submission.js +++ b/lms/www/assignment_submission/assignment_submission.js @@ -15,10 +15,15 @@ frappe.ready(() => { const upload_file = (e) => { let type = $(e.currentTarget).data("type"); let mapper = { - Image: "image/*", - Document: - ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", - PDF: ".pdf", + Image: ["image/*"], + Document: [ + ".doc", + ".docx", + ".xml", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ], + PDF: [".pdf"], }; new frappe.ui.FileUploader({ @@ -26,20 +31,23 @@ const upload_file = (e) => { folder: "Home/Attachments", make_attachments_public: true, restrictions: { - allowed_file_types: [mapper[type]], + allowed_file_types: mapper[type], }, on_success: (file_doc) => { $(e.currentTarget).addClass("hide"); - $(".file-source-preview .btn-close").removeClass("hide"); - $(".file-source-preview iframe") - .attr("src", file_doc.file_url) - .removeClass("hide"); + $("#assignment-preview").removeClass("hide"); + $("#assignment-preview .btn-close").removeClass("hide"); + $("#assignment-preview a").attr( + "href", + encodeURI(file_doc.file_url) + ); + $("#assignment-preview a").text(file_doc.file_url); }, }); }; const save_assignment = (e) => { - let file = $(".image-preview").attr("src"); + let file = $("#assignment-preview a").attr("href"); if (!file) { frappe.throw({ title: __("No File"), @@ -51,7 +59,10 @@ const save_assignment = (e) => { method: "lms.lms.doctype.lms_assignment_submission.lms_assignment_submission.upload_assignment", args: { assignment: $(e.currentTarget).data("assignment"), + submission: $(e.currentTarget).data("submission") || "", assignment_attachment: file, + status: $("#status").val(), + comments: $("#comments").val(), }, callback: (data) => { frappe.show_alert({ @@ -68,7 +79,8 @@ const save_assignment = (e) => { }; const clear_preview = (e) => { - $(".file-source-preview .btn-upload").removeClass("hide"); - $(".file-source-preview iframe").attr("src", "").addClass("hide"); - $(".file-source-preview .btn-close").addClass("hide"); + $(".btn-upload").removeClass("hide"); + $("#assignment-preview").addClass("hide"); + $("#assignment-preview a").attr("href", ""); + $("#assignment-preview .btn-close").addClass("hide"); }; diff --git a/lms/www/assignment_submission/assignment_submission.py b/lms/www/assignment_submission/assignment_submission.py index 55a16f94..3f903099 100644 --- a/lms/www/assignment_submission/assignment_submission.py +++ b/lms/www/assignment_submission/assignment_submission.py @@ -25,5 +25,5 @@ def get_context(context): if not context.is_moderator and frappe.session.user != context.submission.member: raise frappe.PermissionError(_("You don't have permission to access this page.")) - if not context.assignment or not context.submission: - raise frappe.PermissionError(_("Invalid Submission URL")) + if not context.assignment or not context.submission: + raise frappe.PermissionError(_("Invalid Submission URL")) diff --git a/lms/www/classes/class.html b/lms/www/classes/class.html index 3982d175..6822afd4 100644 --- a/lms/www/classes/class.html +++ b/lms/www/classes/class.html @@ -263,7 +263,7 @@ {{ _("To create a new assignment for this class, click on the create assignment button. Once you have created the new assignment you can come back to the class and add the assignment from here.") }}

- + {{ _("Create Assignment") }}
@@ -322,7 +322,7 @@ {% if assessments | length %}
-
+
{{ _("Title") }}
@@ -331,7 +331,7 @@
{% for assessment in assessments %}
-
+
{{ assessment.title }} diff --git a/lms/www/classes/index.html b/lms/www/classes/index.html index 26c6a9b7..401e1f6a 100644 --- a/lms/www/classes/index.html +++ b/lms/www/classes/index.html @@ -8,7 +8,7 @@
{{ Header() }} {% if past_classes | length or upcoming_classes | length %} - {{ ClassTabs(past_classes, upcoming_classes) }} + {{ ClassTabs(past_classes, upcoming_classes, my_classes) }} {% else %} {{ EmptyState() }} {% endif %} @@ -27,7 +27,7 @@ {% endmacro %} -{% macro ClassTabs(past_classes, upcoming_classes) %} +{% macro ClassTabs(past_classes, upcoming_classes, my_classes) %}
+ {% if is_moderator %}
{{ ClassCards(past_classes) }}
+ {% endif %} + + {% if frappe.session.user != "Guest" %} +
+ {{ ClassCards(my_classes) }} +
+ {% endif %}
diff --git a/lms/www/classes/index.py b/lms/www/classes/index.py index 4e387678..038dd575 100644 --- a/lms/www/classes/index.py +++ b/lms/www/classes/index.py @@ -20,5 +20,24 @@ def get_context(context): upcoming_classes.append(class_) context.past_classes = sorted(past_classes, key=lambda d: d.start_date) - context.upcoming_classes = sorted(upcoming_classes, key=lambda d: d.start_date) + + if frappe.session.user != "Guest": + my_classes_info = [] + my_classes = frappe.get_all( + "Class Student", {"student": frappe.session.user}, pluck="parent" + ) + + for class_ in my_classes: + my_classes_info.append( + frappe.db.get_value( + "LMS Class", + class_, + ["name", "title", "start_date", "end_date", "paid_class", "seat_count"], + as_dict=True, + ) + ) + + context.my_classes = my_classes_info + + print(context.my_classes) diff --git a/lms/www/classes/progress.html b/lms/www/classes/progress.html index 00631561..b2b2eaba 100644 --- a/lms/www/classes/progress.html +++ b/lms/www/classes/progress.html @@ -8,7 +8,7 @@
{{ Header() }}
- {{ Progress() }} + {{ Progress(class_info, student) }}
{% endblock %} @@ -50,7 +50,7 @@
{% for assessment in assessments %}