-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableButton.php
More file actions
executable file
·187 lines (163 loc) · 4.25 KB
/
Copy pathTableButton.php
File metadata and controls
executable file
·187 lines (163 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
declare(strict_types=1);
/*
* This file is part of the Alight package.
*
* (c) June So <june@alight.cc>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alight\Admin;
use Alight\Admin;
class TableButton
{
/**
* Define the configuration index
*
*/
public function __construct(private readonly int $index, string $form)
{
$defaultUrl = '';
if ($_SERVER['REQUEST_URI'] ?? '') {
$defaultUrl = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')) . '/form';
}
Table::$config['button'][$this->index] = [
'form' => $form,
'title' => $form,
'url' => $defaultUrl ?: Admin::url(),
'action' => 'form',
'place' => '_column',
];
}
/**
* Set click action
*
* @param string $value Table::ACTION_*
*/
public function action(string $value): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $value;
return $this;
}
/**
* Put in the batch bar
*
*/
public function batch(): static
{
Table::$config['button'][$this->index]['place'] = '_' . __FUNCTION__;
Table::$config['button'][$this->index]['action'] = 'confirm';
return $this;
}
/**
* Set color
*
* @param string $color Table::COLOR_*
*/
public function color(string $color): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $color;
return $this;
}
/**
* Put in the specified column (Create _column column by default)
*
*/
public function column(string $columnKey = '_column'): static
{
if ($columnKey) {
if ($columnKey !== '_column') {
$columnKey = '_column_' . $columnKey;
}
Table::$config['button'][$this->index]['place'] = $columnKey;
}
return $this;
}
/**
* Put in the specified expand column (Create _expand column by default)
*
*/
public function expand(string $columnKey = '_expand'): static
{
if ($columnKey) {
if ($columnKey !== '_expand') {
$columnKey = '_expand_' . $columnKey;
}
Table::$config['button'][$this->index]['place'] = $columnKey;
}
return $this;
}
/**
* Set display conditions
*
* @param array<string, mixed> $keyValues
*/
public function if(array $keyValues): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $keyValues;
return $this;
}
/**
* Set request parameters
*
* @param array<string, mixed> $keyValues Use {{column_key}} placeholders for column data.
*/
public function param(array $keyValues): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $keyValues;
return $this;
}
/**
* Which role has permission to view
*
* @param list<int> $roleValues
*/
public function role(array $roleValues): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $roleValues;
return $this;
}
/**
* Set title
*
*/
public function title(string $value): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $value;
if (str_starts_with($value, ':')) {
Table::$config['button'][$this->index]['locale'] = true;
}
return $this;
}
/**
* Put in the toolbar
*
*/
public function toolbar(): static
{
Table::$config['button'][$this->index]['place'] = '_' . __FUNCTION__;
return $this;
}
/**
* Set url
*
*/
public function url(string $value): static
{
Table::$config['button'][$this->index][__FUNCTION__] = Admin::url($value);
return $this;
}
/**
* Set variant
*
* @param string $value Table::VARIANT_*
*
* @see https://ant.design/components/button/
*/
public function variant(string $value): static
{
Table::$config['button'][$this->index][__FUNCTION__] = $value;
return $this;
}
}