Skip to content

Commit

Permalink
penambahan fitur
Browse files Browse the repository at this point in the history
- enable config  for default value on generate question
- require wireui
  • Loading branch information
manusiakemos committed May 12, 2024
1 parent 3eb9570 commit 68c93cf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 29 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"laravel/framework": "^10.0",
"livewire/livewire": "^3.0",
"yaza/laravel-repository-service": "^4.0",
"rappasoft/laravel-livewire-tables": "^3.0"
"rappasoft/laravel-livewire-tables": "^3.0",
"wireui/wireui": "^1.19"
},
"require-dev": {
"orchestra/testbench": "^8.0",
Expand Down
7 changes: 6 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
* You can place your custom package configuration in here.
*/
return [

'model' => true,
'livewire' => true,
'repository' => true,
'service' => true,
'view' => true,
'api' => true,
];
69 changes: 52 additions & 17 deletions src/Console/WireCrudConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class WireCrudConsole extends Command

protected function getStub($filename): string
{
$path = base_path('stubs/vendor/manusiakemos/wirecrud/'.$filename);
$path = base_path('stubs/vendor/manusiakemos/wirecrud/' . $filename);
if (File::exists($path)) {
return $path;
}

return __DIR__.'/stubs/'.$filename;
return __DIR__ . '/stubs/' . $filename;
}

public function handle(): bool
Expand All @@ -63,12 +63,36 @@ public function handle(): bool
options: ['modal', 'page'],
default: 'modal'
);
$generateModel = select(
label: 'Generate Api',
options: ['yes', 'no'],
default: config('wirecrud.model') ? 'yes' : 'no'
);
$generateLivewire = select(
label: 'Generate Livewire',
options: ['yes', 'no'],
default: config('wirecrud.livewire') ? 'yes' : 'no'
);
$generateRepository = select(
label: 'Generate Repository',
options: ['yes', 'no'],
default: config('wirecrud.repository') ? 'yes' : 'no'
);
$generateService = select(
label: 'Generate Service',
options: ['yes', 'no'],
default: config('wirecrud.service') ? 'yes' : 'no'
);
$generateView = select(
label: 'Generate View',
options: ['yes', 'no'],
default: config('wirecrud.view') ? 'yes' : 'no'
);
$generateApi = select(
label: 'Generate Api',
options: ['yes', 'no'],
default: 'yes'
default: config('wirecrud.api') ? 'yes' : 'no'
);

$generateSortable = select(
label: 'Generate Sortable',
options: ['yes', 'no'],
Expand All @@ -82,21 +106,21 @@ public function handle(): bool
$keyType = false;
if (Str::contains(haystack: $column, needles: '_id') || Str::contains(haystack: $column, needles: '_by')) {
$keyType = select(
label: 'choose '.$column.' key type',
label: 'choose ' . $column . ' key type',
options: ['primary', 'foreign', 'false'],
default: 'primary'
);
if ($keyType == 'foreign') {
$type = 'select';
$labelColumn = text(label: $column.' label column for select component', default: 'name', required: true);
$labelColumn = text(label: $column . ' label column for select component', default: 'name', required: true);
} elseif ($keyType == 'primary') {
$type = 'invisible';
}
}
$isUpload = 'no';
if (Str::contains(haystack: $column, needles: 'image') || Str::contains(haystack: $column, needles: 'file')) {
$isUpload = select(
label: 'Is '.$column.' a file upload',
label: 'Is ' . $column . ' a file upload',
options: ['yes', 'no'],
default: 'yes'
);
Expand All @@ -106,7 +130,7 @@ public function handle(): bool
}
}

