Skip to content

Commit

Permalink
tambahkan filter dan data summary
Browse files Browse the repository at this point in the history
  • Loading branch information
pandigresik committed Jun 12, 2024
1 parent 5c550c4 commit e897c2a
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 42 deletions.
69 changes: 67 additions & 2 deletions app/Http/Controllers/WebsiteDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\Desa;
use Carbon\Carbon;
use Illuminate\Http\Request;

class WebsiteDashboardController extends Controller
Expand All @@ -27,13 +28,77 @@ public function index(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');
$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');

if($period){
$tanggalAkhir = explode(' - ', $period)[1];
$summary->where('created_at', '<=', $tanggalAkhir);
$summarySebelumnya->where('created_at', '<=', Carbon::parse($tanggalAkhir)->subMonth()->format('Y-m-d'));
$desaAktif = Desa::aktif($tanggalAkhir);
$desaAktifOnline = Desa::aktifOnline($tanggalAkhir);
}
if($provinsi){
$summary->where('kode_provinsi', $provinsi);
$summarySebelumnya->where('kode_provinsi', $provinsi);
$desaAktif->where('kode_provinsi', $provinsi);
$desaAktifOnline->where('kode_provinsi', $provinsi);
}
if($kabupaten){
$summary->where('kode_kabupaten', $kabupaten);
$summarySebelumnya->where('kode_kabupaten', $kabupaten);
$desaAktif->where('kode_kabupaten', $kabupaten);
$desaAktifOnline->where('kode_kabupaten', $kabupaten);
}
if($kecamatan){
$summary->where('kode_kecamatan', $kecamatan);
$summarySebelumnya->where('kode_kecamatan', $kecamatan);
$desaAktif->where('kode_kecamatan', $kecamatan);
$desaAktifOnline->where('kode_kecamatan', $kecamatan);
}
$summareResult = $summary->first();
$summarySebelumnyaResult = $summarySebelumnya->first();
return response()->json([
'total' => [
'provinsi' => ['total' => $summareResult->provinsi,'pertumbuhan' => $summareResult->provinsi - $summarySebelumnyaResult->provinsi],
'kabupaten' => ['total' => $summareResult->kabupaten,'pertumbuhan' => $summareResult->kabupaten - $summarySebelumnyaResult->kabupaten],
'kecamatan' => ['total' => $summareResult->kecamatan,'pertumbuhan' => $summareResult->kecamatan - $summarySebelumnyaResult->kecamatan],
'desa' => ['total' => $summareResult->desa,'pertumbuhan' => $summareResult->desa - $summarySebelumnyaResult->desa],
'desa_aktif' => ['total' => $desaAktif->count()],
'desa_aktif_online' => ['total' => $desaAktifOnline->count()],
],
'detail' => [
'openkab' => [],
'opendk' => [],
'opensid' => [],
'layanan_desa' => [],
'kelola_desa' => [],
]
]
);

}
public function chartUsage(Request $request){
$period = $request->get('period');
$provinsi = $request->get('provinsi');
$kabupaten = $request->get('kabupaten');
$kecamatan = $request->get('kecamatan');
$period = explode(' - ','2024-06-10 - 2024-06-30');

$result = [
'labels' => ['1','2'],
'datasets' => [['label' => 'fda', 'data' => [9,14]],['label' => 'f', 'data' => [9,14]]],
'labels' => [1,2,3,4,5],
'datasets' => [
['label' => 'OpenKab', 'data' => [9,14,2,6]],
['label' => 'OpenDK', 'data' => [19,24]],
['label' => 'OpenSID', 'data' => [9,4]],
['label' => 'LayananDesa', 'data' => [9,1,4]],
['label' => 'KelolaDesa', 'data' => [19,4, 5]],
],
];

return response()->json($result);
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Desa.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -364,4 +365,20 @@ public function scopeWilayahKhusus($query)
$r->where('kode_provinsi', $provinsi);
});
}

public function scopeOnline($query)
{
return $query->where('versi_hosting', '!=', '');
}

public function scopeAktif($query, $batasTgl)
{
$maksimalTanggal = Carbon::parse($batasTgl)->subDays(7)->format('Y-m-d');
return $query->whereRaw(DB::raw("greatest(coalesce(tgl_akses_lokal, 0), coalesce(tgl_akses_hosting, 0)) >= '{$maksimalTanggal}'"));
}

public function scopeAktifOnline($query, $batasTgl)
{
return $query->online()->aktif($batasTgl);
}
}
4 changes: 2 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function boot()

