Compare commits

...

2 Commits

Author SHA1 Message Date
3b4ae7a55a
changed remote totals to traditional time 2025-02-02 17:34:29 +01:00
87607da643
added parent edit page 2025-02-02 15:33:11 +01:00
14 changed files with 108 additions and 18 deletions

View File

@ -29,6 +29,7 @@ urlpatterns = [
path("parents/", views.ParentsView.as_view(), name="parents"), path("parents/", views.ParentsView.as_view(), name="parents"),
path("table/<date:start_date>/<date:end_date>/", views.get_table_data, name="table_data"), path("table/<date:start_date>/<date:end_date>/", views.get_table_data, name="table_data"),
path("table/", views.table_view, name="table"), path("table/", views.table_view, name="table"),
path("parents/<int:id>/", views.parent_view, name="parent"),
path("projects/<int:id>/", views.project_view, name="project"), path("projects/<int:id>/", views.project_view, name="project"),
path("projects/<int:id>/set_parent", views.set_parent, name="set_parent"), path("projects/<int:id>/set_parent", views.set_parent, name="set_parent"),
path("stats/by-month/<int:year>/<int:month>/", views.get_stats_by_month, name="stats_by_month"), path("stats/by-month/<int:year>/<int:month>/", views.get_stats_by_month, name="stats_by_month"),

View File

@ -1,8 +1,13 @@
from django import forms from django import forms
from dispatcher.models import Project from dispatcher.models import Project, Parent
class ParentForm(forms.ModelForm):
class Meta:
model = Parent
fields = "__all__"
class ProjectForm(forms.ModelForm): class ProjectForm(forms.ModelForm):
class Meta: class Meta:
model = Project model = Project

View File

@ -0,0 +1,18 @@
# Generated by Django 5.1.5 on 2025-02-02 14:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dispatcher', '0005_clocking'),
]
operations = [
migrations.AlterField(
model_name='parent',
name='project_num',
field=models.CharField(blank=True, max_length=32),
),
]

View File

@ -1,7 +1,7 @@
from django.db import models from django.db import models
class Parent(models.Model): class Parent(models.Model):
project_num = models.CharField(max_length=32) project_num = models.CharField(max_length=32, blank=True)
name = models.CharField(max_length=256) name = models.CharField(max_length=256)
def __str__(self): def __str__(self):

View File

@ -0,0 +1,30 @@
.container {
display: flex;
flex-direction: column;
width: 100%;
max-width: 30em;
align-self: center;
gap: 2em;
}
form {
display: flex;
flex-direction: column;
gap: 1.6em;
}
form > div {
display: flex;
flex-direction: column;
gap: 0.4em;
}
form label {
font-style: italic;
color: var(--light2);
}
form button {
align-self: center;
padding: 0.4em 1.2em;
}

View File

@ -0,0 +1,8 @@
window.addEventListener("load", () => {
document.querySelectorAll(".list li").forEach(row => {
let id = row.dataset.id
row.querySelector("button.edit").addEventListener("click", () => {
window.location.href = `${id}/`
})
})
})

View File

@ -11,7 +11,7 @@ window.addEventListener("load", () => {
}) })
}) })
row.querySelector("button.see").addEventListener("click", () => { row.querySelector("button.edit").addEventListener("click", () => {
window.location.href = `${id}/` window.location.href = `${id}/`
}) })
}) })

View File

@ -297,7 +297,9 @@ class Table {
Array.from(this.clockings.querySelector(".clocking.remote-total").cells).forEach((cell, i) => { Array.from(this.clockings.querySelector(".clocking.remote-total").cells).forEach((cell, i) => {
let endI = startI + cell.colSpan let endI = startI + cell.colSpan
let remote = this.clockingRemotes.slice(startI, endI).reduce((a, b) => a + b, 0) let remote = this.clockingRemotes.slice(startI, endI).reduce((a, b) => a + b, 0)
cell.innerText = Math.round(remote * 100) / 100 let hour = Math.floor(remote)
let min = Math.floor((remote - hour) * 60)
cell.innerText = hour.toString().padStart(2, "0") + ":" + min.toString().padStart(2, "0")
startI = endI startI = endI
}) })

View File

@ -9,7 +9,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from dispatcher.core import import_tasks from dispatcher.core import import_tasks
from dispatcher.forms import ProjectForm, ImportForm from dispatcher.forms import ProjectForm, ImportForm, ParentForm
from dispatcher.models import Project, Parent, Clocking from dispatcher.models import Project, Parent, Clocking
from dispatcher.serializers import ClockingSerializer from dispatcher.serializers import ClockingSerializer
@ -28,14 +28,30 @@ def projects_view(request):
} }
return render(request, "projects.html", context) return render(request, "projects.html", context)
def parent_view(request, id):
parent = get_object_or_404(Parent, id=id)
context = {
"class": "parent",
"id": id
}
form = ParentForm(request.POST or None, request.FILES or None, instance=parent)
if form.is_valid():
form.save()
context["form"] = ParentForm(instance=parent)
return render(request, "edit.html", context)
def project_view(request, id): def project_view(request, id):
project = get_object_or_404(Project, id=id) project = get_object_or_404(Project, id=id)
context = {} context = {
"class": "project",
"id": id
}
form = ProjectForm(request.POST or None, request.FILES or None, instance=project) form = ProjectForm(request.POST or None, request.FILES or None, instance=project)
if form.is_valid(): if form.is_valid():
form.save() form.save()
context["form"] = ProjectForm(instance=project) context["form"] = ProjectForm(instance=project)
return render(request, "project.html", context) return render(request, "edit.html", context)
def table_view(request): def table_view(request):
return render(request, "table.html") return render(request, "table.html")

16
templates/edit.html Normal file
View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load static %}
{% block title %}Editing {{ class }} {{ id }}{% endblock %}
{% block head %}
<link rel="stylesheet" href="{% static "edit.css" %}">
{% endblock %}
{% block main %}
<div class="container">
<h2>Editing {{ class }} {{ id }}</h2>
<form action="" method="POST">
{% csrf_token %}
{{ form }}
<button type="submit">Save</button>
</form>
</div>
{% endblock %}

View File

@ -2,6 +2,7 @@
{% load static %} {% load static %}
{% block head %} {% block head %}
<link rel="stylesheet" href="{% static "list.css" %}"> <link rel="stylesheet" href="{% static "list.css" %}">
{% block extra-head %}{% endblock %}
{% endblock %} {% endblock %}
{% block main %} {% block main %}
<ul class="list"> <ul class="list">

View File

@ -2,6 +2,9 @@
{% load static %} {% load static %}
{% block title %}Parents{% endblock %} {% block title %}Parents{% endblock %}
{% block element_name %}parent{% endblock %} {% block element_name %}parent{% endblock %}
{% block extra-head %}
<script src="{% static "parents.js" %}"></script>
{% endblock %}
{% block element %} {% block element %}
<div class="name">{{ element.name }}</div> <div class="name">{{ element.name }}</div>
<div class="project_num">({{ element.project_num }})</div> <div class="project_num">({{ element.project_num }})</div>

View File

@ -1,10 +0,0 @@
{% extends "base.html" %}
{% block main %}
<h2>Editing project</h2>
<form action="" method="POST">
{% csrf_token %}
{{ form }}
<button type="submit">Save</button>
</form>
{% endblock %}

View File

@ -29,7 +29,7 @@
</select> </select>
</td> </td>
<td> <td>
<button class="see">See</button> <button class="edit">Edit</button>
<button class="delete">Delete</button> <button class="delete">Delete</button>
</td> </td>
</tr> </tr>