feat: Conditionally render cooperation table filters based on user role and set the status filter to non-native.
This commit is contained in:
parent
9a63d33991
commit
c4347f980e
@ -141,115 +141,120 @@ public static function configure(Table $table): Table
|
||||
|
||||
...TimestampColumns::make(),
|
||||
])
|
||||
->filters([
|
||||
TrashedFilter::make()
|
||||
->native(false)
|
||||
->visible(fn (): bool => auth()->user()?->hasRole(RoleEnum::DEVELOPER->value)),
|
||||
->filters(
|
||||
auth()->user()->hasRole(RoleEnum::DEVELOPER->value) || auth()->user()->hasRole(RoleEnum::ADMINISTRATOR->value)
|
||||
? [
|
||||
TrashedFilter::make()
|
||||
->native(false)
|
||||
->visible(fn (): bool => auth()->user()?->hasRole(RoleEnum::DEVELOPER->value)),
|
||||
|
||||
SelectFilter::make('status')
|
||||
->label('Status')
|
||||
->options(CooperationStatus::class),
|
||||
SelectFilter::make('status')
|
||||
->label('Status')
|
||||
->options(CooperationStatus::class)
|
||||
->native(false),
|
||||
|
||||
SelectFilter::make('partnerMedia')
|
||||
->label('Media')
|
||||
->relationship('partnerMedia', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
SelectFilter::make('partnerMedia')
|
||||
->label('Media')
|
||||
->relationship('partnerMedia', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
|
||||
Filter::make('title')
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label('Nama Kegiatan')
|
||||
->placeholder('Cari nama kegiatan...'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$data['title'],
|
||||
fn (Builder $query, $title): Builder => $query->where('title', 'like', "%{$title}%"),
|
||||
);
|
||||
}),
|
||||
|
||||
Filter::make('date_filter')
|
||||
->schema([
|
||||
Select::make('date_type')
|
||||
->label('Jenis Filter Tanggal')
|
||||
->options([
|
||||
'date' => 'Tanggal Penyerahan Awal',
|
||||
'month' => 'Bulan & Tahun',
|
||||
'year' => 'Tahun',
|
||||
'range' => 'Rentang Tanggal',
|
||||
Filter::make('title')
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label('Nama Kegiatan')
|
||||
->placeholder('Cari nama kegiatan...'),
|
||||
])
|
||||
->live()
|
||||
->native(false),
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$data['title'],
|
||||
fn (Builder $query, $title): Builder => $query->where('title', 'like', "%{$title}%"),
|
||||
);
|
||||
}),
|
||||
|
||||
DatePicker::make('specific_date')
|
||||
->label('Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'date')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
Filter::make('date_filter')
|
||||
->schema([
|
||||
Select::make('date_type')
|
||||
->label('Jenis Filter Tanggal')
|
||||
->options([
|
||||
'date' => 'Tanggal Penyerahan Awal',
|
||||
'month' => 'Bulan & Tahun',
|
||||
'year' => 'Tahun',
|
||||
'range' => 'Rentang Tanggal',
|
||||
])
|
||||
->live()
|
||||
->native(false),
|
||||
|
||||
Select::make('month')
|
||||
->label('Bulan')
|
||||
->options([
|
||||
1 => 'Januari',
|
||||
2 => 'Februari',
|
||||
3 => 'Maret',
|
||||
4 => 'April',
|
||||
5 => 'Mei',
|
||||
6 => 'Juni',
|
||||
7 => 'Juli',
|
||||
8 => 'Agustus',
|
||||
9 => 'September',
|
||||
10 => 'Oktober',
|
||||
11 => 'November',
|
||||
12 => 'Desember',
|
||||
DatePicker::make('specific_date')
|
||||
->label('Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'date')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
Select::make('month')
|
||||
->label('Bulan')
|
||||
->options([
|
||||
1 => 'Januari',
|
||||
2 => 'Februari',
|
||||
3 => 'Maret',
|
||||
4 => 'April',
|
||||
5 => 'Mei',
|
||||
6 => 'Juni',
|
||||
7 => 'Juli',
|
||||
8 => 'Agustus',
|
||||
9 => 'September',
|
||||
10 => 'Oktober',
|
||||
11 => 'November',
|
||||
12 => 'Desember',
|
||||
])
|
||||
->visible(fn (Get $get) => $get('date_type') === 'month')
|
||||
->native(false),
|
||||
|
||||
Select::make('year')
|
||||
->label('Tahun')
|
||||
->options(function () {
|
||||
$years = range(date('Y'), 2020);
|
||||
|
||||
return array_combine($years, $years);
|
||||
})
|
||||
->visible(fn (Get $get) => in_array($get('date_type'), ['month', 'year']))
|
||||
->native(false),
|
||||
|
||||
DatePicker::make('start_date')
|
||||
->label('Mulai Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'range')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
DatePicker::make('end_date')
|
||||
->label('Sampai Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'range')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
])
|
||||
->visible(fn (Get $get) => $get('date_type') === 'month')
|
||||
->native(false),
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
$type = $data['date_type'] ?? null;
|
||||
$column = 'initial_submission_date';
|
||||
|
||||
Select::make('year')
|
||||
->label('Tahun')
|
||||
->options(function () {
|
||||
$years = range(date('Y'), 2020);
|
||||
if ($type === 'date' && ! empty($data['specific_date'])) {
|
||||
return $query->whereDate($column, $data['specific_date']);
|
||||
}
|
||||
if ($type === 'month' && ! empty($data['month']) && ! empty($data['year'])) {
|
||||
return $query->whereMonth($column, $data['month'])
|
||||
->whereYear($column, $data['year']);
|
||||
}
|
||||
if ($type === 'year' && ! empty($data['year'])) {
|
||||
return $query->whereYear($column, $data['year']);
|
||||
}
|
||||
if ($type === 'range' && ! empty($data['start_date']) && ! empty($data['end_date'])) {
|
||||
return $query->whereBetween($column, [$data['start_date'], $data['end_date']]);
|
||||
}
|
||||
|
||||
return array_combine($years, $years);
|
||||
})
|
||||
->visible(fn (Get $get) => in_array($get('date_type'), ['month', 'year']))
|
||||
->native(false),
|
||||
|
||||
DatePicker::make('start_date')
|
||||
->label('Mulai Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'range')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
DatePicker::make('end_date')
|
||||
->label('Sampai Tanggal')
|
||||
->visible(fn (Get $get) => $get('date_type') === 'range')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
$type = $data['date_type'] ?? null;
|
||||
$column = 'initial_submission_date';
|
||||
|
||||
if ($type === 'date' && ! empty($data['specific_date'])) {
|
||||
return $query->whereDate($column, $data['specific_date']);
|
||||
}
|
||||
if ($type === 'month' && ! empty($data['month']) && ! empty($data['year'])) {
|
||||
return $query->whereMonth($column, $data['month'])
|
||||
->whereYear($column, $data['year']);
|
||||
}
|
||||
if ($type === 'year' && ! empty($data['year'])) {
|
||||
return $query->whereYear($column, $data['year']);
|
||||
}
|
||||
if ($type === 'range' && ! empty($data['start_date']) && ! empty($data['end_date'])) {
|
||||
return $query->whereBetween($column, [$data['start_date'], $data['end_date']]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}),
|
||||
], FiltersLayout::AboveContentCollapsible)
|
||||
return $query;
|
||||
}),
|
||||
] : [],
|
||||
FiltersLayout::AboveContentCollapsible
|
||||
)
|
||||
->filtersFormColumns(3)
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
@ -266,18 +271,17 @@ public static function configure(Table $table): Table
|
||||
|
||||
CompleteCooperationAction::make('completeCooperation'),
|
||||
|
||||
EditAction::make()
|
||||
->visible(fn (): bool => ! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)),
|
||||
EditAction::make(),
|
||||
|
||||
DeleteAction::make()
|
||||
->visible(fn (): bool => ! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->headerActions([
|
||||
ExportAction::make()
|
||||
->exports([
|
||||
CooperationExcelExport::make(),
|
||||
])
|
||||
->color('success'),
|
||||
->color('success')
|
||||
->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER->value) || auth()->user()->hasRole(RoleEnum::ADMINISTRATOR->value)),
|
||||
|
||||
])
|
||||
->toolbarActions([
|
||||
|
||||
@ -693,15 +693,6 @@ public function run(): void
|
||||
"permissions": [
|
||||
"ViewAny:Cooperation",
|
||||
"View:Cooperation",
|
||||
"Create:Cooperation",
|
||||
"Update:Cooperation",
|
||||
"Delete:Cooperation",
|
||||
"Restore:Cooperation",
|
||||
"ForceDelete:Cooperation",
|
||||
"ForceDeleteAny:Cooperation",
|
||||
"RestoreAny:Cooperation",
|
||||
"Replicate:Cooperation",
|
||||
"Reorder:Cooperation",
|
||||
|
||||
"View:Company",
|
||||
|
||||
@ -709,15 +700,6 @@ public function run(): void
|
||||
|
||||
"ViewAny:DataChangeRequest",
|
||||
"View:DataChangeRequest",
|
||||
"Create:DataChangeRequest",
|
||||
"Update:DataChangeRequest",
|
||||
"Delete:DataChangeRequest",
|
||||
"Restore:DataChangeRequest",
|
||||
"ForceDelete:DataChangeRequest",
|
||||
"ForceDeleteAny:DataChangeRequest",
|
||||
"RestoreAny:DataChangeRequest",
|
||||
"Replicate:DataChangeRequest",
|
||||
"Reorder:DataChangeRequest",
|
||||
|
||||
"ViewAny:Journalist",
|
||||
"View:Journalist",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user