Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXED: Sesuaikan filter tanggal pada halaman KelolaDesa #472

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Handler extends ExceptionHandler
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
* @var array<class-string<Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
Expand All @@ -19,7 +19,7 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
Expand Down
68 changes: 56 additions & 12 deletions app/Http/Controllers/KelolaDesaDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function versi_detail(Request $request)
public function install_baru(Request $request)
{
if ($request->ajax()) {
return DataTables::of(TrackKeloladesa::with('desa')->whereDate('created_at', '>=', Carbon::now()->subDays(7)))
return DataTables::of(TrackKeloladesa::with('desa')->filter($request))
->editColumn('updated_at', static fn ($q) => $q->updated_at->translatedFormat('j F Y H:i'))
->addIndexColumn()
->make(true);
Expand All @@ -86,20 +86,50 @@ public function install_baru(Request $request)

public function summary(Request $request)
{
$period = $request->get('period') ?? Carbon::now()->format('Y-m-d').' - '.Carbon::now()->format('Y-m-d');
$provinsi = $request->get('provinsi');
$kabupaten = $request->get('kabupaten');
$kecamatan = $request->get('kecamatan');
$summary = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi')->whereIn('kode_desa', function ($q) {
return $q->selectRaw('distinct kode_desa')->from('track_keloladesa');
});
$summarySebelumnya = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi')->whereIn('kode_desa', function ($q) {
return $q->selectRaw('distinct kode_desa')->from('track_keloladesa');

$summary = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi')
->whereIn('kode_desa', function ($q) use ($request) {
$q->selectRaw('distinct kode_desa')
->from('track_keloladesa');

// Menambahkan filter created_at pada subquery
if ($request->period) {
$dates = explode(' - ', $request->period);
if (count($dates) === 2) {
// Jika periode mencakup rentang tanggal
if ($dates[0] !== $dates[1]) {
$q->whereBetween('created_at', [$dates[0], $dates[1]]);
} else {
// Jika hanya satu tanggal
$q->whereDate('created_at', '=', $dates[0]);
}
}
}
});

$tanggalAkhir = explode(' - ', $period)[1];
$summary->where('created_at', '<=', $tanggalAkhir);
$summarySebelumnya->where('created_at', '<=', Carbon::parse($tanggalAkhir)->subMonth()->format('Y-m-d'));
$summarySebelumnya = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi')->whereIn('kode_desa', function ($q) use ($request) {
$q->selectRaw('distinct kode_desa')->from('track_keloladesa');

if ($request->period) {
$dates = explode(' - ', $request->period);
if (count($dates) === 2) {
// Kurangi satu bulan dari setiap tanggal
$startDate = Carbon::parse($dates[0])->subMonth()->format('Y-m-d');
$endDate = Carbon::parse($dates[1])->subMonth()->format('Y-m-d');

// Jika periode mencakup rentang tanggal
if ($dates[0] !== $dates[1]) {
$q->whereBetween('created_at', [$startDate, $endDate]);
} else {
// Jika hanya satu tanggal
$q->whereDate('created_at', '=', $startDate);
}
}
}
});

if ($provinsi) {
$summary->where('kode_provinsi', $provinsi);
Expand Down Expand Up @@ -135,6 +165,7 @@ public function peta(Request $request)
'kode_kabupaten' => $request->kode_kabupaten,
'kode_kecamatan' => $request->kode_kecamatan,
'status' => null,
'period' => $request->period,
'akses' => null,
'versi_lokal' => null,
'versi_hosting' => null,
Expand All @@ -151,8 +182,21 @@ public function peta(Request $request)
->where('lat', '!=', config('tracksid.desa_contoh.lat'))
->where('lng', '!=', config('tracksid.desa_contoh.lng'));
})
->whereIn('kode_desa', function ($q) {
return $q->selectRaw('distinct kode_desa')->from('track_keloladesa');
->whereIn('kode_desa', function ($q) use ($request) {
$q->selectRaw('distinct kode_desa')->from('track_keloladesa');

if ($request->period) {
$dates = explode(' - ', $request->period);
if (count($dates) === 2) {
// Jika periode mencakup rentang tanggal
if ($dates[0] !== $dates[1]) {
$q->whereBetween('created_at', [$dates[0], $dates[1]]);
} else {
// Jika hanya satu tanggal
$q->whereDate('created_at', '=', $dates[0]);
}
}
}
})->orderBy('kode_desa', 'ASC')->get()->map(function ($desa) {
return [
'type' => 'Feature',
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/OpenKabDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public function peta(Request $request)
->whereRaw("CONCAT('',lat * 1) = lat") // tdk ikut sertakan data bukan bilangan
->whereRaw("CONCAT('',lng * 1) = lng") // tdk ikut sertakan data bukan bilangan
->whereRaw('lat BETWEEN -10 AND 6')
->whereRaw('lng BETWEEN 95 AND 142')
->whereRaw('lng BETWEEN 95 AND 142')
->where(function ($query) {
$query
->where('lat', '!=', config('tracksid.desa_contoh.lat'))
->where('lng', '!=', config('tracksid.desa_contoh.lng'));
})
})
->orderBy('kode_desa', 'ASC');
}])
->get()
Expand All @@ -41,7 +41,7 @@ public function peta(Request $request)
],
],
'properties' => $this->properties($desa),
'id' => $desa?->id,
'id' => $desa?->id,
];
});

