Andrew Wallo 1年前
父节点
当前提交
94b3993e5a

+ 117
- 0
app/Filament/Company/Pages/Concerns/HasTableColumnToggleForm.php 查看文件

1
+<?php
2
+
3
+namespace App\Filament\Company\Pages\Concerns;
4
+
5
+use App\Support\Column;
6
+use Filament\Actions\Action;
7
+use Filament\Forms\Components\Checkbox;
8
+use Filament\Forms\Form;
9
+use Filament\Support\Enums\ActionSize;
10
+use Filament\Support\Facades\FilamentIcon;
11
+use Illuminate\Support\Arr;
12
+
13
+trait HasTableColumnToggleForm
14
+{
15
+    public array $toggledTableColumns = [];
16
+
17
+    public function mountHasTableColumnToggleForm(): void
18
+    {
19
+        if (! count($this->toggledTableColumns ?? [])) {
20
+            $this->getTableColumnToggleForm()->fill(session()->get(
21
+                $this->getTableColumnToggleFormStateSessionKey(),
22
+                $this->getDefaultTableColumnToggleState()
23
+            ));
24
+        }
25
+    }
26
+
27
+    protected function getDefaultTableColumnToggleState(): array
28
+    {
29
+        $state = [];
30
+
31
+        foreach ($this->getTable() as $column) {
32
+            if (! $column->isToggleable()) {
33
+                continue;
34
+            }
35
+
36
+            data_set($state, $column->getName(), ! $column->isToggledHiddenByDefault());
37
+        }
38
+
39
+        return $state;
40
+    }
41
+
42
+    public function updatedToggledTableColumns(): void
43
+    {
44
+        session()->put([
45
+            $this->getTableColumnToggleFormStateSessionKey() => $this->toggledTableColumns,
46
+        ]);
47
+    }
48
+
49
+    public function getTableColumnToggleForm(): Form
50
+    {
51
+        if ((! $this->isCachingForms) && $this->hasCachedForm('toggleTableColumnForm')) {
52
+            return $this->getForm('toggleTableColumnForm');
53
+        }
54
+
55
+        return $this->makeForm()
56
+            ->schema($this->getTableColumnToggleFormSchema())
57
+            ->statePath('toggledTableColumns')
58
+            ->live();
59
+    }
60
+
61
+    protected function hasToggleableColumns(): bool
62
+    {
63
+        return ! empty($this->getTableColumnToggleFormSchema());
64
+    }
65
+
66
+    /**
67
+     * @return array<Checkbox>
68
+     */
69
+    protected function getTableColumnToggleFormSchema(): array
70
+    {
71
+        $schema = [];
72
+
73
+        foreach ($this->getTable() as $column) {
74
+            if (! $column->isToggleable()) {
75
+                continue;
76
+            }
77
+
78
+            $schema[] = Checkbox::make($column->getName())
79
+                ->label($column->getLabel());
80
+        }
81
+
82
+        return $schema;
83
+    }
84
+
85
+    public function isTableColumnToggledHidden(string $name): bool
86
+    {
87
+        return Arr::has($this->toggledTableColumns, $name) && ! data_get($this->toggledTableColumns, $name);
88
+    }
89
+
90
+    public function getTableColumnToggleFormStateSessionKey(): string
91
+    {
92
+        $table = class_basename($this::class);
93
+
94
+        return "tables.{$table}_toggled_columns";
95
+    }
96
+
97
+    public function getToggleColumnsTriggerAction(): Action
98
+    {
99
+        return Action::make('toggleColumns')
100
+            ->label(__('filament-tables::table.actions.toggle_columns.label'))
101
+            ->iconButton()
102
+            ->size(ActionSize::Large)
103
+            ->icon(FilamentIcon::resolve('tables::actions.toggle-columns') ?? 'heroicon-m-view-columns')
104
+            ->color('gray')
105
+            ->livewireClickHandlerEnabled(false);
106
+    }
107
+
108
+    protected function getToggledColumns(): array
109
+    {
110
+        return array_values(
111
+            array_filter(
112
+                $this->getTable(),
113
+                fn (Column $column) => ! $column->isToggleable() || ($this->toggledTableColumns[$column->getName()] ?? false)
114
+            )
115
+        );
116
+    }
117
+}

+ 0
- 106
app/Filament/Company/Pages/Concerns/HasToggleTableColumnForm.php 查看文件

