This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Models\Folder;
|
use App\Models\Folder;
|
||||||
use App\Models\Todo;
|
use App\Models\Todo;
|
||||||
|
use App\TodoStatus;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@@ -30,6 +31,8 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
|
|
||||||
public string $description = '';
|
public string $description = '';
|
||||||
|
|
||||||
|
public string $todoStatus = 'open';
|
||||||
|
|
||||||
public ?string $dueDate = null;
|
public ?string $dueDate = null;
|
||||||
|
|
||||||
public string $notes = '';
|
public string $notes = '';
|
||||||
@@ -73,7 +76,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
|
|
||||||
public function openCreateForm(?int $folderId = null): void
|
public function openCreateForm(?int $folderId = null): void
|
||||||
{
|
{
|
||||||
$this->reset('editingTodoId', 'description', 'dueDate', 'notes', 'formFolderId');
|
$this->reset('editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||||
$this->resetErrorBag();
|
$this->resetErrorBag();
|
||||||
|
|
||||||
if ($folderId !== null && $this->folderTree->contains(fn ($node) => $node['folder']->id === $folderId)) {
|
if ($folderId !== null && $this->folderTree->contains(fn ($node) => $node['folder']->id === $folderId)) {
|
||||||
@@ -91,6 +94,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
|
|
||||||
$this->editingTodoId = $todo->id;
|
$this->editingTodoId = $todo->id;
|
||||||
$this->description = $todo->description;
|
$this->description = $todo->description;
|
||||||
|
$this->todoStatus = $todo->status->value;
|
||||||
$this->dueDate = $todo->due_date?->format('Y-m-d') ?? '';
|
$this->dueDate = $todo->due_date?->format('Y-m-d') ?? '';
|
||||||
$this->notes = $todo->notes ?? '';
|
$this->notes = $todo->notes ?? '';
|
||||||
$this->formFolderId = $todo->folder_id;
|
$this->formFolderId = $todo->folder_id;
|
||||||
@@ -103,6 +107,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
{
|
{
|
||||||
$validated = $this->validate([
|
$validated = $this->validate([
|
||||||
'description' => ['required', 'string', 'max:255'],
|
'description' => ['required', 'string', 'max:255'],
|
||||||
|
'todoStatus' => ['required', Rule::enum(TodoStatus::class)],
|
||||||
'dueDate' => ['nullable', 'date'],
|
'dueDate' => ['nullable', 'date'],
|
||||||
'notes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
'notes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
||||||
'formFolderId' => ['required', 'integer', Rule::exists('folders', 'id')->where('user_id', auth()->id())],
|
'formFolderId' => ['required', 'integer', Rule::exists('folders', 'id')->where('user_id', auth()->id())],
|
||||||
@@ -111,6 +116,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
$data = [
|
$data = [
|
||||||
'folder_id' => $validated['formFolderId'],
|
'folder_id' => $validated['formFolderId'],
|
||||||
'description' => $validated['description'],
|
'description' => $validated['description'],
|
||||||
|
'status' => TodoStatus::from($validated['todoStatus']),
|
||||||
'due_date' => filled($validated['dueDate']) ? Carbon::parse($validated['dueDate']) : null,
|
'due_date' => filled($validated['dueDate']) ? Carbon::parse($validated['dueDate']) : null,
|
||||||
'notes' => filled($validated['notes']) ? $validated['notes'] : null,
|
'notes' => filled($validated['notes']) ? $validated['notes'] : null,
|
||||||
];
|
];
|
||||||
@@ -121,7 +127,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
Todo::create($data + ['user_id' => auth()->id()]);
|
Todo::create($data + ['user_id' => auth()->id()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->reset('showTodoForm', 'editingTodoId', 'description', 'dueDate', 'notes', 'formFolderId');
|
$this->reset('showTodoForm', 'editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleComplete(int $todoId): void
|
public function toggleComplete(int $todoId): void
|
||||||
@@ -161,7 +167,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
$query = Todo::query()->forUser(auth()->id());
|
$query = Todo::query()->forUser(auth()->id());
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'open' => (clone $query)->incomplete()->count(),
|
'open' => (clone $query)->active()->count(),
|
||||||
'completed' => (clone $query)->completed()->count(),
|
'completed' => (clone $query)->completed()->count(),
|
||||||
'overdue' => (clone $query)->overdue()->count(),
|
'overdue' => (clone $query)->overdue()->count(),
|
||||||
'dueToday' => (clone $query)->dueToday()->count(),
|
'dueToday' => (clone $query)->dueToday()->count(),
|
||||||
@@ -191,7 +197,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
|
|
||||||
$openByFolder = Todo::query()
|
$openByFolder = Todo::query()
|
||||||
->forUser(auth()->id())
|
->forUser(auth()->id())
|
||||||
->incomplete()
|
->active()
|
||||||
->pluck('folder_id')
|
->pluck('folder_id')
|
||||||
->countBy();
|
->countBy();
|
||||||
$overdueByFolder = Todo::query()
|
$overdueByFolder = Todo::query()
|
||||||
@@ -216,6 +222,19 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
return $this->search !== '' || $this->folderId !== null || $this->status !== 'all';
|
return $this->search !== '' || $this->folderId !== null || $this->status !== 'all';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function statusFilters(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'all' => 'All',
|
||||||
|
...collect(TodoStatus::cases())
|
||||||
|
->mapWithKeys(fn (TodoStatus $status) => [$status->value => $status->label()])
|
||||||
|
->all(),
|
||||||
|
'completed' => 'Completed',
|
||||||
|
'overdue' => 'Overdue',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function todos(): LengthAwarePaginator
|
public function todos(): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
@@ -232,10 +251,11 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
)
|
)
|
||||||
->when($this->status, function (Builder $query) {
|
->when($this->status, function (Builder $query) {
|
||||||
return match ($this->status) {
|
return match ($this->status) {
|
||||||
'open' => $query->incomplete(),
|
'open' => $query->active(),
|
||||||
'completed' => $query->completed(),
|
'completed' => $query->completed(),
|
||||||
'overdue' => $query->overdue(),
|
'overdue' => $query->overdue(),
|
||||||
default => $query,
|
'all', '' => $query,
|
||||||
|
default => $query->where('status', $this->status)->incomplete(),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
->orderByRaw('completed_at IS NOT NULL')
|
->orderByRaw('completed_at IS NOT NULL')
|
||||||
@@ -342,7 +362,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
@foreach (['all' => 'All', 'open' => 'Open', 'completed' => 'Completed', 'overdue' => 'Overdue'] as $value => $label)
|
@foreach ($this->statusFilters as $value => $label)
|
||||||
<flux:button
|
<flux:button
|
||||||
size="sm"
|
size="sm"
|
||||||
:variant="$status === $value ? 'primary' : 'ghost'"
|
:variant="$status === $value ? 'primary' : 'ghost'"
|
||||||
@@ -384,6 +404,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
<flux:table.columns>
|
<flux:table.columns>
|
||||||
<flux:table.column width="3rem">{{ __('Done') }}</flux:table.column>
|
<flux:table.column width="3rem">{{ __('Done') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Description') }}</flux:table.column>
|
<flux:table.column>{{ __('Description') }}</flux:table.column>
|
||||||
|
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Folder') }}</flux:table.column>
|
<flux:table.column>{{ __('Folder') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Due') }}</flux:table.column>
|
<flux:table.column>{{ __('Due') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Created') }}</flux:table.column>
|
<flux:table.column>{{ __('Created') }}</flux:table.column>
|
||||||
@@ -403,12 +424,18 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
|
|
||||||
<flux:table.cell :variant="$todo->completed_at ? 'strong' : 'default'" data-test="todo-description-{{ $todo->id }}">
|
<flux:table.cell :variant="$todo->completed_at ? 'strong' : 'default'" data-test="todo-description-{{ $todo->id }}">
|
||||||
<span :class="$todo->completed_at ? 'line-through text-zinc-400' : ''">{{ $todo->description }}</span>
|
<span @class(['line-through text-zinc-400' => $todo->completed_at !== null])>{{ $todo->description }}</span>
|
||||||
@if ($todo->notes)
|
@if ($todo->notes)
|
||||||
<flux:text size="sm" class="mt-1 block max-w-md truncate text-zinc-500">{{ $todo->notes }}</flux:text>
|
<flux:text size="sm" class="mt-1 block max-w-md truncate text-zinc-500">{{ $todo->notes }}</flux:text>
|
||||||
@endif
|
@endif
|
||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
|
|
||||||
|
<flux:table.cell>
|
||||||
|
<flux:badge size="sm" :color="$todo->status->badgeColor()" data-test="todo-status-{{ $todo->id }}">
|
||||||
|
{{ $todo->status->label() }}
|
||||||
|
</flux:badge>
|
||||||
|
</flux:table.cell>
|
||||||
|
|
||||||
<flux:table.cell class="text-zinc-500">
|
<flux:table.cell class="text-zinc-500">
|
||||||
{{ $todo->folder?->parent?->name }}@if ($todo->folder?->parent) / @endif{{ $todo->folder?->name }}
|
{{ $todo->folder?->parent?->name }}@if ($todo->folder?->parent) / @endif{{ $todo->folder?->name }}
|
||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
@@ -452,7 +479,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
</flux:table.row>
|
</flux:table.row>
|
||||||
@empty
|
@empty
|
||||||
<flux:table.row>
|
<flux:table.row>
|
||||||
<flux:table.cell colspan="6" align="center" class="py-10">
|
<flux:table.cell colspan="7" align="center" class="py-10">
|
||||||
<flux:text>{{ __('No todos match your filters.') }}</flux:text>
|
<flux:text>{{ __('No todos match your filters.') }}</flux:text>
|
||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
</flux:table.row>
|
</flux:table.row>
|
||||||
@@ -480,6 +507,16 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
<flux:error name="description" />
|
<flux:error name="description" />
|
||||||
</flux:field>
|
</flux:field>
|
||||||
|
|
||||||
|
<flux:field>
|
||||||
|
<flux:label>{{ __('Status') }}</flux:label>
|
||||||
|
<flux:select wire:model="todoStatus" data-test="status-select">
|
||||||
|
@foreach (TodoStatus::cases() as $status)
|
||||||
|
<flux:select.option :value="$status->value">{{ $status->label() }}</flux:select.option>
|
||||||
|
@endforeach
|
||||||
|
</flux:select>
|
||||||
|
<flux:error name="todoStatus" />
|
||||||
|
</flux:field>
|
||||||
|
|
||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>{{ __('Due date') }}</flux:label>
|
<flux:label>{{ __('Due date') }}</flux:label>
|
||||||
<flux:input wire:model="dueDate" type="date" data-test="due-date-input" />
|
<flux:input wire:model="dueDate" type="date" data-test="due-date-input" />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Models\Folder;
|
use App\Models\Folder;
|
||||||
use App\Models\Todo;
|
use App\Models\Todo;
|
||||||
|
use App\TodoStatus;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
@@ -34,6 +35,8 @@ new #[Title('Folders')] class extends Component
|
|||||||
|
|
||||||
public string $todoDescription = '';
|
public string $todoDescription = '';
|
||||||
|
|
||||||
|
public string $todoStatus = 'open';
|
||||||
|
|
||||||
public ?string $todoDueDate = null;
|
public ?string $todoDueDate = null;
|
||||||
|
|
||||||
public string $todoNotes = '';
|
public string $todoNotes = '';
|
||||||
@@ -132,8 +135,8 @@ new #[Title('Folders')] class extends Component
|
|||||||
$this->folderForUser($folderId);
|
$this->folderForUser($folderId);
|
||||||
|
|
||||||
$this->todoFolderId = $folderId;
|
$this->todoFolderId = $folderId;
|
||||||
$this->reset('todoDescription', 'todoDueDate', 'todoNotes');
|
$this->reset('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||||
$this->resetErrorBag('todoDescription', 'todoDueDate', 'todoNotes');
|
$this->resetErrorBag('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||||
$this->showTodoForm = true;
|
$this->showTodoForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +146,7 @@ new #[Title('Folders')] class extends Component
|
|||||||
|
|
||||||
$validated = $this->validate([
|
$validated = $this->validate([
|
||||||
'todoDescription' => ['required', 'string', 'max:255'],
|
'todoDescription' => ['required', 'string', 'max:255'],
|
||||||
|
'todoStatus' => ['required', Rule::enum(TodoStatus::class)],
|
||||||
'todoDueDate' => ['nullable', 'date'],
|
'todoDueDate' => ['nullable', 'date'],
|
||||||
'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
||||||
]);
|
]);
|
||||||
@@ -151,11 +155,12 @@ new #[Title('Folders')] class extends Component
|
|||||||
'user_id' => auth()->id(),
|
'user_id' => auth()->id(),
|
||||||
'folder_id' => $folder->id,
|
'folder_id' => $folder->id,
|
||||||
'description' => $validated['todoDescription'],
|
'description' => $validated['todoDescription'],
|
||||||
|
'status' => TodoStatus::from($validated['todoStatus']),
|
||||||
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
|
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
|
||||||
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
|
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoDueDate', 'todoNotes');
|
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
@@ -164,12 +169,34 @@ new #[Title('Folders')] class extends Component
|
|||||||
return Folder::treeForUser(auth()->id());
|
return Folder::treeForUser(auth()->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function todoFolder(): ?Folder
|
||||||
|
{
|
||||||
|
if ($this->todoFolderId === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Folder::query()->with('parent')->forUser(auth()->id())->find($this->todoFolderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function todoFolderPath(): string
|
||||||
|
{
|
||||||
|
if ($this->todoFolder === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect([$this->todoFolder->parent?->name, $this->todoFolder->name])
|
||||||
|
->filter()
|
||||||
|
->implode(' / ');
|
||||||
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function openCounts(): Collection
|
public function openCounts(): Collection
|
||||||
{
|
{
|
||||||
return Todo::query()
|
return Todo::query()
|
||||||
->forUser(auth()->id())
|
->forUser(auth()->id())
|
||||||
->incomplete()
|
->active()
|
||||||
->pluck('folder_id')
|
->pluck('folder_id')
|
||||||
->countBy();
|
->countBy();
|
||||||
}
|
}
|
||||||
@@ -347,8 +374,26 @@ new #[Title('Folders')] class extends Component
|
|||||||
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
|
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
|
||||||
<form wire:submit="saveFolderTodo" class="space-y-6">
|
<form wire:submit="saveFolderTodo" class="space-y-6">
|
||||||
<div>
|
<div>
|
||||||
<flux:heading size="lg">{{ __('Add todo') }}</flux:heading>
|
@if ($this->todoFolder !== null)
|
||||||
|
<flux:heading size="lg" class="truncate">
|
||||||
|
{{ __('Add todo') }} - <span class="text-zinc-500 dark:text-zinc-400" data-test="add-todo-title-folder">{{ $this->todoFolderPath }}</span>
|
||||||
|
</flux:heading>
|
||||||
|
@else
|
||||||
|
<flux:heading size="lg">{{ __('Add todo') }}</flux:heading>
|
||||||
|
@endif
|
||||||
<flux:text class="mt-2">{{ __('Add a task with a description. A due date is optional.') }}</flux:text>
|
<flux:text class="mt-2">{{ __('Add a task with a description. A due date is optional.') }}</flux:text>
|
||||||
|
|
||||||
|
@if ($this->todoFolder !== null)
|
||||||
|
<div class="mt-3 flex items-center gap-1.5" data-test="add-todo-folder-name">
|
||||||
|
<flux:icon.folder variant="micro" class="text-zinc-500 dark:text-zinc-400" />
|
||||||
|
<flux:text size="sm" class="text-zinc-600 dark:text-zinc-300">
|
||||||
|
{{ __('Adding to') }}
|
||||||
|
<strong class="text-zinc-900 dark:text-zinc-100">
|
||||||
|
{{ $this->todoFolderPath }}
|
||||||
|
</strong>
|
||||||
|
</flux:text>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<flux:field>
|
<flux:field>
|
||||||
@@ -363,6 +408,16 @@ new #[Title('Folders')] class extends Component
|
|||||||
<flux:error name="todoDescription" />
|
<flux:error name="todoDescription" />
|
||||||
</flux:field>
|
</flux:field>
|
||||||
|
|
||||||
|
<flux:field>
|
||||||
|
<flux:label>{{ __('Status') }}</flux:label>
|
||||||
|
<flux:select wire:model="todoStatus" data-test="todo-status-select">
|
||||||
|
@foreach (TodoStatus::cases() as $status)
|
||||||
|
<flux:select.option :value="$status->value">{{ $status->label() }}</flux:select.option>
|
||||||
|
@endforeach
|
||||||
|
</flux:select>
|
||||||
|
<flux:error name="todoStatus" />
|
||||||
|
</flux:field>
|
||||||
|
|
||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>{{ __('Due date') }}</flux:label>
|
<flux:label>{{ __('Due date') }}</flux:label>
|
||||||
<flux:input wire:model="todoDueDate" type="date" data-test="todo-due-date-input" />
|
<flux:input wire:model="todoDueDate" type="date" data-test="todo-due-date-input" />
|
||||||
|
|||||||
Reference in New Issue
Block a user