Skip to content

Commit

Permalink
Event resource (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 30, 2024
1 parent 0b8bdcf commit 9ab33f9
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 19 deletions.
28 changes: 19 additions & 9 deletions src/FilamentMailsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Filament\Facades\Filament;
use Filament\Support\Colors\Color;
use Filament\Navigation\NavigationItem;
use Vormkracht10\FilamentMails\Models\Mail;
use Vormkracht10\FilamentMails\Resources\MailResource;
use Vormkracht10\FilamentMails\Resources\EventResource;
use Vormkracht10\FilamentMails\Widgets\BouncerateWidget;
Expand All @@ -22,21 +21,32 @@ public function getId(): string
public function register(Panel $panel): void
{
$panel
->resources([
MailResource::class,
])
->colors([
'clicked' => Color::Purple,
])
->widgets([
BouncerateWidget::class,
])
->discoverWidgets(in: __DIR__ . '/Widgets', for: 'App\\Filament\\Widgets');
->discoverResources(in: __DIR__ . '/Resources', for: 'Vormkracht10\\FilamentMails\\Resources')
->discoverWidgets(in: __DIR__ . '/Widgets', for: 'Vormkracht10\\FilamentMails\\Widgets');
}

public function boot(Panel $panel): void
{
//
Filament::serving(function () use ($panel) {
Filament::registerNavigationItems([

Check failure on line 34 in src/FilamentMailsPlugin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to deprecated method registerNavigationItems() of class Filament\FilamentManager: Use the `navigationItems()` method on the panel configuration instead.
NavigationItem::make()
->group(__('Test'))
->label('Mails')
->url(fn(): string => MailResource::getUrl('index'))
->icon('heroicon-o-envelope')
->isActiveWhen(fn(): bool => request()->routeIs('filament.' . $panel->getId() . '.resources.mails.*'))
->childItems([
NavigationItem::make()
->label('Events')
->url(fn(): string => EventResource::getUrl('index'))
->icon('heroicon-o-calendar')
->isActiveWhen(fn(): bool => request()->routeIs('filament.' . $panel->getId() . '.resources.events.*'))
])
]);
});
}

public static function make(): static
Expand Down
85 changes: 85 additions & 0 deletions src/Resources/EventResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Vormkracht10\FilamentMails\Resources;

use Filament\Tables;
use Filament\Tables\Table;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Resources\Pages\Page;
use Vormkracht10\FilamentMails\Resources\MailResource\Pages\ListMails;
use Vormkracht10\FilamentMails\Resources\EventResource\Pages\ListEvents;
use Vormkracht10\Mails\Models\MailEvent;

class EventResource extends Resource
{
protected static ?string $model = MailEvent::class;

protected static ?string $slug = 'events';

protected static ?string $recordTitleAttribute = 'subject';

protected static bool $isScopedToTenant = false;

protected static bool $shouldRegisterNavigation = false;

public static function getNavigationLabel(): string
{
return __('Events');
}

public static function getLabel(): ?string
{
return __('Events');
}

public static function getNavigationIcon(): string
{
return 'heroicon-o-calendar';
}

public static function shouldRegisterNavigation(): bool
{
return false;
}

public function getTitle(): string
{
return __('Events');
}

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([]);
}

public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make()
->slideOver()
->label(__('View'))
->hiddenLabel()
->tooltip(__('View')),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => ListEvents::route('/'),
];
}
}
36 changes: 36 additions & 0 deletions src/Resources/EventResource/Pages/ListEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Vormkracht10\FilamentMails\Resources\EventResource\Pages;

use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
use Vormkracht10\FilamentMails\Models\Mail;
use Vormkracht10\FilamentMails\Resources\EventResource;
use Vormkracht10\FilamentMails\Widgets\BouncerateWidget;
use Vormkracht10\Mails\Models\MailEvent;

class ListEvents extends ListRecords
{
protected static string $resource = EventResource::class;

public function getTitle(): string
{
return __('Events');
}

protected function getActions(): array
{
return [];
}

public function getTabs(): array
{
return [
'all' => Tab::make()
->label(__('All'))
->icon('heroicon-o-inbox')
->badge(MailEvent::count()),
];
}
}
12 changes: 2 additions & 10 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class MailResource extends Resource

protected static bool $isScopedToTenant = false;

protected static bool $shouldRegisterNavigation = false;

public static function getNavigationLabel(): string
{
return __('Mails');
Expand All @@ -36,21 +38,11 @@ public static function getLabel(): ?string
return __('Mail');
}

public static function getNavigationGroup(): ?string
{
return __('Mails');
}

public static function getNavigationIcon(): string
{
return 'heroicon-o-envelope';
}

public static function shouldRegisterNavigation(): bool
{
return true;
}

public function getTitle(): string
{
return __('Mails');
Expand Down

0 comments on commit 9ab33f9

Please sign in to comment.