]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6482
authorsoufiane <soufiane@cubedesigners.com>
Thu, 4 Jan 2024 10:36:30 +0000 (11:36 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 4 Jan 2024 10:36:30 +0000 (11:36 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
resources/linkeditor/js/linkeditor.js

index a5fa018dcb7c1decfc7ed16f8b6d1abc01b940db..cca8fdfae3e369563a92ee5c351ec0e21f07fde3 100644 (file)
@@ -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]);
             }
index 060add822c624697bd730536a2b8c3616ce5c89b..259e641b19b082afad8ca8b9d5d0976e998aa372 100644 (file)
@@ -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");
     })
 
     //