From b9e392199ef53989fddb6b7a85a788d80820a4ce Mon Sep 17 00:00:00 2001 From: Juzaweb Date: Sat, 12 Aug 2023 12:08:00 +0700 Subject: [PATCH] :+1: Make new theme UI --- modules/CMS/Support/Theme.php | 4 ++-- modules/CMS/Support/Theme/Theme.php | 4 ++-- .../Commands/Theme/ThemeGeneratorCommand.php | 6 +++--- .../Http/Controllers/ThemeController.php | 12 +++++------ modules/DevTool/routes/admin.php | 11 ++++++++-- resources/js/helpers/functions.ts | 21 ++++++++++++++++++- .../pages/dev-tool/components/top-options.tsx | 2 +- resources/js/pages/dev-tool/theme/create.tsx | 18 +++++++++++----- .../dev-tool/theme/{index.tsx => edit.tsx} | 2 +- 9 files changed, 56 insertions(+), 24 deletions(-) rename resources/js/pages/dev-tool/theme/{index.tsx => edit.tsx} (81%) diff --git a/modules/CMS/Support/Theme.php b/modules/CMS/Support/Theme.php index 6a9927add..f34a96215 100644 --- a/modules/CMS/Support/Theme.php +++ b/modules/CMS/Support/Theme.php @@ -136,7 +136,7 @@ public function getInfo(bool $assoc = false): array|Collection $configPath = $this->path . '/theme.json'; - $changelogPath = $this->path . '/changelog.yml'; + // $changelogPath = $this->path . '/changelog.yml'; $config = []; @@ -144,7 +144,7 @@ public function getInfo(bool $assoc = false): array|Collection $config = ReadConfig::load($configPath)->all(); } - $config['changelog'] = ReadConfig::load($changelogPath)->all(); + // $config['changelog'] = ReadConfig::load($changelogPath)->all(); $config['screenshot'] = $this->getScreenshot(); diff --git a/modules/CMS/Support/Theme/Theme.php b/modules/CMS/Support/Theme/Theme.php index e32ce39ec..678287718 100644 --- a/modules/CMS/Support/Theme/Theme.php +++ b/modules/CMS/Support/Theme/Theme.php @@ -137,11 +137,11 @@ public function getInfo(string $theme): bool|Config { $themePath = $this->getPath($theme); $themeConfigPath = $themePath . '/theme.json'; - $themeChangelogPath = $themePath . '/changelog.yml'; + // $themeChangelogPath = $themePath . '/changelog.yml'; if (file_exists($themeConfigPath)) { $themeConfig = Config::load($themeConfigPath); - $themeConfig['changelog'] = Config::load($themeChangelogPath)->all(); + // $themeConfig['changelog'] = Config::load($themeChangelogPath)->all(); $themeConfig['path'] = $themePath; $themeConfig['screenshot'] = $this->getScreenshot($theme); diff --git a/modules/DevTool/Commands/Theme/ThemeGeneratorCommand.php b/modules/DevTool/Commands/Theme/ThemeGeneratorCommand.php index 8f4b0b952..e7000d5cb 100644 --- a/modules/DevTool/Commands/Theme/ThemeGeneratorCommand.php +++ b/modules/DevTool/Commands/Theme/ThemeGeneratorCommand.php @@ -16,7 +16,7 @@ class ThemeGeneratorCommand extends Command * * @var string */ - protected $name = 'theme:make {name}'; + protected $name = 'theme:make'; /** * The console command description. @@ -104,7 +104,7 @@ public function generateThemeInfo(): void $this->theme['description'] = $this->option('description') ?? Str::ucfirst($this->theme['name']).' description'; $this->theme['author'] = $this->option('author'); - $this->theme['version'] = $this->option('version'); + $this->theme['version'] = $this->option('ver'); $this->theme['parent'] = ''; } @@ -214,7 +214,7 @@ protected function getOptions(): array ['title', null, InputOption::VALUE_OPTIONAL, 'Theme Title'], ['description', null, InputOption::VALUE_OPTIONAL, 'Theme Description'], ['author', null, InputOption::VALUE_OPTIONAL, 'Theme Author', 'Author Name'], - ['version', null, InputOption::VALUE_OPTIONAL, 'Theme Version', '1.0'], + ['ver', null, InputOption::VALUE_OPTIONAL, 'Theme Version', '1.0'], ]; } } diff --git a/modules/DevTool/Http/Controllers/ThemeController.php b/modules/DevTool/Http/Controllers/ThemeController.php index b243e1c5a..bd0d05237 100644 --- a/modules/DevTool/Http/Controllers/ThemeController.php +++ b/modules/DevTool/Http/Controllers/ThemeController.php @@ -42,7 +42,6 @@ public function index(Request $request): View|Response public function edit(Request $request, string $name): View|Response { - die; $theme = $this->themeRepository->findOrFail($name); $title = "Dev tool for theme: {$theme->getName()}"; @@ -58,11 +57,10 @@ public function edit(Request $request, string $name): View|Response public function create(): View|Response { $title = "Make new themes"; - $configs = $this->getConfigs('themes'); return $this->view( 'cms::backend.dev-tool.theme.create', - compact('configs', 'title') + compact('title') ); } @@ -75,10 +73,10 @@ public function store(StoreRequest $request): JsonResponse|RedirectResponse 'theme:make', [ 'name' => $request->input('name'), - 'title' => $request->input('title'), - 'description' => $request->input('description'), - 'author' => $request->input('author'), - 'version' => $request->input('version'), + '--title' => $request->input('title'), + '--description' => $request->input('description'), + '--author' => $request->input('author'), + '--ver' => $request->input('version'), ], $outputBuffer ); diff --git a/modules/DevTool/routes/admin.php b/modules/DevTool/routes/admin.php index 83501e910..c7e7d1a46 100644 --- a/modules/DevTool/routes/admin.php +++ b/modules/DevTool/routes/admin.php @@ -36,8 +36,15 @@ function () { Route::group( ['prefix' => 'dev-tools/themes'], function () { - Route::resource('/', ThemeController::class) - ->only(['index', 'edit', 'create', 'destroy']); + // Route::resource('/', ThemeController::class) + // ->only(['index', 'edit', 'create', 'destroy']); + + Route::get('/', [ThemeController::class, 'index']); + Route::get('create', [ThemeController::class, 'create']); + Route::post('/', [ThemeController::class, 'store']); + Route::get('{name}/edit', [ThemeController::class, 'edit']); + Route::put('{name}', [ThemeController::class, 'update']); + Route::delete('{name}', [ThemeController::class, 'destroy']); } ); diff --git a/resources/js/helpers/functions.ts b/resources/js/helpers/functions.ts index f8bbb614f..20e8559f4 100644 --- a/resources/js/helpers/functions.ts +++ b/resources/js/helpers/functions.ts @@ -21,7 +21,8 @@ export function admin_url(path: string): string { return '/admin-cp/' + path; } -export function message_in_response(response: any): { status: boolean, message: string } | undefined { +export function message_in_response(response: any): { status: boolean, message: string, errors?: Array } | undefined { + console.log(response?.response); // CMS json data if (response?.data) { if (response.data.message) { @@ -42,6 +43,24 @@ export function message_in_response(response: any): { status: boolean, message: } } + + // Get message validate error axios + if (response?.response) { + if (response.response.data.errors) { + let message = ''; + $.each(response.response.data.errors, function (index, msg) { + message = msg[0]; + return false; + }); + + return { + status: false, + message: message, + errors: response.response.data.errors + }; + } + } + // Get message validate if (response?.responseJSON) { if (response.responseJSON?.errors) { diff --git a/resources/js/pages/dev-tool/components/top-options.tsx b/resources/js/pages/dev-tool/components/top-options.tsx index 7b6670ad5..06d02d1a3 100644 --- a/resources/js/pages/dev-tool/components/top-options.tsx +++ b/resources/js/pages/dev-tool/components/top-options.tsx @@ -32,7 +32,7 @@ export default function TopOptions( let value = e.target.value; localStorage.setItem('current_module', value); - router.visit(admin_url(`dev-tools/${type}/${value}`), {replace: true}); + router.visit(admin_url(`dev-tools/${type}/${value}/edit`), {replace: true}); } const handleOptionChange = (e: any) => { diff --git a/resources/js/pages/dev-tool/theme/create.tsx b/resources/js/pages/dev-tool/theme/create.tsx index 6e6a683a9..892cb5c6e 100644 --- a/resources/js/pages/dev-tool/theme/create.tsx +++ b/resources/js/pages/dev-tool/theme/create.tsx @@ -5,7 +5,7 @@ import Button from "@/components/form/buttons/button"; import Input from "@/components/form/inputs/input"; import Textarea from "@/components/form/inputs/textarea"; import axios from "axios"; -import {admin_url} from "@/helpers/functions"; +import {admin_url, message_in_response} from "@/helpers/functions"; export default function Create() { const [buttonLoading, setButtonLoading] = useState(false); @@ -15,15 +15,23 @@ export default function Create() { }>(); const [outputBuffer, setOutputBuffer] = useState(); - const handleMakeTheme = (e: any ) => { + const handleMakeTheme = (e: any) => { e.preventDefault(); setButtonLoading(true); - axios.post(admin_url(`/dev-tools/themes`), {}).then((res) => { + setOutputBuffer(undefined); + setMessage(undefined); + + let formData: FormData = new FormData(e.target); + + axios.post(admin_url(`dev-tools/themes`), formData).then((res) => { setButtonLoading(false); - setMessage(res.data); + setMessage(message_in_response(res)); setOutputBuffer(res.data.data.output); + }).catch((err) => { + setButtonLoading(false); + setMessage(message_in_response(err)); }); } @@ -37,7 +45,7 @@ export default function Create() {
{message && ( -
+
{message.message}
)} diff --git a/resources/js/pages/dev-tool/theme/index.tsx b/resources/js/pages/dev-tool/theme/edit.tsx similarity index 81% rename from resources/js/pages/dev-tool/theme/index.tsx rename to resources/js/pages/dev-tool/theme/edit.tsx index b9ca19c74..dd2bc7d69 100644 --- a/resources/js/pages/dev-tool/theme/index.tsx +++ b/resources/js/pages/dev-tool/theme/edit.tsx @@ -2,7 +2,7 @@ import TopOptions from "@/pages/dev-tool/components/top-options"; import Admin from "@/layouts/admin"; import {Theme} from "@/types/themes"; -export default function Index({ theme }: { theme: Theme }) { +export default function Edit({ theme }: { theme: Theme }) { return (