From 11277d2ef3d0706c3959fd481228b7cffa8afcb9 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 10 Oct 2022 13:11:49 +0530 Subject: [PATCH 1/2] fix: misc ux --- lms/hooks.py | 3 +- .../lms_batch_membership.json | 4 +- lms/lms/utils.py | 6 +++ lms/lms/widgets/Reviews.html | 30 ++++++++------ lms/public/css/style.css | 4 -- lms/public/js/common_functions.js | 2 +- .../search_course/search_course.html | 2 +- lms/www/courses/course.html | 39 +++++++++---------- lms/www/courses/course.js | 14 +++++-- lms/www/courses/course.py | 13 +------ 10 files changed, 61 insertions(+), 56 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index 57865f76..8ebc9931 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -202,7 +202,8 @@ jinja = { "lms.lms.utils.format_number", "lms.lms.utils.get_lesson_count", "lms.lms.utils.get_all_memberships", - "lms.lms.utils.get_filtered_membership" + "lms.lms.utils.get_filtered_membership", + "lms.lms.utils.show_start_learing_cta" ], "filters": [] } diff --git a/lms/lms/doctype/lms_batch_membership/lms_batch_membership.json b/lms/lms/doctype/lms_batch_membership/lms_batch_membership.json index 6574cf21..1efcf744 100644 --- a/lms/lms/doctype/lms_batch_membership/lms_batch_membership.json +++ b/lms/lms/doctype/lms_batch_membership/lms_batch_membership.json @@ -116,7 +116,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-09-01 17:11:08.065998", + "modified": "2022-10-10 12:38:17.839525", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch Membership", @@ -140,5 +140,5 @@ "sort_field": "modified", "sort_order": "DESC", "states": [], - "title_field": "member" + "title_field": "member_name" } \ No newline at end of file diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 7987c740..baf6dbee 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -522,6 +522,7 @@ def get_lesson_count(course): def check_profile_restriction(): return frappe.db.get_single_value("LMS Settings", "force_profile_completion") + def get_restriction_details(): user = frappe.db.get_value("User", frappe.session.user, ["profile_complete", "username"], as_dict=True) return { @@ -540,3 +541,8 @@ def get_all_memberships(member): def get_filtered_membership(course, memberships): current_membership = list(filter(lambda x: x.course == course, memberships)) return current_membership[0] if len(current_membership) else None + + +def show_start_learing_cta(course, membership): + return not course.disable_self_learning and not membership and not course.upcoming \ + and not check_profile_restriction() and not is_instructor(course.name) and course.status == "Approved" diff --git a/lms/lms/widgets/Reviews.html b/lms/lms/widgets/Reviews.html index 1e79dbd3..6bba73ce 100644 --- a/lms/lms/widgets/Reviews.html +++ b/lms/lms/widgets/Reviews.html @@ -1,18 +1,7 @@ {% if not course.upcoming %}
{% set reviews = get_reviews(course.name) %} -
- {{ _("Reviews") }} - {% if is_eligible_to_review(course.name, membership) %} - - {{ _("Write a review") }} - - {% elif not is_instructor(course.name) and frappe.session.user == "Guest" %} - {{ _("Login") }} - {% elif not is_instructor(course.name) and not membership and course.status == "Approved" %} -
{{ _("Start Learning") }}
- {% endif %} -
+
{{ _("Reviews") }}
{% set avg_rating = get_average_rating(course.name) %} @@ -22,7 +11,9 @@
{{ frappe.utils.flt(avg_rating, frappe.get_system_settings("float_precision") or 3) }}
+
{{ reviews | length }} {{ _("ratings") }}
+
{% for i in [1, 2, 3, 4, 5] %} @@ -32,9 +23,24 @@ {% endfor %}
+
{{ frappe.utils.flt(avg_rating, frappe.get_system_settings("float_precision") or 3) }} {{ _("out of 5 ") }}
+ + {% if is_eligible_to_review(course.name, membership) %} + + {{ _("Write a review") }} + + {% elif not is_instructor(course.name) and frappe.session.user == "Guest" %} + + {{ _("Login") }} + + {% elif show_start_learing_cta(course, membership) %} +
+ {{ _("Start Learning") }} +
+ {% endif %}
diff --git a/lms/public/css/style.css b/lms/public/css/style.css index be85af70..617b5a8a 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1678,10 +1678,6 @@ li { margin-right: 0; } -.review-link { - float: right -} - .role { margin-bottom: 0; cursor: pointer; diff --git a/lms/public/js/common_functions.js b/lms/public/js/common_functions.js index ccdf3632..88fa7aec 100644 --- a/lms/public/js/common_functions.js +++ b/lms/public/js/common_functions.js @@ -62,7 +62,7 @@ const join_course = (e) => { if (data.message == "OK") { $(".no-preview-modal").modal("hide"); frappe.show_alert({ - message: __("You are now a student of this course."), + message: __("Enrolled successfully"), indicator:'green' }, 3); setTimeout(function () { diff --git a/lms/templates/search_course/search_course.html b/lms/templates/search_course/search_course.html index 43dd100d..6cd4f673 100644 --- a/lms/templates/search_course/search_course.html +++ b/lms/templates/search_course/search_course.html @@ -2,7 +2,7 @@ {% set portal_course_creation = frappe.db.get_single_value("LMS Settings", "portal_course_creation") %}
- + {% if portal_course_creation == "Anyone" or has_course_instructor_role() %} {{ _("Create a Course") }} {% endif %} diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index 558bbd5d..ecb215ff 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -292,10 +292,9 @@ {% set lesson_index = get_lesson_index(membership.current_lesson) if membership and membership.current_lesson else "1.1" if first_lesson_exists(course.name) else None %} - {% if show_start_learing_cta %} + {% if show_start_learing_cta(course, membership) %}
{{ _("Start Learning") }} -
{% elif is_instructor(course.name) and not course.published and course.status != "Under Review" %} @@ -305,13 +304,13 @@ {% elif is_instructor(course.name) and lesson_index %} - {{ _("Checkout Course") }} + href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}"> + {{ _("Checkout Course") }} {% elif course.upcoming and not is_user_interested and not is_instructor %}
- {{ _("Notify me when available") }} + {{ _("Notify me when available") }}
{% elif is_cohort_staff(course.name, frappe.session.user) %} @@ -321,29 +320,29 @@ {% elif membership %} - {{ _("Continue Learning") }} + href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}"> + {{ _("Continue Learning") }} {% endif %} {% set progress = frappe.utils.cint(membership.progress) %} {% if membership and course.enable_certification %} - {% if certificate %} - - {{ _("Get Certificate") }} - + {% if certificate %} + + {{ _("Get Certificate") }} + - {% elif eligible_for_evaluation %} - - {{ _("Apply for Certificate") }} - + {% elif eligible_for_evaluation %} + + {{ _("Apply for Certificate") }} + - {% elif course.grant_certificate_after == "Completion" and progress == 100 %} -
- {{ _("Get Certificate") }} -
- {% endif %} + {% elif course.grant_certificate_after == "Completion" and progress == 100 %} +
+ {{ _("Get Certificate") }} +
+ {% endif %} {% endif %} {% if is_instructor(course.name) or has_course_moderator_role() %} diff --git a/lms/www/courses/course.js b/lms/www/courses/course.js index 06fbec3e..5d21b0dc 100644 --- a/lms/www/courses/course.js +++ b/lms/www/courses/course.js @@ -146,10 +146,10 @@ const highlight_rating = (e) => { }; -var submit_review = (e) => { +const submit_review = (e) => { e.preventDefault(); - var rating = $(".rating-field").children(".star-click").length; - var review = $(".review-field").val(); + let rating = $(".rating-field").children(".star-click").length; + let review = $(".review-field").val(); if (!rating) { $(".error-field").text("Please provide a rating."); return; @@ -164,7 +164,13 @@ var submit_review = (e) => { callback: (data) => { if (data.message == "OK") { $(".review-modal").modal("hide"); - window.location.reload(); + frappe.show_alert({ + message: __("Review submitted."), + indicator:'green' + }, 3); + setTimeout(() => { + window.location.reload(); + }, 1000); } } }); diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py index 7fdea492..b02dbba1 100644 --- a/lms/www/courses/course.py +++ b/lms/www/courses/course.py @@ -1,5 +1,6 @@ import frappe -from lms.lms.utils import check_profile_restriction, get_membership, get_restriction_details, has_course_moderator_role, is_instructor, is_certified, get_evaluation_details, redirect_to_courses_list +from lms.lms.utils import get_membership, has_course_moderator_role, is_instructor, is_certified, get_evaluation_details, redirect_to_courses_list + def get_context(context): context.no_cache = 1 @@ -50,12 +51,6 @@ def set_course_context(context, course_name): context.eligible_for_evaluation = eval_details.eligible context.certificate_request = eval_details.request context.no_of_attempts = eval_details.no_of_attempts - context.restriction = check_profile_restriction() - - if context.restriction: - context.restriction_details = get_restriction_details() - - context.show_start_learing_cta = show_start_learing_cta(course, membership, context.restriction) if context.course.upcoming: context.is_user_interested = get_user_interest(context.course.name) @@ -73,7 +68,3 @@ def get_user_interest(course): "user": frappe.session.user }) - -def show_start_learing_cta(course, membership, restriction): - return not course.disable_self_learning and not membership and not course.upcoming \ - and not restriction and not is_instructor(course.name) and course.status == "Approved" From 328d1d6546d4100e2830095f2f77cb1f9b3ae641 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 10 Oct 2022 13:31:15 +0530 Subject: [PATCH 2/2] fix: label of login button in review section --- lms/lms/widgets/Reviews.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/lms/widgets/Reviews.html b/lms/lms/widgets/Reviews.html index 6bba73ce..89425839 100644 --- a/lms/lms/widgets/Reviews.html +++ b/lms/lms/widgets/Reviews.html @@ -34,7 +34,7 @@ {% elif not is_instructor(course.name) and frappe.session.user == "Guest" %} - {{ _("Login") }} + {{ _("Write a review") }} {% elif show_start_learing_cta(course, membership) %}