fix(master-rule): create crud func expert rule
This commit is contained in:
parent
023ce6fa19
commit
e609b773c8
|
@ -7,13 +7,15 @@
|
|||
use App\Models\RuleExpert;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
|
||||
class RuleExpertController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$indicators = Indicator::whereDoesntHave('expertRules')->orderBy('created_at', 'desc')->get();
|
||||
return view('master-data.aturan.rule_expert', compact('indicators'));
|
||||
$indicators = Indicator::with('expertRules')->orderBy('created_at', 'desc')->get();
|
||||
$parameters = Indicator::whereDoesntHave('expertRules')->get();
|
||||
return view('master-data.aturan.rule_expert', compact('indicators', 'parameters'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
|
@ -62,4 +64,60 @@ public function store(Request $request)
|
|||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$customMessage = [
|
||||
'parameter_type.required' => 'Jenis parameter wajib diisi',
|
||||
'parameter_type.string' => 'Jenis parameter harus berupa teks',
|
||||
'parameter_type.max' => 'Jenis parameter maksimal 25 karakter',
|
||||
|
||||
'description.required' => 'Deskripsi wajib diisi',
|
||||
'description.string' => 'Deskripsi harus berupa teks',
|
||||
'description.max' => 'Deskripsi maksimal 40 karakter',
|
||||
|
||||
'cf.required' => 'Nilai CF wajib diisi',
|
||||
'cf.numeric' => 'Nilai CF harus berupa angka',
|
||||
'cf.min' => 'Nilai CF minimal -1',
|
||||
'cf.max' => 'Nilai CF maksimal 1',
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'parameter_type' => 'required|string|max:25',
|
||||
'description' => 'required|string|max:40',
|
||||
'cf' => 'required|numeric|min:-1|max:1',
|
||||
], $customMessage);
|
||||
|
||||
if ($validator->fails()) {
|
||||
toast($validator->messages()->all()[0], 'error')->position('top')->autoclose(3000);
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
$expertRule = RuleExpert::find($id);
|
||||
$expertRule->parameter_type = $request->parameter_type;
|
||||
$expertRule->description = $request->description;
|
||||
$expertRule->cf = $request->cf;
|
||||
$expertRule->save();
|
||||
toast('Data berhasil disimpan', 'success')->position('top-right')->autoclose(3000);
|
||||
return redirect()->back();
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000);
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$expertRule = RuleExpert::find($id);
|
||||
try {
|
||||
$expertRule->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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
function updateData(data) {
|
||||
console.log(data);
|
||||
var form = document.getElementById("edit-form");
|
||||
var indicator = form.querySelector("#indicator-edit-field");
|
||||
var categoryEditField = form.querySelector("#category-edit-field");
|
||||
var description = form.querySelector("#description-edit-field");
|
||||
var cf = form.querySelector("#cf-edit-field");
|
||||
|
||||
// var form = document.getElementById("edit-form");
|
||||
// var categoryEditField = form.querySelector("#category-edit-field");
|
||||
// var description = form.querySelector("#description-edit-field");
|
||||
// var cf = form.querySelector("#cf-edit-field");
|
||||
// form.action = "/data-aturan/" + rule.id;
|
||||
// window.indicatorEditVal.setChoiceByValue(rule.indicator_id.toString());
|
||||
// window.indicatorEditVal.passedElement.element.value =
|
||||
// rule.indicator_id.toString();
|
||||
// categoryEditField.value = rule.parameter_type;
|
||||
// description.value = rule.description;
|
||||
// cf.value = rule.cf;
|
||||
form.action = "/data-aturan-pakar/" + data.id;
|
||||
indicator.value = data.indicator_id;
|
||||
categoryEditField.value = data.parameter_type;
|
||||
description.value = data.description;
|
||||
cf.value = data.cf;
|
||||
}
|
||||
|
||||
function deleteData(id) {
|
||||
var form = document.getElementById("delete-form");
|
||||
form.action = "/data-aturan/" + id;
|
||||
form.action = "/data-aturan-pakar/" + id;
|
||||
}
|
||||
|
||||
function validateCfInput(input) {
|
||||
|
@ -53,12 +51,23 @@ function validateCfInput(input) {
|
|||
|
||||
let numValue = parseFloat(input.value);
|
||||
|
||||
// **Batasi nilai antara -1.0 dan 1.0**
|
||||
if (!isNaN(numValue)) {
|
||||
if (numValue > 1) {
|
||||
input.value = "1.0";
|
||||
} else if (numValue < -1) {
|
||||
input.value = "-1.0";
|
||||
let decimal = Math.abs(numValue * 10);
|
||||
let lastDigit = decimal % 10;
|
||||
|
||||
if (lastDigit % 2 === 1) {
|
||||
input.value = "";
|
||||
alert("Nilai CF Tidak Sesuai");
|
||||
return;
|
||||
}
|
||||
|
||||
// **Batasi nilai antara -1.0 dan 1.0**
|
||||
if (!isNaN(numValue)) {
|
||||
if (numValue > 1) {
|
||||
input.value = "1.0";
|
||||
} else if (numValue < -1) {
|
||||
input.value = "-1.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,61 @@ function deleteData(id) {
|
|||
form.action = "/data-aturan-pengguna/" + id;
|
||||
}
|
||||
|
||||
function validateCfInput(input) {
|
||||
input.value = input.value.replace(",", ".");
|
||||
|
||||
input.value = input.value.replace(/[^0-9.\-]/g, "");
|
||||
|
||||
if (input.value.includes("-") && !input.value.startsWith("-")) {
|
||||
input.value = input.value.replace("-", "");
|
||||
}
|
||||
|
||||
input.value = input.value.replace(/-+/g, "-");
|
||||
|
||||
if (input.value === "-") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.value.startsWith(".")) {
|
||||
input.value = "0" + input.value;
|
||||
}
|
||||
|
||||
if (input.value.startsWith("-.")) {
|
||||
input.value = "-0.";
|
||||
}
|
||||
|
||||
// **PERBAIKAN**: Hilangkan nol berlebih di depan angka, kecuali nol sebelum titik
|
||||
input.value = input.value.replace(/^(-?)0+(\d)/, "$1$2");
|
||||
|
||||
// **BATASI INPUT**: Hanya satu titik desimal, dan maksimal 1 angka setelah titik
|
||||
let match = input.value.match(/^-?\d*(\.\d{0,1})?/);
|
||||
if (match) {
|
||||
input.value = match[0];
|
||||
}
|
||||
|
||||
let numValue = parseFloat(input.value);
|
||||
|
||||
if (!isNaN(numValue)) {
|
||||
let decimal = Math.abs(numValue * 10);
|
||||
let lastDigit = decimal % 10;
|
||||
|
||||
if (lastDigit % 2 === 1) {
|
||||
input.value = "";
|
||||
alert("Nilai CF Tidak Sesuai");
|
||||
return;
|
||||
}
|
||||
|
||||
// **Batasi nilai antara -1.0 dan 1.0**
|
||||
if (!isNaN(numValue)) {
|
||||
if (numValue > 1) {
|
||||
input.value = "1.0";
|
||||
} else if (numValue < -1) {
|
||||
input.value = "-1.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var perPage = 10,
|
||||
options = {
|
||||
valueNames: ["id", "customer_name", "email", "date", "phone", "status"],
|
||||
|
|
|
@ -146,8 +146,8 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
<label for="indicatorname-field" class="form-label">Indikator</label>
|
||||
<select name="indicator" class="form-control" id="indicator-field" required>
|
||||
<option value="" selected disabled>Pilih Indikator</option>
|
||||
@foreach ($indicators as $indicator)
|
||||
<option value="{{ $indicator->id }}">{{ $indicator->name }}</option>
|
||||
@foreach ($parameters as $parameter)
|
||||
<option value="{{ $parameter->id }}">{{ $parameter->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
|
@ -216,7 +216,8 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
|
||||
<div class="mb-3">
|
||||
<label for="indicator-edit-field" class="form-label">Indikator</label>
|
||||
<select name="indicator" class="form-control" id="indicator-edit-field" required>
|
||||
<select name="indicator" class="form-control" id="indicator-edit-field" required
|
||||
disabled>
|
||||
<option value="" selected disabled>Pilih Indikator</option>
|
||||
@foreach ($indicators as $indicator)
|
||||
<option value="{{ $indicator->id }}">{{ $indicator->name }}</option>
|
||||
|
|
Loading…
Reference in New Issue