|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace InertiaDashboardKit\Adapt\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Collection; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractAction |
|
11
|
|
|
{ |
|
12
|
|
|
protected string $label = ''; |
|
13
|
|
|
protected ?string $icon = null; |
|
14
|
|
|
protected array $actionProps = []; |
|
15
|
|
|
|
|
16
|
|
|
abstract public static function name(): string; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->label = __(Str::ucfirst(static::name())); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function allowedForRequest(Request $request): bool |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
return true; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function setLabel(string $label): static |
|
29
|
|
|
{ |
|
30
|
|
|
$this->label = $label; |
|
31
|
|
|
|
|
32
|
|
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function setIcon(?string $icon = null): static |
|
36
|
|
|
{ |
|
37
|
|
|
$this->icon = $icon; |
|
38
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function toArray(): array |
|
43
|
|
|
{ |
|
44
|
|
|
return array_merge([ |
|
45
|
|
|
'name' => static::name(), |
|
46
|
|
|
'label' => $this->label, |
|
47
|
|
|
'icon' => $this->icon, |
|
48
|
|
|
'component' => $this->component(), |
|
49
|
|
|
], $this->actionProps()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function handle(EloquentCollection|Collection $collection, Request $request): array|null |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return null; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public static function responseSuccess(?string $message = null): array |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
'type' => 'success', |
|
61
|
|
|
'message' => $message ?? __('Action executed'), |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public static function responseWarning(?string $message = null): array |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
'type' => 'warning', |
|
69
|
|
|
'message' => $message ?? __('Action executed'), |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public static function responseError(?string $message = null): array |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
'type' => 'error', |
|
77
|
|
|
'message' => $message ?? __('Action executed'), |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public static function responseDownload(string $url, ?string $name = null): array |
|
82
|
|
|
{ |
|
83
|
|
|
return [ |
|
84
|
|
|
'type' => 'download', |
|
85
|
|
|
'url' => $url, |
|
86
|
|
|
'name' => $name ?: Str::afterLast($url, '/'), |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public static function responseInfo(?string $message = null): array |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
|
|
'type' => 'info', |
|
94
|
|
|
'message' => $message ?? __('Action executed'), |
|
95
|
|
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
protected function component(): array |
|
99
|
|
|
{ |
|
100
|
|
|
return [ |
|
101
|
|
|
'index' => 'IndexAction'.Str::ucfirst(Str::camel(static::name())), |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
protected function actionProps(): array |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->actionProps; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.