filter segmen
This commit is contained in:
@@ -66,9 +66,34 @@ class IndeksPetaniController extends Controller
|
|||||||
->when($filters['kabupatenKota_id'], fn($q, $id) => $q->where('master_kecamatan.kabupaten_kota_id', $id))
|
->when($filters['kabupatenKota_id'], fn($q, $id) => $q->where('master_kecamatan.kabupaten_kota_id', $id))
|
||||||
->when($filters['kecamatan_id'], fn($q, $id) => $q->where('master_desa_kelurahan.kecamatan_id', $id))
|
->when($filters['kecamatan_id'], fn($q, $id) => $q->where('master_desa_kelurahan.kecamatan_id', $id))
|
||||||
->when($filters['desaKelurahan_id'], fn($q, $id) => $q->where('petani.desa_kelurahan_id', $id))
|
->when($filters['desaKelurahan_id'], fn($q, $id) => $q->where('petani.desa_kelurahan_id', $id))
|
||||||
->when($filters['komoditas_id'], fn($q, $id) => $q->where('petani.komoditas_id', $id))
|
|
||||||
->whereIn('petani.komoditas_id', $komoditas);
|
->whereIn('petani.komoditas_id', $komoditas);
|
||||||
|
|
||||||
|
if ($filters['segmen']) {
|
||||||
|
$skor->where(function ($q) use ($filters) {
|
||||||
|
match ($filters['segmen']) {
|
||||||
|
'Penggerak' => $q->where('skor_kesiapan_adopsi', '>=', 4),
|
||||||
|
'Perintis' => $q->where(function($q) {
|
||||||
|
$q->where('skor_kesiapan_adopsi', '>=', 3)
|
||||||
|
->where('skor_kesiapan_adopsi', '<', 4);
|
||||||
|
}),
|
||||||
|
'Pemerhati' => $q->where(function($q) {
|
||||||
|
$q->where('skor_kesiapan_adopsi', '>=', 2)
|
||||||
|
->where('skor_kesiapan_adopsi', '<', 3);
|
||||||
|
}),
|
||||||
|
'Pemula' => $q->where(function($q) {
|
||||||
|
$q->where('skor_kesiapan_adopsi', '>=', 1)
|
||||||
|
->where('skor_kesiapan_adopsi', '<', 2);
|
||||||
|
}),
|
||||||
|
'Belum Lengkap' => $q->where(function ($q) {
|
||||||
|
$q->whereNull('skor_kesiapan_adopsi')
|
||||||
|
->orWhere('skor_kesiapan_adopsi', '<', 1);
|
||||||
|
}),
|
||||||
|
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return $skor;
|
return $skor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,28 +621,37 @@ class IndeksPetaniController extends Controller
|
|||||||
->whereIn('komoditas_id', $komoditas->pluck('id'))
|
->whereIn('komoditas_id', $komoditas->pluck('id'))
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$data = $daftarPetani->map(function ($item) use ($segmentStyles) {
|
$data = $daftarPetani
|
||||||
$segmen = $item->skor
|
->filter(function ($item) use ($filters) {
|
||||||
? $item->segmen()
|
if (!$filters['segmen']) {
|
||||||
: null;
|
return true;
|
||||||
$style = $segmentStyles[$segmen]
|
}
|
||||||
?? ['color' => 'secondary'];
|
$segmen = $item->skor ? $item->segmen() : 'Belum Lengkap';
|
||||||
|
return $segmen === $filters['segmen'];
|
||||||
return [
|
})
|
||||||
'id' => $item->id,
|
->map(function ($item) use ($segmentStyles) {
|
||||||
'nama' => $item->nama,
|
$segmen = $item->skor
|
||||||
'desa' => $item->desaKelurahan?->nama,
|
? $item->segmen()
|
||||||
'desa_kelurahan_id' => $item->desa_kelurahan_id,
|
: null;
|
||||||
'komoditas' => $item->komoditas?->nama,
|
$style = $segmentStyles[$segmen]
|
||||||
'luas_lahan' => $item->lahans?->sum('luas_lahan') ?? 0,
|
?? ['color' => 'secondary'];
|
||||||
'skor' => $item->skor
|
|
||||||
? $item->skor->skor_kesiapan_adopsi
|
return [
|
||||||
: null,
|
'id' => $item->id,
|
||||||
'segmen' => $segmen,
|
'nama' => $item->nama,
|
||||||
'color' => $style['color'],
|
'desa' => $item->desaKelurahan?->nama,
|
||||||
'url' => route('dashboard.profil-petani', $item->id),
|
'desa_kelurahan_id' => $item->desa_kelurahan_id,
|
||||||
];
|
'komoditas' => $item->komoditas?->nama,
|
||||||
});
|
'luas_lahan' => $item->lahans?->sum('luas_lahan') ?? 0,
|
||||||
|
'skor' => $item->skor
|
||||||
|
? $item->skor->skor_kesiapan_adopsi
|
||||||
|
: null,
|
||||||
|
'segmen' => $segmen,
|
||||||
|
'color' => $style['color'],
|
||||||
|
'url' => route('dashboard.profil-petani', $item->id),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->values();
|
||||||
|
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,16 @@ $provinsi = $desaKelurahan
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="filter-item">
|
||||||
|
<select id="filter-segmen" class="form-select form-select-sm" name="segmen">
|
||||||
|
<option value="">Semua Segmen</option>
|
||||||
|
@foreach ($segments as $segment)
|
||||||
|
<option value="{{ $segment['name'] }}" {{ old('segmen', $segmen) == $segment['name'] ? 'selected' : '' }}>
|
||||||
|
{{ $segment['name'] }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
@@ -528,7 +537,6 @@ $provinsi = $desaKelurahan
|
|||||||
$('#filter-desa').prop('disabled', false);
|
$('#filter-desa').prop('disabled', false);
|
||||||
|
|
||||||
let defaultDesa = $('#filter-desa').data('default');
|
let defaultDesa = $('#filter-desa').data('default');
|
||||||
console.log('defaultDesa', defaultDesa);
|
|
||||||
if (defaultDesa) {
|
if (defaultDesa) {
|
||||||
console.log('default desa', defaultDesa);
|
console.log('default desa', defaultDesa);
|
||||||
$('#filter-desa').val(defaultDesa).trigger('change');
|
$('#filter-desa').val(defaultDesa).trigger('change');
|
||||||
@@ -567,30 +575,8 @@ $provinsi = $desaKelurahan
|
|||||||
// Reset chart
|
// Reset chart
|
||||||
chartSegmentasiPetani.resetSeries();
|
chartSegmentasiPetani.resetSeries();
|
||||||
chartSegmentasiPetaniByKomoditas.resetSeries();
|
chartSegmentasiPetaniByKomoditas.resetSeries();
|
||||||
|
|
||||||
// Refresh DataTable
|
|
||||||
updatePetaniSubtitle();
|
|
||||||
tablePetani.draw();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function updatePetaniSubtitle() {
|
|
||||||
let subtitle = 'untuk semua komoditas, semua segmen, dan semua desa/kelurahan';
|
|
||||||
|
|
||||||
if (selectedKomoditas) {
|
|
||||||
subtitle = `untuk komoditas ${selectedKomoditas}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedSegmen) {
|
|
||||||
subtitle += ` dengan segmen ${selectedSegmen}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedDesa) {
|
|
||||||
subtitle += ` pada desa/kel. ${selectedDesa}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('.card-subtitle').text(subtitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Chart Dimensi dan Komponen Kesiapan Adopsi
|
// Chart Dimensi dan Komponen Kesiapan Adopsi
|
||||||
let cardColor, labelColor, fontFamily, headingColor, shadeColor, legendColor, borderColor, barBgColor;
|
let cardColor, labelColor, fontFamily, headingColor, shadeColor, legendColor, borderColor, barBgColor;
|
||||||
@@ -663,10 +649,6 @@ $provinsi = $desaKelurahan
|
|||||||
|
|
||||||
// Set filter segmen
|
// Set filter segmen
|
||||||
selectedSegmen = segmen;
|
selectedSegmen = segmen;
|
||||||
|
|
||||||
// Refresh DataTable
|
|
||||||
updatePetaniSubtitle();
|
|
||||||
tablePetani.draw();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -782,9 +764,6 @@ $provinsi = $desaKelurahan
|
|||||||
console.log('Komoditas dipilih:', komoditas);
|
console.log('Komoditas dipilih:', komoditas);
|
||||||
|
|
||||||
selectedKomoditas = komoditas;
|
selectedKomoditas = komoditas;
|
||||||
|
|
||||||
updatePetaniSubtitle();
|
|
||||||
tablePetani.draw();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1238,7 +1217,7 @@ $provinsi = $desaKelurahan
|
|||||||
data = $('#form-filter').serialize();
|
data = $('#form-filter').serialize();
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
dataSrc: function(json) {
|
"dataSrc": function(json) {
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
"dataType": "json"
|
"dataType": "json"
|
||||||
@@ -1304,7 +1283,7 @@ $provinsi = $desaKelurahan
|
|||||||
data = $('#form-filter').serialize();
|
data = $('#form-filter').serialize();
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
dataSrc: function(json) {
|
"dataSrc": function(json) {
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
"dataType": "json"
|
"dataType": "json"
|
||||||
@@ -1376,9 +1355,6 @@ $provinsi = $desaKelurahan
|
|||||||
createdRow: function(row, data) {
|
createdRow: function(row, data) {
|
||||||
$(row)
|
$(row)
|
||||||
.addClass('clickable-row')
|
.addClass('clickable-row')
|
||||||
.attr('data-desa', data.desa_kelurahan_id)
|
|
||||||
.attr('data-komoditas', data.komoditas)
|
|
||||||
.attr('data-segmen', data.segmen ?? '')
|
|
||||||
.attr('data-url', data.url);
|
.attr('data-url', data.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user