Private
Public Access
1
0

some fine tuning of plannedsession UI

This commit is contained in:
Sander Roosendaal
2018-02-14 11:27:17 +01:00
parent 55513c8470
commit 76cadea8b6
8 changed files with 166 additions and 43 deletions

View File

@@ -801,6 +801,7 @@ class PlannedSession(models.Model):
('session','Training Session'),
('challenge','Challenge'),
('test','Mandatory Test'),
('cycletarget','Cycle Target'),
)
sessionmodechoices = (
@@ -894,6 +895,18 @@ class PlannedSession(models.Model):
return stri
def save(self, *args, **kwargs):
# sort units
if self.sessionmode == 'distance':
if self.sessionunit not in ['m','km']:
self.sessionunit = 'm'
elif self.sessionmode == 'time':
self.sessionunit = 'min'
else:
self.sessionunit = 'None'
super(PlannedSession,self).save(*args, **kwargs)
# Date input utility
class DateInput(forms.DateInput):
input_type = 'date'
@@ -950,7 +963,7 @@ class PlannedSessionFormSmall(ModelForm):
'enddate': DateInput(attrs={'size':10}),
'name': forms.TextInput(attrs={'size':10}),
'comment': forms.TextInput(attrs={'size':10}),
'sessionvalue': forms.TextInput(attrs={'style':'width:3em',
'sessionvalue': forms.TextInput(attrs={'style':'width:5em',
'type':'number'}),
'manager': forms.HiddenInput(),
}

View File

@@ -33,7 +33,7 @@ def add_workouts_plannedsession(ws,ps):
# check if all sessions have same date
dates = [w.date for w in ws]
if (not all(d == dates[0] for d in dates)) and ps.sessiontype != 'challenge':
if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']:
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors
@@ -158,7 +158,7 @@ def is_session_complete_ws(ws,ps):
status = 'partial'
if ps.sessiontype == 'session':
if ps.sessiontype in ['session','cycletarget']:
if ps.criterium == 'exact':
if ratio == 1.0:
return ratio,'completed'

View File

@@ -2,7 +2,7 @@
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}New Planned Session{% endblock %}
{% block title %}Plan entire microcycle{% endblock %}
{% block content %}
<div class="grid_12 alpha">
@@ -55,7 +55,12 @@
<div class="grid_12 alpha">
<p>
On this page, you can create and edit sessions for an entire time
period.
period. You see a list of the current sessions planned for the
selected time period. Each row in the table is a session. You can
remove a session by clicking "remove" at the end of a row.
You can edit the date in the forms. If you need to add a new session,
click the "Add More" button to add a new session. Use the "Submit"
button to commit any changes you made.
</p>
<form id="ps-form-table" method="post">
{% csrf_token %}
@@ -71,7 +76,7 @@
</thead>
<tbody>
{% for form in ps_formset %}
<tr id="id_form_row">
<tr class="session_form_row">
<td> {{ forloop.counter }}
{% if form.instance.pk %}{{ form.DELETE }}{% endif %}
{{ form.id }}
@@ -105,40 +110,40 @@
addText: ''
});
$("td #id_sessionmode").change(function() {
$("tr.session_form_row").each(function() {
var myrow = this;
$( myrow ).find('*[id*=sessionmode]').change(function() {
if (this.value == 'TRIMP') {
$("td #id_sessionunit").prop("value","None");
$( myrow ).find("*[id*=sessionunit]").prop('value','None');
}
if (this.value == 'distance') {
$("td #id_sessionunit").prop("value","m");
$( myrow ).find("*[id*=sessionunit]").prop('value','m');
}
if (this.value == 'time') {
$("td #id_sessionunit").prop("value","min");
$( myrow ).find("*[id*=sessionunit]").prop('value','min');
}
if (this.value == 'rScore') {
$("td #id_sessionunit").prop("value","None");
$( myrow ).find("*[id*=sessionunit]").prop('value','None');
}
});
$("td #id_sessiontype").change(function() {
if (this.value == 'session') {
$("td #id_criterium").prop("value","none");
$( myrow ).find('*[id*=sessionunit]').change(function() {
if (this.value == 'km') {
$( myrow ).find("*[id*=sessionmode]").prop('value','distance');
}
if (this.value == 'test') {
$("td #id_criterium").prop("value","exact");
if (this.value == 'm') {
$( myrow ).find("*[id*=sessionmode]").prop('value','distance');
}
if (this.value == 'challenge') {
$("td #id_criterium").prop("value","minimum");
if (this.value == 'None') {
$( myrow ).find("*[id*=sessionmode]").prop('value','rScore');
}
if (this.value == 'min') {
$( myrow ).find("*[id*=sessionmode]").prop('value','time');
}
);
});
});
});

View File

@@ -160,10 +160,32 @@
$("td #id_criterium").prop("value","minimum");
}
if (this.value == 'cycletarget') {
$("td #id_criterium").prop("value","none");
}
}
);
$("td #id_sessionunit").change(function() {
if (this.value == 'm') {
$("td #id_sessionmode").prop("value","distance");
}
if (this.value == 'km') {
$("td #id_sessionmode").prop("value","distance");
}
if (this.value == 'None') {
$("td #id_sessionmode").prop("value","rScore");
}
if (this.value == 'min') {
$("td #id_sessionmode").prop("value","time");
}
}
);
});

