ekosistem basis data tambah field enum
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<option value="datetime">Datetime</option>
|
||||
<option value="text">Text</option>
|
||||
<option value="foreign_key">Relasi</option>
|
||||
<option value="enum">Enum</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-6 form-control-validation" id="relasi-form-tabel" style="display: none;">
|
||||
@@ -49,6 +50,11 @@
|
||||
<label class="form-label" for="add-kolom-relasi-kolom-label">Kolom Relasi (Label)<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="add-kolom-relasi-kolom-label" name="relasi_kolom_label" placeholder="Cth: Nama Petani" />
|
||||
</div>
|
||||
<div class="mb-6 form-control-validation" id="enum-form-opsi" style="display: none;">
|
||||
<label class="form-label" for="add-kolom-enum-opsi" >Opsi Enum<span class="text-danger">*</span></label>
|
||||
<textarea class="form-control" id="add-kolom-enum-opsi" name="enum_opsi" value="1"
|
||||
placeholder='Cth: [{"label": "Satu Pilihan", "value": "satu"}, {"label": "Dua Saja", "value": "dua"}]'></textarea>
|
||||
</div>
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="add-kolom-validasi">Validasi<span class="text-danger">*</span></label>
|
||||
<textarea class="form-control" id="add-kolom-validasi" name="validasi" value="1" placeholder="Cth: required"></textarea>
|
||||
@@ -78,8 +84,14 @@
|
||||
$('#relasi-form-kolom').hide();
|
||||
$('#relasi-form-kolom-label').hide();
|
||||
}
|
||||
if ($(this).val() === 'enum') {
|
||||
$('#enum-form-opsi').show();
|
||||
} else {
|
||||
$('#enum-form-opsi').hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$.validator.addMethod("snakecase", function(value, element) {
|
||||
return this.optional(element) || /^[a-z0-9]+(_[a-z0-9]+)*$/.test(value);
|
||||
}, "Gunakan format snake_case (huruf kecil dan underscore)");
|
||||
|
||||
@@ -47,6 +47,12 @@
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
@elseif($k->tipe == 'enum')
|
||||
<select class="form-select tipe-fk @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" name="{{ $k->kolom }}">
|
||||
@foreach($k->enum_opsi as $opsi)
|
||||
<option value="{{ $opsi['value'] }}" {{ old($k->kolom) == $opsi['value'] ? 'selected' : '' }}>{{ $opsi['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@else
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}"
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) }}" />
|
||||
|
||||
@@ -64,6 +64,12 @@
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
@elseif($k->tipe == 'enum')
|
||||
<select class="form-select tipe-fk @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" name="{{ $k->kolom }}">
|
||||
@foreach($k->enum_opsi as $opsi)
|
||||
<option value="{{ $opsi['value'] }}" {{ old($k->kolom) ?? $value['value_'.$k->tipe] == $opsi['value'] ? 'selected' : '' }}>{{ $opsi['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@else
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}"
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" />
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom mb-4">
|
||||
<h5 class="card-title mb-0">Lihat Data {{ $tabel->label }}</h5>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form id="addUpdateDataForm" action="{{ route('tabel.data.update', [$tabel->id, $value_id, 'program_id' => $program->id]) }}" method="POST" >
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<h6 class="mb-3">Informasi {{ $tabel->label }}</h6>
|
||||
@if (!$program)
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-4 form-control-validation">
|
||||
<label class="form-label" for="add-data-program">Program<span class="text-danger">*</span></label>
|
||||
<select name="program_id" class="form-select form-select-sm w-auto" onchange="this.form.submit()">
|
||||
<option value="">Pilih Program</option>
|
||||
@foreach($programList as $prog)
|
||||
<option value="{{ $prog->id }}" {{ request('program_id') == $prog->id ? 'selected' : '' }}>{{ $prog->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="row">
|
||||
@foreach($kolom as $k)
|
||||
<?php
|
||||
$value = $values->where('kolom_id', $k->id)->first();
|
||||
?>
|
||||
<div class="col-md-3 mb-4 form-control-validation">
|
||||
<label class="form-label" for="add-data-{{ $k->kolom }}">{{ $k->label }}<span class="text-danger">*</span></label>
|
||||
@if($k->tipe == 'varchar')
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" />
|
||||
@elseif($k->tipe == 'text')
|
||||
<textarea class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}">{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}</textarea>
|
||||
@elseif($k->tipe == 'integer')
|
||||
<input type="number" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" step="1" />
|
||||
@elseif($k->tipe == 'float')
|
||||
<input type="number" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" step="any" />
|
||||
@elseif($k->tipe == 'date')
|
||||
<input type="date" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" />
|
||||
@elseif($k->tipe == 'datetime')
|
||||
<input type="datetime-local" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" />
|
||||
@elseif($k->tipe == 'boolean')
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ (old($k->kolom) ?? $value['value_'.$k->tipe]) == 1 ? 'Ya' : 'Tidak' }}" />
|
||||
@elseif($k->tipe == 'foreign_key')
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ (old($k->kolom) ?? $value['value_relasi_label']) }}" />
|
||||
@elseif($k->tipe == 'enum')
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ (old($k->kolom) ?? $value['value_enum_label']) }}" />
|
||||
@else
|
||||
<input type="text" class="form-control @error($k->kolom) is-invalid @enderror" id="add-data-{{ $k->kolom }}" readonly
|
||||
name="{{ $k->kolom }}" placeholder="Cth: {{ $k->label }}" value="{{ old($k->kolom) ?? $value['value_'.$k->tipe] }}" />
|
||||
@endif
|
||||
@error($k->kolom)<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
|
||||
<div class="mt-4 text-end">
|
||||
<a href="{{ route('tabel.data.index', [$tabel->id, 'program_id' => $program->id]) }}" class="btn btn-label-secondary me-2">Kembali</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
$(document).ready(function () {
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user