feat: Add color methods to ContentType and Channel enums, cast channel and social media in ContentRecap model, and enhance Filament table display with colored badges.
This commit is contained in:
parent
5313afb31e
commit
5a85090652
@ -9,12 +9,13 @@ enum Channel: string implements HasLabel
|
||||
{
|
||||
use WithComment;
|
||||
|
||||
case WEBSITE = 'Website';
|
||||
case TIKTOK = 'Tiktok';
|
||||
case YOUTUBE = 'Youtube';
|
||||
case FACEBOOK = 'Facebook';
|
||||
case INSTAGRAM = 'Instagram';
|
||||
case OTHER = 'Other';
|
||||
case WEBSITE = 'website';
|
||||
case TIKTOK = 'tiktok';
|
||||
case YOUTUBE = 'youtube';
|
||||
case FACEBOOK = 'facebook';
|
||||
case INSTAGRAM = 'instagram';
|
||||
case TWITTER = 'twitter';
|
||||
case OTHER = 'other';
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
@ -24,10 +25,24 @@ public function getLabel(): ?string
|
||||
self::YOUTUBE => 'Youtube',
|
||||
self::FACEBOOK => 'Facebook',
|
||||
self::INSTAGRAM => 'Instagram',
|
||||
self::TWITTER => 'Twitter',
|
||||
self::OTHER => 'Other',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::WEBSITE => 'info',
|
||||
self::TIKTOK => 'success',
|
||||
self::YOUTUBE => 'warning',
|
||||
self::FACEBOOK => 'danger',
|
||||
self::INSTAGRAM => 'primary',
|
||||
self::TWITTER => 'secondary',
|
||||
self::OTHER => 'gray',
|
||||
};
|
||||
}
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
return collect(self::cases())
|
||||
|
||||
@ -25,6 +25,16 @@ public function getLabel(): ?string
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::FOTO => 'info',
|
||||
self::TEXT => 'success',
|
||||
self::GRAPHIC => 'warning',
|
||||
self::VIDEO => 'danger',
|
||||
};
|
||||
}
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
return collect(self::cases())
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Enums\Channel;
|
||||
use App\Enums\SocialMedia;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
@ -28,11 +26,11 @@ public function setUp()
|
||||
|
||||
Column::make('channel')
|
||||
->heading('Kanal')
|
||||
->formatStateUsing(fn ($state) => Channel::tryFrom($state)?->getLabel() ?? $state),
|
||||
->formatStateUsing(fn ($state) => $state->getLabel()),
|
||||
|
||||
Column::make('social_media')
|
||||
->heading('Media Sosial')
|
||||
->formatStateUsing(fn ($state) => SocialMedia::tryFrom($state)?->getLabel() ?? $state),
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('classification.name')
|
||||
->heading('Klasifikasi'),
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Exports\ContentRecapExcelExport;
|
||||
use App\Models\ContentRecap;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
@ -37,15 +38,20 @@ public static function configure(Table $table): Table
|
||||
->label('Judul')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->wrap(),
|
||||
->wrap()
|
||||
->description(fn (ContentRecap $contentRecap): string => $contentRecap->link),
|
||||
|
||||
TextColumn::make('type')
|
||||
->label('Tipe')
|
||||
->badge()
|
||||
->color(fn (ContentType $state): string => $state->getColor())
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('channel')
|
||||
->label('Kanal')
|
||||
->badge()
|
||||
->color(fn (Channel $state): string => $state->getColor())
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
@ -59,11 +65,6 @@ public static function configure(Table $table): Table
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('link')
|
||||
->label('Tautan')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('posting_date')
|
||||
->label('Tgl Posting')
|
||||
->searchable()
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Channel;
|
||||
use App\Enums\ContentType;
|
||||
use App\Enums\SocialMedia;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -21,6 +23,8 @@ protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => ContentType::class,
|
||||
'channel' => Channel::class,
|
||||
'social_media' => SocialMedia::class,
|
||||
'posting_date' => 'date',
|
||||
'classification_id' => 'integer',
|
||||
];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user