View File

@@ -165,10 +165,33 @@
$("td #id_criterium").prop("value","minimum");
}
if (this.value == 'cycletarget') {
$("td #id_criterium").prop("value","none");
}
}
);
$("td #id_sessionunit").change(function() {
if (this.value == 'm') {
$("td #id_sessionmode").prop("value","distance");
}
if (this.value == 'km') {
$("td #id_sessionmode").prop("value","distance");
}
if (this.value == 'None') {
$("td #id_sessionmode").prop("value","rScore");
}
if (this.value == 'min') {
$("td #id_sessionmode").prop("value","time");
}
}
);
});

View File

@@ -75,17 +75,41 @@
it will change to match this session.
</p>
<p>
We will make this form smarter in the near future.
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">
<div class="grid_12 alpha">
<div class="grid_6 alpha">
{{ ps_form.as_table}}
<p>Planned Sessions</p>
<table width="100%">
<tr>
{% for field in ps_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in ps_form.visible_fields %}
<td> {{ field }}</td>
{% endfor %}
</tr>
</table>
</div>
<div class="grid_6 omega">
{{ w_form.as_table}}
<p>Workouts</p>
<table width="100%">
<tr>
{% for field in w_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in w_form.visible_fields %}
<td>
{{ field }}
</td>
{% endfor %}
</tr>
</table>
</div>
</div>
<div class="grid_2 prefix_2 suffix_8">
@@ -101,21 +125,33 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#id_plannedsession').on('click', function(evt) {
function addLink( el ){
var linked = el.next("span.linked");
if (linked.length == 0) {
el.after("<span class='linked' style='color:red'><b>&#10004;</b></span>");
}
}
function getURL() {
var url = window.location.pathname;
var selectedsession = $("input:radio[name='plannedsession']:checked").val();
var url = window.location.pathname;
if (url.indexOf("/session/") >= 0) {
url = url.replace(/\/session\/\d+/g, "/session/"+selectedsession);
} else {
url += "/session/"+selectedsession
}
// window.location.replace(url);
};
return url};
function loadJSON( url ) {
$.getJSON(url, function(json) {
var workouts = json['workouts'];
for (i=0; i < workouts.length; i++) {
var wid = workouts[i][0];
var wcheck = workouts[i][2];
var lcheck = workouts[i][3];
if (wcheck) {
$(":checkbox").filter(function() {
return this.value == wid;
@@ -125,9 +161,25 @@
return this.value == wid;
}).prop("checked",false);
}
}
});
});
if (lcheck) {
addLink( $(":checkbox").filter(function() {
return this.value == wid;
}) );
};
};
});
}
loadJSON( getURL() );
$('#id_plannedsession').on('click', function(evt) {
loadJSON( getURL() );
});
})
</script>
{% endblock %}

View File

@@ -33,7 +33,7 @@
</p>
</div>
<div class="grid_2">
<a class="button gray small" href="/rowers/sessions/multicreate/{{ timeperiod }}/rower/{{ rower.id }}">Bulk Session Edit ({{ timeperiod|verbosetimeperiod }})</a>
<a class="button blue small" href="/rowers/sessions/multicreate/{{ timeperiod }}/rower/{{ rower.id }}">Plan Complete MicroCycle ({{ timeperiod|verbosetimeperiod }})</a>
</div>
<div class="grid_2">
{% if user.is_authenticated and user|is_manager %}

View File

@@ -9103,7 +9103,7 @@ def c2listdebug_view(request,page=1,message=""):
return HttpResponseRedirect(url)
else:
workouts = []
print res.json()['meta']
for item in res.json()['data']:
d = item['distance']
i = item['id']
@@ -11729,7 +11729,9 @@ def plannedsession_multicreate_view(request,timeperiod='thisweek',
for ps in instances:
ps.save()
add_rower_session(r,ps)
messages.info(request,"Saved changes for Planned Session "+str(ps))
for obj in ps_formset.deleted_objects:
messages.info(request,"Deleted Planned Session "+str(obj))
obj.delete()
else:
print ps_formset.errors
@@ -12109,7 +12111,12 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',rowerid=0,
initialworkouts = [w.id for w in Workout.objects.filter(user=r,plannedsession=ps0)]
linkedworkouts = []
for w in ws:
if w.plannedsession is not None:
linkedworkouts.append(w.id)
plannedsessionstuple = []
for ps in sps:
@@ -12167,15 +12174,16 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',rowerid=0,
if is_ajax:
ajax_workouts = []
for id,name in workoutdata['choices']:
if id in initialworkouts:
ajax_workouts.append((id,name,True))
else:
ajax_workouts.append((id,name,False))
ininitial = id in initialworkouts
inlinked = id in linkedworkouts
ajax_workouts.append((id,name,ininitial,inlinked))
ajax_response = {
'workouts':ajax_workouts,
'plannedsessionstuple':plannedsessionstuple,
}
return JSONResponse(ajax_response)