From a291d738283855050be6c11b8b3086d3b2c7be3e Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 27 Sep 2022 18:13:46 +0530 Subject: [PATCH] feat: show notifications from logs --- lms/hooks.py | 8 ++++--- lms/lms/utils.py | 33 +++++++++++++++++++++++++++++ lms/lms/widgets/Avatar.html | 22 +++++++++---------- lms/lms/widgets/Reviews.html | 2 +- lms/public/css/style.css | 36 ++++++++++++++++++++++++-------- lms/templates/notifications.html | 30 ++++++++++++++++++++++++++ lms/www/batch/learn.html | 2 +- lms/www/batch/learn.py | 2 +- lms/www/courses/course.html | 2 +- lms/www/dashboard/index.html | 22 +++++-------------- lms/www/dashboard/index.py | 17 ++++++++++++--- 11 files changed, 129 insertions(+), 47 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index fc70e0e6..85ac2ded 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -85,8 +85,8 @@ web_include_js = ["website.bundle.js", "controls.bundle.js"] # Override standard doctype classes override_doctype_class = { - "User": "lms.overrides.user.CustomUser", - "Web Template": "lms.overrides.web_template.CustomWebTemplate" + "User": "lms.overrides.user.CustomUser", + "Web Template": "lms.overrides.web_template.CustomWebTemplate" } # Document Events @@ -94,7 +94,9 @@ override_doctype_class = { # Hook on document methods and events doc_events = { - + "Discussion Reply": { + "after_insert": "lms.lms.utils.create_notification_log" + } } # Scheduled Tasks diff --git a/lms/lms/utils.py b/lms/lms/utils.py index a36f8438..abc197c3 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -4,6 +4,7 @@ from frappe.utils import flt, cint, cstr, getdate, add_months, fmt_money from lms.lms.md import markdown_to_html, find_macros import string from frappe import _ +from frappe.desk.doctype.notification_log.notification_log import make_notification_logs RE_SLUG_NOTALLOWED = re.compile("[^a-z0-9]+") @@ -469,3 +470,35 @@ def validate_image(path): file.save(ignore_permissions=True) return file.file_url return path + + +def create_notification_log(doc, method): + topic = frappe.db.get_value("Discussion Topic", doc.topic, + ["reference_doctype", "reference_docname", "owner", "title"], as_dict=1) + + if topic.reference_doctype != "Course Lesson": + return + + course = frappe.db.get_value("Course Lesson", topic.reference_docname, "course") + instructors = frappe.db.get_all("Course Instructor", { "parent": course }, pluck="instructor") + + notification = frappe._dict({ + "subject": _("New reply on the topic {0}").format(topic.title), + "email_content": doc.reply, + "document_type": topic.reference_doctype, + "document_name": topic.reference_docname, + "for_user": topic.owner, + "from_user": doc.owner, + "type": "Alert" + }) + + users = [] + if doc.owner != topic.owner: + users.append(topic.owner) + + if doc.owner not in instructors: + users += instructors + make_notification_logs(notification, users) + + + diff --git a/lms/lms/widgets/Avatar.html b/lms/lms/widgets/Avatar.html index f4b7194c..063b2c79 100644 --- a/lms/lms/widgets/Avatar.html +++ b/lms/lms/widgets/Avatar.html @@ -1,14 +1,14 @@ {% set color = get_palette(member.full_name) %} - - {% if member.user_image %} - - - {% else %} - - {{ frappe.utils.get_abbr(member.full_name) }} - - {% endif %} - + + {% if member.user_image %} + + {% else %} + + {{ frappe.utils.get_abbr(member.full_name) }} + + {% endif %} + diff --git a/lms/lms/widgets/Reviews.html b/lms/lms/widgets/Reviews.html index db871e54..1e79dbd3 100644 --- a/lms/lms/widgets/Reviews.html +++ b/lms/lms/widgets/Reviews.html @@ -8,7 +8,7 @@ {{ _("Write a review") }} {% elif not is_instructor(course.name) and frappe.session.user == "Guest" %} - {{ _("Login") }} + {{ _("Login") }} {% elif not is_instructor(course.name) and not membership and course.status == "Approved" %}
{{ _("Start Learning") }}
{% endif %} diff --git a/lms/public/css/style.css b/lms/public/css/style.css index f42a7e66..7e10ceb0 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1399,15 +1399,17 @@ pre { } .lms-nav .nav-link { - color: var(--text-muted); - padding: var(--padding-md) 0; + padding: var(--padding-sm) 0; margin: 0 var(--margin-md); + font-size: var(--text-base); + color: var(--text-muted); + } .lms-nav .nav-link.active { - font-weight: 600; - border-bottom: 1px solid var(--primary); - color: var(--text-color); + font-weight: 500; + border-bottom: 1px solid var(--primary-color); + color: var(--primary-color); } @media (min-width: 500px) { @@ -1416,10 +1418,6 @@ pre { } } -.lms-nav .nav-link:hover { - color: inherit; -} - .dashboard-button { position: relative; top: -50px; @@ -1708,3 +1706,23 @@ li { width: 2.75rem; height: 2.75rem; } + +.modal .comment-field { + height: 150px !important; + resize: auto !important; +} + +.notification-card { + display: flex; + align-items: center; + margin-bottom: 1.5rem; + position: relative; +} + +.notification-card:last-child { + margin-bottom: 0; +} + +.timestamp { + font-size: var(--text-xs); +} diff --git a/lms/templates/notifications.html b/lms/templates/notifications.html index e69de29b..cd6679d4 100644 --- a/lms/templates/notifications.html +++ b/lms/templates/notifications.html @@ -0,0 +1,30 @@ +{% if notifications | length %} +
+ {% for notification in notifications %} +
+
+ {% set member = frappe.db.get_value("User", notification.from_user, + ["username", "full_name", "user_image"], as_dict=1) %} + {{ widgets.Avatar(member=member, avatar_class="avatar-medium") }} +
+
+
+ {{ notification.subject }} {{ frappe.utils.pretty_date(notification.creation) }} +
+ +
+ +
+ + {% endfor %} +
+ +{% else %} +
+ +
+
{{ _("No Notifications") }}
+
{{ _("You don't have any notifications.") }}
+
+
+{% endif %} diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index f71d1580..67cd8b63 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -74,7 +74,7 @@ {% if (is_instructor or has_course_moderator_role()) and not lesson.edit_mode %} - + {% endif %} diff --git a/lms/www/batch/learn.py b/lms/www/batch/learn.py index a1674156..c8b2aabf 100644 --- a/lms/www/batch/learn.py +++ b/lms/www/batch/learn.py @@ -13,7 +13,7 @@ def get_context(context): context.chapter = frappe.db.get_value("Chapter Reference", { "idx": chapter_index, "parent": context.course.name - }, "chapter") + }, "chapter") if not chapter_index or not lesson_index: if context.batch: diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index 27e7257a..558bbd5d 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -347,7 +347,7 @@ {% endif %} {% if is_instructor(course.name) or has_course_moderator_role() %} - {{ _("Edit Course") }} + {{ _("Edit Course") }} {% endif %} {% endmacro %} diff --git a/lms/www/dashboard/index.html b/lms/www/dashboard/index.html index ad6e894b..b9d0a501 100644 --- a/lms/www/dashboard/index.html +++ b/lms/www/dashboard/index.html @@ -17,14 +17,14 @@