From b5a60b5bfbb7b500770a23d7187832e36f5f87d4 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Wed, 17 Apr 2024 11:33:32 +0200 Subject: [PATCH] fix: [analyst-data:thread] Only render the HTML when opening the popover --- app/View/AnalystData/view.ctp | 50 ++++++++++++- .../genericElements/Analyst_data/generic.ctp | 14 +--- .../genericElements/Analyst_data/thread.ctp | 75 ++++++++++++------- app/View/GalaxyClusters/view.ctp | 50 ++++++++++++- 4 files changed, 139 insertions(+), 50 deletions(-) diff --git a/app/View/AnalystData/view.ctp b/app/View/AnalystData/view.ctp index f56460e7a..c9715d63f 100644 --- a/app/View/AnalystData/view.ctp +++ b/app/View/AnalystData/view.ctp @@ -120,15 +120,57 @@ echo $this->element( ); $object_uuid = Hash::get($data, $modelSelection . '.uuid'); + +$notes = $data[$modelSelection]['Note'] ?? []; +$opinions = $data[$modelSelection]['Opinion'] ?? []; +$relationships_outbound = $data[$modelSelection]['Relationship'] ?? []; +$relationships_inbound = $data[$modelSelection]['RelationshipInbound'] ?? []; +$notesOpinions = array_merge($notes, $opinions); +if(!function_exists("countNotes")) { + function countNotes($notesOpinions) { + $notesTotalCount = count($notesOpinions); + $notesCount = 0; + $relationsCount = 0; + foreach ($notesOpinions as $notesOpinion) { + if ($notesOpinion['note_type'] == 2) { // relationship + $relationsCount += 1; + } else { + $notesCount += 1; + } + if (!empty($notesOpinion['Note'])) { + $nestedCounts = countNotes($notesOpinion['Note']); + $notesTotalCount += $nestedCounts['total']; + $notesCount += $nestedCounts['notesOpinions']; + $relationsCount += $nestedCounts['relations']; + } + if (!empty($notesOpinion['Opinion'])) { + $nestedCounts = countNotes($notesOpinion['Opinion']); + $notesTotalCount += $nestedCounts['total']; + $notesCount += $nestedCounts['notesOpinions']; + $relationsCount += $nestedCounts['relations']; + } + } + return ['total' => $notesTotalCount, 'notesOpinions' => $notesCount, 'relations' => $relationsCount]; + } +} +$counts = countNotes($notesOpinions); +$notesOpinionCount = $counts['notesOpinions']; +$allCounts = [ + 'notesOpinions' => $counts['notesOpinions'], + 'relationships_outbound' => count($relationships_outbound), + 'relationships_inbound' => count($relationships_inbound), +]; + $options = [ 'container_id' => 'analyst_data_thread', 'object_type' => $modelSelection, 'object_uuid' => $object_uuid, 'shortDist' => $shortDist, - 'notes' => $data[$modelSelection]['Note'] ?? [], - 'opinions' => $data[$modelSelection]['Opinion'] ?? [], - 'relationships_outbound' => $data[$modelSelection]['Relationship'] ?? [], - 'relationships_inbound' => $data[$modelSelection]['RelationshipInbound'] ?? [], + 'notes' => $notes, + 'opinions' => $opinions, + 'relationships_outbound' => $relationships_outbound, + 'relationships_inbound' => $relationships_inbound, + 'allCounts' => $allCounts, ]; echo $this->element('genericElements/assetLoader', [ diff --git a/app/View/Elements/genericElements/Analyst_data/generic.ctp b/app/View/Elements/genericElements/Analyst_data/generic.ctp index 2ccdc4eb0..acbfae91a 100644 --- a/app/View/Elements/genericElements/Analyst_data/generic.ctp +++ b/app/View/Elements/genericElements/Analyst_data/generic.ctp @@ -65,20 +65,8 @@ $allCounts = [ $(document).ready(function() { $('.node-opener-').click(function() { - openNotes(this) + openNotes(this) }) - - function adjustPopoverPosition() { - var $popover = $('.popover:last'); - $popover.css('top', Math.max($popover.position().top, 50) + 'px') - } - - function openNotes(clicked) { - openPopover(clicked, renderedNotes, undefined, undefined, function() { - adjustPopoverPosition() - $(clicked).removeClass('have-a-popover') // avoid closing the popover if a confirm popover (like the delete one) is called - }) - } }) diff --git a/app/View/Elements/genericElements/Analyst_data/thread.ctp b/app/View/Elements/genericElements/Analyst_data/thread.ctp index 5930f6c5d..bad0a3b8d 100644 --- a/app/View/Elements/genericElements/Analyst_data/thread.ctp +++ b/app/View/Elements/genericElements/Analyst_data/thread.ctp @@ -4,6 +4,7 @@ $URL_DELETE = '/analystData/delete/'; $seed = isset($seed) ? $seed : mt_rand(); + $injectInPage = !empty($container_id) ? true : false; $notes = !empty($notes) ? $notes : []; $opinions = !empty($opinions) ? $opinions : []; @@ -41,7 +42,28 @@ if (!window.shortDist) { var shortDist = ; } -var renderedNotes = null + +var container_id = false + + container_id = '' + + +function adjustPopoverPosition() { + var $popover = $('.popover:last'); + $popover.css('top', Math.max($popover.position().top, 50) + 'px') +} + +function openNotes(clicked) { + var notes = ; + var relationships = ; + var relationships_inbound = ; + var relationship_related_object = ; + var renderedNotes = renderAllNotesWithForm(notes, relationships, relationships_inbound, relationship_related_object) + openPopover(clicked, renderedNotes, undefined, undefined, function() { + adjustPopoverPosition() + $(clicked).removeClass('have-a-popover') // avoid closing the popover if a confirm popover (like the delete one) is called + }) +} function renderNotes(notes, relationship_related_object, emptyMessage='', isInbound=false) { var renderedNotesArray = [] @@ -406,18 +428,7 @@ function fetchMoreNotes(clicked, noteType, uuid) { } - -(function() { - var notes = ; - var relationships = ; - var relationships_inbound = ; - var relationship_related_object = ; - var container_id = false - - container_id = '' - - - var nodeContainerTemplate = doT.template('\ + var nodeContainerTemplate = doT.template('\
\
\ ') - function renderAllNotesWithForm(relationship_related_object) { - var buttonContainer = '
' + addNoteButton + addOpinionButton + '
' - renderedNotes = nodeContainerTemplate({ - content_notes: renderNotes(notes.filter(function(note) { return note.note_type != 2}), relationship_related_object, '') + buttonContainer, - content_relationships_outbound: renderNotes(relationships, relationship_related_object, '') + addRelationshipButton, - content_relationships_inbound: renderNotes(relationships_inbound, relationship_related_object, '', true), - }) - if (container_id) { - $('#' + container_id).html(renderedNotes) - } - } - var addNoteButton = '' @@ -461,10 +460,15 @@ function fetchMoreNotes(clicked, noteType, uuid) { \ ' - $(document).ready(function() { - renderAllNotesWithForm(relationship_related_object) - }) -})() + function renderAllNotesWithForm(notes, relationships, relationships_inbound, relationship_related_object) { + var buttonContainer = '
' + addNoteButton + addOpinionButton + '
' + var renderedNotes = nodeContainerTemplate({ + content_notes: renderNotes(notes.filter(function(note) { return note.note_type != 2}), relationship_related_object, '') + buttonContainer, + content_relationships_outbound: renderNotes(relationships, relationship_related_object, '') + addRelationshipButton, + content_relationships_inbound: renderNotes(relationships_inbound, relationship_related_object, '', true), + }) + return renderedNotes + } function createNewNote(clicked, object_type, object_uuid) { note_type = 'Note'; @@ -516,6 +520,19 @@ function fetchMoreNotes(clicked, noteType, uuid) { } } + + $(document).ready(function() { + var notes = ; + var relationships = ; + var relationships_inbound = ; + var relationship_related_object = ; + var renderedNotes = renderAllNotesWithForm(notes, relationships, relationships_inbound, relationship_related_object) + if (container_id) { + $('#' + container_id).html(renderedNotes) + } + }) + +