Expand Down Expand Up @@ -69,4 +69,4 @@ private function properties($desa)
</b>',
];
}
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/PantauMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PantauMiddleware
* Handle an incoming request.
*
* @param Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param Closure(Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RedirectIfAuthenticated
* Handle an incoming request.
*
* @param Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param Closure(Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/WebDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WebDashboard
* Handle an incoming request.
*
* @param Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param Closure(Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/WilayahMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WilayahMiddleware
* Handle an incoming request.
*
* @param Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param Closure(Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
Expand Down
17 changes: 17 additions & 0 deletions app/Models/TrackKeloladesa.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ public function desa()

protected function scopeFilter($query, $request)
{
if (isset($request['period'])) {
$query->when($request->period ?? false, function ($subQuery) use ($request) {
$dates = explode(' - ', $request->period);
if (count($dates) === 2) {
// Validasi jika tanggal awal dan akhir berbeda
if ($dates[0] !== $dates[1]) {
$subQuery->whereBetween('created_at', [$dates[0], $dates[1]]);
} else {
$subQuery->whereDate('created_at', '=', $dates[0]);
}
}
}, function ($subQuery) {
// Jika $request->period kosong, gunakan filter default
$subQuery->whereDate('created_at', '>=', Carbon::now()->subDays(7));
});
}

if (isset($request['kode_provinsi'])) {
$query->when($request['kode_provinsi'], function ($q) use ($request) {
$q->whereRaw('left(kode_desa, 2) = \''.$request['kode_provinsi'].'\'');
Expand Down
4 changes: 4 additions & 0 deletions resources/views/website/keloladesa/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ class="fa ${total.desa.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"></i>
}

$(document).ready(function () {

// set default kosongkan datepicker
$('input[name=periods]').val('');

$('#filter').click(function () {
updateData()
})
Expand Down
38 changes: 30 additions & 8 deletions resources/views/website/keloladesa/peta.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
function onEachFeature(feature, layer) {
layer.bindPopup(feature.properties.popupContent);
}


loadData();

Expand All @@ -89,6 +90,11 @@ function onEachFeature(feature, layer) {
loadData($('#provinsi').val(), $('#kabupaten').val(), $('#kecamatan').val());
});

// Deteksi perubahan nilai pada input periods
$('input[name=periods]').on('change', function () {
loadData(); // Panggil loadData setiap kali period berubah
});

$('#reset').click(function() {
$('#provinsi').val('').trigger('change');
$('#kabupaten').val('').trigger('change');
Expand All @@ -100,7 +106,6 @@ function onEachFeature(feature, layer) {
});

function loadData(kode_provinsi = null, kode_kabupaten = null, kode_kecamatan = null, status = null) {

$.ajax({
url: "{{ url('web/keloladesa/peta') }}",
contentType: "application/json; charset=utf-8",
Expand All @@ -111,19 +116,31 @@ function loadData(kode_provinsi = null, kode_kabupaten = null, kode_kecamatan =
kode_kabupaten: kode_kabupaten,
kode_kecamatan: kode_kecamatan,
status: status,
period: $('input[name=periods]').val(),
},
responseType: "json",
success: function(response) {
success: function (response) {

// Hapus marker cluster lama jika ada
if (markersBar) {
map.removeLayer(markersBar);
}

// Buat Marker Cluster Group
// Buat Marker Cluster Group baru
markersBar = L.markerClusterGroup();

// Simpan Data geoJSON
barLayer = new L.geoJSON(response, {
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {
icon: baseballIcon
});
pointToLayer: function (feature, latlng) {
// Validasi koordinat sebelum membuat marker
if (isValidCoordinate(latlng.lat) && isValidCoordinate(latlng.lng)) {
return L.marker(latlng, {
icon: baseballIcon
});
} else {
console.warn('Invalid coordinate skipped:', latlng);
return null; // Jangan buat marker jika koordinat tidak valid
}
},

onEachFeature: onEachFeature
Expand All @@ -133,11 +150,16 @@ function loadData(kode_provinsi = null, kode_kabupaten = null, kode_kecamatan =
markersBar.addLayer(barLayer);
map.addLayer(markersBar);
},
error: function() {
error: function () {
alert('Gagal mengambil data');
},
});
}

function isValidCoordinate(value) {
return !isNaN(value) && value !== null && value !== '' && parseFloat(value) <= 180 && parseFloat(value) >= -180;
}

});
</script>
@endsection
29 changes: 25 additions & 4 deletions resources/views/website/keloladesa/tabel.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
$.extend($.fn.dataTable.defaults, {
language: { url: "https://cdn.datatables.net/plug-ins/2.1.8/i18n/id.json" }
});


var desaBaru = $('#table-desa-baru').DataTable({
processing: true,
serverSide: true,
Expand All @@ -33,13 +35,20 @@
ajax: {
url: `{{ url('web/keloladesa/install_baru') }}`,
method: 'get',
data: function() {
let period = $('input[name=periods]').val() || '';
return {
period,
};
},
},
columns: [{
columns: [
{
data: 'DT_RowIndex',
name: 'DT_RowIndex',
searchable: false,
orderable: false
},
},
{
data: 'id_device'
},
Expand All @@ -54,7 +63,7 @@
},
{
data: 'desa.nama_provinsi'
},
},
{
data: 'versi',
searchable: false
Expand All @@ -67,6 +76,18 @@
order: [
[1, 'desc']
],
})
});


$(document).ready(function () {

// Deteksi perubahan nilai pada input periods
$('input[name=periods]').on('change', function () {
desaBaru.ajax.reload();
});


})

</script>
@endpush