<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ujian Akhir</title>
<link rel="stylesheet" href="path/to/your/css/file.css">
<meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
<?php echo $__env->make('web.frontend.layouts.css', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
</head>
<body class="overflow-hidden">
<!-- Content Start -->
<div>
<div class="wrapper d-flex align-items-stretch" style="display: flex; height: calc(150vh - 15rem);">
<div class="wrapper d-flex align-items-stretch" style="display: flex; height: calc(150vh - 15rem);">
<div id="navbarToggleExternalContent" class="show order-last d-flex flex-column p-4" style="width: 450px; background-color: #f8f9fa;">
<div class="text-center mb-4" style="padding-top: 60px;">
<h5 class="fw-bold">Navigasi Soal</h5>
</div>
<div class="flex-grow-1" style="overflow-y: auto;">
<div class="d-flex flex-wrap gap-2 justify-content-start p-2">
<?php $__currentLoopData = $questions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $question): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<a href="#question-<?php echo e($question->id); ?>"
onclick="scrollToQuestion('question-<?php echo e($question->id); ?>', event)"
class="btn btn-outline-primary d-flex align-items-center justify-content-center"
style="width: 50px; height: 50px;">
<?php echo e($index + 1); ?>
</a>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
</div>
</div>
<div class="d-flex flex-column" style="height: 100vh; padding-top: 70px; padding-bottom: 70px; width: 75vw;">
<header class="fixed-top bg-light border-bottom py-3">
<div class="d-flex justify-content-center me-5">
<div class="logo ms-3">
<a href="<?php echo e(route('beranda')); ?>"><img id="logo_img" src="<?php echo e(asset('image/logo/logo aja.png')); ?>" alt="logo"><?php echo e(env('APP_NAME')); ?> </a>
</div>
</div>
</header>
<div class="flex-grow-1 overflow-auto px-4" style="margin-top: 20px; margin-bottom: 20px;">
<div class="fs-5 container">
<h3>Ujian: <?php echo e($course->title); ?></h3>
<div id="timer" class="alert alert-info"></div>
<form method="POST" action="<?php echo e(route('exam.submit', $course)); ?>">
<?php echo csrf_field(); ?>
<?php $__currentLoopData = $questions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $question): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="mb-4">
<strong><?php echo e($index + 1); ?>. <?php echo e($question->question); ?></strong>
<?php $__currentLoopData = $question->choices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $choice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div>
<input type="radio" id="q<?php echo e($question->id); ?>_c<?php echo e($choice->id); ?>" name="answers[<?php echo e($question->id); ?>]" value="<?php echo e($choice->id); ?>" required>
<label for="q<?php echo e($question->id); ?>_c<?php echo e($choice->id); ?>">
<?php echo e(chr(65 + $loop->index)); ?>. <?php echo e($choice->answer); ?>
</label>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
</div>
<footer class="fixed-bottom bg-light border-top py-3">
<div class="d-flex justify-content-end me-5">
</div>
</footer>
</div>
<!-- Footer End -->
<!-- Rating Modal -->
<!-- Modal -->
<div class="modal fade" id="ratingModal" tabindex="-1" aria-labelledby="ratingModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="rating-title fs-1">Beri Review</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
</div>
</div>
</div>
<?php echo $__env->make('web.frontend.layouts.js', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
</body>
<script>
// const deadline = new Date("<?php echo e(\Carbon\Carbon::parse($session->start_time)->addMinutes($course->exam_duration_minutes)); ?>").getTime();
const deadline = new Date("<?php echo e(\Carbon\Carbon::parse($session->start_time)->addMinutes($course->exam_duration_minutes)->toIso8601String()); ?>").getTime();
const x = setInterval(function () {
let now = new Date().getTime();
let distance = deadline - now;
if (distance <= 0) {
clearInterval(x);
alert("Waktu ujian habis!");
window.location.href = "<?php echo e(route('exam.start', $course)); ?>"; // atau redirect ke dashboard
} else {
let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer").innerText = "Sisa waktu: " + minutes + "m " + seconds + "s ";
}
}, 1000);
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Add this new code for dropdown functionality
var moduleToggles = document.getElementsByClassName("module-toggle");
for (var i = 0; i < moduleToggles.length; i++) {
moduleToggles[i].addEventListener("click", function() {
this.classList.toggle("active");
var submodules = this.nextElementSibling;
if (submodules.style.maxHeight) {
submodules.style.maxHeight = null;
} else {
submodules.style.maxHeight = submodules.scrollHeight + "px";
}
});
}
function validateForm() {
var rating = document.querySelector('input[name="rating"]:checked');
var review = document.getElementById('comment').value;
if (!rating || review.trim() === "") {
alert("Mohon isi semua field!");
return false;
}
return true;
}
});
</script>
<script>
// Meneruskan nilai konfigurasi dari Laravel ke JavaScript
window.judge0Config = {
url: "<?php echo e(config('judge0.url', 'https://judge0.britech.id')); ?>",
token: "<?php echo e(config('judge0.token')); ?>"
};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs/loader.min.js"></script>
<script>
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs' }});
function saveAnswer(soalId, answer, isSolved) {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
fetch("<?php echo e(route('soal.saveAnswer')); ?>", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken
},
body: JSON.stringify({
soal_id: soalId,
answer: answer,
is_solved: isSolved
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('Jawaban berhasil disimpan ke database.');
} else {
console.error('Gagal menyimpan jawaban:', data.message);
}
})
.catch(error => {
console.error('Error saat menyimpan jawaban:', error);
});
}
require(['vs/editor/editor.main'], function () {
const codingBoxes = document.querySelectorAll('.live-coding-box');
const nextButton = document.getElementById('nextButton');
const finishButton = document.getElementById('finishButton');
const totalSoal = codingBoxes.length;
let solvedSoal = 0;
// Jika ada soal, nonaktifkan tombol Next/Finish secara default
if (totalSoal > 0) {
if (nextButton) nextButton.classList.add('disabled');
if (finishButton) finishButton.classList.add('disabled');
}
function checkCompletion() {
if (totalSoal > 0 && solvedSoal === totalSoal) {
if (nextButton) nextButton.classList.remove('disabled');
if (finishButton) finishButton.classList.remove('disabled');
}
}
const languageMap = {
'63': 'javascript', // JavaScript (Node.js 12.14.0)
'71': 'python', // Python (3.8.1)
'70': 'python', // Python (2.7.17)
// Tambahkan mapping lain jika diperlukan
};
codingBoxes.forEach(function(box) {
const container = box.querySelector('.monaco-container');
const languageId = box.dataset.languageId;
const monacoLanguage = languageMap[languageId] || 'plaintext';
const initialCode = box.querySelector('.initial-code').textContent;
const editor = monaco.editor.create(container, {
value: initialCode.trim(),
language: monacoLanguage,
automaticLayout: true,
theme: 'vs-dark'
});
const runButton = box.querySelector('.btn-run-code');
const outputEl = box.querySelector('.output');
// Ambil jawaban yang diharapkan dari data-attribute, yang berasal dari model Soal
const expectedOutput = box.dataset.answer.trim();
let useStdin = false; // Variabel untuk melacak status stdin
runButton.addEventListener('click', function () {
const sourceCode = editor.getValue();
// Pengecekan dasar untuk mencegah pengiriman kode kosong
if (!sourceCode.trim()) {
outputEl.style.display = 'block';
outputEl.textContent = '⚠️ Kode tidak boleh kosong.';
outputEl.classList.remove('bg-success-subtle', 'text-success-emphasis');
outputEl.classList.add('bg-dark', 'text-white');
return;
}
outputEl.style.display = 'block';
outputEl.textContent = 'Menjalankan kode...';
runButton.disabled = true; // Nonaktifkan tombol selama eksekusi
// Persiapan payload untuk Judge0, termasuk stdin jika diaktifkan
let submissionData = {
language_id: parseInt(languageId),
source_code: sourceCode,
expected_output: expectedOutput
};
if (useStdin) {
const stdin = box.querySelector(`#stdin-${box.dataset.soalId}`).value;
if (stdin) {
submissionData.stdin = stdin;
}
}
const judge0ApiUrl = `${window.judge0Config.url}/submissions?base64_encoded=false&wait=true`;
fetch(judge0ApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-rapidapi-key': window.judge0Config.token,
},
body: JSON.stringify(submissionData)
})
.then(res => {
if (!res.ok) {
// Tangani error HTTP seperti 500, 404, dll.
return res.json().then(errorData => {
throw new Error(`HTTP error ${res.status}: ${errorData.message || res.statusText}`);
});
}
return res.json();
})
.then(data => {
console.log('Judge0 Response:', data);
// Tangani berbagai status dari Judge0
const statusId = data.status.id;
const statusDescription = data.status.description;
let resultText = `Status: ${statusDescription}\n`;
// Tambahkan pesan output/error
if (data.stdout) resultText += `\nOutput:\n${data.stdout}`;
if (data.stderr) resultText += `\nError:\n${data.stderr}`;
if (data.compile_output) resultText += `\nCompile Error:\n${data.compile_output}`;
if (data.message) resultText += `\nMessage: ${data.message}`;
outputEl.textContent = resultText;
if (statusId === 3) { // Status: Accepted
outputEl.textContent += '\n\n✅ Jawaban benar!';
outputEl.classList.remove('bg-dark', 'text-white');
outputEl.classList.add('bg-success-subtle', 'text-success-emphasis');
saveAnswer(box.dataset.soalId, sourceCode, true);
if (!box.classList.contains('solved')) {
box.classList.add('solved');
solvedSoal++;
checkCompletion(); // Cek apakah semua soal sudah terjawab
}
} else {
outputEl.textContent += '\n❌ Jawaban belum sesuai.';
outputEl.classList.remove('bg-success-subtle', 'text-success-emphasis');
outputEl.classList.add('bg-dark', 'text-white');
}
})
.catch(err => {
console.error('Fetch Error:', err);
outputEl.textContent = `⚠️ Gagal menjalankan kode: ${err.message}`;
outputEl.classList.remove('bg-success-subtle', 'text-success-emphasis');
outputEl.classList.add('bg-dark', 'text-white');
}).finally(() => {
runButton.disabled = false; // Aktifkan kembali tombol
});
});
// Event listener untuk tombol reset kode
box.querySelector('.btn-reset-code').addEventListener('click', function() {
editor.setValue(initialCode.trim());
outputEl.style.display = 'none';
box.classList.remove('solved');
if (box.classList.contains('solved')) {
solvedSoal--;
checkCompletion();
}
});
// Event listener untuk checkbox stdin
box.querySelector(`#useStdin-${box.dataset.soalId}`).addEventListener('change', function() {
useStdin = this.checked;
});
});
});
</script>
</html>
<?php /**PATH C:\laragon\www\web_mudahcoding_2024\resources\views/web/dashboard_member/layouts/exam.blade.php ENDPATH**/ ?>
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]