978 lines
38 KiB
PHP
978 lines
38 KiB
PHP
{{--
|
|
FILE: resources/views/admin/challenge/index.blade.php
|
|
PERUBAHAN:
|
|
- Tambah field "Durasi Pengerjaan (menit)" di form Tambah & Edit
|
|
- Kolom durasi di tabel
|
|
- Logika timer siswa berubah: pakai durasi, bukan tenggat
|
|
--}}
|
|
|
|
@extends('admin.layouts.app')
|
|
|
|
@section('title', 'Daftar Challenge')
|
|
|
|
@section('content')
|
|
|
|
<style>
|
|
.page-title {
|
|
font-size: 30px;
|
|
font-weight: 800;
|
|
margin-bottom: 10px;
|
|
margin-top: -20px;
|
|
}
|
|
.custom-card {
|
|
background: white;
|
|
border-radius: 20px;
|
|
border: 2px solid #e5e5e5;
|
|
padding: 25px;
|
|
}
|
|
.btn-primary-custom {
|
|
background: #2b8ef3;
|
|
color: white;
|
|
border-radius: 10px;
|
|
padding: 8px 18px;
|
|
border: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 14px;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
font-family: 'Poppins', sans-serif;
|
|
}
|
|
.table-header { background: #a5e6ba; }
|
|
.search-box {
|
|
background: #a5e6ba;
|
|
border-radius: 30px;
|
|
padding: 6px 15px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.search-box input {
|
|
border: none;
|
|
outline: none;
|
|
background: transparent;
|
|
width: 160px;
|
|
}
|
|
.action-icon { width: 20px; cursor: pointer; margin: 0 4px; }
|
|
.inline-icon {
|
|
width: 16px;
|
|
height: 16px;
|
|
vertical-align: middle;
|
|
display: inline-block;
|
|
}
|
|
.deadline-badge {
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
padding: 3px 8px;
|
|
border-radius: 99px;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
.deadline-aktif { background: #dcfce7; color: #16a34a; }
|
|
.deadline-lewat { background: #fee2e2; color: #ef4444; }
|
|
.kelas-chip {
|
|
display: inline-block;
|
|
background: #e6f0ff;
|
|
color: #1d4ed8;
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
padding: 2px 8px;
|
|
border-radius: 99px;
|
|
margin: 1px;
|
|
}
|
|
.soal-count {
|
|
background: #f0fdf4;
|
|
color: #16a34a;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
padding: 3px 10px;
|
|
border-radius: 99px;
|
|
}
|
|
|
|
/* Badge durasi */
|
|
.durasi-badge {
|
|
background: #ede9fe;
|
|
color: #5b21b6;
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
padding: 3px 10px;
|
|
border-radius: 99px;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.alert-success-custom {
|
|
background: #dcfce7;
|
|
color: #166534;
|
|
border-radius: 10px;
|
|
padding: 12px 16px;
|
|
margin-bottom: 16px;
|
|
font-weight: 500;
|
|
font-size: 14px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
/* ── MODAL ─────────────────────────────── */
|
|
.modal-content {
|
|
border-radius: 16px;
|
|
border: none;
|
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
|
}
|
|
.modal-header-yellow {
|
|
background: #f9c946;
|
|
color: #1e293b;
|
|
border-bottom: none;
|
|
border-radius: 16px 16px 0 0;
|
|
padding: 18px 24px;
|
|
}
|
|
.modal-header-yellow .modal-title {
|
|
font-weight: 800;
|
|
font-size: 18px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.modal-body label { font-weight: 600; font-size: 13px; }
|
|
|
|
/* ── STEP INDICATOR ───────────────────── */
|
|
.step-indicator {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
background: #f8fafc;
|
|
border-radius: 12px;
|
|
padding: 12px 16px;
|
|
border: 1px solid #e2e8f0;
|
|
}
|
|
.step-dot {
|
|
width: 30px; height: 30px;
|
|
border-radius: 50%;
|
|
display: flex; align-items: center; justify-content: center;
|
|
font-size: 13px; font-weight: 800;
|
|
flex-shrink: 0;
|
|
transition: all 0.3s;
|
|
}
|
|
.step-dot.active { background: #f9c946; color: #1e293b; box-shadow: 0 0 0 3px rgba(249,201,70,.3); }
|
|
.step-dot.done { background: #16a34a; color: white; }
|
|
.step-dot.inactive { background: #e2e8f0; color: #94a3b8; }
|
|
.step-label {
|
|
font-size: 12px; font-weight: 700;
|
|
margin-left: 8px;
|
|
transition: color 0.3s;
|
|
}
|
|
.step-label.active { color: #1e293b; }
|
|
.step-label.inactive { color: #94a3b8; }
|
|
.step-line {
|
|
flex: 1; height: 2px;
|
|
background: #e2e8f0;
|
|
margin: 0 12px;
|
|
border-radius: 2px;
|
|
overflow: hidden;
|
|
position: relative;
|
|
}
|
|
.step-line-fill {
|
|
position: absolute; inset: 0;
|
|
background: #16a34a;
|
|
transform: scaleX(0);
|
|
transform-origin: left;
|
|
transition: transform 0.4s ease;
|
|
}
|
|
.step-line-fill.filled { transform: scaleX(1); }
|
|
|
|
/* ── STEP PANELS ──────────────────────── */
|
|
.step-panel { display: none; }
|
|
.step-panel.active { display: block; }
|
|
|
|
/* ── SOAL CARD ────────────────────────── */
|
|
.soal-card {
|
|
background: #f8fafc;
|
|
border: 1px solid #e2e8f0;
|
|
border-radius: 14px;
|
|
padding: 16px 18px;
|
|
margin-bottom: 12px;
|
|
position: relative;
|
|
}
|
|
.soal-card .soal-number {
|
|
position: absolute; top: -10px; left: 16px;
|
|
background: #667eea; color: white;
|
|
font-size: 11px; font-weight: 700;
|
|
padding: 2px 10px; border-radius: 99px;
|
|
}
|
|
.soal-card .btn-hapus-soal {
|
|
position: absolute; top: 10px; right: 12px;
|
|
background: #fee2e2; color: #ef4444;
|
|
border: none; border-radius: 8px;
|
|
width: 28px; height: 28px;
|
|
font-size: 14px; cursor: pointer;
|
|
display: flex; align-items: center; justify-content: center;
|
|
}
|
|
.soal-card .btn-hapus-soal:hover { background: #fca5a5; }
|
|
.opsi-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 8px; margin-top: 8px;
|
|
}
|
|
.opsi-item { display: flex; flex-direction: column; gap: 4px; }
|
|
.opsi-item label { font-size: 12px; color: #64748b; font-weight: 600; }
|
|
.opsi-item input { border-radius: 8px; border: 1px solid #cbd5e1; padding: 6px 10px; font-size: 13px; }
|
|
.jawaban-row {
|
|
display: flex; gap: 12px; align-items: center;
|
|
margin-top: 10px;
|
|
background: #fff; border-radius: 8px;
|
|
padding: 8px 12px; border: 1px solid #e2e8f0;
|
|
}
|
|
.jawaban-row label { font-size: 12px; color: #64748b; font-weight: 600; min-width: 90px; }
|
|
.btn-tambah-soal {
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
color: white; border: none; border-radius: 10px;
|
|
padding: 9px 18px; font-size: 13px; font-weight: 600;
|
|
cursor: pointer; width: 100%; margin-top: 4px;
|
|
font-family: 'Poppins', sans-serif;
|
|
}
|
|
.kelas-checkbox-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 8px;
|
|
}
|
|
.kelas-check-item {
|
|
display: flex; align-items: center; gap: 8px;
|
|
background: #f8fafc; border: 1px solid #e2e8f0;
|
|
border-radius: 8px; padding: 8px 10px;
|
|
cursor: pointer; transition: all 0.2s;
|
|
}
|
|
.kelas-check-item:hover { background: #e6f0ff; border-color: #2b8ef3; }
|
|
|
|
/* ── MODAL FIXED HEIGHT ───────────────── */
|
|
.modal-dialog-fixed .modal-content {
|
|
max-height: 90vh; overflow: hidden;
|
|
display: flex; flex-direction: column;
|
|
}
|
|
.modal-dialog-fixed form { display: contents; }
|
|
.modal-dialog-fixed .modal-header,
|
|
.modal-dialog-fixed .modal-footer { flex-shrink: 0; }
|
|
.modal-dialog-fixed .modal-body {
|
|
flex: 1 1 auto; overflow: hidden;
|
|
display: flex; flex-direction: column;
|
|
min-height: 0; padding-bottom: 0;
|
|
}
|
|
.modal-dialog-fixed .step-indicator { flex-shrink: 0; margin-bottom: 16px; }
|
|
.modal-dialog-fixed .step-panel { display: none; }
|
|
.modal-dialog-fixed .step-panel.active {
|
|
display: flex; flex-direction: column;
|
|
flex: 1 1 auto; min-height: 0;
|
|
}
|
|
#tambah-step-1, #edit-step-1 { overflow-y: auto; padding-right: 4px; }
|
|
#tambah-step-2, #edit-step-2 { overflow: hidden; }
|
|
.soal-scroll-area {
|
|
flex: 1 1 auto; min-height: 0;
|
|
overflow-y: auto; padding-right: 6px;
|
|
scroll-behavior: smooth;
|
|
}
|
|
.soal-scroll-area::-webkit-scrollbar { width: 6px; }
|
|
.soal-scroll-area::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 99px; }
|
|
.soal-scroll-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
|
|
.soal-scroll-area::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
|
|
|
/* ── DURASI FIELD ─────────────────────── */
|
|
.durasi-input-wrap {
|
|
position: relative;
|
|
}
|
|
.durasi-input-wrap input {
|
|
padding-right: 60px;
|
|
}
|
|
.durasi-input-wrap .durasi-unit {
|
|
position: absolute;
|
|
right: 12px; top: 50%;
|
|
transform: translateY(-50%);
|
|
font-size: 12px; font-weight: 700;
|
|
color: #5b21b6;
|
|
pointer-events: none;
|
|
}
|
|
.durasi-hint {
|
|
font-size: 11px;
|
|
color: #94a3b8;
|
|
margin-top: 4px;
|
|
font-style: italic;
|
|
}
|
|
/* Preview badge durasi di form */
|
|
.durasi-preview {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
background: #ede9fe;
|
|
color: #5b21b6;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
padding: 5px 14px;
|
|
border-radius: 99px;
|
|
margin-top: 6px;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.section-divider {
|
|
display: flex; align-items: center; gap: 6px;
|
|
font-size: 13px; font-weight: 700; color: #667eea;
|
|
border-bottom: 2px solid #e6f0ff;
|
|
padding-bottom: 6px; margin: 16px 0 12px;
|
|
}
|
|
|
|
.btn-green {
|
|
background: #16a34a; color: white;
|
|
border: none; border-radius: 10px;
|
|
padding: 9px 22px; font-size: 14px; font-weight: 700;
|
|
cursor: pointer; font-family: 'Poppins', sans-serif;
|
|
display: inline-flex; align-items: center; gap: 6px;
|
|
transition: background 0.2s;
|
|
}
|
|
.btn-green:hover { background: #15803d; }
|
|
</style>
|
|
|
|
<h3 class="page-title">DAFTAR CHALLENGE</h3>
|
|
|
|
@if(session('success'))
|
|
<div class="alert-success-custom">
|
|
<img src="{{ asset('images/icon/gurud/v.png') }}" class="inline-icon" alt="Berhasil">
|
|
{{ session('success') }}
|
|
</div>
|
|
@endif
|
|
|
|
<div class="custom-card">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<button class="btn-primary-custom" onclick="openTambahModal()">
|
|
<img src="{{ asset('images/icon/main/add.png') }}" class="inline-icon" alt="Tambah"> Tambah Challenge
|
|
</button>
|
|
<form method="GET">
|
|
<div class="search-box">
|
|
<input type="text" name="search" placeholder="Cari challenge..."
|
|
value="{{ request('search') }}">
|
|
<button style="border:none;background:none" type="submit">
|
|
<img src="{{ asset('images/icon/main/search.png') }}" class="inline-icon" alt="Cari">
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<table class="table text-center align-middle">
|
|
<thead class="table-header">
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Judul Challenge</th>
|
|
<th>Kelas</th>
|
|
<th>Soal</th>
|
|
<th>EXP</th>
|
|
<th>Durasi</th>
|
|
<th>Tenggat</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($challenges as $i => $ch)
|
|
@php $isLewat = \Carbon\Carbon::parse($ch->tenggat_waktu)->isPast(); @endphp
|
|
<tr>
|
|
<td>{{ $challenges->firstItem() + $i }}</td>
|
|
<td style="text-align:left">
|
|
<div style="font-weight:700;color:#1e293b">{{ $ch->judul_challenge }}</div>
|
|
@if($ch->deskripsi)
|
|
<div style="font-size:12px;color:#94a3b8">{{ Str::limit($ch->deskripsi, 50) }}</div>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
@foreach($ch->kelas as $k)
|
|
<span class="kelas-chip">{{ $k->tingkat }} {{ $k->nama_kelas }}</span>
|
|
@endforeach
|
|
</td>
|
|
<td><span class="soal-count">{{ $ch->soal_count }} soal</span></td>
|
|
<td style="font-weight:700;color:#667eea">{{ $ch->exp }} EXP</td>
|
|
{{-- Kolom durasi baru --}}
|
|
<td>
|
|
@if($ch->durasi_pengerjaan)
|
|
<span class="durasi-badge">
|
|
⏱ {{ $ch->durasi_pengerjaan }} menit
|
|
</span>
|
|
@else
|
|
<span style="font-size:12px;color:#94a3b8">—</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<span class="deadline-badge {{ $isLewat ? 'deadline-lewat' : 'deadline-aktif' }}">
|
|
@if($isLewat) Lewat @else Aktif @endif
|
|
</span>
|
|
<div style="font-size:11px;color:#64748b;margin-top:3px">
|
|
{{ \Carbon\Carbon::parse($ch->tenggat_waktu)->format('d M Y, H:i') }}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<button onclick="openEditModal({{ $ch->id_challenge }})"
|
|
style="border:none;background:none">
|
|
<img src="{{ asset('images/icon/main/edit.png') }}" class="action-icon" alt="Edit">
|
|
</button>
|
|
<a href="{{ route('admin.challenge.show', $ch->id_challenge) }}"
|
|
style="border:none;background:none;display:inline">
|
|
<img src="{{ asset('images/icon/main/search.png') }}" class="action-icon" alt="Lihat">
|
|
</a>
|
|
<form action="{{ route('admin.challenge.destroy', $ch->id_challenge) }}"
|
|
method="POST" class="d-inline"
|
|
onsubmit="return confirm('Yakin hapus challenge ini?')">
|
|
@csrf @method('DELETE')
|
|
<button type="submit" style="border:none;background:none">
|
|
<img src="{{ asset('images/icon/main/del.png') }}" class="action-icon" alt="Hapus">
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="8" class="text-muted py-4">Belum ada challenge.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
<div class="d-flex justify-content-end">{{ $challenges->links() }}</div>
|
|
</div>
|
|
|
|
|
|
{{-- ============================================================
|
|
MODAL TAMBAH
|
|
============================================================ --}}
|
|
<div class="modal fade" id="modalTambah" tabindex="-1">
|
|
<div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-fixed">
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header modal-header-yellow">
|
|
<h5 class="modal-title">
|
|
<img src="{{ asset('images/icon/gurud/piala.png') }}" class="inline-icon" alt="Piala">
|
|
Tambah Challenge Baru
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
|
|
<form action="{{ route('admin.challenge.store') }}" method="POST" id="formTambah">
|
|
@csrf
|
|
<div class="modal-body">
|
|
|
|
<div class="step-indicator" style="flex-shrink:0">
|
|
<div class="step-dot active" id="tambah-dot-1">1</div>
|
|
<span class="step-label active" id="tambah-label-1">Informasi Challenge</span>
|
|
<div class="step-line">
|
|
<div class="step-line-fill" id="tambah-line-fill"></div>
|
|
</div>
|
|
<div class="step-dot inactive" id="tambah-dot-2">2</div>
|
|
<span class="step-label inactive" id="tambah-label-2">Daftar Soal</span>
|
|
</div>
|
|
|
|
{{-- STEP 1 --}}
|
|
<div class="step-panel active" id="tambah-step-1">
|
|
|
|
<div class="section-divider">
|
|
<img src="{{ asset('images/icon/gurud/buku1.png') }}" class="inline-icon" alt="">
|
|
Informasi Challenge
|
|
</div>
|
|
|
|
<div class="row g-3 mb-2">
|
|
<div class="col-8">
|
|
<label>Judul Challenge <span class="text-danger">*</span></label>
|
|
<input type="text" name="judul_challenge" id="tambah-judul" class="form-control"
|
|
placeholder="Contoh: Challenge Matematika Minggu Ini">
|
|
</div>
|
|
<div class="col-4">
|
|
<label>Total EXP <span class="text-danger">*</span></label>
|
|
<input type="number" name="exp" id="tambah-exp" class="form-control"
|
|
value="100" min="0">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>Deskripsi</label>
|
|
<textarea name="deskripsi" class="form-control" rows="2"
|
|
placeholder="Deskripsi singkat challenge (opsional)"></textarea>
|
|
</div>
|
|
|
|
{{-- BARIS BARU: Tenggat Waktu + Durasi Pengerjaan --}}
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-6">
|
|
<label>Tenggat Waktu <span class="text-danger">*</span></label>
|
|
<input type="datetime-local" name="tenggat_waktu" id="tambah-tenggat"
|
|
class="form-control"
|
|
min="{{ now()->format('Y-m-d\TH:i') }}">
|
|
<div class="durasi-hint">Batas terakhir challenge bisa dikerjakan</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<label>Durasi Pengerjaan <span class="text-danger">*</span></label>
|
|
<div class="durasi-input-wrap">
|
|
<input type="number" name="durasi_pengerjaan" id="tambah-durasi"
|
|
class="form-control" min="1" max="360"
|
|
placeholder="cth: 20"
|
|
oninput="updateDurasiPreview('tambah')">
|
|
<span class="durasi-unit">menit</span>
|
|
</div>
|
|
<div id="tambah-durasi-preview" class="durasi-preview" style="display:none">
|
|
⏱ <span id="tambah-durasi-text">—</span>
|
|
</div>
|
|
<div class="durasi-hint">Waktu hitung mundur saat siswa mengerjakan</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-divider">
|
|
<img src="{{ asset('images/icon/gurud/school.png') }}" class="inline-icon" alt="">
|
|
Target Kelas
|
|
</div>
|
|
<div class="kelas-checkbox-grid mb-1">
|
|
@foreach($kelas as $k)
|
|
<label class="kelas-check-item">
|
|
<input type="checkbox" name="id_kelas[]" value="{{ $k->id_kelas }}">
|
|
<span style="font-size:13px;font-weight:600">{{ $k->tingkat }} {{ $k->nama_kelas }}</span>
|
|
</label>
|
|
@endforeach
|
|
</div>
|
|
|
|
</div>{{-- /tambah-step-1 --}}
|
|
|
|
{{-- STEP 2 --}}
|
|
<div class="step-panel" id="tambah-step-2">
|
|
<div class="section-divider" style="flex-shrink:0">
|
|
<img src="{{ asset('images/icon/gurud/buku1.png') }}" class="inline-icon" alt="">
|
|
Daftar Soal
|
|
</div>
|
|
<div id="soalContainer" class="soal-scroll-area"></div>
|
|
<div style="flex-shrink:0;padding-top:8px">
|
|
<button type="button" class="btn-tambah-soal" onclick="tambahSoal('soalContainer')">
|
|
+ Tambah Soal
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>{{-- /modal-body --}}
|
|
|
|
<div class="modal-footer" style="gap:8px">
|
|
<button type="button" class="btn btn-secondary" id="tambah-btn-back"
|
|
data-bs-dismiss="modal">Batal</button>
|
|
<button type="button" class="btn-green" id="tambah-btn-next"
|
|
onclick="tambahGoStep2()">Berikutnya →</button>
|
|
<button type="submit" class="btn-green" id="tambah-btn-submit" style="display:none">
|
|
<img src="{{ asset('images/icon/gurud/save.png') }}" class="inline-icon" alt=""> Simpan Challenge
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
{{-- ============================================================
|
|
MODAL EDIT
|
|
============================================================ --}}
|
|
<div class="modal fade" id="modalEdit" tabindex="-1">
|
|
<div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-fixed">
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header modal-header-yellow">
|
|
<h5 class="modal-title">
|
|
<img src="{{ asset('images/icon/gurud/pencil.png') }}" class="inline-icon" alt="">
|
|
Edit Challenge
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
|
|
<form id="formEdit" method="POST">
|
|
@csrf @method('PUT')
|
|
<div class="modal-body">
|
|
|
|
<div class="step-indicator" style="flex-shrink:0">
|
|
<div class="step-dot active" id="edit-dot-1">1</div>
|
|
<span class="step-label active" id="edit-label-1">Informasi Challenge</span>
|
|
<div class="step-line">
|
|
<div class="step-line-fill" id="edit-line-fill"></div>
|
|
</div>
|
|
<div class="step-dot inactive" id="edit-dot-2">2</div>
|
|
<span class="step-label inactive" id="edit-label-2">Daftar Soal</span>
|
|
</div>
|
|
|
|
{{-- STEP 1 --}}
|
|
<div class="step-panel active" id="edit-step-1">
|
|
|
|
<div class="section-divider">
|
|
<img src="{{ asset('images/icon/gurud/buku2.png') }}" class="inline-icon" alt="">
|
|
Informasi Challenge
|
|
</div>
|
|
|
|
<div class="row g-3 mb-2">
|
|
<div class="col-8">
|
|
<label>Judul Challenge <span class="text-danger">*</span></label>
|
|
<input type="text" name="judul_challenge" id="editJudul" class="form-control" required>
|
|
</div>
|
|
<div class="col-4">
|
|
<label>Total EXP <span class="text-danger">*</span></label>
|
|
<input type="number" name="exp" id="editExp" class="form-control" min="0" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>Deskripsi</label>
|
|
<textarea name="deskripsi" id="editDeskripsi" class="form-control" rows="2"></textarea>
|
|
</div>
|
|
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-6">
|
|
<label>Tenggat Waktu <span class="text-danger">*</span></label>
|
|
<input type="datetime-local" name="tenggat_waktu" id="editTenggat"
|
|
class="form-control" required>
|
|
<div class="durasi-hint">Batas terakhir challenge bisa dikerjakan</div>
|
|
</div>
|
|
<div class="col-6">
|
|
<label>Durasi Pengerjaan <span class="text-danger">*</span></label>
|
|
<div class="durasi-input-wrap">
|
|
<input type="number" name="durasi_pengerjaan" id="editDurasi"
|
|
class="form-control" min="1" max="360"
|
|
oninput="updateDurasiPreview('edit')">
|
|
<span class="durasi-unit">menit</span>
|
|
</div>
|
|
<div id="edit-durasi-preview" class="durasi-preview" style="display:none">
|
|
⏱ <span id="edit-durasi-text">—</span>
|
|
</div>
|
|
<div class="durasi-hint">Waktu hitung mundur saat siswa mengerjakan</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-divider">
|
|
<img src="{{ asset('images/icon/gurud/school.png') }}" class="inline-icon" alt="">
|
|
Target Kelas
|
|
</div>
|
|
<div class="kelas-checkbox-grid mb-1" id="editKelasContainer">
|
|
@foreach($kelas as $k)
|
|
<label class="kelas-check-item">
|
|
<input type="checkbox" name="id_kelas[]"
|
|
value="{{ $k->id_kelas }}" class="edit-kelas-check">
|
|
<span style="font-size:13px;font-weight:600">{{ $k->tingkat }} {{ $k->nama_kelas }}</span>
|
|
</label>
|
|
@endforeach
|
|
</div>
|
|
|
|
</div>{{-- /edit-step-1 --}}
|
|
|
|
{{-- STEP 2 --}}
|
|
<div class="step-panel" id="edit-step-2">
|
|
<div class="section-divider" style="flex-shrink:0">
|
|
<img src="{{ asset('images/icon/gurud/buku1.png') }}" class="inline-icon" alt="">
|
|
Daftar Soal
|
|
</div>
|
|
<div id="editSoalContainer" class="soal-scroll-area"></div>
|
|
<div style="flex-shrink:0;padding-top:8px">
|
|
<button type="button" class="btn-tambah-soal" onclick="tambahSoal('editSoalContainer')">
|
|
+ Tambah Soal
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>{{-- /modal-body --}}
|
|
|
|
<div class="modal-footer" style="gap:8px">
|
|
<button type="button" class="btn btn-secondary" id="edit-btn-back"
|
|
data-bs-dismiss="modal">Batal</button>
|
|
<button type="button" class="btn-green" id="edit-btn-next"
|
|
onclick="editGoStep2()">Berikutnya →</button>
|
|
<button type="submit" class="btn-green" id="edit-btn-submit" style="display:none">
|
|
<img src="{{ asset('images/icon/gurud/save.png') }}" class="inline-icon" alt=""> Update Challenge
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
let soalCountTambah = 0;
|
|
let soalCountEdit = 0;
|
|
|
|
/* ──────────────────────────────────────────────
|
|
DURASI PREVIEW
|
|
────────────────────────────────────────────── */
|
|
function updateDurasiPreview(prefix) {
|
|
const input = document.getElementById(prefix === 'edit' ? 'editDurasi' : 'tambah-durasi');
|
|
const preview = document.getElementById(`${prefix}-durasi-preview`);
|
|
const textEl = document.getElementById(`${prefix}-durasi-text`);
|
|
const val = parseInt(input.value);
|
|
|
|
if (!val || val < 1) {
|
|
preview.style.display = 'none';
|
|
return;
|
|
}
|
|
|
|
preview.style.display = 'inline-flex';
|
|
const jam = Math.floor(val / 60);
|
|
const menit = val % 60;
|
|
let label = '';
|
|
if (jam > 0 && menit > 0) label = `${jam} jam ${menit} menit`;
|
|
else if (jam > 0) label = `${jam} jam`;
|
|
else label = `${menit} menit`;
|
|
|
|
textEl.textContent = label;
|
|
}
|
|
|
|
/* ──────────────────────────────────────────────
|
|
STEP NAVIGATION — TAMBAH
|
|
────────────────────────────────────────────── */
|
|
function tambahGoStep2() {
|
|
const judul = document.getElementById('tambah-judul').value.trim();
|
|
const tenggat = document.getElementById('tambah-tenggat').value;
|
|
const durasi = document.getElementById('tambah-durasi').value;
|
|
|
|
if (!judul) { alert('Judul challenge wajib diisi.'); return; }
|
|
if (!tenggat) { alert('Tenggat waktu wajib diisi.'); return; }
|
|
if (!durasi || parseInt(durasi) < 1) {
|
|
alert('Durasi pengerjaan wajib diisi (minimal 1 menit).'); return;
|
|
}
|
|
|
|
document.getElementById('tambah-step-1').classList.remove('active');
|
|
document.getElementById('tambah-step-2').classList.add('active');
|
|
document.getElementById('tambah-dot-1').classList.replace('active','done');
|
|
document.getElementById('tambah-dot-1').textContent = '✓';
|
|
document.getElementById('tambah-label-1').classList.replace('active','inactive');
|
|
document.getElementById('tambah-dot-2').classList.replace('inactive','active');
|
|
document.getElementById('tambah-label-2').classList.replace('inactive','active');
|
|
document.getElementById('tambah-line-fill').classList.add('filled');
|
|
|
|
document.getElementById('tambah-btn-next').style.display = 'none';
|
|
document.getElementById('tambah-btn-submit').style.display = '';
|
|
const backBtn = document.getElementById('tambah-btn-back');
|
|
backBtn.removeAttribute('data-bs-dismiss');
|
|
backBtn.textContent = '← Kembali';
|
|
backBtn.onclick = tambahGoStep1;
|
|
}
|
|
|
|
function tambahGoStep1() {
|
|
document.getElementById('tambah-step-2').classList.remove('active');
|
|
document.getElementById('tambah-step-1').classList.add('active');
|
|
document.getElementById('tambah-dot-1').classList.replace('done','active');
|
|
document.getElementById('tambah-dot-1').textContent = '1';
|
|
document.getElementById('tambah-label-1').classList.replace('inactive','active');
|
|
document.getElementById('tambah-dot-2').classList.replace('active','inactive');
|
|
document.getElementById('tambah-label-2').classList.replace('active','inactive');
|
|
document.getElementById('tambah-line-fill').classList.remove('filled');
|
|
|
|
document.getElementById('tambah-btn-next').style.display = '';
|
|
document.getElementById('tambah-btn-submit').style.display = 'none';
|
|
const backBtn = document.getElementById('tambah-btn-back');
|
|
backBtn.setAttribute('data-bs-dismiss','modal');
|
|
backBtn.textContent = 'Batal';
|
|
backBtn.onclick = null;
|
|
}
|
|
|
|
/* ──────────────────────────────────────────────
|
|
STEP NAVIGATION — EDIT
|
|
────────────────────────────────────────────── */
|
|
function editGoStep2() {
|
|
const judul = document.getElementById('editJudul').value.trim();
|
|
const tenggat = document.getElementById('editTenggat').value;
|
|
const durasi = document.getElementById('editDurasi').value;
|
|
|
|
if (!judul) { alert('Judul challenge wajib diisi.'); return; }
|
|
if (!tenggat) { alert('Tenggat waktu wajib diisi.'); return; }
|
|
if (!durasi || parseInt(durasi) < 1) {
|
|
alert('Durasi pengerjaan wajib diisi (minimal 1 menit).'); return;
|
|
}
|
|
|
|
document.getElementById('edit-step-1').classList.remove('active');
|
|
document.getElementById('edit-step-2').classList.add('active');
|
|
document.getElementById('edit-dot-1').classList.replace('active','done');
|
|
document.getElementById('edit-dot-1').textContent = '✓';
|
|
document.getElementById('edit-label-1').classList.replace('active','inactive');
|
|
document.getElementById('edit-dot-2').classList.replace('inactive','active');
|
|
document.getElementById('edit-label-2').classList.replace('inactive','active');
|
|
document.getElementById('edit-line-fill').classList.add('filled');
|
|
|
|
document.getElementById('edit-btn-next').style.display = 'none';
|
|
document.getElementById('edit-btn-submit').style.display = '';
|
|
const backBtn = document.getElementById('edit-btn-back');
|
|
backBtn.removeAttribute('data-bs-dismiss');
|
|
backBtn.textContent = '← Kembali';
|
|
backBtn.onclick = editGoStep1;
|
|
}
|
|
|
|
function editGoStep1() {
|
|
document.getElementById('edit-step-2').classList.remove('active');
|
|
document.getElementById('edit-step-1').classList.add('active');
|
|
document.getElementById('edit-dot-1').classList.replace('done','active');
|
|
document.getElementById('edit-dot-1').textContent = '1';
|
|
document.getElementById('edit-label-1').classList.replace('inactive','active');
|
|
document.getElementById('edit-dot-2').classList.replace('active','inactive');
|
|
document.getElementById('edit-label-2').classList.replace('active','inactive');
|
|
document.getElementById('edit-line-fill').classList.remove('filled');
|
|
|
|
document.getElementById('edit-btn-next').style.display = '';
|
|
document.getElementById('edit-btn-submit').style.display = 'none';
|
|
const backBtn = document.getElementById('edit-btn-back');
|
|
backBtn.setAttribute('data-bs-dismiss','modal');
|
|
backBtn.textContent = 'Batal';
|
|
backBtn.onclick = null;
|
|
}
|
|
|
|
/* ──────────────────────────────────────────────
|
|
EXP RECALC
|
|
────────────────────────────────────────────── */
|
|
function getExpInput(containerId) {
|
|
return containerId === 'editSoalContainer'
|
|
? document.getElementById('editExp')
|
|
: document.getElementById('tambah-exp');
|
|
}
|
|
|
|
function recalcExp(containerId) {
|
|
const expInput = getExpInput(containerId);
|
|
const totalExp = parseInt(expInput?.value) || 0;
|
|
const cards = document.querySelectorAll(`#${containerId} .soal-card`);
|
|
const jumlah = cards.length;
|
|
if (!jumlah) return;
|
|
|
|
const base = Math.floor(totalExp / jumlah);
|
|
const remainder = totalExp - base * jumlah;
|
|
|
|
cards.forEach((card, i) => {
|
|
const hidden = card.querySelector('input[name="exp_per_soal[]"]');
|
|
const display = card.querySelector('.exp-per-soal-display');
|
|
const val = base + (i === jumlah - 1 ? remainder : 0);
|
|
if (hidden) hidden.value = val;
|
|
if (display) display.textContent = val + ' EXP';
|
|
});
|
|
}
|
|
|
|
/* ──────────────────────────────────────────────
|
|
SOAL HELPERS
|
|
────────────────────────────────────────────── */
|
|
function tambahSoal(containerId, data = null) {
|
|
const isEdit = containerId === 'editSoalContainer';
|
|
const count = isEdit ? ++soalCountEdit : ++soalCountTambah;
|
|
const container = document.getElementById(containerId);
|
|
|
|
const card = document.createElement('div');
|
|
card.className = 'soal-card';
|
|
card.innerHTML = `
|
|
<span class="soal-number">Soal ${count}</span>
|
|
<button type="button" class="btn-hapus-soal" onclick="hapusSoal(this,'${containerId}')">✕</button>
|
|
<div class="mb-2" style="margin-top:10px">
|
|
<label>Pertanyaan <span class="text-danger">*</span></label>
|
|
<textarea name="pertanyaan[]" class="form-control" rows="2"
|
|
placeholder="Tuliskan pertanyaan..." required>${data ? data.pertanyaan : ''}</textarea>
|
|
</div>
|
|
<div class="opsi-grid">
|
|
<div class="opsi-item">
|
|
<label>Opsi A</label>
|
|
<input type="text" name="opsi_a[]" class="form-control"
|
|
placeholder="Opsi A" required value="${data ? data.opsi_a : ''}">
|
|
</div>
|
|
<div class="opsi-item">
|
|
<label>Opsi B</label>
|
|
<input type="text" name="opsi_b[]" class="form-control"
|
|
placeholder="Opsi B" required value="${data ? data.opsi_b : ''}">
|
|
</div>
|
|
<div class="opsi-item">
|
|
<label>Opsi C</label>
|
|
<input type="text" name="opsi_c[]" class="form-control"
|
|
placeholder="Opsi C" required value="${data ? data.opsi_c : ''}">
|
|
</div>
|
|
<div class="opsi-item">
|
|
<label>Opsi D</label>
|
|
<input type="text" name="opsi_d[]" class="form-control"
|
|
placeholder="Opsi D" required value="${data ? data.opsi_d : ''}">
|
|
</div>
|
|
</div>
|
|
<div class="jawaban-row">
|
|
<label>Jawaban Benar</label>
|
|
<select name="jawaban_benar[]" class="form-select" style="width:100px" required>
|
|
${['A','B','C','D'].map(o =>
|
|
`<option value="${o}" ${data?.jawaban_benar === o ? 'selected' : ''}>${o}</option>`
|
|
).join('')}
|
|
</select>
|
|
<input type="hidden" name="exp_per_soal[]" value="0">
|
|
<span style="margin-left:auto;background:#f0fdf4;color:#16a34a;font-size:12px;
|
|
font-weight:700;padding:4px 12px;border-radius:99px;white-space:nowrap">
|
|
⚡ <span class="exp-per-soal-display">0 EXP</span>
|
|
</span>
|
|
</div>`;
|
|
|
|
container.appendChild(card);
|
|
renumberSoal(containerId);
|
|
recalcExp(containerId);
|
|
container.scrollTop = container.scrollHeight;
|
|
}
|
|
|
|
function hapusSoal(btn, containerId) {
|
|
if (document.getElementById(containerId).querySelectorAll('.soal-card').length <= 1) {
|
|
alert('Minimal harus ada 1 soal.'); return;
|
|
}
|
|
btn.closest('.soal-card').remove();
|
|
renumberSoal(containerId);
|
|
recalcExp(containerId);
|
|
}
|
|
|
|
function renumberSoal(containerId) {
|
|
document.querySelectorAll(`#${containerId} .soal-card`).forEach((card, i) => {
|
|
const num = card.querySelector('.soal-number');
|
|
if (num) num.textContent = `Soal ${i + 1}`;
|
|
});
|
|
}
|
|
|
|
/* ──────────────────────────────────────────────
|
|
OPEN MODAL TAMBAH
|
|
────────────────────────────────────────────── */
|
|
function openTambahModal() {
|
|
soalCountTambah = 0;
|
|
document.getElementById('soalContainer').innerHTML = '';
|
|
document.getElementById('formTambah').reset();
|
|
document.getElementById('tambah-durasi-preview').style.display = 'none';
|
|
|
|
tambahGoStep1();
|
|
tambahSoal('soalContainer');
|
|
|
|
document.getElementById('tambah-exp').oninput = () => recalcExp('soalContainer');
|
|
new bootstrap.Modal(document.getElementById('modalTambah')).show();
|
|
}
|
|
|
|
async function openEditModal(idChallenge) {
|
|
// Reset semua state dulu sebelum fetch
|
|
soalCountEdit = 0;
|
|
document.getElementById('editSoalContainer').innerHTML = '';
|
|
editGoStep1();
|
|
|
|
// Tutup modal lama kalau masih terbuka, cegah duplikasi instance Bootstrap
|
|
const modalEl = document.getElementById('modalEdit');
|
|
const existingModal = bootstrap.Modal.getInstance(modalEl);
|
|
if (existingModal) existingModal.dispose();
|
|
|
|
const res = await fetch(`/admin/challenge/${idChallenge}/edit-data`);
|
|
const data = await res.json();
|
|
|
|
document.getElementById('formEdit').action = `/admin/challenge/${idChallenge}`;
|
|
document.getElementById('editJudul').value = data.judul_challenge;
|
|
document.getElementById('editExp').value = data.exp;
|
|
document.getElementById('editDeskripsi').value = data.deskripsi ?? '';
|
|
|
|
const durasi = data.durasi_pengerjaan ?? '';
|
|
document.getElementById('editDurasi').value = durasi;
|
|
updateDurasiPreview('edit');
|
|
|
|
const tenggat = data.tenggat_waktu ?? '';
|
|
document.getElementById('editTenggat').value = tenggat.slice(0, 16);
|
|
|
|
document.querySelectorAll('.edit-kelas-check').forEach(cb => {
|
|
cb.checked = data.kelas.includes(parseInt(cb.value));
|
|
});
|
|
|
|
document.getElementById('editSoalContainer').innerHTML = '';
|
|
soalCountEdit = 0;
|
|
|
|
data.soal.forEach(s => tambahSoal('editSoalContainer', s));
|
|
|
|
document.getElementById('editExp').oninput = () => recalcExp('editSoalContainer');
|
|
recalcExp('editSoalContainer');
|
|
|
|
new bootstrap.Modal(modalEl).show();
|
|
}
|
|
</script>
|
|
|
|
@endsection |