Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Generate more correct 'pages' for timer template

Roland Geider3af84b3c1cd5
diff --git a/wger/manager/templates/workout/timer.html b/wger/manager/templates/workout/timer.html
index 296111070..ff9620e09 100644
--- a/wger/manager/templates/workout/timer.html
+++ b/wger/manager/templates/workout/timer.html
@@ -78,6 +78,21 @@ function draw_step(step) { // step between 0 and 1
function start_countdown(step_id, seconds)
{
+
+ // deactivate the button if needed
+ var link = $('#button-' + step_id) ;
+ if (! link.is(".ui-state-disabled"))
+ {
+ link.addClass('ui-state-disabled');
+ link.click(function(e) {
+ e.preventDefault();
+ });
+ }
+ else
+ {
+ return false;
+ }
+
canvas = document.getElementById('canvas-div-'+step_id);
num = $('#counter-'+step_id);
ctx = canvas.getContext('2d');
@@ -110,8 +125,6 @@ $(document).ready(function() {
$('.timer-step').width(div_width);
$('.timer-step').height(div_height);
- 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
@@ -125,6 +138,7 @@ $(document).ready(function() {
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({
@@ -132,6 +146,8 @@ $(document).ready(function() {
return totalWidth;
}
});
+
+ // Bind necessary click events to advance the workout
$('#container ul li').each(function(intIndex) {
$(this).find('a').bind("click", function() {
var step_id = $(this).parents('li').data('step');
@@ -145,8 +161,10 @@ $(document).ready(function() {
$(this).parents('ul').animate({
"margin-left": (-(intIndex - 1) * div_width)
}, 600)
+
} else if ($(this).is(".start")) {
start_countdown(step_id, step_time);
+
} else if ($(this).is(".startover")) {
$(this).parent('li').parent('ul').animate({
"margin-left": (0)
@@ -162,17 +180,23 @@ $(document).ready(function() {
<div id="container">
<ul class="workout-timer">
<li class="timer-step" id="div-warmup">
- <h2>{% trans "Warm up!" %}</h2>
+ <h2>{% trans "Your workout today" %}</h2>
- <div class="filler_div"></div>
- <div class="sub_header">5 min.</div>
+ <div class="filler_div">
+ {% for exercise in exercise_list %}
+ {{exercise}}<br>
+ {% endfor %}
+ </div>
+ <!--
+ <div class="sub_header"></div>
+ -->
<a class="next bottom_button"
href="#"
data-role="button"
data-icon="arrow-r"
- data-iconpos="right">{% trans "Start workout" %}</a>
+ data-iconpos="right">{% trans "Start!" %}</a>
</li>
{% for step in step_list %}
{% if step.type == 'exercise' %}
@@ -213,7 +237,7 @@ $(document).ready(function() {
<div class="sub_header"><span id="counter-{{step.current_step}}">{{step.time}}</span> {% trans "sec" %}</div>
</div>
<div class="ui-block-b">
- <a class="start" href="#" data-role="button">{% trans "start" %}</a>
+ <a class="start" href="#" data-role="button" id="button-{{step.current_step}}">{% trans "start" %}</a>
</div>
</div>
diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.py
index bd6481610..9a57ddf31 100644
--- a/wger/manager/views/workout.py
+++ b/wger/manager/views/workout.py
@@ -179,7 +179,7 @@ def copy_workout(request, pk):
setting_copy.save()
return HttpResponseRedirect(reverse('wger.manager.views.workout.view',
- kwargs={'id': workout.id}))
+ kwargs={'id': workout.id}))
else:
workout_form = WorkoutCopyForm({'comment': workout.comment})
@@ -244,12 +244,28 @@ def timer(request, pk):
day = Day.objects.get(pk=pk, training__user=request.user)
context['day'] = day
+ exercise_list = []
step_list = []
- for set in day.set_set.select_related():
+ for set_obj in day.set_set.select_related():
+
+ is_superset = False if set_obj.exercises.select_related().count() == 1 else True
+ tmp_2 = []
+
+ for exercise in set_obj.exercises.select_related():
+
+ exercise_list.append(exercise)
+
+ # 'compact' means that there is only one setting object, e.g: the set has
+ # set.sets = 4 and there is only one setting: setting.reps = 10, total: 4x10
+ # Not compact settings have an entry for each repetition:
+ # set.sets = 4 and four setting objects: setting.reps = 10, 8, 8, 6
+ is_compact = False \
+ if Setting.objects.filter(set=set_obj, exercise=exercise).count() == 1 \
+ else True
+ logger.debug('is_compact: {0}'.format(is_compact))
- for exercise in set.exercises.select_related():
- for setting in Setting.objects.filter(set=set, exercise=exercise).order_by('order'):
+ for setting in Setting.objects.filter(set=set_obj, exercise=exercise).order_by('order'):
# To find out the last weight, look if the user has already
# a log with same exercise and repetitions and use the last one.
@@ -259,22 +275,29 @@ def timer(request, pk):
if last_log.exists():
weight = last_log[0].weight
else:
- weight = None
+ weight = ''
- # Exercise
- step_list.append({'current_step': uuid.uuid4().hex,
+ # Set range
+ if not is_compact:
+ set_range = range(0, set_obj.sets)
+ else:
+ set_range = (0, )
+
+ for i in set_range:
+ tmp_2.append({'current_step': uuid.uuid4().hex,
'exercise': exercise,
'type': 'exercise',
'weight': weight,
'reps': setting.reps})
- # Pause
- step_list.append({'current_step': uuid.uuid4().hex,
+
+ tmp_2.append({'current_step': uuid.uuid4().hex,
'type': 'pause',
'time': 30})
+ step_list = step_list + tmp_2
+
context['step_list'] = step_list
- import pprint
- pprint.pprint(step_list)
+ context['exercise_list'] = exercise_list
return render_to_response('workout/timer.html',
context,
context_instance=RequestContext(request))