From c4ab91a5651b1bcc26fffaf331e5fafffbc553d2 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 13 Sep 2023 13:07:20 +0530 Subject: [PATCH] feat: certified participants page --- .../lms_certificate/lms_certificate.json | 9 ++++- lms/patches.txt | 3 +- lms/patches/v1_0/publish_certificates.py | 8 +++++ lms/www/batches/index.html | 2 +- .../certified_participants.html | 35 ++++++++++++++++--- .../certified_participants.js | 18 ++++++++++ .../certified_participants.py | 30 +++++++++++++--- 7 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 lms/patches/v1_0/publish_certificates.py create mode 100644 lms/www/certified_participants/certified_participants.js diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.json b/lms/lms/doctype/lms_certificate/lms_certificate.json index 39206779..8033cd8f 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.json +++ b/lms/lms/doctype/lms_certificate/lms_certificate.json @@ -8,6 +8,7 @@ "course", "member", "member_name", + "published", "column_break_3", "issue_date", "expiry_date", @@ -60,11 +61,17 @@ "in_standard_filter": 1, "label": "Batch", "options": "LMS Batch" + }, + { + "default": "0", + "fieldname": "published", + "fieldtype": "Check", + "label": "Publish on Participant Page" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-29 15:23:08.637215", + "modified": "2023-09-13 11:03:23.479255", "modified_by": "Administrator", "module": "LMS", "name": "LMS Certificate", diff --git a/lms/patches.txt b/lms/patches.txt index b8e25bf8..19f9a649 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -67,4 +67,5 @@ lms.patches.v1_0.rename_lms_batch_doctype lms.patches.v1_0.rename_lms_batch_membership_doctype lms.patches.v1_0.rename_lms_class_to_lms_batch lms.patches.v1_0.rename_classes_in_navbar -lms.patches.v1_0.publish_batches \ No newline at end of file +lms.patches.v1_0.publish_batches +lms.patches.v1_0.publish_certificates \ No newline at end of file diff --git a/lms/patches/v1_0/publish_certificates.py b/lms/patches/v1_0/publish_certificates.py new file mode 100644 index 00000000..71e5861f --- /dev/null +++ b/lms/patches/v1_0/publish_certificates.py @@ -0,0 +1,8 @@ +import frappe + + +def execute(): + certificates = frappe.get_all("LMS Certificate", pluck="name") + + for certificate in certificates: + frappe.db.set_value("LMS Certificate", certificate, "published", 1) diff --git a/lms/www/batches/index.html b/lms/www/batches/index.html index 21178371..d05bf6f5 100644 --- a/lms/www/batches/index.html +++ b/lms/www/batches/index.html @@ -174,7 +174,7 @@
{{ _("No Batches") }}
-
{{ _("Nothing to see here.") }}
+
{{ _("Please contact the Administrator for more information.") }}
{% endmacro %} diff --git a/lms/www/certified_participants/certified_participants.html b/lms/www/certified_participants/certified_participants.html index 6435afb8..988c9fac 100644 --- a/lms/www/certified_participants/certified_participants.html +++ b/lms/www/certified_participants/certified_participants.html @@ -7,11 +7,28 @@
-
+ {% if course_filter | length %} + + {% endif %} +
{{ _("Certified Participants") }}
- {{ ParticipantsList() }} + {% if participants | length %} + {{ ParticipantsList() }} + {% else %} + {{ EmptyState() }} + {% endif %} +
{% endblock %} @@ -21,15 +38,25 @@ {% for participant in participants %}
{{ widgets.Avatar(member=participant, avatar_class="avatar-large") }} -
+
{{ participant.full_name }}
{% for course in participant.courses %} -
+
{{ course }}
{% endfor %}
{% endfor %} +{% endmacro %} + +{% macro EmptyState() %} +
+ +
+
{{ _("No Certified Participants") }}
+
{{ _("Enroll in a batch to get certified.") }}
+
+
{% endmacro %} \ No newline at end of file diff --git a/lms/www/certified_participants/certified_participants.js b/lms/www/certified_participants/certified_participants.js new file mode 100644 index 00000000..af5b1340 --- /dev/null +++ b/lms/www/certified_participants/certified_participants.js @@ -0,0 +1,18 @@ +frappe.ready(() => { + $("#certificate-filter").change((e) => { + filter_certified_participants(); + }); +}); + +const filter_certified_participants = () => { + const certificate = $("#certificate-filter").val(); + $(".common-card-style").removeClass("hide"); + + if (certificate) { + $(".common-card-style").addClass("hide"); + $(`[data-course='${certificate}']`) + .closest(".common-card-style") + .removeClass("hide"); + console.log(certificate); + } +}; diff --git a/lms/www/certified_participants/certified_participants.py b/lms/www/certified_participants/certified_participants.py index a0602219..2dc9b238 100644 --- a/lms/www/certified_participants/certified_participants.py +++ b/lms/www/certified_participants/certified_participants.py @@ -3,20 +3,40 @@ import frappe def get_context(context): context.no_cache = 1 - context.members = frappe.get_all( - "LMS Certificate", pluck="member", order_by="creation desc", distinct=1 + members = frappe.get_all( + "LMS Certificate", + filters={"published": 1}, + pluck="member", + order_by="issue_date desc", + distinct=1, ) participants = [] - for member in context.members: + course_filter = [] + for member in members: details = frappe.db.get_value( "User", member, ["name", "full_name", "user_image", "username", "enabled"], as_dict=1 ) - courses = frappe.get_all("LMS Certificate", {"member": member}, pluck="course") + courses = frappe.get_all( + "LMS Certificate", + filters={"member": member, "published": 1}, + fields=["course", "issue_date"], + ) details.courses = [] for course in courses: - details.courses.append(frappe.db.get_value("LMS Course", course, "title")) + + if not details.issue_date: + details.issue_date = course.issue_date + + title = frappe.db.get_value("LMS Course", course.course, "title") + details.courses.append(title) + + if title not in course_filter: + course_filter.append(title) + if details.enabled: participants.append(details) + participants = sorted(participants, key=lambda d: d.issue_date, reverse=True) context.participants = participants + context.course_filter = course_filter