added compose window
This commit is contained in:
+119
-1
@@ -37,6 +37,124 @@ body {
|
||||
margin-block: 2rem 1rem;
|
||||
}
|
||||
|
||||
.task-composer {
|
||||
padding: 1.25rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: #07384d;
|
||||
background: #f4fbfe;
|
||||
border: 1px solid #b9e3f3;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 .5rem 1.5rem rgb(7 56 77 / .1);
|
||||
}
|
||||
|
||||
.task-composer__heading h2,
|
||||
.task-composer__heading p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.task-composer__heading p {
|
||||
margin-top: .25rem;
|
||||
color: #4f7280;
|
||||
}
|
||||
|
||||
.task-composer__form {
|
||||
display: grid;
|
||||
gap: .875rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.task-composer label {
|
||||
display: block;
|
||||
margin-bottom: .3rem;
|
||||
font-size: .875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.task-composer input:not([type='checkbox']),
|
||||
.task-composer select,
|
||||
.task-composer textarea {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
border-color: #9ccfdf;
|
||||
}
|
||||
|
||||
.task-composer__main input {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.task-composer__details {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
|
||||
gap: .75rem;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.task-composer__checks {
|
||||
display: flex;
|
||||
gap: .75rem;
|
||||
padding-bottom: .45rem;
|
||||
}
|
||||
|
||||
.task-composer__checks > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .35rem;
|
||||
}
|
||||
|
||||
.task-composer__checks label {
|
||||
order: 2;
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.task-composer__checks input {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.task-composer__notes {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.task-composer__notes summary {
|
||||
color: #087aa9;
|
||||
}
|
||||
|
||||
.task-composer__notes textarea {
|
||||
margin-top: .6rem;
|
||||
}
|
||||
|
||||
.task-composer__actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.task-composer__submit {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: .35rem;
|
||||
margin: 0;
|
||||
padding: .65rem 1rem;
|
||||
color: #fff;
|
||||
background: #087aa9;
|
||||
border: 0;
|
||||
border-radius: .5rem;
|
||||
}
|
||||
|
||||
.task-composer__submit:hover {
|
||||
background: #06668c;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.task-composer__details {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.task-composer__checks {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
}
|
||||
|
||||
.task-list {
|
||||
display: grid;
|
||||
gap: .5rem;
|
||||
@@ -83,7 +201,7 @@ body {
|
||||
}
|
||||
|
||||
.social-battery__levels label {
|
||||
display: grid;
|
||||
display: grid!important;
|
||||
place-items: center;
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
|
||||
services:
|
||||
###> doctrine/doctrine-bundle ###
|
||||
database:
|
||||
ports:
|
||||
- "5432"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
@@ -24,6 +24,7 @@ final class TaskController extends AbstractController
|
||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel),
|
||||
'battery_level' => $batteryLevel,
|
||||
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
||||
'form' => $this->createForm(TaskType::class, new Task()),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ final class TaskController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
public function new(Request $request, EntityManagerInterface $entityManager, TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService): Response
|
||||
{
|
||||
$task = new Task();
|
||||
$form = $this->createForm(TaskType::class, $task);
|
||||
@@ -51,6 +52,15 @@ final class TaskController extends AbstractController
|
||||
$entityManager->persist($task);
|
||||
$entityManager->flush();
|
||||
|
||||
if ($request->headers->has('HX-Request')) {
|
||||
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
||||
|
||||
return $this->render('task/_task_composer_response.html.twig', [
|
||||
'form' => $this->createForm(TaskType::class, new Task()),
|
||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
@@ -75,6 +85,7 @@ final class TaskController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$task->setUpdatedAt(new \DateTimeImmutable());
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
|
||||
|
||||
@@ -41,6 +41,17 @@ class Task
|
||||
#[ORM\Column]
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
|
||||
$this->priority = 'medium';
|
||||
$this->isRecurring = false;
|
||||
$this->isActive = true;
|
||||
$this->createdAt = $now;
|
||||
$this->updatedAt = $now;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
||||
+34
-11
@@ -5,6 +5,11 @@ namespace App\Form;
|
||||
use App\Entity\Task;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TaskType extends AbstractType
|
||||
@@ -12,18 +17,36 @@ class TaskType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('title')
|
||||
->add('description')
|
||||
->add('estimatedDurationMinutes')
|
||||
->add('priority')
|
||||
->add('category')
|
||||
->add('isRecurring')
|
||||
->add('isActive')
|
||||
->add('createdAt', null, [
|
||||
'widget' => 'single_text',
|
||||
->add('title', TextType::class, [
|
||||
'attr' => ['placeholder' => 'What needs doing?', 'autocomplete' => 'off'],
|
||||
])
|
||||
->add('updatedAt', null, [
|
||||
'widget' => 'single_text',
|
||||
->add('description', TextareaType::class, [
|
||||
'required' => false,
|
||||
'attr' => ['placeholder' => 'A helpful note (optional)', 'rows' => 2],
|
||||
])
|
||||
->add('estimatedDurationMinutes', IntegerType::class, [
|
||||
'label' => 'Minutes',
|
||||
'required' => false,
|
||||
'attr' => ['min' => 1, 'placeholder' => '30'],
|
||||
])
|
||||
->add('priority', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Low' => 'low',
|
||||
'Medium' => 'medium',
|
||||
'High' => 'high',
|
||||
],
|
||||
])
|
||||
->add('category', TextType::class, [
|
||||
'required' => false,
|
||||
'attr' => ['placeholder' => 'e.g. Home'],
|
||||
])
|
||||
->add('isRecurring', CheckboxType::class, [
|
||||
'label' => 'Repeats',
|
||||
'required' => false,
|
||||
])
|
||||
->add('isActive', CheckboxType::class, [
|
||||
'label' => 'Active',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<section id="task-composer" class="task-composer" aria-labelledby="task-composer-title">
|
||||
<div class="task-composer__heading">
|
||||
<h2 id="task-composer-title">Add a task</h2>
|
||||
<p>Capture it now; the details can wait.</p>
|
||||
</div>
|
||||
|
||||
{{ form_start(form, {
|
||||
action: path('app_task_new'),
|
||||
attr: {
|
||||
'class': 'task-composer__form',
|
||||
'hx-post': path('app_task_new'),
|
||||
'hx-target': '#task-composer',
|
||||
'hx-swap': 'outerHTML'
|
||||
}
|
||||
}) }}
|
||||
{{ form_errors(form) }}
|
||||
<div class="task-composer__main">
|
||||
{{ form_label(form.title) }}
|
||||
{{ form_widget(form.title, {attr: {autofocus: true}}) }}
|
||||
{{ form_errors(form.title) }}
|
||||
</div>
|
||||
<div class="task-composer__details">
|
||||
<div>{{ form_row(form.estimatedDurationMinutes) }}</div>
|
||||
<div>{{ form_row(form.priority) }}</div>
|
||||
<div>{{ form_row(form.category) }}</div>
|
||||
<div class="task-composer__checks">{{ form_row(form.isRecurring) }}{{ form_row(form.isActive) }}</div>
|
||||
</div>
|
||||
<details class="task-composer__notes">
|
||||
<summary>Add a note</summary>
|
||||
{{ form_row(form.description) }}
|
||||
</details>
|
||||
<div class="task-composer__actions">
|
||||
<button class="task-composer__submit" type="submit"><span class="material-symbols-outlined" aria-hidden="true">add</span>Add task</button>
|
||||
</div>
|
||||
{{ form_end(form) }}
|
||||
</section>
|
||||
@@ -0,0 +1,2 @@
|
||||
{{ include('task/_task_composer.html.twig', {form: form}) }}
|
||||
{{ include('task/_task_list.html.twig', {tasks: tasks, out_of_band: true}) }}
|
||||
@@ -1,4 +1,4 @@
|
||||
<ul id="task-list" class="task-list" aria-label="Tasks">
|
||||
<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}) }}
|
||||
{% else %}
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
<div class="container">
|
||||
<div class="task-list-header">
|
||||
<h1>Tasks</h1>
|
||||
<a class="task-list__new" href="{{ path('app_task_new') }}" aria-label="Create task" title="Create task"><span class="material-symbols-outlined">
|
||||
add
|
||||
</span></a>
|
||||
</div>
|
||||
|
||||
{{ include('task/_task_composer.html.twig', {form: form}) }}
|
||||
|
||||
{{ include('task/_task_recommendations.html.twig', {
|
||||
tasks: tasks,
|
||||
battery_level: battery_level,
|
||||
|
||||
Reference in New Issue
Block a user