Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions app/Services/ConfigApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public function desa(array $filters = [])

return Cache::remember($cacheKey, $this->cacheTtl, function () use ($filters) {
$data = $this->apiRequest('/api/v1/config/desa', $filters);
if (! $data) {
if (!$data) {
return collect([]);
}

return collect($data)->map(fn ($item) => (object) $item['attributes']);
return collect($data)->map(fn($item) => (object) $item['attributes']);
});
}

public function desaConfig(array $filters = [])
{
// Panggil API dan ambil data
$data = $this->apiRequest('/api/v1/config/desa', $filters);
if (! $data) {
if (!$data) {
return collect([]);
}

Expand All @@ -44,25 +44,30 @@ public function kecamatan(array $filters = [])

return Cache::remember($cacheKey, $this->cacheTtl, function () use ($filters) {
$data = $this->apiRequest('/api/v1/config/kecamatan', $filters);
if (! $data) {
if (!$data) {
return collect([]);
}

return collect($data)->map(fn ($item) => (object) $item['attributes']);
return collect($data)->map(fn($item) => (object) $item['attributes']);
});
}

public function kabupaten(array $filters = [])
{
$cacheKey = $this->buildCacheKey('config_kabupaten', $filters);
if (empty($filters)) {
$identitas = \App\Models\Identitas::first();
$kode_kabupaten = str_replace('.', '', $identitas->kode_kabupaten);
$filters['filter[kode_kabupaten]'] = $kode_kabupaten;
}

$cacheKey = $this->buildCacheKey('config_kabupaten', $filters);
return Cache::remember($cacheKey, $this->cacheTtl, function () use ($filters) {
$data = $this->apiRequest('/api/v1/config/kabupaten', $filters);
if (! $data) {
if (!$data) {
return collect([]);
}

return collect($data)->map(fn ($item) => (object) $item['attributes']);
return collect($data)->map(fn($item) => (object) $item['attributes']);
});
}

Expand Down
1 change: 1 addition & 0 deletions catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Di rilis ini, versi 2604.0.0 berisi penambahan dan perbaikan yang diminta penggu

1. [#954](https://github.com/OpenSID/OpenKab/issues/954) Perbaikan list menu tidak tampil.
2. [#369](https://github.com/OpenSID/API-Database-Gabungan/issues/369) Perbaikan cache artikel tidak dihapus setelah operasi hapus.
3. [#1015](https://github.com/OpenSID/OpenKab/issues/1015) Batasi opsi kabupaten berdasarkan pengaturan yang ada di API satu data.

#### Perubahan Teknis

Expand Down
23 changes: 21 additions & 2 deletions resources/views/components/wilayah_filter_js.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
@push('js')
<script nonce="{{ csp_nonce() }}">
document.addEventListener("DOMContentLoaded", function(event) {
Comment thread
habibie11 marked this conversation as resolved.
const AJAX_PARAMS_CONFIG = {
metaTagName: 'identitas-openkab',
paramNames: ['kode_kabupaten', 'filter[kode_kabupaten]']
};
const identitasOpenkab = $(`meta[name="${AJAX_PARAMS_CONFIG.metaTagName}"]`).attr('content') || '';
let isAutoLoad = false;

let urlKabupaten =
"{{ config('app.databaseGabunganUrl') . '/api/v1/statistik-web/get-list-kabupaten' }}";
"{{ config('app.databaseGabunganUrl') . '/api/v1/statistik-web/get-list-kabupaten' }}?" +
AJAX_PARAMS_CONFIG.paramNames.map(param => `${param}=${identitasOpenkab}`).join('&');
let urlKecamatan =
"{{ config('app.databaseGabunganUrl') . '/api/v1/statistik-web/get-list-kecamatan' }}";
let urlDesa =
Comment thread
habibie11 marked this conversation as resolved.
Expand All @@ -12,16 +20,23 @@
var optionEmpty = new Option("", "");
$("#filter_kabupaten").append(optionEmpty);

const queryKodeKabupaten = new URLSearchParams(window.location.search).get('filter[kode_kabupaten]');
const filterValue = queryKodeKabupaten || identitasOpenkab;

for (var i = 0; i < data.length; i++) {
var newOption = new Option(data[i].nama_kabupaten, data[i]
.kode_kabupaten, false, false);
$("#filter_kabupaten").append(newOption);

if (data[i].kode_kabupaten === filterValue) {
isAutoLoad = true;
$("#filter_kabupaten").val(filterValue).trigger('change');
}
}
}, 'json')

$('#filter_kabupaten').select2({
placeholder: "Pilih {{ config('app.sebutanKab') }}",
allowClear: true,
height: '100%',
width: '100%',
})
Expand Down Expand Up @@ -60,6 +75,10 @@
$("#filter_kecamatan").append(newOption);
}
$('#filter_kecamatan').prop('disabled', false);
if (isAutoLoad) {
$('#bt_filter').trigger('click');
isAutoLoad = false;
}
})
}
})
Expand Down
1 change: 1 addition & 0 deletions resources/views/dasbor/peta.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
const desa = $("#filter_desa").val()
var coordUrl =
"{{ config('app.databaseGabunganUrl') . '/api/v1/statistik-web/get-list-coordinate' }}";

