admin themes to ms

This commit is contained in:
Билай Станислав 2025-01-09 12:17:32 +03:00
parent 7489e999ef
commit 6a07e5cdde
7 changed files with 110 additions and 58 deletions

View File

@ -5,6 +5,7 @@ namespace kernel\modules\module_shop_client\controllers;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Facades\Session;
use kernel\AdminController; use kernel\AdminController;
use kernel\Flash; use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
@ -156,49 +157,6 @@ 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();
//// Debug::dd($filters);
// 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(),
// 'filterValues' => $filters
// ]);
// } else {
// $this->cgView->render("module_shop_error_connection.php");
// }
//
// } else {
// $this->cgView->render("login_at_module_shop.php");
// }
// }
public function actionSearch(int $page_number = 1): void public function actionSearch(int $page_number = 1): void
{ {
$request = new Request(); $request = new Request();
@ -285,4 +243,56 @@ class ModuleShopClientController extends AdminController
$this->cgView->render('module_shop_error_connection.php'); $this->cgView->render('module_shop_error_connection.php');
} }
#[NoReturn] public function actionAdminThemeInstall(): void
{
$request = new Request();
$id = $request->get("id");
$adminThemeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
$adminThemeInfo = json_decode($adminThemeInfo->getBody()->getContents(), true);
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $adminThemeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/admin_themes");
if ($this->adminThemeService->install('/resources/tmp/admin_themes/' . basename($adminThemeInfo['path_to_archive']))) {
Flash::setMessage("success", "Тема админ-панели успешно установлена.");
} else {
Session::start();
Session::set("error", implode(";", $this->adminThemeService->getErrors()));
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionAdminThemeUpdate(): void
{
$request = new Request();
$slug = $request->get("slug");
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
foreach ($modules_info as $module) {
if ($module['slug'] === $slug) {
$path = $module['path_to_archive'];
}
}
if (isset($path)) {
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/admin_themes");
$this->adminThemeService->update('/resources/tmp/admin_themes/' . basename($path));
Flash::setMessage("success", "Тема админ-панели успешно обновлена.");
} else {
Flash::setMessage("error", "Ошибка обновления темы админ-панели.");
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionAdminThemeDelete(): void
{
$request = new Request();
$slug = $request->get("slug");
$adminThemeInfo = $this->adminThemeService->getAdminThemeInfoBySlug($slug);
$this->adminThemeService->uninstall($adminThemeInfo['path']);
Flash::setMessage("success", "Тема админ-панели успешно удалена.");
$this->redirect('/admin/module_shop_client', 302);
}
} }

View File

@ -24,7 +24,9 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
}); });
App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) { App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) {
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']); App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']);
App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']); App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeDelete']);
}); });
}); });
}); });

View File

@ -104,7 +104,7 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
$slug = $row['slug']; $slug = $row['slug'];
if ($adminThemeService->isInstall($slug)) { if ($adminThemeService->isInstall($slug)) {
if (!$adminThemeService->isLastVersion($slug)) { if (!$adminThemeService->isLastVersion($slug)) {
$url = "$url/admin_theme/update/"; $url = "$url/admin_theme/update/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
} }
@ -114,6 +114,22 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
return false; return false;
}); });
$table->addAction(function ($row, $url) use ($adminThemeService) {
if ($row['type'] === 'admin_theme') {
if ($adminThemeService->isInstall($row['slug'])) {
$url = "$url/admin_theme/delete/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
} else {
$url = "$url/admin_theme/install/?id=" . $row['id'];
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
}
return false;
});
$table->afterPrint(function () { $table->afterPrint(function () {
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch(); return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
}); });

View File

@ -82,12 +82,22 @@ class AdminThemeService
return $info; return $info;
} }
public function getAdminThemeInfoBySlug(string $slug) public function getAdminThemeInfoBySlug(string $slug): false|array|string
{ {
// TODO $dirs = $this->getAdminThemeDirs();
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if ($this->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
return $this->getAdminThemeInfo($fileInfo->getPathname());
}
}
}
return false;
} }
public function isInstall(string $slug): bool public function getAdminThemeDirs(): array
{ {
$adminThemePaths = Option::where("key", "admin_theme_paths")->first(); $adminThemePaths = Option::where("key", "admin_theme_paths")->first();
$dirs = []; $dirs = [];
@ -97,6 +107,12 @@ class AdminThemeService
$dirs[] = getConst($p); $dirs[] = getConst($p);
} }
} }
return $dirs;
}
public function isInstall(string $slug): bool
{
$dirs = $this->getAdminThemeDirs();
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) { foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) continue; if ($fileInfo->isDot()) continue;
@ -116,8 +132,7 @@ class AdminThemeService
$modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true); $modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true);
$themeInfo = $this->getAdminThemeInfo($slug); $themeInfo = $this->getAdminThemeInfoBySlug($slug);
// Debug::dd($themeInfo);
foreach ($modulesInfo as $mod) { foreach ($modulesInfo as $mod) {
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) { if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
return true; return true;
@ -195,11 +210,20 @@ class AdminThemeService
$this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default'); $this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
} }
$fileHelper = new Files(); $fileHelper = new Files();
if (file_exists(ROOT_DIR . $path)) { if (file_exists($path)) {
$fileHelper->recursiveRemoveDir(ROOT_DIR . $path); $fileHelper->recursiveRemoveDir($path);
} }
if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) { if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) {
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']); $fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']);
} }
} }
public function update(string $path): bool
{
if ($this->install($path)) {
return true;
}
return false;
}
} }

View File

@ -1,9 +1,9 @@
// Responsive default_user_photo (ensure default_user_photo don't scale beyond their parents) // Responsive images (ensure images don't scale beyond their parents)
// //
// This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s. // This is purposefully opt-in via an explicit class rather than being the default for all `<img>`s.
// We previously tried the "default_user_photo are responsive by default" approach in Bootstrap v2, // We previously tried the "images are responsive by default" approach in Bootstrap v2,
// and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps) // and abandoned it in Bootstrap v3 because it breaks lots of third-party widgets (including Google Maps)
// which weren't expecting the default_user_photo within themselves to be involuntarily resized. // which weren't expecting the images within themselves to be involuntarily resized.
// See also https://github.com/twbs/bootstrap/issues/18178 // See also https://github.com/twbs/bootstrap/issues/18178
.img-fluid { .img-fluid {
@include img-fluid; @include img-fluid;

View File

@ -249,7 +249,7 @@ figure {
img { img {
vertical-align: middle; vertical-align: middle;
border-style: none; // Remove the border on default_user_photo inside links in IE 10-. border-style: none; // Remove the border on images inside links in IE 10-.
} }
svg { svg {

View File

@ -5,12 +5,12 @@
// Responsive image // Responsive image
// //
// Keep default_user_photo from scaling beyond the width of their parents. // Keep images from scaling beyond the width of their parents.
@mixin img-fluid { @mixin img-fluid {
// Part 1: Set a maximum relative to the parent // Part 1: Set a maximum relative to the parent
max-width: 100%; max-width: 100%;
// Part 2: Override the height to auto, otherwise default_user_photo will be stretched // Part 2: Override the height to auto, otherwise images will be stretched
// when setting a width and height attribute on the img element. // when setting a width and height attribute on the img element.
height: auto; height: auto;
} }