mirror of https://github.com/MISP/MISP
chg: [galaxyClusters:view] Both inbound and outbound relations can be viewed
parent
ff6b07dcfe
commit
52d6a2dc02
|
@ -981,14 +981,14 @@ class GalaxyClustersController extends AppController
|
|||
/**
|
||||
* @param mixed $id ID or UUID of the cluster
|
||||
*/
|
||||
public function viewRelations($id)
|
||||
public function viewRelations($id, $includeInbound=1)
|
||||
{
|
||||
if (!$this->request->is('ajax')) {
|
||||
throw new MethodNotAllowedException('This function can only be reached via AJAX.');
|
||||
}
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $id, 'view', true, true);
|
||||
$existingRelations = $this->GalaxyCluster->GalaxyClusterRelation->getExistingRelationships();
|
||||
$cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster);
|
||||
$cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster, $includeInbound);
|
||||
|
||||
App::uses('ClusterRelationsTreeTool', 'Tools');
|
||||
$grapher = new ClusterRelationsTreeTool();
|
||||
|
@ -998,9 +998,16 @@ class GalaxyClustersController extends AppController
|
|||
$this->set('existingRelations', $existingRelations);
|
||||
$this->set('cluster', $cluster);
|
||||
$relations = $cluster['GalaxyCluster']['GalaxyClusterRelation'];
|
||||
if ($includeInbound && !empty($cluster['GalaxyCluster']['TargetingClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyCluster']['TargetingClusterRelation'] as $targetingCluster) {
|
||||
$targetingCluster['isInbound'] = true;
|
||||
$relations[] = $targetingCluster;
|
||||
}
|
||||
}
|
||||
$this->set('passedArgs', json_encode([]));
|
||||
$this->set('relations', $relations);
|
||||
$this->set('tree', $tree);
|
||||
$this->set('includeInbound', $includeInbound);
|
||||
$this->loadModel('Attribute');
|
||||
$distributionLevels = $this->Attribute->distributionLevels;
|
||||
unset($distributionLevels[4]);
|
||||
|
@ -1011,15 +1018,18 @@ class GalaxyClustersController extends AppController
|
|||
/**
|
||||
* @param mixed $id ID or UUID of the cluster
|
||||
*/
|
||||
public function viewRelationTree($id)
|
||||
public function viewRelationTree($id, $includeInbound=1)
|
||||
{
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $id, 'view', $throwErrors=true, $full=true);
|
||||
$cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster);
|
||||
$cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster, $includeInbound);
|
||||
App::uses('ClusterRelationsTreeTool', 'Tools');
|
||||
$grapher = new ClusterRelationsTreeTool();
|
||||
$grapher->construct($this->Auth->user(), $this->GalaxyCluster);
|
||||
$tree = $grapher->getTree($cluster);
|
||||
$this->set('tree', $tree);
|
||||
$this->set('cluster', $cluster);
|
||||
$this->set('includeInbound', $includeInbound);
|
||||
$this->set('testtest', 'testtest');
|
||||
$this->render('/Elements/GalaxyClusters/view_relation_tree');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2064,7 +2064,7 @@ class GalaxyCluster extends AppModel
|
|||
return $cluster;
|
||||
}
|
||||
|
||||
public function attachClusterToRelations($user, $cluster)
|
||||
public function attachClusterToRelations($user, $cluster, $both=true)
|
||||
{
|
||||
if (!empty($cluster['GalaxyCluster']['GalaxyClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyCluster']['GalaxyClusterRelation'] as $k => $relation) {
|
||||
|
@ -2075,12 +2075,14 @@ class GalaxyCluster extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($cluster['GalaxyCluster']['TargetingClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyCluster']['TargetingClusterRelation'] as $k => $relation) {
|
||||
$conditions = array('conditions' => array('GalaxyCluster.uuid' => $relation['galaxy_cluster_uuid']));
|
||||
$relatedCluster = $this->fetchGalaxyClusters($user, $conditions, false);
|
||||
if (!empty($relatedCluster)) {
|
||||
$cluster['GalaxyCluster']['TargetingClusterRelation'][$k]['GalaxyCluster'] = $relatedCluster[0]['GalaxyCluster'];
|
||||
if ($both) {
|
||||
if (!empty($cluster['GalaxyCluster']['TargetingClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyCluster']['TargetingClusterRelation'] as $k => $relation) {
|
||||
$conditions = array('conditions' => array('GalaxyCluster.uuid' => $relation['galaxy_cluster_uuid']));
|
||||
$relatedCluster = $this->fetchGalaxyClusters($user, $conditions, false);
|
||||
if (!empty($relatedCluster)) {
|
||||
$cluster['GalaxyCluster']['TargetingClusterRelation'][$k]['GalaxyCluster'] = $relatedCluster[0]['GalaxyCluster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,16 @@
|
|||
echo $this->element('genericElements/assetLoader', array(
|
||||
'js' => array('d3')
|
||||
));
|
||||
$random = rand();
|
||||
$randomClass = "relation-{$random}";
|
||||
?>
|
||||
|
||||
<div style="padding: 5px; display: flex; position: absolute; top: 0; left: 0; right: 0; bottom: 0;">
|
||||
<svg id="treeSVG" style="width: 100%; height: 100%;"></svg>
|
||||
<label style="position: absolute;">
|
||||
<input type="checkbox" id="checkbox-include-inbound" class="<?= $randomClass ?>" <?= !isset($includeInbound) || !empty($includeInbound) ? "checked=\"checked\"" : "" ?>></input>
|
||||
<?= __('Include inbound relations') ?>
|
||||
</label>
|
||||
<svg id="treeSVG" class="<?= $randomClass ?>" style="width: 100%; height: 100%;"></svg>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
@ -15,14 +21,23 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
var margin = {top: 10, right: 10, bottom: 30, left: 20};
|
||||
var treeWidth, treeHeight;
|
||||
var colors = d3.scale.category10();
|
||||
var hasBeenBuilt = false;
|
||||
var hasBeenBuilt<?= $random ?> = false;
|
||||
|
||||
$(document).ready(function() {
|
||||
var $checkbox = $('#checkbox-include-inbound.<?= $randomClass ?>');
|
||||
$checkbox.click(function() {
|
||||
var $container = $(this).parent().parent().parent();
|
||||
var checked = $(this).prop('checked');
|
||||
reloadDiagram($container, checked);
|
||||
})
|
||||
})
|
||||
|
||||
function buildTree() {
|
||||
if (hasBeenBuilt) {
|
||||
if (hasBeenBuilt<?= $random ?>) {
|
||||
return;
|
||||
}
|
||||
hasBeenBuilt = true;
|
||||
var $tree = $('#treeSVG');
|
||||
hasBeenBuilt<?= $random ?> = true;
|
||||
var $tree = $('#treeSVG.<?= $randomClass ?>');
|
||||
treeWidth = $tree.width() - margin.right - margin.left;
|
||||
treeHeight = $tree.height() - margin.top - margin.bottom;
|
||||
var leftShift;
|
||||
|
@ -142,7 +157,7 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
+ " " + (d.source.y + d.target.y) / 2 + "," + d.target.x
|
||||
+ " " + d.target.y + "," + d.target.x;
|
||||
};
|
||||
var svg = d3.select("#treeSVG")
|
||||
var svg = d3.select("#treeSVG.<?= $randomClass ?>")
|
||||
.attr("width", treeWidth + margin.right + margin.left)
|
||||
.attr("height", treeHeight + margin.top + margin.bottom)
|
||||
.append("g")
|
||||
|
@ -408,7 +423,7 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
}
|
||||
|
||||
function adaptContainerHeightIfNeeded(side) {
|
||||
var $upperContainer = $('#treeSVG').parent().parent();
|
||||
var $upperContainer = $('#treeSVG.<?= $randomClass ?>').parent().parent();
|
||||
var leftNodeNumber = 0
|
||||
var rightNodeNumber = 0
|
||||
if (side == 'left') {
|
||||
|
@ -436,4 +451,17 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
function reloadDiagram($container, checked) {
|
||||
var url = '<?= $baseurl ?>/galaxy_clusters/viewRelationTree/<?= h($cluster['GalaxyCluster']['id']) ?>/' + (checked ? '1' : '0')
|
||||
xhr({
|
||||
dataType: "html",
|
||||
success: function (data) {
|
||||
hasBeenBuilt<?= $random ?> = false;
|
||||
$container.html(data);
|
||||
buildTree()
|
||||
},
|
||||
url: url,
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -3,6 +3,21 @@
|
|||
'data' => array(
|
||||
'skip_pagination' => true,
|
||||
'data' => $relations,
|
||||
'top_bar' => array(
|
||||
'children' => array(
|
||||
array(
|
||||
'type' => 'raw',
|
||||
'children' => array(
|
||||
array(
|
||||
'html' => '<label>' .
|
||||
'<input type="checkbox" id="checkbox-include-inbound" ' . (!isset($includeInbound) || !empty($includeInbound) ? "checked=\"checked\"" : "") . '></input>' .
|
||||
__('Include inbound relations') .
|
||||
'</label>'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => __('Id'),
|
||||
|
@ -15,6 +30,12 @@
|
|||
'element' => 'boolean',
|
||||
'data_path' => 'default',
|
||||
),
|
||||
array(
|
||||
'name' => __('Is Inbound'),
|
||||
'class' => 'short',
|
||||
'element' => 'boolean',
|
||||
'data_path' => 'isInbound',
|
||||
),
|
||||
array(
|
||||
'name' => __('Galaxy Cluster Target (galaxy :: cluster)'),
|
||||
'element' => 'galaxy_cluster_link',
|
||||
|
@ -170,6 +191,14 @@ $(document).ready(function() {
|
|||
$('#buttonAddRelationship').click(function() {
|
||||
submitRelationshipForm();
|
||||
})
|
||||
|
||||
var $checkbox = $('#referencesTable_div #checkbox-include-inbound');
|
||||
$checkbox.click(function() {
|
||||
var checked = $(this).prop('checked');
|
||||
reloadRelationTable(checked, function () {
|
||||
$('#references_div a[href="#tabularView"]').tab('show')
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
function pickerTarget() {
|
||||
|
@ -234,13 +263,7 @@ function submitRelationshipForm() {
|
|||
$.ajax({
|
||||
data: $('#GalaxyClusterRelationAddForm').serialize(),
|
||||
success:function (data) {
|
||||
$.get("/galaxy_clusters/viewRelations/<?php echo $cluster['GalaxyCluster']['id']; ?>", function(data) {
|
||||
$("#relations_container").html(data);
|
||||
$('#references_div').show({
|
||||
complete: buildTree,
|
||||
duration: 0
|
||||
});
|
||||
});
|
||||
reloadRelationTable()
|
||||
},
|
||||
error:function(jqXHR, textStatus, errorThrown) {
|
||||
showMessage('fail', textStatus + ": " + errorThrown);
|
||||
|
@ -266,4 +289,15 @@ function toggleLoadingButton(loading) {
|
|||
$('#buttonAddRelationship > i').removeClass('fa-spinner fa-spin').addClass('fa-plus');
|
||||
}
|
||||
}
|
||||
|
||||
function reloadRelationTable(checked, callback) {
|
||||
$.get("/galaxy_clusters/viewRelations/<?php echo $cluster['GalaxyCluster']['id']; ?>/" + (checked ? '1' : '0'), function(data) {
|
||||
$("#relations_container").html(data);
|
||||
$('#references_div').show({
|
||||
complete: buildTree,
|
||||
duration: 0
|
||||
});
|
||||
callback()
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue