feat(custom-field): tambahkan kolom label dan urutan prioritas
- Menambahkan kolom 'label' pada tabel custom_fields. - Menambahkan kolom 'urutan_prioritas' pada tabel custom_fields. - Memperbarui model CustomField untuk menyertakan kolom baru. - Memperbarui form input untuk label dan urutan prioritas di tampilan create dan index. - Menambahkan validasi untuk label dan urutan prioritas di CustomFieldRequest.
This commit is contained in:
@@ -40,13 +40,15 @@ class CustomFieldController extends Controller
|
|||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
return view('lpj::custom_fields.create');
|
$urutan_prioritas = CustomField::max('urutan_prioritas')+1;
|
||||||
|
return view('lpj::custom_fields.create', compact('urutan_prioritas'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$customField = CustomField::find($id);
|
$customField = CustomField::find($id);
|
||||||
return view('lpj::custom_fields.create', compact('customField'));
|
$urutan_prioritas = $customField->urutan_prioritas ?? CustomField::max('urutan_prioritas')+1;
|
||||||
|
return view('lpj::custom_fields.create', compact('customField', 'urutan_prioritas' ));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(CustomFieldRequest $request, $id)
|
public function update(CustomFieldRequest $request, $id)
|
||||||
@@ -96,6 +98,7 @@ class CustomFieldController extends Controller
|
|||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where(function ($q) use ($search) {
|
||||||
$q->where('name', 'LIKE', "%$search%");
|
$q->where('name', 'LIKE', "%$search%");
|
||||||
|
$q->orWhere('label', 'LIKE', "%$search%");
|
||||||
$q->orWhere('type', 'LIKE', "%$search%");
|
$q->orWhere('type', 'LIKE', "%$search%");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace Modules\Lpj\Http\Requests;
|
namespace Modules\Lpj\Http\Requests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Modules\Lpj\Models\customField;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class CustomFieldRequest extends FormRequest
|
class CustomFieldRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -14,6 +16,12 @@ class CustomFieldRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'name' => 'required|max:255',
|
'name' => 'required|max:255',
|
||||||
'type' => 'required|in:text,select,radio,checkbox',
|
'type' => 'required|in:text,select,radio,checkbox',
|
||||||
|
'label' => 'nullable|max:255',
|
||||||
|
'urutan_prioritas' => [
|
||||||
|
'nullable',
|
||||||
|
'integer',
|
||||||
|
Rule::unique('custom_fields')->ignore($this->route('custom_field')),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,5 +37,22 @@ class CustomFieldRequest extends FormRequest
|
|||||||
if(!$this->type){
|
if(!$this->type){
|
||||||
$this->merge(['type' => 'text']);
|
$this->merge(['type' => 'text']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->urutan_prioritas) {
|
||||||
|
$maxPrioritas = CustomField::max('urutan_prioritas') ?? 0;
|
||||||
|
$this->merge(['urutan_prioritas' => $maxPrioritas + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom messages for validator errors.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function messages()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'urutan_prioritas.unique' => 'Urutan prioritas sudah digunakan. Silakan pilih nomor lain.',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ class customField extends Base
|
|||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'type'
|
'type',
|
||||||
|
'urutan_prioritas',
|
||||||
|
'label'
|
||||||
];
|
];
|
||||||
|
|
||||||
// protected static function newFactory(): CustomFieldFactory
|
// protected static function newFactory(): CustomFieldFactory
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('custom_fields', function (Blueprint $table) {
|
||||||
|
$table->integer('urutan_prioritas')->nullable()->after('type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('custom_fields', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('urutan_prioritas');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('custom_fields', function (Blueprint $table) {
|
||||||
|
$table->string('label')->nullable()->after('name');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('custom_fields', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('label');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -39,6 +39,17 @@
|
|||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
Label
|
||||||
|
</label>
|
||||||
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
|
<input class="input @error('label') border-danger bg-danger-light @enderror" type="text" name="label" value="{{ $customField->label ?? '' }}">
|
||||||
|
@error('label')
|
||||||
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56">
|
<label class="form-label max-w-56">
|
||||||
Type
|
Type
|
||||||
@@ -55,6 +66,17 @@
|
|||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
Urutan Prioritas
|
||||||
|
</label>
|
||||||
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
|
<input class="input @error('urutan_prioritas') border-danger bg-danger-light @enderror" type="number" name="urutan_prioritas" value="{{ $customField->urutan_prioritas ?? $urutan_prioritas }}">
|
||||||
|
@error('urutan_prioritas')
|
||||||
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<button type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary">
|
||||||
Save
|
Save
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
<span class="sort"> <span class="sort-label"> Type </span>
|
<span class="sort"> <span class="sort-label"> Type </span>
|
||||||
<span class="sort-icon"> </span> </span>
|
<span class="sort-icon"> </span> </span>
|
||||||
</th>
|
</th>
|
||||||
|
<th class="min-w-[250px]" data-datatable-column="urutan_prioritas">
|
||||||
|
<span class="sort"> <span class="sort-label"> Urutan Prioritas </span>
|
||||||
|
<span class="sort-icon"> </span> </span>
|
||||||
|
</th>
|
||||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -113,12 +117,15 @@
|
|||||||
return checkbox.outerHTML.trim();
|
return checkbox.outerHTML.trim();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
name: {
|
label: {
|
||||||
title: 'Custom Field',
|
title: 'Custom Field',
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
title: 'Type',
|
title: 'Type',
|
||||||
},
|
},
|
||||||
|
urutan_prioritas: {
|
||||||
|
title: 'Urutan Prioritas',
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
title: 'Status',
|
title: 'Status',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user