1
-<?php
2
-
3
-namespace App\Filament\Company\Pages\Concerns;
4
-
5
-use App\Support\Column;
6
-use Filament\Actions\Action;
7
-use Filament\Forms\Components\Checkbox;
8
-use Filament\Forms\Form;
9
-use Filament\Support\Enums\ActionSize;
10
-use Filament\Support\Facades\FilamentIcon;
11
-use Livewire\Attributes\Session;
12
-
13
-trait HasToggleTableColumnForm
14
-{
15
-    #[Session]
16
-    public array $toggledTableColumns = [];
17
-
18
-    public function mountHasToggleTableColumnForm(): void
19
-    {
20
-        $this->loadDefaultTableColumnToggleState();
21
-    }
22
-
23
-    protected function getHasToggleTableColumnFormForms(): array
24
-    {
25
-        return [
26
-            'toggleTableColumnForm' => $this->getToggleTableColumnForm(),
27
-        ];
28
-    }
29
-
30
-    public function getToggleTableColumnForm(): Form
31
-    {
32
-        return $this->toggleTableColumnForm($this->makeForm()
33
-            ->statePath('toggledTableColumns'));
34
-    }
35
-
36
-    public function toggleTableColumnForm(Form $form): Form
37
-    {
38
-        return $form;
39
-    }
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
-
63
-    public function toggleColumnsAction(): Action
64
-    {
65
-        return Action::make('toggleColumns')
66
-            ->label(__('filament-tables::table.actions.toggle_columns.label'))
67
-            ->iconButton()
68
-            ->size(ActionSize::Large)
69
-            ->icon(FilamentIcon::resolve('tables::actions.toggle-columns') ?? 'heroicon-m-view-columns')
70
-            ->color('gray');
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
-    }
106
-}

+ 2
- 9
app/Filament/Company/Pages/Reports/BaseReportPage.php 查看文件

5
 use App\Contracts\ExportableReport;
5
 use App\Contracts\ExportableReport;
6
 use App\DTO\ReportDTO;
6
 use App\DTO\ReportDTO;
7
 use App\Filament\Company\Pages\Concerns\HasDeferredFiltersForm;
7
 use App\Filament\Company\Pages\Concerns\HasDeferredFiltersForm;
8
-use App\Filament\Company\Pages\Concerns\HasToggleTableColumnForm;
8
+use App\Filament\Company\Pages\Concerns\HasTableColumnToggleForm;
9
 use App\Filament\Forms\Components\DateRangeSelect;
9
 use App\Filament\Forms\Components\DateRangeSelect;
10
 use App\Models\Company;
10
 use App\Models\Company;
11
 use App\Services\DateRangeService;
11
 use App\Services\DateRangeService;
14
 use Filament\Actions\ActionGroup;
14
 use Filament\Actions\ActionGroup;
15
 use Filament\Forms\Components\Component;
15
 use Filament\Forms\Components\Component;
16
 use Filament\Forms\Components\DatePicker;
16
 use Filament\Forms\Components\DatePicker;
17
-use Filament\Forms\Form;
18
 use Filament\Forms\Set;
17
 use Filament\Forms\Set;
19
 use Filament\Pages\Page;
18
 use Filament\Pages\Page;
20
 use Filament\Support\Enums\IconPosition;
19
 use Filament\Support\Enums\IconPosition;
26
 abstract class BaseReportPage extends Page
25
 abstract class BaseReportPage extends Page
27
 {
26
 {
28
     use HasDeferredFiltersForm;
27
     use HasDeferredFiltersForm;
29
-    use HasToggleTableColumnForm;
28
+    use HasTableColumnToggleForm;
30
 
29
 
31
     public string $fiscalYearStartDate;
30
     public string $fiscalYearStartDate;
32
 
31
 
118
         return Carbon::parse($this->getFilterState('endDate'))->endOfDay()->toDateTimeString();
117
         return Carbon::parse($this->getFilterState('endDate'))->endOfDay()->toDateTimeString();
119
     }
118
     }
120
 
119
 
121
-    public function toggleTableColumnForm(Form $form): Form
122
-    {
123
-        return $form
124
-            ->schema($this->getTableColumnToggleFormSchema());
125
-    }
126
-
127
     protected function getHeaderActions(): array
120
     protected function getHeaderActions(): array
