diff --git a/app/admin_themes/custom/manifest.json b/app/admin_themes/custom/manifest.json index 5fcce5d..ab256cb 100644 --- a/app/admin_themes/custom/manifest.json +++ b/app/admin_themes/custom/manifest.json @@ -1,6 +1,7 @@ { "name": "Custom", "version": "0.1", + "author": "Kavalar", "slug": "custom", "description": "Custom admin theme", "preview": "nrnv2024_640x360.jpg", diff --git a/kernel/AdminController.php b/kernel/AdminController.php index 712c5e7..33918e7 100644 --- a/kernel/AdminController.php +++ b/kernel/AdminController.php @@ -10,7 +10,7 @@ class AdminController extends Controller { protected AdminThemeService $adminThemeService; - protected function init() + protected function init(): void { $this->adminThemeService = new AdminThemeService(); $active_theme = $this->adminThemeService->getActiveAdminThemeInfo(); diff --git a/kernel/Module.php b/kernel/Module.php new file mode 100644 index 0000000..cd094e7 --- /dev/null +++ b/kernel/Module.php @@ -0,0 +1,9 @@ +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]); + } + +} \ No newline at end of file diff --git a/kernel/modules/admin_themes/AdminThemesModule.php b/kernel/modules/admin_themes/AdminThemesModule.php new file mode 100644 index 0000000..f95f56e --- /dev/null +++ b/kernel/modules/admin_themes/AdminThemesModule.php @@ -0,0 +1,14 @@ + "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"]; + $meta['columns'] = [ + "preview" => "Превью", + "name" => "Название", + "author" => "Автор", + "version" => "Версия", + "description" => "Описание" + ]; $meta['params'] = ["class" => "table table-bordered"]; $meta['perPage'] = 10; $meta['baseUrl'] = "/admin/settings/admin-themes"; diff --git a/kernel/modules/admin_themes/manifest.json b/kernel/modules/admin_themes/manifest.json new file mode 100644 index 0000000..b792723 --- /dev/null +++ b/kernel/modules/admin_themes/manifest.json @@ -0,0 +1,8 @@ +{ + "name": "Admin themes", + "version": "0.1", + "author": "ITGuild", + "slug": "admin_themes", + "description": "Admin themes module", + "module_class": "AdminThemesModule" +} \ No newline at end of file diff --git a/kernel/modules/admin_themes/views/index.php b/kernel/modules/admin_themes/views/index.php index ab4dc4d..8ae87ff 100644 --- a/kernel/modules/admin_themes/views/index.php +++ b/kernel/modules/admin_themes/views/index.php @@ -15,7 +15,7 @@ $table->columns([ $table->addAction(function ($row, $url){ $path = $row['path']; $active_admin_theme = Option::where("key", "active_admin_theme")->first(); - $btn = "Активировать";; + $btn = "Активировать"; if ($path === $active_admin_theme->value){ $btn = "Активна"; } diff --git a/kernel/modules/menu/MenuModule.php b/kernel/modules/menu/MenuModule.php new file mode 100644 index 0000000..0f138e1 --- /dev/null +++ b/kernel/modules/menu/MenuModule.php @@ -0,0 +1,14 @@ +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->get('/', [\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->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" => "menu"], function (RouteCollector $router){ App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php new file mode 100644 index 0000000..1255c65 --- /dev/null +++ b/kernel/services/ModuleService.php @@ -0,0 +1,39 @@ +first(); + if ($active_modules){ + $path = json_decode($active_modules->value); + foreach ($path->modules as $p){ + if ($p === $slug){ + return true; + } + } + } + + return false; + } + +} \ No newline at end of file diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php new file mode 100644 index 0000000..0239174 --- /dev/null +++ b/kernel/views/module/index.php @@ -0,0 +1,41 @@ + "Название", + "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 = "$label"; + + return $btn; +}); + +$table->create(); +$table->render(); diff --git a/resources/tmp/themes/custom.zip b/resources/tmp/themes/custom.zip index da5f014..c5e1281 100644 Binary files a/resources/tmp/themes/custom.zip and b/resources/tmp/themes/custom.zip differ diff --git a/resources/tmp/themes/custom/meta/manifest.json b/resources/tmp/themes/custom/meta/manifest.json index 5fcce5d..ab256cb 100644 --- a/resources/tmp/themes/custom/meta/manifest.json +++ b/resources/tmp/themes/custom/meta/manifest.json @@ -1,6 +1,7 @@ { "name": "Custom", "version": "0.1", + "author": "Kavalar", "slug": "custom", "description": "Custom admin theme", "preview": "nrnv2024_640x360.jpg",