diff --git a/app/Filament/Actions/DoneTodoAction.php b/app/Filament/Actions/DoneTodoAction.php new file mode 100644 index 0000000..c6b37cc --- /dev/null +++ b/app/Filament/Actions/DoneTodoAction.php @@ -0,0 +1,28 @@ +iconButton() + ->label('erledigt') + ->tooltip('Todo als erledigt markieren') + ->icon(Heroicon::Check) + ->visible(function (Model $record) { + return $record->is_owner_or_assigned() && $record->done_date == null; + }) + ->action(function (Model $record) { + $record->done_date = now()->today(); + $record->save(); + }); + } + +} \ No newline at end of file diff --git a/app/Filament/Actions/ReopenTodoAction.php b/app/Filament/Actions/ReopenTodoAction.php new file mode 100644 index 0000000..dc70ee0 --- /dev/null +++ b/app/Filament/Actions/ReopenTodoAction.php @@ -0,0 +1,38 @@ +iconButton() + ->label('Wiedereröffnen') + ->tooltip('Todo wieder eröffnen') + ->icon(Heroicon::ArrowUturnDown) + ->visible(function (Model $record) { + return $record->is_owner_or_assigned() && $record->done_date != null; + }) + ->schema([ + TextInput::make('notiz')->label('Notiz'), + ]) + ->action(function (Model $record, array $data) { + $record->done_date = null; + $record->save(); + $users = $record->getassignetusers(); + foreach ($users as $user) { + Mail::to($user)->send(new TodoMail($record, 'Todo wiedereröffnet', 'Eine bereits erledigte Todo wurde wiedereröffnet:', notiz: $data['notiz'])); + } + }); + } + +} \ No newline at end of file diff --git a/app/Filament/Resources/Todos/Pages/EditTodo.php b/app/Filament/Resources/Todos/Pages/EditTodo.php index 9854e4a..a4f82df 100644 --- a/app/Filament/Resources/Todos/Pages/EditTodo.php +++ b/app/Filament/Resources/Todos/Pages/EditTodo.php @@ -2,9 +2,12 @@ namespace App\Filament\Resources\Todos\Pages; +use App\Filament\Actions\DoneTodoAction; +use App\Filament\Actions\ReopenTodoAction; use App\Filament\Resources\Todos\TodoResource; use Filament\Actions\DeleteAction; use Filament\Resources\Pages\EditRecord; +use Filament\Support\Icons\Heroicon; class EditTodo extends EditRecord { @@ -13,7 +16,9 @@ class EditTodo extends EditRecord protected function getHeaderActions(): array { return [ - DeleteAction::make(), + DoneTodoAction::make('done'), + ReopenTodoAction::make('reopen'), + DeleteAction::make()->iconButton()->icon(Heroicon::Trash), ]; } } diff --git a/app/Filament/Resources/Todos/Tables/TodosTable.php b/app/Filament/Resources/Todos/Tables/TodosTable.php index 82e89c8..2a4af7d 100644 --- a/app/Filament/Resources/Todos/Tables/TodosTable.php +++ b/app/Filament/Resources/Todos/Tables/TodosTable.php @@ -2,10 +2,13 @@ namespace App\Filament\Resources\Todos\Tables; +use App\Filament\Actions\DoneTodoAction; +use App\Filament\Actions\ReopenTodoAction; use App\Models\Group; use App\Models\User; use Filament\Actions\Action; use Filament\Actions\BulkActionGroup; +use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; use Filament\Support\Icons\Heroicon; @@ -80,14 +83,13 @@ class TodosTable ]) ->recordActions([ - Action::make('done') - ->iconButton() - ->icon(Heroicon::Check) - ->action(function (Model $record) { - $record->done_date = now()->today(); - $record->save(); - }), + DoneTodoAction::make('done'), + ReopenTodoAction::make('reopen'), EditAction::make()->iconButton(), + DeleteAction::make()->iconButton() + ->visible(function (Model $record) { + return $record->is_owner_or_assigned(); + }), ]) ->toolbarActions([ BulkActionGroup::make([ diff --git a/app/Filament/Resources/Todos/TodoResource.php b/app/Filament/Resources/Todos/TodoResource.php index cb30476..d0d31aa 100644 --- a/app/Filament/Resources/Todos/TodoResource.php +++ b/app/Filament/Resources/Todos/TodoResource.php @@ -18,7 +18,7 @@ class TodoResource extends Resource { protected static ?string $model = Todo::class; - protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; + protected static string|BackedEnum|null $navigationIcon = Heroicon::CheckBadge; protected static ?string $recordTitleAttribute = 'name'; diff --git a/app/FollowUpEnum.php b/app/FollowUpEnum.php new file mode 100644 index 0000000..2e1d89a --- /dev/null +++ b/app/FollowUpEnum.php @@ -0,0 +1,28 @@ + 'Morgen', + self::MONDAY => 'Montag', + self::TUESDAY => 'Dienstag', + self::WEDNESDAY => 'Mittwoch', + self::THURSTDAY => 'Donnerstag', + self::FRIDAY => 'Freitag', + self::TWO_WEEKS => 'In 2 Wochen', + }; + } + +} diff --git a/app/Mail/TodoMail.php b/app/Mail/TodoMail.php new file mode 100644 index 0000000..8a878bc --- /dev/null +++ b/app/Mail/TodoMail.php @@ -0,0 +1,68 @@ +mail_subject, + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + markdown: 'mail.todo-mail', + with: [ + 'message' => $this->message, + 'subject' => $this->mail_subject, + 'notiz' => $this->notiz, + 'todo_url' => TodoResource::getUrl('edit', ['record' => $this->todo]), + 'todo' => $this->todo, + ], + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/app/Models/Todo.php b/app/Models/Todo.php index 30d2317..5aad3ef 100644 --- a/app/Models/Todo.php +++ b/app/Models/Todo.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Observers\TodoObserver; use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\ObservedBy; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; @@ -21,4 +22,16 @@ class Todo extends Model { return $this->belongsTo(User::class); } + + public function is_owner_or_assigned() { + if(filament()->auth()->user()->id == $this->user_id) return true; + if($this->todoable_type == Group::class && in_array(filament()->auth()->user()->id, $this->todoable()->first()->get()->users()->get()->pluck('id')->toArray())) return true; + if($this->todoable_type == User::class && $this->todoable()->first()->get()->id == filament()->auth()->user()->id) return true; + else return false; + } + + public function getassignetusers() { + if($this->todoable_type == Group::class) return $this->todoable()->first()->users()->get(); + if($this->todoable_type == User::class) return [$this->todoable()->first()->get()]; + } } diff --git a/app/Observers/TodoObserver.php b/app/Observers/TodoObserver.php index db90a70..e0fb949 100644 --- a/app/Observers/TodoObserver.php +++ b/app/Observers/TodoObserver.php @@ -2,7 +2,16 @@ namespace App\Observers; +use App\Mail\TodoAssigned; +use App\Mail\TodoCreated; +use App\Mail\TodoMail; +use App\Mail\TodoNeedsReview; +use App\Mail\TodoReopened; +use App\Models\Group; use App\Models\Todo; +use App\Models\User; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Str; class TodoObserver { @@ -11,7 +20,17 @@ class TodoObserver */ public function created(Todo $todo): void { - // + if($todo->todoable_type == null) return; + // if($todo->todoable_type == User::class && $todo->user_id == $todo->todoable_id) return; + if($todo->todoable_type == User::class) { + Mail::to(User::find($todo->todoable()->first()))->send(new TodoMail($todo, 'Neue Todo', 'Es gibt eine neue Todo für dich:')); + } + else { + $users = $todo->todoable()->first()->users()->get(); + foreach ($users as $user) { + Mail::to($user)->send(new TodoMail($todo, 'Neue Todo', 'Es gibt eine neue Todo für dich:')); + } + } } /** @@ -19,7 +38,18 @@ class TodoObserver */ public function updated(Todo $todo): void { - // + $hasChanged = $todo->getChanges(); + if ($hasChanged && isset($hasChanged['done_date']) && $todo->done_date != null) { + $user = User::find($todo->user_id); + Mail::to($user)->send(new TodoMail($todo, 'Todo erledigt', 'Todo erledigt, du wolltest, dass du Bescheid bekommst:')); + } + if ($hasChanged && (isset($hasChanged['todoable_type']) || isset($hasChanged['todoable_id']))) { + $users = $todo->getassignetusers(); + foreach ($users as $user) { + Mail::to($user)->send(new TodoMail($todo, 'Todo zugewiesen', 'Dir wurde eine bestehende Todo zugewiesen:')); + } + + } } /** diff --git a/resources/views/mail/todo-mail.blade.php b/resources/views/mail/todo-mail.blade.php new file mode 100644 index 0000000..230d164 --- /dev/null +++ b/resources/views/mail/todo-mail.blade.php @@ -0,0 +1,24 @@ + +# {{ $subject }} + +Hi, + +{{ $message }} + +{{ $notiz }} + +## {{ $todo->name }}: + +Erstellt von: {{ $todo->user->name }} +Zugewiesen: {{ $todo->todoable->name }} + +Inhalt: +{!! $todo->content !!} + + +Todo im Cockpit ansehen + + +Danke,
+{{ config('app.name') }} +