From: soufiane Date: Thu, 4 Jan 2024 10:36:30 +0000 (+0100) Subject: wait #6482 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=710586f24b2c11abe9d2249a09a778e451b50740;p=fluidbook-toolbox.git wait #6482 --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php index a5fa018dc..cca8fdfae 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php @@ -302,48 +302,57 @@ trait LinksOperation $token = $request->token; $userId = backpack_user()->id; $unload = $request->unload; - /*cache()->forget('queue_editor'.$fluidbookId); + /* Reset * */ - if(!cache()->has('queue_editor'.$fluidbookId)) { - $entries = [$token => 'active']; + $entries = [$token]; cache(['queue_editor'.$fluidbookId => $entries]); } else { - $queueEditor = cache()->get('queue_editor'.$fluidbookId); - if(!array_key_exists($token, $queueEditor)) { - $queueEditor[$token] = 'is connected'; - } elseif(intval($unload) === 1) { - unset($queueEditor[$token]); + $queueEditor = cache()->get('queue_editor'.$fluidbookId); // on récupère la liste des onglets + $key = array_search($token, $queueEditor); + + if ((int)$unload === 1) { + unset($queueEditor[$key]); // on supprime l'onglet de la liste au chargement ou à sa fermeture } + if(!$key) { + $queueEditor[] = $token; + } + + $queueEditor = array_unique($queueEditor); + cache(['queue_editor'.$fluidbookId => $queueEditor]); } $connexionExist = cache()->get('connexion'.$fluidbookId); $queueEditor = cache()->get('queue_editor'.$fluidbookId); - $firstKey = array_key_first($queueEditor); - $queueEditor[$firstKey] = 'active'; - cache(['queue_editor'.$fluidbookId => $queueEditor]); - $queueEditor = cache()->get('queue_editor'.$fluidbookId); - // réinitialiser la connexion courante quand on clique sur "déconnecter l'utilisateur" if($request->clear) { - cache()->forget('connexion'.$fluidbookId); + $key = array_search($token, $queueEditor); + $queueEditor = array_slice($queueEditor, $key, 1); + $queueEditor = array_merge([$token],$queueEditor); + cache(['queue_editor'.$fluidbookId => $queueEditor]); + cache(['connexion' . $fluidbookId => ['id' => $userId, 'token' => $token, 'f_id' => $fluidbookId]]); } - if(sizeof(cache()->get('queue_editor'.$fluidbookId)) === 1) { - cache(['connexion'.$fluidbookId => ['id' => $userId, 'token' => $token,'f_id' => $fluidbookId] ]); - return json_encode(["queueEditor"=>$queueEditor,"status"=>"available",$connexionExist]); + /*cache()->forget('queue_editor'.$fluidbookId);*/ + /*cache()->forget('connexion'.$fluidbookId);*/ + + if(cache()->has('queue_editor'.$fluidbookId)) { + if (sizeof(cache()->get('queue_editor' . $fluidbookId)) === 1) { + cache(['connexion' . $fluidbookId => ['id' => $userId, 'token' => $token, 'f_id' => $fluidbookId]]); + return json_encode(["queueEditor" => $queueEditor, "status" => "available", $connexionExist]); + } } if($connexionExist && $fluidbookId === $connexionExist['f_id']) { $user = User::withoutGlobalScopes()->find($connexionExist['id']); $user = $user->firstname.' '.$user->lastname; - if(sizeof($queueEditor) > 1) { - return json_encode(["queueEditor"=>$queueEditor,"status"=>"unavailable","infos_connection"=>array_merge(["user" => $user],$connexionExist)]); + if(current($queueEditor) !== $token) { + return json_encode(["queueEditor"=>$queueEditor,"token"=>$token,"status"=>"unavailable","infos_connection"=>array_merge(["user" => $user],$connexionExist)]); } else { return json_encode(["queueEditor"=>$queueEditor,"status"=>"available",$connexionExist]); } diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index 060add822..259e641b1 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -577,17 +577,18 @@ $(function () { let interval = null let token = $("[data-token]").data("token") - function intervalConnection(data = {}) { + function intervalConnection(clear) { let unload = localStorage.getItem('unload') let token_ = localStorage.getItem('token') $.ajax({ method: "POST", url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/edit/links', - data: Object.keys(data).length > 0 ? data : {id: FLUIDBOOK_DATA.id, token: token_ ?? token, unload: unload} + data: {id: FLUIDBOOK_DATA.id, token: token_ ?? token, unload: unload, clear: clear} }).done(function (msg) { let response = JSON.parse(msg) - console.log(response.queueEditor) + console.log(response) + console.log(response.queueEditor, response.token) if (response.status === "unavailable" ) { if ($("#popup-overlay").find('.popup').length === 0) { $("#popup-overlay").addClass("show") @@ -625,7 +626,9 @@ $(function () { // $("body").on("click", "#connectTo", function(e) { e.preventDefault() - intervalConnection({id:FLUIDBOOK_DATA.id,token:token,clear:true}); + console.log('okkkkkkkkkkkkkk') + clearTimeout(interval) + intervalConnection("1"); }) //