Skip to content

Commit

Permalink
fix: dashboard error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedjof committed Oct 15, 2024
1 parent 91cb643 commit a015cd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions analytics/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_urls(self):

@staticmethod
def analytics_view(request):
chart_error = 'No error'
try:
charts = [
Diagrams.map_weekday_hour_diagram(),
Expand All @@ -62,9 +63,9 @@ def analytics_view(request):
Diagrams.machine_types_per_building(),
]
except Exception as e:
print(e)
chart_error = e
charts = []

# States per building

return render(request, 'admin/analytics.html', context={'charts': charts})
return render(request, 'admin/analytics.html', context={'charts': charts, 'chart_error': chart_error})
5 changes: 3 additions & 2 deletions templates/admin/analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
<script>
document.addEventListener("DOMContentLoaded", function() {
const charts = {{ charts|safe }};
const chart_error = {{ chart_error|safe }};
const container = document.getElementById('charts-container');

if (charts.length === 0) {
if (charts.length === 0 && chart_error !== 'No error') {
const noData = document.createElement('p');
noData.textContent = 'No data available or an error occurred while calculating the analytics.';
noData.textContent = `Error: ${chart_error}`;
container.appendChild(noData);
return;
}
Expand Down

0 comments on commit a015cd6

Please sign in to comment.