feat: add Analytic dashboard with filters and reset action for enhanced data analysis capabilities
This commit is contained in:
parent
25d360983b
commit
c44719efa4
27
app/Filament/Pages/Analytic/Actions/ResetFiltersAction.php
Normal file
27
app/Filament/Pages/Analytic/Actions/ResetFiltersAction.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages\Analytic\Actions;
|
||||||
|
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
|
||||||
|
class ResetFiltersAction extends Action
|
||||||
|
{
|
||||||
|
public static function getDefaultName(): ?string
|
||||||
|
{
|
||||||
|
return 'reset';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->label('Reset Filter')
|
||||||
|
->color('danger')
|
||||||
|
->action(fn ($livewire) => $livewire->resetFilters())
|
||||||
|
->visible(function ($livewire): bool {
|
||||||
|
$filters = $livewire->filters ?? [];
|
||||||
|
|
||||||
|
return ! empty($filters['startDate']) || ! empty($filters['endDate']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages\Analytic;
|
||||||
|
|
||||||
use App\Enums\RoleEnum;
|
use App\Filament\Pages\Analytic\Actions\ResetFiltersAction;
|
||||||
|
use App\Filament\Pages\Analytic\Schemas\AnalyticFiltersForm;
|
||||||
use App\Filament\Widgets\Charts\BudgetRealizationChart;
|
use App\Filament\Widgets\Charts\BudgetRealizationChart;
|
||||||
use App\Filament\Widgets\Charts\CompanyStatusChart;
|
use App\Filament\Widgets\Charts\CompanyStatusChart;
|
||||||
use App\Filament\Widgets\Charts\CooperationStatusChart;
|
use App\Filament\Widgets\Charts\CooperationStatusChart;
|
||||||
@ -22,19 +23,16 @@
|
|||||||
use App\Filament\Widgets\Charts\VisitorTrafficChart;
|
use App\Filament\Widgets\Charts\VisitorTrafficChart;
|
||||||
use BackedEnum;
|
use BackedEnum;
|
||||||
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
||||||
use Filament\Actions\Action;
|
|
||||||
use Filament\Forms\Components\DatePicker;
|
|
||||||
use Filament\Pages\Dashboard as BaseDashboard;
|
use Filament\Pages\Dashboard as BaseDashboard;
|
||||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||||
use Filament\Schemas\Components\Fieldset;
|
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Support\Icons\Heroicon;
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
|
||||||
class Analytic extends BaseDashboard
|
class Index extends BaseDashboard
|
||||||
{
|
{
|
||||||
use HasFiltersForm, HasPageShield;
|
use HasFiltersForm, HasPageShield;
|
||||||
|
|
||||||
protected static string $routePath = '/analytic';
|
protected static string $routePath = 'analytic';
|
||||||
|
|
||||||
protected static ?string $slug = 'analytic';
|
protected static ?string $slug = 'analytic';
|
||||||
|
|
||||||
@ -48,6 +46,11 @@ class Analytic extends BaseDashboard
|
|||||||
|
|
||||||
protected static ?string $pollingInterval = null;
|
protected static ?string $pollingInterval = null;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->can('View:Analytic');
|
||||||
|
}
|
||||||
|
|
||||||
public function getColumns(): int|array
|
public function getColumns(): int|array
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
@ -55,37 +58,13 @@ public function getColumns(): int|array
|
|||||||
|
|
||||||
public function filtersForm(Schema $schema): Schema
|
public function filtersForm(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return $schema
|
return AnalyticFiltersForm::configure($schema);
|
||||||
->schema([
|
|
||||||
Fieldset::make('Filter')
|
|
||||||
->schema([
|
|
||||||
DatePicker::make('startDate')
|
|
||||||
->label('Tanggal Mulai')
|
|
||||||
->placeholder('Pilih tanggal mulai')
|
|
||||||
->native(false)
|
|
||||||
->displayFormat('l, d F Y'),
|
|
||||||
|
|
||||||
DatePicker::make('endDate')
|
|
||||||
->label('Tanggal Selesai')
|
|
||||||
->placeholder('Pilih tanggal selesai')
|
|
||||||
->native(false)
|
|
||||||
->displayFormat('l, d F Y'),
|
|
||||||
])
|
|
||||||
->columns(2)
|
|
||||||
->columnSpanFull()
|
|
||||||
->visible(fn () => auth()->user()->hasRole(RoleEnum::DEVELOPER->value) || auth()->user()->hasRole(RoleEnum::ADMINISTRATOR->value)),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('reset')
|
ResetFiltersAction::make(),
|
||||||
->label('Reset Filter')
|
|
||||||
->icon(Heroicon::OutlinedXMark)
|
|
||||||
->color('danger')
|
|
||||||
->action(fn () => $this->resetFilters())
|
|
||||||
->visible(fn () => ! empty($this->filters['startDate']) || ! empty($this->filters['endDate'])),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
35
app/Filament/Pages/Analytic/Schemas/AnalyticFiltersForm.php
Normal file
35
app/Filament/Pages/Analytic/Schemas/AnalyticFiltersForm.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages\Analytic\Schemas;
|
||||||
|
|
||||||
|
use App\Enums\RoleEnum;
|
||||||
|
use Filament\Forms\Components\DatePicker;
|
||||||
|
use Filament\Schemas\Components\Fieldset;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class AnalyticFiltersForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->schema([
|
||||||
|
Fieldset::make('Filter')
|
||||||
|
->schema([
|
||||||
|
DatePicker::make('startDate')
|
||||||
|
->label('Tanggal Mulai')
|
||||||
|
->placeholder('Pilih tanggal mulai')
|
||||||
|
->native(false)
|
||||||
|
->displayFormat('l, d F Y'),
|
||||||
|
|
||||||
|
DatePicker::make('endDate')
|
||||||
|
->label('Tanggal Selesai')
|
||||||
|
->placeholder('Pilih tanggal selesai')
|
||||||
|
->native(false)
|
||||||
|
->displayFormat('l, d F Y'),
|
||||||
|
])
|
||||||
|
->columns(2)
|
||||||
|
->columnSpanFull()
|
||||||
|
->visible(fn () => auth()->user()?->hasRole(RoleEnum::DEVELOPER->value) || auth()->user()?->hasRole(RoleEnum::ADMINISTRATOR->value)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user