feat: tambah role editor, workflow post, leaderboard, rekap kehadiran, kategori kas dengan type, seeder lengkap
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\CashCategories\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
@@ -11,6 +12,9 @@ class CashCategoryForm
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Nama')->required(),
|
||||
Select::make('type')->label('Tipe')
|
||||
->options(['pemasukan' => 'Pemasukan', 'pengeluaran' => 'Pengeluaran'])
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ class CashCategoriesTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Nama')->searchable(),
|
||||
TextColumn::make('type')->label('Tipe')
|
||||
->badge()
|
||||
->color(fn ($state) => $state === 'pemasukan' ? 'success' : 'danger')
|
||||
->formatStateUsing(fn ($state) => ucfirst($state)),
|
||||
TextColumn::make('records_count')->counts('records')->label('Transaksi'),
|
||||
])
|
||||
->recordActions([EditAction::make()])
|
||||
|
||||
@@ -16,7 +16,11 @@ class CashRecordForm
|
||||
{
|
||||
return $schema->components([
|
||||
Select::make('category_id')->label('Kategori')
|
||||
->options(CashCategory::pluck('name', 'id'))
|
||||
->options(
|
||||
CashCategory::all()->mapWithKeys(fn ($c) => [
|
||||
$c->id => $c->name . ' (' . ucfirst($c->type) . ')'
|
||||
])
|
||||
)
|
||||
->required(),
|
||||
TextInput::make('amount')->label('Jumlah (Rp)')->numeric()->required()
|
||||
->helperText('< Rp500.000: langsung | Rp500.000–2.000.000: perlu approval ketua | > Rp2.000.000: perlu voting')
|
||||
|
||||
@@ -58,6 +58,11 @@ class CashRecordsTable
|
||||
->filters([
|
||||
SelectFilter::make('category_id')->label('Kategori')
|
||||
->options(CashCategory::pluck('name', 'id')),
|
||||
SelectFilter::make('type')->label('Tipe')
|
||||
->options(['pemasukan' => 'Pemasukan', 'pengeluaran' => 'Pengeluaran'])
|
||||
->query(fn ($query, $state) => $state['value']
|
||||
? $query->whereHas('category', fn ($q) => $q->where('type', $state['value']))
|
||||
: $query),
|
||||
])
|
||||
->recordActions([
|
||||
// Ketua: approve transaksi 500rb–2jt
|
||||
|
||||
@@ -23,7 +23,7 @@ class PostResource extends Resource
|
||||
// Label dinamis sesuai role
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return auth()->user()?->can('ViewAny:Post') && auth()->user()?->can('Update:Post')
|
||||
return auth()->user()?->can('Publish:Post')
|
||||
? 'Artikel'
|
||||
: 'Artikel Saya';
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class PostResource extends Resource
|
||||
{
|
||||
$query = parent::getEloquentQuery();
|
||||
|
||||
if (auth()->user()?->can('Update:Post')) {
|
||||
if (auth()->user()?->can('Publish:Post')) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class PostForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
$isAdmin = auth()->user()?->can('Update:Post');
|
||||
$canReview = auth()->user()?->can('Publish:Post');
|
||||
|
||||
return $schema->components([
|
||||
TextInput::make('title')->label('Judul')->required()
|
||||
@@ -28,7 +28,7 @@ class PostForm
|
||||
])
|
||||
->default('umum')->required(),
|
||||
DateTimePicker::make('published_at')->label('Tanggal Publikasi')
|
||||
->visible($isAdmin)
|
||||
->visible($canReview)
|
||||
->helperText('Kosongkan untuk menyimpan sebagai draft'),
|
||||
RichEditor::make('content')->label('Konten')->required()->columnSpanFull(),
|
||||
]);
|
||||
|
||||
@@ -7,6 +7,7 @@ use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
@@ -16,7 +17,8 @@ class PostsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
$isAdmin = auth()->user()?->can('Update:Post');
|
||||
$canReview = auth()->user()?->can('Publish:Post');
|
||||
$canPublish = auth()->user()?->can('Publish:Post');
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
@@ -30,68 +32,74 @@ class PostsTable
|
||||
TextColumn::make('status')->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'published' => 'success',
|
||||
'approved' => 'info',
|
||||
'pending' => 'warning',
|
||||
'rejected' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => match ($state) {
|
||||
'draft' => 'Draft',
|
||||
'pending' => 'Menunggu',
|
||||
'approved' => 'Disetujui',
|
||||
'published' => 'Diterbitkan',
|
||||
'rejected' => 'Ditolak',
|
||||
default => $state,
|
||||
}),
|
||||
TextColumn::make('author.name')->label('Penulis')->visible($isAdmin),
|
||||
TextColumn::make('rejection_reason')->label('Alasan Penolakan')
|
||||
->limit(40)->default('-')
|
||||
->visible(fn ($record) => $record?->status === 'rejected'),
|
||||
TextColumn::make('author.name')->label('Penulis')->visible($canReview),
|
||||
TextColumn::make('published_at')->label('Dipublikasi')
|
||||
->dateTime('d M Y')->default('-')->sortable(),
|
||||
->dateTime('d M Y')->placeholder('-')->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')->options([
|
||||
'draft' => 'Draft',
|
||||
'pending' => 'Menunggu',
|
||||
'approved' => 'Disetujui',
|
||||
'published' => 'Diterbitkan',
|
||||
'rejected' => 'Ditolak',
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
// Untuk anggota/pengurus/bendahara: ajukan artikel
|
||||
// Member: ajukan artikel
|
||||
Action::make('submit')
|
||||
->label('Ajukan')
|
||||
->icon('heroicon-o-paper-airplane')
|
||||
->color('info')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => ! $isAdmin && in_array($record->status, ['draft', 'rejected']))
|
||||
->visible(fn ($record) => ! $canReview && in_array($record->status, ['draft', 'rejected']))
|
||||
->action(function ($record): void {
|
||||
$record->update(['status' => 'pending', 'rejection_reason' => null]);
|
||||
NotificationService::toRole('ketua', 'Artikel Menunggu Persetujuan',
|
||||
NotificationService::toRole('editor', 'Artikel Menunggu Persetujuan',
|
||||
"\"{$record->title}\" oleh {$record->author->name} menunggu persetujuan.", 'warning',
|
||||
route('filament.admin.resources.posts.edit', $record));
|
||||
}),
|
||||
|
||||
// Untuk admin: approve
|
||||
Action::make('publish')
|
||||
->label('Terbitkan')
|
||||
// Editor: approve
|
||||
Action::make('approve')
|
||||
->label('Setujui')
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
||||
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
||||
->action(fn ($record) => tap($record->update([
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
'reviewed_by' => auth()->id(),
|
||||
'status' => 'approved',
|
||||
'approved_by' => auth()->id(),
|
||||
'approved_at' => now(),
|
||||
'reviewed_by' => auth()->id(),
|
||||
]), fn () => NotificationService::send(
|
||||
$record->author, 'Artikel Diterbitkan',
|
||||
"Artikel \"{$record->title}\" Anda telah diterbitkan.", 'success',
|
||||
$record->author, 'Artikel Disetujui',
|
||||
"Artikel \"{$record->title}\" Anda telah disetujui dan akan segera diterbitkan.", 'success',
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
// Untuk admin: tolak
|
||||
// Editor: tolak
|
||||
Action::make('reject')
|
||||
->label('Tolak')
|
||||
->icon('heroicon-o-x-circle')
|
||||
->color('danger')
|
||||
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
||||
->form([
|
||||
Textarea::make('rejection_reason')->label('Alasan Penolakan')->required(),
|
||||
])
|
||||
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
||||
->form([Textarea::make('rejection_reason')->label('Alasan Penolakan')->required()])
|
||||
->action(fn ($record, array $data) => tap($record->update([
|
||||
'status' => 'rejected',
|
||||
'status' => 'draft',
|
||||
'reviewed_by' => auth()->id(),
|
||||
'rejection_reason' => $data['rejection_reason'],
|
||||
]), fn () => NotificationService::send(
|
||||
@@ -100,8 +108,35 @@ class PostsTable
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
// Editor: publish (approved → published)
|
||||
Action::make('publish')
|
||||
->label('Terbitkan')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->color('success')
|
||||
->visible(fn ($record) => $canPublish && $record->status === 'approved')
|
||||
->form([
|
||||
DateTimePicker::make('published_at')->label('Tanggal Publikasi')
|
||||
->default(now())->required(),
|
||||
])
|
||||
->action(fn ($record, array $data) => $record->update([
|
||||
'status' => 'published',
|
||||
'published_at' => $data['published_at'],
|
||||
])),
|
||||
|
||||
// Editor: unpublish
|
||||
Action::make('unpublish')
|
||||
->label('Batalkan Publikasi')
|
||||
->icon('heroicon-o-eye-slash')
|
||||
->color('warning')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $canPublish && $record->status === 'published')
|
||||
->action(fn ($record) => $record->update([
|
||||
'status' => 'approved',
|
||||
'published_at' => null,
|
||||
])),
|
||||
|
||||
EditAction::make()
|
||||
->visible(fn ($record) => $isAdmin || in_array($record->status, ['draft', 'rejected'])),
|
||||
->visible(fn ($record) => $canReview || in_array($record->status, ['draft', 'rejected'])),
|
||||
])
|
||||
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\RelationManagers;
|
||||
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AttendanceRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'activities';
|
||||
protected static ?string $title = 'Rekap Kehadiran';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')->label('Kegiatan'),
|
||||
TextColumn::make('start_date')->label('Tanggal')->date('d M Y')->sortable(),
|
||||
TextColumn::make('pivot.status')->label('Status')
|
||||
->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'hadir' => 'success',
|
||||
'izin' => 'warning',
|
||||
'alpha' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => ucfirst($state ?? '-')),
|
||||
TextColumn::make('pivot.notes')->label('Catatan')->placeholder('-'),
|
||||
])
|
||||
->defaultSort('activities.start_date', 'desc')
|
||||
->paginated([10, 25]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\Users;
|
||||
use App\Filament\Resources\Users\Pages\CreateUser;
|
||||
use App\Filament\Resources\Users\Pages\EditUser;
|
||||
use App\Filament\Resources\Users\Pages\ListUsers;
|
||||
use App\Filament\Resources\Users\RelationManagers\AttendanceRelationManager;
|
||||
use App\Filament\Resources\Users\Schemas\UserForm;
|
||||
use App\Filament\Resources\Users\Tables\UsersTable;
|
||||
use App\Models\User;
|
||||
@@ -30,6 +31,13 @@ class UserResource extends Resource
|
||||
return UsersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
AttendanceRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user