ms client update

This commit is contained in:
Билай Станислав 2024-10-31 16:12:02 +03:00
parent 9d243b5b35
commit a02c55e16e
19 changed files with 75 additions and 142 deletions

View File

@ -1,6 +1,6 @@
{
"name": "Tags",
"version": "0.2",
"version": "0.1",
"author": "ITGuild",
"slug": "tag",
"description": "Tags module",

View File

@ -3,10 +3,11 @@
namespace kernel\IGTabel\action_column;
use Itguild\Tables\ActionColumn\ActionColumn;
use kernel\helpers\Debug;
class ViewActionColumn extends ActionColumn
{
protected string $prefix = '/';
protected string $prefix = '/view/';
public function fetch(): string
{

View File

@ -74,7 +74,7 @@ class ModuleController extends AdminController
{
$request = new Request();
$active_res = $this->moduleService->setActiveModule($request->get("slug"));
if (!$active_res){
if (!$active_res) {
Session::start();
Session::set("error", implode(";", $this->moduleService->getErrors()));
$this->redirect("/admin", 302);

View File

@ -43,7 +43,7 @@ class MenuController extends AdminController
if ($menuForm->validate()){
$menuItem = $this->menuService->create($menuForm);
if ($menuItem){
$this->redirect("/admin/settings/menu/" . $menuItem->id, code: 302);
$this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302);
}
}
$this->redirect("/admin/settings/menu/create", code: 302);
@ -107,7 +107,7 @@ class MenuController extends AdminController
if ($menuForm->validate()){
$menuItem = $this->menuService->update($menuForm, $menuItem);
if ($menuItem){
$this->redirect("/admin/settings/menu/" . $menuItem->id, code: 302);
$this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302);
}
}
$this->redirect("/admin/settings/menu/update/" . $id, code: 302);

View File

@ -14,7 +14,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
App::$collector->get('/view/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);

View File

@ -3,9 +3,11 @@
namespace kernel\modules\module_shop_client\controllers;
use GuzzleHttp\Client;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\helpers\Debug;
use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\Request;
use kernel\services\ModuleService;
class ModuleShopClientController extends AdminController
@ -37,6 +39,7 @@ class ModuleShopClientController extends AdminController
$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,
@ -55,8 +58,10 @@ class ModuleShopClientController extends AdminController
$this->cgView->render("view.php", ['data' => $module_info]);
}
public function actionInstall(int $id): void
public function actionInstall(): void
{
$request = new Request();
$id = $request->get("id");
$token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU';
$module_info = $this->client->request('GET', 'http://igfs.loc/api/module_shop/' . $id, [
'headers' => [
@ -69,4 +74,13 @@ class ModuleShopClientController extends AdminController
}
#[NoReturn] public function actionDelete(): void
{
$request = new Request();
$slug = $request->get("slug");
$module_info = $this->moduleService->getModuleInfoBySlug($slug);
$this->moduleService->uninstallModule($module_info['app_module_path']);
$this->redirect('/admin/module_shop_client', 302);
}
}

View File

@ -11,13 +11,13 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "module_shop_client"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionIndex']);
App::$collector->get('/install/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionInstall']);
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionInstall']);
// App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']);
// App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
App::$collector->get('/{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->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
// 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', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']);
});
});
});

View File

@ -1,57 +0,0 @@
<?php
namespace kernel\modules\module_shop_client\services;
use GuzzleHttp\Client;
use Itguild\Tables\ListJsonTable;
use kernel\services\ModuleService;
class ModuleShopClientService extends ModuleService
{
public static function getModuleShopClientInfo()
{
$client = new Client();
$token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU';
$res = $client->request('GET', 'http://igfs.loc/api/module_shop/gb_slug', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
]
]);
return json_decode($res->getBody()->getContents());
}
/**
* @throws \Exception
*/
// public static function getModuleShopClientTable(): ListJsonTable
// {
// $modules_info = json_decode(ModuleShopClientService::getModuleShopClientInfo());
//
// $meta = [];
// $meta['columns'] = [
// "name" => "Название",
// "author" => "Автор",
// "version" => "Версия",
// "description" => "Описание",
// "installations" => 'Установки',
// "views" => 'Просмотры'
// ];
// $meta['params'] = ["class" => "table table-bordered"];
// $meta['perPage'] = 3;
// $meta['baseUrl'] = "/admin/module_shop_client";
// $meta['currentPage'] = 1;
// $meta['total'] = count($modules_info);
//
// $info_to_table['meta'] = $meta;
// $info_to_table['data'] = $modules_info;
//
// $table = new ListJsonTable(json_encode($info_to_table, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
//
// $table->create();
// return $table;
// }
}

