Skip to content

Commit

Permalink
add ability to refresh heartrate
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Jan 22, 2025
1 parent 751b3c0 commit be24921
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions activity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
urlpatterns = [
path("integrations/", views.IntegrationsListView.as_view(), name="integrations"),
path("<slug:code>/callback/", views.IntegrationCallbackView.as_view(), name="integration-callback"),
path("heartrate/refresh/<slug:match_id>/", views.update_heartrate, name="update-heartrate"),
]
16 changes: 15 additions & 1 deletion activity/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.contrib import messages
from django.core.exceptions import BadRequest
from django.urls import reverse
from django.views import generic
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from rest_framework.generics import get_object_or_404
from django_htmx.http import HttpResponseClientRefresh

from activity.models import Application, ApplicationToken
from activity.models import Application, ApplicationToken, Heartrate
from match.models import Match


class IntegrationsListView(LoginRequiredMixin, generic.TemplateView):
Expand Down Expand Up @@ -48,3 +53,12 @@ def handle_callback(self, request):
application = Application.objects.get(code=code.upper())
api = application.api
token = api.handle_authorize_request(request)


@login_required
def update_heartrate(request, match_id):
if not request.method == 'POST':
raise BadRequest("Invalid method.")
match = get_object_or_404(Match, _id=match_id)
Heartrate.objects.import_hr_for_match(match, request.user)
return HttpResponseClientRefresh()
4 changes: 4 additions & 0 deletions match/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ def slug(self):
def __str__(self):
return f"Match(_id={self._id}, queue_id={self.queue_id}, game_version={self.game_version})"

@property
def external_id(self):
return self._id

@property
def result(self):
match self.end_of_game_result:
Expand Down
17 changes: 15 additions & 2 deletions templates/cotton/match/team_gold_chart.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
<c-vars id="team-gold-chart" />

<canvas id="{{ id }}">
</canvas>
<div id="{{ id }}-chart" class="flex flex-col h-full">

<div class="relative flex-grow">
<canvas id="{{ id }}" class="absolute inset-0 w-full h-full">
</canvas>
</div>
{% if heartrate %}
<form hx-post="{% url 'activity:update-heartrate' match_id=object.external_id %}">
{% csrf_token %}
<button class="btn btn-default" type="submit">refresh HR</button>
</form>
{% endif %}

</div>


<script>
(function() {
Expand Down

0 comments on commit be24921

Please sign in to comment.