|
@@ -12,7 +12,6 @@ use App\Services\DateRangeService;
|
12
|
12
|
use App\Support\Column;
|
13
|
13
|
use Filament\Actions\Action;
|
14
|
14
|
use Filament\Actions\ActionGroup;
|
15
|
|
-use Filament\Forms\Components\Checkbox;
|
16
|
15
|
use Filament\Forms\Components\Component;
|
17
|
16
|
use Filament\Forms\Components\DatePicker;
|
18
|
17
|
use Filament\Forms\Form;
|
|
@@ -22,7 +21,6 @@ use Filament\Support\Enums\IconPosition;
|
22
|
21
|
use Filament\Support\Enums\IconSize;
|
23
|
22
|
use Illuminate\Support\Carbon;
|
24
|
23
|
use Livewire\Attributes\Computed;
|
25
|
|
-use Livewire\Attributes\Session;
|
26
|
24
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
27
|
25
|
|
28
|
26
|
abstract class BaseReportPage extends Page
|
|
@@ -38,9 +36,6 @@ abstract class BaseReportPage extends Page
|
38
|
36
|
|
39
|
37
|
public bool $reportLoaded = false;
|
40
|
38
|
|
41
|
|
- #[Session]
|
42
|
|
- public array $toggledTableColumns = [];
|
43
|
|
-
|
44
|
39
|
abstract protected function buildReport(array $columns): ReportDTO;
|
45
|
40
|
|
46
|
41
|
abstract public function exportCSV(): StreamedResponse;
|
|
@@ -59,8 +54,6 @@ abstract class BaseReportPage extends Page
|
59
|
54
|
$this->initializeProperties();
|
60
|
55
|
|
61
|
56
|
$this->loadDefaultDateRange();
|
62
|
|
-
|
63
|
|
- $this->loadDefaultTableColumnToggleState();
|
64
|
57
|
}
|
65
|
58
|
|
66
|
59
|
protected function initializeProperties(): void
|
|
@@ -91,45 +84,11 @@ abstract class BaseReportPage extends Page
|
91
|
84
|
$this->reportLoaded = true;
|
92
|
85
|
}
|
93
|
86
|
|
94
|
|
- protected function loadDefaultTableColumnToggleState(): void
|
95
|
|
- {
|
96
|
|
- $tableColumns = $this->getTable();
|
97
|
|
-
|
98
|
|
- foreach ($tableColumns as $column) {
|
99
|
|
- $columnName = $column->getName();
|
100
|
|
-
|
101
|
|
- if (empty($this->toggledTableColumns)) {
|
102
|
|
- if ($column->isToggleable()) {
|
103
|
|
- $this->toggledTableColumns[$columnName] = ! $column->isToggledHiddenByDefault();
|
104
|
|
- } else {
|
105
|
|
- $this->toggledTableColumns[$columnName] = true;
|
106
|
|
- }
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
- // Handle cases where the toggle state needs to be reset
|
110
|
|
- if (! $column->isToggleable()) {
|
111
|
|
- $this->toggledTableColumns[$columnName] = true;
|
112
|
|
- } elseif ($column->isToggleable() && $column->isToggledHiddenByDefault() && isset($this->toggledTableColumns[$columnName]) && $this->toggledTableColumns[$columnName]) {
|
113
|
|
- $this->toggledTableColumns[$columnName] = false;
|
114
|
|
- }
|
115
|
|
- }
|
116
|
|
- }
|
117
|
|
-
|
118
|
87
|
public function getDefaultDateRange(): string
|
119
|
88
|
{
|
120
|
89
|
return 'FY-' . now()->year;
|
121
|
90
|
}
|
122
|
91
|
|
123
|
|
- protected function getToggledColumns(): array
|
124
|
|
- {
|
125
|
|
- return array_values(
|
126
|
|
- array_filter(
|
127
|
|
- $this->getTable(),
|
128
|
|
- fn (Column $column) => $this->toggledTableColumns[$column->getName()] ?? false,
|
129
|
|
- )
|
130
|
|
- );
|
131
|
|
- }
|
132
|
|
-
|
133
|
92
|
#[Computed(persist: true)]
|
134
|
93
|
public function report(): ?ExportableReport
|
135
|
94
|
{
|
|
@@ -165,28 +124,6 @@ abstract class BaseReportPage extends Page
|
165
|
124
|
->schema($this->getTableColumnToggleFormSchema());
|
166
|
125
|
}
|
167
|
126
|
|
168
|
|
- protected function hasToggleableColumns(): bool
|
169
|
|
- {
|
170
|
|
- return ! empty($this->getTableColumnToggleFormSchema());
|
171
|
|
- }
|
172
|
|
-
|
173
|
|
- /**
|
174
|
|
- * @return array<Checkbox>
|
175
|
|
- */
|
176
|
|
- protected function getTableColumnToggleFormSchema(): array
|
177
|
|
- {
|
178
|
|
- $schema = [];
|
179
|
|
-
|
180
|
|
- foreach ($this->getTable() as $column) {
|
181
|
|
- if ($column->isToggleable()) {
|
182
|
|
- $schema[] = Checkbox::make($column->getName())
|
183
|
|
- ->label($column->getLabel());
|
184
|
|
- }
|
185
|
|
- }
|
186
|
|
-
|
187
|
|
- return $schema;
|
188
|
|
- }
|
189
|
|
-
|
190
|
127
|
protected function getHeaderActions(): array
|
191
|
128
|
{
|
192
|
129
|
return [
|