From a71102eb0582cac86516f736f21c96c68352e10a Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 19 Dec 2024 12:59:27 +0300 Subject: [PATCH] fix module install, add filters to msc, fix primary btn --- kernel/IGTabel/btn/PrimaryBtn.php | 8 ++-- .../ModuleShopClientController.php | 41 +++++++++++++++++++ .../routs/module_shop_client.php | 1 + .../module_shop_client/views/index.php | 6 +++ kernel/services/ModuleService.php | 16 +++++++- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/kernel/IGTabel/btn/PrimaryBtn.php b/kernel/IGTabel/btn/PrimaryBtn.php index 31a43c3..b389401 100644 --- a/kernel/IGTabel/btn/PrimaryBtn.php +++ b/kernel/IGTabel/btn/PrimaryBtn.php @@ -6,9 +6,9 @@ class PrimaryBtn { protected string $btn = ''; - public function __construct(string $title, string $url) + public function __construct(string $title, string $url, $width) { - $this->btn = "$title"; + $this->btn = "$title"; } public function fetch(): string @@ -16,9 +16,9 @@ class PrimaryBtn return $this->btn; } - public static function create(string $title, string $url): PrimaryBtn + public static function create(string $title, string $url, $width = '150px'): PrimaryBtn { - return new self($title, $url); + return new self($title, $url, $width); } } \ No newline at end of file diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 5ad60cd..d4d4102 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -157,6 +157,47 @@ class ModuleShopClientController extends AdminController $this->redirect('/admin/module_shop_client', 302); } + public function actionSearch(int $page_number = 1): void + { + $request = new Request(); + $filters = $request->get(); + if ($this->moduleService->issetModuleShopToken()) { + if ($this->moduleService->isServerAvailable()) { + $modules_info = []; + $per_page = 8; + $modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modules = json_decode($modules->getBody()->getContents(), true); + foreach ($modules as $module) { + foreach ($filters as $key => $value) { + if ($value === '') continue; + if ($module[$key] !== $value) { + break; + } + + $modules_info[] = $module; + } + } + $module_count = count($modules_info); + $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page); + + $this->cgView->render("index.php", [ + 'modules_info' => $modules_info, + 'moduleService' => $this->moduleService, + 'page_number' => $page_number, + 'module_count' => $module_count, + 'per_page' => $per_page, + 'kernelService' => new KernelService(), + 'adminThemeService' => new AdminThemeService(), + ]); + } else { + $this->cgView->render("module_shop_error_connection.php"); + } + + } else { + $this->cgView->render("login_at_module_shop.php"); + } + } + /** * @throws Exception */ diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php index cd1a960..945ccd2 100644 --- a/kernel/modules/module_shop_client/routs/module_shop_client.php +++ b/kernel/modules/module_shop_client/routs/module_shop_client.php @@ -15,6 +15,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']); App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']); App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']); + App::$collector->get('/search', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionSearch']); App::$collector->post('/auth', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAuth']); App::$collector->post('/code_check', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionCodeCheck']); App::$collector->group(["prefix" => "kernel"], function (RouteCollector $router) { diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php index 72ab7cd..f5c5b79 100644 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -17,6 +17,7 @@ $meta['columns'] = [ "name" => "Название", "author" => "Автор", "version" => "Версия", + "type" => "Тип", "description" => "Описание", "installations" => "Установки", "views" => "Просмотры" @@ -29,6 +30,7 @@ $meta['total'] = $module_count; $info_to_table['meta'] = $meta; $info_to_table['data'] = $modules_info; +$info_to_table['filters'] = ['type'/*, 'author'*/]; $table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); @@ -95,6 +97,10 @@ $table->addAction(function ($row, $url) use ($adminThemeService) { return false; }); +$table->afterPrint(function () { + return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch(); +}); + \kernel\widgets\ModuleTabsWidget::create()->run(); $table->create(); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 3d769fa..56ca7be 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -308,7 +308,12 @@ class ModuleService $manifest = Manifest::getWithVars($manifestJson); $fileHelper = new Files(); - $fileHelper->copy_folder($tmpModuleDirFull . 'app', $manifest['app_module_path']); + if (isset($manifest['app_module_path'])) { + $fileHelper->copy_folder($tmpModuleDirFull . 'app', $manifest['app_module_path']); + } else { + $fileHelper->copy_folder($tmpModuleDirFull . 'app', APP_DIR . '/modules/' . $manifest['slug']); + } + if (isset($manifest['kernel_module_path'])) { $fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']); } else { @@ -316,6 +321,7 @@ class ModuleService } $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + unlink(ROOT_DIR . $path); return true; } @@ -392,8 +398,12 @@ class ModuleService $manifest = Manifest::getWithVars($manifestJson); $fileHelper = new Files(); + if (isset($manifest['app_module_path'])) { + $fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', $manifest['app_module_path'] . '/manifest.json'); + } else { + $fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', APP_DIR . '/modules/' . $manifest['slug'] . '/manifest.json'); + } - $fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', $manifest['app_module_path'] . '/manifest.json'); if (isset($manifest['kernel_module_path'])) { $fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']); } else { @@ -401,6 +411,8 @@ class ModuleService } $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + unlink(ROOT_DIR . $path); + return true; }