diff --git a/app/Controller/GalaxiesController.php b/app/Controller/GalaxiesController.php index 33e047ff3..baf8c7447 100644 --- a/app/Controller/GalaxiesController.php +++ b/app/Controller/GalaxiesController.php @@ -413,4 +413,51 @@ class GalaxiesController extends AppController $this->set('object', $object[0]); $this->render('/Events/ajax/ajaxGalaxies'); } + + public function forkTree($galaxyId) + { + $clusters = $this->Galaxy->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => array('GalaxyCluster.galaxy_id' => $galaxyId))); + if (empty($clusters)) { + throw new MethodNotAllowedException('Invalid Galaxy.'); + } + foreach ($clusters as $k => $cluster) { + $clusters[$k] = $this->Galaxy->GalaxyCluster->attachExtendByInfo($this->Auth->user(), $clusters[$k]); + $clusters[$k] = $this->Galaxy->GalaxyCluster->attachExtendFromInfo($this->Auth->user(), $clusters[$k]); + } + $galaxy = $this->Galaxy->find('first', array( + 'recursive' => -1, + 'conditions' => array('Galaxy.id' => $galaxyId) + )); + $tree = array(); + $lookup = array(); + foreach ($clusters as $i => $cluster) { + $clusters[$i]['children'] = array(); + $lookup[$cluster['GalaxyCluster']['id']] = &$clusters[$i]; + } + foreach ($clusters as $i => $cluster) { + if (!empty($cluster['GalaxyCluster']['extended_from'])) { + $parent = $cluster['GalaxyCluster']['extended_from']; + $lookup[$parent['GalaxyCluster']['id']]['children'][] = &$clusters[$i]; + } else { + $tree[] = &$clusters[$i]; + } + } + + foreach($tree as $i => $node) { + if (empty($node['children'])) { + unset($tree[$i]); + } + } + + $tree = array(array( + 'Galaxy' => $galaxy['Galaxy'], + 'children' => array_values($tree) + )); + if ($this->_isRest()) { + return $this->RestResponse->viewData($tree, $this->response->type()); + } + $this->set('tree', $tree); + $this->set('galaxy', $galaxy); + $this->set('galaxy_id', $galaxyId); + } } diff --git a/app/Controller/GalaxyClustersController.php b/app/Controller/GalaxyClustersController.php index cef60ce5c..c30db8403 100644 --- a/app/Controller/GalaxyClustersController.php +++ b/app/Controller/GalaxyClustersController.php @@ -312,7 +312,7 @@ class GalaxyClustersController extends AppController if ($temp === null) { throw new NotFoundException('Invalid galaxy cluster'); } - $id = $temp['Galaxy']['id']; + $id = $temp['GalaxyCluster']['id']; } elseif (!is_numeric($id)) { throw new NotFoundException(__('Invalid galaxy cluster')); } diff --git a/app/View/Galaxies/fork_tree.ctp b/app/View/Galaxies/fork_tree.ctp new file mode 100644 index 000000000..af51b74d9 --- /dev/null +++ b/app/View/Galaxies/fork_tree.ctp @@ -0,0 +1,115 @@ +
+
+ +
+

+ +
+ +element('genericElements/assetLoader', array( + 'js' => array('d3') +)); +?> + + + \ No newline at end of file diff --git a/app/View/Galaxies/view.ctp b/app/View/Galaxies/view.ctp index a00b1b4ab..47736344c 100644 --- a/app/View/Galaxies/view.ctp +++ b/app/View/Galaxies/view.ctp @@ -33,11 +33,13 @@ $(document).ready(function () { $.get("", function(data) { diff --git a/app/View/GalaxyClusters/ajax/index.ctp b/app/View/GalaxyClusters/ajax/index.ctp index 905b45cdf..d7b15a5a2 100644 --- a/app/View/GalaxyClusters/ajax/index.ctp +++ b/app/View/GalaxyClusters/ajax/index.ctp @@ -29,6 +29,11 @@ 'active' => $context === 'org', 'url' => sprintf('%s/galaxies/view/%s/context:org', $baseurl, $galaxy_id), 'text' => __('My Galaxy Clusters'), + ), + array( + 'active' => $context === 'fork_tree', + 'url' => sprintf('%s/galaxies/view/%s/context:fork_tree', $baseurl, $galaxy_id), + 'text' => __('View fork tree'), ) ) ),