Skip to content

Commit

Permalink
feat(filament): added timestamps panel and avatar provider (#657)
Browse files Browse the repository at this point in the history
* feat(filament): timestamps panel

* feat(filament): using gravatar image as avatar

* fix(filament): added isServing for filament policies and force delete any

* feat(filament): resource icons
  • Loading branch information
Kyrch authored Apr 22, 2024
1 parent 1ce7d7c commit ac38b27
Show file tree
Hide file tree
Showing 50 changed files with 1,100 additions and 262 deletions.
38 changes: 31 additions & 7 deletions app/Filament/Resources/Admin/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use App\Models\Admin\Announcement as AnnouncementModel;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Form;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Infolist;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

Expand All @@ -27,13 +29,6 @@ class Announcement extends BaseResource
*/
protected static ?string $model = AnnouncementModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -70,6 +65,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.admin');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.announcements');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down Expand Up @@ -143,6 +150,23 @@ public static function table(Table $table): Table
->bulkActions(static::getBulkActions());
}

/**
* Get the infolist available for the resource.
*
* @param Infolist $infolist
* @return Infolist
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make(__('filament.fields.base.timestamps'))
->schema(parent::timestamps()),
]);
}

/**
* Get the relationships available for the resource.
*
Expand Down
38 changes: 31 additions & 7 deletions app/Filament/Resources/Admin/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Filament\Tables\Actions\ActionGroup;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Infolist;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

Expand All @@ -32,13 +34,6 @@ class Dump extends BaseResource
*/
protected static ?string $model = DumpModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -75,6 +70,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.admin');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.dumps');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down Expand Up @@ -150,6 +157,23 @@ public static function table(Table $table): Table
->headerActions(static::getHeaderActions());
}

/**
* Get the infolist available for the resource.
*
* @param Infolist $infolist
* @return Infolist
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make(__('filament.fields.base.timestamps'))
->schema(parent::timestamps()),
]);
}

/**
* Get the relationships available for the resource.
*
Expand Down
19 changes: 12 additions & 7 deletions app/Filament/Resources/Admin/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ class Feature extends BaseResource
*/
protected static ?string $model = FeatureModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -70,6 +63,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.admin');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.features');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down
73 changes: 40 additions & 33 deletions app/Filament/Resources/Admin/FeaturedTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
use App\Filament\Resources\Wiki\Video as VideoResource;
use App\Models\Admin\FeaturedTheme as FeaturedThemeModel;
use App\Models\Auth\User;
use App\Models\Wiki\Anime;
use App\Models\Wiki\Anime\AnimeTheme;
use App\Models\Wiki\Anime\Theme\AnimeThemeEntry as EntryModel;
use App\Models\Wiki\Video;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Infolist;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand All @@ -39,13 +38,6 @@ class FeaturedTheme extends BaseResource
*/
protected static ?string $model = FeaturedThemeModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -82,6 +74,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.admin');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.featured_themes');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down Expand Up @@ -155,22 +159,14 @@ public static function form(Form $form): Form

Select::make(FeaturedThemeModel::ATTRIBUTE_ENTRY)
->label(__('filament.resources.singularLabel.anime_theme_entry'))
->relationship(FeaturedThemeModel::RELATION_ENTRY, EntryModel::ATTRIBUTE_VERSION)
->relationship(FeaturedThemeModel::RELATION_ENTRY, EntryModel::ATTRIBUTE_ID)
->searchable()
->getSearchResultsUsing(function (string $search) {
$arr = [];
$animeResult = Anime::query()->where(Anime::ATTRIBUTE_NAME, 'like', "%{$search}%")->limit(50)->get();

$animeResult->each(function (Anime $anime) use (&$arr) {
$anime->animethemes->each(function (AnimeTheme $theme) use ($anime, &$arr) {
$theme->animethemeentries->each(function (EntryModel $entry) use ($anime, $theme, &$arr) {
$version = $entry->version ? " v{$entry->version}" : '';
Arr::set($arr, $entry->entry_id, "{$anime->getName()} {$theme->slug}{$version}");
});
});
});

return $arr;
return EntryModel::search($search)
->get()
->load(EntryModel::RELATION_ANIME_SHALLOW)
->mapWithKeys(fn (EntryModel $entry) => [$entry->entry_id => $entry->getName()])
->toArray();
}),

Select::make(FeaturedThemeModel::ATTRIBUTE_USER)
Expand Down Expand Up @@ -200,13 +196,13 @@ public static function table(Table $table): Table
TextColumn::make(FeaturedThemeModel::ATTRIBUTE_START_AT)
->label(__('filament.fields.featured_theme.start_at.name'))
->sortable()
->dateTime()
->date()
->toggleable(),

TextColumn::make(FeaturedThemeModel::ATTRIBUTE_END_AT)
->label(__('filament.fields.featured_theme.end_at.name'))
->sortable()
->dateTime()
->date()
->toggleable(),

TextColumn::make(FeaturedThemeModel::RELATION_VIDEO.'.'.Video::ATTRIBUTE_FILENAME)
Expand All @@ -217,13 +213,7 @@ public static function table(Table $table): Table
TextColumn::make(FeaturedThemeModel::RELATION_ENTRY.'.'.EntryModel::ATTRIBUTE_ID)
->label(__('filament.resources.singularLabel.anime_theme_entry'))
->toggleable()
->formatStateUsing(function (string $state) {
$entry = EntryModel::find(intval($state));
$version = $entry->version ? " v{$entry->version}" : '';
$theme = $entry->animetheme;

return "{$theme->anime->getName()} {$theme->slug}{$version}";
})
->formatStateUsing(fn (string $state) => EntryModel::find(intval($state))->load(EntryModel::RELATION_ANIME)->getName())
->urlToRelated(EntryResource::class, FeaturedThemeModel::RELATION_ENTRY),

TextColumn::make(FeaturedThemeModel::RELATION_USER.'.'.User::ATTRIBUTE_NAME)
Expand All @@ -237,6 +227,23 @@ public static function table(Table $table): Table
->bulkActions(static::getBulkActions());
}

/**
* Get the infolist available for the resource.
*
* @param Infolist $infolist
* @return Infolist
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make(__('filament.fields.base.timestamps'))
->schema(parent::timestamps()),
]);
}

/**
* Get the relationships available for the resource.
*
Expand Down
19 changes: 12 additions & 7 deletions app/Filament/Resources/Auth/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class Permission extends BaseResource
*/
protected static ?string $model = PermissionModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -76,6 +69,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.auth');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.permissions');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down
21 changes: 13 additions & 8 deletions app/Filament/Resources/Auth/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class Role extends BaseResource
*/
protected static ?string $model = RoleModel::class;

/**
* The icon displayed to the resource.
*
* @var string|null
*/
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

/**
* Get the displayable singular label of the resource.
*
Expand Down Expand Up @@ -80,6 +73,18 @@ public static function getNavigationGroup(): string
return __('filament.resources.group.auth');
}

/**
* The icon displayed to the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationIcon(): string
{
return __('filament.resources.icon.roles');
}

/**
* Get the slug (URI key) for the resource.
*
Expand Down Expand Up @@ -137,7 +142,7 @@ public static function form(Form $form): Form
->numeric()
->minValue(1)
->nullable()
->rules(['nullable', 'integer', 'min:1'])
->rules(['nullable', 'integer', 'min:1']),
])
->columns(1);
}
Expand Down
Loading

0 comments on commit ac38b27

Please sign in to comment.