module manager
This commit is contained in:
parent
2105c7bc61
commit
95e80ab87b
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Custom",
|
"name": "Custom",
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
|
"author": "Kavalar",
|
||||||
"slug": "custom",
|
"slug": "custom",
|
||||||
"description": "Custom admin theme",
|
"description": "Custom admin theme",
|
||||||
"preview": "nrnv2024_640x360.jpg",
|
"preview": "nrnv2024_640x360.jpg",
|
||||||
|
@ -10,7 +10,7 @@ class AdminController extends Controller
|
|||||||
{
|
{
|
||||||
protected AdminThemeService $adminThemeService;
|
protected AdminThemeService $adminThemeService;
|
||||||
|
|
||||||
protected function init()
|
protected function init(): void
|
||||||
{
|
{
|
||||||
$this->adminThemeService = new AdminThemeService();
|
$this->adminThemeService = new AdminThemeService();
|
||||||
$active_theme = $this->adminThemeService->getActiveAdminThemeInfo();
|
$active_theme = $this->adminThemeService->getActiveAdminThemeInfo();
|
||||||
|
9
kernel/Module.php
Normal file
9
kernel/Module.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
abstract class Module
|
||||||
|
{
|
||||||
|
abstract public function init();
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
|
"author": "ItGuild",
|
||||||
"slug": "default",
|
"slug": "default",
|
||||||
"description": "Default admin theme",
|
"description": "Default admin theme",
|
||||||
"preview": "preview.png",
|
"preview": "preview.png",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Simple",
|
"name": "Simple",
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
|
"author": "ItGuild",
|
||||||
"slug": "simple",
|
"slug": "simple",
|
||||||
"description": "Simple admin theme",
|
"description": "Simple admin theme",
|
||||||
"preview": "preview.png",
|
"preview": "preview.png",
|
||||||
|
50
kernel/controllers/ModuleController.php
Normal file
50
kernel/controllers/ModuleController.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\controllers;
|
||||||
|
|
||||||
|
use DirectoryIterator;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\models\Option;
|
||||||
|
use kernel\modules\user\service\UserService;
|
||||||
|
use kernel\services\ModuleService;
|
||||||
|
|
||||||
|
class ModuleController extends AdminController
|
||||||
|
{
|
||||||
|
protected ModuleService $moduleService;
|
||||||
|
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_DIR . "/views/module/";
|
||||||
|
|
||||||
|
$this->moduleService = new ModuleService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex(): void
|
||||||
|
{
|
||||||
|
$admin_theme_paths = Option::where("key", "module_paths")->first();
|
||||||
|
$dirs = [];
|
||||||
|
if ($admin_theme_paths){
|
||||||
|
$path = json_decode($admin_theme_paths->value);
|
||||||
|
foreach ($path->paths as $p){
|
||||||
|
$dirs[] = getConst($p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$modules_info = [];
|
||||||
|
foreach ($dirs as $dir){
|
||||||
|
$i = 1;
|
||||||
|
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||||
|
$info = [];
|
||||||
|
if($fileInfo->isDot()) continue;
|
||||||
|
$info['id'] = $i;
|
||||||
|
$modules_info[] = array_merge($info, $this->moduleService->getModuleInfo($fileInfo->getPathname()));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cgView->render("index.php", ['modules_info' => $modules_info, 'moduleService' => $this->moduleService]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
kernel/modules/admin_themes/AdminThemesModule.php
Normal file
14
kernel/modules/admin_themes/AdminThemesModule.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\admin_themes;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
|
||||||
|
class AdminThemesModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// TODO: Implement init() method.
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,13 @@ class AdminThemeController extends AdminController
|
|||||||
|
|
||||||
$info_to_table = [];
|
$info_to_table = [];
|
||||||
$meta = [];
|
$meta = [];
|
||||||
$meta['columns'] = ["preview" => "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"];
|
$meta['columns'] = [
|
||||||
|
"preview" => "Превью",
|
||||||
|
"name" => "Название",
|
||||||
|
"author" => "Автор",
|
||||||
|
"version" => "Версия",
|
||||||
|
"description" => "Описание"
|
||||||
|
];
|
||||||
$meta['params'] = ["class" => "table table-bordered"];
|
$meta['params'] = ["class" => "table table-bordered"];
|
||||||
$meta['perPage'] = 10;
|
$meta['perPage'] = 10;
|
||||||
$meta['baseUrl'] = "/admin/settings/admin-themes";
|
$meta['baseUrl'] = "/admin/settings/admin-themes";
|
||||||
|
8
kernel/modules/admin_themes/manifest.json
Normal file
8
kernel/modules/admin_themes/manifest.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Admin themes",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "admin_themes",
|
||||||
|
"description": "Admin themes module",
|
||||||
|
"module_class": "AdminThemesModule"
|
||||||
|
}
|
@ -15,7 +15,7 @@ $table->columns([
|
|||||||
$table->addAction(function ($row, $url){
|
$table->addAction(function ($row, $url){
|
||||||
$path = $row['path'];
|
$path = $row['path'];
|
||||||
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
|
$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>";;
|
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>";
|
||||||
if ($path === $active_admin_theme->value){
|
if ($path === $active_admin_theme->value){
|
||||||
$btn = "Активна";
|
$btn = "Активна";
|
||||||
}
|
}
|
||||||
|
14
kernel/modules/menu/MenuModule.php
Normal file
14
kernel/modules/menu/MenuModule.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\menu;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
|
||||||
|
class MenuModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// TODO: Implement init() method.
|
||||||
|
}
|
||||||
|
}
|
8
kernel/modules/menu/manifest.json
Normal file
8
kernel/modules/menu/manifest.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Menu",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "menu",
|
||||||
|
"description": "Menu module",
|
||||||
|
"module_class": "MenuModule"
|
||||||
|
}
|
14
kernel/modules/post/PostModule.php
Normal file
14
kernel/modules/post/PostModule.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\post;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
|
||||||
|
class PostModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// TODO: Implement init() method.
|
||||||
|
}
|
||||||
|
}
|
8
kernel/modules/post/manifest.json
Normal file
8
kernel/modules/post/manifest.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Post",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "post",
|
||||||
|
"description": "Post module",
|
||||||
|
"module_class": "PostModule"
|
||||||
|
}
|
15
kernel/modules/user/UserModule.php
Normal file
15
kernel/modules/user/UserModule.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\user;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
|
||||||
|
class UserModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// TODO: Implement init() method.
|
||||||
|
}
|
||||||
|
}
|
8
kernel/modules/user/manifest.json
Normal file
8
kernel/modules/user/manifest.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "User",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "user",
|
||||||
|
"description": "User module",
|
||||||
|
"module_class": "UserModule"
|
||||||
|
}
|
@ -7,6 +7,9 @@ use Phroute\Phroute\RouteCollector;
|
|||||||
|
|
||||||
|
|
||||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||||
|
App::$collector->group(["prefix" => "module"], function (RouteCollector $router){
|
||||||
|
App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']);
|
||||||
|
});
|
||||||
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
|
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
|
||||||
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
||||||
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
||||||
@ -17,6 +20,16 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
|||||||
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
|
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
|
||||||
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
|
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
|
||||||
});
|
});
|
||||||
|
App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){
|
||||||
|
App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']);
|
||||||
|
App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']);
|
||||||
|
App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']);
|
||||||
|
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
|
||||||
|
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
||||||
|
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
|
||||||
|
});
|
||||||
App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){
|
App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){
|
||||||
App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){
|
App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){
|
||||||
App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
|
App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
|
||||||
|
39
kernel/services/ModuleService.php
Normal file
39
kernel/services/ModuleService.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\services;
|
||||||
|
|
||||||
|
use kernel\helpers\Manifest;
|
||||||
|
use kernel\models\Option;
|
||||||
|
|
||||||
|
class ModuleService
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getModuleInfo(string $module): false|array|string
|
||||||
|
{
|
||||||
|
$info = [];
|
||||||
|
$info['path'] = $module;
|
||||||
|
if (file_exists($module . "/manifest.json")){
|
||||||
|
$manifest = file_get_contents($module . "/manifest.json");
|
||||||
|
$manifest = Manifest::getWithVars($manifest);
|
||||||
|
$info = array_merge($info, $manifest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isActive(string $slug): bool
|
||||||
|
{
|
||||||
|
$active_modules= Option::where("key", "active_modules")->first();
|
||||||
|
if ($active_modules){
|
||||||
|
$path = json_decode($active_modules->value);
|
||||||
|
foreach ($path->modules as $p){
|
||||||
|
if ($p === $slug){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
kernel/views/module/index.php
Normal file
41
kernel/views/module/index.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var array $modules_info
|
||||||
|
* @var \kernel\services\ModuleService $moduleService
|
||||||
|
*/
|
||||||
|
|
||||||
|
$meta = [];
|
||||||
|
$meta['columns'] = [
|
||||||
|
"name" => "Название",
|
||||||
|
"author" => "Автор",
|
||||||
|
"version" => "Версия",
|
||||||
|
"description" => "Описание"
|
||||||
|
];
|
||||||
|
$meta['params'] = ["class" => "table table-bordered"];
|
||||||
|
$meta['perPage'] = 10;
|
||||||
|
$meta['baseUrl'] = "/admin/module";
|
||||||
|
$meta['currentPage'] = 1;
|
||||||
|
$meta['total'] = count($modules_info);
|
||||||
|
|
||||||
|
$info_to_table['meta'] = $meta;
|
||||||
|
$info_to_table['data'] = $modules_info;
|
||||||
|
|
||||||
|
$table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
$table->addAction(function ($row, $url) use ($moduleService){
|
||||||
|
$slug = $row['slug'];
|
||||||
|
if ($moduleService->isActive($slug)){
|
||||||
|
$label = "Деактивировать";
|
||||||
|
$btn_type = "warning";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$label = "Активировать";
|
||||||
|
$btn_type = "primary";
|
||||||
|
}
|
||||||
|
$btn = "<a class='btn btn-$btn_type' href='$url/activate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||||
|
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Custom",
|
"name": "Custom",
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
|
"author": "Kavalar",
|
||||||
"slug": "custom",
|
"slug": "custom",
|
||||||
"description": "Custom admin theme",
|
"description": "Custom admin theme",
|
||||||
"preview": "nrnv2024_640x360.jpg",
|
"preview": "nrnv2024_640x360.jpg",
|
||||||
|
Loading…
Reference in New Issue
Block a user