This commit is contained in:
Kavalar 2024-12-19 14:45:57 +03:00
commit b24fac512a
5 changed files with 66 additions and 6 deletions

View File

@ -6,9 +6,9 @@ class PrimaryBtn
{ {
protected string $btn = ''; protected string $btn = '';
public function __construct(string $title, string $url) public function __construct(string $title, string $url, $width)
{ {
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 150px;' >$title</a>"; $this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
} }
public function fetch(): string public function fetch(): string
@ -16,9 +16,9 @@ class PrimaryBtn
return $this->btn; 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);
} }
} }

View File

@ -157,6 +157,47 @@ class ModuleShopClientController extends AdminController
$this->redirect('/admin/module_shop_client', 302); $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 * @throws Exception
*/ */

View File

@ -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('/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('/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('/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('/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->post('/code_check', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionCodeCheck']);
App::$collector->group(["prefix" => "kernel"], function (RouteCollector $router) { App::$collector->group(["prefix" => "kernel"], function (RouteCollector $router) {

View File

@ -17,6 +17,7 @@ $meta['columns'] = [
"name" => "Название", "name" => "Название",
"author" => "Автор", "author" => "Автор",
"version" => "Версия", "version" => "Версия",
"type" => "Тип",
"description" => "Описание", "description" => "Описание",
"installations" => "Установки", "installations" => "Установки",
"views" => "Просмотры" "views" => "Просмотры"
@ -29,6 +30,7 @@ $meta['total'] = $module_count;
$info_to_table['meta'] = $meta; $info_to_table['meta'] = $meta;
$info_to_table['data'] = $modules_info; $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)); $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; return false;
}); });
$table->afterPrint(function () {
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
});
\kernel\widgets\ModuleTabsWidget::create()->run(); \kernel\widgets\ModuleTabsWidget::create()->run();
$table->create(); $table->create();

View File

@ -308,7 +308,12 @@ class ModuleService
$manifest = Manifest::getWithVars($manifestJson); $manifest = Manifest::getWithVars($manifestJson);
$fileHelper = new Files(); $fileHelper = new Files();
if (isset($manifest['app_module_path'])) {
$fileHelper->copy_folder($tmpModuleDirFull . 'app', $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'])) { if (isset($manifest['kernel_module_path'])) {
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']); $fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
} else { } else {
@ -316,6 +321,7 @@ class ModuleService
} }
$fileHelper->recursiveRemoveDir($tmpModuleDirFull); $fileHelper->recursiveRemoveDir($tmpModuleDirFull);
unlink(ROOT_DIR . $path);
return true; return true;
} }
@ -392,8 +398,12 @@ class ModuleService
$manifest = Manifest::getWithVars($manifestJson); $manifest = Manifest::getWithVars($manifestJson);
$fileHelper = new Files(); $fileHelper = new Files();
if (isset($manifest['app_module_path'])) {
$fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', $manifest['app_module_path'] . '/manifest.json'); $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');
}
if (isset($manifest['kernel_module_path'])) { if (isset($manifest['kernel_module_path'])) {
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']); $fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
} else { } else {
@ -401,6 +411,8 @@ class ModuleService
} }
$fileHelper->recursiveRemoveDir($tmpModuleDirFull); $fileHelper->recursiveRemoveDir($tmpModuleDirFull);
unlink(ROOT_DIR . $path);
return true; return true;
} }