update
parent
95dcb91f56
commit
146df57870
|
@ -8,6 +8,8 @@ use Illuminate\Support\Facades\DB;
|
|||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Models\Master\Instansi;
|
||||
use App\Models\Master\Template;
|
||||
use App\Models\Master\Group;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InstansiController extends Controller
|
||||
|
@ -36,7 +38,7 @@ class InstansiController extends Controller
|
|||
public function grid(Request $request)
|
||||
{
|
||||
|
||||
$data = Instansi::all();
|
||||
$data = Instansi::orderBy('MsInstansiId','ASC')->get();
|
||||
// $data = User::with(['group'])->orderBy('id','DESC')->get();
|
||||
$_data = [];
|
||||
|
||||
|
@ -55,12 +57,19 @@ class InstansiController extends Controller
|
|||
}
|
||||
$action .= '</div>';
|
||||
}
|
||||
|
||||
if(@$row->resource_data){
|
||||
$resource = 'Ada';
|
||||
}else{
|
||||
$resource = '';
|
||||
}
|
||||
|
||||
$_data[] = [
|
||||
'no' => $key+1,
|
||||
'id' => encode_id($row->id),
|
||||
'name' => @$row->name,
|
||||
'parent' => @$row->parent,
|
||||
'resource' => @$resource,
|
||||
'action' => @$action,
|
||||
];
|
||||
|
||||
|
@ -100,6 +109,7 @@ class InstansiController extends Controller
|
|||
$user->alamat = $request->alamat;
|
||||
$user->telp = $request->telp;
|
||||
$user->website = $request->website;
|
||||
$user->resource_data = json_encode($request->resource_data);
|
||||
$user->save();
|
||||
}else{
|
||||
Validator::make($request->all(), [
|
||||
|
@ -113,6 +123,7 @@ class InstansiController extends Controller
|
|||
$user->alamat = $request->alamat;
|
||||
$user->telp = $request->telp;
|
||||
$user->website = $request->website;
|
||||
$user->resource_data = json_encode($request->resource_data);
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
@ -160,6 +171,8 @@ class InstansiController extends Controller
|
|||
$data['route'] = $this->route;
|
||||
$data['keyId'] = $id;
|
||||
$data['item'] = Instansi::where('MsInstansiId',$keyId)->first();
|
||||
$data['group'] = Group::where('MsGroupId','!=',1)->get();
|
||||
$data['template'] = Template::all();
|
||||
return view($this->template.'.form',$data);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,13 +36,11 @@ class ResourceController extends Controller
|
|||
public function grid(Request $request)
|
||||
{
|
||||
|
||||
$data = Template::all();
|
||||
$data = Template::orderBy('MsTemplateId','ASC')->get();
|
||||
$_data = [];
|
||||
|
||||
|
||||
foreach ($data as $key => $row) {
|
||||
|
||||
|
||||
$action = '';
|
||||
|
||||
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
|
||||
|
@ -50,11 +48,18 @@ class ResourceController extends Controller
|
|||
$action .= '<a href="'.url('master/resource/update/'.encode_id($row->MsTemplateId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block bg-primary"><i class="ri-pencil-line text-white"></i></a>';
|
||||
$action .= '</div>';
|
||||
}
|
||||
|
||||
if($row->show_dashboard == 0){
|
||||
$radio = '<input data-key="'.encode_id($row->MsTemplateId).'" class="showDashboard" type="checkbox" name="show_dashboard">';
|
||||
}else{
|
||||
$radio = '<input data-key="'.encode_id($row->MsTemplateId).'" class="showDashboard" type="checkbox" name="show_dashboard" checked>';
|
||||
}
|
||||
|
||||
$_data[] = [
|
||||
'no' => $key+1,
|
||||
'id' => encode_id($row->id),
|
||||
'id' => encode_id($row->MsTemplateId),
|
||||
'name' => @$row->name,
|
||||
'show_dashboard' => $radio,
|
||||
'action' => @$action,
|
||||
];
|
||||
|
||||
|
@ -163,4 +168,19 @@ class ResourceController extends Controller
|
|||
{
|
||||
//
|
||||
}
|
||||
|
||||
function changeShowDashboard(Request $request){
|
||||
try {
|
||||
// dd($request->all());
|
||||
$keyId = decode_id($request->id);
|
||||
$template = Template::where('MsTemplateId',$keyId)->first();
|
||||
// dd($template);
|
||||
$template->show_dashboard = ($request->val == 'true' ? '1' : '0');
|
||||
$template->save();
|
||||
return response()->json(['data' => $template,'status' => true]);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json(['status' => false]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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('ms_instansi', function (Blueprint $table) {
|
||||
$table->json('resource_data')->after('id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ms_instansi', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
|
@ -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('ms_template', function (Blueprint $table) {
|
||||
$table->integer('show_dashboard')->after('template_url')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ms_template', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
|
@ -21,12 +21,11 @@
|
|||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="mb-3">Jenis Instansi</label>
|
||||
<select name="parent" class="form-input @error('parent') is-invalid @enderror" required>
|
||||
<select name="parent" class="form-input select2 @error('parent') is-invalid @enderror" required>
|
||||
<option value="">-Pilih Jenis Instansi-</option>
|
||||
<option {{@$item->parent == 'Biro' ? 'selected' : ''}} value="Biro">Biro</option>
|
||||
<option {{@$item->parent == 'Badan' ? 'selected' : ''}} value="Badan">Badan</option>
|
||||
<option {{@$item->parent == 'Deputi' ? 'selected' : ''}} value="Deputi">Deputi</option>
|
||||
<option {{@$item->parent == 'Dinas' ? 'selected' : ''}} value="Dinas">Dinas</option>
|
||||
@foreach($group as $dataGroup)
|
||||
<option {{@$dataGroup->name == @$item->parent ? 'selected' : ''}} value="{{ @$dataGroup->name }}">{{ @$dataGroup->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('parent')
|
||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||
|
@ -47,6 +46,23 @@
|
|||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
@php
|
||||
// Ambil data yang sudah dipilih (bisa dari old input atau dari model saat edit)
|
||||
$selectedResources = @$item->resource_data ? json_decode(@$item->resource_data) : [];
|
||||
// dd($selectedResources);
|
||||
@endphp
|
||||
<div class="mb-3">
|
||||
<label class="mb-3 required">Resource Data</label>
|
||||
<select name="resource_data[]" required class="form-input resource_data select2 @error('resource_data') is-invalid @enderror" id="" multiple>
|
||||
<option value="">-</option>
|
||||
@foreach($template as $dataTemplate)
|
||||
<option {{ in_array(encode_id($dataTemplate->MsTemplateId), $selectedResources) ? 'selected' : '' }} value="{{encode_id($dataTemplate->MsTemplateId)}}">{{$dataTemplate->name}} - {{$dataTemplate->template_url}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('resource_data')
|
||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="mb-3">Alamat</label>
|
||||
<textarea name="alamat" class="form-input @error('alamat') is-invalid @enderror" id="">{{@$item->alamat}}</textarea>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</div>
|
||||
<div class="p-6">
|
||||
<div id="toolbar">
|
||||
<a href="{{route($route.'.create')}}" class="btn bg-success text-white"><i class="ri-add-line"></i> Tambah Data</a>
|
||||
<a href="{{route($route.'.update')}}" class="btn bg-success text-white"><i class="ri-add-line"></i> Tambah Data</a>
|
||||
</div>
|
||||
<table class="gridjs-table"
|
||||
data-search="true"
|
||||
|
@ -32,6 +32,7 @@
|
|||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-width="10" data-field="no">No</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-field="name">Name</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-field="parent">Jenis Instansi</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-field="resource">Resource Data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="gridjs-tbody"></tbody>
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-width="10" data-field="action">#</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-width="10" data-field="no">No</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-gray-500" data-field="name">Name</th>
|
||||
<th class="gridjs-td gridjs-th text-sm text-center text-gray-500" data-field="show_dashboard">Tampilkan Di Dashboard ?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="gridjs-tbody"></tbody>
|
||||
|
@ -42,6 +43,37 @@
|
|||
@endsection
|
||||
@section('js')
|
||||
<script type="text/javascript">
|
||||
$("#grid-data").on("click", ".showDashboard", function() {
|
||||
var base_url = "{{ route($route.'.changeShowDashboard') }}";
|
||||
var id = $(this).attr('data-key');
|
||||
var val = $(this).is(':checked');
|
||||
|
||||
request = $.ajax({
|
||||
url: base_url,
|
||||
type: "POST",
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
data:{
|
||||
id:id,
|
||||
val:val,
|
||||
_token:'{{ csrf_token() }}',
|
||||
}
|
||||
});
|
||||
// Callback handler that will be called on success
|
||||
request.done(function(response, textStatus, jqXHR){
|
||||
console.log(response);
|
||||
toastr.success("Berhasil Update Data", 'Berhasil!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
|
||||
$('#grid-data').bootstrapTable('refresh');
|
||||
});
|
||||
|
||||
// Callback handler that will be called on failure
|
||||
request.fail(function (jqXHR, textStatus, errorThrown){
|
||||
toastr.error(
|
||||
"Gagal "+textStatus, errorThrown
|
||||
);
|
||||
});
|
||||
});
|
||||
$("#grid-data").on("click", ".remove_data", function() {
|
||||
var base_url = $(this).attr('data-href');
|
||||
var id = $(this).attr('data-id');
|
||||
|
|
|
@ -49,6 +49,7 @@ Route::name('master.')->prefix('master')->group(function () {
|
|||
Route::resource('/',ResourceController::class);
|
||||
Route::get('grid',[ResourceController::class,'grid'])->name('grid');
|
||||
Route::get('update/{id?}',[ResourceController::class,'update'])->name('update');
|
||||
Route::post('changeShowDashboard',[ResourceController::class,'changeShowDashboard'])->name('changeShowDashboard');
|
||||
});
|
||||
|
||||
Route::name('topik.')->prefix('topik')->group(function () {
|
||||
|
|
Loading…
Reference in New Issue