Skip to content

Commit

Permalink
👍 Make new theme UI
Browse files Browse the repository at this point in the history
  • Loading branch information
juzaweb committed Aug 12, 2023
1 parent 0a0948f commit b9e3921
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 24 deletions.
4 changes: 2 additions & 2 deletions modules/CMS/Support/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public function getInfo(bool $assoc = false): array|Collection

$configPath = $this->path . '/theme.json';

$changelogPath = $this->path . '/changelog.yml';
// $changelogPath = $this->path . '/changelog.yml';

$config = [];

if (file_exists($configPath)) {
$config = ReadConfig::load($configPath)->all();
}

$config['changelog'] = ReadConfig::load($changelogPath)->all();
// $config['changelog'] = ReadConfig::load($changelogPath)->all();

$config['screenshot'] = $this->getScreenshot();

Expand Down
4 changes: 2 additions & 2 deletions modules/CMS/Support/Theme/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions modules/DevTool/Commands/Theme/ThemeGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ThemeGeneratorCommand extends Command
*
* @var string
*/
protected $name = 'theme:make {name}';
protected $name = 'theme:make';

/**
* The console command description.
Expand Down Expand Up @@ -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'] = '';
}

Expand Down Expand Up @@ -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'],
];
}
}
12 changes: 5 additions & 7 deletions modules/DevTool/Http/Controllers/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}";
Expand All @@ -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')
);
}

Expand All @@ -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
);
Expand Down
11 changes: 9 additions & 2 deletions modules/DevTool/routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
);

Expand Down
21 changes: 20 additions & 1 deletion resources/js/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> } | undefined {
console.log(response?.response);
// CMS json data
if (response?.data) {
if (response.data.message) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/pages/dev-tool/components/top-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
18 changes: 13 additions & 5 deletions resources/js/pages/dev-tool/theme/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
Expand All @@ -15,15 +15,23 @@ export default function Create() {
}>();
const [outputBuffer, setOutputBuffer] = useState<string>();

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));
});
}

Expand All @@ -37,7 +45,7 @@ export default function Create() {
<div className="col-md-12">

{message && (
<div className={`alert alert-${message.status ? 'success' : 'danger' } jw-message`}>
<div className={`alert alert-${message.status ? 'success' : 'danger'} jw-message`}>
{message.message}
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Admin>

Expand Down

0 comments on commit b9e3921

Please sign in to comment.