From 4c0e4984e1d2abae166ba839441b954a4e102489 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 13 May 2020 11:01:16 +0200 Subject: [PATCH] chg: [clusterRelations] Moved relation_tree into its own `tool` and added modal support for galaxyQuickView --- app/Controller/GalaxiesController.php | 2 +- app/Controller/GalaxyClustersController.php | 56 ++++++------- app/Lib/Tools/ClusterRelationsTreeTool.php | 78 +++++++++++++++++++ .../GalaxyClusters/view_relation_tree.ctp | 4 +- app/View/Elements/galaxyQuickViewMini.ctp | 27 ++++++- app/View/Events/view.ctp | 11 --- app/View/GalaxyClusters/view_relations.ctp | 6 +- app/webroot/css/main.css | 4 + app/webroot/js/misp.js | 36 ++++++++- 9 files changed, 169 insertions(+), 55 deletions(-) create mode 100644 app/Lib/Tools/ClusterRelationsTreeTool.php diff --git a/app/Controller/GalaxiesController.php b/app/Controller/GalaxiesController.php index 101b15f1e..b6b075ea1 100644 --- a/app/Controller/GalaxiesController.php +++ b/app/Controller/GalaxiesController.php @@ -517,7 +517,7 @@ class GalaxiesController extends AppController 'recursive' => -1, 'conditions' => array('Galaxy.id' => $galaxyId) )); - $tree = $this->Galaxy->generateForkTree($clusters, $galaxy, $pruneRootLeaves=true); // moved this to Lib/Tool + $tree = $this->Galaxy->generateForkTree($clusters, $galaxy, $pruneRootLeaves=true); if ($this->_isRest()) { return $this->RestResponse->viewData($tree, $this->response->type()); } diff --git a/app/Controller/GalaxyClustersController.php b/app/Controller/GalaxyClustersController.php index b213e9ed0..07f592692 100644 --- a/app/Controller/GalaxyClustersController.php +++ b/app/Controller/GalaxyClustersController.php @@ -834,41 +834,11 @@ class GalaxyClustersController extends AppController $cluster = $this->GalaxyCluster->attachReferencingRelations($this->Auth->user(), $cluster); $cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster); - $treeRight = array(array( - 'GalaxyCluster' => $cluster['GalaxyCluster'], - 'children' => array() - )); - // add relation info between the two clusters - foreach($cluster['GalaxyClusterRelation'] as $relation) { - $tmp = array( - 'Relation' => array_diff_key($relation, array_flip(array('GalaxyCluster'))), - 'children' => array( - array('GalaxyCluster' => $relation['GalaxyCluster']), - ) - ); - $treeRight[0]['children'][] = $tmp; - } + App::uses('ClusterRelationsTreeTool', 'Tools'); + $grapher = new ClusterRelationsTreeTool(); + $grapher->construct($this->Auth->user(), $this->GalaxyCluster); + $tree = $grapher->getTree($cluster); - $treeLeft = array(array( - 'GalaxyCluster' => $cluster['GalaxyCluster'], - 'children' => array() - )); - if (!empty($cluster['ReferencingGalaxyClusterRelation'])) { - foreach($cluster['ReferencingGalaxyClusterRelation'] as $relation) { - $tmp = array( - 'Relation' => array_diff_key($relation, array_flip(array('GalaxyCluster'))), - 'children' => array( - array('GalaxyCluster' => $relation['GalaxyCluster']), - ) - ); - $treeLeft[0]['children'][] = $tmp; - } - } - - $tree = array( - 'right' => $treeRight, - 'left' => $treeLeft, - ); $this->set('existingRelations', $existingRelations); $this->set('cluster', $cluster); $relations = $this->GalaxyCluster->GalaxyClusterRelation->fetchRelations($this->Auth->user(), array( @@ -885,4 +855,22 @@ class GalaxyClustersController extends AppController unset($distributionLevels[5]); $this->set('distributionLevels', $distributionLevels); } + + public function viewRelationTree($clusterId) + { + $options = array('conditions' => array('GalaxyCluster.id' => $clusterId)); + $cluster = $this->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), $options, true); + if (empty($cluster)) { + throw new NotFoundException('Invalid galaxy cluster'); + } + $cluster = $cluster[0]; + $cluster = $this->GalaxyCluster->attachReferencingRelations($this->Auth->user(), $cluster); + $cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster); + App::uses('ClusterRelationsTreeTool', 'Tools'); + $grapher = new ClusterRelationsTreeTool(); + $grapher->construct($this->Auth->user(), $this->GalaxyCluster); + $tree = $grapher->getTree($cluster); + $this->set('tree', $tree); + $this->render('/Elements/GalaxyClusters/view_relation_tree'); + } } diff --git a/app/Lib/Tools/ClusterRelationsTreeTool.php b/app/Lib/Tools/ClusterRelationsTreeTool.php new file mode 100644 index 000000000..8c62f245e --- /dev/null +++ b/app/Lib/Tools/ClusterRelationsTreeTool.php @@ -0,0 +1,78 @@ +GalaxyCluster = $GalaxyCluster; + $this->user = $user; + return true; + } + + public function getTree($cluster) + { + $treeRight = array(array( + 'GalaxyCluster' => $cluster['GalaxyCluster'], + 'children' => array() + )); + // add relation info between the two clusters + foreach($cluster['GalaxyClusterRelation'] as $relation) { + $tmp = array( + 'Relation' => array_diff_key($relation, array_flip(array('GalaxyCluster'))), + 'children' => array( + array('GalaxyCluster' => $relation['GalaxyCluster']), + ) + ); + $treeRight[0]['children'][] = $tmp; + } + + $treeLeft = array(array( + 'GalaxyCluster' => $cluster['GalaxyCluster'], + 'children' => array() + )); + if (!empty($cluster['ReferencingGalaxyClusterRelation'])) { + foreach($cluster['ReferencingGalaxyClusterRelation'] as $relation) { + $tmp = array( + 'Relation' => array_diff_key($relation, array_flip(array('GalaxyCluster'))), + 'children' => array( + array('GalaxyCluster' => $relation['GalaxyCluster']), + ) + ); + $treeLeft[0]['children'][] = $tmp; + } + } + + $tree = array( + 'right' => $treeRight, + 'left' => $treeLeft, + ); + return $tree; + } + + private function attachOwnerInsideCluster($cluster) + { + if (!empty($cluster['Org']) && !isset($cluster['GalaxyCluster']['Org'])) { + $cluster['GalaxyCluster']['Org'] = array( + 'id' => $cluster['Org']['id'], + 'name' => $cluster['Org']['name'], + ); + } + if (!empty($cluster['Orgc']) && !isset($cluster['GalaxyCluster']['Orgc'])) { + $cluster['GalaxyCluster']['Orgc'] = array( + 'id' => $cluster['Orgc']['id'], + 'name' => $cluster['Orgc']['name'], + ); + } + if (!empty($cluster['SharingGroup']) && !isset($cluster['GalaxyCluster']['SharingGroup'])) { + $cluster['GalaxyCluster']['SharingGroup'] = array( + 'id' => $cluster['SharingGroup']['id'], + 'name' => $cluster['SharingGroup']['name'], + 'description' => $cluster['SharingGroup']['description'], + ); + } + return $cluster; + } + } diff --git a/app/View/Elements/GalaxyClusters/view_relation_tree.ctp b/app/View/Elements/GalaxyClusters/view_relation_tree.ctp index e02030728..f6bc138c4 100644 --- a/app/View/Elements/GalaxyClusters/view_relation_tree.ctp +++ b/app/View/Elements/GalaxyClusters/view_relation_tree.ctp @@ -4,8 +4,8 @@ echo $this->element('genericElements/assetLoader', array( )); ?> -
- +
+
diff --git a/app/View/Events/view.ctp b/app/View/Events/view.ctp index 8510b135c..165435434 100644 --- a/app/View/Events/view.ctp +++ b/app/View/Events/view.ctp @@ -517,9 +517,6 @@ - @@ -585,13 +582,5 @@ function enable_attack_matrix() { $("#attackmatrix_div").html(data); }); } - -function enable_galaxy_relations() { - if ($("#clusterrelation_div").find('svg').length == 0) { - $.get("/events/viewClusterRelations/", function(data) { - $("#clusterrelation_div").html(data); - }); - } -} diff --git a/app/View/GalaxyClusters/view_relations.ctp b/app/View/GalaxyClusters/view_relations.ctp index e24999e1b..6042eea16 100644 --- a/app/View/GalaxyClusters/view_relations.ctp +++ b/app/View/GalaxyClusters/view_relations.ctp @@ -151,7 +151,9 @@
- element('GalaxyClusters/view_relation_tree'); ?> +
+ element('GalaxyClusters/view_relation_tree'); ?> +