Skip to content

Commit

Permalink
Move remaining logic in the dashboard to react
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jan 26, 2024
1 parent 79fd15f commit 70ed3f3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 238 deletions.
2 changes: 1 addition & 1 deletion wger/core/static/react/locales/de/translation.json
Expand Up @@ -54,7 +54,7 @@
"changeExerciseLanguage": "Ändere die Sprache dieser Übung",
"identicalExercise": "Vermeide doppelte Übungen",
"cacheWarning": "Aufgrund von Caching kann es einige Zeit dauern, bis Änderungen in der ganzen Anwendung sichtbar sind.",
"replacements": "Ersätze",
"replacements": "Ersätzen",
"replacementsInfoText": "Optional können Sie auch eine Übung auswählen, die diese ersetzen soll (z. B. weil sie zweimal eingereicht wurde oder ähnliches). Dadurch wird die Übung in Routinen sowie Trainingsprotokollen ersetzt, anstatt sie einfach zu löschen. Diese Änderungen werden auch auf alle Instanzen übertragen, die die Übungen von dieser übernehmen.",
"replacementsSearch": "Suche nach Übungen oder kopiere eine Bekannte ID in das Feld und drücke den \"Laden\" Button.",
"noReplacementSelected": " Keine Übung zum ersätzen ausgewählt"
Expand Down
2 changes: 1 addition & 1 deletion wger/core/static/react/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wger/core/static/react/main.js

Large diffs are not rendered by default.

117 changes: 4 additions & 113 deletions wger/core/templates/index.html
Expand Up @@ -12,129 +12,20 @@


{% block content %}
{% if current_workout %}
<div class="modal fade" id="calendar-day-select-popup">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{% translate 'Add log to day' %}</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>{% blocktranslate %}Click to add weight logs to a training
day in your current workout:{% endblocktranslate %} <strong>{{ current_workout }}</strong>
</p>

{% for day in current_workout.day_set.all %}
<a href="{% url 'manager:day:log' day.pk %}"
class="btn btn-block btn-light">{{ day.description }}</a>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-light"
data-bs-dismiss="modal">
{% translate "Close" %}
</button>
</div>
</div>
</div>
</div>
{% endif %}



<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{% translate "Workout" %}</h5>
<div class="card-text">
{% if current_workout %}
<p>
<a href="{{ current_workout.get_absolute_url }}">
{% if current_workout.comment %}
{{ current_workout.comment }}
{% else %}
{% translate "Workout" %}
{% endif %}
</a>
</p>
<p>
– {{ current_workout.created }}
<p>
{% endif %}

<table class="table table-hover table-sm">
{% for day, exercise, is_workout in weekdays %}
<tr>
<td>
{{ day }}
</td>
<td>
{% if not is_workout %}<span class="text-muted">{% endif %}
{{ exercise }}
{% if not is_workout %}</span>{% endif %}
</td>
</tr>
{% endfor %}
</table>

{% if schedule %}
<p>
→ {% translate "This workout is part of a schedule:" %}
<a href="{{ schedule.get_absolute_url }}">{{ schedule.name }}</a>
</p>
{% endif %}
<p><em>
{% blocktranslate trimmed %}The current workout is selected from your active
schedule or, if you don't have one, simply by date.{% endblocktranslate %}
</em></p>
</div>
</div>
<div class="card-footer">
{% if current_workout %}
{% if current_workout.day_set.all %}
<a href="#"
id="logging-popup-link"
data-bs-toggle="modal"
data-bs-target="#calendar-day-select-popup"
class="btn btn-success btn-sm btn-block">
{% translate "Add new log" %}
</a>
{% endif %}
{% else %}
<a href="{% url 'manager:workout:add' %}" class="btn btn-sm btn-success">
{% translate "No workouts found." %} {% translate "Add one now." %}
</a>
{% endif %}
</div>
</div>
<div id="react-routine-dashboard"></div>
</div>


<div class="col-sm-6 col-md-4">
<div id="react-nutrition-dashboard"></div>
</div>


<div class="col-sm-12 col-md-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{% translate "Weight" %}</h5>
<div class="card-text">
<div id="react-weight-dashboard"></div>
</div>
</div>
<div class="card-footer">
<a href="{% url 'weight:add' %}" class="btn btn-success btn-sm wger-modal-dialog" role="button">
{% translate "Add weight entry" %}
</a>
</div>
</div>
<div class="col-sm-6 col-md-4">
<div id="react-weight-dashboard"></div>
</div>

</div>
</div>

{% endblock %}
90 changes: 0 additions & 90 deletions wger/core/tests/test_index.py

This file was deleted.

32 changes: 1 addition & 31 deletions wger/core/views/misc.py
Expand Up @@ -50,7 +50,6 @@
from wger.core.models import DaysOfWeek
from wger.manager.models import Schedule


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -107,36 +106,7 @@ def dashboard(request):
Show the index page, in our case, the last workout and nutritional plan
and the current weight
"""

context = {}

# Load the last workout, either from a schedule or a 'regular' one
(current_workout, schedule) = Schedule.objects.get_current_workout(request.user)

context['current_workout'] = current_workout
context['schedule'] = schedule

# Format a bit the days, so it doesn't have to be done in the template
used_days = {}
if current_workout:
for day in current_workout.day_set.select_related():
for day_of_week in day.day.select_related():
used_days[day_of_week.id] = day.description

week_day_result = []
for week in DaysOfWeek.objects.all():
day_has_workout = False

if week.id in used_days:
day_has_workout = True
week_day_result.append((_(week.day_of_week), used_days[week.id], True))

if not day_has_workout:
week_day_result.append((_(week.day_of_week), _('Rest day'), False))

context['weekdays'] = week_day_result

return render(request, 'index.html', context)
return render(request, 'index.html')


class FeedbackClass(FormView):
Expand Down

0 comments on commit 70ed3f3

Please sign in to comment.