Private
Public Access
1
0

made ranking pieces explicit

This commit is contained in:
Sander Roosendaal
2018-01-04 21:13:33 +01:00
parent cd4faf861a
commit efeb5bc2f7
5 changed files with 240 additions and 141 deletions

View File

@@ -4,12 +4,49 @@
{% block title %}Rowsandall Workouts List{% endblock %}
{% block content %}
{% block scripts %}
<script>
setTimeout("location.reload(true);",60000);
</script>
<script
type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
<script>
$(function() {
$("td.rankingtoggle").click( function() {
var workout_id = $(this).attr('workoutid');
console.log(workout_id);
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/workout/'+workout_id+'/toggle-ranking', function(json) {
console.log(JSON.stringify(json));
rankingpiece = json.result;
tdid = "#star"+workout_id;
console.log(rankingpiece);
console.log($(tdid).length);
if (rankingpiece) {
$(tdid).addClass('yellow');
$(tdid).removeClass('notyellow');
$(tdid).html('&starf;');
console.log('adding yellow '+tdid);
} else {
$(tdid).removeClass('yellow');
$(tdid).addClass('notyellow');
$(tdid).html('&star;');
console.log('remove yellow '+tdid);
};
});
});
});
</script>
{% endblock %}
{% block content %}
<style>
#mypointer {
cursor: pointer;
}
</style>
<div class="grid_12">
@@ -51,6 +88,7 @@
<table width="100%" class="listtable shortpadded">
<thead>
<tr>
<th> R</th>
<th style="width:80"> Date</th>
<th> Time</th>
<th> Name</th>
@@ -76,23 +114,34 @@
{% else %}
<tr>
{% endif %}
<td id="mypointer"
class="rankingtoggle" workoutid="{{ workout.id }}">
{% if workout.rankingpiece %}
<span id="star{{ workout.id }}" class="yellow">&starf;</span>
{% else %}
<span id="star{{ workout.id }}" class="notyellow">&star;</span>
{% endif %}
</td>
<td> {{ workout.date|date:"Y-m-d" }} </td>
<td> {{ workout.starttime|date:"H:i" }} </td>
<td>
{% if workout.user.user == user or user == team.manager %}
{% if workout.rankingpiece %}
[RANKING PIECE]
{% endif %}
{% if workout.name != '' %}
<a href={% url rower.defaultlandingpage id=workout.id %}>{{ workout.name }}</a> </td>
<td>
<a href={% url rower.defaultlandingpage id=workout.id %}>
{{ workout.name }}
</a>
</td>
{% else %}
<a href={% url rower.defaultlandingpage id=workout.id %}>No Name</a> </td>
<td>
<a href={% url rower.defaultlandingpage
id=workout.id %}>No Name
</a></td>
{% endif %}
{% else %}
{% if workout.name != '' %}
<a href="/rowers/workout/{{ workout.id }}/">{{ workout.name }}</a> </td>
<td><a href="/rowers/workout/{{ workout.id }}/">{{ workout.name }}</a></td>
{% else %}
<a href="/rowers/workout/{{ workout.id }}/">No Name</a> </td>
<td><a href="/rowers/workout/{{ workout.id }}/">No Name</a> </td>
{% endif %}
{% endif %}
<td> {{ workout.workouttype }} </td>

View File

@@ -212,6 +212,7 @@ urlpatterns = [
url(r'^graph/(?P<id>\d+)/deleteconfirm$',views.graph_delete_confirm_view),
url(r'^graph/(?P<id>\d+)/delete$',views.graph_delete_view),
url(r'^workout/(?P<id>\d+)/get-thumbnails$',views.get_thumbnails),
url(r'^workout/(?P<id>\d+)/toggle-ranking$',views.workout_toggle_ranking),
url(r'^workout/(?P<id>\d+)/get-testscript$',views.get_testscript),
url(r'^workout/upload/team/$',views.team_workout_upload_view),
url(r'^workout/upload/$',views.workout_upload_view,name='workout_upload_view'),

View File

@@ -5,6 +5,7 @@ import colorsys
from django.conf import settings
import uuid
import datetime
lbstoN = 4.44822
@@ -127,6 +128,22 @@ palettes = {
'yellow_red':trcolors(255,255,178,189,0,39)
}
rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000]
rankingdurations = []
rankingdurations.append(datetime.time(minute=1))
rankingdurations.append(datetime.time(minute=4))
rankingdurations.append(datetime.time(minute=30))
rankingdurations.append(datetime.time(hour=1,minute=15))
rankingdurations.append(datetime.time(hour=1))
def is_ranking_piece(workout):
if workout.distance in rankingdistances:
return True
elif workout.duration in rankingdurations:
return True
return False
def range_to_color_hex(groupcols,palette='monochrome_blue'):

View File

@@ -711,7 +711,7 @@ def splitstdata(lijst):
from utils import (
geo_distance,serialize_list,deserialize_list,uniqify,
str2bool,range_to_color_hex,absolute,myqueue,get_call,
calculate_age
calculate_age,rankingdistances,rankingdurations
)
import datautils
@@ -3297,20 +3297,10 @@ def rankings_view(request,theuser=0,
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
enddate = enddate+datetime.timedelta(days=1)
rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000]
rankingdurations = []
rankingdurations.append(datetime.time(minute=1))
rankingdurations.append(datetime.time(minute=4))
rankingdurations.append(datetime.time(minute=30))
rankingdurations.append(datetime.time(hour=1,minute=15))
rankingdurations.append(datetime.time(hour=1))
thedistances = []
theworkouts = []
thesecs = []
rankingdistances.sort()
rankingdurations.sort()
@@ -9302,6 +9292,35 @@ def workout_getc2workout_view(request,c2id):
url = reverse(workout_c2import_view)
return HttpResponseRedirect(url)
@login_required
def workout_toggle_ranking(request,id=0):
is_ajax = False
if request.is_ajax():
is_ajax = True
try:
# check if valid ID exists (workout exists)
row = Workout.objects.get(id=id)
except Workout.DoesNotExist:
raise Http404("Workout doesn't exist")
if not checkworkoutuser(request.user,row):
message = "You are not allowed to change this workout"
messages.error(request,message)
# we are still here - we own the workout
row.rankingpiece = not row.rankingpiece
row.save()
if is_ajax:
return JSONResponse({'result':row.rankingpiece})
else:
url = reverse(workouts_view)
response = HttpResponseRedirect(url)
return response
# This is the main view for processing uploaded files
@login_required()
def workout_upload_view(request,

View File

@@ -56,6 +56,19 @@ body {
padding-bottom: 20px;
}
.notyellow {
font-size: 1.2em;
height: auto;
padding: 0px;
}
.yellow {
color: #cccc00;
font-size: 1.2em;
height: auto;
padding: 0px;
}
a {
/* color: #fff; */