diff --git a/app/Http/Controllers/Guru/DashboardController.php b/app/Http/Controllers/Guru/DashboardController.php index 3e42dac..ed7d154 100644 --- a/app/Http/Controllers/Guru/DashboardController.php +++ b/app/Http/Controllers/Guru/DashboardController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Mengajar; use App\Models\Siswa; +use App\Models\Tugas; use Illuminate\Support\Facades\Auth; class DashboardController extends Controller @@ -15,25 +16,47 @@ public function index() try { $totalKelas = Mengajar::where('id_guru', $guru->id_guru) - ->distinct('id_kelas') - ->count('id_kelas'); + ->distinct('id_kelas')->count('id_kelas'); $totalMapel = Mengajar::where('id_guru', $guru->id_guru) - ->distinct('id_mapel') - ->count('id_mapel'); + ->distinct('id_mapel')->count('id_mapel'); - $kelasIds = Mengajar::where('id_guru', $guru->id_guru) - ->pluck('id_kelas') - ->unique(); + $kelasIds = Mengajar::where('id_guru', $guru->id_guru) + ->pluck('id_kelas')->unique(); $totalSiswa = Siswa::whereIn('id_kelas', $kelasIds)->count(); + // Chart: pengumpulan tugas per tugas (6 tugas terbaru) + $idMengajars = Mengajar::where('id_guru', $guru->id_guru)->pluck('id_mengajar'); + + $tugasList = Tugas::with(['mengajar.mapel', 'pengumpulanTugas']) + ->whereIn('id_mengajar', $idMengajars) + ->latest()->take(6)->get(); + + $chartLabels = []; + $chartSudah = []; + $chartBelum = []; + + foreach ($tugasList as $tugas) { + $namaMapel = optional($tugas->mengajar->mapel)->nama_mapel ?? 'Mapel'; + $chartLabels[] = strlen($namaMapel) > 14 ? substr($namaMapel, 0, 14) . '…' : $namaMapel; + $sudah = $tugas->pengumpulanTugas->count(); + $chartSudah[] = $sudah; + $chartBelum[] = max(0, $totalSiswa - $sudah); + } + } catch (\Exception $e) { - $totalKelas = 0; - $totalMapel = 0; - $totalSiswa = 0; + $totalKelas = 0; + $totalMapel = 0; + $totalSiswa = 0; + $chartLabels = []; + $chartSudah = []; + $chartBelum = []; } - return view('guru.dashboard', compact('totalKelas', 'totalMapel', 'totalSiswa')); + return view('guru.dashboard', compact( + 'totalKelas', 'totalMapel', 'totalSiswa', + 'chartLabels', 'chartSudah', 'chartBelum' + )); } } \ No newline at end of file diff --git a/resources/views/admin/challenge/index.blade.php b/resources/views/admin/challenge/index.blade.php index aacacba..603d39e 100644 --- a/resources/views/admin/challenge/index.blade.php +++ b/resources/views/admin/challenge/index.blade.php @@ -956,7 +956,6 @@ function openTambahModal() { data.soal.forEach(s => tambahSoal('editSoalContainer', s)); - // Recalc EXP otomatis setiap kali angka EXP di modal edit berubah const expElEdit = document.getElementById('editExp'); expElEdit.oninput = () => recalcExp('editSoalContainer'); diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index d0c8769..4ba3a2f 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -4,118 +4,64 @@ @push('styles') @@ -134,7 +80,6 @@ @php use Carbon\Carbon; - $greeting = Carbon::now()->hour < 12 ? 'Selamat Pagi' : (Carbon::now()->hour < 17 ? 'Selamat Siang' : 'Selamat Malam'); @endphp
@@ -165,7 +110,7 @@
-{{-- BOTTOM: Chart + Challenge --}} +{{-- BOTTOM --}}
{{-- Bar Chart --}} @@ -183,7 +128,7 @@
Challenge Terbaru
- Lihat Semua → + Lihat Semua →
@forelse($latestChallenges as $ch) @@ -221,16 +166,16 @@ const values = @json($chartData->pluck('siswa_count')); const colors = [ - 'rgba(43,142,243,0.8)', - 'rgba(34,197,94,0.8)', - 'rgba(249,115,22,0.8)', - 'rgba(168,85,247,0.8)', - 'rgba(236,72,153,0.8)', - 'rgba(234,179,8,0.8)', + 'rgba(43,142,243,0.85)', + 'rgba(34,197,94,0.85)', + 'rgba(249,115,22,0.85)', + 'rgba(168,85,247,0.85)', + 'rgba(236,72,153,0.85)', + 'rgba(234,179,8,0.85)', ]; const ctx = document.getElementById('kelasChart').getContext('2d'); -new Chart(ctx, { +const kelasChart = new Chart(ctx, { type: 'bar', data: { labels: labels, @@ -238,7 +183,7 @@ label: 'Jumlah Siswa', data: values, backgroundColor: labels.map((_, i) => colors[i % colors.length]), - borderRadius: 10, + borderRadius: 8, borderSkipped: false, }] }, @@ -248,16 +193,14 @@ plugins: { legend: { display: false }, tooltip: { - callbacks: { - label: ctx => ` ${ctx.parsed.y} siswa` - } + callbacks: { label: ctx => ` ${ctx.parsed.y} siswa` } } }, scales: { y: { beginAtZero: true, grid: { color: '#f1f5f9' }, - ticks: { font: { family: 'Poppins', size: 11 }, color: '#94a3b8' } + ticks: { font: { family: 'Poppins', size: 11 }, color: '#94a3b8', stepSize: 1 } }, x: { grid: { display: false }, @@ -266,5 +209,10 @@ } } }); + +// Fix resize saat sidebar toggle +document.getElementById('sidebarToggleBtn')?.addEventListener('click', () => { + setTimeout(() => kelasChart.resize(), 320); +}); @endpush \ No newline at end of file diff --git a/resources/views/guru/dashboard.blade.php b/resources/views/guru/dashboard.blade.php index 9606266..18728aa 100644 --- a/resources/views/guru/dashboard.blade.php +++ b/resources/views/guru/dashboard.blade.php @@ -5,70 +5,58 @@ @push('styles') @endpush @@ -87,17 +75,13 @@ @php use Carbon\Carbon; use App\Models\Mengajar; - $guru = Auth::guard('guru')->user(); - $greeting = Carbon::now()->hour < 12 ? 'Selamat Pagi' : (Carbon::now()->hour < 17 ? 'Selamat Siang' : 'Selamat Malam'); - - // Ambil mengajar dengan relasi mapel & kelas + $guru = Auth::guard('guru')->user(); $mengajars = Mengajar::with(['mapel', 'kelas']) - ->where('id_guru', $guru->id_guru) - ->get(); + ->where('id_guru', $guru->id_guru)->get(); + $dotColors = ['#2b8ef3','#22c55e','#f97316','#a855f7','#ec4899','#eab308']; @endphp
-
{{ $greeting }}, {{ $guru->nama ?? 'Guru' }} 👋
{{ Carbon::now()->isoFormat('dddd, D MMMM Y') }}
@@ -120,8 +104,37 @@
-{{-- INFO GRID --}} -
+{{-- BOTTOM --}} +
+ + {{-- Stacked Bar Chart: Pengumpulan Tugas --}} +
+
+
Status Pengumpulan Tugas
+ Lihat Semua → +
+ + @if(count($chartLabels) > 0) +
+ +
+
+
+
+ Sudah Kumpul +
+
+
+ Belum Kumpul +
+
+ @else +
+
📋
+
Belum ada tugas dibuat.
+
+ @endif +
{{-- Daftar Mengajar --}}
@@ -130,9 +143,7 @@ Lihat Semua →
- @php $dotColors = ['#2b8ef3','#22c55e','#f97316','#a855f7','#ec4899','#eab308']; @endphp - - @forelse($mengajars->take(6) as $i => $m) + @forelse($mengajars->take(7) as $i => $m)
{{ optional($m->mapel)->nama_mapel ?? '-' }}
@@ -145,49 +156,58 @@ @endforelse
- {{-- Quick Links --}} - -
-@endsection \ No newline at end of file +@endsection + +@push('scripts') + + +@endpush \ No newline at end of file