action btns

This commit is contained in:
Билай Станислав 2024-11-19 14:55:25 +03:00
parent 7a90980772
commit 6c2798c123
5 changed files with 53 additions and 51 deletions

View File

@ -1,15 +0,0 @@
<?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

@ -4,6 +4,7 @@
*/ */
use kernel\models\Option; use kernel\models\Option;
use kernel\widgets\ActionButtonWidget;
$table = new \Itguild\Tables\ListJsonTable($json); $table = new \Itguild\Tables\ListJsonTable($json);
@ -15,7 +16,12 @@ $table->columns([
$table->addAction(function ($row, $url){ $table->addAction(function ($row, $url){
$path = $row['path']; $path = $row['path'];
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme'); $active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme');
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>"; $btn = ActionButtonWidget::create([
'btn_type' => "primary",
'label' => "Активировать",
'url' => "$url/activate/?p=$path",
])->run();
if ($path === $active_admin_theme){ if ($path === $active_admin_theme){
$btn = "Активна"; $btn = "Активна";
} }

View File

@ -8,6 +8,7 @@
*/ */
use Itguild\Tables\ListJsonTable; use Itguild\Tables\ListJsonTable;
use kernel\widgets\ActionButtonWidget;
$meta = []; $meta = [];
$meta['columns'] = [ $meta['columns'] = [
@ -29,32 +30,44 @@ $info_to_table['data'] = $modules_info;
$table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); $table->addAction(function ($row, $url) use ($moduleService) {
$id = $row['id'];
return ActionButtonWidget::create([
'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>",
'url' => "$url/view/$id",
])->run();
});
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
$id = $row['id']; $id = $row['id'];
if ($moduleService->isInstall($slug)){ if ($moduleService->isInstall($slug)){
$label = "Удалить"; return ActionButtonWidget::create([
$btn_type = "danger"; 'btn_type' => "danger",
$btn = "<a class='btn btn-$btn_type' href='$url/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; 'label' => "<i class='fa-regular fa-trash-can'></i>",
'url' => "$url/delete/?slug=$slug",
])->run();
} }
else { else {
$label = "Установить"; return ActionButtonWidget::create([
$btn_type = "success"; 'btn_type' => "success",
$btn = "<a class='btn btn-$btn_type' href='$url/install/?id=$id' style='margin: 3px; width: 150px;' >$label</a>"; 'label' => "<i class='fa-solid fa-download'></i>",
'url' => "$url/install/?id=$id",
])->run();
} }
return $btn;
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
if ($moduleService->isInstall($slug)){ if ($moduleService->isInstall($slug)){
if (!$moduleService->isLastVersion($slug)) { if (!$moduleService->isLastVersion($slug)) {
$label = "Обновить"; return ActionButtonWidget::create([
$btn_type = "info"; 'btn_type' => "info",
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; 'label' => "<i class='fa-regular fa-pen-to-square'></i>",
'url' => "$url/update/?slug=$slug",
])->run();
} }
} }

View File

@ -7,8 +7,8 @@
* @var \kernel\services\ModuleService $moduleService * @var \kernel\services\ModuleService $moduleService
*/ */
use kernel\IGTabel\btn\ActionButton;
use kernel\widgets\ActionButtonWidget; use kernel\widgets\ActionButtonWidget;
use kernel\widgets\ModuleTabsWidget;
$meta = []; $meta = [];
$meta['columns'] = [ $meta['columns'] = [
@ -32,11 +32,11 @@ $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)) {
return ActionButton::create([ return ActionButtonWidget::create([
'btn_type' => "warning", 'btn_type' => "warning",
'label' => "<i class='fa-regular fa-circle-xmark'></i>", 'label' => "<i class='fa-regular fa-circle-xmark'></i>",
'url' => "$url/deactivate/?slug=$slug", 'url' => "$url/deactivate/?slug=$slug",
]); ])->run();
} else { } else {
return ActionButtonWidget::create([ return ActionButtonWidget::create([
@ -44,33 +44,28 @@ $table->addAction(function ($row, $url) use ($moduleService) {
'url' => "$url/deactivate/?slug=$slug", 'url' => "$url/deactivate/?slug=$slug",
'btn_type' => "success" 'btn_type' => "success"
])->run(); ])->run();
// 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 ActionButton::create([ return ActionButtonWidget::create([
'btn_type' => "primary", 'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>", 'label' => "<i class='fa-regular fa-eye'></i>",
'url' => "$url/view/?slug=$slug", 'url' => "$url/view/?slug=$slug",
]); ])->run();
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug']; $slug = $row['slug'];
if (!$moduleService->isKernelModule($slug)){ if (!$moduleService->isKernelModule($slug)){
if (!$moduleService->isLastVersion($slug)) { if (!$moduleService->isLastVersion($slug)) {
$label = "Обновить"; return ActionButtonWidget::create([
$btn_type = "info"; 'btn_type' => "info",
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>"; 'label' => "<i class='fa-regular fa-pen-to-square'></i>",
'url' => "$url/view/?slug=$slug",
])->run();
} }
} }
@ -80,21 +75,17 @@ $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 = "Удалить"; return ActionButtonWidget::create([
// $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 ActionButton::create([
'btn_type' => "danger", 'btn_type' => "danger",
'label' => "<i class='fa-regular fa-trash-can'></i>", 'label' => "<i class='fa-regular fa-trash-can'></i>",
'url' => "admin/module_shop_client/delete/?slug=$slug", 'url' => "admin/module_shop_client/delete/?slug=$slug",
]); ])->run();
} }
return false; return false;
}); });
if ($moduleService->isActive('module_shop_client')) { if ($moduleService->isActive('module_shop_client')) {
\kernel\widgets\ModuleTabsWidget::create()->run(); ModuleTabsWidget::create()->run();
} }
$table->create(); $table->create();

View File

@ -2,10 +2,17 @@
namespace kernel\widgets; namespace kernel\widgets;
use kernel\helpers\Debug;
use kernel\Widget; use kernel\Widget;
class ActionButtonWidget extends Widget class ActionButtonWidget extends Widget
{ {
public static function create(array $data = []): ActionButtonWidget
{
return new static($data);
}
public function run(): string public function run(): string
{ {
$label = $this->data['label']; $label = $this->data['label'];