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;
|
use WithComment;
|
||||||
|
|
||||||
case WEBSITE = 'Website';
|
case WEBSITE = 'website';
|
||||||
case TIKTOK = 'Tiktok';
|
case TIKTOK = 'tiktok';
|
||||||
case YOUTUBE = 'Youtube';
|
case YOUTUBE = 'youtube';
|
||||||
case FACEBOOK = 'Facebook';
|
case FACEBOOK = 'facebook';
|
||||||
case INSTAGRAM = 'Instagram';
|
case INSTAGRAM = 'instagram';
|
||||||
case OTHER = 'Other';
|
case TWITTER = 'twitter';
|
||||||
|
case OTHER = 'other';
|
||||||
|
|
||||||
public function getLabel(): ?string
|
public function getLabel(): ?string
|
||||||
{
|
{
|
||||||
@ -24,10 +25,24 @@ public function getLabel(): ?string
|
|||||||
self::YOUTUBE => 'Youtube',
|
self::YOUTUBE => 'Youtube',
|
||||||
self::FACEBOOK => 'Facebook',
|
self::FACEBOOK => 'Facebook',
|
||||||
self::INSTAGRAM => 'Instagram',
|
self::INSTAGRAM => 'Instagram',
|
||||||
|
self::TWITTER => 'Twitter',
|
||||||
self::OTHER => 'Other',
|
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
|
public static function options(): array
|
||||||
{
|
{
|
||||||
return collect(self::cases())
|
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
|
public static function options(): array
|
||||||
{
|
{
|
||||||
return collect(self::cases())
|
return collect(self::cases())
|
||||||
|
|||||||
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Filament\Exports;
|
namespace App\Filament\Exports;
|
||||||
|
|
||||||
use App\Enums\Channel;
|
|
||||||
use App\Enums\SocialMedia;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||||
use Maatwebsite\Excel\Events\AfterSheet;
|
use Maatwebsite\Excel\Events\AfterSheet;
|
||||||
@ -28,11 +26,11 @@ public function setUp()
|
|||||||
|
|
||||||
Column::make('channel')
|
Column::make('channel')
|
||||||
->heading('Kanal')
|
->heading('Kanal')
|
||||||
->formatStateUsing(fn ($state) => Channel::tryFrom($state)?->getLabel() ?? $state),
|
->formatStateUsing(fn ($state) => $state->getLabel()),
|
||||||
|
|
||||||
Column::make('social_media')
|
Column::make('social_media')
|
||||||
->heading('Media Sosial')
|
->heading('Media Sosial')
|
||||||
->formatStateUsing(fn ($state) => SocialMedia::tryFrom($state)?->getLabel() ?? $state),
|
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||||
|
|
||||||
Column::make('classification.name')
|
Column::make('classification.name')
|
||||||
->heading('Klasifikasi'),
|
->heading('Klasifikasi'),
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
use App\Filament\Actions\DefaultBulkActions;
|
use App\Filament\Actions\DefaultBulkActions;
|
||||||
use App\Filament\Columns\TimestampColumns;
|
use App\Filament\Columns\TimestampColumns;
|
||||||
use App\Filament\Exports\ContentRecapExcelExport;
|
use App\Filament\Exports\ContentRecapExcelExport;
|
||||||
|
use App\Models\ContentRecap;
|
||||||
use Filament\Actions\BulkActionGroup;
|
use Filament\Actions\BulkActionGroup;
|
||||||
use Filament\Forms\Components\DatePicker;
|
use Filament\Forms\Components\DatePicker;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
@ -37,15 +38,20 @@ public static function configure(Table $table): Table
|
|||||||
->label('Judul')
|
->label('Judul')
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable()
|
->sortable()
|
||||||
->wrap(),
|
->wrap()
|
||||||
|
->description(fn (ContentRecap $contentRecap): string => $contentRecap->link),
|
||||||
|
|
||||||
TextColumn::make('type')
|
TextColumn::make('type')
|
||||||
->label('Tipe')
|
->label('Tipe')
|
||||||
|
->badge()
|
||||||
|
->color(fn (ContentType $state): string => $state->getColor())
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
TextColumn::make('channel')
|
TextColumn::make('channel')
|
||||||
->label('Kanal')
|
->label('Kanal')
|
||||||
|
->badge()
|
||||||
|
->color(fn (Channel $state): string => $state->getColor())
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
@ -59,11 +65,6 @@ public static function configure(Table $table): Table
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
TextColumn::make('link')
|
|
||||||
->label('Tautan')
|
|
||||||
->searchable()
|
|
||||||
->sortable(),
|
|
||||||
|
|
||||||
TextColumn::make('posting_date')
|
TextColumn::make('posting_date')
|
||||||
->label('Tgl Posting')
|
->label('Tgl Posting')
|
||||||
->searchable()
|
->searchable()
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\Channel;
|
||||||
use App\Enums\ContentType;
|
use App\Enums\ContentType;
|
||||||
|
use App\Enums\SocialMedia;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -21,6 +23,8 @@ protected function casts(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => ContentType::class,
|
'type' => ContentType::class,
|
||||||
|
'channel' => Channel::class,
|
||||||
|
'social_media' => SocialMedia::class,
|
||||||
'posting_date' => 'date',
|
'posting_date' => 'date',
|
||||||
'classification_id' => 'integer',
|
'classification_id' => 'integer',
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user