if (kecamatan != null || desa != null) {
coordUrl = coordUrl += "?filter[kabupaten]=" + (kabupaten == null ? "" : kabupaten) +
"&filter[kecamatan]=" + (kecamatan == null ? "" : kecamatan) + "&filter[desa]=" + (
Expand Down
2 changes: 1 addition & 1 deletion resources/views/dasbor/summary.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let url = "{{ config('app.databaseGabunganUrl') . '/api/v1/data-website' }}";
if (kabupaten || kecamatan || desa) {
url +=
`?filter[kode_kabupaten]=${kabupaten || ''}&filter[kode_kecamatan]=${kecamatan || ''}&filter[kode_desa]=${desa || ''}`;
`?filter[kode_kabupaten]=${kabupaten || ''}&kode_kabupaten=${kabupaten || ''}&filter[kode_kecamatan]=${kecamatan || ''}&filter[kode_desa]=${desa || ''}`;
}
$.get(url, {}, function(result) {
let category = result.data.categoriesItems;
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@extends('adminlte::page')

<meta name="identitas-openkab" content="{{ str_replace('.','',$identitasAplikasi['kode_kabupaten'] ?? '') }}">
@section('footer')
<strong>Hak cipta © <?= date('Y') ?> <a href="https://opendesa.id">OpenDesa</a>.</strong>
Seluruh hak cipta dilindungi.
Expand Down
6 changes: 6 additions & 0 deletions resources/views/penduduk/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ className: 'text-nowrap',
penduduk.draw();
});

$('#filter_kabupaten, #filter_kecamatan, #filter_desa').on('change', function() {
penduduk.draw();
});

$(document).on('click', '#reset', function(e) {
e.preventDefault();
$('#sex').val('').change();
Expand Down Expand Up @@ -382,6 +386,8 @@ className: 'text-nowrap',
for (let i in filterDefault) {
$(`#${i}`).val(filterDefault[i]).trigger('change');
}

penduduk.draw();
});

function getDataset(data, chart) {
Expand Down
51 changes: 51 additions & 0 deletions tests/Feature/WilayahFilterParameterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Tests\Feature;

use Tests\BaseTestCase;

class WilayahFilterParameterTest extends BaseTestCase
{
/** @test */
public function test_meta_tag_identitas_openkab_exists()
{
$response = $this->get(route('dasbor'));

$response->assertStatus(200);
$response->assertSee('name="identitas-openkab"', false);
}

/** @test */
public function test_wilayah_filter_js_contains_kode_kabupaten_param()
{
$response = $this->get(route('dasbor'));

$response->assertStatus(200);
$response->assertSee('kode_kabupaten', false);
}

/** @test */
public function test_wilayah_filter_js_contains_filter_kode_kabupaten_param()
{
$response = $this->get(route('dasbor'));

$response->assertStatus(200);
$response->assertSee('filter[kode_kabupaten]', false);
}

/** @test */
public function test_summary_api_url_contains_kode_kabupaten_param()
{
$response = $this->get(route('dasbor') . '?page=summary');

$response->assertStatus(200);
}

/** @test */
public function test_peta_api_url_contains_kode_kabupaten_param()
{
$response = $this->get(route('dasbor') . '?page=peta');

$response->assertStatus(200);
}
}
Loading