diff --git a/app/Filament/Resources/Todos/Pages/CreateTodo.php b/app/Filament/Resources/Todos/Pages/CreateTodo.php new file mode 100644 index 0000000..8fd2945 --- /dev/null +++ b/app/Filament/Resources/Todos/Pages/CreateTodo.php @@ -0,0 +1,11 @@ +components([ + TextInput::make('name') + ->label('Titel') + ->required(), + Select::make('user.name')->relationship('user', 'name')->label('Benutzer')->hiddenOn(['create'])->disabledOn(['edit']), + Hidden::make('user_id')->default(filament()->auth()->user()->id), + RichEditor::make('content') + ->label('Todo') + ->columnSpanFull(), + MorphToSelect::make('todoable') + ->types([ + MorphToSelect\Type::make(User::class)->label('Benutzer')->titleAttribute('name'), + MorphToSelect\Type::make(Group::class)->label('Gruppe')->titleAttribute('name'), + ]) + ->label('zugeordnet'), + Section::make()->components([ + DatePicker::make('due_date')->label('Todo-Datum'), + Toggle::make('review')->label('Review')->hint('Todo geht nach Erledigung noch mal zum Ersteller'), + + ]), + DatePicker::make('follow_up')->label('Wiedervorlage/Erinnerung'), + DatePicker::make('done_date')->label('Erledigt am')->hiddenOn(['create']), + ]); + } +} diff --git a/app/Filament/Resources/Todos/Tables/TodosTable.php b/app/Filament/Resources/Todos/Tables/TodosTable.php new file mode 100644 index 0000000..f66a4b2 --- /dev/null +++ b/app/Filament/Resources/Todos/Tables/TodosTable.php @@ -0,0 +1,57 @@ +columns([ + TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + TextColumn::make('name') + ->searchable(), + TextColumn::make('user.name') + ->searchable(), + TextColumn::make('todoable.name') + ->label('Zugewiesen') + ->searchable(), + TextColumn::make('due_date') + ->date() + ->sortable(), + TextColumn::make('done_date') + ->date() + ->sortable(), + TextColumn::make('follow_up') + ->date() + ->sortable(), + IconColumn::make('review') + ->boolean(), + ]) + ->filters([ + // + ]) + ->recordActions([ + EditAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Filament/Resources/Todos/TodoResource.php b/app/Filament/Resources/Todos/TodoResource.php new file mode 100644 index 0000000..cb30476 --- /dev/null +++ b/app/Filament/Resources/Todos/TodoResource.php @@ -0,0 +1,50 @@ + ListTodos::route('/'), + 'create' => CreateTodo::route('/create'), + 'edit' => EditTodo::route('/{record}/edit'), + ]; + } +} diff --git a/app/Models/Todo.php b/app/Models/Todo.php new file mode 100644 index 0000000..3c27649 --- /dev/null +++ b/app/Models/Todo.php @@ -0,0 +1,23 @@ +morphTo(); + } + + public function user(): BelongsTo { + return $this->belongsTo(User::class); + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index 9d6628a..19e088d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Hidden; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -49,6 +50,11 @@ class User extends Authenticatable implements FilamentUser return $this->belongsToMany(Group::class); } + public function todos(): HasMany + { + return $this->hasMany(Todo::class); + } + public function hasRole(string $role): bool { return in_array($role, $this->roles()->pluck('name')->toArray()); diff --git a/database/migrations/2026_06_02_171154_create_todos_table.php b/database/migrations/2026_06_02_171154_create_todos_table.php new file mode 100644 index 0000000..d2d6b2f --- /dev/null +++ b/database/migrations/2026_06_02_171154_create_todos_table.php @@ -0,0 +1,37 @@ +id(); + $table->timestamps(); + $table->string('name'); + $table->text('content')->nullable(); + $table->foreignIdFor(User::class); + $table->string('todoable_type')->nullable(); + $table->integer('todoable_id')->nullable(); + $table->date('due_date')->nullable(); + $table->date('done_date')->nullable(); + $table->date('follow_up')->nullable(); + $table->boolean('review')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('todos'); + } +};