Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
40
vendor/filament/notifications/src/BroadcastNotification.php
vendored
Normal file
40
vendor/filament/notifications/src/BroadcastNotification.php
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Notifications\Notification as BaseNotification;
|
||||
|
||||
class BroadcastNotification extends BaseNotification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(
|
||||
public array $data,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param Model $notifiable
|
||||
* @return array<string>
|
||||
*/
|
||||
public function via($notifiable): array
|
||||
{
|
||||
return ['broadcast'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $notifiable
|
||||
*/
|
||||
public function toBroadcast($notifiable): BroadcastMessage
|
||||
{
|
||||
return (new BroadcastMessage($this->data))
|
||||
->onConnection($this->connection)
|
||||
->onQueue($this->queue);
|
||||
}
|
||||
}
|
||||
35
vendor/filament/notifications/src/Collection.php
vendored
Normal file
35
vendor/filament/notifications/src/Collection.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications;
|
||||
|
||||
use Illuminate\Support\Collection as BaseCollection;
|
||||
use Livewire\Wireable;
|
||||
|
||||
class Collection extends BaseCollection implements Wireable
|
||||
{
|
||||
/**
|
||||
* @param array<array<string, mixed>> $items
|
||||
*/
|
||||
final public function __construct($items = [])
|
||||
{
|
||||
parent::__construct($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array<string, mixed>>
|
||||
*/
|
||||
public function toLivewire(): array
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array<string, mixed>> $value
|
||||
*/
|
||||
public static function fromLivewire($value): static
|
||||
{
|
||||
return app(static::class, ['items' => $value])->transform(
|
||||
fn (array $notification): Notification => Notification::fromArray($notification),
|
||||
);
|
||||
}
|
||||
}
|
||||
20
vendor/filament/notifications/src/Concerns/CanBeInline.php
vendored
Normal file
20
vendor/filament/notifications/src/Concerns/CanBeInline.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
trait CanBeInline
|
||||
{
|
||||
protected bool $isInline = false;
|
||||
|
||||
public function inline(bool $condition = true): static
|
||||
{
|
||||
$this->isInline = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isInline(): bool
|
||||
{
|
||||
return $this->isInline;
|
||||
}
|
||||
}
|
||||
41
vendor/filament/notifications/src/Concerns/HasActions.php
vendored
Normal file
41
vendor/filament/notifications/src/Concerns/HasActions.php
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasActions
|
||||
{
|
||||
/**
|
||||
* @var array<Action | ActionGroup> | ActionGroup | Closure
|
||||
*/
|
||||
protected array | ActionGroup | Closure $actions = [];
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup | Closure $actions
|
||||
*/
|
||||
public function actions(array | ActionGroup | Closure $actions): static
|
||||
{
|
||||
$this->actions = $actions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getActions(): array
|
||||
{
|
||||
return array_map(
|
||||
fn (Action | ActionGroup $action) => match (true) {
|
||||
$action instanceof Action => $action->defaultView(Action::LINK_VIEW)->defaultSize(Size::Small),
|
||||
$action instanceof ActionGroup => $action->defaultTriggerView(ActionGroup::LINK_VIEW)->defaultSize(Size::Small)
|
||||
},
|
||||
Arr::wrap($this->evaluate($this->actions)),
|
||||
);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/notifications/src/Concerns/HasBody.php
vendored
Normal file
22
vendor/filament/notifications/src/Concerns/HasBody.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasBody
|
||||
{
|
||||
protected string | Closure | null $body = null;
|
||||
|
||||
public function body(string | Closure | null $body): static
|
||||
{
|
||||
$this->body = $body;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBody(): ?string
|
||||
{
|
||||
return $this->evaluate($this->body);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/notifications/src/Concerns/HasDate.php
vendored
Normal file
22
vendor/filament/notifications/src/Concerns/HasDate.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasDate
|
||||
{
|
||||
protected string | Closure | null $date = null;
|
||||
|
||||
public function date(string | Closure | null $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?string
|
||||
{
|
||||
return $this->evaluate($this->date);
|
||||
}
|
||||
}
|
||||
36
vendor/filament/notifications/src/Concerns/HasDuration.php
vendored
Normal file
36
vendor/filament/notifications/src/Concerns/HasDuration.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasDuration
|
||||
{
|
||||
protected int | string | Closure $duration = 6000;
|
||||
|
||||
public function duration(int | string | Closure | null $duration): static
|
||||
{
|
||||
$this->duration = $duration ?? 'persistent';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDuration(): int | string
|
||||
{
|
||||
return $this->evaluate($this->duration) ?? 'persistent';
|
||||
}
|
||||
|
||||
public function seconds(float $seconds): static
|
||||
{
|
||||
$this->duration((int) ($seconds * 1000));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistent(): static
|
||||
{
|
||||
$this->duration('persistent');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
28
vendor/filament/notifications/src/Concerns/HasIcon.php
vendored
Normal file
28
vendor/filament/notifications/src/Concerns/HasIcon.php
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Notifications\View\NotificationsIconAlias;
|
||||
use Filament\Support\Concerns\HasIcon as BaseTrait;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasIcon
|
||||
{
|
||||
use BaseTrait {
|
||||
getIcon as getBaseIcon;
|
||||
}
|
||||
|
||||
public function getIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->getBaseIcon() ?? match ($this->getStatus()) {
|
||||
'danger' => FilamentIcon::resolve(NotificationsIconAlias::NOTIFICATION_DANGER) ?? Heroicon::OutlinedXCircle,
|
||||
'info' => FilamentIcon::resolve(NotificationsIconAlias::NOTIFICATION_INFO) ?? Heroicon::OutlinedInformationCircle,
|
||||
'success' => FilamentIcon::resolve(NotificationsIconAlias::NOTIFICATION_SUCCESS) ?? Heroicon::OutlinedCheckCircle,
|
||||
'warning' => FilamentIcon::resolve(NotificationsIconAlias::NOTIFICATION_WARNING) ?? Heroicon::OutlinedExclamationCircle,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
20
vendor/filament/notifications/src/Concerns/HasIconColor.php
vendored
Normal file
20
vendor/filament/notifications/src/Concerns/HasIconColor.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Filament\Support\Concerns\HasIconColor as BaseTrait;
|
||||
|
||||
trait HasIconColor
|
||||
{
|
||||
use BaseTrait {
|
||||
getIconColor as getBaseIconColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getIconColor(): string | array | null
|
||||
{
|
||||
return $this->getBaseIconColor() ?? $this->getStatus();
|
||||
}
|
||||
}
|
||||
20
vendor/filament/notifications/src/Concerns/HasId.php
vendored
Normal file
20
vendor/filament/notifications/src/Concerns/HasId.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
trait HasId
|
||||
{
|
||||
protected string $id;
|
||||
|
||||
public function id(string $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
42
vendor/filament/notifications/src/Concerns/HasStatus.php
vendored
Normal file
42
vendor/filament/notifications/src/Concerns/HasStatus.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasStatus
|
||||
{
|
||||
protected string | Closure | null $status = null;
|
||||
|
||||
public function status(string | Closure | null $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?string
|
||||
{
|
||||
return $this->evaluate($this->status);
|
||||
}
|
||||
|
||||
public function danger(): static
|
||||
{
|
||||
return $this->status('danger');
|
||||
}
|
||||
|
||||
public function info(): static
|
||||
{
|
||||
return $this->status('info');
|
||||
}
|
||||
|
||||
public function success(): static
|
||||
{
|
||||
return $this->status('success');
|
||||
}
|
||||
|
||||
public function warning(): static
|
||||
{
|
||||
return $this->status('warning');
|
||||
}
|
||||
}
|
||||
22
vendor/filament/notifications/src/Concerns/HasTitle.php
vendored
Normal file
22
vendor/filament/notifications/src/Concerns/HasTitle.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasTitle
|
||||
{
|
||||
protected string | Closure | null $title = null;
|
||||
|
||||
public function title(string | Closure | null $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->evaluate($this->title);
|
||||
}
|
||||
}
|
||||
47
vendor/filament/notifications/src/DatabaseNotification.php
vendored
Normal file
47
vendor/filament/notifications/src/DatabaseNotification.php
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notification as BaseNotification;
|
||||
|
||||
class DatabaseNotification extends BaseNotification implements Arrayable, ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(
|
||||
public array $data,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param Model $notifiable
|
||||
* @return array<string>
|
||||
*/
|
||||
public function via($notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $notifiable
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase($notifiable): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
38
vendor/filament/notifications/src/Events/DatabaseNotificationsSent.php
vendored
Normal file
38
vendor/filament/notifications/src/Events/DatabaseNotificationsSent.php
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DatabaseNotificationsSent implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
protected Model | Authenticatable $user,
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): string
|
||||
{
|
||||
if (method_exists($this->user, 'receivesBroadcastNotificationsOn')) {
|
||||
return new PrivateChannel($this->user->receivesBroadcastNotificationsOn());
|
||||
}
|
||||
|
||||
$userClass = str_replace('\\', '.', $this->user::class);
|
||||
|
||||
return new PrivateChannel("{$userClass}.{$this->user->getKey()}");
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'database-notifications.sent';
|
||||
}
|
||||
}
|
||||
225
vendor/filament/notifications/src/Livewire/DatabaseNotifications.php
vendored
Normal file
225
vendor/filament/notifications/src/Livewire/DatabaseNotifications.php
vendored
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Livewire;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Notifications\DatabaseNotificationCollection;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class DatabaseNotifications extends Component implements HasActions, HasSchemas
|
||||
{
|
||||
use InteractsWithActions;
|
||||
use InteractsWithSchemas;
|
||||
use WithPagination;
|
||||
|
||||
public static bool $isPaginated = true;
|
||||
|
||||
public static ?string $trigger = null;
|
||||
|
||||
public static ?string $pollingInterval = '30s';
|
||||
|
||||
public static ?string $authGuard = null;
|
||||
|
||||
#[On('databaseNotificationsSent')]
|
||||
public function refresh(): void {}
|
||||
|
||||
#[On('notificationClosed')]
|
||||
public function removeNotification(string $id): void
|
||||
{
|
||||
if (! Str::isUuid($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getNotificationsQuery()
|
||||
->where('id', $id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
#[On('markedNotificationAsRead')]
|
||||
public function markNotificationAsRead(string $id): void
|
||||
{
|
||||
if (! Str::isUuid($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getNotificationsQuery()
|
||||
->where('id', $id)
|
||||
->update(['read_at' => now()]);
|
||||
}
|
||||
|
||||
#[On('markedNotificationAsUnread')]
|
||||
public function markNotificationAsUnread(string $id): void
|
||||
{
|
||||
if (! Str::isUuid($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getNotificationsQuery()
|
||||
->where('id', $id)
|
||||
->update(['read_at' => null]);
|
||||
}
|
||||
|
||||
public function clearNotifications(): void
|
||||
{
|
||||
$this->getNotificationsQuery()->delete();
|
||||
}
|
||||
|
||||
public function markAllNotificationsAsRead(): void
|
||||
{
|
||||
$this->getUnreadNotificationsQuery()->update(['read_at' => now()]);
|
||||
}
|
||||
|
||||
public function getNotifications(): DatabaseNotificationCollection | Paginator
|
||||
{
|
||||
if (! $this->isPaginated()) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
return $this->getNotificationsQuery()->get();
|
||||
}
|
||||
|
||||
return $this->getNotificationsQuery()->simplePaginate(50, pageName: 'database-notifications-page');
|
||||
}
|
||||
|
||||
public function isPaginated(): bool
|
||||
{
|
||||
return static::$isPaginated;
|
||||
}
|
||||
|
||||
public function getNotificationsQuery(): Builder | Relation
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
if (! $user) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
return $user->notifications()->where('data->format', 'filament');
|
||||
}
|
||||
|
||||
public function getUnreadNotificationsQuery(): Builder | Relation
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
return $this->getNotificationsQuery()->unread();
|
||||
}
|
||||
|
||||
public function getUnreadNotificationsCount(): int
|
||||
{
|
||||
return $this->getUnreadNotificationsQuery()->count();
|
||||
}
|
||||
|
||||
public function getPollingInterval(): ?string
|
||||
{
|
||||
return static::$pollingInterval;
|
||||
}
|
||||
|
||||
public function getTrigger(): ?View
|
||||
{
|
||||
$viewPath = static::$trigger;
|
||||
|
||||
if (blank($viewPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return view($viewPath);
|
||||
}
|
||||
|
||||
public function markAllNotificationsAsReadAction(): Action
|
||||
{
|
||||
return Action::make('markAllNotificationsAsRead')
|
||||
->link()
|
||||
->label(__('filament-notifications::database.modal.actions.mark_all_as_read.label'))
|
||||
->action('markAllNotificationsAsRead');
|
||||
}
|
||||
|
||||
public function clearNotificationsAction(): Action
|
||||
{
|
||||
return Action::make('clearNotifications')
|
||||
->link()
|
||||
->color('danger')
|
||||
->label(__('filament-notifications::database.modal.actions.clear.label'))
|
||||
->action('clearNotifications')
|
||||
->close();
|
||||
}
|
||||
|
||||
public function getUser(): Model | Authenticatable | null
|
||||
{
|
||||
return auth(static::$authGuard)->user();
|
||||
}
|
||||
|
||||
public function getBroadcastChannel(): ?string
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
if (! $user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (method_exists($user, 'receivesBroadcastNotificationsOn')) {
|
||||
return $user->receivesBroadcastNotificationsOn();
|
||||
}
|
||||
|
||||
$userClass = str_replace('\\', '.', $user::class);
|
||||
|
||||
return "{$userClass}.{$user->getKey()}";
|
||||
}
|
||||
|
||||
public function getNotification(DatabaseNotification $notification): Notification
|
||||
{
|
||||
return Notification::fromDatabase($notification)
|
||||
->date($this->formatNotificationDate($notification->getAttributeValue('created_at')));
|
||||
}
|
||||
|
||||
protected function formatNotificationDate(CarbonInterface $date): string
|
||||
{
|
||||
return $date->diffForHumans();
|
||||
}
|
||||
|
||||
public static function trigger(?string $trigger): void
|
||||
{
|
||||
static::$trigger = $trigger;
|
||||
}
|
||||
|
||||
public static function pollingInterval(?string $interval): void
|
||||
{
|
||||
static::$pollingInterval = $interval;
|
||||
}
|
||||
|
||||
public static function authGuard(?string $guard): void
|
||||
{
|
||||
static::$authGuard = $guard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function queryStringHandlesPagination(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('filament-notifications::database-notifications');
|
||||
}
|
||||
|
||||
public function placeholder(): string
|
||||
{
|
||||
return '<div>' . $this->getTrigger()?->with(['unreadNotificationsCount' => $this->getUnreadNotificationsCount()])->render() . '</div>';
|
||||
}
|
||||
}
|
||||
130
vendor/filament/notifications/src/Livewire/Notifications.php
vendored
Normal file
130
vendor/filament/notifications/src/Livewire/Notifications.php
vendored
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Livewire;
|
||||
|
||||
use Filament\Notifications\Collection;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\VerticalAlignment;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class Notifications extends Component
|
||||
{
|
||||
// Used to check if Livewire messages should trigger notification animations.
|
||||
public bool $isFilamentNotificationsComponent = true;
|
||||
|
||||
public Collection $notifications;
|
||||
|
||||
public static Alignment $alignment = Alignment::Right;
|
||||
|
||||
public static VerticalAlignment $verticalAlignment = VerticalAlignment::Start;
|
||||
|
||||
public static ?string $authGuard = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->notifications = new Collection;
|
||||
$this->pullNotificationsFromSession();
|
||||
}
|
||||
|
||||
#[On('notificationsSent')]
|
||||
public function pullNotificationsFromSession(): void
|
||||
{
|
||||
$notifications = session()->pull('filament.claimed_notifications')
|
||||
?? session()->pull('filament.notifications')
|
||||
?? [];
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification = Notification::fromArray($notification);
|
||||
|
||||
$this->pushNotification($notification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $notification
|
||||
*/
|
||||
#[On('notificationSent')]
|
||||
public function pushNotificationFromEvent(array $notification): void
|
||||
{
|
||||
$notification = Notification::fromArray($notification);
|
||||
|
||||
$this->pushNotification($notification);
|
||||
}
|
||||
|
||||
#[On('notificationClosed')]
|
||||
public function removeNotification(string $id): void
|
||||
{
|
||||
if (! $this->notifications->has($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->notifications->forget($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $notification
|
||||
*/
|
||||
public function handleBroadcastNotification(array $notification): void
|
||||
{
|
||||
if (($notification['format'] ?? null) !== 'filament') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->pushNotification(Notification::fromArray($notification));
|
||||
}
|
||||
|
||||
protected function pushNotification(Notification $notification): void
|
||||
{
|
||||
$this->notifications->put(
|
||||
$notification->getId(),
|
||||
$notification,
|
||||
);
|
||||
}
|
||||
|
||||
public function getUser(): Model | Authenticatable | null
|
||||
{
|
||||
return auth(static::$authGuard)->user();
|
||||
}
|
||||
|
||||
public function getBroadcastChannel(): ?string
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
if (! $user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (method_exists($user, 'receivesBroadcastNotificationsOn')) {
|
||||
return $user->receivesBroadcastNotificationsOn();
|
||||
}
|
||||
|
||||
$userClass = str_replace('\\', '.', $user::class);
|
||||
|
||||
return "{$userClass}.{$user->getKey()}";
|
||||
}
|
||||
|
||||
public static function alignment(Alignment $alignment): void
|
||||
{
|
||||
static::$alignment = $alignment;
|
||||
}
|
||||
|
||||
public static function verticalAlignment(VerticalAlignment $alignment): void
|
||||
{
|
||||
static::$verticalAlignment = $alignment;
|
||||
}
|
||||
|
||||
public static function authGuard(?string $guard): void
|
||||
{
|
||||
static::$authGuard = $guard;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('filament-notifications::notifications');
|
||||
}
|
||||
}
|
||||
437
vendor/filament/notifications/src/Notification.php
vendored
Normal file
437
vendor/filament/notifications/src/Notification.php
vendored
Normal file
|
|
@ -0,0 +1,437 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Notifications\Events\DatabaseNotificationsSent;
|
||||
use Filament\Notifications\Livewire\Notifications;
|
||||
use Filament\Notifications\View\Components\NotificationComponent;
|
||||
use Filament\Notifications\View\Components\NotificationComponent\IconComponent;
|
||||
use Filament\Notifications\View\NotificationsIconAlias;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Components\ViewComponent;
|
||||
use Filament\Support\Concerns\HasColor;
|
||||
use Filament\Support\Concerns\HasIconSize;
|
||||
use Filament\Support\Contracts\ScalableIcon;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\DatabaseNotification as DatabaseNotificationModel;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class Notification extends ViewComponent implements Arrayable, HasEmbeddedView
|
||||
{
|
||||
use Concerns\CanBeInline;
|
||||
use Concerns\HasActions;
|
||||
use Concerns\HasBody;
|
||||
use Concerns\HasDate;
|
||||
use Concerns\HasDuration;
|
||||
use Concerns\HasIcon;
|
||||
use Concerns\HasIconColor;
|
||||
use Concerns\HasId;
|
||||
use Concerns\HasStatus;
|
||||
use Concerns\HasTitle;
|
||||
use HasColor;
|
||||
use HasIconSize;
|
||||
|
||||
protected string $viewIdentifier = 'notification';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $safeViews = [];
|
||||
|
||||
public function __construct(string $id)
|
||||
{
|
||||
$this->id($id);
|
||||
}
|
||||
|
||||
public static function make(?string $id = null): static
|
||||
{
|
||||
$static = app(static::class, ['id' => $id ?? Str::orderedUuid()]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$icon = $this->getIcon();
|
||||
|
||||
if ($icon instanceof ScalableIcon) {
|
||||
$icon = $icon->getIconForSize(IconSize::Large);
|
||||
} elseif ($icon instanceof BackedEnum) {
|
||||
$icon = $icon->value;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'actions' => array_map(fn (Action | ActionGroup $action): array => $action->toArray(), $this->getActions()),
|
||||
'body' => $this->getBody(),
|
||||
'color' => $this->getColor(),
|
||||
'duration' => $this->getDuration(),
|
||||
'icon' => $icon,
|
||||
'iconColor' => $this->getIconColor(),
|
||||
'status' => $this->getStatus(),
|
||||
'title' => $this->getTitle(),
|
||||
'view' => $this->hasView() ? $this->getView() : null,
|
||||
'viewData' => $this->getViewData(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function fromArray(array $data): static
|
||||
{
|
||||
$static = static::make($data['id'] ?? Str::random());
|
||||
|
||||
// If the container constructs an instance of child class
|
||||
// instead of the current class, we should run `fromArray()`
|
||||
// on the child class instead.
|
||||
if (
|
||||
($static::class !== self::class) &&
|
||||
(get_called_class() === self::class)
|
||||
) {
|
||||
return $static::fromArray($data);
|
||||
}
|
||||
|
||||
$static->actions(
|
||||
array_map(
|
||||
fn (array $action): Action | ActionGroup => match (array_key_exists('actions', $action)) {
|
||||
true => ActionGroup::fromArray($action),
|
||||
false => Action::fromArray($action),
|
||||
},
|
||||
$data['actions'] ?? [],
|
||||
),
|
||||
);
|
||||
|
||||
$view = $data['view'] ?? null;
|
||||
|
||||
if (filled($view) && ((! $static->hasView()) || ($static->getView() !== $view)) && $static->isViewSafe($view)) {
|
||||
$static->view($data['view']);
|
||||
}
|
||||
|
||||
$static->viewData($data['viewData'] ?? []);
|
||||
$static->body($data['body'] ?? null);
|
||||
$static->color($data['color'] ?? null);
|
||||
$static->duration($data['duration'] ?? $static->getDuration());
|
||||
$static->status($data['status'] ?? $static->getStatus());
|
||||
$static->icon($data['icon'] ?? $static->getIcon());
|
||||
$static->iconColor($data['iconColor'] ?? $static->getIconColor());
|
||||
$static->title($data['title'] ?? null);
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function isViewSafe(string $view): bool
|
||||
{
|
||||
// Security: Only explicitly whitelisted views can be rendered in
|
||||
// notifications, preventing view injection from stored data.
|
||||
|
||||
return in_array($view, $this->safeViews, strict: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> $safeViews
|
||||
*/
|
||||
public function safeViews(string | array $safeViews): static
|
||||
{
|
||||
$this->safeViews = [
|
||||
...$this->safeViews,
|
||||
...Arr::wrap($safeViews),
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send(): static
|
||||
{
|
||||
session()->push(
|
||||
'filament.notifications',
|
||||
$this->toArray(),
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | Authenticatable | Collection | array<Model | Authenticatable> $users
|
||||
*/
|
||||
public function broadcast(Model | Authenticatable | Collection | array $users): static
|
||||
{
|
||||
if (! is_iterable($users)) {
|
||||
$users = [$users];
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->notify($this->toBroadcast());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | Authenticatable | Collection | array<Model | Authenticatable> $users
|
||||
*/
|
||||
public function sendToDatabase(Model | Authenticatable | Collection | array $users, bool $isEventDispatched = false): static
|
||||
{
|
||||
if (! is_iterable($users)) {
|
||||
$users = [$users];
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->notify($this->toDatabase());
|
||||
|
||||
if ($isEventDispatched) {
|
||||
DatabaseNotificationsSent::dispatch($user);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toBroadcast(): BroadcastNotification
|
||||
{
|
||||
$data = $this->toArray();
|
||||
$data['format'] = 'filament';
|
||||
|
||||
return app(BroadcastNotification::class, ['data' => $data]);
|
||||
}
|
||||
|
||||
public function toDatabase(): DatabaseNotification
|
||||
{
|
||||
return new DatabaseNotification($this->getDatabaseMessage());
|
||||
}
|
||||
|
||||
public function getBroadcastMessage(): BroadcastMessage
|
||||
{
|
||||
$data = $this->toArray();
|
||||
$data['format'] = 'filament';
|
||||
|
||||
return new BroadcastMessage($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getDatabaseMessage(): array
|
||||
{
|
||||
$data = $this->toArray();
|
||||
$data['duration'] = 'persistent';
|
||||
$data['format'] = 'filament';
|
||||
unset($data['id']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function fromDatabase(DatabaseNotificationModel $notification): static
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
$static = static::fromArray($notification->data);
|
||||
$static->id($notification->getKey());
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public static function assertNotified(Notification | string | null $notification = null): void
|
||||
{
|
||||
$notificationsLivewireComponent = new Notifications;
|
||||
$notificationsLivewireComponent->mount();
|
||||
$notifications = $notificationsLivewireComponent->notifications;
|
||||
|
||||
$expectedNotification = null;
|
||||
|
||||
Assert::assertIsArray($notifications->toArray());
|
||||
|
||||
if (is_string($notification)) {
|
||||
$expectedNotification = $notifications->first(fn (Notification $mountedNotification): bool => $mountedNotification->title === $notification);
|
||||
}
|
||||
|
||||
if ($notification instanceof Notification) {
|
||||
$expectedNotificationArray = collect($notification->toArray())->except(['id'])->toArray();
|
||||
|
||||
$expectedNotification = $notifications->first(
|
||||
fn (Notification $mountedNotification): bool => collect($mountedNotification->toArray())->except(['id'])->toArray() === $expectedNotificationArray,
|
||||
);
|
||||
}
|
||||
|
||||
if (blank($notification)) {
|
||||
Assert::assertNotEmpty(
|
||||
$notifications->toArray(),
|
||||
'A notification was expected but none were sent.',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert::assertNotNull($expectedNotification, 'A notification was not sent');
|
||||
|
||||
if ($notification instanceof Notification) {
|
||||
Assert::assertSame(
|
||||
collect($expectedNotification)->except(['id'])->toArray(),
|
||||
collect($notification->toArray())->except(['id'])->toArray()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert::assertSame($expectedNotification->title, $notification);
|
||||
}
|
||||
|
||||
public static function assertNotNotified(Notification | string | null $notification = null): void
|
||||
{
|
||||
$notificationsLivewireComponent = new Notifications;
|
||||
$notificationsLivewireComponent->mount();
|
||||
$notifications = $notificationsLivewireComponent->notifications;
|
||||
|
||||
$expectedNotification = null;
|
||||
|
||||
Assert::assertIsArray($notifications->toArray());
|
||||
|
||||
if (is_string($notification)) {
|
||||
$expectedNotification = $notifications->first(fn (Notification $mountedNotification): bool => $mountedNotification->title === $notification);
|
||||
}
|
||||
|
||||
if ($notification instanceof Notification) {
|
||||
$expectedNotificationArray = collect($notification->toArray())->except(['id'])->toArray();
|
||||
|
||||
$expectedNotification = $notifications->first(
|
||||
fn (Notification $mountedNotification): bool => collect($mountedNotification->toArray())->except(['id'])->toArray() === $expectedNotificationArray,
|
||||
);
|
||||
}
|
||||
|
||||
if (blank($notification)) {
|
||||
Assert::assertEmpty(
|
||||
$notifications->toArray(),
|
||||
'No notification was expected but at least one was sent.',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($notification instanceof Notification) {
|
||||
Assert::assertNotSame(
|
||||
collect($expectedNotification)->except(['id'])->toArray(),
|
||||
collect($notification->toArray())->except(['id'])->toArray(),
|
||||
'The notification with the given configuration was sent'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($expectedNotification instanceof Notification) {
|
||||
Assert::assertNotSame(
|
||||
$expectedNotification->title,
|
||||
$notification,
|
||||
'The notification with the given title was sent'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$status = $this->getStatus();
|
||||
$title = $this->getTitle();
|
||||
$hasTitle = filled($title);
|
||||
$date = $this->getDate();
|
||||
$hasDate = filled($date);
|
||||
$body = $this->getBody();
|
||||
$hasBody = filled($body);
|
||||
$closeButtonLabel = __('filament-notifications::notification.actions.close.label');
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
// `danger` toasts convey errors, so they get an assertive live region
|
||||
// (`role="alert"`) to interrupt; other statuses inherit the polite
|
||||
// `role="status"` container. Inline notifications (e.g. rendered into the
|
||||
// database-notifications modal) are excluded, otherwise opening the panel
|
||||
// would replay every stored danger notification as an assertive burst.
|
||||
'role' => ($status === 'danger' && ! $this->isInline) ? 'alert' : null,
|
||||
'wire:key' => "{$this->getId()}.notifications.{$this->getId()}",
|
||||
'x-on:close-notification.window' => "if (\$event.detail.id == '{$this->getId()}') close()",
|
||||
], escape: false)
|
||||
->color(NotificationComponent::class, $this->getColor() ?? 'gray')
|
||||
->class([
|
||||
'fi-no-notification',
|
||||
'fi-inline' => $this->isInline,
|
||||
"fi-status-{$status}" => $status,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div
|
||||
x-data="notificationComponent({ notification: <?= Js::from([
|
||||
'id' => $this->getId(),
|
||||
'duration' => $this->getDuration(),
|
||||
]) ?> })"
|
||||
x-transition:enter-start="fi-transition-enter-start"
|
||||
x-transition:enter-end="fi-transition-enter-end"
|
||||
x-transition:leave-start="fi-transition-leave-start"
|
||||
x-transition:leave-end="fi-transition-leave-end"
|
||||
<?= $attributes ?>
|
||||
>
|
||||
<?= generate_icon_html(
|
||||
$this->getIcon(),
|
||||
attributes: (new FilamentComponentAttributeBag)->color(IconComponent::class, $this->getIconColor())->class(['fi-no-notification-icon']),
|
||||
size: $this->getIconSize(),
|
||||
)?->toHtml() ?>
|
||||
|
||||
<div class="fi-no-notification-main">
|
||||
<?php if ($hasTitle || $hasDate || $hasBody) { ?>
|
||||
<div class="fi-no-notification-text">
|
||||
<?php if ($hasTitle) { ?>
|
||||
<h3 class="fi-no-notification-title">
|
||||
<?= str($title)->sanitizeHtml() ?>
|
||||
</h3>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasDate) { ?>
|
||||
<time class="fi-no-notification-date">
|
||||
<?= e($date) ?>
|
||||
</time>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasBody) { ?>
|
||||
<div class="fi-no-notification-body">
|
||||
<?= str($body)->sanitizeHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($actions = $this->getActions()) { ?>
|
||||
<div class="fi-ac fi-no-notification-actions">
|
||||
<?php foreach ($actions as $action) { ?>
|
||||
<?= $action->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
x-on:click="close"
|
||||
aria-label="<?= e($closeButtonLabel) ?>"
|
||||
title="<?= e($closeButtonLabel) ?>"
|
||||
class="fi-icon-btn fi-no-notification-close-btn"
|
||||
>
|
||||
<?= generate_icon_html(Heroicon::XMark, alias: NotificationsIconAlias::NOTIFICATION_CLOSE_BUTTON)->toHtml() ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
61
vendor/filament/notifications/src/NotificationsServiceProvider.php
vendored
Normal file
61
vendor/filament/notifications/src/NotificationsServiceProvider.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications;
|
||||
|
||||
use Filament\Notifications\Livewire\DatabaseNotifications;
|
||||
use Filament\Notifications\Livewire\Notifications;
|
||||
use Filament\Notifications\Testing\TestsNotifications;
|
||||
use Filament\Support\Assets\Js;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportTesting\Testable;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
|
||||
use function Livewire\on;
|
||||
use function Livewire\store;
|
||||
|
||||
class NotificationsServiceProvider extends PackageServiceProvider
|
||||
{
|
||||
public function configurePackage(Package $package): void
|
||||
{
|
||||
$package
|
||||
->name('filament-notifications')
|
||||
->hasTranslations()
|
||||
->hasViews();
|
||||
}
|
||||
|
||||
public function packageBooted(): void
|
||||
{
|
||||
FilamentAsset::register([
|
||||
Js::make('notifications', __DIR__ . '/../dist/index.js'),
|
||||
], 'filament/notifications');
|
||||
|
||||
Livewire::component('database-notifications', DatabaseNotifications::class);
|
||||
|
||||
Livewire::component('notifications', Notifications::class);
|
||||
|
||||
on('dehydrate', function (Component $component): void {
|
||||
if (! Livewire::isLivewireRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (store($component)->has('redirect')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notifications = session()->pull('filament.notifications') ?? [];
|
||||
|
||||
if (count($notifications) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
session()->put('filament.claimed_notifications', $notifications);
|
||||
|
||||
$component->dispatch('notificationsSent');
|
||||
});
|
||||
|
||||
Testable::mixin(new TestsNotifications);
|
||||
}
|
||||
}
|
||||
34
vendor/filament/notifications/src/Testing/TestsNotifications.php
vendored
Normal file
34
vendor/filament/notifications/src/Testing/TestsNotifications.php
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Testing;
|
||||
|
||||
use Closure;
|
||||
use Filament\Notifications\Notification;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportTesting\Testable;
|
||||
|
||||
/**
|
||||
* @method Component instance()
|
||||
*
|
||||
* @mixin Testable
|
||||
*/
|
||||
class TestsNotifications
|
||||
{
|
||||
public function assertNotified(): Closure
|
||||
{
|
||||
return function (Notification | string | null $notification = null): static {
|
||||
Notification::assertNotified($notification);
|
||||
|
||||
return $this;
|
||||
};
|
||||
}
|
||||
|
||||
public function assertNotNotified(): Closure
|
||||
{
|
||||
return function (Notification | string | null $notification = null): static {
|
||||
Notification::assertNotNotified($notification);
|
||||
|
||||
return $this;
|
||||
};
|
||||
}
|
||||
}
|
||||
15
vendor/filament/notifications/src/Testing/helpers.php
vendored
Normal file
15
vendor/filament/notifications/src/Testing/helpers.php
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\Testing;
|
||||
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* @return TestCall | TestCase | mixed
|
||||
*/
|
||||
function assertNotified(Notification | string | null $notification = null)
|
||||
{
|
||||
Notification::assertNotified($notification);
|
||||
|
||||
return test();
|
||||
}
|
||||
18
vendor/filament/notifications/src/View/Components/NotificationComponent.php
vendored
Normal file
18
vendor/filament/notifications/src/View/Components/NotificationComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\View\Components;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class NotificationComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
18
vendor/filament/notifications/src/View/Components/NotificationComponent/IconComponent.php
vendored
Normal file
18
vendor/filament/notifications/src/View/Components/NotificationComponent/IconComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\View\Components\NotificationComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class IconComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
18
vendor/filament/notifications/src/View/NotificationsIconAlias.php
vendored
Normal file
18
vendor/filament/notifications/src/View/NotificationsIconAlias.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Notifications\View;
|
||||
|
||||
class NotificationsIconAlias
|
||||
{
|
||||
const DATABASE_MODAL_EMPTY_STATE = 'notifications::database.modal.empty-state';
|
||||
|
||||
const NOTIFICATION_CLOSE_BUTTON = 'notifications::notification.close-button';
|
||||
|
||||
const NOTIFICATION_DANGER = 'notifications::notification.danger';
|
||||
|
||||
const NOTIFICATION_INFO = 'notifications::notification.info';
|
||||
|
||||
const NOTIFICATION_SUCCESS = 'notifications::notification.success';
|
||||
|
||||
const NOTIFICATION_WARNING = 'notifications::notification.warning';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue