Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-04-07 12:14:47 +02:00
parent 19dcd01143
commit 084e384aaa
3 changed files with 104 additions and 7 deletions

View File

@@ -2420,11 +2420,11 @@ class PlannedSessionStep(models.Model):
targetvalue = models.IntegerField(default=0)
targettype = models.TextField(default='',max_length=200, blank=True, null=True,
choices=targettypes)
customtargetvaluelow = models.IntegerField(default=0)
customtargetvaluehigh = models.IntegerField(default=0)
targetvaluelow = models.IntegerField(default=0)
targetvaluehigh = models.IntegerField(default=0)
intensity = models.TextField(default='',max_length=200, blank=True, null=True,
choices=intensitytypes)
notes = models.TextField(default='',max_length=200, blank=True, null=True)
description = models.TextField(default='',max_length=200, blank=True, null=True)
color = models.TextField(default='#ddd',max_length=200)
def save(self, *args, **kwargs):
@@ -2437,6 +2437,19 @@ class PlannedSessionStep(models.Model):
super(PlannedSessionStep, self).save(*args, **kwargs)
def asdict(self):
d = {
'wkt_step_name': self.name,
'durationType': self.durationtype,
'durationValue': self.durationvalue,
'targetValue': self.targetvalue,
'description': self.description,
'stepId': self.pk,
'intensity': self.intensity,
}
return d
class StepEditorForm(ModelForm):
class Meta:
model = PlannedSessionStep

View File

@@ -31,7 +31,8 @@
{% endfor %}
</div>
</section>
<section>
<ul class="main-content">
<li class="grid_2 library">
<h2>Add new step</h2>
<form enctype="multipart/multipart/form-data" method="post">
<table>
@@ -40,7 +41,14 @@
{% csrf_token %}
<input name="newstep" type="submit" value="Add to Library">
</form>
</section>
</li>
<li class="grid_2 library">
<h2>Step Information</h2>
<div id="stepinfo">
<p>Step information</p>
</div>
</li>
</ul>
{% endblock %}
{% block scripts %}
@@ -49,6 +57,15 @@
</script>
<script>
let csrftoken;
let steps = {};
{% for step in steps %}
steps["{{ step.id }}"] = { 'name': '{{ step.name }}' };
{% endfor %}
let descriptions = {}
{% for key, value in stepdescriptions.items %}
descriptions["{{ key }}"] = "{{ value }}"
{% endfor %}
console.log(descriptions);
$(document).ready(function() {
csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
console.log("CSRF token",csrftoken);
@@ -122,14 +139,33 @@
}
}
function handleDragOver(event) {
function handleMouseOver(event) {
if (event.preventDefault) {
event.preventDefault();
const id = event.target.id;
console.log(id);
var name = steps[id]['name'];
var txt = descriptions[id];
var divstring = `<p>${name}</p><p>${txt}</p>`
const div = document.getElementById("stepinfo");
div.innerHTML = divstring
}
return false;
}
function handleMouseLeave(event) {
if (event.preventDefault) {
const div = document.getElementById("stepinfo");
div.innerHTML = '<p>Hover over a step to get details</p>'
}
return false;
}
function handleDragOver(event) {
event.preventDefault();
}
function handleDragEnter(event) {
this.classList.add('over');
const target = event.target;
@@ -213,6 +249,8 @@
item.addEventListener('dragleave', handleDragLeave);
item.addEventListener('drop',noDrop);
item.addEventListener('dragenter',noDrop);
item.addEventListener('mouseover',handleMouseOver);
item.addEventListener('mouseleave',handleMouseLeave);
});
</script>

View File

@@ -7,6 +7,7 @@ from rowers.views.statements import *
import rowers.garmin_stuff as gs
from rowers import credits
from json.decoder import JSONDecodeError
from rowers.utils import step_to_string
@login_required
@@ -3013,6 +3014,40 @@ def stepadder(request, id=0):
redirect_field_name=None)
def stepeditor(request, id=0):
ps = get_object_or_404(PlannedSession, pk=id)
if ps.steps:
for step in ps.steps['steps']:
print(step)
durationtype = step.get('durationType','')
durationvalue = step.get('durationValue',0)
targetvalue = step.get('targetValue',0)
targettype = step.get('targetType','')
targetvaluelow = step.get('targetValueLow',0)
targetvaluehigh = step.get('targetValueHigh',0)
intensity = step.get('intensity','Active')
archived_steps = PlannedSessionStep.objects.filter(
manager = request.user,
durationtype = durationtype,
durationvalue = durationvalue,
targetvalue = targetvalue,
targettype = targettype,
targetvaluelow = targetvaluelow,
targetvaluehigh = targetvaluehigh,
intensity = intensity,
).count()
if not archived_steps and durationvalue != 0:
s = PlannedSessionStep(
manager = request.user,
durationtype = durationtype,
durationvalue = durationvalue,
targetvalue = targetvalue,
targettype = targettype,
targetvaluelow = targetvaluelow,
targetvaluehigh = targetvaluehigh,
intensity = intensity,
name = step.get('wkt_step_name','Step')
)
s.save()
ps.steps = {}
@@ -3028,9 +3063,20 @@ def stepeditor(request, id=0):
steps = PlannedSessionStep.objects.filter(manager=request.user)
stepdescriptions = {}
for step in steps:
stepdescriptions[step.id] = step_to_string(step.asdict(), short=False)[0]
print(stepdescriptions)
print(steps)
return render(request, 'stepeditor.html',
{
'steps':steps,
'stepdescriptions': stepdescriptions,
'form':form,
'ps':ps,
})