Skip to content

Commit 5ee4e64

Browse files
commit
1 parent 5e84b26 commit 5ee4e64

File tree

5 files changed

+85
-27
lines changed

5 files changed

+85
-27
lines changed

app/base/abstracts/Controllers/AdminManageModelsPage.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,12 @@ public function __construct(
9595
}
9696

9797
$this->addPaginationSizeSelector();
98-
$this->addNewButton();
9998

10099
$adminTableId = 'listing-'.$layout.'-' . strtolower($this->getUtils()->getClassBasename($this->getObjectClass()));
101100

102-
$controllerClassName = str_replace("\\","\\\\", static::class);
103-
$modelClassName = str_replace("\\","\\\\", $this->getObjectClass());
104-
105101
$itemsPerPage = $this->getItemsPerPage();
106102
$data = $this->getTableItems($itemsPerPage);
107103

108-
if (static::hasMassActions() && !empty($data['items'])) {
109-
$this->addBatchDeleteButton($modelClassName, $adminTableId);
110-
111-
// need to check if there is at least one edit button in the table
112-
$hasEditButton = false;
113-
foreach ($this->getTableElements($data['items']) as $tableElement) {
114-
if (isset($tableElement['actions'][static::EDIT_BTN])) {
115-
$hasEditButton = true;
116-
break;
117-
}
118-
}
119-
120-
if ($hasEditButton) {
121-
$this->addBatchEditButton($controllerClassName, $modelClassName, $adminTableId);
122-
}
123-
}
124-
125104
$tableElements = $this->getTableElements($data['items'], ['layout' => $layout]);
126105