128
     {
121
     {
129
         return [
122
         return [

+ 17
- 17
composer.lock 查看文件

497
         },
497
         },
498
         {
498
         {
499
             "name": "aws/aws-sdk-php",
499
             "name": "aws/aws-sdk-php",
500
-            "version": "3.321.7",
500
+            "version": "3.321.8",
501
             "source": {
501
             "source": {
502
                 "type": "git",
502
                 "type": "git",
503
                 "url": "https://github.com/aws/aws-sdk-php.git",
503
                 "url": "https://github.com/aws/aws-sdk-php.git",
504
-                "reference": "c64ee32d80ec2ab5d8d6a0b77297c2d69602ef3b"
504
+                "reference": "df456658bdc2ad84a00cf35a7b5af874fdcc7a53"
505
             },
505
             },
506
             "dist": {
506
             "dist": {
507
                 "type": "zip",
507
                 "type": "zip",
508
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c64ee32d80ec2ab5d8d6a0b77297c2d69602ef3b",
509
-                "reference": "c64ee32d80ec2ab5d8d6a0b77297c2d69602ef3b",
508
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/df456658bdc2ad84a00cf35a7b5af874fdcc7a53",
509
+                "reference": "df456658bdc2ad84a00cf35a7b5af874fdcc7a53",
510
                 "shasum": ""
510
                 "shasum": ""
511
             },
511
             },
512
             "require": {
512
             "require": {
589
             "support": {
589
             "support": {
590
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
590
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
591
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
591
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
592
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.321.7"
592
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.321.8"
593
             },
593
             },
594
-            "time": "2024-09-09T18:09:23+00:00"
594
+            "time": "2024-09-10T18:18:03+00:00"
595
         },
595
         },
596
         {
596
         {
597
             "name": "aws/aws-sdk-php-laravel",
597
             "name": "aws/aws-sdk-php-laravel",
2852
         },
2852
         },
2853
         {
2853
         {
2854
             "name": "kirschbaum-development/eloquent-power-joins",
2854
             "name": "kirschbaum-development/eloquent-power-joins",
2855
-            "version": "3.5.7",
2855
+            "version": "3.5.8",
2856
             "source": {
2856
             "source": {
2857
                 "type": "git",
2857
                 "type": "git",
2858
                 "url": "https://github.com/kirschbaum-development/eloquent-power-joins.git",
2858
                 "url": "https://github.com/kirschbaum-development/eloquent-power-joins.git",
2859
-                "reference": "3f57b398117d97bae4dfd5c37ea0f8f48f296c97"
2859
+                "reference": "397ef08f15ceff48111fd7f57d9f1fd41bf1a453"
2860
             },
2860
             },
2861
             "dist": {
2861
             "dist": {
2862
                 "type": "zip",
2862
                 "type": "zip",
2863
-                "url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/3f57b398117d97bae4dfd5c37ea0f8f48f296c97",
2864
-                "reference": "3f57b398117d97bae4dfd5c37ea0f8f48f296c97",
2863
+                "url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/397ef08f15ceff48111fd7f57d9f1fd41bf1a453",
2864
+                "reference": "397ef08f15ceff48111fd7f57d9f1fd41bf1a453",
2865
                 "shasum": ""
2865
                 "shasum": ""
2866
             },
2866
             },
2867
             "require": {
2867
             "require": {
2908
             ],
2908
             ],
2909
             "support": {
2909
             "support": {
2910
                 "issues": "https://github.com/kirschbaum-development/eloquent-power-joins/issues",
2910
                 "issues": "https://github.com/kirschbaum-development/eloquent-power-joins/issues",
2911
-                "source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/3.5.7"
2911
+                "source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/3.5.8"
2912
             },
2912
             },
2913
-            "time": "2024-06-26T13:09:29+00:00"
2913
+            "time": "2024-09-10T10:28:05+00:00"
2914
         },
2914
         },
2915
         {
2915
         {
2916
             "name": "knplabs/knp-snappy",
2916
             "name": "knplabs/knp-snappy",
4365
         },
4365
         },
4366
         {
4366
         {
4367
             "name": "matomo/device-detector",
4367
             "name": "matomo/device-detector",
4368
-            "version": "6.3.2",
4368
+            "version": "6.4.0",
4369
             "source": {
4369
             "source": {
4370
                 "type": "git",
4370
                 "type": "git",
4371
                 "url": "https://github.com/matomo-org/device-detector.git",
4371
                 "url": "https://github.com/matomo-org/device-detector.git",
4372
-                "reference": "fd4042cb6a7f3f985a81aedc075dd59e0b991a51"
4372
+                "reference": "05dca429cfe7b6a59947a0d449dbeb60cddc02f2"
4373
             },
4373
             },
4374
             "dist": {
4374
             "dist": {
4375
                 "type": "zip",
4375
                 "type": "zip",
4376
-                "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/fd4042cb6a7f3f985a81aedc075dd59e0b991a51",
4377
-                "reference": "fd4042cb6a7f3f985a81aedc075dd59e0b991a51",
4376
+                "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/05dca429cfe7b6a59947a0d449dbeb60cddc02f2",
4377
+                "reference": "05dca429cfe7b6a59947a0d449dbeb60cddc02f2",
4378
                 "shasum": ""
4378
                 "shasum": ""
4379
             },
4379
             },
4380
             "require": {
4380
             "require": {
4430
                 "source": "https://github.com/matomo-org/matomo",
4430
                 "source": "https://github.com/matomo-org/matomo",
4431
                 "wiki": "https://dev.matomo.org/"
4431
                 "wiki": "https://dev.matomo.org/"
4432
             },
4432
             },
4433
-            "time": "2024-05-28T10:16:19+00:00"
4433
+            "time": "2024-09-10T08:27:24+00:00"
4434
         },
4434
         },
4435
         {
4435
         {
4436
             "name": "monolog/monolog",
4436
             "name": "monolog/monolog",

+ 6
- 6
package-lock.json 查看文件

998
             }
998
             }
999
         },
999
         },
1000
         "node_modules/caniuse-lite": {
1000
         "node_modules/caniuse-lite": {
1001
-            "version": "1.0.30001659",
1002
-            "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001659.tgz",
1003
-            "integrity": "sha512-Qxxyfv3RdHAfJcXelgf0hU4DFUVXBGTjqrBUZLUh8AtlGnsDo+CnncYtTd95+ZKfnANUOzxyIQCuU/UeBZBYoA==",
1001
+            "version": "1.0.30001660",
1002
+            "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001660.tgz",
1003
+            "integrity": "sha512-GacvNTTuATm26qC74pt+ad1fW15mlQ/zuTzzY1ZoIzECTP8HURDfF43kNxPgf7H1jmelCBQTTbBNxdSXOA7Bqg==",
1004
             "dev": true,
1004
             "dev": true,
1005
             "funding": [
1005
             "funding": [
1006
                 {
1006
                 {
1159
             "license": "MIT"
1159
             "license": "MIT"
1160
         },
1160
         },
1161
         "node_modules/electron-to-chromium": {
1161
         "node_modules/electron-to-chromium": {
1162
-            "version": "1.5.18",
1163
-            "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.18.tgz",
1164
-            "integrity": "sha512-1OfuVACu+zKlmjsNdcJuVQuVE61sZOLbNM4JAQ1Rvh6EOj0/EUKhMJjRH73InPlXSh8HIJk1cVZ8pyOV/FMdUQ==",
1162
+            "version": "1.5.19",
1163
+            "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.19.tgz",
1164
+            "integrity": "sha512-kpLJJi3zxTR1U828P+LIUDZ5ohixyo68/IcYOHLqnbTPr/wdgn4i1ECvmALN9E16JPA6cvCG5UG79gVwVdEK5w==",
1165
             "dev": true,
1165
             "dev": true,
1166
             "license": "ISC"
1166
             "license": "ISC"
1167
         },
1167
         },

+ 2
- 2
resources/views/filament/company/pages/reports/detailed-report.blade.php 查看文件

9
             <!-- Grouping Button and Column Toggle -->
9
             <!-- Grouping Button and Column Toggle -->
10
             @if($this->hasToggleableColumns())
10
             @if($this->hasToggleableColumns())
11
                 <x-filament-tables::column-toggle.dropdown
11
                 <x-filament-tables::column-toggle.dropdown
12
-                    :form="$this->toggleTableColumnForm"
13
-                    :trigger-action="$this->toggleColumnsAction"
12
+                    :form="$this->getTableColumnToggleForm()"
13
+                    :trigger-action="$this->getToggleColumnsTriggerAction()"
14
                 />
14
                 />
15
             @endif
15
             @endif
16
 
16
 

+ 2
- 2
resources/views/filament/company/pages/reports/income-statement.blade.php 查看文件

9
             <!-- Grouping Button and Column Toggle -->
9
             <!-- Grouping Button and Column Toggle -->
10
             @if($this->hasToggleableColumns())
10
             @if($this->hasToggleableColumns())
11
                 <x-filament-tables::column-toggle.dropdown
11
                 <x-filament-tables::column-toggle.dropdown
12
-                    :form="$this->toggleTableColumnForm"
13
-                    :trigger-action="$this->toggleColumnsAction"
12
+                    :form="$this->getTableColumnToggleForm()"
13
+                    :trigger-action="$this->getToggleColumnsTriggerAction()"
14
                 />
14
                 />
15
             @endif
15
             @endif
16
 
16
 

正在加载...
取消
保存