From 381c6c059e919f2ec0351489bf7d339d4ffe8488 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Tue, 8 Oct 2024 13:16:57 +0300 Subject: [PATCH] app module --- app/modules/tag/TagModule.php | 5 +++ app/modules/tag/controllers/TagController.php | 8 ++++ app/modules/tag/manifest.json | 3 +- app/modules/tag/routs/tag.php | 2 + bootstrap.php | 3 ++ .../action_column/ViewActionColumn.php | 16 ++++++++ .../tag/controllers/TagController.php | 21 +++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++++++++++++ kernel/app_modules/tag/models/Tag.php | 37 +++++++++++++++++++ kernel/app_modules/tag/routs/tag.php | 18 +++++++++ kernel/app_modules/tag/views/index.php | 31 ++++++++++++++++ kernel/services/MigrationService.php | 3 ++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++++++++++++ .../tmp/modules/tag/kernel/models/Tag.php | 37 +++++++++++++++++++ 14 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 app/modules/tag/controllers/TagController.php create mode 100644 app/modules/tag/routs/tag.php create mode 100644 kernel/IGTabel/action_column/ViewActionColumn.php create mode 100644 kernel/app_modules/tag/controllers/TagController.php create mode 100644 kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 kernel/app_modules/tag/models/Tag.php create mode 100644 kernel/app_modules/tag/routs/tag.php create mode 100644 kernel/app_modules/tag/views/index.php create mode 100644 resources/tmp/modules/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/modules/tag/kernel/models/Tag.php diff --git a/app/modules/tag/TagModule.php b/app/modules/tag/TagModule.php index ee01d77..b2f0ffd 100644 --- a/app/modules/tag/TagModule.php +++ b/app/modules/tag/TagModule.php @@ -4,14 +4,17 @@ namespace app\modules\tag; use kernel\Module; use kernel\modules\menu\service\MenuService; +use kernel\services\MigrationService; class TagModule extends Module { public MenuService $menuService; + public MigrationService $migrationService; public function __construct() { $this->menuService = new MenuService(); + $this->migrationService = new MigrationService(); } /** @@ -19,6 +22,8 @@ class TagModule extends Module */ public function init(): void { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + $this->menuService->createItem([ "label" => "Тэги", "url" => "/admin/tag", diff --git a/app/modules/tag/controllers/TagController.php b/app/modules/tag/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/app/modules/tag/controllers/TagController.php @@ -0,0 +1,8 @@ + KERNEL_ADMIN_THEMES_DIR, "{KERNEL}" => KERNEL_DIR, "{KERNEL_MODULES}" => KERNEL_MODULES_DIR, + "{KERNEL_APP_MODULES}" => KERNEL_APP_MODULES_DIR, "{CONSOLE}" => CONSOLE_DIR, "{APP}" => APP_DIR, ]; diff --git a/kernel/IGTabel/action_column/ViewActionColumn.php b/kernel/IGTabel/action_column/ViewActionColumn.php new file mode 100644 index 0000000..bf17e93 --- /dev/null +++ b/kernel/IGTabel/action_column/ViewActionColumn.php @@ -0,0 +1,16 @@ +baseUrl . $this->prefix . $this->id; + return " Просмотр "; + } +} \ No newline at end of file diff --git a/kernel/app_modules/tag/controllers/TagController.php b/kernel/app_modules/tag/controllers/TagController.php new file mode 100644 index 0000000..6a72046 --- /dev/null +++ b/kernel/app_modules/tag/controllers/TagController.php @@ -0,0 +1,21 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/";; + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + +} \ No newline at end of file diff --git a/kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php b/kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/kernel/app_modules/tag/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/kernel/app_modules/tag/models/Tag.php b/kernel/app_modules/tag/models/Tag.php new file mode 100644 index 0000000..fb408c9 --- /dev/null +++ b/kernel/app_modules/tag/models/Tag.php @@ -0,0 +1,37 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/kernel/app_modules/tag/routs/tag.php b/kernel/app_modules/tag/routs/tag.php new file mode 100644 index 0000000..edabefa --- /dev/null +++ b/kernel/app_modules/tag/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); +// 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->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']); + }); +}); \ No newline at end of file diff --git a/kernel/app_modules/tag/views/index.php b/kernel/app_modules/tag/views/index.php new file mode 100644 index 0000000..c423207 --- /dev/null +++ b/kernel/app_modules/tag/views/index.php @@ -0,0 +1,31 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +//$table->addAction(MenuEditActionColumn::class); +//$table->addAction(MenuDeleteActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/kernel/services/MigrationService.php b/kernel/services/MigrationService.php index 9085637..8205fa7 100644 --- a/kernel/services/MigrationService.php +++ b/kernel/services/MigrationService.php @@ -6,6 +6,7 @@ use Illuminate\Database\Migrations\DatabaseMigrationRepository; use Illuminate\Database\Migrations\Migrator; use Illuminate\Filesystem\Filesystem; use kernel\App; +use kernel\helpers\Debug; class MigrationService { @@ -21,6 +22,8 @@ class MigrationService */ public function runAtPath(string $path = ROOT_DIR . '/migrations'): array { + $path = getConst($path); + try { $dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration'); diff --git a/resources/tmp/modules/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/modules/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/modules/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/modules/tag/kernel/models/Tag.php b/resources/tmp/modules/tag/kernel/models/Tag.php new file mode 100644 index 0000000..55042a3 --- /dev/null +++ b/resources/tmp/modules/tag/kernel/models/Tag.php @@ -0,0 +1,37 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file