From fdda679141c813be11708225a745fb184a4d52d4 Mon Sep 17 00:00:00 2001 From: Mahayoga Date: Tue, 28 Apr 2026 13:58:04 +0700 Subject: [PATCH] WIP: halaman ujian --- .../Controllers/HalamanUjianController.php | 107 +++++++++++++ ..._26_174728_change_column_in_soal_table.php | 28 ++++ .../user/layouts/test_layout/index.blade.php | 4 +- .../user/pages/tutorial_tes/index.blade.php | 54 +++++-- .../views/user/pages/ujian/index.blade.php | 146 ++++++++++++++++++ routes/web.php | 2 + 6 files changed, 323 insertions(+), 18 deletions(-) create mode 100644 app/Http/Controllers/HalamanUjianController.php create mode 100644 database/migrations/2026_04_26_174728_change_column_in_soal_table.php create mode 100644 resources/views/user/pages/ujian/index.blade.php diff --git a/app/Http/Controllers/HalamanUjianController.php b/app/Http/Controllers/HalamanUjianController.php new file mode 100644 index 0000000..0bc89dc --- /dev/null +++ b/app/Http/Controllers/HalamanUjianController.php @@ -0,0 +1,107 @@ +id_test_sessions != null) { + $id_session = $request->id_test_sessions; + } else { + return redirect()->route('cek-status.index')->with('error', 'Data sesi tes tidak ditemukan. Silakan mulai tes terlebih dahulu.'); + } + + $data_session = TestSessionsModel::where('id_test_sessions', $id_session)->first(); + if($data_session != null) { + if($data_session->status_session != '1') { + return redirect()->route('cek-status.index')->with('error', 'Data sesi tes belum dimulai atau telah usai. Silahkan cek status dengan kode untuk informasi lebih lanjut.'); + } + } else { + return redirect()->route('cek-status.index')->with('error', 'Data sesi tes tidak ditemukan. Silakan mulai tes terlebih dahulu.'); + } + + $question_number = null; + $data_question = null; + if(session('question') != null) { + $question_number = session('question'); + } else if($request->question != null) { + $question_number = $request->question; + } else { + $question_number = 1; + } + + $data_question = DataSoalModel::all(); + $total_question = null; + $is_last_question = false; + if($question_number <= 0 || $question_number > count($data_question)) { + $question_number = 1; + } + if(count($data_question) == $question_number) { + $is_last_question = true; + } + $total_question = count($data_question); + $data_question = $data_question[$question_number - 1]; + + return view("user.pages.ujian.index", compact('data_session', 'data_question', 'total_question', 'is_last_question', 'question_number')); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/database/migrations/2026_04_26_174728_change_column_in_soal_table.php b/database/migrations/2026_04_26_174728_change_column_in_soal_table.php new file mode 100644 index 0000000..08d9e41 --- /dev/null +++ b/database/migrations/2026_04_26_174728_change_column_in_soal_table.php @@ -0,0 +1,28 @@ +text('pertanyaan')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('soal', function (Blueprint $table) { + $table->string('pertanyaan', 255)->change(); + }); + } +}; diff --git a/resources/views/user/layouts/test_layout/index.blade.php b/resources/views/user/layouts/test_layout/index.blade.php index dce7425..2a54072 100644 --- a/resources/views/user/layouts/test_layout/index.blade.php +++ b/resources/views/user/layouts/test_layout/index.blade.php @@ -40,11 +40,11 @@ ======================================================== --> - + {{-- @include('user.layouts.navbar') --}} -
+
@yield('content') diff --git a/resources/views/user/pages/tutorial_tes/index.blade.php b/resources/views/user/pages/tutorial_tes/index.blade.php index df1b854..912200b 100644 --- a/resources/views/user/pages/tutorial_tes/index.blade.php +++ b/resources/views/user/pages/tutorial_tes/index.blade.php @@ -1,4 +1,6 @@ @section('title', 'Tutorial Test Kecemasan') +@section('body_status_overflow', 'overflow: hidden;') +@section('main_style', 'width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center;') @extends('user.layouts.test_layout.index') @section('content')
@@ -73,7 +75,7 @@ - Mulai Ujian + Mulai Ujian
@@ -147,7 +149,8 @@ function showTutorial(step, tutorialId) { $(`#${tutorialId}`).hide(); $(`#tutorial_${step}`).show(); - if(step === 2) { + if(step === 2 || step === 3) { + startTobii(); checkTobiiInterval = setInterval(() => { checkTobiiConnection(); }, 2000); @@ -155,26 +158,18 @@ function showTutorial(step, tutorialId) { if(checkTobiiInterval) { clearInterval(checkTobiiInterval); } + stopTobii(); } if(step === 3) { $('#calibration_point').show(); + let test_url = '{{ route('ujian.index', ['id_test_sessions' => '__ID_TEST_SESSIONS__']) }}'; + $('#start_ujian').attr('href', test_url.replace('__ID_TEST_SESSIONS__', SESSION_ID)); } else { $('#calibration_point').hide(); } } - async function startPolling() { - while(getDataInterval) { - await fetchDataTobii(); - await delay(300); - } - } - - function delay(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); - } - function hidePanelTutorial(btn) { const status = $(btn).attr('data-status'); if (status === 'hide') { @@ -288,8 +283,8 @@ function copyLinkTokenTobii() { function checkTobiiConnection() { ws.send(JSON.stringify({ - type: "check_temp_data", - id_session: SESSION_ID + type: "check_tobii_connection", + session_id: SESSION_ID, })); if(tobiiConnectedStatus) { @@ -314,6 +309,22 @@ function checkTobiiConnection() { } } + function startTobii() { + ws.send(JSON.stringify({ + type: "command", + action: "start", + session_id: SESSION_ID + })); + } + + function stopTobii() { + ws.send(JSON.stringify({ + type: "command", + action: "stop", + session_id: SESSION_ID + })); + } + $(document).ready(function() { $('#tutorial_2').hide(); $('#tutorial_3').hide(); @@ -352,13 +363,24 @@ function checkTobiiConnection() { // } if(data.type === 'tobii_data') { - console.log('Tobii data not active:', data); try { moveTheEye(data.gaze_x, data.gaze_y); } catch(error) { console.log(error); } } + + // if(data.type === 'status_tobii') { + // if(data.status) { + // tobiiConnectedStatus = true; + // } else if(!data.status) { + // tobiiConnectedStatus = false; + // } + // } + + if(data.type === 'reset_start_tobii') { + startTobii(); + } }; }); diff --git a/resources/views/user/pages/ujian/index.blade.php b/resources/views/user/pages/ujian/index.blade.php new file mode 100644 index 0000000..9a5d584 --- /dev/null +++ b/resources/views/user/pages/ujian/index.blade.php @@ -0,0 +1,146 @@ +@section('title', 'Ujian Kecemasan') +{{-- @section('body_status_overflow', 'overflow: hidden;') --}} +@section('main_style', 'min-height: 100vh;') +@extends('user.layouts.test_layout.index') +@section('content') +
+ + +
+
+
+
+
Soal
+
{{ $data_question->pertanyaan }}
+
+
Jawaban:
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
Navigasi Soal
+ @for ($i = 0; $i < $total_question; $i++) +
{{ $i + 1 }}
+ @endfor + +
+ @if ($question_number > 1) +
Previous
+ @endif + + @if ($is_last_question) +
Finish
+ @else +
Next
+ @endif +
+
+
+
+
+
+@endsection + +@section('script') + +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 74c250d..414fa24 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use App\Http\Controllers\CekStatusController; use App\Http\Controllers\DashboardController; use App\Http\Controllers\DataSoalController; +use App\Http\Controllers\HalamanUjianController; use App\Http\Controllers\HasilTesController; use App\Http\Controllers\LandingController; use App\Http\Controllers\ProfileController; @@ -36,6 +37,7 @@ Route::resource('test-sessions', TestSessionsController::class)->only(['store', 'show']); Route::resource('tobii-receiver', TobiiReceiverController::class)->only(['store', 'show']); Route::get('tobii-receiver/fetch/data/{id_test_sessions}', [TobiiReceiverController::class, 'fetchDataTobii'])->name('tobii-receiver.fetchData'); +Route::resource('ujian', HalamanUjianController::class); Route::middleware(['auth', 'role.auth'])->group(function() { Route::resource('dashboard', DashboardController::class); Route::resource('users', UsersController::class);