Merge pull request #8 from arieeefajar/fix/master-indicator

fix(master-indicator): create store and delete func
This commit is contained in:
Arie Fajar Bachtiar 2025-02-06 21:00:48 +07:00 committed by GitHub
commit 930f079ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 189 additions and 223 deletions

View File

@ -15,34 +15,57 @@ public function index()
return view('master-data.indikator.index', compact('indicators'));
}
public function store(Request $request)
{
$customMessage = [
"name.required" => "Nama wajib diisi",
"name.max" => "Nama maksimal 25 karakter",
"name.string" => "Nama harus berupa string",
"description.required" => "Deskripsi wajib diisi",
"description.max" => "Deskripsi maksimal 50 karakter",
"description.string" => "Deskripsi harus berupa string",
];
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:25',
'description' => 'required|string|max:50',
], $customMessage);
if ($validator->fails()) {
toast($validator->messages()->all()[0], 'error')->position('top-right')->autoclose(3000);
return redirect()->back()->withInput();
}
$indicator = new Indicator();
$indicator->name = $request->name;
$indicator->description = $request->description;
try {
$indicator->save();
toast('Data berhasil disimpan', 'success')->position('top-right')->autoclose(3000);
return redirect()->back();
} catch (\Throwable $th) {
toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000);
return redirect()->back();
}
}
public function update(Request $request, $id)
{
$customMessage = [
"name.required" => "Nama wajib diisi",
"name.max" => "Nama maksimal 255 karakter",
"name.max" => "Nama maksimal 25 karakter",
"name.string" => "Nama harus berupa string",
"description.required" => "Deskripsi wajib diisi",
"description.max" => "Deskripsi maksimal 255 karakter",
"description.max" => "Deskripsi maksimal 50 karakter",
"description.string" => "Deskripsi harus berupa string",
"ideal_min.required" => "Nilai ideal minimum wajib diisi",
"ideal_min.numeric" => "Nilai ideal minimum harus berupa angka",
"ideal_max.required" => "Nilai ideal maksimum wajib diisi",
"ideal_max.numeric" => "Nilai ideal maksimum harus berupa angka",
"unit.required" => "Unit wajib diisi",
"unit.max" => "Unit maksimal 255 karakter",
"unit.string" => "Unit harus berupa string",
];
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255',
'description' => 'required|string|max:255',
'ideal_min' => 'required|numeric',
'ideal_max' => 'required|numeric',
'unit' => 'required|string|max:255',
'name' => 'required|string|max:25',
'description' => 'required|string|max:50',
], $customMessage);
if ($validator->fails()) {
@ -53,9 +76,6 @@ public function update(Request $request, $id)
$indicator = Indicator::find($id);
$indicator->name = $request->name;
$indicator->description = $request->description;
$indicator->ideal_min = $request->ideal_min;
$indicator->ideal_max = $request->ideal_max;
$indicator->unit = $request->unit;
try {
$indicator->save();
@ -66,4 +86,17 @@ public function update(Request $request, $id)
return redirect()->back();
}
}
public function destroy($id)
{
$indicator = Indicator::find($id);
try {
$indicator->delete();
toast('Data berhasil dihapus', 'success')->position('top-right')->autoclose(3000);
return redirect()->back();
} catch (\Throwable $th) {
toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000);
return redirect()->back();
}
}
}

View File

@ -13,15 +13,13 @@ class EvaluationDetail extends Model
protected $primaryKey = 'id';
protected $guarded = [];
// protected $fillable = [
// 'evaluation_id',
// 'indicator_id',
// 'value',
// 'cf',
// ];
public function evaluation()
{
return $this->belongsTo(Evalutaion::class);
}
public function indicator()
{
return $this->belongsTo(Indicator::class);
}
}

View File

