Skip to content

Commit

Permalink
bugs fixed penamaan class dengan 2 kata
Browse files Browse the repository at this point in the history
  • Loading branch information
manusiakemos committed Aug 24, 2024
1 parent eba225a commit ce1ea19
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 75 deletions.
75 changes: 37 additions & 38 deletions resources/views/_helper_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,80 @@
@foreach ($fields as $field)
@switch($field['type'])
@case('boolean')
<wirex-toggle lg
wire:key="{{ $field['column'] }}"
left-label="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('file')
<xxx-inputs.filepond
<wirex-inputs.filepond
wire:key="{{ $field['column'] }}"
id="{{ $field['column'] }}" wire:model.live="myFile"/>
@break
@case('date')
<xxx-datetime-picker
<wirex-datetime-picker
wire:key="{{ $field['column'] }}"
time-format="24" :without-timezone="true" :without-time="true" label="{{ $field['label'] }}"
placeholder="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('datetime')
<xxx-datetime-picker
<wirex-datetime-picker
wire:key="{{ $field['column'] }}"
time-format="24" :without-timezone="true" :without-time="true" label="{{ $field['label'] }}"
placeholder="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('time')
<xxx-datetime-picker time-format="24" :without-timezone="true" :without-time="false"
label="{{ $field['label'] }}"
placeholder="{{ $field['label'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-datetime-picker time-format="24" :without-timezone="true" :without-time="false"
label="{{ $field['label'] }}"
placeholder="{{ $field['label'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('longtext')
<xxx-inputs.editor wire:key="{{ $field['column'] }}" id="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-inputs.editor wire:key="{{ $field['column'] }}" id="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('select')
<xxx-select label="{{ $field['label'] }}"
placeholder="Pilih salah satu"
wire:key="{{ $field['column'] }}"
:options="{{ __('$options') }}['{{ $field['column'] }}']"
option-label="{{ $field['label_column'] }}"
option-value="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-select label="{{ $field['label'] }}"
placeholder="Pilih salah satu"
wire:key="{{ $field['column'] }}"
:options="{{ __('$options') }}['{{ $field['column'] }}']"
option-label="{{ $field['label_column'] }}"
option-value="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('string')
<xxx-input label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-input label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('text')
<xxx-textarea label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-textarea label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('integer')
<xxx-input type="number" step="1" label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-input type="number" step="1" label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('double' || 'float')
<xxx-input type="text" label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-input label="{{ $field['label'] }}" placeholder="{{ $field['label'] }}"
wire:key="{{ $field['column'] }}"
wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('radio')
<xxx--radio
<wirex-radio
wire:key="{{ $field['column'] }}"
label="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break

@case('tinyint')
<xxx-toggle lg
wire:key="{{ $field['column'] }}"
left-label="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@case('boolean')
<xxx-toggle lg
wire:key="{{ $field['column'] }}"
left-label="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
<wirex-toggle lg
wire:key="{{ $field['column'] }}"
left-label="{{ $field['label'] }}" wire:model="{{ $model }}.{{ $field['column'] }}"/>
@break
@endswitch
@endforeach
52 changes: 26 additions & 26 deletions src/Console/WireCrudConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WireCrudConsole extends Command

protected string $className;

protected string $classNameLower;
protected string $classNameCamel;

protected string $classNameSpace;

