From 96643c30ded0770ead09d47c11506abffdd9af6a Mon Sep 17 00:00:00 2001 From: myuqinurrohman Date: Mon, 24 Mar 2025 10:50:56 +0700 Subject: [PATCH] chore: add issue count and change show UI in gov agency --- .../Dashboard/DatatableController.php | 20 ++- .../Dashboard/GovernmentAgencyController.php | 4 +- .../Dashboard/IssueManagementController.php | 2 +- app/Http/Requests/ClassificationRequest.php | 11 +- app/Http/Requests/GovernmentAgencyRequest.php | 21 ++++ app/Http/Requests/LocationRequest.php | 10 +- .../Requests/SubClassificationRequest.php | 14 ++- app/Http/Requests/SubLocationRequest.php | 14 ++- app/Models/GovernmentAgency.php | 3 +- ...14325_create_government_agencies_table.php | 1 + database/seeders/GovernmentAgencySeeder.php | 1 + .../dashboard/classifications/show.blade.php | 2 +- .../government-agencies/create.blade.php | 4 +- .../government-agencies/edit.blade.php | 8 +- .../government-agencies/show.blade.php | 119 +++++++++++------- .../views/dashboard/locations/show.blade.php | 25 ++-- .../sub-classifications/show.blade.php | 2 +- .../dashboard/sub-locations/show.blade.php | 26 ++-- .../views/partials/app/datatable.blade.php | 19 ++- 19 files changed, 213 insertions(+), 93 deletions(-) diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index db4abb9..a159831 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -356,12 +356,19 @@ public function subLocation(Request $request){ public function governmentAgency(Request $request){ if ($request->ajax()) { - $data = GovernmentAgency::all(); + $data = GovernmentAgency::with(['issues'])->get(); return DataTables::of($data) ->addIndexColumn() ->addColumn('issues', function ($data) { - return $data->managementIssues->count(); + $issueCount = $data->issues->count(); + + if($issueCount > 0){ + return $issueCount. ' [Lihat]'; + }else{ + return $issueCount; + } + }) ->addColumn('action', function ($data) { $showUrl = route('dashboard.government.agencies.show', ['id' => encrypt_id($data->id)]); @@ -392,7 +399,7 @@ public function governmentAgency(Request $request){ return $dropdown; }) - ->rawColumns(['action']) + ->rawColumns(['issues', 'action']) ->make(true); } @@ -1722,6 +1729,7 @@ public function issueManagement(Request $request){ $subClassificationParam = $request->input('sub_classification', null); $locationParam = $request->input('location', null); $subLocationParam = $request->input('sub_location', null); + $governmentAgencyParam = $request->input('government_agency', null); if($classificationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('classification_id', decrypt_id($classificationParam))->get(); @@ -1735,6 +1743,12 @@ public function issueManagement(Request $request){ }else if($subLocationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_location_id', decrypt_id($subLocationParam))->get(); + }else if($governmentAgencyParam){ + $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies']) + ->whereHas('governmentAgencies', function ($query) use ($governmentAgencyParam) { + $query->where('issue_managements_government_agencies.government_agency_id', decrypt_id($governmentAgencyParam)); + }) + ->get(); }else{ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->get(); } diff --git a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php index 0f43b03..ca942df 100644 --- a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php +++ b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php @@ -25,13 +25,12 @@ public function create(){ public function store(GovernmentAgencyRequest $request){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $createdGovernmentAgency = GovernmentAgency::create($validatedData); if($createdGovernmentAgency){ - return redirect()->back()->with('success-status', 'Berhasil menambahkan OPD.'); + return redirect()->route('dashboard.government.agencies.index')->with('success-status', 'Berhasil menambahkan OPD.'); }else{ return redirect()->back()->with('failed-status', 'Gagal menambahkan OPD'); } @@ -48,7 +47,6 @@ public function edit($id){ public function update(GovernmentAgencyRequest $request, $id){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $governmentAgency = GovernmentAgency::findOrFail(decrypt_id($id)); diff --git a/app/Http/Controllers/Dashboard/IssueManagementController.php b/app/Http/Controllers/Dashboard/IssueManagementController.php index daea6f2..b9dbce1 100644 --- a/app/Http/Controllers/Dashboard/IssueManagementController.php +++ b/app/Http/Controllers/Dashboard/IssueManagementController.php @@ -23,7 +23,7 @@ public function index(Request $request){ 'sub_classification' => $request->input('sub_classification', null), 'location' => $request->input('location', null), 'sub_location' => $request->input('sub_location', null), - 'agency' => $request->input('agency', null), + 'government_agency' => $request->input('government_agency', null), ]); } diff --git a/app/Http/Requests/ClassificationRequest.php b/app/Http/Requests/ClassificationRequest.php index f8dd5ba..467c265 100644 --- a/app/Http/Requests/ClassificationRequest.php +++ b/app/Http/Requests/ClassificationRequest.php @@ -24,17 +24,26 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + + public function messages(): array { return [ 'name.required' => 'Nama klasifikasi harus diisi.', + 'name.max' => 'Nama klasifikasi tidak boleh lebih dari 100 karakter.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus memiliki nilai aktif atau tidak aktif.', 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', diff --git a/app/Http/Requests/GovernmentAgencyRequest.php b/app/Http/Requests/GovernmentAgencyRequest.php index 5b17fe6..a0cfcea 100644 --- a/app/Http/Requests/GovernmentAgencyRequest.php +++ b/app/Http/Requests/GovernmentAgencyRequest.php @@ -29,4 +29,25 @@ public function rules(): array 'description' => ['nullable'], ]; } + + protected function prepareForValidation() + { + $this->merge([ + 'short_name' => filled($this->short_name) ? $this->short_name : null, + 'location' => filled($this->location) ? $this->location : null, + 'description' => filled($this->description) ? $this->description : null, + ]); + } + + public function messages(): array + { + return [ + 'name.required' => 'Nama OPD harus diisi.', + 'name.max' => 'Nama OPD tidak boleh lebih dari 100 karakter.', + 'short_name.nullable' => 'Singkatan nama boleh kosong jika tidak diperlukan.', + 'short_name.max' => 'Singkatan nama tidak boleh lebih dari 100 karakter.', + 'location.nullable' => 'Lokasi boleh kosong jika tidak diperlukan.', + 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', + ]; + } } diff --git a/app/Http/Requests/LocationRequest.php b/app/Http/Requests/LocationRequest.php index c119be5..3ca14ac 100644 --- a/app/Http/Requests/LocationRequest.php +++ b/app/Http/Requests/LocationRequest.php @@ -23,16 +23,24 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ 'name.required' => 'Nama lokus harus diisi.', + 'name.max' => 'Nama lokus tidak boleh lebih dari 100 karakter.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus memiliki nilai aktif atau tidak aktif.', 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', diff --git a/app/Http/Requests/SubClassificationRequest.php b/app/Http/Requests/SubClassificationRequest.php index c661a85..ae05180 100644 --- a/app/Http/Requests/SubClassificationRequest.php +++ b/app/Http/Requests/SubClassificationRequest.php @@ -23,19 +23,27 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'classification_id' => ['required', 'exists:classifications,id'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ - 'name.required' => 'Nama klasifikasi harus diisi.', - 'classification_id.required' => 'Klasifikasi utama harus dipilih.', + 'name.required' => 'Nama sub klasifikasi harus diisi.', + 'name.max' => 'Nama sub klasifikasi tidak boleh lebih dari 100 karakter.', + 'classification_id.required' => 'Klasifikasi harus dipilih.', 'classification_id.exists' => 'Klasifikasi yang dipilih tidak valid.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus bernilai aktif atau tidak aktif.', diff --git a/app/Http/Requests/SubLocationRequest.php b/app/Http/Requests/SubLocationRequest.php index bd8480b..4bff82f 100644 --- a/app/Http/Requests/SubLocationRequest.php +++ b/app/Http/Requests/SubLocationRequest.php @@ -23,18 +23,26 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'location_id' => ['required', 'exists:locations,id'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ - 'name.required' => 'Nama lokus harus diisi.', - 'location_id.required' => 'Lokus utama harus dipilih.', + 'name.required' => 'Nama sub lokus harus diisi.', + 'name.max' => 'Nama sub lokus tidak boleh lebih dari 100 karakter.', + 'location_id.required' => 'Lokus harus dipilih.', 'location_id.exists' => 'Lokus yang dipilih tidak valid.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus bernilai aktif atau tidak aktif.', diff --git a/app/Models/GovernmentAgency.php b/app/Models/GovernmentAgency.php index a2f9dff..1890727 100644 --- a/app/Models/GovernmentAgency.php +++ b/app/Models/GovernmentAgency.php @@ -7,6 +7,7 @@ class GovernmentAgency extends Model { + use SoftDeletes; protected $table = 'government_agencies'; @@ -18,7 +19,7 @@ class GovernmentAgency extends Model 'enhancer_id', ]; - public function managementIssues() + public function issues() { return $this->belongsToMany(IssueManagement::class, 'issue_managements_government_agencies', 'government_agency_id', 'issue_management_id') ->using(IssueManagementGovernmentAgency::class) diff --git a/database/migrations/2025_02_27_014325_create_government_agencies_table.php b/database/migrations/2025_02_27_014325_create_government_agencies_table.php index 122a498..24ec2fd 100644 --- a/database/migrations/2025_02_27_014325_create_government_agencies_table.php +++ b/database/migrations/2025_02_27_014325_create_government_agencies_table.php @@ -20,6 +20,7 @@ public function up(): void $table->unsignedBigInteger('enhancer_id'); $table->foreign('enhancer_id')->references('id')->on('users'); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/seeders/GovernmentAgencySeeder.php b/database/seeders/GovernmentAgencySeeder.php index 7320138..8400db6 100644 --- a/database/seeders/GovernmentAgencySeeder.php +++ b/database/seeders/GovernmentAgencySeeder.php @@ -28,6 +28,7 @@ public function run(): void 'name' => $normalizedAgencyName, // Simpan dengan format aslinya 'created_at' => $agency->created_at, 'updated_at' => $agency->updated_at, + 'deleted_at' => $agency->deleted_at, 'enhancer_id' => $agency->user_id, ]); } diff --git a/resources/views/dashboard/classifications/show.blade.php b/resources/views/dashboard/classifications/show.blade.php index 1c22a5e..7211deb 100644 --- a/resources/views/dashboard/classifications/show.blade.php +++ b/resources/views/dashboard/classifications/show.blade.php @@ -36,7 +36,7 @@ @elseif ($classification->status == 0) Nonaktif @elseif ($classification->status == 1) - Aktif + Aktif @else Tidak Diketahui @endif diff --git a/resources/views/dashboard/government-agencies/create.blade.php b/resources/views/dashboard/government-agencies/create.blade.php index 2953a87..6b48cc1 100644 --- a/resources/views/dashboard/government-agencies/create.blade.php +++ b/resources/views/dashboard/government-agencies/create.blade.php @@ -12,7 +12,7 @@
{{$title}}
-
+ @csrf
@@ -60,7 +60,7 @@
Kembali - +
diff --git a/resources/views/dashboard/government-agencies/edit.blade.php b/resources/views/dashboard/government-agencies/edit.blade.php index bd6b81e..24f2d6e 100644 --- a/resources/views/dashboard/government-agencies/edit.blade.php +++ b/resources/views/dashboard/government-agencies/edit.blade.php @@ -12,7 +12,7 @@
{{$title}}
- + @csrf @method('put')
@@ -60,8 +60,12 @@

+ @if (request()->query('show')) + Kembali + @else Kembali - + @endif +
diff --git a/resources/views/dashboard/government-agencies/show.blade.php b/resources/views/dashboard/government-agencies/show.blade.php index da1b7bc..0e29a98 100644 --- a/resources/views/dashboard/government-agencies/show.blade.php +++ b/resources/views/dashboard/government-agencies/show.blade.php @@ -7,57 +7,80 @@
-
-
-
-
{{$title}}
-
- - @csrf - @method('put') -
-
-
- -
- +
+
+
+ +
+
+ {{--
+
Personal Information
+

Basic info, like your name and address, that you use on Nio Platform.

+
--}} +
+
+
+ Nama OPD + {{$governmentAgency->name}} +
-
-
-
-
- -
- +
+
+ Singkatan Nama + {{$governmentAgency->short_name ?? '-'}} +
-
-
-
-
- -
- +
+
+ Lokasi + {{$governmentAgency->location ?? '-'}} +
-
-
-
-
- -
-
{!! $governmentAgency->description !!}
+
+
+ Isu + + @if ($governmentAgency->issues->count() > 0) + {{$governmentAgency->issues->count()}} + @else + {{$governmentAgency->issues->count()}} + @endif + +
-
-
-
-
-
- Kembali - Ubah -
-
-
- -
+
+
+ Dibuat Pada + {{idn_date($governmentAgency->created_at, 'l, d F Y')}} +
+
+
+
+ {{--
--}} +
+
+ Deskripsi +
+
+
+
+ {!!$governmentAgency->description ?? '-' !!} +
+
+
+
+
+
+ Kembali + Ubah +
+
+
+
@@ -65,4 +88,4 @@
-@include('partials.dashboard.footer', ['rich_editor' => true]) +@include('partials.dashboard.footer', ['rich_editor' => false]) diff --git a/resources/views/dashboard/locations/show.blade.php b/resources/views/dashboard/locations/show.blade.php index 6e34ae9..9ea01b6 100644 --- a/resources/views/dashboard/locations/show.blade.php +++ b/resources/views/dashboard/locations/show.blade.php @@ -31,16 +31,15 @@
Status - @switch($location->status) - @case(0) - Nonaktif - @break - @case(1) - Aktif - @break - @default - Tidak Diketahui - @endswitch + @if (filled($location->deleted_at)) + Dihapus + @elseif ($location->status == 0) + Nonaktif + @elseif ($location->status == 1) + Aktif + @else + Tidak Diketahui + @endif
@@ -68,6 +67,12 @@
+
+
+ Dibuat Pada + {{idn_date($location->created_at, 'l, d F Y')}} +
+
{{--
--}} diff --git a/resources/views/dashboard/sub-classifications/show.blade.php b/resources/views/dashboard/sub-classifications/show.blade.php index 6e24b7d..4332c6d 100644 --- a/resources/views/dashboard/sub-classifications/show.blade.php +++ b/resources/views/dashboard/sub-classifications/show.blade.php @@ -54,7 +54,7 @@ @elseif ($subClassification->status == 0) Nonaktif @elseif ($subClassification->status == 1) - Aktif + Aktif @else Tidak Diketahui @endif diff --git a/resources/views/dashboard/sub-locations/show.blade.php b/resources/views/dashboard/sub-locations/show.blade.php index 3663011..b44fed1 100644 --- a/resources/views/dashboard/sub-locations/show.blade.php +++ b/resources/views/dashboard/sub-locations/show.blade.php @@ -49,18 +49,22 @@
Status - @switch($subLocation->status) - @case(0) - Nonaktif - @break - @case(1) - Aktif - @break - @default - Tidak Diketahui - @endswitch + @if (filled($subLocation->deleted_at)) + Dihapus + @elseif ($subLocation->status == 0) + Nonaktif + @elseif ($subLocation->status == 1) + Aktif + @else + Tidak Diketahui + @endif +
+
+
+
+ Dibuat Pada + {{idn_date($subLocation->created_at, 'l, d F Y')}}
-
diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index 24e5755..04b367b 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -222,9 +222,24 @@ { data: 'created_at', name: 'created_at', visible: false }, { data: 'id', name: 'id', orderable: true, searchable: false, visible: false }, ], + columnDefs: [ + { targets: 0, width: 'auto' }, + { targets: 2, width: '10%' }, + { targets: 3, width: '7%' }, + { + targets: [1], + createdCell: function(td, cellData, rowData, row, col) { + $(td).css({ + 'word-wrap': 'break-word', + 'white-space': 'normal', + 'overflow-wrap': 'break-word' + }); + } + } + ], language: datatableLanguage, autoWidth: false, - order: [[3, 'desc']], + order: [[4, 'desc']], pagingType: "simple", lengthMenu: [[10, 25, 50, 100, -1], ['Tampilkan 10 data', 'Tampilkan 25 data', 'Tampilkan 50 data', 'Tampilkan 100 data', 'Tampilkan semua']], scrollX: true @@ -805,7 +820,7 @@ $('#issueManagementsTable').DataTable({ processing: true, serverSide: true, - ajax: '{{ route('dashboard.issue.managements.data', ["classification" => $classification, "sub_classification" => $sub_classification, "location" => $location, "sub_location" => $sub_location, "agency" => $agency]) }}', + ajax: '{{ route('dashboard.issue.managements.data', ["classification" => $classification, "sub_classification" => $sub_classification, "location" => $location, "sub_location" => $sub_location, "government_agency" => $government_agency]) }}', columns: [ { data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false }, { data: 'code', name: 'code' },