added compose window
This commit is contained in:
@@ -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,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user