diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php index f655ac6..d4a48fd 100644 --- a/kernel/console/controllers/AdminConsoleController.php +++ b/kernel/console/controllers/AdminConsoleController.php @@ -49,7 +49,7 @@ class AdminConsoleController extends ConsoleController $this->optionService->createFromParams( key: "active_admin_theme", - value: "/home/kavlar/php/MicroFrameWork/kernel/admin_themes/default", + value: "{KERNEL_ADMIN_THEMES}/default", label: "Активная тема админпанели" ); $this->out->r("create option active_admin_theme", "green"); @@ -57,7 +57,7 @@ class AdminConsoleController extends ConsoleController $this->optionService->createFromParams( key: "module_paths", value: "{\"paths\": [\"{KERNEL_MODULES}\", \"{APP}/modules\"]}", - label: "Пути к модулям " + label: "Пути к модулям" ); $this->out->r("create option module_paths", "green"); @@ -72,6 +72,8 @@ class AdminConsoleController extends ConsoleController "label" => "Модули", "url" => "/admin", "slug" => "module", + "priority" => 1, + "status" => 2 ]); $this->out->r("create item menu module", "green"); diff --git a/kernel/models/Menu.php b/kernel/models/Menu.php index 343fca3..85b307f 100644 --- a/kernel/models/Menu.php +++ b/kernel/models/Menu.php @@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Model; * @property string url * @property int status * @property string slug + * @property string priority * @method static find($id) */ @@ -22,7 +23,7 @@ class Menu extends Model const ACTIVE_STATUS = 1; protected $table = 'menu'; - protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug']; + protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug', 'priority']; protected array $dates = ['deleted_at']; public static function labels(): array @@ -35,6 +36,8 @@ class Menu extends Model 'url' => 'URL', 'status' => 'Статус', 'slug' => 'Slug', + 'priority' => 'Приоритет' + ]; } diff --git a/kernel/modules/menu/controllers/MenuController.php b/kernel/modules/menu/controllers/MenuController.php index 84b4490..2c8daf0 100644 --- a/kernel/modules/menu/controllers/MenuController.php +++ b/kernel/modules/menu/controllers/MenuController.php @@ -90,8 +90,6 @@ class MenuController extends AdminController */ public function actionEdit($id): void { -// Debug::prn($_REQUEST); -// Debug::prn($_FILES); $menuItem = Menu::find($id); if (!$menuItem){ throw new Exception(message: "The menu item not found"); diff --git a/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php b/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php index 272ae80..60ee3b6 100644 --- a/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php +++ b/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php @@ -20,6 +20,7 @@ return new class extends Migration $table->string('url', 255); $table->string('slug', 255)->unique(); $table->integer('status')->default(1); + $table->integer('priority')->default(5); $table->timestamps(); }); } diff --git a/kernel/modules/menu/models/Menu.php b/kernel/modules/menu/models/Menu.php index fce307b..32e401d 100644 --- a/kernel/modules/menu/models/Menu.php +++ b/kernel/modules/menu/models/Menu.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Model; * @property string label * @property string url * @property int status + * @property int priority * @method static find($id) */ @@ -21,7 +22,7 @@ class Menu extends Model const ACTIVE_STATUS = 1; protected $table = 'menu'; - protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug']; + protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug', 'priority']; protected array $dates = ['deleted_at']; public static function labels(): array @@ -34,6 +35,7 @@ class Menu extends Model 'url' => 'URL', 'status' => 'Статус', 'slug' => 'Slug', + 'priority' => 'Приоритет' ]; } diff --git a/kernel/modules/menu/models/forms/CreateMenuForm.php b/kernel/modules/menu/models/forms/CreateMenuForm.php index 4e3424e..0d915c4 100644 --- a/kernel/modules/menu/models/forms/CreateMenuForm.php +++ b/kernel/modules/menu/models/forms/CreateMenuForm.php @@ -11,6 +11,7 @@ use kernel\FormModel; * @property string $label * @property string $url * @property int $status + * @property int priority * @property string $slug * @property string $parent_slug */ @@ -26,7 +27,8 @@ class CreateMenuForm extends FormModel 'url' => 'required|min-str-len:1', 'status' => '', 'slug' => 'required|min-str-len:1|max-str-len:50', - 'parent_slug' => '' + 'parent_slug' => '', + 'priority' => '' ]; } } \ No newline at end of file diff --git a/kernel/modules/menu/service/MenuService.php b/kernel/modules/menu/service/MenuService.php index dc61c51..0b32ff6 100644 --- a/kernel/modules/menu/service/MenuService.php +++ b/kernel/modules/menu/service/MenuService.php @@ -21,6 +21,7 @@ class MenuService $model->url = $form_model->getItem('url'); $model->status = $form_model->getItem('status') ?? 1; $model->slug = $form_model->getItem('slug'); + $model->priority = $form_model->getItem('priority') ?? 5; if ($model->save()){ return $model; } @@ -70,6 +71,7 @@ class MenuService $menuItem->url = $form_model->getItem('url'); $menuItem->status = $form_model->getItem('status'); $menuItem->slug = $form_model->getItem('slug'); + $menuItem->priority = $form_model->getItem('priority') ?? 5; if ($menuItem->save()){ return $menuItem; } @@ -90,7 +92,7 @@ class MenuService } public static function getChild(int $id) { - $collection = Menu::where("parent_id", $id)->get(); + $collection = Menu::where("parent_id", $id)->get()->sortBy('priority'); if (!$collection->isEmpty()){ return $collection; } diff --git a/kernel/modules/menu/views/index.php b/kernel/modules/menu/views/index.php index eed36d2..f9cd7c9 100644 --- a/kernel/modules/menu/views/index.php +++ b/kernel/modules/menu/views/index.php @@ -4,9 +4,6 @@ * @var int $page_number */ -//use app\tables\columns\menu\MenuDeleteActionColumn; -//use app\tables\columns\menu\MenuEditActionColumn; -//use app\tables\columns\menu\MenuViewActionColumn; use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\ListEloquentTable; use kernel\IGTabel\btn\PrimaryBtn; diff --git a/kernel/modules/menu/views/view.php b/kernel/modules/menu/views/view.php index da9f5cc..5e73c57 100644 --- a/kernel/modules/menu/views/view.php +++ b/kernel/modules/menu/views/view.php @@ -4,7 +4,6 @@ * @var \Illuminate\Database\Eloquent\Collection $menu */ -use app\models\User; use Itguild\EloquentTable\ViewEloquentTable; use Itguild\EloquentTable\ViewJsonTableEloquentModel; use kernel\IGTabel\btn\DangerBtn; diff --git a/kernel/modules/option/views/index.php b/kernel/modules/option/views/index.php index 8b02702..db334b7 100644 --- a/kernel/modules/option/views/index.php +++ b/kernel/modules/option/views/index.php @@ -24,6 +24,13 @@ $table->beforePrint(function () { //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); }); +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Option::getStatus()[$cell]; + }] +]); + $table->addAction(OptionViewActionColumn::class); $table->addAction(OptionEditActionColumn::class); $table->addAction(OptionDeleteActionColumn::class); diff --git a/kernel/services/AdminThemeService.php b/kernel/services/AdminThemeService.php index afd40fd..6bdc894 100644 --- a/kernel/services/AdminThemeService.php +++ b/kernel/services/AdminThemeService.php @@ -32,7 +32,8 @@ class AdminThemeService public function setActiveAdminTheme(string $theme): void { $active_admin_theme = Option::where("key", "active_admin_theme")->first(); - $active_admin_theme->value = $theme; + Debug::prn(getConst($theme)); + $active_admin_theme->value = getConst($theme); $active_admin_theme->save(); } @@ -44,6 +45,7 @@ class AdminThemeService public function getAdminThemeInfo(string $theme): false|array|string { $info = []; + $theme = getConst($theme); $info['path'] = $theme; if (file_exists($theme . "/manifest.json")){ $manifest = file_get_contents($theme . "/manifest.json"); diff --git a/kernel/widgets/MenuWidget.php b/kernel/widgets/MenuWidget.php index a0f3aaf..52dfe62 100644 --- a/kernel/widgets/MenuWidget.php +++ b/kernel/widgets/MenuWidget.php @@ -10,7 +10,7 @@ class MenuWidget extends Widget public function run(): void { - $menu = Menu::where("parent_id", 0)->get(); + $menu = Menu::where("parent_id", 0)->get()->sortBy("priority"); $this->cgView->render('/admin/menu.php', ['menu' => $menu]); }