mirror of https://github.com/MISP/MISP
fix: [analyst-data:thread] Only render the HTML when opening the popover
parent
8934982ff2
commit
b5a60b5bfb
|
@ -120,15 +120,57 @@ echo $this->element(
|
||||||
);
|
);
|
||||||
|
|
||||||
$object_uuid = Hash::get($data, $modelSelection . '.uuid');
|
$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 = [
|
$options = [
|
||||||
'container_id' => 'analyst_data_thread',
|
'container_id' => 'analyst_data_thread',
|
||||||
'object_type' => $modelSelection,
|
'object_type' => $modelSelection,
|
||||||
'object_uuid' => $object_uuid,
|
'object_uuid' => $object_uuid,
|
||||||
'shortDist' => $shortDist,
|
'shortDist' => $shortDist,
|
||||||
'notes' => $data[$modelSelection]['Note'] ?? [],
|
'notes' => $notes,
|
||||||
'opinions' => $data[$modelSelection]['Opinion'] ?? [],
|
'opinions' => $opinions,
|
||||||
'relationships_outbound' => $data[$modelSelection]['Relationship'] ?? [],
|
'relationships_outbound' => $relationships_outbound,
|
||||||
'relationships_inbound' => $data[$modelSelection]['RelationshipInbound'] ?? [],
|
'relationships_inbound' => $relationships_inbound,
|
||||||
|
'allCounts' => $allCounts,
|
||||||
];
|
];
|
||||||
|
|
||||||
echo $this->element('genericElements/assetLoader', [
|
echo $this->element('genericElements/assetLoader', [
|
||||||
|
|
|
@ -65,20 +65,8 @@ $allCounts = [
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.node-opener-<?= $seed ?>').click(function() {
|
$('.node-opener-<?= $seed ?>').click(function() {
|
||||||
openNotes(this)
|
openNotes<?= $seed ?>(this)
|
||||||
})
|
})
|
||||||
|
|
||||||
function adjustPopoverPosition() {
|
|
||||||
var $popover = $('.popover:last');
|
|
||||||
$popover.css('top', Math.max($popover.position().top, 50) + 'px')
|
|
||||||
}
|
|
||||||
|
|
||||||
function openNotes(clicked) {
|
|
||||||
openPopover(clicked, renderedNotes<?= $seed ?>, undefined, undefined, function() {
|
|
||||||
adjustPopoverPosition()
|
|
||||||
$(clicked).removeClass('have-a-popover') // avoid closing the popover if a confirm popover (like the delete one) is called
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
$URL_DELETE = '/analystData/delete/';
|
$URL_DELETE = '/analystData/delete/';
|
||||||
|
|
||||||
$seed = isset($seed) ? $seed : mt_rand();
|
$seed = isset($seed) ? $seed : mt_rand();
|
||||||
|
$injectInPage = !empty($container_id) ? true : false;
|
||||||
|
|
||||||
$notes = !empty($notes) ? $notes : [];
|
$notes = !empty($notes) ? $notes : [];
|
||||||
$opinions = !empty($opinions) ? $opinions : [];
|
$opinions = !empty($opinions) ? $opinions : [];
|
||||||
|
@ -41,7 +42,28 @@
|
||||||
if (!window.shortDist) {
|
if (!window.shortDist) {
|
||||||
var shortDist = <?= json_encode($shortDist) ?>;
|
var shortDist = <?= json_encode($shortDist) ?>;
|
||||||
}
|
}
|
||||||
var renderedNotes<?= $seed ?> = null
|
|
||||||
|
var container_id = false
|
||||||
|
<?php if (isset($container_id)): ?>
|
||||||
|
container_id = '<?= h($container_id) ?>'
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
function adjustPopoverPosition() {
|
||||||
|
var $popover = $('.popover:last');
|
||||||
|
$popover.css('top', Math.max($popover.position().top, 50) + 'px')
|
||||||
|
}
|
||||||
|
|
||||||
|
function openNotes<?= $seed ?>(clicked) {
|
||||||
|
var notes = <?= json_encode($notesOpinions) ?>;
|
||||||
|
var relationships = <?= json_encode($relationshipsOutbound) ?>;
|
||||||
|
var relationships_inbound = <?= json_encode($relationshipsInbound) ?>;
|
||||||
|
var relationship_related_object = <?= json_encode($related_objects) ?>;
|
||||||
|
var renderedNotes = renderAllNotesWithForm<?= $seed ?>(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='<?= __('Empty') ?>', isInbound=false) {
|
function renderNotes(notes, relationship_related_object, emptyMessage='<?= __('Empty') ?>', isInbound=false) {
|
||||||
var renderedNotesArray = []
|
var renderedNotesArray = []
|
||||||
|
@ -406,18 +428,7 @@ function fetchMoreNotes(clicked, noteType, uuid) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nodeContainerTemplate<?= $seed ?> = doT.template('\
|
||||||
(function() {
|
|
||||||
var notes = <?= json_encode($notesOpinions) ?>;
|
|
||||||
var relationships = <?= json_encode($relationshipsOutbound) ?>;
|
|
||||||
var relationships_inbound = <?= json_encode($relationshipsInbound) ?>;
|
|
||||||
var relationship_related_object = <?= json_encode($related_objects) ?>;
|
|
||||||
var container_id = false
|
|
||||||
<?php if (isset($container_id)): ?>
|
|
||||||
container_id = '<?= h($container_id) ?>'
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
var nodeContainerTemplate = doT.template('\
|
|
||||||
<div> \
|
<div> \
|
||||||
<ul class="nav nav-tabs" style="margin-bottom: 10px;"> \
|
<ul class="nav nav-tabs" style="margin-bottom: 10px;"> \
|
||||||
<li class="active"><a href="#notes-<?= $seed ?>" data-toggle="tab"><i class="<?= $this->FontAwesome->getClass('sticky-note') ?>"></i> <?= __('Notes & Opinions') ?> <span class="label label-secondary"><?= $allCounts['notesOpinions'] ?></span></a></li> \
|
<li class="active"><a href="#notes-<?= $seed ?>" data-toggle="tab"><i class="<?= $this->FontAwesome->getClass('sticky-note') ?>"></i> <?= __('Notes & Opinions') ?> <span class="label label-secondary"><?= $allCounts['notesOpinions'] ?></span></a></li> \
|
||||||
|
@ -439,18 +450,6 @@ function fetchMoreNotes(clicked, noteType, uuid) {
|
||||||
</div> \
|
</div> \
|
||||||
')
|
')
|
||||||
|
|
||||||
function renderAllNotesWithForm(relationship_related_object) {
|
|
||||||
var buttonContainer = '<div id="add-button-container" style="margin-top: 0.5rem;">' + addNoteButton + addOpinionButton + '</div>'
|
|
||||||
renderedNotes<?= $seed ?> = nodeContainerTemplate({
|
|
||||||
content_notes: renderNotes(notes.filter(function(note) { return note.note_type != 2}), relationship_related_object, '<?= __('No notes for this UUID.') ?>') + buttonContainer,
|
|
||||||
content_relationships_outbound: renderNotes(relationships, relationship_related_object, '<?= __('No relationship from this UUID') ?>') + addRelationshipButton,
|
|
||||||
content_relationships_inbound: renderNotes(relationships_inbound, relationship_related_object, '<?= __('No element are referencing this UUID') ?>', true),
|
|
||||||
})
|
|
||||||
if (container_id) {
|
|
||||||
$('#' + container_id).html(renderedNotes<?= $seed ?>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var addNoteButton = '<button class="btn btn-small btn-block btn-primary" type="button" onclick="createNewNote(this, \'<?= $object_type ?>\', \'<?= $object_uuid ?>\')"> \
|
var addNoteButton = '<button class="btn btn-small btn-block btn-primary" type="button" onclick="createNewNote(this, \'<?= $object_type ?>\', \'<?= $object_uuid ?>\')"> \
|
||||||
<i class="<?= $this->FontAwesome->getClass('plus') ?>"></i> <?= __('Add a note') ?> \
|
<i class="<?= $this->FontAwesome->getClass('plus') ?>"></i> <?= __('Add a note') ?> \
|
||||||
</button>'
|
</button>'
|
||||||
|
@ -461,10 +460,15 @@ function fetchMoreNotes(clicked, noteType, uuid) {
|
||||||
<i class="<?= $this->FontAwesome->getClass('plus') ?>"></i> <?= __('Add a relationship') ?> \
|
<i class="<?= $this->FontAwesome->getClass('plus') ?>"></i> <?= __('Add a relationship') ?> \
|
||||||
</button>'
|
</button>'
|
||||||
|
|
||||||
$(document).ready(function() {
|
function renderAllNotesWithForm<?= $seed ?>(notes, relationships, relationships_inbound, relationship_related_object) {
|
||||||
renderAllNotesWithForm(relationship_related_object)
|
var buttonContainer = '<div id="add-button-container" style="margin-top: 0.5rem;">' + addNoteButton + addOpinionButton + '</div>'
|
||||||
})
|
var renderedNotes = nodeContainerTemplate<?= $seed ?>({
|
||||||
})()
|
content_notes: renderNotes(notes.filter(function(note) { return note.note_type != 2}), relationship_related_object, '<?= __('No notes for this UUID.') ?>') + buttonContainer,
|
||||||
|
content_relationships_outbound: renderNotes(relationships, relationship_related_object, '<?= __('No relationship from this UUID') ?>') + addRelationshipButton,
|
||||||
|
content_relationships_inbound: renderNotes(relationships_inbound, relationship_related_object, '<?= __('No element are referencing this UUID') ?>', true),
|
||||||
|
})
|
||||||
|
return renderedNotes
|
||||||
|
}
|
||||||
|
|
||||||
function createNewNote(clicked, object_type, object_uuid) {
|
function createNewNote(clicked, object_type, object_uuid) {
|
||||||
note_type = 'Note';
|
note_type = 'Note';
|
||||||
|
@ -516,6 +520,19 @@ function fetchMoreNotes(clicked, noteType, uuid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<?php if(!empty($injectInPage)): ?>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var notes = <?= json_encode($notesOpinions) ?>;
|
||||||
|
var relationships = <?= json_encode($relationshipsOutbound) ?>;
|
||||||
|
var relationships_inbound = <?= json_encode($relationshipsInbound) ?>;
|
||||||
|
var relationship_related_object = <?= json_encode($related_objects) ?>;
|
||||||
|
var renderedNotes = renderAllNotesWithForm<?= $seed ?>(notes, relationships, relationships_inbound, relationship_related_object)
|
||||||
|
if (container_id) {
|
||||||
|
$('#' + container_id).html(renderedNotes)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -170,15 +170,57 @@ $md.html(md.render($md.text()));
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$object_uuid = $cluster['GalaxyCluster']['uuid'];
|
$object_uuid = $cluster['GalaxyCluster']['uuid'];
|
||||||
|
|
||||||
|
$notes = $cluster['GalaxyCluster']['Note'] ?? [];
|
||||||
|
$opinions = $cluster['GalaxyCluster']['Opinion'] ?? [];
|
||||||
|
$relationships_outbound = $cluster['GalaxyCluster']['Relationship'] ?? [];
|
||||||
|
$relationships_inbound = $cluster['GalaxyCluster']['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 = [
|
$options = [
|
||||||
'container_id' => 'analyst_data_thread',
|
'container_id' => 'analyst_data_thread',
|
||||||
'object_type' => 'GalaxyCluster',
|
'object_type' => 'GalaxyCluster',
|
||||||
'object_uuid' => $object_uuid,
|
'object_uuid' => $object_uuid,
|
||||||
'shortDist' => $shortDist,
|
'shortDist' => $shortDist,
|
||||||
'notes' => $cluster['GalaxyCluster']['Note'] ?? [],
|
'notes' => $notes,
|
||||||
'opinions' => $cluster['GalaxyCluster']['Opinion'] ?? [],
|
'opinions' => $opinions,
|
||||||
'relationships_outbound' => $cluster['GalaxyCluster']['Relationship'] ?? [],
|
'relationships_outbound' => $relationships_outbound,
|
||||||
'relationships_inbound' => $cluster['GalaxyCluster']['RelationshipInbound'] ?? [],
|
'relationships_inbound' => $relationships_inbound,
|
||||||
|
'allCounts' => $allCounts,
|
||||||
];
|
];
|
||||||
|
|
||||||
echo $this->element('genericElements/Analyst_data/thread', $options);
|
echo $this->element('genericElements/Analyst_data/thread', $options);
|
||||||
|
|
Loading…
Reference in New Issue