if (! Str::contains(haystack: $column, needles: '_at')) {
if (!Str::contains(haystack: $column, needles: '_at')) {
if (Str::contains(haystack: $column, needles: '_id') && $keyType == 'foreign') {
$label = Str::replace(search: '_id', replace: '', subject: $column);
} else {
Expand Down Expand Up @@ -136,12 +160,23 @@ public function handle(): bool

$this->setPrimaryKey();

$this->generateModel();
$this->generateRepository();
$this->generateService();
$this->generateRepository();
$this->generateLivewire();
$this->generateView();
if ($generateModel == 'yes') {
$this->generateModel();
}

if ($generateService == 'yes') {
$this->generateService();
$this->generateRepository();
}
if ($generateRepository == 'yes' && $generateService == 'no') {
$this->generateRepository();
}
if ($generateLivewire) {
$this->generateLivewire();
}
if ($generateView) {
$this->generateView();
}
$this->generateSeeder();
$this->generateFactory();
if ($generateApi == 'yes') {
Expand Down Expand Up @@ -206,7 +241,7 @@ public function generateRepository(): void
$stub_template = file_get_contents($this->getStub('repository.stub'));
$modelTemplate = str_replace($stubTemplate, $stubReplaceTemplate, $stub_template);

$path = app_path('/Repositories/'.$this->className);
$path = app_path('/Repositories/' . $this->className);
File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);

file_put_contents(app_path("Repositories/$this->className/{$this->className}Repository.php"), $modelTemplate);
Expand Down Expand Up @@ -238,7 +273,7 @@ public function generateService(): void
$stub_template = file_get_contents($this->getStub('service.stub'));
$modelTemplate = str_replace($stubTemplate, $stubReplaceTemplate, $stub_template);

$path = app_path('/Services/'.$this->className);
$path = app_path('/Services/' . $this->className);
File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);

file_put_contents(app_path("Services/$this->className/{$this->className}Service.php"), $modelTemplate);
Expand Down Expand Up @@ -355,7 +390,7 @@ private function generateLivewire(): void
$path = app_path("/Livewire/$this->className");
File::isDirectory($path) or File::makeDirectory($path, 0775, true, true);
file_put_contents(app_path("/Livewire/$this->className/{$this->className}Page.php"), $template);
if (! $this->isModal) {
if (!$this->isModal) {
$templateFile = file_get_contents($this->getStub('livewire-form.stub'));
$template = str_replace($stubTemplate, $stubReplaceTemplate, $templateFile);
file_put_contents(app_path("/Livewire/$this->className/{$this->className}FormPage.php"), $template);
Expand Down
4 changes: 2 additions & 2 deletions src/Console/stubs/action-modal.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex justify-center items-center gap-1">
<x-button.circle primary icon="pencil" wire:click="$dispatchTo('{@classNameSlug}.{@classNameSlug}-page', 'edit',{ id : {{$row->{@primaryKey}}} })"/>
<x-button.circle negative icon="trash" wire:click="$dispatch('confirmDestroy',{ id : {{$row->{@primaryKey}}} })"/>
<x-button.circle primary icon="pencil" wire:click="$parent.edit({ id : {{$row->{@primaryKey}}} })"/>
<x-button.circle negative icon="trash" wire:click="$dispatchTo('{@classNameSlug}.{@classNameSlug}-page','confirmDestroy',{ id : {{$row->{@primaryKey}}} })"/>
</div>
13 changes: 5 additions & 8 deletions src/Console/stubs/form-modal.stub
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<x-modal.card max-width="4xl" blur wire:model.defer="showModalForm" align="start">
<x-modal.card blur wire:model.defer="showModalForm" align="start">
<form action="#" wire:submit.prevent="save" class="relative flex flex-col gap-4">

<div class="flex flex-col gap-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
{@forms}
</div>

<div class="md:flex place-content-end py-4 gap-1">
<x-button secondary x-on:click="show = false">
{{ __('messages.close') }}
</x-button>
<x-button spinner="save" loading-delay="short" type="submit" primary>
{{ $updateMode ? __('messages.save_changes') : __('messages.save') }}
</x-button>
<x-button secondary x-on:click="show = false" label="Tutup"/>
<x-button spinner="save" loading-delay="short" type="submit" primary
label=" {{ $updateMode ? __('messages.save_changes') : __('messages.save') }}"/>
</div>
</form>
</x-modal.card>

0 comments on commit 68c93cf

Please sign in to comment.