Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add links to add workout logs directly from the calendar

Roland Geiderb9275899407a
diff --git a/wger/manager/models.py b/wger/manager/models.py
index f43965ae0..41d3c5a7b 100644
--- a/wger/manager/models.py
+++ b/wger/manager/models.py
@@ -108,6 +108,7 @@ class ScheduleManager(models.Manager):
'''
Finds the currently active workout for the user, by checking the schedules
and the workouts
+ :rtype : list
'''
# Try first to find an active schedule that has steps
diff --git a/wger/manager/templates/mobile/workout/calendar.html b/wger/manager/templates/mobile/workout/calendar.html
index 078ff82ed..469b58533 100644
--- a/wger/manager/templates/mobile/workout/calendar.html
+++ b/wger/manager/templates/mobile/workout/calendar.html
@@ -61,12 +61,39 @@ $(document).ready(function() {
{% block sidebar %}
+<div data-role="popup"
+ id="calendar-day-select-popup"
+ data-overlay-theme="a"
+ class="ui-content">
+ <div>
+ <h3>{% trans "Add log to day" %}</h3>
+ {% if current_workout %}
+ <p>{% blocktrans %}Click to add weight logs to a training
+day in your current workout:{% endblocktrans %} {{current_workout}}</p>
+
+ <ul data-role="listview" data-inset="true">
+ {% for day in current_workout.day_set.all %}
+ <li><a href="{% url 'day-log' day.pk %}">{{day.description}}</a></li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p><em>{% trans "No workouts found." %}</em></p>
+ <a href="{% url 'wger.manager.views.workout.add' %}" data-role="button">
+ <img src="{% static 'images/icons/add.svg' %}"
+ width="22"
+ height="22"
+ alt="">
+ {% trans "Add one now." %}
+ </a>
+ {% endif %}
+ </div>
+</div>
+
<h3>{% trans 'Info' %}</h3>
<p>{% blocktrans %}The coloured days in the calendar have weight logs,
you can click on them to see the details.{% endblocktrans %}</p>
<h3>{% trans 'Log' %}</h3>
-<p>
<a href="{% url 'workout-calendar' %}" data-role="button" data-ajax="false">
<img src="{% static 'images/icons/calendar.svg' %}"
width="32"
@@ -74,7 +101,14 @@ you can click on them to see the details.{% endblocktrans %}</p>
alt="{% trans 'Go to current month' %}"
>
{% trans "Go to current month" %}</a>
-</p>
+
+ <a href="#calendar-day-select-popup" data-role="button" data-rel="popup">
+ <img src="{% static 'images/icons/add.svg' %}"
+ width="32"
+ height="32"
+ alt="{% trans 'Add new log' %}">
+ {% trans "Add new log" %}</a>
+
<div class="timeline-log">
<ul data-role="listview" data-inset="true">
{% for date in month_list %}
diff --git a/wger/manager/templates/workout/calendar.html b/wger/manager/templates/workout/calendar.html
index 3b3de07cb..7cfdecee3 100644
--- a/wger/manager/templates/workout/calendar.html
+++ b/wger/manager/templates/workout/calendar.html
@@ -14,6 +14,14 @@ $(document).ready(function() {
$('.calendar-log-data').hide();
$('#' + $(this).data('log')).toggle();
});
+
+ // Popup for adding logs
+ $('#calendar-day-select-link').click(function(e){
+ e.preventDefault();
+ $('#calendar-day-select-popup').dialog({
+ modal: true
+ });
+ });
});
</script>
{% endblock %}
@@ -54,6 +62,32 @@ $(document).ready(function() {
{% block sidebar %}
+<div id="calendar-day-select-popup" style="display:none;">
+ <div>
+ <h3>{% trans "Add log to day" %}</h3>
+ {% if current_workout %}
+ <p>{% blocktrans %}Click to add weight logs to a training
+day in your current workout:{% endblocktrans %} {{current_workout}}</p>
+
+ {% for day in current_workout.day_set.all %}
+ <a href="{% url 'day-log' day.pk %}" class="btn btn-block">{{day.description}}</a>
+ {% endfor %}
+
+ {% else %}
+ <p><em>{% trans "No workouts found." %}</em></p>
+ <p>
+ <a href="{% url 'wger.manager.views.workout.add' %}" class="btn btn-block">
+ <img src="{% static 'images/icons/add.svg' %}"
+ width="22"
+ height="22"
+ alt="">
+ {% trans "Add one now." %}
+ </a>
+ </p>
+ {% endif %}
+ </div>
+</div>
+
<h3>{% trans 'Info' %}</h3>
<p>{% blocktrans %}The coloured days in the calendar have weight logs,
you can click on them to see the details.{% endblocktrans %}</p>
@@ -67,6 +101,14 @@ you can click on them to see the details.{% endblocktrans %}</p>
alt="{% trans 'Go to current month' %}">
{% trans "Go to current month" %}</a>
</p>
+<p>
+ <a href="" id="calendar-day-select-link">
+ <img src="{% static 'images/icons/add.svg' %}"
+ width="32"
+ height="32"
+ alt="{% trans 'Add new log' %}">
+ {% trans "Add new log" %}</a>
+</p>
<div class="timeline-log">
{% for date in month_list %}
{% ifchanged date.year %}
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index 9c9164b21..63698dd22 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -38,6 +38,7 @@ from django.views.generic import DetailView
from wger.manager.models import Workout
from wger.manager.models import Day
from wger.manager.models import WorkoutLog
+from wger.manager.models import Schedule
from wger.manager.forms import HelperDateForm
from wger.manager.forms import WorkoutLogForm
@@ -309,10 +310,12 @@ def calendar(request, year=None, month=None):
temp.append(log.date)
logs_filtered.append(log)
+ (current_workout, schedule) = Schedule.objects.get_current_workout(request.user)
context['calendar'] = WorkoutCalendar(logs_filtered).formatmonth(year, month)
context['logs'] = WorkoutLog().process_log_entries(logs)[0]
context['current_year'] = year
context['current_month'] = month
+ context['current_workout'] = current_workout
context['month_list'] = WorkoutLog.objects.filter(user=request.user).dates('date', 'month')
return render_to_response('workout/calendar.html',
context,