Skip to content

Commit

Permalink
Merge pull request #95 from training-solonet/ipan
Browse files Browse the repository at this point in the history
Ipan
  • Loading branch information
Diandaru authored Dec 27, 2024
2 parents 8556d19 + d7b98ce commit a5e8205
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 11 deletions.
34 changes: 33 additions & 1 deletion app/Http/Controllers/DashboardRplController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ public function index(Request $request)
],
];


$siswaDataLearning = Siswa::where('user_id', $userId)
->where('kategori', 'Learning')
->get()
->groupBy('materi_id')
->map(function ($items) use ($totalWaktuLearning) {
$totalTime = $items->sum(function ($item) {
if ($item->waktu_mulai && $item->waktu_selesai) {
$waktuMulai = Carbon::parse($item->waktu_mulai);
$waktuSelesai = Carbon::parse($item->waktu_selesai);
return $waktuSelesai->greaterThan($waktuMulai) ? $waktuSelesai->diffInSeconds($waktuMulai) : 0;
}
return 0;
});

$percentage = $totalWaktuLearning ? ($totalTime / $totalWaktuLearning) * 100 : 0;
return ['totalTime' => $totalTime, 'percentage' => $percentage];
});

$learningChartData = [
'labels' => $materiNamesLearning->values(),
'datasets' => [
[
'data' => $siswaDataLearning->pluck('percentage')->values(),
'backgroundColor' => ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF'],
]
]
];


$activityData = $jumlahAktivitasLearning;

return view('dashboardrpl', compact(
Expand All @@ -109,11 +139,13 @@ public function index(Request $request)
'totalWaktu',
'persentaseLearning',
'persentaseProject',
'chartData',
'learningChartData',
'activityData',
'aktivitasNames',
'siswaData',
'chartData',
'activityData'
));

}
}
64 changes: 60 additions & 4 deletions resources/views/dashboardrpl.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class="btn btn-sm btn-outline-dark d-flex align-items-center">
<div class="col-md-6">
<h6 class="text-center mb-3">Persentase Waktu Per Learning</h6>
<div class="chart">
<canvas id="chart-pie-Learning" class="chart-canvas" height="240"></canvas>
<canvas id="chart-pie" class="chart-canvas" height="240"></canvas>
</div>
<div class="text-center mt-3">
<button id="toggle-legend-dikantor" class="btn btn-sm btn-outline-info">
<button id="toggle-legend" class="btn btn-sm btn-outline-info">
<i class="fas fa-info-circle me-1"></i> Detail
</button>
</div>
Expand All @@ -128,15 +128,14 @@ class="btn btn-sm btn-outline-dark d-flex align-items-center">
<div class="col-md-6">
<h6 class="text-center mb-3">Persentase Waktu Per Project</h6>
<div class="chart">
<canvas id="chart-pie" class="chart-canvas" height="240"></canvas>
<canvas id="chart-pie-dikantor" class="chart-canvas" height="240"></canvas>
</div>
<div class="text-center mt-3">
<button id="toggle-legend-dikantor" class="btn btn-sm btn-outline-info">
<i class="fas fa-info-circle me-1"></i> Detail
</button>
</div>
</div>

</div>
</div>
</div>
Expand All @@ -146,6 +145,35 @@ class="btn btn-sm btn-outline-dark d-flex align-items-center">
</main>

<script>
document.addEventListener('DOMContentLoaded', function() {
const pieChartData = @json($chartData);
// Chart untuk Learning vs Project
const ctxPie = document.getElementById('chart-pie').getContext('2d');
const pieChart = new Chart(ctxPie, {
type: 'pie',
data: pieChartData,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(context) {
const label = context.label || '';
const value = context.raw || 0;
return `${label}: ${value.toFixed(2)}%`;
}
}
}
}
}
});
});
document.addEventListener('DOMContentLoaded', function() {
// Ambil elemen tombol dan konten
const showDiagramButton = document.getElementById('show-diagram');
Expand All @@ -171,5 +199,33 @@ function toggleContent(showDiagram) {
// Inisialisasi: tampilkan detail secara default
toggleContent(false);
});
document.addEventListener('DOMContentLoaded', function() {
const learningChartData = @json($learningChartData);
// Chart untuk Learning Detail
const ctxLearning = document.getElementById('chart-pie-dikantor').getContext('2d');
const learningPieChart = new Chart(ctxLearning, {
type: 'pie',
data: learningChartData,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(context) {
const label = context.label || '';
const value = context.raw || 0;
return `${label}: ${value.toFixed(2)}%`;
}
}
}
}
}
});
});
</script>
</x-app-layout>
6 changes: 0 additions & 6 deletions resources/views/monitoring_siswa/siswarpl.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,4 @@ function toggleMateriDropdown(selectId, materi2Id) {
}
}
</script>






</x-app-layout>

0 comments on commit a5e8205

Please sign in to comment.