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