From e71c3eed38241f54ea9970d39d5d2461d76584c0 Mon Sep 17 00:00:00 2001 From: Vinsensiaaa Date: Mon, 4 Mar 2024 16:01:10 +0700 Subject: [PATCH] Melakukan Perubahan pada pengguna --- .../Admin/MstPenggunaController.php | 35 ++++++++++++++++--- app/Models/Pengaturan.php | 18 ++++++++++ .../views/admin/mst_pengguna/index.blade.php | 30 ++++++++-------- routes/web.php | 6 ++-- 4 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 app/Models/Pengaturan.php diff --git a/app/Http/Controllers/Admin/MstPenggunaController.php b/app/Http/Controllers/Admin/MstPenggunaController.php index 53763ef..3e4533f 100644 --- a/app/Http/Controllers/Admin/MstPenggunaController.php +++ b/app/Http/Controllers/Admin/MstPenggunaController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Models\User; use App\Models\Role; +use App\Models\Pengaturan; use App\Models\Roless; use App\Models\RoleUser; use Illuminate\Http\Request; @@ -25,7 +26,8 @@ class MstPenggunaController extends Controller { $data = null; // $data = User::where('role_name', "<>", "superadmin")->latest()->paginate(10); - return view('admin.mst_pengguna.index',compact('data')) + $pengaturan = Pengaturan::where("id",1)->first(); + return view('admin.mst_pengguna.index',compact('data', 'pengaturan')) ->with('i', (request()->input('page', 1) - 1) * 10); } @@ -171,7 +173,7 @@ class MstPenggunaController extends Controller ->with('success','Lock upload data sudah diubah!'); } - public function lockTambahData($userId="", $reset=0, Request $req) + public function lockTambahData($userId="", $reset=0, $check=0, Request $req) { $updateValue = [ "lock_tambah_data"=>$reset == 0 ? 1:0, @@ -181,6 +183,15 @@ class MstPenggunaController extends Controller if (empty($userId)) { + if ($check==2){ + $updateValue = [ + "lock_tambah_data"=>0, + ]; + Pengaturan::where("id",1)->update(["check_all_tambah"=>0]); + }else{ + Pengaturan::where("id",1)->update(["check_all_tambah"=>1]); + } + User::query()->update($updateValue); }else{ User::where(["id"=>$userId])->update($updateValue); @@ -191,7 +202,7 @@ class MstPenggunaController extends Controller } - public function lockUbahData($userId="", $reset=0, Request $req) + public function lockUbahData($userId="", $reset=0, $check=0, Request $req) { $updateValue = [ "lock_ubah_data"=>$reset == 0 ? 1:0, @@ -200,6 +211,14 @@ class MstPenggunaController extends Controller if (empty($userId)) { + if ($check==2){ + $updateValue = [ + "lock_ubah_data"=>0, + ]; + Pengaturan::where("id",1)->update(["check_all_ubah"=>0]); + }else{ + Pengaturan::where("id",1)->update(["check_all_ubah"=>1]); + } User::query()->update($updateValue); }else{ User::where(["id"=>$userId])->update($updateValue); @@ -210,7 +229,7 @@ class MstPenggunaController extends Controller } - public function lockHapusData($userId="", $reset=0, Request $req) + public function lockHapusData($userId="", $reset=0, $check=0, Request $req) { $updateValue = [ "lock_hapus_data"=>$reset == 0 ? 1:0, @@ -219,6 +238,14 @@ class MstPenggunaController extends Controller if (empty($userId)) { + if ($check==2){ + $updateValue = [ + "lock_hapus_data"=>0, + ]; + Pengaturan::where("id",1)->update(["check_all_hapus"=>0]); + }else{ + Pengaturan::where("id",1)->update(["check_all_hapus"=>1]); + } User::query()->update($updateValue); }else{ User::where(["id"=>$userId])->update($updateValue); diff --git a/app/Models/Pengaturan.php b/app/Models/Pengaturan.php new file mode 100644 index 0000000..566c1c5 --- /dev/null +++ b/app/Models/Pengaturan.php @@ -0,0 +1,18 @@ + Tambah Data - - - - - - - -
@@ -40,10 +32,10 @@ NRK Nama Level - Lock Upload - Lock Tambah - Lock Ubah - Lock Hapus + Lock Upload + check_all_tambah=="1"?"checked":"" }}>Lock Tambah + check_all_ubah=="1"?"checked":"" }}>Lock Ubah + check_all_hapus=="1"?"checked":"" }}>Lock Hapus Action @@ -201,6 +193,8 @@ } }) }); + + $("#btn_reset_lock_all").on("click", function(){ let test = Swal.fire({ @@ -220,6 +214,7 @@ $("#btn_lock_tambah").on("click", function(){ + let checkVal = $(this).prop("checked"); let test = Swal.fire({ title: 'Fitur tambah data akan dikunci untuk semua user!?', showDenyButton: true, @@ -230,7 +225,8 @@ }).then((result) => { /* Read more about isConfirmed, isDenied below */ if (result.isConfirmed) { - location.href = "{{ URL::to("/admin/users") }}/lock-tambah-all/0/0"; + let val = checkVal == true?1:2; + location.href = "{{ URL::to("/admin/users") }}/lock-tambah-all/0/0/"+val; } }) }); @@ -252,6 +248,7 @@ }); $("#btn_lock_ubah").on("click", function(){ + let checkVal = $(this).prop("checked"); let test = Swal.fire({ title: 'Fitur ubah data akan dikunci untuk semua user!?', showDenyButton: true, @@ -262,7 +259,8 @@ }).then((result) => { /* Read more about isConfirmed, isDenied below */ if (result.isConfirmed) { - location.href = "{{ URL::to("/admin/users") }}/lock-ubah-all/0/0"; + let val = checkVal == true?1:2; + location.href = "{{ URL::to("/admin/users") }}/lock-ubah-all/0/0/"+val; } }) }); @@ -284,6 +282,7 @@ }); $("#btn_lock_hapus").on("click", function(){ + let checkVal = $(this).prop("checked"); let test = Swal.fire({ title: 'Fitur hapus data akan dikunci untuk semua user!?', showDenyButton: true, @@ -294,7 +293,8 @@ }).then((result) => { /* Read more about isConfirmed, isDenied below */ if (result.isConfirmed) { - location.href = "{{ URL::to("/admin/users") }}/lock-hapus-all/0/0"; + let val = checkVal == true?1:2; + location.href = "{{ URL::to("/admin/users") }}/lock-hapus-all/0/0/"+val; } }) }); diff --git a/routes/web.php b/routes/web.php index 8f355ef..5584a23 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,13 +38,13 @@ Route::group(['middleware' => 'auth'], function () { Route::get('users/{userId}/lock-ubah-data/{type}', [MstPenggunaController::class, 'lockUbahData']); Route::get('users/{userId}/lock-hapus-data/{type}', [MstPenggunaController::class, 'lockHapusData']); - Route::get('users/lock-tambah-all/{userId}/{reset}', [MstPenggunaController::class, 'lockTambahData']); + Route::get('users/lock-tambah-all/{userId}/{reset}/{check}', [MstPenggunaController::class, 'lockTambahData']); Route::get('users/{userId}/lock-tambah-all/{reset}', [MstPenggunaController::class, 'lockTambahData']); Route::get('users/{userId}/lock-ubah/{reset}', [MstPenggunaController::class, 'lockUbahData']); - Route::get('users/lock-ubah-all/{userId}/{reset}', [MstPenggunaController::class, 'lockUbahData']); + Route::get('users/lock-ubah-all/{userId}/{reset}/{check}', [MstPenggunaController::class, 'lockUbahData']); - Route::get('users/lock-hapus-all/{userId}/{reset}', [MstPenggunaController::class, 'lockHapusData']); + Route::get('users/lock-hapus-all/{userId}/{reset}/{check}', [MstPenggunaController::class, 'lockHapusData']); Route::get('users/{userId}/lock-hapus-all/{reset}', [MstPenggunaController::class, 'lockHapusData']); Route::get('users/{user}/reset', [MstPenggunaController::class, 'resetPass']);