WIP: halaman finish ujian

This commit is contained in:
Mahayoga 2026-05-04 11:04:29 +07:00
parent f18c470f14
commit b1f5b14287
3 changed files with 108 additions and 39 deletions

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('soal', function (Blueprint $table) {
$table->string('jawaban_a')->nullable()->change();
$table->string('jawaban_b')->nullable()->change();
$table->string('jawaban_c')->nullable()->change();
$table->string('jawaban_d')->nullable()->change();
$table->string('jawaban_e')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('soal', function (Blueprint $table) {
$table->string('jawaban_a')->change();
$table->string('jawaban_b')->change();
$table->string('jawaban_c')->change();
$table->string('jawaban_d')->change();
$table->string('jawaban_e')->change();
});
}
};

View File

@ -140,7 +140,7 @@
<script>
let getDataInterval = false;
let checkTobiiInterval = null;
let tobiiConnectedStatus = true;
let tobiiConnectedStatus = false;
const ws = new WebSocket('{{ env("WEBSOCKET_URL") }}');
let SESSION_ID = '{{ $data_session->id_test_sessions }}';
let TOKEN_SESSION = '{{ $data_session->token_session }}';
@ -151,9 +151,10 @@ function showTutorial(step, tutorialId) {
if(step === 2 || step === 3) {
startTobii();
checkTobiiInterval = setInterval(() => {
checkTobiiConnection();
}, 2000);
checkTobiiConnection();
// checkTobiiInterval = setInterval(() => {
// checkTobiiConnection();
// }, 2000);
} else {
if(checkTobiiInterval) {
clearInterval(checkTobiiInterval);
@ -282,10 +283,10 @@ function copyLinkTokenTobii() {
}
function checkTobiiConnection() {
ws.send(JSON.stringify({
type: "check_tobii_connection",
session_id: SESSION_ID,
}));
// ws.send(JSON.stringify({
// type: "check_tobii_connection",
// session_id: SESSION_ID,
// }));
if(tobiiConnectedStatus) {
$('#status_tobii').text('Status Tobii: Terhubung').removeClass('text-danger').addClass('text-success');
@ -353,15 +354,6 @@ function stopTobii() {
const data = JSON.parse(event.data);
console.log('Received data from WebSocket:', data);
// if(data.type === 'temp_data') {
// console.log('Received temp_data:', data);
// if((Date.now() - data.data[0].timestamp) < 5000) {
// tobiiConnectedStatus = true;
// } else {
// tobiiConnectedStatus = false;
// }
// }
if(data.type === 'tobii_data') {
try {
moveTheEye(data.gaze_x, data.gaze_y);
@ -370,13 +362,16 @@ function stopTobii() {
}
}
// if(data.type === 'status_tobii') {
// if(data.status) {
// tobiiConnectedStatus = true;
// } else if(!data.status) {
// tobiiConnectedStatus = false;
// }
// }
if(data.type === 'status_tobii_device') {
if(data.status) {
console.log('Tobii device is connected');
tobiiConnectedStatus = true;
} else {
console.log('Tobii device is not connected');
tobiiConnectedStatus = false;
}
checkTobiiConnection();
}
if(data.type === 'reset_start_tobii') {
startTobii();

View File

@ -180,23 +180,61 @@ function updateTimeLeft() {
}
function finishExam() {
ws.send(JSON.stringify({
type: "command",
action: "stop",
session_id: SESSION_ID
}));
Swal.fire({
title: 'Alert',
icon: 'question',
text: 'Apakah Anda yakin ingin mengakhiri ujian? (aksi tidak dapat dikembalikan)',
confirmButtonText: 'Ya',
cancelButtonText: 'Tidak',
showCancelButton: true,
showCloseButton: true,
//send_data_to_db
ws.send(JSON.stringify({
type: "send_data_to_db",
session_id: SESSION_ID
}));
}).then((result) => {
if (result.isConfirmed) {
event.preventDefault();
let current_num = new URLSearchParams(window.location.search).get('question');
let xhttp = new XMLHttpRequest();
let the_answer = null;
let token = document.getElementById('_token').getAttribute('value');
let formData = new FormData();
ws.send(JSON.stringify({
type: "update_status",
status_sessions: false,
session_id: SESSION_ID
}));
document.getElementsByName('jawaban_final').forEach(element => {
if (element.checked) {
the_answer = {
key: element.id.split('_')[1],
};
}
});
if(the_answer) {
formData.append('jawaban_final', the_answer.key);
formData.append('_token', token);
formData.append('question', current_num);
formData.append('id_question', $('#id_question').attr('value'));
formData.append('session_id', SESSION_ID);
xhttp.open("POST", "{{ route('ujian.store') }}", false);
xhttp.send(formData);
console.log("sending answer (finish)");
}
ws.send(JSON.stringify({
type: "command",
action: "stop",
session_id: SESSION_ID
}));
//send_data_to_db
ws.send(JSON.stringify({
type: "send_data_to_db",
session_id: SESSION_ID
}));
ws.send(JSON.stringify({
type: "update_status",
status_sessions: false,
session_id: SESSION_ID
}));
}
});
}
function startTobii() {