Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show muscle on top of exercise list

Roland Geider9114ed888c3f
diff --git a/wger/core/static/js/wger-core.js b/wger/core/static/js/wger-core.js
index a05cf5718..fb08dad8f 100644
--- a/wger/core/static/js/wger-core.js
+++ b/wger/core/static/js/wger-core.js
@@ -599,16 +599,6 @@ function wgerLoadMaincontent() {
});
}
-/*
- Helper function to prefetch images on a page
- */
-function wgerPrefetchImages(imageArray) {
- $(imageArray).each(function () {
- (new Image()).src = this;
- // console.log('Preloading image' + this);
- });
-}
-
/*
Helper function used in the workout log dialog to fetch existing workout sessions through the
REST API
diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.html
index 063b03560..c7f4ecf3a 100644
--- a/wger/core/templates/navigation.html
+++ b/wger/core/templates/navigation.html
@@ -17,7 +17,7 @@
<a href="{% url 'manager:workout:overview' %}"
rel="nofollow"
class="dropdown-toggle nav-link"
- data-toggle="dropdown">{% trans "Workouts" %} <b class="caret"></b></a>
+ data-toggle="dropdown">{% trans "Training" %} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{% url 'manager:workout:overview' %}" rel="nofollow">{% trans "Workouts" %}</a></li>
<li><a class="dropdown-item" href="{% url 'manager:workout:calendar' user.username %}" rel="nofollow">{% trans "Calendar" %}</a></li>
diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.py
index cd9c5d910..a8f038b83 100644
--- a/wger/core/templatetags/wger_extras.py
+++ b/wger/core/templatetags/wger_extras.py
@@ -17,6 +17,7 @@
# Django
from django import template
from django.conf import settings
+from django.db.models import QuerySet
from django.utils.html import strip_spaces_between_tags
from django.utils.safestring import mark_safe
from django.utils.translation import (
@@ -109,6 +110,25 @@ def license_sidebar(license, author=None):
'author': author}
[email protected]_tag('tags/muscles.html')
+def render_muscles(muscles_main, muscles_sec=None):
+ """
+ Renders the given muscles
+ """
+ out_main = muscles_main if isinstance(muscles_main, (list, tuple, QuerySet)) else [muscles_main]
+ muscles_sec = muscles_sec if muscles_sec is not None else []
+
+ out_sec = muscles_sec if isinstance(muscles_sec, (list, tuple, QuerySet)) else [muscles_sec]
+ front_back = "front" if out_main[0].is_front else "back"
+ backgrounds_main = ["images/muscles/main/muscle-{}.svg".format(i.id) for i in out_main]
+ backgrounds_sec = ["images/muscles/secondary/muscle-{}.svg".format(i.id) for i in out_sec]
+ backgrounds = backgrounds_main + backgrounds_sec
+ backgrounds.append("images/muscles/muscular_system_{}.svg".format(front_back))
+
+ return {"backgrounds": backgrounds}
+
+
+
@register.inclusion_tag('tags/language_select.html', takes_context=True)
def language_select(context, language):
"""
diff --git a/wger/exercises/static/js/exercises.js b/wger/exercises/static/js/exercises.js
index 7ff3a01f7..7982d560a 100644
--- a/wger/exercises/static/js/exercises.js
+++ b/wger/exercises/static/js/exercises.js
@@ -20,37 +20,6 @@
'use strict';
-/*
- Highlight a muscle in the overview
- */
-function wgerHighlightMuscle(element) {
- var $muscle;
- var muscleId;
- var isFront;
- var divId;
- divId = $(element).data('target');
- isFront = ($(element).data('isFront') === 'True') ? 'front' : 'back';
- muscleId = divId.match(/\d+/);
-
- // Reset all other highlighted muscles
- $muscle = $('.muscle');
- $muscle.removeClass('active');
- $muscle.addClass('inactive');
-
- // Highlight the current one
- $(element).removeClass('inactive');
- $(element).addClass('active');
-
- // Set the corresponding background
- $('#muscle-system').css('background-image',
- 'url({{ STATIC_URL | escapejs }}images/muscles/main/muscle-' + muscleId + '.svg),' +
- 'url({{ STATIC_URL | escapejs }}images/muscles/muscular_system_' + isFront + '.svg)');
-
- // Show the corresponding exercises
- $('.exercise-list').hide();
- $('#' + divId).show();
-}
-
/*
D3js functions
*/
diff --git a/wger/exercises/templates/muscles/overview.html b/wger/exercises/templates/muscles/overview.html
index ea111e2cf..79c39da42 100644
--- a/wger/exercises/templates/muscles/overview.html
+++ b/wger/exercises/templates/muscles/overview.html
@@ -1,5 +1,5 @@
-{% extends "base_wide.html" %}
-{% load i18n static cache wger_extras compress %}
+{% extends "base.html" %}
+{% load i18n static cache wger_extras compress thumbnail %}
<!--
Title
@@ -12,35 +12,6 @@
<script src="{% static 'js/exercises.js' %}"></script>
{% endcompress %}
-<script>
-$(document).ready(function() {
- //Prefetch the background images
- wgerPrefetchImages([
- '{% static 'images/muscles/muscular_system_back.svg' %}',
- {% for muscle in muscle_list|first %}
- {% with muscle_id=muscle.id|stringformat:"s" %}
- {% with muscle_img='images/muscles/main/muscle-'|add:muscle_id|add:'.svg' %}
- '{% static muscle_img %}',
- {% endwith %}
- {% endwith %}
- {% endfor %}
- ]);
-
-
- // Hightlight the first element
- var $muscle = $('.muscle');
- wgerHighlightMuscle($muscle.first());
-
- // Highlight on hover
- $muscle.hover(function(e) {
- e.preventDefault();
- wgerHighlightMuscle(this);
- });
-
- // Highlight on click
-
-});
-</script>
{% endblock %}
@@ -49,55 +20,69 @@ $(document).ready(function() {
-->
{% block content %}
{% cache cache_timeout muscle-overview language.id %}
-{% trans "Hover with the mouse over the muscles to show corresponding exercises." %}
-
-<div class="row mt-3">
- <div class="col-sm-4 col-6">
- {# Why do we need to use |first? #}
- {% regroup muscle_list|first by is_front as muscle_group %}
- {% for group in muscle_group %}
- {% if group.grouper %}
- <h4>{% trans "Front side" %}</h4>
- {% else %}
- <h4 class="mt-3">{% trans "Back side" %}</h4>
- {% endif %}
-
- <ul class="list-group muscle-list">
- {% for muscle in group.list %}
- <li class="muscle list-group-item py-1 py-md-2"
- data-target="muscle-{{muscle.id}}"
- data-is-front="{{muscle.is_front}}"
- data-name="{{muscle.name}}"
- itemscope itemtype="http://schema.org/Muscle">
- <span itemprop="name">{{muscle.name}}</span>
- </li>
- {% endfor %}
- </ul>
- {% endfor %}
- </div>
- <div class="col-sm-4 col-6">
- {% for muscle in muscle_list|first %}
- <div id="muscle-{{muscle.id}}" style="display:none;" class="exercise-list">
- <h4>{% trans "Exercises" %}</h4>
- <div class="list-group exercise-overview">
- {% for exercise in muscle.exercise_set.select_related %}
+<div class="accordion" id="muscleAccordion">
+ {% for entry in muscle_list %}
+ {% for muscle in entry %}
+ <div class="card">
+ <div class="card-header" id="header-{{muscle.pk}}">
+ <button
+ class="btn btn-block text-left muscle"
+ type="button"
+ data-toggle="collapse"
+ aria-expanded="true"
+ aria-controls="collapse-{{muscle.pk}}"
+ data-target="#collapse-{{muscle.pk}}"
+ data-muscle-target="muscle-{{muscle.id}}"
+ data-is-front="{{muscle.is_front}}"
+ data-name="{{muscle.name}}"
+ itemscope itemtype="http://schema.org/Muscle"
+ >
+ {{ muscle }}
+ </button>
+ </div>
+ <div class="collapse" id="collapse-{{muscle.pk}}" data-parent="#muscleAccordion">
+ <div class="card-body px-0">
+ <div class="list-group list-group-flush">
+ <div class="list-group-item">
+ {% render_muscles muscle %}
+ </div>
+
+ {% for exercise in muscle.exercise_set.all %}
{% if exercise.language in active_languages %}
- <a class="exercise list-group-item list-group-item-action py-1 py-md-2" href="{{exercise.get_absolute_url}}">{{exercise}}</a>
+ <a href="{{ exercise.get_absolute_url }}" class="list-group-item">
+ <div class="media">
+ {% if exercise.main_image %}
+ <img alt="{{ exercise.name }}"
+ class="mr-3"
+ src="{{ exercise.main_image.image|thumbnail_url:'thumbnail' }}">
+ {% else %}
+ <img alt="{% trans 'Placeholder image for exercise' %}"
+ class="mr-3"
+ src="{% static 'images/icons/image-placeholder.svg' %}">
+ {% endif %}
+ <div class="media-body">
+ <p class="media-heading h5">{{ exercise.name }}</p>
+ <span class="text-muted small">
+ {% trans exercise.category.name %}
+ <!--
+ {% trans "Main muscles" %}: {{ exercise.muscles.all|join:", " }}
+ <br>
+ {% trans "Secondary muscles" %}: {{ exercise.muscles_secondary.all|join:", " }}
+ -->
+ </span>
+ </div>
+ </div>
+ </a>
{% endif %}
{% empty %}
- <em>{% trans "No exercises that mainly train this muscle" %}</em>
+ {% trans "No exercises for this equipment. Add or edit an exercise and set the equipment." %}
{% endfor %}
</div>
</div>
- {% endfor %}
- </div>
- <div class="col-sm-4">
- <h4 style="padding-bottom:0.5em;">{% trans "Muscles" %}</h4>
- <div id="muscle-system"
- class="muscle-background"
- style="background-image: url('{% static "images/muscles/muscular_system_front.svg" %}');">
</div>
</div>
+ {% endfor %}
+ {% endfor %}
</div>
{% endcache %}
{% endblock %}