admin themes

This commit is contained in:
2024-09-03 16:29:44 +03:00
parent c325b156bd
commit 2ae5c4ac73
235 changed files with 33397 additions and 57 deletions

View File

@ -0,0 +1,68 @@
<?php
namespace kernel\modules\admin_themes\controllers;
use app\helpers\Debug;
use DirectoryIterator;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\Controller;
use kernel\models\Option;
use kernel\Request;
use kernel\services\AdminThemeService;
class AdminThemeController extends AdminController
{
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/admin_themes/views/";
}
public function actionIndex(): void
{
$admin_theme_paths = Option::where("key", "admin_theme_paths")->first();
$dirs = [];
if ($admin_theme_paths){
$path = json_decode($admin_theme_paths->value);
foreach ($path->paths as $p){
$dirs[] = getConst($p);
}
}
$info_to_table = [];
$meta = [];
$meta['columns'] = ["preview" => "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"];
$meta['params'] = ["class" => "table table-bordered"];
$meta['perPage'] = 10;
$meta['baseUrl'] = "/admin/settings/admin-themes";
$meta['currentPage'] = 1;
$info_to_table['meta'] = $meta;
$themes_info = [];
foreach ($dirs as $dir){
$i = 1;
foreach (new DirectoryIterator($dir) as $fileInfo) {
$info = [];
if($fileInfo->isDot()) continue;
$info['id'] = $i;
$themes_info[] = array_merge($info, $this->adminThemeService->getAdminThemeInfo($fileInfo->getPathname()));
$i++;
}
}
$info_to_table['meta']['total'] = count($themes_info);
$info_to_table['data'] = $themes_info;
$this->cgView->render("index.php", ['json' => json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)]);
}
#[NoReturn] public function actionActivate(): void
{
$request = new Request();
$this->adminThemeService->setActiveAdminTheme($request->get("p"));
$this->cgView->render("view.php", ['data' => $this->adminThemeService->getAdminThemeInfo($request->get("p"))]);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* @var $json string
*/
use app\helpers\Debug;
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\models\Option;
$table = new \Itguild\Tables\ListJsonTable($json);
$table->columns([
'preview' => function ($data) {
return "<img src='$data' width='200px'>";
}
]);
$table->addAction(function ($row, $url){
$path = $row['path'];
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>";;
if ($path === $active_admin_theme->value){
$btn = "Активна";
}
return $btn;
});
$table->create();
$table->render();

View File

@ -0,0 +1,30 @@
<?php
/**
* @var array $data
*/
use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn;
$table_info = [
"meta" => [
"rows" => ["preview" => "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/settings/admin-themes",
],
"data" => $data
];
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->rows([
'preview' => function ($data) {
return "<img src='$data' width='500px'>";
}
]);
$table->beforePrint(function () {
$btn = PrimaryBtn::create("Список", "/admin/settings/admin-themes")->fetch();
return $btn;
});
$table->create();
$table->render();