first version of defer/sick mode
This commit is contained in:
@@ -540,4 +540,27 @@ header {
|
|||||||
.weather-refresh {
|
.weather-refresh {
|
||||||
box-shadow: unset;
|
box-shadow: unset;
|
||||||
border: unset;
|
border: unset;
|
||||||
|
}
|
||||||
|
.user {
|
||||||
|
border-radius: 100%;
|
||||||
|
height: 50px;
|
||||||
|
width: 50px;
|
||||||
|
background-color: #fff;
|
||||||
|
border-color: #aaa;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: #000;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 1.6em;
|
||||||
|
line-height: 1;
|
||||||
|
// temporary?
|
||||||
|
position: fixed;
|
||||||
|
top: 50px;
|
||||||
|
right: 50px;
|
||||||
|
&:visited,
|
||||||
|
&:focus {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20260825212706 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE user ADD username VARCHAR(255) NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE `user` DROP username');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20260825213158 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE user CHANGE username username VARCHAR(255) DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE `user` CHANGE username username VARCHAR(255) NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20260907120000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add task deferral, Sick Day task requirements, and persistent Sick Day settings.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||||
|
$this->addSql('ALTER TABLE task ADD required_on_sick_day BOOLEAN NOT NULL DEFAULT FALSE');
|
||||||
|
$this->addSql('ALTER TABLE task ADD defer_days INT DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE task ADD deferred_until DATE DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE task ADD deferral_source VARCHAR(20) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE settings ADD sick_mode_enabled BOOLEAN NOT NULL DEFAULT FALSE');
|
||||||
|
$this->addSql('ALTER TABLE settings ADD sick_until DATE DEFAULT NULL');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE task ADD required_on_sick_day TINYINT(1) NOT NULL DEFAULT 0, ADD defer_days INT DEFAULT NULL, ADD deferred_until DATE DEFAULT NULL, ADD deferral_source VARCHAR(20) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE settings ADD sick_mode_enabled TINYINT(1) NOT NULL DEFAULT 0, ADD sick_until DATE DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||||
|
$this->addSql('ALTER TABLE task DROP required_on_sick_day');
|
||||||
|
$this->addSql('ALTER TABLE task DROP defer_days');
|
||||||
|
$this->addSql('ALTER TABLE task DROP deferred_until');
|
||||||
|
$this->addSql('ALTER TABLE task DROP deferral_source');
|
||||||
|
$this->addSql('ALTER TABLE settings DROP sick_mode_enabled');
|
||||||
|
$this->addSql('ALTER TABLE settings DROP sick_until');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE task DROP required_on_sick_day, DROP defer_days, DROP deferred_until, DROP deferral_source');
|
||||||
|
$this->addSql('ALTER TABLE settings DROP sick_mode_enabled, DROP sick_until');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,10 @@ use App\Entity\Settings;
|
|||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
|
||||||
use App\Entity\Task;
|
use App\Entity\Task;
|
||||||
use App\Entity\UserSetting;
|
|
||||||
use App\Form\TaskType;
|
use App\Form\TaskType;
|
||||||
use App\Repository\TaskRepository;
|
use App\Service\TaskDeferralService;
|
||||||
use App\Service\TaskRecommendationService;
|
use App\Service\TaskRecommendationService;
|
||||||
|
use App\Service\TaskSchedulingService;
|
||||||
use App\Service\WeatherService;
|
use App\Service\WeatherService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@@ -16,12 +16,13 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
|
||||||
#[Route('/task')]
|
#[Route('/task')]
|
||||||
final class TaskController extends AbstractController
|
final class TaskController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(name: 'app_task_index', methods: ['GET'])]
|
#[Route(name: 'app_task_index', methods: ['GET'])]
|
||||||
public function index(Request $request, TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService, WeatherService $weatherService): Response
|
public function index(Request $request, TaskRecommendationService $taskRecommendationService, TaskSchedulingService $taskSchedulingService, WeatherService $weatherService, Security $security): Response
|
||||||
{
|
{
|
||||||
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
||||||
$selectedDate = $this->selectedDate($request);
|
$selectedDate = $this->selectedDate($request);
|
||||||
@@ -29,9 +30,12 @@ final class TaskController extends AbstractController
|
|||||||
$newTask->setScheduledFor($selectedDate);
|
$newTask->setScheduledFor($selectedDate);
|
||||||
$settings = $this->currentSettings();
|
$settings = $this->currentSettings();
|
||||||
|
|
||||||
|
/** @var User|null $user */
|
||||||
|
$user = $security->getUser();
|
||||||
|
|
||||||
return $this->render('task/index.html.twig', [
|
return $this->render('task/index.html.twig', [
|
||||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel, $selectedDate, $settings),
|
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $settings),
|
||||||
|
'user' => $user,
|
||||||
'battery_level' => $batteryLevel,
|
'battery_level' => $batteryLevel,
|
||||||
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
||||||
'selected_date' => $selectedDate,
|
'selected_date' => $selectedDate,
|
||||||
@@ -42,7 +46,7 @@ final class TaskController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/social-battery', name: 'app_task_social_battery', methods: ['POST'])]
|
#[Route('/social-battery', name: 'app_task_social_battery', methods: ['POST'])]
|
||||||
public function socialBattery(Request $request, TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService): Response
|
public function socialBattery(Request $request, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||||
{
|
{
|
||||||
if (!$this->isCsrfTokenValid('social_battery', $request->getPayload()->getString('_token'))) {
|
if (!$this->isCsrfTokenValid('social_battery', $request->getPayload()->getString('_token'))) {
|
||||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||||
@@ -51,11 +55,11 @@ final class TaskController extends AbstractController
|
|||||||
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getPayload()->getInt('social_battery'));
|
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getPayload()->getInt('social_battery'));
|
||||||
$request->getSession()->set('social_battery', $batteryLevel);
|
$request->getSession()->set('social_battery', $batteryLevel);
|
||||||
|
|
||||||
return $this->renderTaskRecommendations($taskRepository, $taskRecommendationService, $batteryLevel, $this->selectedDate($request));
|
return $this->renderTaskRecommendations($taskSchedulingService, $taskRecommendationService, $batteryLevel, $this->selectedDate($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])]
|
#[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])]
|
||||||
public function new(Request $request, EntityManagerInterface $entityManager, TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService): Response
|
public function new(Request $request, EntityManagerInterface $entityManager, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||||
{
|
{
|
||||||
$task = new Task();
|
$task = new Task();
|
||||||
$form = $this->createForm(TaskType::class, $task, ['include_active' => false]);
|
$form = $this->createForm(TaskType::class, $task, ['include_active' => false]);
|
||||||
@@ -74,7 +78,7 @@ final class TaskController extends AbstractController
|
|||||||
|
|
||||||
return $this->render('task/_task_composer_response.html.twig', [
|
return $this->render('task/_task_composer_response.html.twig', [
|
||||||
'form' => $this->createForm(TaskType::class, $newTask, ['include_active' => false]),
|
'form' => $this->createForm(TaskType::class, $newTask, ['include_active' => false]),
|
||||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel, $selectedDate),
|
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||||
'selected_date' => $selectedDate,
|
'selected_date' => $selectedDate,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -116,7 +120,7 @@ final class TaskController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/{id}/completion', name: 'app_task_toggle_completion', methods: ['POST'])]
|
#[Route('/{id}/completion', name: 'app_task_toggle_completion', methods: ['POST'])]
|
||||||
public function toggleCompletion(Request $request, Task $task, EntityManagerInterface $entityManager, TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService): Response
|
public function toggleCompletion(Request $request, Task $task, EntityManagerInterface $entityManager, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||||
{
|
{
|
||||||
if (!$this->isCsrfTokenValid('completion' . $task->getId(), $request->getPayload()->getString('_token'))) {
|
if (!$this->isCsrfTokenValid('completion' . $task->getId(), $request->getPayload()->getString('_token'))) {
|
||||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||||
@@ -130,9 +134,40 @@ final class TaskController extends AbstractController
|
|||||||
|
|
||||||
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
||||||
|
|
||||||
return $this->renderTaskList($taskRepository, $taskRecommendationService, $batteryLevel, $this->selectedDate($request));
|
return $this->renderTaskList($taskSchedulingService, $taskRecommendationService, $batteryLevel, $this->selectedDate($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}/snooze', name: 'app_task_snooze', methods: ['POST'])]
|
||||||
|
public function snooze(Request $request, Task $task, TaskDeferralService $taskDeferralService, EntityManagerInterface $entityManager, TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService): Response
|
||||||
|
{
|
||||||
|
if (!$this->isCsrfTokenValid('snooze' . $task->getId(), $request->getPayload()->getString('_token'))) {
|
||||||
|
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedDate = $this->selectedDate($request);
|
||||||
|
$choice = $request->getPayload()->getString('snooze');
|
||||||
|
$until = match ($choice) {
|
||||||
|
'tomorrow' => $selectedDate->modify('+1 day'),
|
||||||
|
'two_days' => $selectedDate->modify('+2 days'),
|
||||||
|
'week' => $selectedDate->modify('+1 week'),
|
||||||
|
'custom' => \DateTimeImmutable::createFromFormat('!Y-m-d', $request->getPayload()->getString('custom_date')),
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!$until instanceof \DateTimeImmutable || $until <= $selectedDate) {
|
||||||
|
throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException('Choose a future snooze date.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$taskDeferralService->deferUntil($task, $until, TaskDeferralService::SOURCE_MANUAL);
|
||||||
|
$task->setUpdatedAt(new \DateTimeImmutable());
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
$batteryLevel = $taskRecommendationService->normaliseBatteryLevel($request->getSession()->get('social_battery', 3));
|
||||||
|
|
||||||
|
return $this->renderTaskList($taskSchedulingService, $taskRecommendationService, $batteryLevel, $selectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_task_delete', methods: ['POST'])]
|
#[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): Response
|
||||||
{
|
{
|
||||||
@@ -148,18 +183,18 @@ final class TaskController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
|
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderTaskList(TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
private function renderTaskList(TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
||||||
{
|
{
|
||||||
return $this->render('task/_task_list.html.twig', [
|
return $this->render('task/_task_list.html.twig', [
|
||||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel, $selectedDate),
|
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||||
'selected_date' => $selectedDate,
|
'selected_date' => $selectedDate,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderTaskRecommendations(TaskRepository $taskRepository, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
private function renderTaskRecommendations(TaskSchedulingService $taskSchedulingService, TaskRecommendationService $taskRecommendationService, int $batteryLevel, \DateTimeImmutable $selectedDate): Response
|
||||||
{
|
{
|
||||||
return $this->render('task/_task_recommendations.html.twig', [
|
return $this->render('task/_task_recommendations.html.twig', [
|
||||||
'tasks' => $taskRecommendationService->sort($taskRepository->findAll(), $batteryLevel, $selectedDate),
|
'tasks' => $taskSchedulingService->tasksForDate($batteryLevel, $selectedDate, $this->currentSettings()),
|
||||||
'battery_level' => $batteryLevel,
|
'battery_level' => $batteryLevel,
|
||||||
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
'battery_budget' => $taskRecommendationService->budgetFor($batteryLevel),
|
||||||
'selected_date' => $selectedDate,
|
'selected_date' => $selectedDate,
|
||||||
@@ -204,11 +239,13 @@ final class TaskController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_task_index');
|
return $this->redirectToRoute('app_task_index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserSetting(string $label): Settings{
|
public function getUserSetting(string $label): Settings
|
||||||
|
{
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$settings = $user->getSettings();
|
$settings = $user->getSettings();
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Form\UserType;
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
#[Route('/user')]
|
||||||
|
final class UserController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route(name: 'app_user_index', methods: ['GET'])]
|
||||||
|
public function index(UserRepository $userRepository): Response
|
||||||
|
{
|
||||||
|
return $this->render('user/index.html.twig', [
|
||||||
|
'users' => $userRepository->findAll(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/new', name: 'app_user_new', methods: ['GET', 'POST'])]
|
||||||
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$form = $this->createForm(UserType::class, $user);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$entityManager->persist($user);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('user/new.html.twig', [
|
||||||
|
'user' => $user,
|
||||||
|
'form' => $form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}', name: 'app_user_show', methods: ['GET'])]
|
||||||
|
public function show(User $user): Response
|
||||||
|
{
|
||||||
|
return $this->render('user/show.html.twig', [
|
||||||
|
'user' => $user,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}/edit', name: 'app_user_edit', methods: ['GET', 'POST'])]
|
||||||
|
public function edit(Request $request, User $user, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
$form = $this->createForm(UserType::class, $user);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('user/edit.html.twig', [
|
||||||
|
'user' => $user,
|
||||||
|
'form' => $form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}', name: 'app_user_delete', methods: ['POST'])]
|
||||||
|
public function delete(Request $request, User $user, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->getPayload()->getString('_token'))) {
|
||||||
|
$entityManager->remove($user);
|
||||||
|
$entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,80 +2,48 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\UserSetting;
|
use App\Entity\Settings;
|
||||||
use App\Form\UserSetting1Type;
|
use App\Entity\User;
|
||||||
use App\Repository\UserSettingRepository;
|
use App\Form\SettingsType;
|
||||||
|
use App\Service\SickDayService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
#[Route('/user/settings')]
|
#[Route('/settings')]
|
||||||
final class UserSettingController extends AbstractController
|
final class UserSettingController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(name: 'app_user_settings_index', methods: ['GET'])]
|
#[Route(name: 'app_settings', methods: ['GET', 'POST'])]
|
||||||
public function index(UserSettingRepository $UserSettingRepository): Response
|
public function index(Request $request, EntityManagerInterface $entityManager, SickDayService $sickDays): Response
|
||||||
{
|
{
|
||||||
return $this->render('user_settings/index.html.twig', [
|
$user = $this->getUser();
|
||||||
'user_settings' => $UserSettingRepository->findAll(),
|
if (!$user instanceof User) {
|
||||||
]);
|
throw $this->createAccessDeniedException();
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/new', name: 'app_user_settings_new', methods: ['GET', 'POST'])]
|
|
||||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
|
||||||
{
|
|
||||||
$userSetting = new UserSetting();
|
|
||||||
$form = $this->createForm(UserSetting1Type::class, $userSetting);
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
|
||||||
$entityManager->persist($userSetting);
|
|
||||||
$entityManager->flush();
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('user_settings/new.html.twig', [
|
$settings = $user->getSettings();
|
||||||
'user_setting' => $userSetting,
|
if (null === $settings) {
|
||||||
'form' => $form,
|
$settings = (new Settings())->setUser($user);
|
||||||
]);
|
$user->setSettings($settings);
|
||||||
}
|
$entityManager->persist($settings);
|
||||||
|
$entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_user_settings_show', methods: ['GET'])]
|
$form = $this->createForm(SettingsType::class, $settings);
|
||||||
public function show(UserSetting $userSetting): Response
|
|
||||||
{
|
|
||||||
return $this->render('user_settings/show.html.twig', [
|
|
||||||
'user_setting' => $userSetting,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/{id}/edit', name: 'app_user_settings_edit', methods: ['GET', 'POST'])]
|
|
||||||
public function edit(Request $request, UserSetting $userSetting, EntityManagerInterface $entityManager): Response
|
|
||||||
{
|
|
||||||
$form = $this->createForm(UserSetting1Type::class, $userSetting);
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
$sickDays->syncStoredDeferrals($settings);
|
||||||
|
|
||||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
return $this->redirectToRoute('app_settings', [], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('user_settings/edit.html.twig', [
|
return $this->render('settings/index.html.twig', [
|
||||||
'user_setting' => $userSetting,
|
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
|
'settings' => $settings,
|
||||||
|
'today' => new \DateTimeImmutable('today'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_user_settings_delete', methods: ['POST'])]
|
|
||||||
public function delete(Request $request, UserSetting $userSetting, EntityManagerInterface $entityManager): Response
|
|
||||||
{
|
|
||||||
if ($this->isCsrfTokenValid('delete'.$userSetting->getId(), $request->getPayload()->getString('_token'))) {
|
|
||||||
$entityManager->remove($userSetting);
|
|
||||||
$entityManager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\SettingsRepository;
|
use App\Repository\SettingsRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: SettingsRepository::class)]
|
#[ORM\Entity(repositoryClass: SettingsRepository::class)]
|
||||||
@@ -26,6 +27,12 @@ class Settings
|
|||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?\DateTimeImmutable $locationUpdatedAt = null;
|
private ?\DateTimeImmutable $locationUpdatedAt = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => false])]
|
||||||
|
private bool $sickModeEnabled = false;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||||
|
private ?\DateTimeImmutable $sickUntil = null;
|
||||||
|
|
||||||
public function getId(): ?int { return $this->id; }
|
public function getId(): ?int { return $this->id; }
|
||||||
public function getUser(): ?User { return $this->user; }
|
public function getUser(): ?User { return $this->user; }
|
||||||
public function setUser(User $user): static { $this->user = $user; return $this; }
|
public function setUser(User $user): static { $this->user = $user; return $this; }
|
||||||
@@ -46,4 +53,33 @@ class Settings
|
|||||||
{
|
{
|
||||||
return null !== $this->latitude && null !== $this->longitude;
|
return null !== $this->latitude && null !== $this->longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isSickModeEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->sickModeEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSickModeEnabled(bool $sickModeEnabled): static
|
||||||
|
{
|
||||||
|
$this->sickModeEnabled = $sickModeEnabled;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSickUntil(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->sickUntil;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSickUntil(?\DateTimeImmutable $sickUntil): static
|
||||||
|
{
|
||||||
|
$this->sickUntil = $sickUntil?->setTime(0, 0);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSickOn(\DateTimeImmutable $date): bool
|
||||||
|
{
|
||||||
|
return $this->sickModeEnabled && (null === $this->sickUntil || $date->setTime(0, 0) <= $this->sickUntil);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Entity;
|
|||||||
use App\Repository\TaskRepository;
|
use App\Repository\TaskRepository;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: TaskRepository::class)]
|
#[ORM\Entity(repositoryClass: TaskRepository::class)]
|
||||||
class Task
|
class Task
|
||||||
@@ -53,6 +54,19 @@ class Task
|
|||||||
#[ORM\Column(length: 30)]
|
#[ORM\Column(length: 30)]
|
||||||
private ?string $weatherProfile = 'none';
|
private ?string $weatherProfile = 'none';
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => false])]
|
||||||
|
private bool $requiredOnSickDay = false;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
#[Assert\Positive]
|
||||||
|
private ?int $deferDays = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||||
|
private ?\DateTimeImmutable $deferredUntil = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
private ?string $deferralSource = null;
|
||||||
|
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private ?\DateTimeImmutable $updatedAt = null;
|
private ?\DateTimeImmutable $updatedAt = null;
|
||||||
@@ -213,6 +227,55 @@ class Task
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequiredOnSickDay(): bool
|
||||||
|
{
|
||||||
|
return $this->requiredOnSickDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRequiredOnSickDay(bool $requiredOnSickDay): static
|
||||||
|
{
|
||||||
|
$this->requiredOnSickDay = $requiredOnSickDay;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeferDays(): ?int
|
||||||
|
{
|
||||||
|
return $this->deferDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeferDays(?int $deferDays): static
|
||||||
|
{
|
||||||
|
$this->deferDays = $deferDays;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeferredUntil(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->deferredUntil;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeferredUntil(?\DateTimeImmutable $deferredUntil): static
|
||||||
|
{
|
||||||
|
$this->deferredUntil = $deferredUntil?->setTime(0, 0);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeferralSource(): ?string
|
||||||
|
{
|
||||||
|
return $this->deferralSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeferralSource(?string $deferralSource): static
|
||||||
|
{
|
||||||
|
$this->deferralSource = $deferralSource;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setRecurrenceUnit(?string $recurrenceUnit): static
|
public function setRecurrenceUnit(?string $recurrenceUnit): static
|
||||||
{
|
{
|
||||||
$this->recurrenceUnit = $recurrenceUnit;
|
$this->recurrenceUnit = $recurrenceUnit;
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
#[ORM\OneToMany(targetEntity: UserSetting::class, mappedBy: 'user_id', orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: UserSetting::class, mappedBy: 'user_id', orphanRemoval: true)]
|
||||||
private Collection $UserSetting;
|
private Collection $UserSetting;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $username = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->UserSetting = new ArrayCollection();
|
$this->UserSetting = new ArrayCollection();
|
||||||
@@ -171,4 +174,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUsername(): ?string
|
||||||
|
{
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUsername(string $username): static
|
||||||
|
{
|
||||||
|
$this->username = $username;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Settings;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
final class SettingsType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('sickModeEnabled', CheckboxType::class, [
|
||||||
|
'label' => 'Sick Day Mode',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('sickUntil', DateType::class, [
|
||||||
|
'label' => 'Expected recovery date',
|
||||||
|
'widget' => 'single_text',
|
||||||
|
'input' => 'datetime_immutable',
|
||||||
|
'required' => false,
|
||||||
|
'help' => 'Optional. Sick Day Mode stays active until you turn it off when this is blank.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults(['data_class' => Settings::class]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,6 +41,16 @@ class TaskType extends AbstractType
|
|||||||
'required' => false,
|
'required' => false,
|
||||||
'attr' => ['placeholder' => 'e.g. Home'],
|
'attr' => ['placeholder' => 'e.g. Home'],
|
||||||
])
|
])
|
||||||
|
->add('requiredOnSickDay', CheckboxType::class, [
|
||||||
|
'label' => 'Required on sick days',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('deferDays', IntegerType::class, [
|
||||||
|
'label' => 'Automatically defer missed tasks by (days)',
|
||||||
|
'required' => false,
|
||||||
|
'attr' => ['min' => 1, 'placeholder' => 'Optional'],
|
||||||
|
'help' => 'Used when automatic missed-task deferral is enabled.',
|
||||||
|
])
|
||||||
->add('isOutdoor', CheckboxType::class, [
|
->add('isOutdoor', CheckboxType::class, [
|
||||||
'label' => 'Outdoor task',
|
'label' => 'Outdoor task',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Settings;
|
||||||
|
use App\Entity\User;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class UserType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('email')
|
||||||
|
->add('roles')
|
||||||
|
->add('password')
|
||||||
|
->add('username')
|
||||||
|
->add('settings', EntityType::class, [
|
||||||
|
'class' => Settings::class,
|
||||||
|
'choice_label' => 'id',
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => User::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\Settings;
|
||||||
|
use App\Entity\Task;
|
||||||
|
use App\Repository\TaskRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
/** Applies Sick Day policy through the shared task deferral mechanism. */
|
||||||
|
final class SickDayService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TaskRecommendationService $recommendations,
|
||||||
|
private TaskDeferralService $deferrals,
|
||||||
|
private TaskRepository $tasks,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Task[] $tasks
|
||||||
|
*/
|
||||||
|
public function applyForDate(array $tasks, ?Settings $settings, \DateTimeImmutable $selectedDate): void
|
||||||
|
{
|
||||||
|
if (null === $settings || !$settings->isSickOn($selectedDate)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// With no recovery estimate, the date advances only as the user views
|
||||||
|
// dates. Disabling the mode therefore immediately restores eligibility.
|
||||||
|
$returnDate = (null === $settings->getSickUntil() ? $selectedDate : $settings->getSickUntil())
|
||||||
|
->modify('+1 day')
|
||||||
|
->setTime(0, 0);
|
||||||
|
$changed = false;
|
||||||
|
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
if (!$task->isActive()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($task->isRequiredOnSickDay()) {
|
||||||
|
if (TaskDeferralService::SOURCE_SICK_DAY === $task->getDeferralSource()) {
|
||||||
|
$this->deferrals->clearDeferral($task);
|
||||||
|
$changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->recommendations->isNormallyScheduledFor($task, $selectedDate)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = $this->deferrals->replaceSickDayDeferral($task, $returnDate) || $changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changing or disabling Sick Day Mode should affect only its own deferrals.
|
||||||
|
*/
|
||||||
|
public function syncStoredDeferrals(Settings $settings): void
|
||||||
|
{
|
||||||
|
$tasks = $this->tasks->findBy(['deferralSource' => TaskDeferralService::SOURCE_SICK_DAY]);
|
||||||
|
$changed = false;
|
||||||
|
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
if (!$settings->isSickModeEnabled()) {
|
||||||
|
$this->deferrals->clearDeferral($task);
|
||||||
|
$changed = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $settings->getSickUntil()) {
|
||||||
|
$changed = $this->deferrals->replaceSickDayDeferral($task, $settings->getSickUntil()->modify('+1 day')) || $changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\Task;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Owns the temporary scheduling override shared by manual and automatic rules.
|
||||||
|
*/
|
||||||
|
final class TaskDeferralService
|
||||||
|
{
|
||||||
|
public const SOURCE_MANUAL = 'manual';
|
||||||
|
public const SOURCE_MISSED = 'missed';
|
||||||
|
public const SOURCE_SICK_DAY = 'sick_day';
|
||||||
|
|
||||||
|
public function __construct(private EntityManagerInterface $entityManager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deferUntil(Task $task, \DateTimeImmutable $until, ?string $source = null): bool
|
||||||
|
{
|
||||||
|
$until = $until->setTime(0, 0);
|
||||||
|
$current = $task->getDeferredUntil();
|
||||||
|
|
||||||
|
if (null !== $current && $current >= $until) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$task
|
||||||
|
->setDeferredUntil($until)
|
||||||
|
->setDeferralSource($source);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deferByDays(Task $task, int $days, ?string $source = null, ?\DateTimeImmutable $from = null): bool
|
||||||
|
{
|
||||||
|
if ($days < 1) {
|
||||||
|
throw new \InvalidArgumentException('A task must be deferred by at least one day.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$from ??= new \DateTimeImmutable('today');
|
||||||
|
|
||||||
|
return $this->deferUntil($task, $from->setTime(0, 0)->modify(sprintf('+%d days', $days)), $source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updating the recovery estimate may move only a Sick Day deferral earlier.
|
||||||
|
* A manual (or future) deferral is never shortened by Sick Day Mode.
|
||||||
|
*/
|
||||||
|
public function replaceSickDayDeferral(Task $task, \DateTimeImmutable $until): bool
|
||||||
|
{
|
||||||
|
$until = $until->setTime(0, 0);
|
||||||
|
if (self::SOURCE_SICK_DAY !== $task->getDeferralSource()) {
|
||||||
|
return $this->deferUntil($task, $until, self::SOURCE_SICK_DAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($task->getDeferredUntil()?->format('Y-m-d') === $until->format('Y-m-d')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$task->setDeferredUntil($until);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearDeferral(Task $task): void
|
||||||
|
{
|
||||||
|
$task
|
||||||
|
->setDeferredUntil(null)
|
||||||
|
->setDeferralSource(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Task[] $tasks
|
||||||
|
*/
|
||||||
|
public function deferMissedTasks(array $tasks, \DateTimeImmutable $selectedDate): void
|
||||||
|
{
|
||||||
|
$changed = false;
|
||||||
|
$selectedDate = $selectedDate->setTime(0, 0);
|
||||||
|
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
$scheduledFor = $task->getScheduledFor();
|
||||||
|
$deferDays = $task->getDeferDays();
|
||||||
|
|
||||||
|
// Recurring tasks already have a future occurrence owned by their
|
||||||
|
// recurrence rule. Do not manufacture a second catch-up occurrence.
|
||||||
|
if (!$task->isActive() || $task->isRecurring() || null === $scheduledFor || null === $deferDays
|
||||||
|
|| $scheduledFor >= $selectedDate || self::SOURCE_MISSED === $task->getDeferralSource()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = $this->deferByDays($task, $deferDays, self::SOURCE_MISSED, $selectedDate) || $changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDeferred(Task $task, ?\DateTimeImmutable $on = null): bool
|
||||||
|
{
|
||||||
|
$on ??= new \DateTimeImmutable('today');
|
||||||
|
|
||||||
|
return null !== $task->getDeferredUntil() && $on->setTime(0, 0) < $task->getDeferredUntil();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,8 +54,9 @@ final class TaskRecommendationService
|
|||||||
$selectedDate = $selectedDate->setTime(0, 0);
|
$selectedDate = $selectedDate->setTime(0, 0);
|
||||||
$tasks = array_values(array_filter(
|
$tasks = array_values(array_filter(
|
||||||
$tasks,
|
$tasks,
|
||||||
fn (Task $task): bool => $this->isScheduledFor($task, $selectedDate)
|
fn (Task $task): bool => !$this->isDeferredOn($task, $selectedDate)
|
||||||
|| $this->weatherEvaluator->shouldCarryForward($task, $selectedDate, $previousForecast, $forecast),
|
&& ($this->isScheduledFor($task, $selectedDate)
|
||||||
|
|| $this->weatherEvaluator->shouldCarryForward($task, $selectedDate, $previousForecast, $forecast)),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
@@ -68,6 +69,18 @@ final class TaskRecommendationService
|
|||||||
|
|
||||||
public function isScheduledFor(Task $task, \DateTimeImmutable $selectedDate): bool
|
public function isScheduledFor(Task $task, \DateTimeImmutable $selectedDate): bool
|
||||||
{
|
{
|
||||||
|
$selectedDate = $selectedDate->setTime(0, 0);
|
||||||
|
$deferredUntil = $task->getDeferredUntil();
|
||||||
|
if (null !== $deferredUntil && $selectedDate->format('Y-m-d') === $deferredUntil->format('Y-m-d')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->isNormallyScheduledFor($task, $selectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNormallyScheduledFor(Task $task, \DateTimeImmutable $selectedDate): bool
|
||||||
|
{
|
||||||
|
$selectedDate = $selectedDate->setTime(0, 0);
|
||||||
$scheduledFor = $task->getScheduledFor();
|
$scheduledFor = $task->getScheduledFor();
|
||||||
if (null === $scheduledFor || $selectedDate < $scheduledFor) {
|
if (null === $scheduledFor || $selectedDate < $scheduledFor) {
|
||||||
return false;
|
return false;
|
||||||
@@ -90,6 +103,13 @@ final class TaskRecommendationService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDeferredOn(Task $task, \DateTimeImmutable $date): bool
|
||||||
|
{
|
||||||
|
$deferredUntil = $task->getDeferredUntil();
|
||||||
|
|
||||||
|
return null !== $deferredUntil && $date->setTime(0, 0) < $deferredUntil;
|
||||||
|
}
|
||||||
|
|
||||||
private function isMonthlyOccurrence(\DateTimeImmutable $scheduledFor, \DateTimeImmutable $selectedDate, int $interval): bool
|
private function isMonthlyOccurrence(\DateTimeImmutable $scheduledFor, \DateTimeImmutable $selectedDate, int $interval): bool
|
||||||
{
|
{
|
||||||
$monthsApart = ((int) $selectedDate->format('Y') - (int) $scheduledFor->format('Y')) * 12
|
$monthsApart = ((int) $selectedDate->format('Y') - (int) $scheduledFor->format('Y')) * 12
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\Settings;
|
||||||
|
use App\Entity\Task;
|
||||||
|
use App\Repository\TaskRepository;
|
||||||
|
|
||||||
|
/** Coordinates eligibility rules while keeping controllers free of scheduling policy. */
|
||||||
|
final class TaskSchedulingService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TaskRepository $tasks,
|
||||||
|
private TaskRecommendationService $recommendations,
|
||||||
|
private TaskDeferralService $deferrals,
|
||||||
|
private SickDayService $sickDays,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Task[]
|
||||||
|
*/
|
||||||
|
public function tasksForDate(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header><img src="{{ asset('build/images/logo.png') }}" class="logo" alt="Logo">TaskNest <img src="{{ asset('build/images/TaskNestMascots.png') }}" class="mascots" alt="Mascots"></header>
|
<header>
|
||||||
|
<img src="{{ asset('build/images/logo.png') }}" class="logo" alt="Logo">TaskNest
|
||||||
|
{% if app.user %}
|
||||||
|
<a class="settings-link" href="{{ path('app_settings') }}">Settings</a>
|
||||||
|
{% endif %}
|
||||||
|
<img src="{{ asset('build/images/TaskNestMascots.png') }}" class="mascots" alt="Mascots">
|
||||||
|
</header>
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Settings{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<main class="container container-flex--narrow">
|
||||||
|
<p><a href="{{ path('app_task_index') }}">← Back to tasks</a></p>
|
||||||
|
|
||||||
|
<section class="settings-page" aria-labelledby="settings-title">
|
||||||
|
<h1 id="settings-title">Settings</h1>
|
||||||
|
|
||||||
|
<section class="settings-page__section" aria-labelledby="sick-day-title">
|
||||||
|
<h2 id="sick-day-title">Sick Day Mode</h2>
|
||||||
|
<p>Non-essential tasks are deferred until recovery. Tasks marked “Required on sick days” remain available.</p>
|
||||||
|
|
||||||
|
{{ form_start(form) }}
|
||||||
|
{{ form_row(form.sickModeEnabled) }}
|
||||||
|
{{ form_row(form.sickUntil) }}
|
||||||
|
<button class="btn btn-primary" type="submit">Save settings</button>
|
||||||
|
{{ form_end(form) }}
|
||||||
|
|
||||||
|
{% if settings.isSickOn(today) %}
|
||||||
|
<p class="settings-page__status">Sick Day Mode is active{% if settings.sickUntil %} through {{ settings.sickUntil|date('j F') }}{% endif %}.</p>
|
||||||
|
{% elseif settings.sickModeEnabled and settings.sickUntil %}
|
||||||
|
<p class="settings-page__status">The saved recovery date has passed, so Sick Day Mode is no longer affecting tasks.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="settings-page__section" aria-labelledby="weather-settings-title">
|
||||||
|
<h2 id="weather-settings-title">Weather location</h2>
|
||||||
|
<p>{{ settings.hasLocation ? 'Your saved location is used for weather-aware task suggestions.' : 'Set your weather location from the Tasks page.' }}</p>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
<div>{{ form_row(form.estimatedDurationMinutes) }}</div>
|
<div>{{ form_row(form.estimatedDurationMinutes) }}</div>
|
||||||
<div>{{ form_row(form.priority) }}</div>
|
<div>{{ form_row(form.priority) }}</div>
|
||||||
<div>{{ form_row(form.category) }}</div>
|
<div>{{ form_row(form.category) }}</div>
|
||||||
|
<div>{{ form_row(form.requiredOnSickDay) }}</div>
|
||||||
|
<div>{{ form_row(form.deferDays) }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="task-composer__row">
|
<div class="task-composer__row">
|
||||||
<div>{{ form_row(form.scheduledFor) }}</div>
|
<div>{{ form_row(form.scheduledFor) }}</div>
|
||||||
|
|||||||
@@ -25,6 +25,29 @@
|
|||||||
<span class="task-list__recurrence">Every {{ task.recurrenceInterval }} {{ task.recurrenceUnit }}{{ task.recurrenceInterval != 1 ? 's' : '' }}</span>
|
<span class="task-list__recurrence">Every {{ task.recurrenceInterval }} {{ task.recurrenceUnit }}{{ task.recurrenceInterval != 1 ? 's' : '' }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% if task.isActive %}
|
||||||
|
<form
|
||||||
|
class="task-list__snooze-form"
|
||||||
|
hx-post="{{ path('app_task_snooze', {'id': task.id}) }}"
|
||||||
|
hx-target="closest .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 %}
|
||||||
|
|
||||||
<form
|
<form
|
||||||
class="task-list__remove-form"
|
class="task-list__remove-form"
|
||||||
hx-post="{{ path('app_task_delete', {'id': task.id}) }}"
|
hx-post="{{ path('app_task_delete', {'id': task.id}) }}"
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<a class="user" href="{{ path('app_user_index') }}">
|
||||||
|
{% if user.username != "" %} {{ user.username|first }}{% endif %}
|
||||||
|
</a>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="task-list-header">
|
<div class="task-list-header">
|
||||||
<button class="weather-location" type="button" data-weather-location data-location-url="{{ path('app_task_location') }}" data-location-token="{{ csrf_token('weather_location') }}">
|
<button class="weather-location" type="button" data-weather-location data-location-url="{{ path('app_task_location') }}" data-location-token="{{ csrf_token('weather_location') }}">
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<form method="post" action="{{ path('app_user_delete', {'id': user.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ user.id) }}">
|
||||||
|
<button class="btn">Delete</button>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{{ form_start(form) }}
|
||||||
|
{{ form_widget(form) }}
|
||||||
|
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||||
|
{{ form_end(form) }}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Edit User{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>Edit User</h1>
|
||||||
|
|
||||||
|
{{ include('user/_form.html.twig', {'button_label': 'Update'}) }}
|
||||||
|
|
||||||
|
<a href="{{ path('app_user_index') }}">back to list</a>
|
||||||
|
|
||||||
|
{{ include('user/_delete_form.html.twig') }}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}User index{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>User index</h1>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Roles</th>
|
||||||
|
<th>Password</th>
|
||||||
|
<th>Username</th>
|
||||||
|
<th>actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for user in users %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ user.id }}</td>
|
||||||
|
<td>{{ user.email }}</td>
|
||||||
|
<td>{{ user.roles ? user.roles|json_encode : '' }}</td>
|
||||||
|
<td>{{ user.password }}</td>
|
||||||
|
<td>{{ user.username }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ path('app_user_show', {'id': user.id}) }}">show</a>
|
||||||
|
<a href="{{ path('app_user_edit', {'id': user.id}) }}">edit</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="6">no records found</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<a href="{{ path('app_user_new') }}">Create new</a>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}New User{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>Create new User</h1>
|
||||||
|
|
||||||
|
{{ include('user/_form.html.twig') }}
|
||||||
|
|
||||||
|
<a href="{{ path('app_user_index') }}">back to list</a>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}User{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>User</h1>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<td>{{ user.id }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Email</th>
|
||||||
|
<td>{{ user.email }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Roles</th>
|
||||||
|
<td>{{ user.roles ? user.roles|json_encode : '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Password</th>
|
||||||
|
<td>{{ user.password }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Username</th>
|
||||||
|
<td>{{ user.username }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<a href="{{ path('app_user_index') }}">back to list</a>
|
||||||
|
|
||||||
|
<a href="{{ path('app_user_edit', {'id': user.id}) }}">edit</a>
|
||||||
|
|
||||||
|
{{ include('user/_delete_form.html.twig') }}
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user