View File

@ -4,6 +4,7 @@
* @var int $module_count
* @var int $page_number
* @var int $per_page
* @var \kernel\services\ModuleService $moduleService
*/
use Itguild\Tables\ListJsonTable;
@ -28,26 +29,25 @@ $info_to_table['data'] = $modules_info;
$table = new 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";
// $btn = "<a class='btn btn-$btn_type' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
//
// }
// 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->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\InstallActionColumn::class);
$table->addAction(function ($row, $url) use ($moduleService){
$slug = $row['slug'];
$id = $row['id'];
if ($moduleService->isInstall($slug)){
$label = "Удалить";
$btn_type = "danger";
$btn = "<a class='btn btn-$btn_type' href='$url/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
}
else {
$label = "Установить";
$btn_type = "warning";
$btn = "<a class='btn btn-$btn_type' href='$url/install/?id=$id' style='margin: 3px; width: 150px;' >$label</a>";
}
return $btn;
});
$table->create();
$table->render();

View File

@ -88,7 +88,7 @@ class OptionController extends AdminController
if ($optionForm->validate()) {
$option = $this->optionService->update($optionForm, $option);
if ($option) {
$this->redirect('/admin/option/' . $option->id);
$this->redirect('/admin/option/view/' . $option->id);
}
}

View File

@ -10,7 +10,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']);
App::$collector->get('/view/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']);

View File

@ -32,7 +32,7 @@ class PostController extends AdminController
if ($postForm->validate()) {
$post = $this->postService->create($postForm);
if ($post) {
$this->redirect("/admin/post/" . $post->id);
$this->redirect("/admin/post/view/" . $post->id);
}
}
$this->redirect("/admin/post/create");
@ -87,7 +87,7 @@ class PostController extends AdminController
if ($postForm->validate()) {
$post = $this->postService->update($postForm, $post);
if ($post) {
$this->redirect("/admin/post/" . $post->id);
$this->redirect("/admin/post/view/" . $post->id);
}
}
$this->redirect("/admin/post/update/" . $id);

View File

@ -13,7 +13,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
App::$collector->get('/view/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);

View File

@ -1,16 +0,0 @@
<?php
namespace kernel\modules\post\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostDeleteActionColumn extends ActionColumn
{
protected string $prefix = "/delete/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace kernel\modules\post\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostEditActionColumn extends ActionColumn
{
protected string $prefix = "/update/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace kernel\modules\post\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostViewActionColumn extends actionColumn
{
protected string $prefix = "/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
}
}

View File

@ -36,7 +36,7 @@ class UserController extends AdminController
if ($userForm->validate()){
$user = $this->userService->create($userForm);
if ($user){
$this->redirect("/admin/user/" . $user->id);
$this->redirect("/admin/user/view/" . $user->id);
}
}
$this->redirect("/admin/user/create");
@ -94,7 +94,7 @@ class UserController extends AdminController
if ($userForm->validate()){
$user = $userService->update($userForm, $user);
if ($user){
$this->redirect("/admin/user/" . $user->id);
$this->redirect("/admin/user/view/" . $user->id);
}
}
$this->redirect("/admin/user/update/" . $id);

View File

@ -13,7 +13,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
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->get('/view/{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']);

View File

@ -411,4 +411,27 @@ class ModuleService
return $dependence_array;
}
public function isInstall(string $slug): bool
{
$module_paths = Option::where("key", "module_paths")->first();
$dirs = [];
if ($module_paths){
$path = json_decode($module_paths->value);
foreach ($path->paths as $p){
$dirs[] = getConst($p);
}
}
foreach ($dirs as $dir){
foreach (new DirectoryIterator($dir) as $fileInfo) {
if($fileInfo->isDot()) continue;
if ($this->getModuleInfo($fileInfo->getPathname())['slug'] === $slug) {
return true;
};
}
}
return false;
}
}