Skip to content

Commit

Permalink
BE: Continue sub task update view
Browse files Browse the repository at this point in the history
  • Loading branch information
justuswilhelm committed Jan 9, 2025
1 parent f2b7bda commit b9dfc5c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 91 deletions.
172 changes: 86 additions & 86 deletions backend/projectify/workspace/templates/workspace/task_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,99 +30,99 @@
>
<a href="{% url "dashboard:projects:detail" task.section.project.uuid %}#{{ section.uuid }}"
class="text-primary underline hover:text-primary-hover active:text-primary-pressed text-base">{{ task.section.title }}</a>
&gt; <a href="{% url "dashboard:sections:create-task" task.section.uuid %}"
class="text-primary underline hover:text-primary-hover active:text-primary-pressed text-base">New task (currently creating)</a>
</div>
</div>
<div class="flex items-center justify-between gap-4 sm:flex-row">
<input type="submit"
value="Update task"
name="submit"
class=" bg-primary text-primary-content hover:bg-primary-hover active:bg-primary-pressed text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-disabled disabled:text-disabled-primary-content" />
<input type="submit"
name="submit_stay"
value="Update task and stay"
class=" bg-primary text-primary-content hover:bg-primary-hover active:bg-primary-pressed text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-disabled disabled:text-disabled-primary-content" />
&gt; <a href="{% url "dashboard:tasks:detail" task.uuid %}"
class="text-primary underline hover:text-primary-hover active:text-primary-pressed text-base">{{ task.title }}</a>
</div>
</div>
<div class="flex flex-col gap-8">
<table class="flex w-full max-w-xl flex-col gap-y-4 sm:grid sm:grid-cols-4">
<tbody class="contents">
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.title.label_tag }}</th>
<td class="col-span-3">
<div class="flex items-center justify-between gap-4 sm:flex-row">
<input type="submit"
value="Update task"
name="submit"
class=" bg-primary text-primary-content hover:bg-primary-hover active:bg-primary-pressed text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-disabled disabled:text-disabled-primary-content" />
<input type="submit"
name="submit_stay"
value="Update task and stay"
class=" bg-primary text-primary-content hover:bg-primary-hover active:bg-primary-pressed text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-disabled disabled:text-disabled-primary-content" />
</div>
</div>
<div class="flex flex-col gap-8">
<table class="flex w-full max-w-xl flex-col gap-y-4 sm:grid sm:grid-cols-4">
<tbody class="contents">
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.title.label_tag }}</th>
<td class="col-span-3">
<div class="flex flex-col items-start gap-2">
<div class="flex w-full flex-row items-center gap-2">{{ form.title }}</div>
</div>
</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.assignee.label_tag }}</th>
<td class="col-span-3">{{ form.assignee }}</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.labels.label_tag }}</th>
<td class="col-span-3">{{ form.labels }}</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.due_date.label_tag }}</th>
<td class="col-span-3">
<div class="flex flex-row items-center gap-4">
<div class="flex flex-col items-start gap-2">
<div class="flex w-full flex-row items-center gap-2">{{ form.title }}</div>
</div>
</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.assignee.label_tag }}</th>
<td class="col-span-3">{{ form.assignee }}</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.labels.label_tag }}</th>
<td class="col-span-3">{{ form.labels }}</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.due_date.label_tag }}</th>
<td class="col-span-3">
<div class="flex flex-row items-center gap-4">
<div class="flex flex-col items-start gap-2">
<div class="flex w-full flex-row items-center gap-2">
<input type="text"
class="placeholder:text-task-update-text peer h-full w-full rounded-lg border border-border px-2 py-2"
id="due-date"
name="due-date"
placeholder="Select due date">
</div>
<div class="flex w-full flex-row items-center gap-2">
<input type="text"
class="placeholder:text-task-update-text peer h-full w-full rounded-lg border border-border px-2 py-2"
id="due-date"
name="due-date"
placeholder="Select due date">
</div>
</div>
</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.description.label_tag }}</th>
<td class="col-span-3">{{ form.description }}</td>
</tr>
</tbody>
</table>
<div class="flex flex-col gap-4">
<div class="flex flex-row items-center justify-between">
<div class="flex flex-row items-center gap-4">
<h4 class="text-xl font-bold">Sub tasks</h4>
</div>
<input type="hidden"
name="form-TOTAL_FORMS"
value="{{ formset_total }}"
id="total-subtasks">
<div id="add-subtask" class="flex flex-row items-center gap-6">
<button type="button"
hx-select-oob="#total-subtasks,#add-subtask"
hx-trigger="click"
hx-target="#subtasks"
hx-select="[data-formset]"
hx-swap="beforeend"
hx-swap="outerHTML"
class="w-full text-tertiary-content hover:text-tertiary-content-hover active:bg-tertiary-pressed active:text-tertiary-content-hover text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-transparent disabled:text-disabled-content">
<svg fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="100%"
height="100%"
class="h-6 w-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
Add sub task
</button>
</div>
</div>
</td>
</tr>
<tr class="contents">
<th scope="row" class="col-span-1 text-left font-bold">{{ form.description.label_tag }}</th>
<td class="col-span-3">{{ form.description }}</td>
</tr>
</tbody>
</table>
<div class="flex flex-col gap-4">
<div class="flex flex-row items-center justify-between">
<div class="flex flex-row items-center gap-4">
<h4 class="text-xl font-bold">Sub tasks</h4>
</div>
<input type="hidden"
name="form-TOTAL_FORMS"
value="{{ formset_total }}"
id="total-subtasks">
<div id="add-subtask" class="flex flex-row items-center gap-6">
<button type="button"
hx-select-oob="#total-subtasks,#add-subtask"
hx-trigger="click"
hx-target="#subtasks"
hx-select="[data-formset]"
hx-swap="beforeend"
hx-swap="outerHTML"
class="w-full text-tertiary-content hover:text-tertiary-content-hover active:bg-tertiary-pressed active:text-tertiary-content-hover text-base flex min-w-max flex-row justify-center gap-2 rounded-lg px-4 py-2 font-bold disabled:bg-transparent disabled:text-disabled-content">
<svg fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="100%"
height="100%"
class="h-6 w-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
Add sub task
</button>
</div>
<div id="subtasks">{% include "workspace/task_update/sub_task_update.html" with formset=formset %}</div>
</div>
{{ formset.management_form }}
{% csrf_token %}
<div id="subtasks">{% include "workspace/task_update/sub_task_update.html" with formset=formset %}</div>
</div>
{{ formset.management_form }}
{% csrf_token %}
</div>
</form>
</div>
</form>
{% endblock dashboard_content %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<div class="flex w-full flex-row items-center gap-2">{{ form.title }}</div>
</div>
</div>
<input type="hidden"
name="{{ form.uuid.html_name }}"
value="{{ form.uuid.initial }}">
</div>
</div>
{% endfor %}
6 changes: 2 additions & 4 deletions backend/projectify/workspace/views/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def task_update_view(
"title": f["title"],
"done": f["done"],
"_order": i,
"uuid": UUID(f["uuid"]),
"uuid": f["uuid"],
}
for i, f in enumerate(formset.cleaned_data)
]
Expand All @@ -301,10 +301,8 @@ def task_update_view(
)
if cleaned_data["submit_stay"]:
n = reverse("dashboard:tasks:detail", args=(task.uuid,))
elif cleaned_data["submit"]:
n = reverse("dashboard:projects:detail", args=(project.uuid,))
else:
raise ValueError(cleaned_data)
n = reverse("dashboard:projects:detail", args=(project.uuid,))
return redirect(n)


Expand Down
10 changes: 9 additions & 1 deletion docs/remove-fe-worklog.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,13 @@ to call things what they are instead. Gotta think on this one.

## 2025-01-9

Today I try to finish the formset -> sub task update conversion and make the
Today I finished the formset -> sub task update conversion and make the
basic use case 1. "Make it possible to update existing sub tasks" work.

There are no error messages or anything right now.

I can use this

https://docs.djangoproject.com/en/5.1/topics/forms/#looping-over-the-form-s-fields

and make the template for the form a bit more maintainable. This is the way.

0 comments on commit b9dfc5c

Please sign in to comment.