protected function bootLogQuery()
{
if ($this->app->environment('local')) {
//if ($this->app->environment('local')) {
Event::listen(QueryExecuted::class, function ($query) {
$bindings = collect($query->bindings)->map(function ($param) {
if (is_numeric($param)) {
Expand All @@ -43,6 +43,6 @@ protected function bootLogQuery()

$this->app->log->debug(Str::replaceArray('?', $bindings->toArray(), $query->sql));
});
}
//}
}
}
59 changes: 58 additions & 1 deletion resources/views/website/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,63 @@ class="btn btn-sm btn-block btn-primary">
$('.datepicker').each(function () {
const _options = $(this).data('option')
$(this).daterangepicker(_options)
})
})
function updateData(){
const params = {period : $('input[name=periods]').val(), provinsi : $('select[name=provinsi]').val(), kabupaten : $('select[name=kabupaten]').val(), kecamatan : $('select[name=kecamatan]').val()}
$.ajax({
url: 'api/web/chart-usage',
data: params,
type: "GET",
success: function(data) {
myChart.data = data;
myChart.update();
}
}, 'json')
$.ajax({
url: 'api/web/summary',
data: params,
type: "GET",
success: function(data) {
const total = data.total
const detail = data.detail
$('#box-provinsi>.total').text(total.provinsi.total)
$('#box-provinsi span.pertumbuhan').html(`<a href="#" class="${total.provinsi.pertumbuhan < 0 ? 'text-red' : 'text-green'}"><i
class="fa ${total.provinsi.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"></i>
${total.provinsi.pertumbuhan}</span></a>`)
$('#box-kabupaten>.total').text(total.kabupaten.total)
$('#box-kabupaten span.pertumbuhan').html(`<a href="#" class="${total.kabupaten.pertumbuhan < 0 ? 'text-red' : 'text-green'}"><i
class="fa ${total.kabupaten.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"></i>
${total.kabupaten.pertumbuhan}</span></a>`)
$('#box-kecamatan>.total').text(total.kecamatan.total)
$('#box-kecamatan span.pertumbuhan').html(`<a href="#" class="${total.kecamatan.pertumbuhan < 0 ? 'text-red' : 'text-green'}"><i
class="fa ${total.kecamatan.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"></i>
${total.kecamatan.pertumbuhan}</span></a>`)
$('#box-desa>.total').text(total.desa.total)
$('#box-desa span.pertumbuhan').html(`<a href="#" class="${total.desa.pertumbuhan < 0 ? 'text-red' : 'text-green'}"><i
class="fa ${total.desa.pertumbuhan < 0 ? 'fa-arrow-down' : 'fa-arrow-up'}"></i>
${total.desa.pertumbuhan}</span></a>`)
$('#desa_aktif>.total').text(total.desa_aktif.total)
$('#desa_aktif_online>.total').text(total.desa_aktif_online.total)
}
}, 'json')
}
$(document).ready(function() {
$('#filter').click(function(){
updateData()
})
$('input[name=periods]').change(function(){
updateData()
})
$('#reset').click(function(){
$('#collapse-filter select').val('')
})
updateData()
})
</script>
@endpush
24 changes: 6 additions & 18 deletions resources/views/website/partial/chart.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@
</div>
@push('js')
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
$(document).ready(function() {
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
data: {}
});
$.ajax({
url: 'api/web/chart-usage',
data: {period : $('input[name=periods]').val()},
type: "GET",
success: function(data) {
myChart.data = data;
myChart.update();
}
}, 'json')
})
<script>
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
data: {}
});
</script>
@endpush
38 changes: 19 additions & 19 deletions resources/views/website/partial/summary.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
<div class="col-md-8 text-center bg-white">
<div class="row">
<div class="col-md">
<div class="">
<div class="display-4 text-bold">0</div>
<div style="margin-top:-10px">Provinsi <span><a href="#" class="text-green"><i
<div id="box-provinsi">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Provinsi <span class="pertumbuhan"><a href="#" class="text-green"><i
class="fa fa-arrow-up"></i>
2</span></a></div>
0</span></a></div>
</div>
</div>
<div class="col-md">
<div class="">
<div class="display-4 text-bold">0</div>
<div style="margin-top:-10px">Kabupaten <span><a href="#" class="text-red"><i
<div id="box-kabupaten">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Kabupaten <span class="pertumbuhan"><a href="#" class="text-red"><i
class="fa fa-arrow-down"></i>
2</span></a></div>
0</span></a></div>
</div>
</div>
<div class="col-md">
<div class="">
<div class="display-4 text-bold">0</div>
<div style="margin-top:-10px">Kecamatan <span><a href="#"><i class="fa fa-arrow-up"></i>
2</span></a></div>
<div id="box-kecamatan">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Kecamatan <span class="pertumbuhan"><a href="#"><i class="fa fa-arrow-up"></i>
0</span></a></div>
</div>
</div>
<div class="col-md">
<div class="">
<div class="display-4 text-bold">0</div>
<div style="margin-top:-10px">Desa <span><a href="#"><i class="fa fa-arrow-up"></i>
<div id="box-desa">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Desa <span class="pertumbuhan"><a href="#"><i class="fa fa-arrow-up"></i>
2</span></a></div>
</div>
</div>
Expand All @@ -36,14 +36,14 @@ class="fa fa-arrow-down"></i>
<div class="col-md-4 text-center">
<div class="row">
<div class="col-md">
<div class="bg-green">
<div class="display-4 text-bold">0</div>
<div class="bg-green" id="desa_aktif">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Desa Aktif</div>
</div>
</div>
<div class="col-md">
<div class="bg-blue">
<div class="display-4 text-bold">0</div>
<div class="bg-blue" id="desa_aktif_online">
<div class="display-4 text-bold total">0</div>
<div style="margin-top:-10px">Desa Aktif Online</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
Route::prefix('web')
->group(function () {
Route::get('chart-usage', [WebsiteDashboardController::class, 'chartUsage']);
Route::get('summary', [WebsiteDashboardController::class, 'summary']);
});

0 comments on commit e897c2a

Please sign in to comment.