From e4ee75c7eedd7fd795ffcb8f1a3c39dc8a32618a Mon Sep 17 00:00:00 2001 From: bobbyvish Date: Wed, 15 May 2024 17:31:26 +0530 Subject: [PATCH] refactor: user report filter --- templates/module_auth/user_view.html | 64 ++++++++++++------- templates/module_cms/faq.html | 5 +- ...am_principal_resource_permission_edit.html | 1 + templates/module_support/feedback.html | 25 +++----- 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/templates/module_auth/user_view.html b/templates/module_auth/user_view.html index 3cb0290..d8880ef 100644 --- a/templates/module_auth/user_view.html +++ b/templates/module_auth/user_view.html @@ -346,17 +346,25 @@
+
@@ -393,13 +401,21 @@ var mealUrl = "{% url 'module_activity:meal_detail' pk=0 %}" var medicationUrl = "{% url 'module_activity:medication_detail' pk=0 %}" var bowelUrl = "{% url 'module_activity:bowel_detail' pk=0 %}" var symptomUrl = "{% url 'module_activity:meal_symptom_detail' pk=0 %}" -var reportUrl = "{% url 'module_activity:report_data' principal_id=obj.id %}?date_range=20" +var reportUrl = "{% url 'module_activity:report_data' principal_id=obj.id %}?date_range=date_range_data" // Entry point $(document).ready(function() { tableName = $('#table'); //dataTableInstance = initializeDataTable(tableName, activityMainUrl); - //getReportData(); + + var selectedDays = $('input[name="dateFilter"]:checked').val(); + getReportData(selectedDays); + + $('input[name="dateFilter"]').change(function() { + selectedDays = $(this).val(); + console.log(selectedDays) + getReportData(selectedDays); + }); }); // Function to initialize DataTable @@ -523,17 +539,20 @@ function filterActivityData(dateRange){ */ -function getReportData(timeRange){ - console.log("data range is ", timeRange) - var url = timeRange ? reportUrl.replace("7", timeRange) : reportUrl +function getReportData(days){ + console.log("data range is ", days) + var url = days ? reportUrl.replace("date_range_data", days) : reportUrl $('#pills-tab3Content').empty() + // Show loader + $('#loaderContainer').show(); $.ajax({ url: url, type: 'GET', success: function(response) { - console.log("reposne is ", response); + // Hide loader + $('#loaderContainer').hide(); if (response.status == 200){ - setReportContent(response.data) + setReportContent(response.data, days) } if (response.status == 202){ const errorCard = $('
'); @@ -548,12 +567,13 @@ function getReportData(timeRange){ } }, error: function(response) { - + // Hide loader + $('#loaderContainer').hide(); } }); } -function setReportContent(data) { +function setReportContent(data, days) { // Clear previous content $('#pills-tab3Content').empty(); @@ -562,7 +582,7 @@ function setReportContent(data) { const section = $('
'); if (data.food_avoid) { - createFoodToAvoid(section, data.food_avoid); + createFoodToAvoid(section, data.food_avoid, days); } if (data.highest_stool) { @@ -590,13 +610,13 @@ function setReportContent(data) { $('#pills-tab3Content').append(tableSection); } -function createFoodToAvoid(parent, content) { +function createFoodToAvoid(parent, content, days) { const col = $('
'); const title = $('
').text('Foods to Avoid'); const img = $('').attr('src', "{% static 'img/foods.png' %}"); const h4 = $('

').text(content); const h6 = $('
').html( - 'Based on the Symptoms added within the last 7 days, ' + content + ' should be avoided.' + 'Based on the Symptoms added within the last '+ days +' days, ' + content + ' should be avoided.' ); col.append(title); diff --git a/templates/module_cms/faq.html b/templates/module_cms/faq.html index 316d371..bfe5eb3 100644 --- a/templates/module_cms/faq.html +++ b/templates/module_cms/faq.html @@ -73,7 +73,7 @@