Andrew Wallo пре 1 година
родитељ
комит
49a5a2566a

+ 67
- 0
app/Filament/Company/Pages/Concerns/HasToggleTableColumnForm.php Прегледај датотеку

@@ -2,13 +2,24 @@
2 2
 
3 3
 namespace App\Filament\Company\Pages\Concerns;
4 4
 
5
+use App\Support\Column;
5 6
 use Filament\Actions\Action;
7
+use Filament\Forms\Components\Checkbox;
6 8
 use Filament\Forms\Form;
7 9
 use Filament\Support\Enums\ActionSize;
8 10
 use Filament\Support\Facades\FilamentIcon;
11
+use Livewire\Attributes\Session;
9 12
 
10 13
 trait HasToggleTableColumnForm
11 14
 {
15
+    #[Session]
16
+    public array $toggledTableColumns = [];
17
+
18
+    public function mountHasToggleTableColumnForm(): void
19
+    {
20
+        $this->loadDefaultTableColumnToggleState();
21
+    }
22
+
12 23
     protected function getHasToggleTableColumnFormForms(): array
13 24
     {
14 25
         return [
@@ -27,6 +38,28 @@ trait HasToggleTableColumnForm
27 38
         return $form;
28 39
     }
29 40
 
41
+    protected function hasToggleableColumns(): bool
42
+    {
43
+        return ! empty($this->getTableColumnToggleFormSchema());
44
+    }
45
+
46
+    /**
47
+     * @return array<Checkbox>
48
+     */
49
+    protected function getTableColumnToggleFormSchema(): array
50
+    {
51
+        $schema = [];
52
+
53
+        foreach ($this->getTable() as $column) {
54
+            if ($column->isToggleable()) {
55
+                $schema[] = Checkbox::make($column->getName())
56
+                    ->label($column->getLabel());
57
+            }
58
+        }
59
+
60
+        return $schema;
61
+    }
62
+
30 63
     public function toggleColumnsAction(): Action
31 64
     {
32 65
         return Action::make('toggleColumns')
@@ -36,4 +69,38 @@ trait HasToggleTableColumnForm
36 69
             ->icon(FilamentIcon::resolve('tables::actions.toggle-columns') ?? 'heroicon-m-view-columns')
37 70
             ->color('gray');
38 71
     }
72
+
73
+    protected function loadDefaultTableColumnToggleState(): void
74
+    {
75
+        $tableColumns = $this->getTable();
76
+
77
+        foreach ($tableColumns as $column) {
78
+            $columnName = $column->getName();
79
+
80
+            if (empty($this->toggledTableColumns)) {
81
+                if ($column->isToggleable()) {
82
+                    $this->toggledTableColumns[$columnName] = ! $column->isToggledHiddenByDefault();
83
+                } else {
84
+                    $this->toggledTableColumns[$columnName] = true;
85
+                }
86
+            }
87
+
88
+            // Handle cases where the toggle state needs to be reset
89
+            if (! $column->isToggleable()) {
90
+                $this->toggledTableColumns[$columnName] = true;
91
+            } elseif ($column->isToggleable() && $column->isToggledHiddenByDefault() && isset($this->toggledTableColumns[$columnName]) && $this->toggledTableColumns[$columnName]) {
92
+                $this->toggledTableColumns[$columnName] = false;
93
+            }
94
+        }
95
+    }
96
+
97
+    protected function getToggledColumns(): array
98
+    {
99
+        return array_values(
100
+            array_filter(
101
+                $this->getTable(),
102
+                fn (Column $column) => $this->toggledTableColumns[$column->getName()] ?? false,
103
+            )
104
+        );
105
+    }
39 106
 }

+ 0
- 63
app/Filament/Company/Pages/Reports/BaseReportPage.php Прегледај датотеку

@@ -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 [

+ 3
- 1
resources/views/filament/company/pages/reports/account-transactions.blade.php Прегледај датотеку

@@ -1,6 +1,8 @@
1 1
 <x-filament-panels::page>
2 2
     <x-filament::section>
3
-        {{ $this->getFiltersForm() }}
3
+        @if(method_exists($this, 'filtersForm'))
4
+            {{ $this->filtersForm }}
5
+        @endif
4 6
     </x-filament::section>
5 7
 
6 8
     <x-filament-tables::container>

+ 7
- 4
resources/views/filament/company/pages/reports/detailed-report.blade.php Прегледај датотеку

@@ -2,9 +2,9 @@
2 2
     <x-filament::section>
3 3
         <div class="flex flex-col md:flex-row items-start md:items-center justify-between gap-4 md:gap-8">
4 4
             <!-- Form Container -->
5
-            <div class="flex-grow">
6
-                {{ $this->getFiltersForm() }}
7
-            </div>
5
+            @if(method_exists($this, 'filtersForm'))
6
+                {{ $this->filtersForm }}
7
+            @endif
8 8
 
9 9
             <!-- Grouping Button and Column Toggle -->
10 10
             <div class="flex flex-col md:flex-row items-start md:items-center gap-4 md:gap-8 flex-shrink-0">
@@ -14,7 +14,10 @@
14 14
                         :trigger-action="$this->toggleColumnsAction"
15 15
                     />
16 16
                 @endif
17
-                {{ $this->getFiltersApplyAction() }}
17
+            </div>
18
+
19
+            <div class="inline-flex items-center flex-shrink-0 min-w-[8.5rem] justify-end">
20
+                {{ $this->applyFiltersAction }}
18 21
             </div>
19 22
         </div>
20 23
     </x-filament::section>

Loading…
Откажи
Сачувај