Private
Public Access
1
0

sessions manage

This commit is contained in:
Sander Roosendaal
2018-10-15 16:56:45 +02:00
parent e1cd70f016
commit bd757c7bb4
4 changed files with 90 additions and 165 deletions

View File

@@ -140,7 +140,7 @@
<label for="athlete-selector"><i class="fas fa-users fa-fw"></i>&nbsp;Athletes</label> <label for="athlete-selector"><i class="fas fa-users fa-fw"></i>&nbsp;Athletes</label>
<ul> <ul>
{% for member in user|team_members %} {% for member in user|team_members %}
<a href={{ request.path|userurl:member }}> <a href={{ request.path|userurl:member }}?when={{ timeperiod }}>
<i class="fas fa-user fa-fw"></i> <i class="fas fa-user fa-fw"></i>
{% if member == rower.user %} {% if member == rower.user %}
&bull; &bull;

View File

@@ -1,4 +1,4 @@
{% extends "base.html" %} {% extends "newbase.html" %}
{% load staticfiles %} {% load staticfiles %}
{% load rowerfilters %} {% load rowerfilters %}
@@ -16,119 +16,71 @@
{% endblock %} {% endblock %}
{% block content %} {% block main %}
<div class="grid_12 alpha"> <h1>Manage Plan Execution for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
{% include "planningbuttons.html" %}
</div>
<div class="grid_12 alpha">
<div class="grid_6 alpha">
<h1>Manage Plan Execution for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
</div>
<div id="timeperiod" class="grid_2 dropdown"> <p>Select one session on the left, and one or more workouts on the right
<button class="grid_2 alpha button gray small dropbtn">Select Time Period ({{ timeperiod|verbosetimeperiod }})</button> to match the workouts to the session. For tests and training sessions,
<div class="dropdown-content"> the selected workouts must be done on the same date. For all sessions,
<a class="button gray small alpha" the workout dates must be between the start and end date for the
href="/rowers/sessions/manage/today/rower/{{ rower.id }}"> session.
Today </p>
</a> <p>
<a class="button gray small alpha" If you select a workout that has already been matched to another session,
href="/rowers/sessions/manage/thisweek/rower/{{ rower.id }}"> it will change to match this session.
This Week </p>
</a> <p>
<a class="button gray small alpha" Workouts marked with a red check mark (<span style="color:red"><b>&#10004;</b></span>)
href="/rowers/sessions/manage/thismonth/rower/{{ rower.id }}"> are currently linked to one of your sessions. A workout can only be assigned to
This Month one session at a time.
</a> </p>
<a class="button gray small alpha"
href="/rowers/sessions/manage/lastweek/rower/{{ rower.id }}"> <form id="session_form" action="/rowers/sessions/manage/user/{{ rower.user.id }}/?when={{ timeperiod }}"
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/lastmonth/rower/{{ rower.id }}">
Last Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/nextweek/rower/{{ rower.id }}">
Next Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/nextmonth/rower/{{ rower.id }}">
Next Month
</a>
</div>
</div>
{% if user.is_authenticated and user|is_manager %}
<div class="grid_2 dropdown">
<button class="grid_2 alpha button green small dropbtn">
{{ rower.user.first_name }} {{ rower.user.last_name }}
</button>
<div class="dropdown-content">
{% for member in user|team_rowers %}
<a class="button green small" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ member.id }}">{{ member.user.first_name }} {{ member.user.last_name }}</a>
{% endfor %}
</div>
</div>
{% endif %}
</div>
<div class="grid_12 alpha">
<p>Select one session on the left, and one or more workouts on the right
to match the workouts to the session. For tests and training sessions,
the selected workouts must be done on the same date. For all sessions,
the workout dates must be between the start and end date for the
session.
</p>
<p>
If you select a workout that has already been matched to another session,
it will change to match this session.
</p>
<p>
Workouts marked with a red check mark (<span style="color:red"><b>&#10004;</b></span>)
are currently linked to one of your sessions. A workout can only be assigned to
one session at a time.
</p>
</div>
<form id="session_form" action="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}"
method="post"> method="post">
<div class="grid_12 alpha"> <ul class="main-content">
<div class="grid_6 alpha"> <li class="grid_2">
<p>Planned Sessions</p> <h2>Planned Sessions</h2>
<table width="100%"> <table width="100%">
<tr> <tr>
{% for field in ps_form.hidden_fields %} {% for field in ps_form.hidden_fields %}
{{ field }} {{ field }}
{% endfor %} {% endfor %}
{% for field in ps_form.visible_fields %} {% for field in ps_form.visible_fields %}
<td> {{ field }}</td> <td> {{ field }}</td>
{% endfor %} {% endfor %}
</tr> </tr>
</table> </table>
</div> </li>
<div class="grid_6 omega"> <li class="grid_2">
<p>Workouts</p> <h2>Workouts</h2>
<table width="100%"> <table width="100%">
<tr> <tr>
{% for field in w_form.hidden_fields %} {% for field in w_form.hidden_fields %}
{{ field }} {{ field }}
{% endfor %} {% endfor %}
{% for field in w_form.visible_fields %} {% for field in w_form.visible_fields %}
<td> <td>
{{ field }} {{ field }}
</td> </td>
{% endfor %} {% endfor %}
</tr> </tr>
</table> </table>
</div> </li>
</div> <li class="grid_2">
<div class="grid_2 prefix_2 suffix_8">
{% csrf_token %} {% csrf_token %}
<input class="button green" type="submit" value="Submit"> <input class="button green" type="submit" value="Submit">
</div> </li>
</ul>
</form> </form>
{% endblock %} {% endblock %}
{% block sidebar %}
{% include 'menu_plan.html' %}
{% endblock %}
{% block scripts %} {% block scripts %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script> <script>
@@ -144,13 +96,13 @@
function getURL() { function getURL() {
var url = window.location.pathname; var url = window.location.pathname;
var selectedsession = $("input:radio[name='plannedsession']:checked").val(); var selectedsession = $("input:radio[name='plannedsession']:checked").val();
if (url.indexOf("/session/") >= 0) { if (url.indexOf("/session/") >= 0) {
url = url.replace(/\/session\/\d+/g, "/session/"+selectedsession); url = url.replace(/\/session\/\d+/g, "/session/"+selectedsession);
} else { } else {
url += "/session/"+selectedsession url = url.replace("manage","manage/session/"+selectedsession);
}; };
url += '?when={{ timeperiod }}'
return url}; return url};
function loadJSON( url ) { function loadJSON( url ) {

View File

@@ -469,13 +469,13 @@ urlpatterns = [
url(r'^sessions/(?P<pk>\d+)/deleteconfirm$',views.PlannedSessionDelete.as_view()), url(r'^sessions/(?P<pk>\d+)/deleteconfirm$',views.PlannedSessionDelete.as_view()),
url(r'^sessions/(?P<pk>\d+)/delete$',views.PlannedSessionDelete.as_view(), url(r'^sessions/(?P<pk>\d+)/delete$',views.PlannedSessionDelete.as_view(),
name='plannedsession_delete_view'), name='plannedsession_delete_view'),
url(r'^sessions/manage/session/(?P<initialsession>\d+)$', url(r'^sessions/manage/session/(?P<initialsession>\d+)/$',
views.plannedsessions_manage_view), views.plannedsessions_manage_view),
url(r'^sessions/manage/user/(?P<userid>\d+)/session/(?P<initialsession>\d+)$', url(r'^sessions/manage/session/(?P<initialsession>\d+)/user/(?P<userid>\d+)/$',
views.plannedsessions_manage_view), views.plannedsessions_manage_view),
url(r'^sessions/manage/?$', url(r'^sessions/manage/?$',
views.plannedsessions_manage_view), views.plannedsessions_manage_view),
url(r'^sessions/manage/user/(?P<userid>\d+)$', url(r'^sessions/manage/user/(?P<userid>\d+)/$',
views.plannedsessions_manage_view), views.plannedsessions_manage_view),
url(r'^sessions/coach$',views.plannedsessions_coach_view), url(r'^sessions/coach$',views.plannedsessions_coach_view),
url(r'^sessions/print/?$',views.plannedsessions_print_view), url(r'^sessions/print/?$',views.plannedsessions_print_view),

View File

@@ -14298,13 +14298,19 @@ def plannedsessions_print_view(request,timeperiod='thisweek',userid=0):
@login_required() @login_required()
def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0, def plannedsessions_manage_view(request,userid=0,
initialsession=0): initialsession=0):
is_ajax = False is_ajax = False
if request.is_ajax(): if request.is_ajax():
is_ajax = True is_ajax = True
when = request.GET.get('when')
if when:
timeperiod = when
else:
timeperiod = 'thisweek'
r = getrequestrower(request,userid=userid) r = getrequestrower(request,userid=userid)
startdate,enddate = get_dates_timeperiod(timeperiod) startdate,enddate = get_dates_timeperiod(timeperiod)
@@ -14336,7 +14342,7 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
"date","startdatetime","id" "date","startdatetime","id"
) )
initialworkouts = [w.id for w in Workout.objects.filter(user=r,plannedsession=ps0)] initialworkouts = [w.id for w in Workout.objects.filter(user=r,plannedsession=ps0)]
linkedworkouts = [] linkedworkouts = []
@@ -14413,6 +14419,23 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
return JSONResponse(ajax_response) return JSONResponse(ajax_response)
breadcrumbs = [
{
'url':reverse(plannedsessions_view,
kwargs={'userid':userid}),
'name': 'Plan'
},
{
'url':reverse(plannedsessions_manage_view,
kwargs={
'userid':userid,
'initialsession':initialsession,
}
),
'name': 'Link Sessions to Workouts'
},
]
return render(request,'plannedsessionsmanage.html', return render(request,'plannedsessionsmanage.html',
{ {
@@ -14420,6 +14443,8 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
'plan':trainingplan, 'plan':trainingplan,
'plannedsessions':sps, 'plannedsessions':sps,
'workouts':ws, 'workouts':ws,
'active':'nav-plan',
'breadcrumbs':breadcrumbs,
'timeperiod':timeperiod, 'timeperiod':timeperiod,
'rower':r, 'rower':r,
'ps_form':ps_form, 'ps_form':ps_form,
@@ -14858,58 +14883,6 @@ class PlannedSessionDelete(DeleteView):
return obj return obj
@login_required()
def plannedsession_delete_view(request,id=0):
r = getrower(request.user)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise PermissionDenied("You are not allowed to delete this planned session")
ws = Workout.objects.filter(plannedsession=ps)
for w in ws:
w.plannedsession=None
w.save()
ps.delete()
url = reverse(plannedsessions_view)
return HttpResponseRedirect(url)
@login_required()
def plannedsession_deleteconfirm_view(request,id=0):
r = getrower(request.user)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise PermissionDenied("You are not allowed to delete this planned session")
psdict = my_dict_from_instance(ps,PlannedSession)
return render(request,'plannedsessiondeleteconfirm.html',
{
'ps':ps,
'psdict': psdict,
'attrs':[
'name','startdate','enddate','sessiontype',
],
'rower':r,
}
)
def virtualevents_view(request): def virtualevents_view(request):
is_ajax = False is_ajax = False