action button class

This commit is contained in:
Билай Станислав 2024-11-19 13:41:13 +03:00
parent 772ad48961
commit 0f47f73dda
10 changed files with 67 additions and 29 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace kernel\IGTabel\btn;
class ActionButton
{
public static function create(array $data): string
{
$btn_type = $data['btn_type'];
$url = $data['url'];
$label = $data['label'];
return "<a class='btn btn-$btn_type' href='$url' style='margin: 3px'>$label</a>";
}
}

View File

@ -11,7 +11,7 @@ class Widget
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
$this->cgView = new CgView(); $this->cgView = new CgView();
$this->cgView->viewPath = ROOT_DIR . "/views/widgets"; $this->cgView->viewPath = KERNEL_DIR . "/views/widgets";
$this->data = $data; $this->data = $data;

View File

@ -7,6 +7,9 @@
* @var \kernel\services\ModuleService $moduleService * @var \kernel\services\ModuleService $moduleService
*/ */
use kernel\IGTabel\btn\ActionButton;
use kernel\widgets\ActionButtonWidget;
$meta = []; $meta = [];
$meta['columns'] = [ $meta['columns'] = [
"name" => "Название", "name" => "Название",
@ -29,22 +32,36 @@ $table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRET
$table->addAction(function ($row, $url) use ($moduleService) { $table->addAction(function ($row, $url) use ($moduleService) {
$slug = $row['slug']; $slug = $row['slug'];
if ($moduleService->isActive($slug)) { if ($moduleService->isActive($slug)) {
$label = "Деактивировать"; return ActionButton::create([
$btn_type = "warning"; 'btn_type' => "warning",
$btn = "<a class='btn btn-$btn_type' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; 'label' => "<i class='fa-regular fa-circle-xmark'></i>",
'url' => "$url/deactivate/?slug=$slug",
]);
} else { } else {
$label = "<i class='fa-regular fa-circle-check'></i>"; ActionButtonWidget::create([
$btn_type = "success"; 'label' => "<i class='fa-regular fa-circle-check'></i>",
$btn = "<a class='btn btn-$btn_type' href='$url/activate/?slug=$slug' style='margin: 3px;' >$label</a>"; 'url' => "$url/deactivate/?slug=$slug",
} 'btn_type' => "success"
])->run();
return $btn; // return ActionButton::create([
// 'btn_type' => "success",
// 'label' => "<i class='fa-regular fa-circle-check'></i>",
// 'url' => "$url/deactivate/?slug=$slug",
// ]);
}
}); });
$table->addAction(function ($row, $url) use ($moduleService) { $table->addAction(function ($row, $url) use ($moduleService) {
$slug = $row['slug']; $slug = $row['slug'];
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>"; // return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
return ActionButton::create([
'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>",
'url' => "$url/view/?slug=$slug",
]);
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
@ -63,16 +80,22 @@ $table->addAction(function ($row, $url) use ($moduleService){
$table->addAction(function ($row) use ($moduleService){ $table->addAction(function ($row) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
if (!$moduleService->isKernelModule($slug)){ if (!$moduleService->isKernelModule($slug)){
$label = "Удалить"; // $label = "Удалить";
$btn_type = "danger"; // $btn_type = "danger";
return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; // return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
return ActionButton::create([
'btn_type' => "danger",
'label' => "<i class='fa-regular fa-trash-can'></i>",
'url' => "admin/module_shop_client/delete/?slug=$slug",
]);
} }
return false; return false;
}); });
$table->create();
if ($moduleService->isActive('module_shop_client')) { if ($moduleService->isActive('module_shop_client')) {
\kernel\widgets\ModuleTabsWidget::create()->run(); \kernel\widgets\ModuleTabsWidget::create()->run();
} }
$table->create();
$table->render(); $table->render();

View File

@ -0,0 +1,9 @@
<?php
/**
* @var string $label
* @var string $btn_type
* @var string $url
*/
?>
<a class='btn btn-<?= $btn_type ?>' href='<?= $url ?>' style='margin: 3px' ><?= $label ?></a>

View File

@ -1,9 +0,0 @@
<?php
/**
* @var string $icon
* @var string $btn
* @var string $url
*/
?>
"<a class='btn btn-$btn' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$icon</a>";

View File

@ -8,9 +8,9 @@ class ActionButtonWidget extends Widget
{ {
public function run(): void public function run(): void
{ {
$icon = $this->data['icon']; $label = $this->data['label'];
$btn = $this->data['btn']; $btn_type = $this->data['btn_type'];
$url = $this->data['url']; $url = $this->data['url'];
$this->cgView->render('/admin/action_button.php', ['icon' => $icon, 'btn' => $btn, 'url' => $url]); $this->cgView->render('/action_button.php', ['label' => $label, 'btn_type' => $btn_type, 'url' => $url]);
} }
} }

View File

@ -11,7 +11,7 @@ class MenuWidget extends Widget
public function run(): void public function run(): void
{ {
$menu = Menu::where("parent_id", 0)->get()->sortBy("priority"); $menu = Menu::where("parent_id", 0)->get()->sortBy("priority");
$this->cgView->render('/admin/menu.php', ['menu' => $menu]); $this->cgView->render('/menu.php', ['menu' => $menu]);
} }
} }

View File

@ -13,6 +13,6 @@ class ModuleTabsWidget extends Widget
'/admin' => 'Локальные', '/admin' => 'Локальные',
'/admin/module_shop_client' => 'Каталог' '/admin/module_shop_client' => 'Каталог'
]; ];
$this->cgView->render('/admin/module_tabs.php', ['tabs' => $tabs]); $this->cgView->render('/module_tabs.php', ['tabs' => $tabs]);
} }
} }