akses done
This commit is contained in:
parent
304ba1a3f3
commit
b778b7dee4
170
app/Http/Controllers/AksesFileController.php
Normal file
170
app/Http/Controllers/AksesFileController.php
Normal file
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\AksesFile;
|
||||
use App\Models\DataUser;
|
||||
use App\Models\FileDirectory;
|
||||
use App\Models\UnitKerja;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AksesFileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'title' => 'Akses'
|
||||
];
|
||||
return view('akses.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
DB::connection('dbDirectory')->beginTransaction();
|
||||
try {
|
||||
$datas = request('data');
|
||||
foreach ($datas as $data) {
|
||||
$payload = [
|
||||
'pegawai_id' => $data['pegawai_id'],
|
||||
'pegawai_id_entry' => auth()->user()?->dataUser?->id,
|
||||
'pegawai_nama_entry' => auth()->user()?->dataUser?->namalengkap,
|
||||
'entry_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
|
||||
];
|
||||
if($data['akses'] === "all"){
|
||||
$payload['all_akses'] = true;
|
||||
}else{
|
||||
$payload['all_akses'] = false;
|
||||
$payload['unit_akses'] = $data['unit_akses'];
|
||||
|
||||
}
|
||||
AksesFile::create($payload);
|
||||
}
|
||||
DB::connection('dbDirectory')->commit();
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Data berhasil disimpan',
|
||||
], 200);
|
||||
} catch (\Throwable $th) {
|
||||
DB::connection('dbDirectory')->rollBack();
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => $th->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
try {
|
||||
$data = AksesFile::where('akses_file_id', $id)->first();
|
||||
$payload = [
|
||||
'pegawai_id' => request('pegawai_id'),
|
||||
'pegawai_id_modified' => auth()->user()?->dataUser?->id,
|
||||
'pegawai_nama_modified' => auth()->user()?->dataUser?->namalengkap,
|
||||
'modified_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
|
||||
'all_akses' => request('akses') === "all" ? true : false,
|
||||
'unit_akses' => request('unit_akses')
|
||||
];
|
||||
$data->update($payload);
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Data berhasil diperbarui',
|
||||
], 200);
|
||||
} catch (\Throwable $th) {
|
||||
DB::connection('dbDirectory')->rollBack();
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => $th->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
$data = AksesFile::where('akses_file_id', $id)->first();
|
||||
if(!$data){
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Data tidak ditemukan'
|
||||
], 404);
|
||||
}
|
||||
$payload =[
|
||||
'statusenabled' => false
|
||||
];
|
||||
$data->update($payload);
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Data berhasil dihapus'
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
public function datatable(){
|
||||
return AksesFile::where('statusenabled', true)->get();
|
||||
}
|
||||
|
||||
public function optionPegawai(){
|
||||
$q = request()->get('q');
|
||||
$query = DataUser::where('statusenabled', true);
|
||||
$data = $query->when($q, function($query, $q){
|
||||
$query->where('nama', 'ILIKE', '%' . $q . '%');
|
||||
})->select('id','nama')->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function optionUnitKerja(){
|
||||
$q = request()->get('q');
|
||||
$query = UnitKerja::where('statusenabled', true);
|
||||
$data = $query->when($q, function($query, $q){
|
||||
$query->where('name', 'ILIKE', '%' . $q . '%');
|
||||
})->select('id','name')->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\AksesFile;
|
||||
use App\Models\FileDirectory;
|
||||
use App\Models\MasterKategori;
|
||||
use App\Models\MasterKlasifikasi;
|
||||
@ -41,11 +42,11 @@ class DashboardController extends Controller
|
||||
$klasifikasi = request('klasifikasi');
|
||||
|
||||
|
||||
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)
|
||||
->where('id', $authUnitKerja)
|
||||
->with(['subUnitKerja' => function ($query) use ($authSubUnitKerja, $kategori, $filterUnit, $subUnit, $klasifikasi) {
|
||||
$query->where('id', $authSubUnitKerja)
|
||||
if($kategori && $filterUnit && $subUnit && $klasifikasi){
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)
|
||||
->where('id', $filterUnit)
|
||||
->with(['subUnitKerja' => function ($query) use ($kategori, $filterUnit, $subUnit, $klasifikasi) {
|
||||
$query->where('id', $subUnit)
|
||||
->with(['fileDirectory' => function ($q) use ($kategori, $filterUnit, $subUnit, $klasifikasi) {
|
||||
$q->when($filterUnit, function ($subQ) use ($filterUnit) {
|
||||
$subQ->where('id_unit_kerja', $filterUnit);
|
||||
@ -60,10 +61,11 @@ class DashboardController extends Controller
|
||||
}])
|
||||
->select('id', 'name')
|
||||
->get();
|
||||
}
|
||||
|
||||
$katDok = MasterKategori::where('statusenabled', true)->select('master_kategori_directory_id', 'nama_kategori_directory')->get();
|
||||
$data = [
|
||||
'unitKerja' => $unitKerja,
|
||||
'unitKerja' => $unitKerja ?? null,
|
||||
'katDok' => $katDok
|
||||
];
|
||||
return response()->json([
|
||||
@ -109,18 +111,29 @@ class DashboardController extends Controller
|
||||
|
||||
public function OptionUnitKerja(){
|
||||
$q = request()->get('q');
|
||||
$authMapping = auth()->user()?->dataUser?->mappingUnitKerjaPegawai[0];
|
||||
$authUnitKerja = $authMapping?->objectunitkerjapegawaifk;
|
||||
$authSubUnitKerja = $authMapping?->objectsubunitkerjapegawaifk;
|
||||
$akses = false;
|
||||
$authPegawai = auth()->user()?->dataUser;
|
||||
|
||||
$query = UnitKerja::query();
|
||||
if(!$akses){
|
||||
$query->where(['statusenabled' => true, 'id' => $authUnitKerja])
|
||||
$authUnitKerja = optional($authPegawai->mappingUnitKerjaPegawai[0] ?? null)->objectunitkerjapegawaifk;
|
||||
$authSubUnitKerja = optional($authPegawai->mappingUnitKerjaPegawai[0] ?? null)->objectsubunitkerjapegawaifk;
|
||||
|
||||
$aksesFile = AksesFile::where('pegawai_id', $authPegawai->id)
|
||||
->where('statusenabled', true)
|
||||
->first();
|
||||
|
||||
$query = UnitKerja::where('statusenabled', true);
|
||||
if($aksesFile){
|
||||
if($aksesFile->all_akses){
|
||||
|
||||
}elseif($aksesFile->unit_akses){
|
||||
$query->where('id', $aksesFile->unit_akses);
|
||||
}
|
||||
}else{
|
||||
$query->where('id', $authUnitKerja)
|
||||
->with(['subUnitKerja' => function($query) use($authSubUnitKerja){
|
||||
$query->where('id', $authSubUnitKerja);
|
||||
}]);
|
||||
}
|
||||
|
||||
$data = $query->when($q, function ($query, $q){
|
||||
$query->where('name', 'ILIKE', '%' .$q . '%');
|
||||
})
|
||||
|
||||
24
app/Models/AksesFile.php
Normal file
24
app/Models/AksesFile.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AksesFile extends Model
|
||||
{
|
||||
protected $connection = 'dbDirectory';
|
||||
protected $table = 'public.akses_file';
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'akses_file_id';
|
||||
protected $guarded = ['akses_file_id'];
|
||||
|
||||
protected $with =['pegawai', 'akses'];
|
||||
|
||||
public function pegawai(){
|
||||
return $this->belongsTo(DataUser::class, 'pegawai_id', 'id')->select('id', 'namalengkap');
|
||||
}
|
||||
|
||||
public function akses(){
|
||||
return $this->belongsTo(UnitKerja::class, 'unit_akses', 'id')->select('id', 'name');
|
||||
}
|
||||
}
|
||||
@ -11,4 +11,10 @@ class FileDirectory extends Model
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'file_directory_id';
|
||||
protected $guarded = ['file_directory_id'];
|
||||
|
||||
protected $with = ['klasifikasi'];
|
||||
|
||||
public function klasifikasi(){
|
||||
return $this->belongsTo(MasterKlasifikasi::class, 'master_klasifikasi_directory_id', 'master_klasifikasi_directory_id');
|
||||
}
|
||||
}
|
||||
|
||||
7
public/js/akses/_init.js
Normal file
7
public/js/akses/_init.js
Normal file
@ -0,0 +1,7 @@
|
||||
const datatableAkses = $("#table_akses")
|
||||
|
||||
const formCreateAkses = $("#formAkses")
|
||||
const modalCreate = document.getElementById('modalAkses')
|
||||
|
||||
const modalEdit = document.getElementById('modalEditAkses')
|
||||
const formEditAkses = $("#formEditAkses")
|
||||
265
public/js/akses/action.js
Normal file
265
public/js/akses/action.js
Normal file
@ -0,0 +1,265 @@
|
||||
formCreateAkses.on('submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
const form = this;
|
||||
const formData = new FormData(form);
|
||||
|
||||
fetch(`/akses`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': document.querySelector('input[name="_token"]').value,
|
||||
},
|
||||
body: formData
|
||||
}).then(async(res) => {
|
||||
const responseData = await res.json();
|
||||
if (responseData.status) {
|
||||
const handler = function () {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
text: responseData.message || 'Berhasil melakukan aksi!',
|
||||
timer: 2000,
|
||||
showConfirmButton: false,
|
||||
backdrop: true,
|
||||
});
|
||||
$("#col_add_akses").html('');
|
||||
colCount = 1; // reset counter
|
||||
formCreateAkses.find('select').val(null).trigger('change');
|
||||
datatableAkses.bootstrapTable('refresh');
|
||||
modalCreate.removeEventListener('hidden.bs.modal', handler);
|
||||
};
|
||||
modalCreate.addEventListener('hidden.bs.modal', handler);
|
||||
bootstrap.Modal.getInstance(modalCreate).hide();
|
||||
} else {
|
||||
throw new Error(responseData.message || 'Terjadi kesalahan saat menyimpan data.');
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
if (err.message) {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Gagal',
|
||||
text: err.message
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function deleteAkses(e){
|
||||
let id =$(e).data('akses_file_id')
|
||||
Swal.fire({
|
||||
title: "Apakah kamu yakin ingin menghapus akses?",
|
||||
text : $(e).data('name') + ' sebagai ' + $(e).data('akses'),
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
backdrop: true,
|
||||
}).then((result) => {
|
||||
if(result.isConfirmed){
|
||||
fetch(`/akses/${id}`, {
|
||||
method:'DELETE',
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": document.querySelector('input[name="_token"]').value,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}).then((response) => {
|
||||
if(!response.ok){
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
if(data.status){
|
||||
Swal.fire({
|
||||
title: "Success",
|
||||
text: "Data berhasil dihapus",
|
||||
icon:"success",
|
||||
showConfirmButton: false,
|
||||
timer: 1000
|
||||
}).then(() => {
|
||||
datatableAkses.bootstrapTable("refresh")
|
||||
})
|
||||
}else{
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: data.message || "Failed to delete Item.",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "Something went wrong. Please try again later.",
|
||||
icon: "error"
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function editAkses(e){
|
||||
const data = $(e).data();
|
||||
new bootstrap.Modal(modalEdit).show();
|
||||
formEditAkses.attr('action', `/akses/${data.akses_file_id}`)
|
||||
$("#akses_id_edit").val(data.akses === 1 ? 'all' : 'unit')
|
||||
selectAksesEdit()
|
||||
|
||||
selectOptionPegawaiEdit()
|
||||
selectOptionUnitEdit()
|
||||
if (data.pegawai_id) {
|
||||
setOldSelect2Value('#pegawai_id_edit', data.pegawai_id, data.pegawai_nama);
|
||||
}
|
||||
|
||||
if (data.unit_id) {
|
||||
setOldSelect2Value('#unit_akses_edit', data.unit_id, data.unit_nama);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('change', function(e){
|
||||
e.preventDefault()
|
||||
if(e.target){
|
||||
selectAksesEdit()
|
||||
}
|
||||
})
|
||||
|
||||
function selectAksesEdit(){
|
||||
let aksesId = $(`#akses_id_edit`);
|
||||
let colUnit = $(`#col_select_unit_edit`)
|
||||
if(aksesId.val() === "all"){
|
||||
colUnit.addClass('d-none')
|
||||
}else{
|
||||
colUnit.removeClass('d-none')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function selectOptionPegawaiEdit() {
|
||||
let selectPegawai = $(`#pegawai_id_edit`);
|
||||
// inisialisasi select2 untuk Unit Kerja
|
||||
selectPegawai.select2({
|
||||
placeholder: '-- Pilih Pegawai --',
|
||||
allowClear:true,
|
||||
width: '100%',
|
||||
dropdownParent: selectPegawai.parent(),
|
||||
ajax:{
|
||||
url : '/select-pegawai',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function(params){
|
||||
return { q: params.term }
|
||||
},
|
||||
processResults: function(data){
|
||||
return {
|
||||
results : data?.data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.nama,
|
||||
}))
|
||||
}
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
});
|
||||
}
|
||||
|
||||
function selectOptionUnitEdit(oldId = null) {
|
||||
let selectUnit = $(`#unit_akses_edit`);
|
||||
// inisialisasi select2 untuk Unit Kerja
|
||||
selectUnit.select2({
|
||||
placeholder: '-- Pilih Unit --',
|
||||
allowClear:true,
|
||||
width: '100%',
|
||||
dropdownParent: selectUnit.parent(),
|
||||
ajax:{
|
||||
url : '/select-unit-kerja-option',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function(params){
|
||||
return { q: params.term }
|
||||
},
|
||||
processResults: function(data){
|
||||
return {
|
||||
results : data?.data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.name,
|
||||
}))
|
||||
}
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
});
|
||||
|
||||
if (oldId) {
|
||||
$.ajax({
|
||||
url: '/select-unit-kerja',
|
||||
data: { id: oldId },
|
||||
dataType: 'json'
|
||||
}).then(function (data) {
|
||||
if (data?.data?.length) {
|
||||
let item = data.data[0];
|
||||
let option = new Option(item.name, item.id, true, true);
|
||||
selectUnit.append(option).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setOldSelect2Value(selector, id, text) {
|
||||
if (!id || !text) return;
|
||||
let option = new Option(text, id, true, true);
|
||||
$(selector).append(option).trigger('change')
|
||||
}
|
||||
|
||||
|
||||
formEditAkses.on('submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
const form = this;
|
||||
const actionUrl = formEditAkses.attr('action');
|
||||
const formData = new FormData(form);
|
||||
formData.append('_method', 'PUT')
|
||||
fetch(actionUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': document.querySelector('input[name="_token"]').value,
|
||||
},
|
||||
body: formData
|
||||
}).then(async(res) => {
|
||||
const responseData = await res.json();
|
||||
|
||||
if (responseData.status) {
|
||||
const handler = function () {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
text: responseData.message || 'Berhasil melakukan aksi!',
|
||||
timer: 2000,
|
||||
showConfirmButton: false,
|
||||
backdrop: true,
|
||||
});
|
||||
formCreateAkses.find('select').val(null).trigger('change');
|
||||
datatableAkses.bootstrapTable('refresh');
|
||||
datatableAkses.bootstrapTable('refresh');
|
||||
modalEdit.removeEventListener('hidden.bs.modal', handler);
|
||||
};
|
||||
modalEdit.addEventListener('hidden.bs.modal', handler);
|
||||
bootstrap.Modal.getInstance(modalEdit).hide();
|
||||
} else {
|
||||
throw new Error(responseData.message || 'Terjadi kesalahan saat menyimpan data.');
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
if (err.message) {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Gagal',
|
||||
text: err.message
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
57
public/js/akses/dt.js
Normal file
57
public/js/akses/dt.js
Normal file
@ -0,0 +1,57 @@
|
||||
datatableAkses.bootstrapTable({
|
||||
url: "/datatable/akses",
|
||||
showRefresh: true,
|
||||
sortable: true,
|
||||
search: true,
|
||||
searchOnEnterKey: false,
|
||||
searchHighlight: true,
|
||||
pagination: true,
|
||||
serverSide:true,
|
||||
pageSize: 10,
|
||||
pageList: [10, 20, 30],
|
||||
cookie: true,
|
||||
cookieIdTable: "table_master_kategori",
|
||||
icons: {
|
||||
refresh: "fas fa-sync-alt",
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
title:"Action",
|
||||
formatter: function(value, row){
|
||||
let buttons = '';
|
||||
buttons += `
|
||||
<button class="btn btn-sm btn-danger me-2" onclick="deleteAkses(this)"
|
||||
data-akses_file_id="${row.akses_file_id}" data-name="${row?.pegawai?.namalengkap}" data-akses="${row?.all_akses ? 'Semua Akses' : row?.akses?.name}">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
`
|
||||
|
||||
buttons += `
|
||||
<button class="btn btn-sm btn-primary me-2" onclick="editAkses(this)"
|
||||
data-akses_file_id="${row.akses_file_id}" data-akses="${row?.all_akses ? 1 : row?.unit_akses}"
|
||||
data-pegawai_id="${row?.pegawai_id}"
|
||||
data-pegawai_nama="${row?.pegawai?.namalengkap}"
|
||||
data-unit_id="${row?.unit_akses}"
|
||||
data-unit_nama="${row?.akses?.name}"
|
||||
>
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>`
|
||||
return `
|
||||
<div class="d-flex space-x">
|
||||
${buttons}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"Nama",
|
||||
field:'pegawai.namalengkap'
|
||||
},
|
||||
{
|
||||
title:"Akses",
|
||||
formatter:function(value, row){
|
||||
return row?.all_akses ? 'Semua Akses' : row?.akses?.name;
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
130
public/js/akses/functions.js
Normal file
130
public/js/akses/functions.js
Normal file
@ -0,0 +1,130 @@
|
||||
$(document).ready(function() {
|
||||
selectOptionPegawai(0)
|
||||
selectOptionUnit(0)
|
||||
});
|
||||
|
||||
function selectOptionPegawai(colCount) {
|
||||
let selectPegawai = $(`#pegawai_id_${colCount}`);
|
||||
// inisialisasi select2 untuk Unit Kerja
|
||||
selectPegawai.select2({
|
||||
placeholder: '-- Pilih Pegawai --',
|
||||
allowClear:true,
|
||||
width: '100%',
|
||||
dropdownParent: selectPegawai.parent(),
|
||||
ajax:{
|
||||
url : '/select-pegawai',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function(params){
|
||||
return { q: params.term }
|
||||
},
|
||||
processResults: function(data){
|
||||
return {
|
||||
results : data?.data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.nama,
|
||||
}))
|
||||
}
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
});
|
||||
}
|
||||
|
||||
function selectOptionUnit(colCount) {
|
||||
let selectUnit = $(`#unit_akses_${colCount}`);
|
||||
// inisialisasi select2 untuk Unit Kerja
|
||||
selectUnit.select2({
|
||||
placeholder: '-- Pilih Unit --',
|
||||
allowClear:true,
|
||||
width: '100%',
|
||||
dropdownParent: selectUnit.parent(),
|
||||
ajax:{
|
||||
url : '/select-unit-kerja-option',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function(params){
|
||||
return { q: params.term }
|
||||
},
|
||||
processResults: function(data){
|
||||
return {
|
||||
results : data?.data.map(item => ({
|
||||
id: item.id,
|
||||
text: item.name,
|
||||
}))
|
||||
}
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
});
|
||||
}
|
||||
|
||||
function selectAkses(colCount){
|
||||
let aksesId = $(`#akses_id_${colCount}`);
|
||||
let colUnit = $(`#col_select_unit_${colCount}`)
|
||||
if(aksesId.val() === "all"){
|
||||
colUnit.addClass('d-none')
|
||||
}else{
|
||||
colUnit.removeClass('d-none')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('change', function(e){
|
||||
e.preventDefault()
|
||||
if(e.target && e.target.id.startsWith("akses_id")){
|
||||
let colCount = e.target.id.split("_")[2];
|
||||
selectAkses(colCount)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
let colCount = 1;
|
||||
function addForm(){
|
||||
let col = $("#col_add_akses")
|
||||
|
||||
let html = '';
|
||||
|
||||
html += `
|
||||
<div class="row mt-3" id="col-${colCount}">
|
||||
<hr/>
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Nama</label>
|
||||
<select class="form-control" name="data[${colCount}][pegawai_id]" id="pegawai_id_${colCount}" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Akses</label>
|
||||
<select class="form-control" name="data[${colCount}][akses]" id="akses_id_${colCount}" required>
|
||||
<option value="" disable>Select Choose</option>
|
||||
<option value="all">Semua Akses</option>
|
||||
<option value="unit">By Unit Akses</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-10 mb-2 d-none" id="col_select_unit_${colCount}">
|
||||
<label>Pilih Unit</label>
|
||||
<select class="form-control" name="data[${colCount}][unit_akses]" id="unit_akses_${colCount}">
|
||||
<option value="" disable>Select Choose</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger mt-3 me-2" onclick="removeCol(${colCount})"><i class="fa-solid fa-trash"></i></button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`
|
||||
col.append(html)
|
||||
selectOptionPegawai(colCount)
|
||||
selectOptionUnit(colCount)
|
||||
colCount++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function removeCol(count){
|
||||
$(`#col-${count}`).remove()
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ function renderTree(units, katDok) {
|
||||
if (!Array.isArray(units)) return '';
|
||||
|
||||
return `
|
||||
<button type="button" class="btn btn-sm btn-primary" onclick="referesh()"><i class="fas fa-sync-alt"></i></button>
|
||||
<ul class="file-tree-ul mt-3">
|
||||
${units.map(el => `
|
||||
<li class="file-tree-li folder">
|
||||
@ -30,7 +31,7 @@ function renderTree(units, katDok) {
|
||||
${files.map(file => `
|
||||
<li class="file-tree-li">
|
||||
📄 <a href="#" class="file-link" data-file="${file.file}" data-id="${file?.file_directory_id}">
|
||||
${file.file}
|
||||
${file.file} - <strong>(${file?.klasifikasi?.nama_klasifikasi_directory})</strong>
|
||||
</a>
|
||||
</li>
|
||||
`).join('')}
|
||||
@ -80,7 +81,7 @@ function index(kategori_dok = null, unitKerja = null, subUnitKerja = null, klasi
|
||||
});
|
||||
});
|
||||
} else {
|
||||
file_tree.innerHTML = '<p style="color:red">Terdapat kesalahan pada server</p>';
|
||||
file_tree.innerHTML = '<p style="color:primary">Silakan lakukan pencarian terlebih dahulu untuk menampilkan data</p>';
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error : ', error));
|
||||
@ -88,6 +89,9 @@ function index(kategori_dok = null, unitKerja = null, subUnitKerja = null, klasi
|
||||
|
||||
index();
|
||||
|
||||
function referesh(){
|
||||
index()
|
||||
}
|
||||
function searchData(){
|
||||
let klasifikasi_id = $("#klasifikasi_dok").val()
|
||||
let kategori_dok = $("#kategori_dok").val()
|
||||
|
||||
30
resources/views/akses/index.blade.php
Normal file
30
resources/views/akses/index.blade.php
Normal file
@ -0,0 +1,30 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('body_main')
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card w-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h4 class="mb-0">Akses</h4>
|
||||
<button type="button" class="btn btn-primary" data-bs-target="#modalAkses" data-bs-toggle="modal">
|
||||
<i data-feather="plus" class="me-1"></i>
|
||||
Tambah Data
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body pt-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table" id="table_akses"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('akses.modal.add')
|
||||
@include('akses.modal.edit')
|
||||
<!-- Scripts -->
|
||||
<script src="{{ ver('/js/akses/_init.js') }}"></script>
|
||||
<script src="{{ ver('/js/akses/dt.js') }}"></script>
|
||||
<script src="{{ ver('/js/akses/functions.js') }}"></script>
|
||||
<script src="{{ ver('/js/akses/action.js') }}"></script>
|
||||
@endsection
|
||||
53
resources/views/akses/modal/add.blade.php
Normal file
53
resources/views/akses/modal/add.blade.php
Normal file
@ -0,0 +1,53 @@
|
||||
<div class="modal fade" id="modalAkses" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<!-- Modal Header -->
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5">Aksi</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<!-- Modal Form -->
|
||||
<form enctype="multipart/form-data" method="POST" id="formAkses">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Nama</label>
|
||||
<select class="form-control" name="data[0][pegawai_id]" id="pegawai_id_0" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Akses</label>
|
||||
<select class="form-control" name="data[0][akses]" id="akses_id_0" required>
|
||||
<option value="" disable>Select Choose</option>
|
||||
<option value="all">Semua Akses</option>
|
||||
<option value="unit">By Unit Akses</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-12 mb-2 d-none" id="col_select_unit_0">
|
||||
<label>Pilih Unit</label>
|
||||
<select class="form-control" name="data[0][unit_akses]" id="unit_akses_0">
|
||||
<option value="" disable>Select Choose</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div id="col_add_akses"></div>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm mt-2" onclick="addForm()">
|
||||
+ Tambah Form
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Footer -->
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
50
resources/views/akses/modal/edit.blade.php
Normal file
50
resources/views/akses/modal/edit.blade.php
Normal file
@ -0,0 +1,50 @@
|
||||
<div class="modal fade" id="modalEditAkses" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<!-- Modal Header -->
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5">Aksi</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<!-- Modal Form -->
|
||||
<form enctype="multipart/form-data" method="POST" id="formEditAkses">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="modal-body">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Nama</label>
|
||||
<select class="form-control" name="pegawai_id" id="pegawai_id_edit" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<label>Akses</label>
|
||||
<select class="form-control" name="akses" id="akses_id_edit" required>
|
||||
<option value="" disable>Select Choose</option>
|
||||
<option value="all">Semua Akses</option>
|
||||
<option value="unit">By Unit Akses</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-12 mb-2 d-none" id="col_select_unit_edit">
|
||||
<label>Pilih Unit</label>
|
||||
<select class="form-control" name="unit_akses" id="unit_akses_edit">
|
||||
<option value="" disable>Select Choose</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Footer -->
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -119,7 +119,7 @@
|
||||
<div id="preview-wrapper" class="col-md-6 d-none">
|
||||
<div class="card shadow-sm h-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center py-2">
|
||||
<h6 class="mb-0">📄 Preview</h6>
|
||||
<h6 class="mb-0">📄 Preview <strong id="confirm_preview_file"></strong></h6>
|
||||
<button class="btn btn-sm btn-outline-danger" id="close-preview">✕</button>
|
||||
</div>
|
||||
<div class="card-body p-2" style="min-height:250px; max-height:80vh; overflow:auto;">
|
||||
@ -145,19 +145,18 @@
|
||||
const katDok = @json($katDok);
|
||||
let currentFile = null;
|
||||
let idDirectory = null;
|
||||
document.addEventListener('click', function(e) {
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.matches('.file-link')) {
|
||||
e.preventDefault();
|
||||
let fileUrl = e.target.getAttribute('data-file');
|
||||
currentFile = fileUrl
|
||||
idDirectory = e.target.getAttribute('data-id');
|
||||
let ext = fileUrl.split('.').pop().toLowerCase();
|
||||
|
||||
$("#confirm_preview_file").html(fileUrl)
|
||||
// ubah layout
|
||||
document.getElementById('tree-wrapper').classList.remove('col-12');
|
||||
document.getElementById('tree-wrapper').classList.add('col-md-6');
|
||||
document.getElementById('preview-wrapper').classList.remove('d-none');
|
||||
|
||||
let previewBox = document.getElementById('file-preview');
|
||||
|
||||
if (['jpg','jpeg','png','gif','webp'].includes(ext)) {
|
||||
@ -172,7 +171,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (e.target.id === 'delete-file') {
|
||||
if (e.target.id === 'delete-file') {
|
||||
if (!currentFile) {
|
||||
Swal.fire({
|
||||
text: "Tidak ada file yang dipilih!",
|
||||
@ -182,8 +181,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Swal.fire({
|
||||
Swal.fire({
|
||||
title: 'Yakin ingin menghapus file ini?',
|
||||
text: "File akan dihapus",
|
||||
icon: 'warning',
|
||||
@ -238,19 +236,16 @@
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// tombol close
|
||||
// tombol close
|
||||
document.getElementById('close-preview').addEventListener('click', function() {
|
||||
document.getElementById('tree-wrapper').classList.remove('col-md-6');
|
||||
document.getElementById('tree-wrapper').classList.add('col-12');
|
||||
document.getElementById('preview-wrapper').classList.add('d-none');
|
||||
document.getElementById('tree-wrapper').classList.remove('col-md-6');
|
||||
document.getElementById('tree-wrapper').classList.add('col-12');
|
||||
document.getElementById('preview-wrapper').classList.add('d-none');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script src="{{ ver('/js/dashboard/_init.js') }}"></script>
|
||||
<script src="{{ ver('/js/dashboard/index.js') }}"></script>
|
||||
|
||||
@ -46,7 +46,17 @@
|
||||
</span>
|
||||
<span class="hide-menu">Master Klasifikasi</span>
|
||||
</div>
|
||||
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a class="sidebar-link justify-content-between"
|
||||
href="/akses" aria-expanded="false">
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="d-flex">
|
||||
<i class="ti ti-layout-grid"></i>
|
||||
</span>
|
||||
<span class="hide-menu">Akses</span>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\AksesFileController;
|
||||
use App\Http\Controllers\AuthController;
|
||||
use App\Http\Controllers\DashboardController;
|
||||
use App\Http\Controllers\MasterKategoriController;
|
||||
@ -16,6 +17,10 @@ Route::middleware(['auth'])->group(function(){
|
||||
Route::get('datatable/master-kategori', [MasterKategoriController::class, 'datatable']);
|
||||
Route::resource('/master-klasifikasi', MasterKlasifikasiController::class);
|
||||
Route::get('datatable/master-klasifikasi', [MasterKlasifikasiController::class, 'datatable']);
|
||||
Route::resource('/akses', AksesFileController::class);
|
||||
Route::get('datatable/akses', [AksesFileController::class, 'datatable']);
|
||||
Route::get('/select-pegawai', [AksesFileController::class, 'optionPegawai']);
|
||||
Route::get('/select-unit-kerja-option', [AksesFileController::class, 'optionUnitKerja']);
|
||||
|
||||
Route::get('/select-unit-kerja', [DashboardController::class, 'OptionUnitKerja']);
|
||||
Route::delete('/delete-file/{id}', [DashboardController::class, 'deleteFile']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user