From 13b968e18c8feb96873192bda759beefb05517e5 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 1 Sep 2021 16:21:55 +0530 Subject: [PATCH 1/6] fix: profile and progress on dashboard --- community/community/widgets/Avatar.html | 2 +- community/hooks.py | 5 ++- .../lms/doctype/lms_course/lms_course.py | 28 +++++++------- community/lms/web_form/profile/profile.js | 2 +- .../course_cards/course_cards.html | 2 +- community/lms/widgets/BatchHeader.html | 4 -- community/lms/widgets/CourseCard.html | 36 ++++++++++++++---- community/lms/widgets/CourseTeaser.html | 2 +- community/lms/widgets/InstructorSection.html | 6 --- community/lms/widgets/MemberCard.html | 2 +- community/lms/widgets/Reviews.html | 2 +- community/overrides/user.py | 19 +++++++++- community/public/css/style.css | 7 +++- community/public/js/profile.js | 6 +++ community/public/js/website.bundle.js | 1 + community/templates/message_card.html | 2 +- community/www/courses/index.html | 2 +- community/www/profiles/profile.html | 38 ++++++++++++++++--- community/www/profiles/profile.py | 9 ++++- 19 files changed, 126 insertions(+), 49 deletions(-) delete mode 100644 community/lms/widgets/BatchHeader.html delete mode 100644 community/lms/widgets/InstructorSection.html create mode 100644 community/public/js/profile.js create mode 100644 community/public/js/website.bundle.js diff --git a/community/community/widgets/Avatar.html b/community/community/widgets/Avatar.html index 59f59a91..b72fc909 100644 --- a/community/community/widgets/Avatar.html +++ b/community/community/widgets/Avatar.html @@ -1,5 +1,5 @@ {% set color = member.get_palette() %} - + {% if member.user_image %} diff --git a/community/hooks.py b/community/hooks.py index 00472b15..31027f41 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -21,7 +21,7 @@ app_license = "AGPL" # include js, css files in header of web template web_include_css = "community.bundle.css" # web_include_css = "/assets/community/css/community.css" -# web_include_js = "/assets/community/js/community.js" +web_include_js = "website.bundle.js" # include custom scss in every website theme (without file extension ".scss") # website_theme_scss = "community/public/scss/website" @@ -142,7 +142,8 @@ website_route_rules = [ {"from_route": "/courses//progress", "to_route": "batch/progress"}, {"from_route": "/courses//join", "to_route": "batch/join"}, {"from_route": "/discussions/", "to_route": "discussions/discussion"}, - {"from_route": "/user/", "to_route": "profiles/profile"}, + {"from_route": "/users/", "to_route": "profiles/profile"}, + {"from_route": "/users", "to_route": "profiles/profile"}, ] website_redirects = [ diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index babbe45b..385bf762 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -187,20 +187,6 @@ class LMSCourse(Document): def get_slugified_chapter_title(self, chapter): return slugify(chapter) - def get_course_progress(self): - """ Returns the course progress of the session user """ - lesson_count = len(self.get_lessons()) - completed_lessons = frappe.db.count("LMS Course Progress", - { - "course": self.name, - "owner": frappe.session.user, - "status": "Complete" - }) - precision = cint(frappe.db.get_default("float_precision")) or 3 - if not lesson_count: - return 0 - return flt(((completed_lessons/lesson_count) * 100), precision) - def get_batch(self, batch_name): return find("LMS Batch", name=batch_name, course=self.name) @@ -340,6 +326,20 @@ class LMSCourse(Document): }, ["status"]) + def get_course_progress(self, member=None): + """ Returns the course progress of the session user """ + lesson_count = len(self.get_lessons()) + completed_lessons = frappe.db.count("LMS Course Progress", + { + "course": self.name, + "owner": member or frappe.session.user, + "status": "Complete" + }) + precision = cint(frappe.db.get_default("float_precision")) or 3 + if not lesson_count: + return 0 + return flt(((completed_lessons/lesson_count) * 100), precision) + def get_neighbours(self, current, lessons): current = flt(current) numbers = sorted(lesson.number for lesson in lessons) diff --git a/community/lms/web_form/profile/profile.js b/community/lms/web_form/profile/profile.js index c9869a5c..984fb964 100644 --- a/community/lms/web_form/profile/profile.js +++ b/community/lms/web_form/profile/profile.js @@ -8,7 +8,7 @@ frappe.ready(function () { frappe.web_form.after_save = () => { setTimeout(() => { - window.location.href = `/user/${frappe.web_form.get_value(["username"])}`; + window.location.href = `/users/${frappe.web_form.get_value(["username"])}`; }) } }) diff --git a/community/lms/web_template/course_cards/course_cards.html b/community/lms/web_template/course_cards/course_cards.html index 3e59bc97..693223e5 100644 --- a/community/lms/web_template/course_cards/course_cards.html +++ b/community/lms/web_template/course_cards/course_cards.html @@ -3,7 +3,7 @@
{% for course_row in courses %} {% set course = frappe.get_doc("LMS Course", course_row.course) %} - {{ widgets.CourseCard(course=course) }} + {{ widgets.CourseCard(course=course, show_progress_indicators=True) }} {% endfor %}
diff --git a/community/lms/widgets/BatchHeader.html b/community/lms/widgets/BatchHeader.html deleted file mode 100644 index a6c99cdc..00000000 --- a/community/lms/widgets/BatchHeader.html +++ /dev/null @@ -1,4 +0,0 @@ -
-

