From 76cadea8b652770e43c932298a7896b500cdabef Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 14 Feb 2018 11:27:17 +0100 Subject: [PATCH] some fine tuning of plannedsession UI --- rowers/models.py | 15 +++- rowers/plannedsessions.py | 4 +- .../templates/plannedsession_multicreate.html | 51 +++++++------ rowers/templates/plannedsessioncreate.html | 22 ++++++ rowers/templates/plannedsessionedit.html | 23 ++++++ rowers/templates/plannedsessionsmanage.html | 72 ++++++++++++++++--- rowers/templates/planningbuttons.html | 2 +- rowers/views.py | 20 ++++-- 8 files changed, 166 insertions(+), 43 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index f9632550..b62f0f78 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -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(), } diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 3cc15766..449de9e1 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -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' diff --git a/rowers/templates/plannedsession_multicreate.html b/rowers/templates/plannedsession_multicreate.html index 8ec43d64..d1be9b95 100644 --- a/rowers/templates/plannedsession_multicreate.html +++ b/rowers/templates/plannedsession_multicreate.html @@ -2,7 +2,7 @@ {% load staticfiles %} {% load rowerfilters %} -{% block title %}New Planned Session{% endblock %} +{% block title %}Plan entire microcycle{% endblock %} {% block content %}
@@ -55,7 +55,12 @@

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.

{% csrf_token %} @@ -71,7 +76,7 @@ {% for form in ps_formset %} - + {{ 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'); } - - ); - + }); + }); + }); diff --git a/rowers/templates/plannedsessioncreate.html b/rowers/templates/plannedsessioncreate.html index 5263c3f5..d36fe8e8 100644 --- a/rowers/templates/plannedsessioncreate.html +++ b/rowers/templates/plannedsessioncreate.html @@ -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"); + } + + } + + ); }); diff --git a/rowers/templates/plannedsessionedit.html b/rowers/templates/plannedsessionedit.html index b01ae7d7..ff679912 100644 --- a/rowers/templates/plannedsessionedit.html +++ b/rowers/templates/plannedsessionedit.html @@ -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"); + } + + } + + ); + }); diff --git a/rowers/templates/plannedsessionsmanage.html b/rowers/templates/plannedsessionsmanage.html index fdb8bc6e..1362cab2 100644 --- a/rowers/templates/plannedsessionsmanage.html +++ b/rowers/templates/plannedsessionsmanage.html @@ -75,17 +75,41 @@ it will change to match this session.

- We will make this form smarter in the near future. + Workouts marked with a red check mark () + are currently linked to one of your sessions. A workout can only be assigned to + one session at a time.

- {{ ps_form.as_table}} +

Planned Sessions

+ + + {% for field in ps_form.hidden_fields %} + {{ field }} + {% endfor %} + {% for field in ps_form.visible_fields %} + + {% endfor %} + +
{{ field }}
- {{ w_form.as_table}} +

Workouts

+ + + {% for field in w_form.hidden_fields %} + {{ field }} + {% endfor %} + {% for field in w_form.visible_fields %} + + {% endfor %} + +
+ {{ field }} +
@@ -101,21 +125,33 @@ {% endblock %} diff --git a/rowers/templates/planningbuttons.html b/rowers/templates/planningbuttons.html index 4bfeb6c0..1e9c944a 100644 --- a/rowers/templates/planningbuttons.html +++ b/rowers/templates/planningbuttons.html @@ -33,7 +33,7 @@

{% if user.is_authenticated and user|is_manager %} diff --git a/rowers/views.py b/rowers/views.py index 4d5453a2..2c608383 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -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)