diff --git a/app/Controller/GalaxyClusterRelationsController.php b/app/Controller/GalaxyClusterRelationsController.php index 9165d7dc5..3b14b21b4 100644 --- a/app/Controller/GalaxyClusterRelationsController.php +++ b/app/Controller/GalaxyClusterRelationsController.php @@ -145,7 +145,7 @@ class GalaxyClusterRelationsController extends AppController public function edit($id) { - $conditions = array('conditions' => array('GalaxyClusterRelation.id' => $id)); + $conditions = array('conditions' => array('GalaxyClusterRelation.id' => $id), 'contain' => array('GalaxyClusterRelationTag' => 'Tag')); $existingRelation = $this->GalaxyClusterRelation->fetchRelations($this->Auth->user(), $conditions); if (empty($existingRelation)) { throw new NotFoundException(__('Invalid cluster relation')); @@ -156,6 +156,9 @@ class GalaxyClusterRelationsController extends AppController throw new MethodNotAllowedException(__('Default cluster relation cannot be edited')); } + $existingRelation['GalaxyClusterRelation']['tags'] = Hash::extract($existingRelation['GalaxyClusterRelationTag'], '{n}.Tag.name'); + $existingRelation['GalaxyClusterRelation']['tags'] = implode(', ', $existingRelation['GalaxyClusterRelation']['tags']); + $this->loadModel('Attribute'); $distributionLevels = $this->Attribute->distributionLevels; unset($distributionLevels[5]); @@ -182,6 +185,12 @@ class GalaxyClusterRelationsController extends AppController $errors = array(__('Invalid permssions')); } + if (!empty($relation['GalaxyClusterRelation']['tags'])) { + $tags = explode(',', $relation['GalaxyClusterRelation']['tags']); + $tags = array_map('trim', $tags); + $relation['GalaxyClusterRelation' ]['tags'] = $tags; + } + if ($this->Auth->user()['Role']['perm_site_admin'] || $clusterSource['GalaxyCluster']['org_id'] != $this->Auth->user()['org_id']) { $errors = $this->GalaxyClusterRelation->editRelation($this->Auth->user(), $relation); } else { diff --git a/app/Model/Galaxy.php b/app/Model/Galaxy.php index 644b336aa..e38d5b1a2 100644 --- a/app/Model/Galaxy.php +++ b/app/Model/Galaxy.php @@ -214,7 +214,7 @@ class Galaxy extends AppModel $db->insertMulti('galaxy_elements', $fields, $elements); } $tempUser = array('Role' => array('perm_tag_editor' => 1, 'perm_site_admin' => 1)); // only site-admin are authorized to update galaxies - $this->GalaxyCluster->GalaxyClusterRelation->addRelations($tempUser, $relations); + $this->GalaxyCluster->GalaxyClusterRelation->addRelations($tempUser, $relations, $capture=true); } return true; } diff --git a/app/Model/GalaxyClusterRelation.php b/app/Model/GalaxyClusterRelation.php index 43e1a1265..5891354c2 100644 --- a/app/Model/GalaxyClusterRelation.php +++ b/app/Model/GalaxyClusterRelation.php @@ -129,7 +129,7 @@ class GalaxyClusterRelation extends AppModel $this->deleteAll($conditions, false, false); } - public function addRelations($user, $relations) + public function addRelations($user, $relations, $capture=false) { $fieldList = array( 'galaxy_cluster_uuid', @@ -155,7 +155,7 @@ class GalaxyClusterRelation extends AppModel $saveResult = $this->save($relation, array('fieldList' => $fieldList)); if ($saveResult) { $savedId = $this->id; - $this->GalaxyClusterRelationTag->attachTags($user, $savedId, $relation['tags']); + $this->GalaxyClusterRelationTag->attachTags($user, $savedId, $relation['tags'], $capture=$capture); } } else { throw new NotFoundException(__('Invalid referenced galaxy cluster')); @@ -210,7 +210,7 @@ class GalaxyClusterRelation extends AppModel return $errors; } - public function editRelation($user, $relation, $fieldList=array()) + public function editRelation($user, $relation, $fieldList=array(), $capture=false) { $this->SharingGroup = ClassRegistry::init('SharingGroup'); $errors = array(); @@ -263,6 +263,9 @@ class GalaxyClusterRelation extends AppModel foreach($this->validationErrors as $validationError) { $errors[] = $validationError[0]; } + } else { + $this->GalaxyClusterRelationTag->deleteAll(array('GalaxyClusterRelationTag.galaxy_cluster_relation_id' => $relation['GalaxyClusterRelation']['id'])); + $this->GalaxyClusterRelationTag->attachTags($user, $relation['GalaxyClusterRelation']['id'], $relation['GalaxyClusterRelation']['tags'], $capture=$capture); } } } @@ -331,7 +334,7 @@ class GalaxyClusterRelation extends AppModel $results['imported']++; if (!empty($relation['GalaxyClusterRelationTag'])) { $tagNames = Hash::extract($relation['GalaxyClusterRelationTag'], '{n}.name'); - $this->GalaxyClusterRelationTag->attachTags($user, $this->id, $tagNames); + $this->GalaxyClusterRelationTag->attachTags($user, $this->id, $tagNames, $capture=true); } } else { $results['failed']++; diff --git a/app/Model/GalaxyClusterRelationTag.php b/app/Model/GalaxyClusterRelationTag.php index 3f5beaaba..1fd5b7ff8 100644 --- a/app/Model/GalaxyClusterRelationTag.php +++ b/app/Model/GalaxyClusterRelationTag.php @@ -43,11 +43,16 @@ class GalaxyClusterRelationTag extends AppModel $this->delete($id); } - public function attachTags($user, $galaxyClusterRelationId, $tags) + public function attachTags($user, $galaxyClusterRelationId, $tags, $capture=false) { $allSaved = true; + $saveResult = false; foreach ($tags as $tagName) { - $tagId = $this->Tag->captureTag(array('name' => $tagName), $user); + if ($capture) { + $tagId = $this->Tag->captureTag(array('name' => $tagName), $user); + } else { + $tagId = $this->Tag->lookupTagIdFromName($tagName); + } $existingAssociation = $this->find('first', array( 'recursive' => -1, 'conditions' => array( @@ -55,7 +60,7 @@ class GalaxyClusterRelationTag extends AppModel 'galaxy_cluster_relation_id' => $galaxyClusterRelationId ) )); - if (empty($existingAssociation)) { + if (empty($existingAssociation) && $tagId != -1) { $this->create(); $saveResult = $this->save(array('galaxy_cluster_relation_id' => $galaxyClusterRelationId, 'tag_id' => $tagId)); $allSaved = $allSaved && $saveResult; @@ -64,6 +69,11 @@ class GalaxyClusterRelationTag extends AppModel } } } - return $saveResult; + return $allSaved; + } + + public function detachTag($user, $relationTagId) + { + $this->delete(array('GalaxyClusterRelationTag.relationTagId' => $relationTagId)); } } diff --git a/app/View/GalaxyClusterRelations/add.ctp b/app/View/GalaxyClusterRelations/add.ctp index 9e111a042..fe08ab761 100644 --- a/app/View/GalaxyClusterRelations/add.ctp +++ b/app/View/GalaxyClusterRelations/add.ctp @@ -34,8 +34,9 @@ ), array( 'field' => 'tags', - 'label' => __('Tags'), - 'type' => 'text', + 'label' => __('Tag list'), + 'type' => 'textarea', + 'placeholder' => __('estimative-language:likelihood-probability="very-likely", false-positive:risk="low"') ), ), 'submit' => array(