{{batch_name}}

-
{{member_count}} members
-
diff --git a/community/lms/widgets/CourseCard.html b/community/lms/widgets/CourseCard.html index 8fe82fb4..a2618e81 100644 --- a/community/lms/widgets/CourseCard.html +++ b/community/lms/widgets/CourseCard.html @@ -1,6 +1,8 @@ +{% set membership = course.get_membership(frappe.session.user) %} +
-
+
{% for tag in course.get_tags() %}
{{ tag }}
@@ -10,7 +12,9 @@
{{ course.title[0] }}
{% endif %}
+
+ +
{{ course.title }}
+ {% if membership and show_progress_indicators %} + {% set progress = course.get_course_progress() %} +
+
+
+ {% else %}
+ {% endif %} +
- {{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }} - - {{ course.get_instructor().full_name }} + + {{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }} + + + {{ course.get_instructor().full_name }} + + {% if course.get_students() | length %} @@ -42,14 +65,13 @@ {% endif %} {% set avg_rating = course.get_average_rating() %} {% if avg_rating %} - + {{ avg_rating }} {% endif %}
- {% set membership = course.get_membership(frappe.session.user) %} {% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and membership.current_lesson diff --git a/community/lms/widgets/CourseTeaser.html b/community/lms/widgets/CourseTeaser.html index 2b7b54ec..53bc6362 100644 --- a/community/lms/widgets/CourseTeaser.html +++ b/community/lms/widgets/CourseTeaser.html @@ -12,7 +12,7 @@ {% endif %}
{% with author = course.get_instructor() %} - {{ widgets.Avatar(member=author, avatar_class="avatar-medium") }} {{ author.full_name }} + {{ widgets.Avatar(member=author, avatar_class="avatar-medium") }} {{ author.full_name }} {% endwith %}
diff --git a/community/lms/widgets/InstructorSection.html b/community/lms/widgets/InstructorSection.html deleted file mode 100644 index 9c96c294..00000000 --- a/community/lms/widgets/InstructorSection.html +++ /dev/null @@ -1,6 +0,0 @@ -
- {{ widgets.Avatar(member=instructor, avatar_class="avatar-medium") }} - {{ instructor.full_name }} -
Course Creator
- -
diff --git a/community/lms/widgets/MemberCard.html b/community/lms/widgets/MemberCard.html index 77f00556..3ed9ed5d 100644 --- a/community/lms/widgets/MemberCard.html +++ b/community/lms/widgets/MemberCard.html @@ -11,5 +11,5 @@ Created {{ course_count }} {{ suffix }}
{% endif %} - +
diff --git a/community/lms/widgets/Reviews.html b/community/lms/widgets/Reviews.html index f9ba6524..57f08833 100644 --- a/community/lms/widgets/Reviews.html +++ b/community/lms/widgets/Reviews.html @@ -19,7 +19,7 @@ {% endmacro %} + +{% block script %} + +{% endblock %} diff --git a/community/www/profiles/profile.py b/community/www/profiles/profile.py index 2ea2bdd5..1498f215 100644 --- a/community/www/profiles/profile.py +++ b/community/www/profiles/profile.py @@ -4,7 +4,14 @@ def get_context(context): context.no_cache = 1 try: - context.member = frappe.get_doc("User", {"username": frappe.form_dict["username"]}) + username = frappe.form_dict["username"] + except KeyError: + username = frappe.db.get_value("User", frappe.session.user, ["username"]) + if username: + frappe.local.flags.redirect_location = "/users/" + username + raise frappe.Redirect + try: + context.member = frappe.get_doc("User", {"username": username}) except: context.template = "www/404.html" return From e0b25c1e6e541d78e2b84624d263a4cf8a5b145f Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 1 Sep 2021 16:50:27 +0530 Subject: [PATCH 2/6] fix: certificate link --- community/lms/widgets/CourseCard.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community/lms/widgets/CourseCard.html b/community/lms/widgets/CourseCard.html index a2618e81..38a51591 100644 --- a/community/lms/widgets/CourseCard.html +++ b/community/lms/widgets/CourseCard.html @@ -31,7 +31,7 @@ {% endif %} {% set certificate = course.is_certified() %} {% if certificate and show_progress_indicators %} - View + Get Certificate {% endif %}
From 3a2ebd42a74a532b30f1c52c2c6c0f11a4c90874 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 2 Sep 2021 13:26:45 +0530 Subject: [PATCH 3/6] fix: progress pill and certificate secondary cta --- .../course_cards/course_cards.html | 2 +- community/lms/widgets/CourseCard.html | 33 +++++++------- community/public/css/style.css | 10 ++--- community/www/courses/index.html | 2 +- community/www/profiles/profile.html | 45 ++++++++++--------- 5 files changed, 45 insertions(+), 47 deletions(-) diff --git a/community/lms/web_template/course_cards/course_cards.html b/community/lms/web_template/course_cards/course_cards.html index 693223e5..437ab432 100644 --- a/community/lms/web_template/course_cards/course_cards.html +++ b/community/lms/web_template/course_cards/course_cards.html @@ -3,7 +3,7 @@
{% for course_row in courses %} {% set course = frappe.get_doc("LMS Course", course_row.course) %} - {{ widgets.CourseCard(course=course, show_progress_indicators=True) }} + {{ widgets.CourseCard(course=course, read_only=False) }} {% endfor %}
diff --git a/community/lms/widgets/CourseCard.html b/community/lms/widgets/CourseCard.html index 38a51591..e73a46f2 100644 --- a/community/lms/widgets/CourseCard.html +++ b/community/lms/widgets/CourseCard.html @@ -7,6 +7,10 @@ {% for tag in course.get_tags() %}
{{ tag }}
{% endfor %} + {% set progress = course.get_course_progress() %} + {% if membership and not read_only %} +
{{ frappe.utils.rounded(progress) }}%
+ {% endif %} {% if not course.image %}
{{ course.title[0] }}
@@ -29,25 +33,11 @@ {{ course.get_upcoming_batches() | length }} Open Batches {% endif %} - {% set certificate = course.is_certified() %} - {% if certificate and show_progress_indicators %} - Get - Certificate - {% endif %}
{{ course.title }}
- {% if membership and show_progress_indicators %} - {% set progress = course.get_course_progress() %} -
-
-
- {% else %} -
- {% endif %} - + {% endif %} {% endif %} + diff --git a/community/public/css/style.css b/community/public/css/style.css index ef6b463a..e7e47d22 100644 --- a/community/public/css/style.css +++ b/community/public/css/style.css @@ -76,7 +76,6 @@ input[type=checkbox] { border-radius: 4px; padding: 4px 6px; font-size: 10px; - line-height: 120%; text-align: center; letter-spacing: 0.011em; text-transform: uppercase; @@ -85,6 +84,15 @@ input[type=checkbox] { box-shadow: 0px 5px 10px rgb(0 0 0 / 10%); } +.dark-pills { + background: rgba(25, 39, 52, 0.8); + color: #ffffff; +} +.dark-pills img { + width: 0.75rem; + height: 0.75rem; +} + .common-page-style { background: #F4F5F6; padding-bottom: 5rem; @@ -172,6 +180,7 @@ input[type=checkbox] { padding: 8px 0px 8px; text-align: center; line-height: 135%; + cursor: pointer; } .cards-parent { diff --git a/community/www/profiles/profile.py b/community/www/profiles/profile.py index 1498f215..73ea980f 100644 --- a/community/www/profiles/profile.py +++ b/community/www/profiles/profile.py @@ -1,4 +1,5 @@ import frappe +from community.page_renderers import get_profile_url_prefix def get_context(context): context.no_cache = 1 @@ -8,7 +9,7 @@ def get_context(context): except KeyError: username = frappe.db.get_value("User", frappe.session.user, ["username"]) if username: - frappe.local.flags.redirect_location = "/users/" + username + frappe.local.flags.redirect_location = get_profile_url_prefix() + username raise frappe.Redirect try: context.member = frappe.get_doc("User", {"username": username}) From 6a2c749a8695d51dd81cc3ecbc005fe79852d117 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 10 Sep 2021 19:46:48 +0530 Subject: [PATCH 6/6] fix: formatting --- community/lms/widgets/CourseCard.html | 178 +++++++++++++------------- 1 file changed, 91 insertions(+), 87 deletions(-) diff --git a/community/lms/widgets/CourseCard.html b/community/lms/widgets/CourseCard.html index d1bc96f8..3934316f 100644 --- a/community/lms/widgets/CourseCard.html +++ b/community/lms/widgets/CourseCard.html @@ -2,8 +2,8 @@ {% set progress = course.get_course_progress() %}
-
+
{% for tag in course.get_tags() %}
{{ tag }}
@@ -21,102 +21,105 @@ {% endif %}
-
-
- {% if course.get_chapters() | length %} - - {{ course.get_chapters() | length }} Chapters - - {% endif %} - {% if course.get_chapters() | length and course.get_upcoming_batches() | length %} - . - {% endif %} - {% if course.get_upcoming_batches() | length %} - - {{ course.get_upcoming_batches() | length }} Open Batches - - {% endif %} -
-
{{ course.title }}
-
- - {{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }} - - - {{ course.get_instructor().full_name }} - - - - - {% if course.get_students() | length %} - - - {{ course.get_students() | length }} - {% endif %} - {% set avg_rating = course.get_average_rating() %} - {% if avg_rating %} - - - {{ avg_rating }} +
+
+ {% if course.get_chapters() | length %} + + {{ course.get_chapters() | length }} Chapters {% endif %} - + {% if course.get_chapters() | length and course.get_upcoming_batches() | length %} + . + {% endif %} + {% if course.get_upcoming_batches() | length %} + + {{ course.get_upcoming_batches() | length }} Open Batches + + {% endif %} +
+
{{ course.title }}
+
+ + {{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }} + + + {{ course.get_instructor().full_name }} + + + + + {% if course.get_students() | length %} + + + {{ course.get_students() | length }} + {% endif %} + {% set avg_rating = course.get_average_rating() %} + {% if avg_rating %} + + + {{ avg_rating }} + + {% endif %} + +
+ + {% if not read_only %} + + {% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and + membership.current_lesson else '1.1' %} + {% set query_parameter = "?batch=" + membership.batch if membership and + membership.batch else "" %} + {% set certificate = course.is_certified() %} + + {% if certificate %} + + + + {% elif course.enable_certification and progress == 100 %} + + + {% elif progress == 100 %} + + + + {% elif course.upcoming %} + + + + {% elif membership %} + + + + {% else %} + + + + {% endif %} + {% endif %}
- - {% if not read_only %} - - {% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and - membership.current_lesson else '1.1' %} - {% set query_parameter = "?batch=" + membership.batch if membership and - membership.batch else "" %} - {% set certificate = course.is_certified() %} - - {% if certificate %} - - - - {% elif course.enable_certification and progress == 100 %} - - - {% elif progress == 100 %} - - - - {% elif course.upcoming %} - - - - {% elif membership %} - - - - {% else %} - - - - {% endif %} - {% endif %} -
+