127106
if (static::hasMassActions()) {
@@ -145,6 +124,8 @@ public function __construct(
145124
}
146125

147126
$this->template_data += [
127+
'adminTableId' => $adminTableId,
128+
'data' => $data,
148129
'before_listing' => $this->getBeforeListing(),
149130
'listing' => $tableContents,
150131
'total' => $data['total'],
@@ -153,6 +134,35 @@ public function __construct(
153134
];
154135
}
155136

137+
$this->collectActionButtons();
138+
}
139+
140+
protected function collectActionButtons() : self
141+
{
142+
if (($this->template_data['action'] ?? 'list') == 'list') {
143+
$this->addNewButton();
144+
145+
$controllerClassName = str_replace("\\","\\\\", static::class);
146+
$modelClassName = str_replace("\\","\\\\", $this->getObjectClass());
147+
148+
if (static::hasMassActions() && !empty($this->template_data['data']['items'] ?? null)) {
149+
$this->addBatchDeleteButton($modelClassName, $this->template_data['adminTableId']);
150+
151+
// need to check if there is at least one edit button in the table
152+
$hasEditButton = false;
153+
foreach ($this->getTableElements($this->template_data['data']['items']) as $tableElement) {
154+
if (isset($tableElement['actions'][static::EDIT_BTN])) {
155+
$hasEditButton = true;
156+
break;
157+
}
158+
}
159+
160+
if ($hasEditButton) {
161+
$this->addBatchEditButton($controllerClassName, $modelClassName, $this->template_data['adminTableId']);
162+
}
163+
}
164+
}
165+
156166
if (($this->template_data['action'] ?? 'list') == 'edit') {
157167
if ($this->getEnvironment()->getVariable('ENABLE_VERSIONING') && $this->containerCall([$this->getObject(), 'canSaveVersions'])) {
158168
$this->addVersionsButton($this->getObject());
@@ -165,6 +175,8 @@ public function __construct(
165175
if (($this->template_data['action'] ?? 'list') != 'list') {
166176
$this->addBackButton();
167177
}
178+
179+
return $this;
168180
}
169181

170182
/**

app/base/abstracts/Controllers/AdminManageProductsPage.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,29 @@ protected function getProductTypes(): array
112112
$classes = array_filter(ClassFinder::getClassesInNamespace(App::MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE), fn($modelClass) => is_subclass_of($modelClass, ProductInterface::class));
113113
return array_combine($classes, array_map(fn($class) => strtolower(basename($class)), $classes));
114114
}
115+
116+
protected function collectActionButtons() : self
117+
{
118+
parent::collectActionButtons();
119+
120+
121+
if (($this->template_data['action'] ?? 'list') == 'edit') {
122+
$product = $this->getObject();
123+
if (false && $product instanceof ProductInterface) {
124+
// Add Manage Stock button for physical products
125+
if ($product->isPhysical()) {
126+
$this->addActionLink(
127+
'stock-btn',
128+
'stock-btn',
129+
$this->getUtils()->translate('Manage Stock', locale: $this->getCurrentLocale()),
130+
'#',
131+
'btn btn-sm btn-light inToolSidePanel',
132+
['data-panelWidth' => '80%']
133+
);
134+
}
135+
}
136+
}
137+
138+
return $this;
139+
}
115140
}

app/base/abstracts/Controllers/AdminPage.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,14 @@ public function addBackButton(?array $query_params = null) : void
278278
}
279279
}
280280

281-
$this->addActionLink(static::BACK_BTN, static::BACK_BTN, $this->getHtmlRenderer()->getIcon('rewind') . ' ' . $this->getUtils()->translate('Back', locale: $this->getCurrentLocale()), $this->getControllerUrl() . $query_params, 'btn btn-sm btn-outline-dark');
281+
$this->addActionLink(
282+
static::BACK_BTN,
283+
static::BACK_BTN,
284+
$this->getHtmlRenderer()->getIcon('rewind') . ' ' . $this->getUtils()->translate('Back', locale: $this->getCurrentLocale()),
285+
$this->getControllerUrl() . $query_params,
286+
'btn btn-sm btn-outline-dark',
287+
order: PHP_INT_MAX
288+
);
282289
}
283290

284291
/**

app/base/traits/AdminTrait.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ protected function renderActionButtons(): string
122122
);
123123

124124

125-
foreach ($this->action_buttons as $key => $button_html) {
125+
@uasort($this->action_buttons, function ($a, $b) {
126+
return $a['order'] <=> $b['order'];
127+
});
128+
129+
$action_buttons = array_column($this->action_buttons, 'tag');
130+
131+
foreach ($action_buttons as $key => $button_html) {
126132
$ul->addChild(
127133
$this->containerMake(
128134
TagElement::class,
@@ -178,8 +184,11 @@ protected function renderLayoutButtons(): string
178184
* @param string $button_class
179185
* @return self
180186
*/
181-
public function addActionButton(string $key, string $button_id, string $button_text, $button_class = 'btn btn-sm btn-light') : static
187+
public function addActionButton(string $key, string $button_id, string $button_text, string $button_class = 'btn btn-sm btn-light', array $attributes = [], ?int $order = null) : static
182188
{
189+
if (!is_array($attributes)) {
190+
$attributes = [];
191+
}
183192
$button = $this->containerMake(TagElement::class, ['options' => [
184193
'tag' => 'button',
185194
'id' => $button_id,
@@ -189,7 +198,7 @@ public function addActionButton(string $key, string $button_id, string $button_t
189198
],
190199
'text' => $button_text,
191200
]]);
192-
$this->action_buttons[$key] = $button;
201+
$this->action_buttons[$key] = ['tag' => $button, 'order' => $order ?? PHP_INT_MAX / 2];
193202

194203
return $this;
195204
}
@@ -205,7 +214,7 @@ public function addActionButton(string $key, string $button_id, string $button_t
205214
* @param array $attributes
206215
* @return self
207216
*/
208-
public function addActionLink($key, $link_id, $link_text, $link_href = '#', $link_class = 'btn btn-sm btn-light', $attributes = []) : static
217+
public function addActionLink($key, $link_id, $link_text, $link_href = '#', string $link_class = 'btn btn-sm btn-light', array $attributes = [], ?int $order = null) : static
209218
{
210219
if (!is_array($attributes)) {
211220
$attributes = [];
@@ -221,7 +230,7 @@ public function addActionLink($key, $link_id, $link_text, $link_href = '#', $lin
221230
'text' => $link_text,
222231
]]);
223232

224-
$this->action_buttons[$key] = $button;
233+
$this->action_buttons[$key] = ['tag' => $button, 'order' => $order ?? PHP_INT_MAX / 2];
225234
return $this;
226235
}
227236

scss/partials/admin_sidebar.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
.feather {
9494
vertical-align: middle !important;
9595
}
96+
97+
svg {
98+
height: auto !important;
99+
min-width: 20px;
100+
}
96101
}
97102
}
98103

0 commit comments

Comments
 (0)