diff --git a/mood/static/mood/dashboard.js b/mood/static/mood/dashboard.js index 6fbc0c0..c10270c 100644 --- a/mood/static/mood/dashboard.js +++ b/mood/static/mood/dashboard.js @@ -1,5 +1,10 @@ const cal = new CalHeatmap(); +cal.on("click", (event, timestamp, value) => { + const date_str = dayjs(timestamp).format("YYYY-MM-DD"); + window.location.href = "/mood/?from=" + date_str + "&to=" + date_str; +}); + fetch("/mood/statistics/heatmap/values/") .then((response) => response.json()) .then((data) => { diff --git a/mood/views.py b/mood/views.py index 95f4fe5..049fd35 100644 --- a/mood/views.py +++ b/mood/views.py @@ -45,7 +45,22 @@ class StatusListView(LoginRequiredMixin, ListView): return context def get_queryset(self): - return Status.objects.filter(user=self.request.user).order_by("timestamp") + status_list = Status.objects.filter(user=self.request.user).order_by("timestamp") + + if "from" in self.request.GET: + from_timestamp = datetime.strptime(self.request.GET["from"], "%Y-%m-%d") + status_list = status_list.filter( + timestamp__gte=from_timestamp + ) + + if "to" in self.request.GET: + to_timestamp = datetime.strptime(self.request.GET["to"], "%Y-%m-%d") + to_timestamp = to_timestamp.replace(hour=23, minute=59, second=59) + status_list = status_list.filter( + timestamp__lte=self.request.GET["to"] + ) + + return status_list class StatusViewView(LoginRequiredMixin, DetailView):