diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 82a37e40..8a54bada 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -10,7 +10,7 @@ class Handler extends ExceptionHandler /** * A list of exception types with their corresponding custom log levels. * - * @var array, \Psr\Log\LogLevel::*> + * @var array, \Psr\Log\LogLevel::*> */ protected $levels = [ // @@ -19,7 +19,7 @@ class Handler extends ExceptionHandler /** * A list of the exception types that are not reported. * - * @var array> + * @var array> */ protected $dontReport = [ // diff --git a/app/Http/Controllers/KelolaDesaDashboardController.php b/app/Http/Controllers/KelolaDesaDashboardController.php index bb874ede..60b39f8e 100644 --- a/app/Http/Controllers/KelolaDesaDashboardController.php +++ b/app/Http/Controllers/KelolaDesaDashboardController.php @@ -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); @@ -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); @@ -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, @@ -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', diff --git a/app/Http/Controllers/OpenKabDashboardController.php b/app/Http/Controllers/OpenKabDashboardController.php index f5aab0b3..156c3102 100644 --- a/app/Http/Controllers/OpenKabDashboardController.php +++ b/app/Http/Controllers/OpenKabDashboardController.php @@ -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() @@ -41,7 +41,7 @@ public function peta(Request $request) ], ], 'properties' => $this->properties($desa), - 'id' => $desa?->id, + 'id' => $desa?->id, ]; }); @@ -69,4 +69,4 @@ private function properties($desa) ', ]; } -} \ No newline at end of file +} diff --git a/app/Http/Middleware/PantauMiddleware.php b/app/Http/Middleware/PantauMiddleware.php index 480e2128..eb2079f7 100644 --- a/app/Http/Middleware/PantauMiddleware.php +++ b/app/Http/Middleware/PantauMiddleware.php @@ -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) diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index a37e9144..7e18ff2f 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -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 */ diff --git a/app/Http/Middleware/WebDashboard.php b/app/Http/Middleware/WebDashboard.php index eaaf9706..e7f3364b 100644 --- a/app/Http/Middleware/WebDashboard.php +++ b/app/Http/Middleware/WebDashboard.php @@ -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) diff --git a/app/Http/Middleware/WilayahMiddleware.php b/app/Http/Middleware/WilayahMiddleware.php index 5dce932b..34b42baf 100644 --- a/app/Http/Middleware/WilayahMiddleware.php +++ b/app/Http/Middleware/WilayahMiddleware.php @@ -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) diff --git a/app/Models/TrackKeloladesa.php b/app/Models/TrackKeloladesa.php index a37228fc..a9427f9f 100644 --- a/app/Models/TrackKeloladesa.php +++ b/app/Models/TrackKeloladesa.php @@ -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'].'\''); diff --git a/resources/views/website/keloladesa/index.blade.php b/resources/views/website/keloladesa/index.blade.php index 83794389..3f846a43 100644 --- a/resources/views/website/keloladesa/index.blade.php +++ b/resources/views/website/keloladesa/index.blade.php @@ -169,6 +169,10 @@ class="fa ${total.desa.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"> } $(document).ready(function () { + + // set default kosongkan datepicker + $('input[name=periods]').val(''); + $('#filter').click(function () { updateData() }) diff --git a/resources/views/website/keloladesa/peta.blade.php b/resources/views/website/keloladesa/peta.blade.php index 629f7689..e19c7668 100644 --- a/resources/views/website/keloladesa/peta.blade.php +++ b/resources/views/website/keloladesa/peta.blade.php @@ -80,6 +80,7 @@ function onEachFeature(feature, layer) { layer.bindPopup(feature.properties.popupContent); } + loadData(); @@ -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'); @@ -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", @@ -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 @@ -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; + } + }); @endsection \ No newline at end of file diff --git a/resources/views/website/keloladesa/tabel.blade.php b/resources/views/website/keloladesa/tabel.blade.php index 438800e8..90195f3e 100644 --- a/resources/views/website/keloladesa/tabel.blade.php +++ b/resources/views/website/keloladesa/tabel.blade.php @@ -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, @@ -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' }, @@ -54,7 +63,7 @@ }, { data: 'desa.nama_provinsi' - }, + }, { data: 'versi', searchable: false @@ -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(); + }); + + + }) + @endpush \ No newline at end of file