first version of defer/sick mode
This commit is contained in:
@@ -403,6 +403,35 @@ header {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.task-list__item {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.task-list__item-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
}
|
||||
|
||||
.task-list__subtasks {
|
||||
display: grid;
|
||||
gap: .5rem;
|
||||
padding: .5rem 0 0 2.75rem;
|
||||
margin: .5rem 0 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #d9f4ff;
|
||||
}
|
||||
|
||||
.task-list__item--subtask {
|
||||
background-color: #f2fbff;
|
||||
}
|
||||
|
||||
.task-list__add-subtask {
|
||||
color: #087aa9;
|
||||
font-size: .85rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.task-result-container {
|
||||
|
||||
.task-result {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260907123000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add an optional self-referencing parent task relationship for sub-tasks.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
$this->addSql('ALTER TABLE task ADD parent_task_id INT DEFAULT NULL');
|
||||
$this->addSql('CREATE INDEX IDX_TASK_PARENT_TASK ON task (parent_task_id)');
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_TASK_PARENT_TASK FOREIGN KEY (parent_task_id) REFERENCES task (id) ON DELETE SET NULL');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql('ALTER TABLE task ADD parent_task_id INT DEFAULT NULL, ADD INDEX IDX_TASK_PARENT_TASK (parent_task_id), ADD CONSTRAINT FK_TASK_PARENT_TASK FOREIGN KEY (parent_task_id) REFERENCES task (id) ON DELETE SET NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
$this->addSql('ALTER TABLE task DROP CONSTRAINT FK_TASK_PARENT_TASK');
|
||||
$this->addSql('DROP INDEX IDX_TASK_PARENT_TASK');
|
||||
$this->addSql('ALTER TABLE task DROP parent_task_id');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_TASK_PARENT_TASK, DROP INDEX IDX_TASK_PARENT_TASK, DROP parent_task_id');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use App\Entity\Settings;
|
||||
use App\Entity\User;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Repository\TaskRepository;
|
||||
use App\Form\TaskType;
|
||||
use App\Service\TaskDeferralService;
|
||||
use App\Service\TaskRecommendationService;
|
||||
@@ -33,8 +34,11 @@ final class TaskController extends AbstractController
|
||||
/** @var User|null $user */
|
||||
$user = $security->getUser();
|
||||
|
||||
$taskGroups = $taskSchedulingService->taskGroupsForDate($batteryLevel, $selectedDate, $settings);
|
||||
|
||||
return $this->render('task/index.html.twig', [
|
||||
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $settings),
|
||||
'tasks' => $taskGroups['tasks'],
|
||||
'subtasks_by_parent' => $taskGroups['subtasks_by_parent'],
|
||||
'user' => $user,
|
||||
'battery_level' => $batteryLevel,
|
||||
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
||||
@@ -59,9 +63,20 @@ final class TaskController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||
public function new(Request $request, EntityManagerInterface $entityManager, TaskRepository $tasks, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||
{
|
||||
$task = new Task();
|
||||
$task->setScheduledFor($this->selectedDate($request));
|
||||
|
||||
$parentId = $request->query->getInt('parent');
|
||||
if ($parentId > 0) {
|
||||
$parentTask = $tasks->find($parentId);
|
||||
if (null === $parentTask || null !== $parentTask->getParentTask()) {
|
||||
throw $this->createNotFoundException('Choose a top-level task as the parent.');
|
||||
}
|
||||
|
||||
$task->setParentTask($parentTask);
|
||||
}
|
||||
$form = $this->createForm(TaskType::class, $task, ['include_active' => false]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
@@ -76,9 +91,12 @@ final class TaskController extends AbstractController
|
||||
$selectedDate = $task->getScheduledFor() ?? new \DateTimeImmutable('today');
|
||||
$newTask = (new Task())->setScheduledFor($selectedDate);
|
||||
|
||||
$taskGroups = $taskSchedulingService->taskGroupsForDate($batteryLevel, $selectedDate, $this->currentSettings());
|
||||
|
||||
return $this->render('task/_task_composer_response.html.twig', [
|
||||
'form' => $this->createForm(TaskType::class, $newTask, ['include_active' => false]),
|
||||
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||
'tasks' => $taskGroups['tasks'],
|
||||
'subtasks_by_parent' => $taskGroups['subtasks_by_parent'],
|
||||
'selected_date' => $selectedDate,
|
||||
]);
|
||||
}
|
||||
@@ -169,15 +187,21 @@ final class TaskController extends AbstractController
|
||||
|
||||
|
||||
#[Route('/{id}', name: 'app_task_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, Task $task, EntityManagerInterface $entityManager): Response
|
||||
public function delete(Request $request, Task $task, EntityManagerInterface $entityManager, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete' . $task->getId(), $request->getPayload()->getString('_token'))) {
|
||||
foreach ($task->getSubtasks()->toArray() as $subtask) {
|
||||
$subtask->setParentTask(null);
|
||||
}
|
||||
|
||||
$entityManager->remove($task);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
if ($request->headers->has('HX-Request')) {
|
||||
return new Response('', Response::HTTP_OK);
|
||||
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
||||
|
||||
return $this->renderTaskList($taskSchedulingService, $taskRecommendationService, $batteryLevel, $this->selectedDate($request));
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
|
||||
@@ -185,16 +209,22 @@ final class TaskController extends AbstractController
|
||||
|
||||
private function renderTaskList(TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
||||
{
|
||||
$taskGroups = $taskSchedulingService->taskGroupsForDate($batteryLevel, $selectedDate, $this->currentSettings());
|
||||
|
||||
return $this->render('task/_task_list.html.twig', [
|
||||
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||
'tasks' => $taskGroups['tasks'],
|
||||
'subtasks_by_parent' => $taskGroups['subtasks_by_parent'],
|
||||
'selected_date' => $selectedDate,
|
||||
]);
|
||||
}
|
||||
|
||||
private function renderTaskRecommendations(TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
||||
{
|
||||
$taskGroups = $taskSchedulingService->taskGroupsForDate($batteryLevel, $selectedDate, $this->currentSettings());
|
||||
|
||||
return $this->render('task/_task_recommendations.html.twig', [
|
||||
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||
'tasks' => $taskGroups['tasks'],
|
||||
'subtasks_by_parent' => $taskGroups['subtasks_by_parent'],
|
||||
'battery_level' => $batteryLevel,
|
||||
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
||||
'selected_date' => $selectedDate,
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\TaskRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: TaskRepository::class)]
|
||||
class Task
|
||||
@@ -67,6 +70,14 @@ class Task
|
||||
#[ORM\Column(length: 20, nullable: true)]
|
||||
private ?string $deferralSource = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subtasks')]
|
||||
#[ORM\JoinColumn(name: 'parent_task_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||
private ?self $parentTask = null;
|
||||
|
||||
/** @var Collection<int, Task> */
|
||||
#[ORM\OneToMany(mappedBy: 'parentTask', targetEntity: self::class)]
|
||||
private Collection $subtasks;
|
||||
|
||||
|
||||
#[ORM\Column]
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
@@ -83,6 +94,7 @@ class Task
|
||||
$this->scheduledFor = $now->setTime(0, 0);
|
||||
$this->createdAt = $now;
|
||||
$this->updatedAt = $now;
|
||||
$this->subtasks = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -276,6 +288,78 @@ class Task
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParentTask(): ?self
|
||||
{
|
||||
return $this->parentTask;
|
||||
}
|
||||
|
||||
public function setParentTask(?self $parentTask): static
|
||||
{
|
||||
if ($this->parentTask === $parentTask) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->parentTask?->subtasks->removeElement($this);
|
||||
$this->parentTask = $parentTask;
|
||||
|
||||
if (null !== $parentTask && !$parentTask->subtasks->contains($this)) {
|
||||
$parentTask->subtasks->add($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, Task> */
|
||||
public function getSubtasks(): Collection
|
||||
{
|
||||
return $this->subtasks;
|
||||
}
|
||||
|
||||
public function addSubtask(self $subtask): static
|
||||
{
|
||||
$subtask->setParentTask($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeSubtask(self $subtask): static
|
||||
{
|
||||
if ($subtask->getParentTask() === $this) {
|
||||
$subtask->setParentTask(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validateParentTask(ExecutionContextInterface $context): void
|
||||
{
|
||||
$parent = $this->parentTask;
|
||||
$seen = [];
|
||||
|
||||
while (null !== $parent) {
|
||||
if ($parent === $this) {
|
||||
$context->buildViolation('A task cannot be its own parent or create a circular parent relationship.')
|
||||
->atPath('parentTask')
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$key = null === $parent->getId() ? 'new-' . spl_object_id($parent) : 'task-' . $parent->getId();
|
||||
if (isset($seen[$key])) {
|
||||
$context->buildViolation('A task parent relationship cannot contain a cycle.')
|
||||
->atPath('parentTask')
|
||||
->addViolation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$seen[$key] = true;
|
||||
$parent = $parent->getParentTask();
|
||||
}
|
||||
}
|
||||
|
||||
public function setRecurrenceUnit(?string $recurrenceUnit): static
|
||||
{
|
||||
$this->recurrenceUnit = $recurrenceUnit;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Repository\TaskRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@@ -41,6 +43,15 @@ class TaskType extends AbstractType
|
||||
'required' => false,
|
||||
'attr' => ['placeholder' => 'e.g. Home'],
|
||||
])
|
||||
->add('parentTask', EntityType::class, [
|
||||
'class' => Task::class,
|
||||
'label' => 'Parent task',
|
||||
'required' => false,
|
||||
'placeholder' => 'No parent (top-level task)',
|
||||
'choice_label' => static fn (Task $task): string => $task->getTitle() ?? '',
|
||||
'query_builder' => static fn (TaskRepository $repository) => $repository->createTopLevelParentQueryBuilder($options['data']),
|
||||
'help' => 'Optional. Sub-tasks remain independent tasks with their own schedule and completion state.',
|
||||
])
|
||||
->add('requiredOnSickDay', CheckboxType::class, [
|
||||
'label' => 'Required on sick days',
|
||||
'required' => false,
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Task;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -16,6 +17,26 @@ class TaskRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Task::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The first sub-task UI level is attached only to visible top-level tasks.
|
||||
* Keeping this in the repository also prevents a task selecting itself or
|
||||
* one of its children as a parent in the normal form.
|
||||
*/
|
||||
public function createTopLevelParentQueryBuilder(?Task $excluding = null): QueryBuilder
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('t')
|
||||
->andWhere('t.parentTask IS NULL')
|
||||
->orderBy('LOWER(t.title)', 'ASC');
|
||||
|
||||
if (null !== $excluding?->getId()) {
|
||||
$queryBuilder
|
||||
->andWhere('t.id != :excludingTask')
|
||||
->setParameter('excludingTask', $excluding->getId());
|
||||
}
|
||||
|
||||
return $queryBuilder;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Task[] Returns an array of Task objects
|
||||
// */
|
||||
|
||||
@@ -21,12 +21,48 @@ final class TaskSchedulingService
|
||||
* @return Task[]
|
||||
*/
|
||||
public function tasksForDate(int $batteryLevel, \DateTimeImmutable $selectedDate, ?Settings $settings): array
|
||||
{
|
||||
return $this->taskGroupsForDate($batteryLevel, $selectedDate, $settings)['tasks'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{tasks: Task[], subtasks_by_parent: array<int, Task[]>}
|
||||
*/
|
||||
public function taskGroupsForDate(int $batteryLevel, \DateTimeImmutable $selectedDate, ?Settings $settings): array
|
||||
{
|
||||
$tasks = $this->tasks->findAll();
|
||||
|
||||
$this->deferrals->deferMissedTasks($tasks, $selectedDate);
|
||||
$this->sickDays->applyForDate($tasks, $settings, $selectedDate);
|
||||
|
||||
return $this->recommendations->sort($tasks, $batteryLevel, $selectedDate, $settings);
|
||||
$eligibleTasks = $this->recommendations->sort($tasks, $batteryLevel, $selectedDate, $settings);
|
||||
$topLevelTasks = [];
|
||||
$subtasksByParent = [];
|
||||
$visibleParentIds = [];
|
||||
|
||||
foreach ($eligibleTasks as $task) {
|
||||
if (null !== $task->getParentTask()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$topLevelTasks[] = $task;
|
||||
if (null !== $task->getId()) {
|
||||
$visibleParentIds[$task->getId()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($eligibleTasks as $task) {
|
||||
$parentId = $task->getParentTask()?->getId();
|
||||
if (null === $parentId || !isset($visibleParentIds[$parentId])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subtasksByParent[$parentId][] = $task;
|
||||
}
|
||||
|
||||
return [
|
||||
'tasks' => $topLevelTasks,
|
||||
'subtasks_by_parent' => $subtasksByParent,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<div>{{ form_row(form.estimatedDurationMinutes) }}</div>
|
||||
<div>{{ form_row(form.priority) }}</div>
|
||||
<div>{{ form_row(form.category) }}</div>
|
||||
<div>{{ form_row(form.parentTask) }}</div>
|
||||
<div>{{ form_row(form.requiredOnSickDay) }}</div>
|
||||
<div>{{ form_row(form.deferDays) }}</div>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
{{ include('task/_task_composer.html.twig', {form: form}) }}
|
||||
{{ include('task/_task_list.html.twig', {tasks: tasks, selected_date: selected_date|default(null), out_of_band: true}) }}
|
||||
{{ include('task/_task_list.html.twig', {tasks: tasks, subtasks_by_parent: subtasks_by_parent|default({}), selected_date: selected_date|default(null), out_of_band: true}) }}
|
||||
|
||||
@@ -1,67 +1,80 @@
|
||||
<li class="task-list__item{{ not task.isActive ? ' task-list__item--completed' : '' }}">
|
||||
<form class="task-list__completion-form">
|
||||
<input type="hidden" name="date" value="{{ selected_date|default('now')|date('Y-m-d') }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('completion' ~ task.id) }}">
|
||||
<input
|
||||
id="task-completion-{{ task.id }}"
|
||||
class="task-list__checkbox"
|
||||
type="checkbox"
|
||||
name="completed"
|
||||
value="1"
|
||||
{{ not task.isActive ? 'checked' : '' }}
|
||||
aria-label="Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}"
|
||||
hx-post="{{ path('app_task_toggle_completion', {'id': task.id}) }}"
|
||||
hx-include="closest form"
|
||||
hx-target="closest .task-list"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<label class="task-list__toggle" for="task-completion-{{ task.id }}" title="Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}">
|
||||
<span class="material-symbols-outlined task-list__toggle-icon task-list__toggle-icon--unchecked" aria-hidden="true">circle</span>
|
||||
<span class="material-symbols-outlined task-list__toggle-icon task-list__toggle-icon--checked" aria-hidden="true">check_circle</span>
|
||||
<span class="visually-hidden">Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}</span>
|
||||
</label>
|
||||
<a class="task-list__title" href="{{ path('app_task_edit', {'id': task.id}) }}">{{ task.title }}</a>
|
||||
{% if task.isRecurring %}
|
||||
<span class="task-list__recurrence">Every {{ task.recurrenceInterval }} {{ task.recurrenceUnit }}{{ task.recurrenceInterval != 1 ? 's' : '' }}</span>
|
||||
{% endif %}
|
||||
</form>
|
||||
<li class="task-list__item{{ is_subtask|default(false) ? ' task-list__item--subtask' : '' }}{{ not task.isActive ? ' task-list__item--completed' : '' }}">
|
||||
<div class="task-list__item-content">
|
||||
<form class="task-list__completion-form">
|
||||
<input type="hidden" name="date" value="{{ selected_date|default('now')|date('Y-m-d') }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('completion' ~ task.id) }}">
|
||||
<input
|
||||
id="task-completion-{{ task.id }}"
|
||||
class="task-list__checkbox"
|
||||
type="checkbox"
|
||||
name="completed"
|
||||
value="1"
|
||||
{{ not task.isActive ? 'checked' : '' }}
|
||||
aria-label="Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}"
|
||||
hx-post="{{ path('app_task_toggle_completion', {'id': task.id}) }}"
|
||||
hx-include="closest form"
|
||||
hx-target="#task-list"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<label class="task-list__toggle" for="task-completion-{{ task.id }}" title="Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}">
|
||||
<span class="material-symbols-outlined task-list__toggle-icon task-list__toggle-icon--unchecked" aria-hidden="true">circle</span>
|
||||
<span class="material-symbols-outlined task-list__toggle-icon task-list__toggle-icon--checked" aria-hidden="true">check_circle</span>
|
||||
<span class="visually-hidden">Mark {{ task.title }} as {{ task.isActive ? 'completed' : 'active' }}</span>
|
||||
</label>
|
||||
<a class="task-list__title" href="{{ path('app_task_edit', {'id': task.id}) }}">{{ task.title }}</a>
|
||||
{% if task.isRecurring %}
|
||||
<span class="task-list__recurrence">Every {{ task.recurrenceInterval }} {{ task.recurrenceUnit }}{{ task.recurrenceInterval != 1 ? 's' : '' }}</span>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% if task.isActive %}
|
||||
<form
|
||||
class="task-list__snooze-form"
|
||||
hx-post="{{ path('app_task_snooze', {'id': task.id}) }}"
|
||||
hx-target="#task-list"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<input type="hidden" name="date" value="{{ selected_date|default('now')|date('Y-m-d') }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('snooze' ~ task.id) }}">
|
||||
<label class="visually-hidden" for="task-snooze-{{ task.id }}">Snooze {{ task.title }}</label>
|
||||
<select id="task-snooze-{{ task.id }}" name="snooze">
|
||||
<option value="tomorrow">Tomorrow</option>
|
||||
<option value="two_days">2 days</option>
|
||||
<option value="week">1 week</option>
|
||||
<option value="custom">Custom date</option>
|
||||
</select>
|
||||
<label class="visually-hidden" for="task-snooze-date-{{ task.id }}">Custom snooze date</label>
|
||||
<input id="task-snooze-date-{{ task.id }}" type="date" name="custom_date" min="{{ selected_date|default('now')|date_modify('+1 day')|date('Y-m-d') }}">
|
||||
<button type="submit">Snooze</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if task.isActive %}
|
||||
<form
|
||||
class="task-list__snooze-form"
|
||||
hx-post="{{ path('app_task_snooze', {'id': task.id}) }}"
|
||||
hx-target="closest .task-list"
|
||||
class="task-list__remove-form"
|
||||
hx-post="{{ path('app_task_delete', {'id': task.id}) }}"
|
||||
hx-target="#task-list"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Remove {{ task.title }}?"
|
||||
>
|
||||
<input type="hidden" name="date" value="{{ selected_date|default('now')|date('Y-m-d') }}">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('snooze' ~ task.id) }}">
|
||||
<label class="visually-hidden" for="task-snooze-{{ task.id }}">Snooze {{ task.title }}</label>
|
||||
<select id="task-snooze-{{ task.id }}" name="snooze">
|
||||
<option value="tomorrow">Tomorrow</option>
|
||||
<option value="two_days">2 days</option>
|
||||
<option value="week">1 week</option>
|
||||
<option value="custom">Custom date</option>
|
||||
</select>
|
||||
<label class="visually-hidden" for="task-snooze-date-{{ task.id }}">Custom snooze date</label>
|
||||
<input id="task-snooze-date-{{ task.id }}" type="date" name="custom_date" min="{{ selected_date|default('now')|date_modify('+1 day')|date('Y-m-d') }}">
|
||||
<button type="submit">Snooze</button>
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ task.id) }}">
|
||||
<button class="task-list__remove" type="submit" aria-label="Remove {{ task.title }}" title="Remove {{ task.title }}">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">delete</span>
|
||||
</button>
|
||||
</form>
|
||||
<a class="task-list__title" href="{{ path('app_task_edit', {'id': task.id}) }}" aria-label="Edit {{ task.title }}" title="Edit {{ task.title }}">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">edit</span>
|
||||
</a>
|
||||
{% if not is_subtask|default(false) %}
|
||||
<a class="task-list__add-subtask" href="{{ path('app_task_new', {parent: task.id, date: selected_date|default('now')|date('Y-m-d')}) }}">Add sub-task</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if subtasks|default([]) is not empty %}
|
||||
<ul class="task-list__subtasks" aria-label="Sub-tasks for {{ task.title }}">
|
||||
{% for subtask in subtasks %}
|
||||
{{ include('task/_task_item.html.twig', {task: subtask, subtasks: [], is_subtask: true, selected_date: selected_date|default(null)}) }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<form
|
||||
class="task-list__remove-form"
|
||||
hx-post="{{ path('app_task_delete', {'id': task.id}) }}"
|
||||
hx-target="closest .task-list__item"
|
||||
hx-swap="delete"
|
||||
hx-confirm="Remove {{ task.title }}?"
|
||||
>
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ task.id) }}">
|
||||
<button class="task-list__remove" type="submit" aria-label="Remove {{ task.title }}" title="Remove {{ task.title }}">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">delete</span>
|
||||
</button>
|
||||
</form>
|
||||
<a class="task-list__title" href="{{ path('app_task_edit', {'id': task.id}) }}">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">edit</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<ul id="task-list" class="task-list" aria-label="Tasks"{% if out_of_band|default(false) %} hx-swap-oob="outerHTML"{% endif %}>
|
||||
{% for task in tasks %}
|
||||
{{ include('task/_task_item.html.twig', {task: task, selected_date: selected_date|default(null)}) }}
|
||||
{{ include('task/_task_item.html.twig', {task: task, subtasks: subtasks_by_parent[task.id]|default([]), selected_date: selected_date|default(null)}) }}
|
||||
{% else %}
|
||||
<li class="task-list__empty">No tasks yet.</li>
|
||||
{% endfor %}
|
||||
|
||||
@@ -36,5 +36,5 @@
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{{ include('task/_task_list.html.twig', {tasks: tasks}) }}
|
||||
{{ include('task/_task_list.html.twig', {tasks: tasks, subtasks_by_parent: subtasks_by_parent|default({}), selected_date: selected_date|default(null)}) }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user