@ -9,7 +9,9 @@ class Evalutaion extends Model
{
use HasFactory;
protected $table = 'evaluations';
protected $table = 'evaluation';
protected $guarded = [];
public function land()
{

View File

@ -10,12 +10,5 @@ class Indicator extends Model
use HasFactory;
protected $table = 'indicators';
protected $fillable = [
'name',
'description',
'ideal_min',
'ideal_max',
'unit',
];
protected $guarded = [];
}

View File

@ -9,14 +9,11 @@ class Rule extends Model
{
use HasFactory;
protected $table = 'rules';
protected $table = 'rule';
protected $fillable = [
'indicator_id',
'range_min',
'range_max',
'mb',
'md',
];
public function indicator()

View File

@ -14,7 +14,7 @@
|
*/
'enabled' => env('DEBUGBAR_ENABLED', true),
'enabled' => env('DEBUGBAR_ENABLED', false),
'hide_empty_tabs' => false, // Hide tabs until they have content
'except' => [
'telescope*',

View File

@ -15,9 +15,6 @@ public function up(): void
$table->id();
$table->string('name');
$table->string('description');
$table->float('ideal_min');
$table->float('ideal_max');
$table->string('unit');
$table->timestamps();
});
}

View File

@ -11,17 +11,14 @@
*/
public function up(): void
{
Schema::create('rules', function (Blueprint $table) {
Schema::create('rule', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('indicator_id');
$table->float('range_min');
$table->float('range_max');
$table->float('mb');
$table->float('md');
$table->timestamps();
});
Schema::table('rules', function (Blueprint $table) {
Schema::table('rule', function (Blueprint $table) {
$table->foreign('indicator_id')->references('id')->on('indicators')->onDelete('cascade');
});
}
@ -31,6 +28,6 @@ public function up(): void
*/
public function down(): void
{
Schema::dropIfExists('rules');
Schema::dropIfExists('rule');
}
};

View File

@ -11,13 +11,15 @@
*/
public function up(): void
{
Schema::create('evaluations', function (Blueprint $table) {
Schema::create('evaluation', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('land_id');
$table->float('cf_value');
$table->string('conclusion');
$table->timestamps();
});
Schema::table('evaluations', function (Blueprint $table) {
Schema::table('evaluation', function (Blueprint $table) {
$table->foreign('land_id')->references('id')->on('land')->onDelete('cascade');
});
}
@ -27,6 +29,6 @@ public function up(): void
*/
public function down(): void
{
Schema::dropIfExists('evaluations');
Schema::dropIfExists('evaluation');
}
};

View File

@ -15,13 +15,12 @@ public function up(): void
$table->id();
$table->unsignedBigInteger('evaluation_id');
$table->unsignedBigInteger('indicator_id');
$table->float('value');
$table->float('cf');
$table->float('md_value');
$table->timestamps();
});
Schema::table('evaluation_details', function (Blueprint $table) {
$table->foreign('evaluation_id')->references('id')->on('evaluations')->onDelete('cascade');
$table->foreign('evaluation_id')->references('id')->on('evaluation')->onDelete('cascade');
$table->foreign('indicator_id')->references('id')->on('indicators')->onDelete('cascade');
});
}

View File

@ -13,35 +13,16 @@ class IndicatorSeeder extends Seeder
*/
public function run(): void
{
[
Indicator::create([
"name" => "pH Tanah",
"description" => "Tingkat keasaman tanah.",
"ideal_min" => 5.5,
"ideal_max" => 7.0,
"unit" => "pH"
]),
Indicator::create([
"name" => "Ketinggian Tempat",
"description" => "Ketinggian dari permukaan laut..",
"ideal_min" => 0,
"ideal_max" => 1000,
"unit" => "meter"
]),
Indicator::create([
"name" => "Ketersediaan Air",
"description" => "Ketersediaan air di lahan.",
"ideal_min" => 70,
"ideal_max" => 100,
"unit" => "persen"
]),
Indicator::create([
"name" => "Curah Hujan",
"description" => "Intensitas curah hujan.",
"ideal_min" => 1000,
"ideal_max" => 2000,
"unit" => "mm/tahun"
]),
$indicator = [
['name' => 'pH Tanah', 'description' => 'Indicator 1 Description'],
['name' => 'Ketinggian Tempat', 'description' => 'Indicator 2 Description'],
['name' => 'Ketersediaan Air', 'description' => 'Indicator 3 Description'],
['name' => 'Curah Hujan', 'description' => 'Indicator 4 Description'],
['name' => 'Isolasi', 'description' => 'Indicator 5 Description']
];
foreach ($indicator as $item) {
Indicator::create($item);
}
}
}

View File

@ -13,63 +13,16 @@ class RuleSeeder extends Seeder
*/
public function run(): void
{
[
Rule::create([
'indicator_id' => 1,
'range_min' => 5.5,
'range_max' => 6.0,
'mb' => 0.8,
'md' => 0.2
]),
Rule::create([
'indicator_id' => 1,
'range_min' => 6.0,
'range_max' => 7.0,
'mb' => 1.0,
'md' => 0.0
]),
Rule::create([
'indicator_id' => 2,
'range_min' => 0,
'range_max' => 500,
'mb' => 0.9,
'md' => 0.1
]),
Rule::create([
'indicator_id' => 2,
'range_min' => 500,
'range_max' => 1000,
'mb' => 0.8,
'md' => 0.2
]),
Rule::create([
'indicator_id' => 3,
'range_min' => 70,
'range_max' => 85,
'mb' => 0.7,
'md' => 0.3
]),
Rule::create([
'indicator_id' => 3,
'range_min' => 85,
'range_max' => 100,
'mb' => 1.0,
'md' => 0.0
]),
Rule::create([
'indicator_id' => 4,
'range_min' => 1000,
'range_max' => 1500,
'mb' => 0.9,
'md' => 0.1
]),
Rule::create([
'indicator_id' => 4,
'range_min' => 1500,
'range_max' => 2000,
'mb' => 1.0,
'md' => 0.0
]),
$rules = [
['indicator_id' => 1, 'mb' => 0.5],
['indicator_id' => 2, 'mb' => 0.5],
['indicator_id' => 3, 'mb' => 0.5],
['indicator_id' => 4, 'mb' => 0.5],
['indicator_id' => 5, 'mb' => 0.5],
];
foreach ($rules as $rule) {
Rule::create($rule);
}
}
}

View File

@ -18,22 +18,20 @@ document.addEventListener("DOMContentLoaded", function () {
});
function updateData(indicator) {
console.log(indicator);
var form = document.getElementById("edit-form");
var indicatorName = form.querySelector('input[name="name"]');
var description = form.querySelector('textarea[name="description"]');
var idealMin = form.querySelector('input[name="ideal_min"]');
var idealMax = form.querySelector('input[name="ideal_max"]');
var unit = form.querySelector('input[name="unit"]');
indicatorName.value = indicator.name;
description.value = indicator.description;
idealMin.value = indicator.ideal_min;
idealMax.value = indicator.ideal_max;
unit.value = indicator.unit;
form.action = "/data-indikator/" + indicator.id;
}
function deleteData(id) {
var form = document.getElementById("delete-form");
form.action = "/data-indikator/" + id;
}
var checkAll = document.getElementById("checkAll");
checkAll &&
(checkAll.onclick = function () {
@ -52,14 +50,7 @@ checkAll &&
});
var perPage = 8,
options = {
valueNames: [
"id",
"indicator_name",
"description",
"ideal_min",
"ideal_max",
"status",
],
valueNames: ["id", "indicator_name", "status"],
page: perPage,
pagination: !0,
plugins: [ListPagination({ left: 2, right: 2 })],
@ -180,11 +171,11 @@ refreshCallbacks(),
.querySelector(".modal-footer").style.display = "none"));
}),
ischeckboxcheck(),
document
.getElementById("showModal")
.addEventListener("hidden.bs.modal", function () {
clearFields();
}),
// document
// .getElementById("showModal")
// .addEventListener("hidden.bs.modal", function () {
// clearFields();
// }),
document
.querySelector("#customerList")
.addEventListener("click", function () {

View File

@ -33,14 +33,14 @@
<div class="card-body">
<div id="customerList">
<div class="row g-4 mb-3">
{{-- <div class="col-sm-auto">
<div class="col-sm-auto">
<div>
<button type="button" class="btn btn-primary add-btn" data-bs-toggle="modal"
id="create-btn" data-bs-target="#showModal">
<button type="button" class="btn btn-success add-btn" data-bs-toggle="modal"
id="create-btn" data-bs-target="#addModal">
<i class="ri-add-line align-bottom me-1"></i> Tambah
</button>
</div>
</div> --}}
</div>
<div class="col-sm">
<div class="d-flex justify-content-sm-end">
<div class="search-box ms-2">
@ -62,13 +62,6 @@
Name
</th>
<th class="sort" data-sort="description">Description</th>
<th class="sort" data-sort="ideal_min">Ideal Min</th>
<th class="sort" data-sort="ideal_max">
Ideal Max
</th>
<th class="sort" data-sort="status">
Unit
</th>
<th class="sort" data-sort="action">Action</th>
</tr>
</thead>
@ -81,11 +74,8 @@
class="fw-medium link-primary">#VZ2101</a>
</td>
<td class="indicator_name">{{ $indicator->name }}</td>
<td class="description">{{ $indicator->description }}</td>
<td class="ideal_min">{{ $indicator->ideal_min }}</td>
<td class="ideal_max">{{ $indicator->ideal_max }}</td>
<td class="status">
<span>{{ $indicator->unit }}</span>
<span>{{ $indicator->description }}</span>
</td>
<td>
<div class="d-flex gap-2 justify-content-center">
@ -96,12 +86,14 @@ class="fw-medium link-primary">#VZ2101</a>
Edit
</button>
</div>
{{-- <div class="remove">
<button class="btn btn-sm btn-success remove-item-btn"
data-bs-toggle="modal" data-bs-target="#deleteRecordModal">
Remove
<div class="remove">
<button class="btn btn-sm btn-danger remove-item-btn"
data-bs-toggle="modal"
data-bs-target="#deleteRecordModal"
onclick="deleteData({{ $indicator->id }})">
Hapus
</button>
</div> --}}
</div>
</div>
</td>
</tr>
@ -141,12 +133,65 @@ class="fw-medium link-primary">#VZ2101</a>
</div>
<!-- end row -->
{{-- edit modal --}}
<div class="modal fade" id="showModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
{{-- add modal --}}
<div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light p-3">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<h5 class="modal-title" id="exampleModalLabel">Tambah Indikator</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
id="close-modal"></button>
</div>
<form action="" class="needs-validation" method="POST" novalidate id="add-form">
@csrf
<div class="modal-body">
<div class="mb-3" id="modal-id" style="display: none">
<label for="id-field" class="form-label">ID</label>
<input type="text" id="id-field" class="form-control" placeholder="ID"
readonly />
</div>
<div class="mb-3">
<label for="indicatorname-field" class="form-label">Indikator</label>
<input type="text" id="indicatorname-field" class="form-control" name="name"
value="{{ old('name') }}" placeholder="Masukan Nama Indikator" required
autocomplete="off" />
<div class="invalid-feedback">
Masukan Nama Indikator
</div>
</div>
<div>
<label for="description-field" class="form-label">Description</label>
<textarea name="description" id="description-field" id="description-field" rows="5" class="form-control"
placeholder="Masukan Deskripsi" required>{{ old('description') }}</textarea>
<div class="invalid-feedback">
Masukan Deskripsi
</div>
</div>
</div>
<div class="modal-footer">
<div class="hstack gap-2 justify-content-end">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">
Tutup
</button>
<button type="submit" class="btn btn-success" id="edit-btn">
Simpan
</button>
</div>
</div>
</form>
</div>
</div>
</div>
{{-- edit modal --}}
<div class="modal fade" id="showModal" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light p-3">
<h5 class="modal-title" id="exampleModalLabel">Update Data Indikator</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
id="close-modal"></button>
</div>
@ -163,13 +208,14 @@ class="fw-medium link-primary">#VZ2101</a>
<div class="mb-3">
<label for="indicatorname-field" class="form-label">Indikator</label>
<input type="text" id="indicatorname-field" class="form-control" name="name"
value="{{ old('name') }}" placeholder="Masukan Nama Indikator" required />
value="{{ old('name') }}" placeholder="Masukan Nama Indikator" required
autocomplete="off" />
<div class="invalid-feedback">
Masukan Nama Indikator
</div>
</div>
<div class="mb-3">
<div>
<label for="description-field" class="form-label">Description</label>
<textarea name="description" id="description-field" id="description-field" rows="5" class="form-control"
placeholder="Masukan Deskripsi" required>{{ old('description') }}</textarea>
@ -177,33 +223,6 @@ class="fw-medium link-primary">#VZ2101</a>
Masukan Deskripsi
</div>
</div>
<div class="mb-3">
<label for="idealmin-field" class="form-label">Ideal Min</label>
<input type="text" id="idealmin-field" class="form-control" name="ideal_min"
value="{{ old('ideal_min') }}" placeholder="Masukan Ideal Min." required />
<div class="invalid-feedback">
Masukan angka ideal min
</div>
</div>
<div class="mb-3">
<label for="idealmax-field" class="form-label">Ideal Max</label>
<input type="text" id="idealmax-field" class="form-control" name="ideal_max"
value="{{ old('ideal_max') }}" placeholder="Masukan Ideal Max." required />
<div class="invalid-feedback">
Masukan angka ideal max
</div>
</div>
<div>
<label for="status-field" class="form-label">Unit</label>
<input type="text" id="status-field" class="form-control" name="unit"
value="{{ old('unit') }}" placeholder="Masukan Unit" required>
<div class="invalid-feedback">
Masukan Unit
</div>
</div>
</div>
<div class="modal-footer">
<div class="hstack gap-2 justify-content-end">
@ -234,19 +253,23 @@ class="fw-medium link-primary">#VZ2101</a>
colors="primary:#25a0e2,secondary:#00bd9d"
style="width: 100px; height: 100px"></lord-icon>
<div class="mt-4 pt-2 fs-15 mx-4 mx-sm-5">
<h4>Are you sure ?</h4>
<h4>Anda yakin ?</h4>
<p class="text-muted mx-4 mb-0">
Are you sure you want to remove this record ?
Anda yakin mau menghapus data ini ?
</p>
</div>
</div>
<div class="d-flex gap-2 justify-content-center mt-4 mb-2">
<button type="button" class="btn w-sm btn-light" data-bs-dismiss="modal">
Close
Tutup
</button>
<button type="button" class="btn w-sm btn-primary" id="delete-record">
Yes, Delete It!
<form action="" method="POST" id="delete-form">
@csrf
@method('DELETE')
<button type="submit" class="btn w-sm btn-danger" id="delete-record">
Ya, Hapus!
</button>
</form>
</div>
</div>
</div>

View File

@ -79,9 +79,9 @@
Route::prefix('data-indikator')->controller(IndicatorController::class)->name('indikator.')->group(function () {
Route::get('/', 'index')->name('index');
// Route::post('/', 'store')->name('store');
Route::post('/', 'store')->name('store');
Route::put('/{id}', 'update')->name('update');
// Route::delete('/{id}', 'destroy')->name('destroy');
Route::delete('/{id}', 'destroy')->name('destroy');
});
Route::prefix('data-aturan')->controller(RuleController::class)->name('aturan.')->group(function () {