diff --git a/app/Http/Controllers/TestSessionsController.php b/app/Http/Controllers/TestSessionsController.php index 3b01fee..f675950 100644 --- a/app/Http/Controllers/TestSessionsController.php +++ b/app/Http/Controllers/TestSessionsController.php @@ -7,6 +7,22 @@ class TestSessionsController extends Controller { + public function getScreen(Request $request) { + $data = TestSessionsModel::where('id_test_sessions', $request->id_test_sessions)->first(); + + if($data != null) { + return response()->json([ + 'status' => true, + 'screen_w' => $data->screen_w, + 'screen_h' => $data->screen_h + ]); + } else { + return response()->json([ + 'status' => false, + 'msg' => 'Data tidak ditemukan!' + ]); + } + } /** * Display a listing of the resource. */ @@ -36,6 +52,8 @@ public function store(Request $request) 'id_booking' => $request->id_booking, 'status_session' => '0', 'is_active' => '0', + 'screen_w' => $request->screen_w, + 'screen_h' => $request->screen_h ]); return redirect()->route('tutorial-tes.index')->with([ diff --git a/app/Models/TestSessionsModel.php b/app/Models/TestSessionsModel.php index d5c0cdf..6b3ec8e 100644 --- a/app/Models/TestSessionsModel.php +++ b/app/Models/TestSessionsModel.php @@ -21,6 +21,8 @@ class TestSessionsModel extends Model 'unix_start_time', 'is_active', 'unix_end_time', + 'screen_w', + 'screen_h' ]; protected $casts = [ diff --git a/database/migrations/2026_05_19_150903_add_column_in_test_sessions_table.php b/database/migrations/2026_05_19_150903_add_column_in_test_sessions_table.php new file mode 100644 index 0000000..56aeb80 --- /dev/null +++ b/database/migrations/2026_05_19_150903_add_column_in_test_sessions_table.php @@ -0,0 +1,30 @@ +char('screen_w', 20)->after('unix_end_time'); + $table->char('screen_h', 20)->after('screen_w'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('test_sessions', function (Blueprint $table) { + $table->dropColumn('screen_w'); + $table->dropColumn('screen_h'); + }); + } +}; diff --git a/resources/views/user/pages/cek_status/index.blade.php b/resources/views/user/pages/cek_status/index.blade.php index 39f667b..d9985dd 100644 --- a/resources/views/user/pages/cek_status/index.blade.php +++ b/resources/views/user/pages/cek_status/index.blade.php @@ -85,6 +85,8 @@
@csrf + +
@@ -259,6 +261,8 @@ function startSessionTest() { cancelButtonText: 'Nggak jadi deh' }).then((result) => { if(result.isConfirmed) { + $('#screen_w').val(window.screen.width); + $('#screen_h').val(window.screen.height); form.attr('action', url); form.submit(); } diff --git a/resources/views/user/pages/finish_ujian/index.blade.php b/resources/views/user/pages/finish_ujian/index.blade.php index fa5298a..4ec63bc 100644 --- a/resources/views/user/pages/finish_ujian/index.blade.php +++ b/resources/views/user/pages/finish_ujian/index.blade.php @@ -79,6 +79,8 @@ let heatmapContainer = null; let clientWidth = null; let clientHeight = null; + let recordedScreenWidth = null + let recordedScreenHeight = null let mappedHeatmapData = null; let scaleX = null; let scaleY = null; @@ -188,6 +190,14 @@ function renderVelocityChart(timeseries) { ws.onopen = () => { console.log("Connected to WebSocket"); + Swal.fire({ + title: 'Status', + text: 'Memuat data...', + icon: 'info', + showConfirmButton: false, + allowOutsideClick: false, + allowEscapeKey: false + }); ws.send(JSON.stringify({ type: 'get_json_file', @@ -199,20 +209,43 @@ function renderVelocityChart(timeseries) { if(data.type === 'json_file_data') { if(data.data != null) { data_tobii = data.data; + let xhttp = new XMLHttpRequest(); - heatmapContainer = document.getElementById('heatmapChart'); - clientWidth = heatmapContainer.clientWidth; - clientHeight = heatmapContainer.clientHeight; - scaleX = clientWidth / 1366; - scaleY = clientHeight / 768; - - heatmapInstance = h337.create({ - container: heatmapContainer, - radius: 40, - maxOpacity: 0.6, - blur: 0.85 - }); - loadData(data_tobii); + xhttp.onreadystatechange = function() { + if(this.readyState == 4 && this.status == 200) { + let data = JSON.parse(this.responseText); + if(data.status) { + heatmapContainer = document.getElementById('heatmapChart'); + clientWidth = heatmapContainer.clientWidth; + clientHeight = heatmapContainer.clientHeight; + recordedScreenWidth = data.screen_w; + recordedScreenHeight = data.screen_h; + scaleX = clientWidth / recordedScreenWidth; + scaleY = clientHeight / recordedScreenHeight; + + heatmapInstance = h337.create({ + container: heatmapContainer, + radius: 40, + maxOpacity: 0.6, + blur: 0.85 + }); + Swal.close(); + loadData(data_tobii); + } else { + Swal.fire({ + title: 'Error', + text: 'Gagal mencari data, silahkan coba lagi nanti', + icon: 'error', + showConfirmButton: true, + allowOutsideClick: false, + allowEscapeKey: false + }); + } + } + }; + + xhttp.open('GET', '{{ route('test-sessions.getScreen', ['id_test_sessions', $id_session]) }}', true); + xhttp.send(); } } }; diff --git a/routes/web.php b/routes/web.php index acd6a34..8a930a0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,6 +36,7 @@ Route::resource('cek-status', CekStatusController::class)->only(['index', 'show']); Route::resource('tutorial-tes', TutorialTesController::class)->only(['index']); Route::resource('test-sessions', TestSessionsController::class)->only(['store', 'show']); + Route::get('test-sessions/get/screen', [TestSessionsController::class, 'getScreen'])->name('test-sessions.getScreen');; 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);