fix(master-rule): add func read and create rule expert
This commit is contained in:
parent
e9d20b60ff
commit
023ce6fa19
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\MasterData;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Indicator;
|
||||
use App\Models\RuleExpert;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$customMessage = [
|
||||
'indicator.required' => 'Harap pilih indikator',
|
||||
'indicator.exists' => 'Indikator tidak ditemukan',
|
||||
|
||||
'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.max' => 'Nilai CF maksimal 1',
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'indicator' => 'required|exists:indicators,id',
|
||||
'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-right')->autoclose(3000);
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
$expertRule = new RuleExpert();
|
||||
$expertRule->indicator_id = $request->indicator;
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,11 @@ public function rules()
|
|||
return $this->hasMany(Rule::class, 'indicator_id', 'id');
|
||||
}
|
||||
|
||||
public function expertRules()
|
||||
{
|
||||
return $this->hasMany(RuleExpert::class, 'indicator_id', 'id');
|
||||
}
|
||||
|
||||
public function evaluationDetails()
|
||||
{
|
||||
return $this->hasMany(EvaluationDetail::class, 'indicator_id', 'id');
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RuleExpert extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'rule_expert_cf';
|
||||
protected $guarded = [];
|
||||
}
|
|
@ -1,23 +1,17 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const indicatorField = document.getElementById("indicator-field");
|
||||
const indicatorVal = new Choices(indicatorField);
|
||||
const indicatorEditField = document.getElementById("indicator-edit-field");
|
||||
window.indicatorEditVal = new Choices(indicatorEditField);
|
||||
});
|
||||
function updateData(data) {
|
||||
console.log(data);
|
||||
|
||||
function updateData(rule) {
|
||||
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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
function deleteData(id) {
|
|
@ -1,5 +1,5 @@
|
|||
@extends('layouts.app')
|
||||
@push('title', 'Data Aturan')
|
||||
@push('title', 'Data Aturan Pakar')
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
@ -7,7 +7,7 @@
|
|||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
||||
<h4 class="mb-sm-0">Data Aturan</h4>
|
||||
<h4 class="mb-sm-0">Data Aturan Pakar</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title mb-0">Data Aturan</h4>
|
||||
<h4 class="card-title mb-0">Data Aturan Pakar</h4>
|
||||
</div><!-- end card header -->
|
||||
|
||||
<div class="card-body">
|
||||
|
@ -50,7 +50,7 @@ class="ri-add-line align-bottom me-1"></i> Tambah</button>
|
|||
<th class="sort" data-sort="customer_name">Indikator</th>
|
||||
<th class="sort" data-sort="email">Kategori</th>
|
||||
<th class="sort" data-sort="phone">Deskripsi</th>
|
||||
<th class="sort" data-sort="status">CF(e)</th>
|
||||
<th class="sort" data-sort="status">CF(h)</th>
|
||||
<th class="sort" data-sort="action">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -59,7 +59,7 @@ class="ri-add-line align-bottom me-1"></i> Tambah</button>
|
|||
@endphp
|
||||
<tbody class="list form-check-all">
|
||||
@foreach ($indicators as $indicator)
|
||||
@foreach ($indicator->rules as $index => $rule)
|
||||
@foreach ($indicator->expertRules as $index => $rule)
|
||||
<tr class="text-center">
|
||||
<th scope="row" class="no">
|
||||
{{ $no++ }}
|
||||
|
@ -132,8 +132,8 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
|
||||
id="close-modal"></button>
|
||||
</div>
|
||||
<form action="{{ route('master_data.aturan.store') }}" class="needs-validation" method="POST"
|
||||
novalidate id="add-form">
|
||||
<form action="{{ route('master_data.aturan.expert_store') }}" class="needs-validation"
|
||||
method="POST" novalidate id="add-form">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="mb-3" id="modal-id" style="display: none">
|
||||
|
@ -199,7 +199,7 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
<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">Edit Data Aturan</h5>
|
||||
<h5 class="modal-title" id="exampleModalLabel">Edit Data Aturan Pakar</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"
|
||||
id="close-modal"></button>
|
||||
</div>
|
||||
|
@ -246,11 +246,11 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="cf-edit-field" class="form-label">CF(e)</label>
|
||||
<label for="cf-edit-field" class="form-label">CF(h)</label>
|
||||
<input type="text" id="cf-edit-field" class="form-control" name="cf"
|
||||
placeholder="Masukan Nilai CF(e)" required oninput="validateCfInput(this)" />
|
||||
<div class="invalid-feedback">
|
||||
Masukan CF(e)
|
||||
Masukan CF(h)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -318,7 +318,7 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
<script src="assets/libs/list.pagination.js/list.pagination.min.js"></script>
|
||||
|
||||
<!-- listjs init -->
|
||||
<script src="assets/js/pages/customJs/master-data/aturan/index1.js"></script>
|
||||
<script src="assets/js/pages/customJs/master-data/aturan/pakar.js"></script>
|
||||
|
||||
<script src="assets/js/pages/form-validation.init.js"></script>
|
||||
@endpush
|
|
@ -1,5 +1,5 @@
|
|||
@extends('layouts.app')
|
||||
@push('title', 'Data Aturan')
|
||||
@push('title', 'Data Aturan Petugas')
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
|
|
@ -84,7 +84,9 @@ class="nav-link {{ request()->routeIs('master_data.aturan.*') ? 'collapsed activ
|
|||
id="rules">
|
||||
<ul class="nav nav-sm flex-column">
|
||||
<li class="nav-item">
|
||||
<a href="" class="nav-link" data-key="t-level-3.1"> Keyakinan
|
||||
<a href="{{ route('master_data.aturan.expert') }}"
|
||||
class="nav-link {{ request()->routeIs('master_data.aturan.expert') ? 'active' : '' }}"
|
||||
data-key="t-level-3.1"> Keyakinan
|
||||
Pakar
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
use App\Http\Controllers\MasterData\IndicatorController;
|
||||
use App\Http\Controllers\MasterData\LandController;
|
||||
use App\Http\Controllers\MasterData\RuleController;
|
||||
use App\Http\Controllers\MasterData\RuleExpertController;
|
||||
use App\Http\Controllers\MasterData\UserController;
|
||||
use Illuminate\Routing\RouteGroup;
|
||||
use Illuminate\Routing\RouteUrlGenerator;
|
||||
|
@ -102,6 +103,12 @@
|
|||
});
|
||||
|
||||
Route::name('aturan.')->group(function () {
|
||||
Route::prefix('data-aturan-pakar')->controller(RuleExpertController::class)->group(function () {
|
||||
Route::get('/', 'index')->name('expert');
|
||||
Route::post('/', 'store')->name('expert_store');
|
||||
Route::put('/{id}', 'update')->name('expert_update');
|
||||
Route::delete('/{id}', 'destroy')->name('expert_destroy');
|
||||
});
|
||||
|
||||
Route::prefix('data-aturan-pengguna')->controller(RuleController::class)->group(function () {
|
||||
Route::get('/', 'index')->name('user');
|
||||
|
|
Loading…
Reference in New Issue