From 8d92aa3b24ec6ed7d5e7ae7ba86bb0d28af8ab3f Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 4 Apr 2024 17:03:34 +0530 Subject: [PATCH] [UPDT] LEAVE: Updated department chart and leave chart to change with selected month --- leave/static/dashboard/dashboard.js | 72 ++++++++++++++++++- leave/templates/leave/dashboard.html | 41 +++++------ .../dashboard_leave_requests.html | 14 ++-- 3 files changed, 93 insertions(+), 34 deletions(-) diff --git a/leave/static/dashboard/dashboard.js b/leave/static/dashboard/dashboard.js index 3f5a74874..9fc1f9a2a 100644 --- a/leave/static/dashboard/dashboard.js +++ b/leave/static/dashboard/dashboard.js @@ -19,6 +19,8 @@ $(document).ready(function () { year = today.getFullYear(); $(".month").val(`${year}-${month}`); $("#dash_month").val(`${year}-${month}`); + $("#dash_department_month").val(`${year}-${month}`); + $("#dash_leave_type_month").val(`${year}-${month}`); function isChartEmpty(chartData) { if (!chartData) { @@ -189,7 +191,7 @@ $(document).ready(function () { $("#employee_leave_canvas").html( `
- +

${response.message}

` @@ -213,7 +215,7 @@ $(document).ready(function () { $("#availableLeaveContainer").html( `
- +

${response.message}

` @@ -280,7 +282,7 @@ $(document).ready(function () { $("#employee_leave_canvas").html( `
- +

${response.message}

` @@ -383,4 +385,68 @@ $(document).ready(function () { }); }); + $("#dash_department_month").on("change", function () { + let month = $(this).val(); + $.ajax({ + type: "GET", + url: "/leave/department-leave-chart", + dataType: "json", + data: { + date: month, + }, + success: function (response) { + if (isChartEmpty(response.dataset)) { + $("#department_leave_canvas").html( + `
+
+ +

${response.message}

+
+
` + ); + } else { + $("#department_leave_canvas").html( + '' + ); + department_leave_chart(response); + } + }, + error: (error) => { + console.log("Error", error); + }, + }); + }); + + $("#dash_leave_type_month").on("change", function () { + let month = $(this).val(); + $.ajax({ + type: "GET", + url: "/leave/leave-type-chart", + dataType: "json", + data: { + date: month, + }, + success: function (response) { + if (isChartEmpty(response.dataset)) { + $("#leave_type_canvas").html( + `
+
+ +

${response.message}

+
+
` + ); + } else { + $("#leave_type_canvas").html( + '' + ); + leave_type_chart(response); + } + }, + error: (error) => { + console.log("Error", error); + }, + }); + }); + }); diff --git a/leave/templates/leave/dashboard.html b/leave/templates/leave/dashboard.html index fb2615072..2b19066a0 100644 --- a/leave/templates/leave/dashboard.html +++ b/leave/templates/leave/dashboard.html @@ -79,7 +79,9 @@ {% trans "Employee Leaves" %} - +
+ +
@@ -87,7 +89,6 @@
-
{% trans "On Leave" %}
@@ -115,8 +116,7 @@

{% trans "Today is a holiday." %}

- - {% else %} + {% else %}
@@ -126,7 +126,6 @@ {% endif %}
-
@@ -154,7 +153,7 @@ {% trans "Next Holiday" %} {{next_holiday.name}} {{next_holiday.start_date}} -
+ @@ -191,9 +190,7 @@ {% trans "Department Leaves" %}
- {% if leave_today_employees %} - - {% elif current_date == next_holiday.start_date|date:"Y-m-d" %} + {% if current_date == next_holiday.start_date|date:"Y-m-d" %}
@@ -201,11 +198,11 @@
{% else %} -
-
- -

{% trans "No leave requests for today." %}

-
+
+ +
+
+
{% endif %}
@@ -214,19 +211,15 @@
- {% trans "Leave Type - Count of approved leaves" %} + {% trans "Leave Type - Count of leaves" %}
- {% if leave_requests %} - - {% else %} -
-
- -

{% trans "No leave requests for any leave type this month." %}

-
+
+ +
+
+
- {% endif %}
diff --git a/leave/templates/leave/leave_request/dashboard_leave_requests.html b/leave/templates/leave/leave_request/dashboard_leave_requests.html index 0897aca2e..b59075c38 100644 --- a/leave/templates/leave/leave_request/dashboard_leave_requests.html +++ b/leave/templates/leave/leave_request/dashboard_leave_requests.html @@ -18,8 +18,8 @@
{% for leave_request in leave_requests %} -
+
@@ -30,11 +30,11 @@ {{leave_request.employee_id}}
-
{{leave_request.leave_type_id}}
-
{{leave_request.start_date}}
-
{{leave_request.end_date}}
-
{{leave_request.requested_days}}
-
+
{{leave_request.leave_type_id}}
+
{{leave_request.start_date}}
+
{{leave_request.end_date}}
+
{{leave_request.requested_days}}
+
{% if leave_request.multiple_approvals and leave_request.status == "requested" %}
{{leave_request.multiple_approvals.approved|length}} / {{leave_request.multiple_approvals.managers|length}} {% trans "Approved" %}