From 0f47f73dda76053b4ba9685490d67e424c2c3f27 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 19 Nov 2024 13:41:13 +0300 Subject: [PATCH] action button class --- kernel/IGTabel/btn/ActionButton.php | 15 ++++++ kernel/Widget.php | 2 +- kernel/views/module/index.php | 51 ++++++++++++++----- kernel/views/widgets/action_button.php | 9 ++++ kernel/views/widgets/admin/action_button.php | 9 ---- kernel/views/widgets/{admin => }/menu.php | 0 .../views/widgets/{admin => }/module_tabs.php | 0 kernel/widgets/ActionButtonWidget.php | 6 +-- kernel/widgets/MenuWidget.php | 2 +- kernel/widgets/ModuleTabsWidget.php | 2 +- 10 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 kernel/IGTabel/btn/ActionButton.php create mode 100644 kernel/views/widgets/action_button.php delete mode 100644 kernel/views/widgets/admin/action_button.php rename kernel/views/widgets/{admin => }/menu.php (100%) rename kernel/views/widgets/{admin => }/module_tabs.php (100%) diff --git a/kernel/IGTabel/btn/ActionButton.php b/kernel/IGTabel/btn/ActionButton.php new file mode 100644 index 0000000..a11431c --- /dev/null +++ b/kernel/IGTabel/btn/ActionButton.php @@ -0,0 +1,15 @@ +$label"; + } +} \ No newline at end of file diff --git a/kernel/Widget.php b/kernel/Widget.php index 3ecbad8..07a1327 100644 --- a/kernel/Widget.php +++ b/kernel/Widget.php @@ -11,7 +11,7 @@ class Widget public function __construct(array $data = []) { $this->cgView = new CgView(); - $this->cgView->viewPath = ROOT_DIR . "/views/widgets"; + $this->cgView->viewPath = KERNEL_DIR . "/views/widgets"; $this->data = $data; diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php index 5caf429..f396de1 100644 --- a/kernel/views/module/index.php +++ b/kernel/views/module/index.php @@ -7,6 +7,9 @@ * @var \kernel\services\ModuleService $moduleService */ +use kernel\IGTabel\btn\ActionButton; +use kernel\widgets\ActionButtonWidget; + $meta = []; $meta['columns'] = [ "name" => "Название", @@ -29,22 +32,36 @@ $table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRET $table->addAction(function ($row, $url) use ($moduleService) { $slug = $row['slug']; if ($moduleService->isActive($slug)) { - $label = "Деактивировать"; - $btn_type = "warning"; - $btn = "$label"; + return ActionButton::create([ + 'btn_type' => "warning", + 'label' => "", + 'url' => "$url/deactivate/?slug=$slug", + ]); } else { - $label = ""; - $btn_type = "success"; - $btn = "$label"; - } + ActionButtonWidget::create([ + 'label' => "", + 'url' => "$url/deactivate/?slug=$slug", + 'btn_type' => "success" + ])->run(); - return $btn; +// return ActionButton::create([ +// 'btn_type' => "success", +// 'label' => "", +// 'url' => "$url/deactivate/?slug=$slug", +// ]); + } }); $table->addAction(function ($row, $url) use ($moduleService) { $slug = $row['slug']; - return "Просмотр"; +// return "Просмотр"; + + return ActionButton::create([ + 'btn_type' => "primary", + 'label' => "", + 'url' => "$url/view/?slug=$slug", + ]); }); $table->addAction(function ($row, $url) use ($moduleService){ @@ -63,16 +80,22 @@ $table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row) use ($moduleService){ $slug = $row['slug']; if (!$moduleService->isKernelModule($slug)){ - $label = "Удалить"; - $btn_type = "danger"; - return "$label"; +// $label = "Удалить"; +// $btn_type = "danger"; +// return "$label"; + + return ActionButton::create([ + 'btn_type' => "danger", + 'label' => "", + 'url' => "admin/module_shop_client/delete/?slug=$slug", + ]); } return false; }); -$table->create(); - if ($moduleService->isActive('module_shop_client')) { \kernel\widgets\ModuleTabsWidget::create()->run(); } + +$table->create(); $table->render(); diff --git a/kernel/views/widgets/action_button.php b/kernel/views/widgets/action_button.php new file mode 100644 index 0000000..918d5ac --- /dev/null +++ b/kernel/views/widgets/action_button.php @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/kernel/views/widgets/admin/action_button.php b/kernel/views/widgets/admin/action_button.php deleted file mode 100644 index 32dee23..0000000 --- a/kernel/views/widgets/admin/action_button.php +++ /dev/null @@ -1,9 +0,0 @@ - - -"$icon"; \ No newline at end of file diff --git a/kernel/views/widgets/admin/menu.php b/kernel/views/widgets/menu.php similarity index 100% rename from kernel/views/widgets/admin/menu.php rename to kernel/views/widgets/menu.php diff --git a/kernel/views/widgets/admin/module_tabs.php b/kernel/views/widgets/module_tabs.php similarity index 100% rename from kernel/views/widgets/admin/module_tabs.php rename to kernel/views/widgets/module_tabs.php diff --git a/kernel/widgets/ActionButtonWidget.php b/kernel/widgets/ActionButtonWidget.php index adea90f..f60217f 100644 --- a/kernel/widgets/ActionButtonWidget.php +++ b/kernel/widgets/ActionButtonWidget.php @@ -8,9 +8,9 @@ class ActionButtonWidget extends Widget { public function run(): void { - $icon = $this->data['icon']; - $btn = $this->data['btn']; + $label = $this->data['label']; + $btn_type = $this->data['btn_type']; $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]); } } \ No newline at end of file diff --git a/kernel/widgets/MenuWidget.php b/kernel/widgets/MenuWidget.php index 52dfe62..d45da7f 100644 --- a/kernel/widgets/MenuWidget.php +++ b/kernel/widgets/MenuWidget.php @@ -11,7 +11,7 @@ class MenuWidget extends Widget public function run(): void { $menu = Menu::where("parent_id", 0)->get()->sortBy("priority"); - $this->cgView->render('/admin/menu.php', ['menu' => $menu]); + $this->cgView->render('/menu.php', ['menu' => $menu]); } } \ No newline at end of file diff --git a/kernel/widgets/ModuleTabsWidget.php b/kernel/widgets/ModuleTabsWidget.php index 94686f2..ef41ec2 100644 --- a/kernel/widgets/ModuleTabsWidget.php +++ b/kernel/widgets/ModuleTabsWidget.php @@ -13,6 +13,6 @@ class ModuleTabsWidget extends Widget '/admin' => 'Локальные', '/admin/module_shop_client' => 'Каталог' ]; - $this->cgView->render('/admin/module_tabs.php', ['tabs' => $tabs]); + $this->cgView->render('/module_tabs.php', ['tabs' => $tabs]); } } \ No newline at end of file