601 lines
20 KiB
PHP
601 lines
20 KiB
PHP
@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; }
|
|
|
|
.deadline-badge {
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
padding: 3px 8px;
|
|
border-radius: 99px;
|
|
display: inline-block;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
.alert-success-custom {
|
|
background: #dcfce7;
|
|
color: #166534;
|
|
border-radius: 10px;
|
|
padding: 12px 16px;
|
|
margin-bottom: 16px;
|
|
font-weight: 500;
|
|
font-size: 14px;
|
|
}
|
|
|
|
/* MODAL */
|
|
.modal-header-challenge {
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
color: white;
|
|
border-bottom: none;
|
|
border-radius: 16px 16px 0 0;
|
|
}
|
|
|
|
.modal-header-challenge .btn-close { filter: brightness(0) invert(1); }
|
|
|
|
.modal-content {
|
|
border-radius: 16px;
|
|
border: none;
|
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
|
}
|
|
|
|
.modal-body label { font-weight: 600; font-size: 13px; }
|
|
|
|
/* 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; }
|
|
.kelas-check-item input[type="checkbox"] { cursor: pointer; }
|
|
|
|
.section-divider {
|
|
font-size: 13px;
|
|
font-weight: 700;
|
|
color: #667eea;
|
|
border-bottom: 2px solid #e6f0ff;
|
|
padding-bottom: 6px;
|
|
margin: 16px 0 12px;
|
|
}
|
|
</style>
|
|
|
|
<h3 class="page-title">DAFTAR CHALLENGE</h3>
|
|
|
|
@if(session('success'))
|
|
<div class="alert-success-custom">✅ {{ 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') }}" width="18"> 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') }}" width="18">
|
|
</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>Total EXP</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>
|
|
<td>
|
|
<span class="deadline-badge {{ $isLewat ? 'deadline-lewat' : 'deadline-aktif' }}">
|
|
{{ $isLewat ? '⏰ Lewat' : '✅ Aktif' }}
|
|
</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">
|
|
</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">
|
|
</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">
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="7" 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-scrollable">
|
|
<div class="modal-content">
|
|
<div class="modal-header modal-header-challenge">
|
|
<h5 class="modal-title">🏆 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">
|
|
|
|
{{-- INFO CHALLENGE --}}
|
|
<div class="section-divider">📋 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" class="form-control"
|
|
placeholder="Contoh: Challenge Matematika Minggu Ini" required>
|
|
</div>
|
|
<div class="col-4">
|
|
<label>Total EXP <span class="text-danger">*</span></label>
|
|
<input type="number" name="exp" class="form-control" value="100" min="0" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>Deskripsi</label>
|
|
<textarea name="deskripsi" class="form-control" rows="2"
|
|
placeholder="Deskripsi singkat challenge (opsional)"></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" class="form-control" required
|
|
min="{{ now()->format('Y-m-d\TH:i') }}">
|
|
</div>
|
|
<div class="col-6">
|
|
<label>Badge Reward</label>
|
|
<select name="id_badge" class="form-control">
|
|
<option value="">-- Tanpa Badge --</option>
|
|
@foreach($badges as $badge)
|
|
<option value="{{ $badge->id_badge }}">{{ $badge->nama_badge }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- PILIH KELAS --}}
|
|
<div class="section-divider">🏫 Target Kelas</div>
|
|
<div class="kelas-checkbox-grid mb-3">
|
|
@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>
|
|
|
|
{{-- SOAL --}}
|
|
<div class="section-divider">📝 Daftar Soal</div>
|
|
<div id="soalContainer"></div>
|
|
<button type="button" class="btn-tambah-soal" onclick="tambahSoal('soalContainer')">
|
|
+ Tambah Soal
|
|
</button>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
|
<button type="submit" class="btn btn-success">💾 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-scrollable">
|
|
<div class="modal-content">
|
|
<div class="modal-header modal-header-challenge">
|
|
<h5 class="modal-title">✏️ 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="section-divider">📋 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>
|
|
<div class="col-6">
|
|
<label>Badge Reward</label>
|
|
<select name="id_badge" id="editBadge" class="form-control">
|
|
<option value="">-- Tanpa Badge --</option>
|
|
@foreach($badges as $badge)
|
|
<option value="{{ $badge->id_badge }}">{{ $badge->nama_badge }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-divider">🏫 Target Kelas</div>
|
|
<div class="kelas-checkbox-grid mb-3" 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 class="section-divider">📝 Daftar Soal</div>
|
|
<div id="editSoalContainer"></div>
|
|
<button type="button" class="btn-tambah-soal" onclick="tambahSoal('editSoalContainer')">
|
|
+ Tambah Soal
|
|
</button>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
|
<button type="submit" class="btn btn-warning">💾 Update Challenge</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let soalCountTambah = 0;
|
|
let soalCountEdit = 0;
|
|
|
|
// ===== TAMBAH SOAL BARU =====
|
|
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 && data.jawaban_benar === o ? 'selected' : ''}>${o}</option>`
|
|
).join('')}
|
|
</select>
|
|
<label style="margin-left:16px">EXP per Soal</label>
|
|
<input type="number" name="exp_per_soal[]" class="form-control" style="width:90px"
|
|
min="0" value="${data ? data.exp_per_soal : 10}" required>
|
|
</div>
|
|
`;
|
|
|
|
container.appendChild(card);
|
|
renumberSoal(containerId);
|
|
}
|
|
|
|
// ===== HAPUS SOAL =====
|
|
function hapusSoal(btn, containerId) {
|
|
const container = document.getElementById(containerId);
|
|
if (container.querySelectorAll('.soal-card').length <= 1) {
|
|
alert('Minimal harus ada 1 soal.');
|
|
return;
|
|
}
|
|
btn.closest('.soal-card').remove();
|
|
renumberSoal(containerId);
|
|
}
|
|
|
|
// ===== RENUMBER SOAL =====
|
|
function renumberSoal(containerId) {
|
|
const cards = document.querySelectorAll(`#${containerId} .soal-card`);
|
|
cards.forEach((card, i) => {
|
|
const num = card.querySelector('.soal-number');
|
|
if (num) num.textContent = `Soal ${i + 1}`;
|
|
});
|
|
}
|
|
|
|
// ===== BUKA MODAL TAMBAH =====
|
|
function openTambahModal() {
|
|
soalCountTambah = 0;
|
|
document.getElementById('soalContainer').innerHTML = '';
|
|
document.getElementById('formTambah').reset();
|
|
tambahSoal('soalContainer'); // default 1 soal
|
|
new bootstrap.Modal(document.getElementById('modalTambah')).show();
|
|
}
|
|
|
|
// ===== BUKA MODAL EDIT =====
|
|
async function openEditModal(idChallenge) {
|
|
soalCountEdit = 0;
|
|
document.getElementById('editSoalContainer').innerHTML = '';
|
|
|
|
// Fetch data challenge via AJAX
|
|
const res = await fetch(`/admin/challenge/${idChallenge}/edit-data`);
|
|
const data = await res.json();
|
|
|
|
// Isi form
|
|
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 ?? '';
|
|
document.getElementById('editBadge').value = data.id_badge ?? '';
|
|
|
|
// Format datetime-local
|
|
const dt = new Date(data.tenggat_waktu);
|
|
const pad = n => String(n).padStart(2,'0');
|
|
document.getElementById('editTenggat').value =
|
|
`${dt.getFullYear()}-${pad(dt.getMonth()+1)}-${pad(dt.getDate())}T${pad(dt.getHours())}:${pad(dt.getMinutes())}`;
|
|
|
|
// Centang kelas
|
|
document.querySelectorAll('.edit-kelas-check').forEach(cb => {
|
|
cb.checked = data.kelas.includes(parseInt(cb.value));
|
|
});
|
|
|
|
// Isi soal
|
|
data.soal.forEach(s => tambahSoal('editSoalContainer', s));
|
|
|
|
new bootstrap.Modal(document.getElementById('modalEdit')).show();
|
|
}
|
|
</script>
|
|
|
|
@endsection |