From 1077421fbbaa7e5be56db437f6fc3f15644e0465 Mon Sep 17 00:00:00 2001 From: Habibie Date: Tue, 8 Sep 2026 15:56:29 +0700 Subject: [PATCH] fix edit identitas: logo, pilih kab --- app/Http/Controllers/IdentitasController.php | 15 +++- resources/views/identitas/edit.blade.php | 83 ++++++++++++++------ tests/Feature/IdentitasControllerApiTest.php | 23 ++++++ 3 files changed, 93 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/IdentitasController.php b/app/Http/Controllers/IdentitasController.php index ab5afb6ca..781efba09 100644 --- a/app/Http/Controllers/IdentitasController.php +++ b/app/Http/Controllers/IdentitasController.php @@ -28,9 +28,18 @@ public function edit() public function logo() { $path = Identitas::first(); - if (is_null($path) || is_null($path->logo)) { - $path->logo = 'opensid_logo.png'; + if ($path && $path->logo) { + $storagePath = storage_path('app/public/img/'.$path->logo); + if (file_exists($storagePath)) { + return ambilBerkas($storagePath); + } + + $publicPath = public_path('storage/img/'.$path->logo); + if (file_exists($publicPath)) { + return ambilBerkas($publicPath); + } } - ambilBerkas(public_path('storage/img/').$path->logo); + + return ambilBerkas(public_path('assets/img/opensid_logo.png')); } } diff --git a/resources/views/identitas/edit.blade.php b/resources/views/identitas/edit.blade.php index c5bda83c4..aff744449 100644 --- a/resources/views/identitas/edit.blade.php +++ b/resources/views/identitas/edit.blade.php @@ -22,6 +22,7 @@
Logo
Logo {{ config('app.namaAplikasi') }}
@@ -153,16 +154,18 @@ function identitas() { }; }, processResults: function(data) { - let results = data.results; + let results = data.results || []; return { - results: results.map(value => { - return { - 'id': value.kode_prov, - 'text': value.nama_prov, - 'kode_prov': value.kode_prov, - 'nama_prov': value.nama_prov - } - }), + results: results + .filter(value => value.kode_prov && value.nama_prov) + .map(value => { + return { + 'id': value.kode_prov, + 'text': value.nama_prov, + 'kode_prov': value.kode_prov, + 'nama_prov': value.nama_prov + } + }), pagination: data.pagination, } }, @@ -177,13 +180,30 @@ function identitas() { }, }); + if (this.dataIdentitas.kode_provinsi && this.dataIdentitas.nama_provinsi) { + let optionProv = new Option(this.dataIdentitas.nama_provinsi, this.dataIdentitas.kode_provinsi, true, true); + $(this.$refs.selectProv).append(optionProv).trigger('change'); + } + this.select2Prov.on("select2:select", (event) => { this.dataIdentitas.kode_provinsi = event.params.data.kode_prov; this.dataIdentitas.nama_provinsi = event.params.data.nama_prov; + this.dataIdentitas.kode_kabupaten = null; + this.dataIdentitas.nama_kabupaten = null; + $(this.$refs.select).val(null).trigger('change'); + }); + + this.select2Prov.on("select2:clear", () => { + this.dataIdentitas.kode_provinsi = null; + this.dataIdentitas.nama_provinsi = null; + this.dataIdentitas.kode_kabupaten = null; + this.dataIdentitas.nama_kabupaten = null; + $(this.$refs.select).val(null).trigger('change'); }); }, selectKab() { + const _this = this; this.select2 = $(this.$refs.select).select2({ ajax: { url: function() { @@ -195,23 +215,25 @@ function identitas() { data: function(params) { return { cari: params.term || '', - kode: $('select[name=prov]').val(), + kode: $('select[name=prov]').val() || _this.dataIdentitas.kode_provinsi, page: params.page || 1, }; }, processResults: function(data) { - let results = data.results; + let results = data.results || []; return { - results: results.map(value => { - return { - 'id': value.kode_kab, - 'text': value.nama_prov + ' - ' + value.nama_kab, - 'kode_kab': value.kode_kab, - 'kode_prov': value.kode_prov, - 'nama_kab': value.nama_kab, - 'nama_prov': value.nama_prov - } - }), + results: results + .filter(value => value.kode_kab && value.nama_kab) + .map(value => { + return { + 'id': value.kode_kab, + 'text': (value.nama_prov ? value.nama_prov + ' - ' : '') + value.nama_kab, + 'kode_kab': value.kode_kab, + 'kode_prov': value.kode_prov, + 'nama_kab': value.nama_kab, + 'nama_prov': value.nama_prov + } + }), pagination: data.pagination, } }, @@ -226,12 +248,23 @@ function identitas() { }, }); + if (this.dataIdentitas.kode_kabupaten && this.dataIdentitas.nama_kabupaten) { + let kabText = (this.dataIdentitas.nama_provinsi ? this.dataIdentitas.nama_provinsi + ' - ' : '') + this.dataIdentitas.nama_kabupaten; + let optionKab = new Option(kabText, this.dataIdentitas.kode_kabupaten, true, true); + $(this.$refs.select).append(optionKab).trigger('change'); + } + this.select2.on("select2:select", (event) => { this.dataIdentitas.kode_kabupaten = event.params.data.kode_kab; this.dataIdentitas.kode_provinsi = event.params.data.kode_prov; this.dataIdentitas.nama_kabupaten = event.params.data.nama_kab; this.dataIdentitas.nama_provinsi = event.params.data.nama_prov; }); + + this.select2.on("select2:clear", () => { + this.dataIdentitas.kode_kabupaten = null; + this.dataIdentitas.nama_kabupaten = null; + }); }, uploadGambar() { @@ -267,15 +300,15 @@ function identitas() { contentType: false, // tell jQuery not to set contentType success: function(response) { if (response.success == true) { - this.data.logo = response.data Swal.fire({ title: 'Simpan!', text: 'Data berhasil tersimpan', icon: 'success', - showConfirmButton: false, + showConfirmButton: true, timer: 1500, - }) - location.reload(); + }).then(function() { + window.location.reload(); + }); } else { Swal.fire({ diff --git a/tests/Feature/IdentitasControllerApiTest.php b/tests/Feature/IdentitasControllerApiTest.php index 06100a4db..16eeedd5d 100644 --- a/tests/Feature/IdentitasControllerApiTest.php +++ b/tests/Feature/IdentitasControllerApiTest.php @@ -95,4 +95,27 @@ public function test_post_upload_favicon() $this->assertTrue(File::exists('public/favicons/favicon-96x96.png')); $this->assertDatabaseHas('identitas', $dataLogo); } + + public function test_get_logo() + { + ob_start(); + $response = $this->get('/pengaturan/logo'); + ob_end_clean(); + + $response->assertStatus(Response::HTTP_OK); + } + + public function test_get_logo_fallback_when_null() + { + $identitas = \App\Models\Identitas::first(); + if ($identitas) { + $identitas->update(['logo' => null]); + } + + ob_start(); + $response = $this->get('/pengaturan/logo'); + ob_end_clean(); + + $response->assertStatus(Response::HTTP_OK); + } }