Expand All @@ -53,9 +53,9 @@ public function handle(): bool
{
//ask to use uuid
$this->uuid = select(
label:'ID is uuid',
options:['yes', 'no'],
default:config('wirecrud.uuid') ? 'yes' : 'no',
label: 'ID is uuid',
options: ['yes', 'no'],
default: config('wirecrud.uuid') ? 'yes' : 'no',
);
$tableName = text(label: 'table name on database:', required: true);
$columns = Schema::getColumnListing($tableName);
Expand All @@ -64,7 +64,7 @@ public function handle(): bool

return false;
}
$className = text(label: 'class name:', default: Str::ucfirst($tableName), required: true);
$className = text(label: 'class name:', default: Str::studly($tableName), required: true);
$pageType = select(
label: 'Form Type',
options: ['modal', 'page'],
Expand Down Expand Up @@ -141,7 +141,7 @@ public function handle(): bool
if (Str::contains(haystack: $column, needles: 'id') || Str::contains(haystack: $column, needles: '_by') && $keyType == 'foreign') {
$label = Str::replace(search: 'id', replace: '', subject: $column);
} else {
$label = Str::replace('_', ' ',Str::snake($column, ' '));
$label = Str::replace('_', ' ', Str::snake($column, ' '));
}

$fields->push([
Expand All @@ -158,9 +158,9 @@ public function handle(): bool
Log::debug('fields', $fields->toArray());
$this->fields = $fields;
$this->className = $className;
$this->classNameLower = strtolower(Str::camel($className));
$this->classNameSlug = strtolower(Str::slug(Str::snake($className, '-')));
$this->classNameSpace = Str::replace('_', ' ', Str::title($className));
$this->classNameSpace = Str::of($className)->headline();
$this->classNameCamel = Str::of($this->classNameSpace)->camel();
$this->classNameSlug = Str::of($this->classNameSpace)->slug();
$this->table = $tableName;
$this->isModal = $pageType == 'modal';
$this->hasUpload = $hasUpload;
Expand Down Expand Up @@ -310,16 +310,16 @@ private function generateLivewire(): void
$useTraitFile = View::make('wirecrud::_use-trait')->render();
$traitFile = 'use UploadFileTrait,WithFileUploads;';
$storeUpload = View::make('wirecrud::_store-upload', [
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();
$updateUpload = View::make('wirecrud::_update-upload', [
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();

$deleteUpload = View::make('wirecrud::_delete-upload', [
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
'uploadColumn' => $this->fields->where('type', '=', 'file')->first(),
])->render();
} else {
Expand All @@ -336,13 +336,13 @@ private function generateLivewire(): void

$handleRequest = View::make('wirecrud::_helper_handle_request', [
'fields' => $this->fields,
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
])->render();

$validate = View::make('wirecrud::_helper_validate_generator', [
'hasUpload' => $this->hasUpload,
'field_validate' => $this->fields->where('key_type', '<>', 'primary')->where('type', '<>', 'file'),
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
])->render();

$generatedProps = View::make('wirecrud::_helper_props', [
Expand All @@ -351,7 +351,7 @@ private function generateLivewire(): void

$columns = View::make('wirecrud::_helper_columns', [
'fields' => $this->fields->where('key_type', '<>', 'primary'),
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
])->render();

$stubTemplate = [
Expand Down Expand Up @@ -382,7 +382,7 @@ private function generateLivewire(): void
$traitFile,
$this->primaryKey,
$this->className,
$this->classNameLower,
$this->classNameCamel,
$handleRequest,
$validate,
$columns,
Expand Down Expand Up @@ -441,7 +441,7 @@ private function generateViewPage(): void
$this->primaryKey,
$this->className,
$this->classNameSlug,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSpace,
];
if ($this->isModal) {
Expand All @@ -461,9 +461,9 @@ public function generateFormView(): void
{
$forms = View::make('wirecrud::_helper_form', [
'fields' => $this->fields->where('key_type', '<>', 'primary'),
'model' => $this->classNameLower,
'model' => $this->classNameCamel,
])->render();
$forms = str_replace('xxx', 'x', $forms);
$forms = str_replace('wirex', 'x', $forms);

$search = [
'{@pk}',
Expand All @@ -480,7 +480,7 @@ public function generateFormView(): void
$this->table,
$forms,
$this->classNameSlug,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSpace,
];

Expand Down Expand Up @@ -510,7 +510,7 @@ public function generateActionView(): void
$stubReplaceTemplate = [
$this->primaryKey,
$this->className,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSlug,
];
if ($this->isModal) {
Expand All @@ -537,13 +537,13 @@ public function generateNavigationView(): void
$replace = [
$this->primaryKey,
$this->className,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSlug,
$this->classNameSpace,
];
$subject = file_get_contents($this->getStub('nav.stub'));
$template = str_replace($search, $replace, $subject);
$path = resource_path("views/livewire/$this->classNameLower");
$path = resource_path("views/livewire/$this->classNameCamel");
File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);
$pathToWrite = resource_path("views/livewire/$this->classNameSlug/_$this->classNameSlug-nav.blade.php");
file_put_contents($pathToWrite, $template);
Expand Down Expand Up @@ -590,7 +590,7 @@ public function generateApi(): void
{
$validate = View::make('wirecrud::_helper_validate_generator_api', [
'field_validate' => $this->fields->where('key_type', '<>', 'primary'),
'classNameLower' => $this->classNameLower,
'classNameLower' => $this->classNameCamel,
])->render();

$stubTemplate = [
Expand All @@ -601,7 +601,7 @@ public function generateApi(): void
];
$stubReplaceTemplate = [
$this->className,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSlug,
$validate,
];
Expand All @@ -623,7 +623,7 @@ public function generateSortable(): void
];
$stubReplaceTemplate = [
$this->className,
$this->classNameLower,
$this->classNameCamel,
$this->classNameSlug,
$this->primaryKey,
];
Expand Down
19 changes: 8 additions & 11 deletions src/Console/stubs/livewire-modal.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ use Livewire\Component;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use App\Services\{@className}\{@className}Service;
use App\Repositories\{@className}\{@className}Repository;
use WireUi\Traits\Actions;
{@useTraitFile}

class {@className}Page extends Component
{
{@traitFile}

protected $listeners = ['create', 'edit'];
protected {@className}Service ${@classNameLower}Service;
protected {@className}Repository ${@classNameLower}Repository;

public mixed $myFile = null;

Expand All @@ -25,9 +22,9 @@ class {@className}Page extends Component
public bool $showModalForm = false;
{@options}

public function boot({@className}Service ${@classNameLower}Service): void
public function boot({@className}Repository ${@classNameLower}Repository): void
{
$this->{@classNameLower}Service = ${@classNameLower}Service;
$this->{@classNameLower}Repository = ${@classNameLower}Repository;
}

public function mount(): void
Expand Down Expand Up @@ -71,7 +68,7 @@ class {@className}Page extends Component
);
$this->updateMode = false;
{@storeUpload}
$this->{@classNameLower}Service->create($data['{@classNameLower}']);
$this->{@classNameLower}Repository->create($data['{@classNameLower}']);
$this->reset(['{@classNameLower}', 'showModalForm']);
$this->notification()->send([
'title' => '{@classNameSpace} berhasil ditambahkan',
Expand All @@ -85,7 +82,7 @@ class {@className}Page extends Component
$this->reset(['{@classNameLower}', 'showModalForm','myFile']);
$this->updateMode = true;
$this->setOptions();
$this->{@classNameLower} = $this->{@classNameLower}Service->find($id)->toArray();
$this->{@classNameLower} = $this->{@classNameLower}Repository->find($id)->toArray();
$this->showModalForm = true;
}

Expand All @@ -97,7 +94,7 @@ class {@className}Page extends Component
);
{@updateUpload}
if ($this->{@classNameLower}['{@primaryKey}'] && $this->updateMode) {
$this->{@classNameLower}Service->update($this->{@classNameLower}['{@primaryKey}'],$data['{@classNameLower}']);
$this->{@classNameLower}Repository->update($this->{@classNameLower}['{@primaryKey}'],$data['{@classNameLower}']);
} else {
abort('403', '{@className} Not Found');
}
Expand All @@ -111,7 +108,7 @@ class {@className}Page extends Component

public function destroy($id): void
{
$data = $this->{@classNameLower}Service->find($id);
$data = $this->{@classNameLower}Repository->find($id);
{@deleteUpload}
$data->delete();
$this->notification()->send([
Expand Down

0 comments on commit ce1ea19

Please sign in to comment.