diff --git a/lms/hooks.py b/lms/hooks.py index 85ac2ded..627cf2df 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -197,7 +197,8 @@ jinja = { "lms.lms.utils.get_courses_under_review", "lms.lms.utils.has_course_instructor_role", "lms.lms.utils.has_course_moderator_role", - "lms.lms.utils.get_certificates" + "lms.lms.utils.get_certificates", + "lms.lms.utils.format_number" ], "filters": [] } diff --git a/lms/lms/utils.py b/lms/lms/utils.py index abc197c3..02452a69 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -419,6 +419,13 @@ def format_amount(amount, currency): return _("{0}k").format(fmt_money(amount_reduced, precision, currency)) +def format_number(number): + number_reduced = number / 1000 + if number_reduced < 1: + return number + return "{0}k".format(frappe.utils.flt(number_reduced, 1)) + + def first_lesson_exists(course): first_chapter = frappe.db.get_value("Chapter Reference", {"parent": course, "idx": 1}, "name") if not first_chapter: diff --git a/lms/lms/web_template/dashboard_stats/__init__.py b/lms/lms/web_template/dashboard_stats/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/lms/web_template/dashboard_stats/dashboard_stats.html b/lms/lms/web_template/dashboard_stats/dashboard_stats.html new file mode 100644 index 00000000..4c1c1843 --- /dev/null +++ b/lms/lms/web_template/dashboard_stats/dashboard_stats.html @@ -0,0 +1 @@ +{% include "lms/templates/dashboard_stats.html" %} diff --git a/lms/lms/web_template/dashboard_stats/dashboard_stats.json b/lms/lms/web_template/dashboard_stats/dashboard_stats.json new file mode 100644 index 00000000..825ee411 --- /dev/null +++ b/lms/lms/web_template/dashboard_stats/dashboard_stats.json @@ -0,0 +1,35 @@ +{ + "__unsaved": 1, + "creation": "2022-09-28 15:30:58.893302", + "docstatus": 0, + "doctype": "Web Template", + "fields": [ + { + "fieldname": "published_courses", + "fieldtype": "Check", + "label": "Published Courses", + "reqd": 0 + }, + { + "fieldname": "total_signups", + "fieldtype": "Check", + "label": "Total Signups", + "reqd": 0 + }, + { + "fieldname": "enrollment_count", + "fieldtype": "Check", + "label": "Enrollment Count", + "reqd": 0 + } + ], + "idx": 0, + "modified": "2022-09-28 17:44:37.982923", + "modified_by": "Administrator", + "module": "LMS", + "name": "Dashboard Stats", + "owner": "Administrator", + "standard": 1, + "template": "", + "type": "Section" +} \ No newline at end of file diff --git a/lms/public/css/style.css b/lms/public/css/style.css index 7e10ceb0..815d04f2 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1726,3 +1726,26 @@ li { .timestamp { font-size: var(--text-xs); } + +.stats-parent { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); + grid-gap: 2rem; +} + +.stats-label { + color: var(--text-muted); + font-weight: bold; +} + +.stats-value { + color: var(--gray-900); + font-weight: 600; + font-size: 2rem; +} + +.stats-card { + display: flex; + flex-direction: column; + align-items: center; +} diff --git a/lms/templates/dashboard_stats.html b/lms/templates/dashboard_stats.html new file mode 100644 index 00000000..b8080650 --- /dev/null +++ b/lms/templates/dashboard_stats.html @@ -0,0 +1,36 @@ +
+ + {% if published_courses %} +
+
+ {{ _("Published Courses") }} +
+
+ {{ format_number(frappe.db.count("LMS Course", { "published": 1, "upcoming": 0 })) }} +
+
+ {% endif %} + + {% if total_signups %} +
+
+ {{ _("Total Signups") }} +
+
+ {{ format_number(frappe.db.count("User", { "enabled": 1 })) }} +
+
+ {% endif %} + + {% if enrollment_count %} +
+
+ {{ _("Enrollment Count") }} +
+
+ {{ format_number(frappe.db.count("LMS Batch Membership")) }} +
+
+ {% endif %} + +
diff --git a/lms/www/dashboard/index.html b/lms/www/dashboard/index.html index b9d0a501..9188faa2 100644 --- a/lms/www/dashboard/index.html +++ b/lms/www/dashboard/index.html @@ -5,6 +5,7 @@ {% block content %} +