From f37229c20299adb51ea41a306a4562082f57714b Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 14 Oct 2022 20:33:27 +0530 Subject: [PATCH] feat: statistics section --- lms/hooks.py | 2 +- .../new_signups/new_signups.json | 32 ++++++++++++++++ lms/public/css/style.css | 23 +++++------ lms/templates/statistics.html | 6 +-- lms/templates/stats.html | 16 ++++++++ lms/www/courses/course.html | 6 +++ lms/www/courses/index.html | 14 ++++++- lms/www/courses/index.js | 38 +++++++++++++++++++ 8 files changed, 120 insertions(+), 17 deletions(-) create mode 100644 lms/lms/dashboard_chart/new_signups/new_signups.json create mode 100644 lms/templates/stats.html create mode 100644 lms/www/courses/index.js diff --git a/lms/hooks.py b/lms/hooks.py index db6a33de..6d5b87f1 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -21,7 +21,7 @@ app_license = "AGPL" # include js, css files in header of web template web_include_css = "lms.bundle.css" # web_include_css = "/assets/lms/css/lms.css" -web_include_js = ["website.bundle.js", "controls.bundle.js"] +web_include_js = ["website.bundle.js"] # include custom scss in every website theme (without file extension ".scss") # website_theme_scss = "lms/public/scss/website" diff --git a/lms/lms/dashboard_chart/new_signups/new_signups.json b/lms/lms/dashboard_chart/new_signups/new_signups.json new file mode 100644 index 00000000..a72c7438 --- /dev/null +++ b/lms/lms/dashboard_chart/new_signups/new_signups.json @@ -0,0 +1,32 @@ +{ + "based_on": "creation", + "chart_name": "New Signups", + "chart_type": "Count", + "color": "#4463F0", + "creation": "2021-09-28 18:57:50.047656", + "docstatus": 0, + "doctype": "Dashboard Chart", + "document_type": "User", + "dynamic_filters_json": "[]", + "filters_json": "[]", + "group_by_type": "Count", + "idx": 1, + "is_public": 1, + "is_standard": 1, + "last_synced_on": "2022-10-14 15:57:47.583435", + "modified": "2022-10-14 17:20:21.880532", + "modified_by": "Administrator", + "module": "LMS", + "name": "New Signups", + "number_of_groups": 0, + "owner": "basawaraj@erpnext.com", + "roles": [], + "source": "", + "time_interval": "Daily", + "timeseries": 1, + "timespan": "Last Quarter", + "type": "Line", + "use_report_chart": 0, + "value_based_on": "", + "y_axis": [] +} \ No newline at end of file diff --git a/lms/public/css/style.css b/lms/public/css/style.css index 6a6846a5..166170a5 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -1713,25 +1713,20 @@ li { .stats-parent { display: grid; - grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; } .stats-label { - color: var(--text-muted); - font-weight: bold; + color: var(--gray-900); + font-weight: 500; } .stats-value { color: var(--gray-900); - font-weight: 600; - font-size: 2rem; -} - -.stats-card { - display: flex; - flex-direction: column; - align-items: center; + font-weight: 500; + font-size: 1.5rem; + margin-top: 2rem; } .indicator-pill.green::before { @@ -1774,3 +1769,9 @@ li { .modal-header .modal-title { color: var(--gray-900); } + +.frappe-chart .title { + font-size: 1rem; + font-weight: bold; + color: var(--gray-900); +} diff --git a/lms/templates/statistics.html b/lms/templates/statistics.html index b8080650..252d3ac3 100644 --- a/lms/templates/statistics.html +++ b/lms/templates/statistics.html @@ -1,7 +1,7 @@
{% if published_courses %} -
+
{{ _("Published Courses") }}
@@ -12,7 +12,7 @@ {% endif %} {% if total_signups %} -
+
{{ _("Total Signups") }}
@@ -23,7 +23,7 @@ {% endif %} {% if enrollment_count %} -
+
{{ _("Enrollment Count") }}
diff --git a/lms/templates/stats.html b/lms/templates/stats.html new file mode 100644 index 00000000..e35591c1 --- /dev/null +++ b/lms/templates/stats.html @@ -0,0 +1,16 @@ +{% set published_courses = True %} +{% set total_signups = True %} +{% set enrollment_count = True %} + +
+ {% include "lms/templates/statistics.html" %} + +
+
+
+
+
+
+
+
+
diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index be5fac09..0cc4c4e1 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -423,3 +423,9 @@
{% endmacro %} + + +{%- block script %} + {{ super() }} + {{ include_script('controls.bundle.js') }} +{% endblock %} diff --git a/lms/www/courses/index.html b/lms/www/courses/index.html index 8ae83339..aeaf8392 100644 --- a/lms/www/courses/index.html +++ b/lms/www/courses/index.html @@ -42,7 +42,7 @@
-
+
{% set courses = live_courses %} {% set title = _("Live Courses") %} {% set classes = "live-courses" %} @@ -113,6 +119,10 @@
{% endif %} +
+ {% include "lms/templates/stats.html" %} +
+
{% endif %} diff --git a/lms/www/courses/index.js b/lms/www/courses/index.js new file mode 100644 index 00000000..5e7204df --- /dev/null +++ b/lms/www/courses/index.js @@ -0,0 +1,38 @@ + +frappe.ready(() => { + generate_graph("New Signups"); + generate_graph("Course Enrollments"); +}); + + +const generate_graph = (chart_name) => { + let date = frappe.datetime; + + frappe.call({ + method: "frappe.desk.doctype.dashboard_chart.dashboard_chart.get", + args: { + "chart_name": chart_name, + "timespan": "Select Date Range", + "from_date": date.add_days(date.get_today(), -30), + "to_date": date.get_today() + }, + callback: (data) => { + render_chart(data.message, chart_name); + } + }); +}; + + +const render_chart = (data, chart_name) => { + let dom_element = chart_name == "Course Enrollments" ? "#course-enrollments" : "#new-signups" + const chart = new frappe.Chart(dom_element, { + title: chart_name, + data: data, + type: 'line', + height: 250, + colors: ['#2490ef'], + axisOptions: { + xIsSeries: 1, + }, + }); +};