Self hosted FLOSS fitness/workout, nutrition and weight tracker
Start working on timer for workout and log while in the gym, refs #49
Roland Geider2f4c6d3ae8d2
diff --git a/wger/manager/templates/mobile/index.html b/wger/manager/templates/mobile/index.htmlindex 881aa1883..0226b7c1c 100644--- a/wger/manager/templates/mobile/index.html+++ b/wger/manager/templates/mobile/index.html@@ -7,6 +7,20 @@{% block content %}+<div data-role="popup"+ id="timer-workout"+ data-overlay-theme="a"+ class="ui-content">+ <div>+ <h3>{% trans "Timer" %}</h3>+ {% for day in current_workout.day_set.select_related|dictsort:"get_first_day_id" %}+ <a href="{% url 'workout-timer' day.pk %}"+ data-role="button"+ data-ajax="false">{{day.description}}</a>+ {% endfor %}+ </div>+</div>+<h3>{% trans "Workout"%}</h3>{% if current_workout %}<p>@@ -16,6 +30,10 @@data-ajax="false">{{ current_workout }}</a>+ <a href="#timer-workout"+ data-role="button"+ data-mini="true"+ data-rel="popup">Start workout!</a></p>– {{ current_workout.creation_date }}@@ -32,9 +50,10 @@{% endfor %}</ul>+{% if schedule %}<p>- → {% trans "This workout is part of a schedule:" %}+ {% trans "This workout is part of a schedule:" %}<a href="{{schedule.get_absolute_url}}">{{schedule.name}}</a></p>{% endif %}diff --git a/wger/manager/templates/workout/timer.html b/wger/manager/templates/workout/timer.htmlnew file mode 100644index 000000000..fc35b48ad--- /dev/null+++ b/wger/manager/templates/workout/timer.html@@ -0,0 +1,138 @@+{% extends "base.html" %}+{% load url from future %}+{% load i18n %}+{% load staticfiles %}+{% load wger_extras %}+{% load cache %}++{% block title %}{% endblock %}++{% block header %}+<style>++*{+ padding:0;+ margin:0;+}+ul li {+ float:left;+ list-style:none;+ position:relative;++}++/*styled*/+div#container{+ border:1px solid black;+ padding:13px;+ clear:both;+ overflow:hidden;+ /*top:35px;*/+ margin:0 auto;+ display:block;+}++</style>+<script>+/*+ * http://fearlessflyer.com/how-to-create-your-own-jquery-content-slider/+ * https://github.com/fearlessflyer/content-slider+ */+$(document).ready(function() {+ var div_height = $( window ).height() * 0.80;+ var div_width = $( window ).width() * 0.85;++ $('.timer-step').width(div_width);+ $('.timer-step').height(div_height);+ //$('.timer-step').first().show();++ var theImage = $('ul li img');+ var theWidth = theImage.width();+ //wrap into mother div+ $('#container ul').wrap('<div id="mother" />');+ //assign height width and overflow hidden to mother+ $('#mother').css({+ width: function() {+ return div_width;+ },+ height: function() {+ return div_height;+ },+ position: 'relative',+ overflow: 'hidden'+ });+ //get total of image sizes and set as width for ul+ var totalWidth = $('.timer-step').length * div_width;+ $('#container ul').css({+ width: function() {+ return totalWidth;+ }+ });+ $('#container ul li').each(function(intIndex) {+ $(this).find('a').bind("click", function() {+ console.log($(this).html());+ if ($(this).is(".next")) {+ $(this).parents('ul').animate({+ "margin-left": (-(intIndex + 1) * div_width)+ }, 600)++ } else if ($(this).is(".previous")) {+ $(this).parents('ul').animate({+ "margin-left": (-(intIndex - 1) * div_width)+ }, 600)++ } else if ($(this).is(".startover")) {+ $(this).parent('li').parent('ul').animate({+ "margin-left": (0)+ }, 600)+ }+ });// .bind()+ });// .each()+});+</script>+{% endblock %}++{% block content %}+<div id="container">+<ul class="workout-timer">+{% for set in day.set_set.select_related %}++ {% for exercise in set.exercises.select_related %}++ {% for setting in exercise|get_current_settings:set.id %}+ <li class="timer-step" id="div-{{set.pk}}">+ <h2>{{exercise}}</h2>+ {{set.sets}} x {{setting.reps}}<br>+ <div class="ui-grid-a">+ <div class="ui-block-a"><a class="previous" href="#" data-role="button">prev</a></div>+ <div class="ui-block-b"><a class="next " href="#" data-role="button">{% trans "skip" %}</a></div>+ </div>+ </li>+ <li class="timer-step" id="div-{{set.pk}}">+ <h2>{% trans "Pause!" %}</h2>+ 120 sec+ <div class="ui-grid-a">+ <div class="ui-block-a"><a class="previous" href="#" data-role="button">prev</a></div>+ <div class="ui-block-b"><a class="next " href="#" data-role="button">{% trans "skip" %}</a></div>+ </div>+ </li>+ {% endfor %}+ {% endfor %}++{% endfor %}+<li class="timer-step" id="div-{{set.pk}}">+ <h2>{% trans "Workout complete!" %}</h2>+ <p><strong>{% trans "Time" %}:</strong> MM:SS</p>+</li>+</ul>+</div>+{% endblock %}++++<!--+ Side bar+-->+{% block sidebar %}++{% endblock %}diff --git a/wger/manager/urls.py b/wger/manager/urls.pyindex 6105f86b4..d25fd1251 100644--- a/wger/manager/urls.py+++ b/wger/manager/urls.py@@ -70,6 +70,11 @@ urlpatterns = patterns('wger.manager.views',WorkoutLogUpdateView.as_view(),name='workout-log-edit'),+ # Timer+ url(r'^workout/(?P<pk>\d+)/timer$',+ 'workout.timer',+ name='workout-timer'),+# Schedulesurl(r'^workout/schedule/overview$','schedule.overview',diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.pyindex c6c39e683..17825724e 100644--- a/wger/manager/views/workout.py+++ b/wger/manager/views/workout.py@@ -33,6 +33,7 @@ from django.views.generic import DeleteViewfrom django.views.generic import UpdateViewfrom wger.manager.models import Workout+from wger.manager.models import Dayfrom wger.manager.forms import WorkoutFormfrom wger.manager.forms import WorkoutCopyForm@@ -225,3 +226,19 @@ class WorkoutEditView(WgerFormMixin, UpdateView, WgerPermissionMixin):title = ugettext_lazy('Edit workout')form_action_urlname = 'workout-edit'login_required = True+++@login_required+def timer(request, pk):+ '''+ The timer view ("gym mode") for a workout+ '''++ context = {}++ day = Day.objects.get(pk=pk, training__user=request.user)+ context['day'] = day++ return render_to_response('workout/timer.html',+ context,+ context_instance=RequestContext(request))