From 124e629f4a0f5e40813c767fbdceca45cb64cbb1 Mon Sep 17 00:00:00 2001 From: Sallu9007 Date: Tue, 13 May 2025 18:27:52 +0530 Subject: [PATCH] Feat: clickable graphs --- resources/views/admin/dashboard.blade.php | 35 ++++++++++++++++++- .../pages/activities-attended/index.blade.php | 17 ++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index b80e8c3..66e1e2f 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -90,6 +90,18 @@ if (window.comparisonChartInstance) { window.comparisonChartInstance.destroy(); } + // Map each bar to its corresponding page + const modelPages = [ + 'ActivitiesAttendedResponses', + 'ActivitiesOrganisedResponses', + 'BooksPublishedResponses', + 'ExternalEngagementResponses', + 'IvOrganisedResponses', + 'OnlineCoursesResponses', + 'PatentsResponses', + 'PublicationsResponses' + ]; + const barLinks = modelPages.map(page => `/admin/${page}`); window.comparisonChartInstance = new Chart(ctx, { type: 'bar', data: { @@ -152,6 +164,16 @@ y: { beginAtZero: true } + }, + onClick: function(evt, elements) { + if (elements.length > 0) { + const idx = elements[0].index; + const departmentId = departmentSelector.value; + // Only redirect if the bar index is within the modelPages range + if (idx < barLinks.length) { + window.location.href = `${barLinks[idx]}?department_id=${departmentId}`; + } + } } } }); @@ -192,8 +214,13 @@ if (window.contributionChartInstance) { window.contributionChartInstance.destroy(); } + // Define bar links for each label (customize as needed) + const barLinks = data.labels.map((label, idx) => { + // Example: redirect to /admin/contribution/{id} (replace with your actual route/logic) + return `/admin/contribution/${data.ids ? data.ids[idx] : idx+1}`; + }); window.contributionChartInstance = new Chart(ctx, { - type: 'bar', // Changed to bar chart + type: 'bar', data: { labels: data.labels, datasets: [{ @@ -258,6 +285,12 @@ y: { beginAtZero: true } + }, + onClick: function(evt, elements) { + if (elements.length > 0) { + const idx = elements[0].index; + window.location.href = barLinks[idx]; + } } } }); diff --git a/resources/views/pages/activities-attended/index.blade.php b/resources/views/pages/activities-attended/index.blade.php index 8351cce..d80b419 100644 --- a/resources/views/pages/activities-attended/index.blade.php +++ b/resources/views/pages/activities-attended/index.blade.php @@ -48,9 +48,11 @@ - + -
+
+ +
- - @@ -685,6 +685,15 @@ $('.dropdown-menu').on('click', function(e) { e.stopPropagation(); }); + + // Set department filter from query string if present + $(document).ready(function() { + const urlParams = new URLSearchParams(window.location.search); + const departmentId = urlParams.get('department_id'); + if (departmentId) { + $('#department-filter').val(departmentId).trigger('change'); + } + }); });