Doppelbuchungen nur einmal melden und im Postfach der Verwaltung zeigen
Der Kalenderabgleich alle 5 Minuten hat jede fortbestehende Ueberschneidung erneut gemailt. ReportChannelConflicts legt jede Ueberschneidung einmal im neuen Postfach (InboxMessage, Fingerabdruck je Mandant) ab und mailt nur neue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
876a0a20f3
commit
b9225f5fb8
17 files changed
+593
-15
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InboxMessages;
|
||||
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Resources\InboxMessages\Pages\ListInboxMessages;
|
||||
use App\Filament\Resources\InboxMessages\Tables\InboxMessagesTable;
|
||||
use App\Models\InboxMessage;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* The admin inbox ("Postfach"): findings the landlord has to look at, each posted once (App\Support\Inbox).
|
||||
*/
|
||||
class InboxMessageResource extends Resource
|
||||
{
|
||||
use FollowsAdminMode;
|
||||
|
||||
protected static ?string $model = InboxMessage::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedInbox;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||||
|
||||
protected static ?string $navigationLabel = 'Postfach';
|
||||
|
||||
protected static ?string $modelLabel = 'Meldung';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Postfach';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return InboxMessagesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$unread = InboxMessage::query()->unread()->count();
|
||||
|
||||
return $unread > 0 ? (string) $unread : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): string
|
||||
{
|
||||
return 'danger';
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeTooltip(): ?string
|
||||
{
|
||||
return 'Ungelesen';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListInboxMessages::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InboxMessages\Pages;
|
||||
|
||||
use App\Filament\Concerns\ListsCurrentProperty;
|
||||
use App\Filament\Resources\InboxMessages\InboxMessageResource;
|
||||
use App\Models\Property;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListInboxMessages extends ListRecords
|
||||
{
|
||||
use ListsCurrentProperty;
|
||||
|
||||
protected static string $resource = InboxMessageResource::class;
|
||||
|
||||
/**
|
||||
* Messages of the chosen apartment and those that concern no apartment in particular.
|
||||
*/
|
||||
protected function scopeToProperty(Builder $query, Property $property): Builder
|
||||
{
|
||||
return $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id'));
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('readAll')
|
||||
->label('Alle als gelesen markieren')
|
||||
->icon(Heroicon::OutlinedCheck)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->getTableQuery()->unread()->exists())
|
||||
->action(fn () => $this->getTableQuery()->unread()->update(['read_at' => now()])),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\InboxMessages\Tables;
|
||||
|
||||
use App\Enums\InboxMessageKind;
|
||||
use App\Models\InboxMessage;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class InboxMessagesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->description('Hinweise, um die Sie sich kümmern sollten. Jede Meldung kommt nur einmal – auch wenn sie bei jedem Kalenderabgleich wieder auffällt.')
|
||||
->emptyStateHeading('Keine Meldungen')
|
||||
->columns([
|
||||
IconColumn::make('read_at')
|
||||
->label('')
|
||||
->state(fn (InboxMessage $record): bool => ! $record->isRead())
|
||||
->boolean()
|
||||
->trueIcon(Heroicon::Envelope)
|
||||
->falseIcon(Heroicon::OutlinedEnvelopeOpen)
|
||||
->trueColor('danger')
|
||||
->falseColor('gray')
|
||||
->tooltip(fn (InboxMessage $record): string => $record->isRead() ? 'Gelesen' : 'Ungelesen'),
|
||||
TextColumn::make('created_at')->label('Eingang')->dateTime('d.m. H:i')->sortable(),
|
||||
TextColumn::make('kind')->label('Art')->badge(),
|
||||
TextColumn::make('subject')
|
||||
->label('Meldung')
|
||||
->weight(fn (InboxMessage $record): ?FontWeight => $record->isRead() ? null : FontWeight::Bold)
|
||||
->description(fn (InboxMessage $record): string => $record->body)
|
||||
->wrap(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('read_at')
|
||||
->label('Gelesen')
|
||||
->nullable()
|
||||
->trueLabel('Nur gelesene')
|
||||
->falseLabel('Nur ungelesene'),
|
||||
SelectFilter::make('kind')->label('Art')->options(InboxMessageKind::class),
|
||||
])
|
||||
->recordUrl(null)
|
||||
->recordActions([
|
||||
Action::make('open')
|
||||
->label('Ansehen')
|
||||
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
|
||||
->visible(fn (InboxMessage $record): bool => filled($record->action_url))
|
||||
->action(function (InboxMessage $record) {
|
||||
$record->update(['read_at' => $record->read_at ?? now()]);
|
||||
|
||||
return redirect($record->action_url);
|
||||
}),
|
||||
Action::make('toggleRead')
|
||||
->label(fn (InboxMessage $record): string => $record->isRead() ? 'Als ungelesen markieren' : 'Als gelesen markieren')
|
||||
->icon(fn (InboxMessage $record): Heroicon => $record->isRead() ? Heroicon::OutlinedEnvelope : Heroicon::OutlinedCheck)
|
||||
->color('gray')
|
||||
->action(fn (InboxMessage $record) => $record->update(['read_at' => $record->isRead() ? null : now()])),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
BulkAction::make('markRead')
|
||||
->label('Als gelesen markieren')
|
||||
->icon(Heroicon::OutlinedCheck)
|
||||
->action(fn (Collection $records) => InboxMessage::query()->whereKey($records->modelKeys())->update(['read_at' => now()]))
|
||||
->deselectRecordsAfterCompletion(),
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user