Skip to content

Commit

Permalink
add category jabatan
Browse files Browse the repository at this point in the history
  • Loading branch information
punkestu committed Nov 23, 2024
1 parent b991ee1 commit 11d0b94
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\Cabang;
use App\Models\PersonelJabatanCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Profile;
Expand All @@ -18,7 +19,10 @@ public function index()
if ($akun->role->name == 'admin') {
$akuns = Profile::with(['user'])->get();
$cabangs = Cabang::all();
return view('account.index', ['akun' => $akun, 'akuns' => $akuns, 'cabangs' => $cabangs]);
$kategori_jabatan = PersonelJabatanCategory::select('category')->distinct()->get();
$jabatans = PersonelJabatanCategory::all();
$jabatans = $jabatans->groupBy('category');
return view('account.index', ['akun' => $akun, 'akuns' => $akuns, 'cabangs' => $cabangs, 'kategori_jabatan' => $kategori_jabatan, 'jabatans' => $jabatans]);
}
return view('account.index', ['akun' => $akun]);
}
Expand Down
44 changes: 44 additions & 0 deletions app/Http/Controllers/JabatanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers;

use App\Models\PersonelJabatanCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class JabatanController extends Controller
{
public function store(Request $request)
{
$request->validate([
'category' => 'required',
'jabatan' => 'required'
]);
DB::beginTransaction();
if (is_array($request->jabatan)) {
foreach ($request->jabatan as $jabatan) {
$personelJabatanCategory = new PersonelJabatanCategory();
$personelJabatanCategory->category = $request->category;
$personelJabatanCategory->jabatan = $jabatan;
$personelJabatanCategory->save();
}
} else {
$personelJabatanCategory = new PersonelJabatanCategory();
$personelJabatanCategory->category = $request->category;
$personelJabatanCategory->jabatan = $request->jabatan;
$personelJabatanCategory->save();
}
DB::commit();
return redirect()->back()->with('success', 'Data berhasil disimpan');
}

public function destroy($id)
{
$personelJabatanCategory = PersonelJabatanCategory::find($id);
if(!$personelJabatanCategory) {
return redirect()->back()->with('error', 'Data tidak ditemukan');
}
$personelJabatanCategory->delete();
return redirect()->back()->with('success', 'Data berhasil dihapus');
}
}
13 changes: 13 additions & 0 deletions app/Models/PersonelJabatanCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PersonelJabatanCategory extends Model
{
use HasFactory;

protected $fillable = ["category", "jabatan"];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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::create('personel_jabatan_categories', function (Blueprint $table) {
$table->id();
$table->string("category");
$table->string("jabatan")->unique();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personel_jabatan_categories');
}
};
2 changes: 2 additions & 0 deletions note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ ] reset konsep + tambah validasi only showable in browser
- [ ] cek ulang koordinat
121 changes: 121 additions & 0 deletions resources/views/account/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,95 @@ class="px-4 py-2 bg-[#003285] text-white opacity-80 hover:opacity-100 rounded-md
class="px-4 py-2 bg-[#003285] text-white opacity-80 hover:opacity-100 rounded-md duration-300">Daftarkan
cabang ke
akun</button>
<button popovertarget="kategori-jabatan"
class="px-4 py-2 bg-[#003285] text-white opacity-80 hover:opacity-100 rounded-md duration-300">Kategori
jabatan</button>
<div id="kategori-jabatan" popover class="p-2 rounded-md w-1/2 max-h-[50vh] overflow-y-auto border-2">
<div>
@if ($kategori_jabatan->count() == 0)
<div class="flex flex-col items-center gap-4">
<p class="text-center">Belum ada kategori jabatan</p>
<button popovertarget="add-kategori"
class=" bg-[#7186F3] hover:bg-[#435EEF] duration-200 text-white px-4 py-2 rounded-lg font-semibold text-center">Tambah
Kategori</button>
</div>
@else
<table class="w-full">
<thead>
<tr>
<th class="border-2 border-slate-400">Nama</th>
<th class="border-2 border-slate-400">Jabatan</th>
<th class="border-2 border-slate-400">Aksi</th>
</tr>
</thead>
<tbody>
@foreach ($kategori_jabatan as $currKategori)
<tr>
<td class="border-2 border-slate-400 px-2 py-1">
{{ $currKategori->category }}</td>
<td class="border-2 border-slate-400 px-2 py-1">
@foreach ($jabatans[$currKategori->category] as $currJabatan)
<div
class="flex items-center gap-1 px-2 py-1 mt-1 bg-gray-200 border-2 border-slate-400 rounded-md">
{{ $currJabatan->jabatan }}
<input type="hidden" name="jabatan"
value="{{ $currJabatan->jabatan }}">
<a href="/akun/jabatan/{{ $currJabatan->id }}/delete">X</a>
</div>
@endforeach
</td>
<td class="border-2 border-slate-400 px-2 py-1">
<button popovertarget="add-jabatan"
class="underline text-blue-500">Tambah</button>
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
</div>
<div id="add-jabatan" popover class="p-2 rounded-md border-2">
<form action="/akun/jabatan" method="POST" class="flex flex-col gap-2">
@csrf
<h1 class="text-center font-semibold text-xl">Tambah Jabatan</h1>
<select name="category" id="category"
class="w-full px-2 py-1 mt-1 bg-white border-2 border-slate-400 rounded-md text-center">
<option value disabled selected>--- Pilih Kategori ---</option>
@foreach ($kategori_jabatan as $currKategori)
<option value="{{ $currKategori->category }}">{{ $currKategori->category }}</option>
@endforeach
</select>
<input type="text" name="jabatan" id="jabatan"
class="w-full px-2 py-1 mt-1 bg-white border-2 border-slate-400 rounded-md text-center"
placeholder="Nama Jabatan">
<button
class="bg-[#7186F3] hover:bg-[#435EEF] duration-200 text-white px-4 py-2 rounded-lg font-semibold text-center">Simpan</button>
</form>
</div>
<div id="add-kategori" popover class="p-2 rounded-md border-2">
<form action="/akun/jabatan" id="add-jabatan-form" method="POST" class="flex flex-col gap-2">
@csrf
<h1 class="text-center font-semibold text-xl">Tambah Kategori Jabatan</h1>
<input type="text" name="category" id="category"
class="w-full px-2 py-1 mt-1 bg-white border-2 border-slate-400 rounded-md text-center"
placeholder="Nama Kategori">
<div class="flex flex-wrap gap-2">
<div class="flex flex-wrap gap-2" id="jabatan-list">
</div>
<div class="flex flex-wrap items-center gap-2">
<input type="text" id="jabatan-baru"
class="max-w-full px-2 py-1 mt-1 bg-white border-2 border-slate-400 rounded-md text-center"
placeholder="Jabatan Baru ...">
<button type="button"
class="bg-[#7186F3] hover:bg-[#435EEF] duration-200 text-white px-4 py-2 rounded-lg font-semibold text-center"
onclick="tambahJabatan()">Tambah</button>
</div>
</div>
<button
class="bg-[#7186F3] hover:bg-[#435EEF] duration-200 text-white px-4 py-2 rounded-lg font-semibold text-center">Simpan</button>
</form>
</div>
<div id="cabang-assign" popover class="p-2 rounded-md w-1/2 border-2">
<form action="/akun/assign" method="POST" class="flex flex-col gap-2">
@csrf
Expand Down Expand Up @@ -90,6 +179,38 @@ class="bg-[#7186F3] hover:bg-[#435EEF] duration-200 text-white px-4 py-2 rounded
@include('components.footer')
<script src="/script/nav.js"></script>
<script src="/script/chatbot.js"></script>
<script>
function itemJabatan(nama) {
return `<div
class="flex items-center gap-1 px-2 py-1 mt-1 bg-gray-200 border-2 border-slate-400 rounded-md">
${nama}
<input type="hidden" name="jabatan" value="${nama}">
<button type="button" onclick="removeJabatan(this)">X</button>
</div>`;
}
function tambahJabatan() {
const jabatanBaru = document.getElementById('jabatan-baru').value;
const jabatanList = document.getElementById('jabatan-list');
jabatanList.innerHTML += itemJabatan(jabatanBaru);
document.getElementById('jabatan-baru').value = "";
}
function removeJabatan(e) {
e.parentElement.remove();
}
document.getElementById('jabatan-baru').addEventListener('keyup', function(e) {
if (e.key === 'Enter') {
tambahJabatan();
}
});
document.getElementById('add-jabatan-form').addEventListener('submit', function(e) {
if (document.activeElement === document.getElementById("jabatan-baru")) {
e.preventDefault();
return;
}
});
</script>
</body>

</html>
1 change: 1 addition & 0 deletions resources/views/components/modal-component.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@include('components.modal', ['message' => session('success')])
@endif
@if ($errors->any())
{{$errors->first()}}
@include('components.modal', [
'message' => str_contains($errors->first(), 'required')
? 'Mohon isi semua kolom'
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\AuthController;
use App\Http\Controllers\JabatanController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\PersonelController;
// use App\Http\Controllers\Rotasi\HomeController as RotasiHomeController;
Expand Down Expand Up @@ -52,6 +53,8 @@
Route::get('/edit', [AccountController::class, 'updateView']);
Route::post('/edit', [AccountController::class, 'update']);
Route::middleware(['is.admin'])->post('/assign', [AccountController::class, 'assign']);
Route::middleware(['is.admin'])->post('/jabatan', [JabatanController::class, 'store']);
Route::middleware(['is.admin'])->get('/jabatan/{id}/delete', [JabatanController::class, 'destroy']);
});

Route::group(['prefix' => 'personel', 'middleware' => [
Expand Down

0 comments on commit 11d0b94

Please sign in to comment.