Masih WIP bagian connect tobii
This commit is contained in:
parent
5ea079e470
commit
3711b59d70
|
|
@ -35,6 +35,7 @@ public function store(Request $request)
|
|||
$testSession = TestSessionsModel::create([
|
||||
'id_booking' => $request->id_booking,
|
||||
'status_session' => '0',
|
||||
'is_active' => '0',
|
||||
]);
|
||||
|
||||
return redirect()->route('tutorial-tes.index')->with([
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TobiiDataController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\TestSessionsModel;
|
||||
use App\Models\TobiiDataModel;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TobiiReceiverController extends Controller
|
||||
|
|
@ -28,17 +29,35 @@ public function create()
|
|||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data_sessions = TestSessionsModel::where('id_test_sessions', $request->id_test_sessions)->first();
|
||||
if($data_sessions != null) {
|
||||
if($request->token_session == $data_sessions->token_session) {
|
||||
// simpan data tobii ke db
|
||||
|
||||
return response()->json(['message' => 'Data tobii berhasil disimpan.'], 200);
|
||||
try {
|
||||
$data_sessions = TestSessionsModel::where('id_test_sessions', $request->id_test_sessions)->first();
|
||||
if($data_sessions != null) {
|
||||
if($request->token_session == $data_sessions->token_session) {
|
||||
if($data_sessions->status_session == '1') {
|
||||
$is_valid = '0';
|
||||
if($data_sessions->is_active == '1') {
|
||||
$is_valid = '1';
|
||||
}
|
||||
// simpan data tobii ke db
|
||||
$data_tobii = TobiiDataModel::create([
|
||||
'gaze_x' => $request->gaze_x,
|
||||
'gaze_y' => $request->gaze_y,
|
||||
'timestamp' => now(),
|
||||
'is_valid' => $is_valid,
|
||||
'id_test_sessions' => $request->id_test_sessions,
|
||||
]);
|
||||
return response()->json(['message' => 'Data tobii berhasil disimpan.'], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Sesi tes belum aktif.'], 403);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => 'Token sesi tidak valid.'], 401);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => 'Token sesi tidak valid.'], 401);
|
||||
return response()->json(['message' => 'Data sesi tes tidak ditemukan.'], 404);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => 'Data sesi tes tidak ditemukan.'], 404);
|
||||
} catch(\Exception $e) {
|
||||
return response()->json(['message' => 'Terjadi kesalahan saat menyimpan data tobii.', 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +66,20 @@ public function store(Request $request)
|
|||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
$data_tobii = TobiiDataModel::where('id_test_sessions', $id)->latest()->first();
|
||||
if ($data_tobii->timestamp->lt(now()->subSeconds(5))) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'msg' => 'Data tobii kadaluarsa (' . $id . ')',
|
||||
'connected' => false,
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'connected' => true,
|
||||
'msg' => 'Data tobii ditemukan (' . $id . ')',
|
||||
'data_tobii' => $data_tobii,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ class TestSessionsModel extends Model
|
|||
protected $fillable = [
|
||||
'status_session',
|
||||
'token_session',
|
||||
'id_booking'
|
||||
'id_booking',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
|
@ -36,6 +37,10 @@ protected static function boot()
|
|||
if (empty($model->token_session)) {
|
||||
$model->token_session = \Illuminate\Support\Str::random(50);
|
||||
}
|
||||
|
||||
if (empty($model->is_active)) {
|
||||
$model->is_active = '0';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TobiiDataModel extends Model
|
||||
{
|
||||
protected $table = 'tobii_data';
|
||||
|
||||
protected $primaryKey = 'id_tobii_data';
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = [
|
||||
'id_tobii_data',
|
||||
'gaze_x',
|
||||
'gaze_y',
|
||||
'timestamp',
|
||||
'id_test_sessions',
|
||||
'is_valid',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id_tobii_data' => 'string',
|
||||
'gaze_x' => 'float',
|
||||
'gaze_y' => 'float',
|
||||
'timestamp' => 'datetime',
|
||||
'id_test_sessions' => 'string',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
if (empty($model->id_tobii_data)) {
|
||||
$model->id_tobii_data = (string) \Illuminate\Support\Str::uuid();
|
||||
}
|
||||
if (empty($model->is_valid)) {
|
||||
$model->is_valid = '0';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?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::create('tobii_data', function (Blueprint $table) {
|
||||
$table->uuid('id_tobii_data')->primary();
|
||||
$table->string('gaze_x')->nullable()->default(0);
|
||||
$table->string('gaze_y')->nullable()->default(0);
|
||||
$table->string('timestamp');
|
||||
$table->uuid('id_test_sessions');
|
||||
$table->timestamps();
|
||||
|
||||
// Foreign key constraint
|
||||
$table->foreign('id_test_sessions')->references('id_test_sessions')->on('test_sessions')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tobii_data');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?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('test_sessions', function (Blueprint $table) {
|
||||
$table->string('is_active')->default('0')->after('token_session');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('test_sessions', function (Blueprint $table) {
|
||||
$table->dropColumn('is_active');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?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('tobii_data', function (Blueprint $table) {
|
||||
$table->enum('is_valid', ['0', '1'])->default('0')->after('timestamp');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tobii_data', function (Blueprint $table) {
|
||||
$table->dropColumn('is_valid');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -47,14 +47,22 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8" id="tutorial_3">
|
||||
<div class="card shadow-sm border-0">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title fw-bold mb-4">Tes Keakuratan Mata</h3>
|
||||
<p class="card-text mb-3">Sebelum tes dimulai, cek keakuratan device Tobii anda, jika tidak akurat, lakukan kalibrasi kepada administrator.</p>
|
||||
<button class="btn btn-primary" id="back_btn" onclick="showTutorial(2, 'tutorial_2')">Back</button>
|
||||
<a class="btn btn-primary">Mulai Ujian</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('script')
|
||||
<script>
|
||||
$('#tutorial_2').hide();
|
||||
$('#next_btn_connect_tobii').hide();
|
||||
function showTutorial(step, tutorialId) {
|
||||
$(`#${tutorialId}`).hide();
|
||||
$(`#tutorial_${step}`).show();
|
||||
|
|
@ -85,8 +93,34 @@ function copyLinkApiTobii() {
|
|||
});
|
||||
}
|
||||
|
||||
function checkTobiiConnection() {
|
||||
$.ajax({
|
||||
url: '{{ route("tobii-receiver.show", ['tobii_receiver' => $data_session->id_test_sessions]) }}',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
if (response.connected) {
|
||||
$('#status_tobii').text('Status Tobii: Terhubung').removeClass('text-danger').addClass('text-success');
|
||||
$('#next_btn_connect_tobii').show();
|
||||
} else {
|
||||
$('#status_tobii').text('Status Tobii: Tidak Terhubung').removeClass('text-success').addClass('text-danger');
|
||||
$('#next_btn_connect_tobii').hide();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#status_tobii').text('Status Tobii: Tidak Terhubung').removeClass('text-success').addClass('text-danger');
|
||||
$('#next_btn_connect_tobii').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#tutorial_2').hide();
|
||||
$('#next_btn_connect_tobii').hide();
|
||||
generateLinkApiTobii();
|
||||
|
||||
setInterval(() => {
|
||||
checkTobiiConnection();
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,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::resource('tobii-receiver', TobiiReceiverController::class)->only(['store']);
|
||||
Route::resource('tobii-receiver', TobiiReceiverController::class)->only(['store', 'show']);
|
||||
Route::middleware(['auth', 'role.auth'])->group(function() {
|
||||
Route::resource('dashboard', DashboardController::class);
|
||||
Route::resource('users', UsersController::class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue