chg: [galaxyClusters:updateCluster] Working version and improved UI and

text
pull/6120/head
mokaddem 2020-05-04 16:20:09 +02:00
parent 28239ba674
commit 83a7080474
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 67 additions and 52 deletions

View File

@ -775,20 +775,17 @@ class GalaxyClustersController extends AppController
$forkVersion = $cluster['GalaxyCluster']['extends_version'];
$parentVersion = $parentCluster['GalaxyCluster']['version'];
if ($this->request->is('post') || $this->request->is('put')) {
debug($this->request->data);
// if (empty($cluster['GalaxyCluster']['elements'])) {
// $cluster['GalaxyCluster']['elements'] = array();
// } else {
// $decoded = json_decode($cluster['GalaxyCluster']['elements'], true);
// if (is_null($decoded)) {
// $this->GalaxyCluster->validationErrors['values'][] = __('Invalid JSON');
// $errors[] = sprintf(__('Invalid JSON'));
// }
// $cluster['GalaxyCluster']['elements'] = $decoded;
// }
$this->request->data['GalaxyCluster']['extends_version'] = $parentVersion;
// $errors = $this->GalaxyCluster->editCluster($this->Auth->user(), $cluster);
$errors = array('block');
$elements = array();
foreach ($this->request->data['GalaxyCluster'] as $k => $jElement) {
$element = json_decode($jElement, true);
$elements[] = array(
'key' => $element['key'],
'value' => $element['value'],
);
}
$cluster['GalaxyCluster']['elements'] = $elements;
$cluster['GalaxyCluster']['extends_version'] = $parentVersion;
$errors = $this->GalaxyCluster->editCluster($this->Auth->user(), $cluster, $fromPull=false, $fieldList=array('extends_version'));
if (!empty($errors)) {
$flashErrorMessage = implode(', ', $errors);
$this->Flash->error($flashErrorMessage);

View File

@ -157,7 +157,7 @@ class GalaxyCluster extends AppModel
return $saveSuccess;
}
public function editCluster($user, $cluster, $fromPull = false)
public function editCluster($user, $cluster, $fromPull = false, $fieldList = array())
{
$this->SharingGroup = ClassRegistry::init('SharingGroup');
$errors = array();
@ -192,7 +192,9 @@ class GalaxyCluster extends AppModel
$cluster['GalaxyCluster']['version'] = $date->getTimestamp();
}
$cluster['GalaxyCluster']['default'] = false;
$fieldList = array('value', 'description', 'version', 'source', 'authors', 'distribution', 'sharing_group_id', 'default');
if (empty($fieldList)) {
$fieldList = array('value', 'description', 'version', 'source', 'authors', 'distribution', 'sharing_group_id', 'default');
}
$saveSuccess = $this->save($cluster, array('fieldList' => $fieldList));
if ($saveSuccess) {
$elementsToSave = array();
@ -435,8 +437,13 @@ class GalaxyCluster extends AppModel
if (isset($options['group'])) {
$params['group'] = empty($options['group']) ? $options['group'] : false;
}
$galaxClusters = $this->find('all', $params);
return $galaxClusters;
$galaxyClusters = $this->find('all', $params);
foreach ($galaxyClusters as $k => $cluster) {
if ($cluster['GalaxyCluster']['distribution'] == 4) {
unset($cluster['SharingGroup']);
}
}
return $galaxyClusters;
}
/**

View File

@ -123,7 +123,7 @@ function drawCluster(gEnter) {
.append("xhtml:div")
.append("a")
.attr("class", "fas fa-arrow-up useCursorPointer")
.attr("title", "<?= __('Update cluster to new version') ?>")
.attr("title", "<?= __('Update cluster to parent\'s new version') ?>")
.attr("href", function(d) { return "<?= sprintf('%s/galaxy_clusters/updateCluster/', $baseurl) ?>" + d.GalaxyCluster.id; })
drawLabel(gEnter, {

View File

@ -10,7 +10,7 @@
<div class="span6">
<h4><?= __('Parent fork elements') ?></h4>
<div class="alert alert-success" style="margin-bottom: 0px">
<div><?= sprintf(__('Version: %s'), h($parentVersion)) ?></div>
<div><?= sprintf(__('Version: %s (newer)'), h($parentVersion)) ?></div>
</div>
<table class="table table-striped table-hover table-condensed">
<thead>
@ -38,7 +38,7 @@
<div class="span6">
<h4><?= __('Current elements') ?></h4>
<div class="alert alert-warning" style="margin-bottom: 0px">
<div><?= sprintf(__('Parent version: %s'), h($forkVersion)) ?></div>
<div><?= sprintf(__('Parent version: %s (older)'), h($forkVersion)) ?></div>
</div>
<table class="table table-striped table-hover table-condensed">
<thead>
@ -65,38 +65,49 @@
</div>
</div>
<h4><?= __('Elements in parent fork but not in this cluster') ?></h4>
<?php echo $this->Form->create('GalaxyCluster');?>
<div class="row">
<div class="span8">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th><?= __('Key'); ?></th>
<th><?= __('Value'); ?></th>
<th><?= __('Import element into the cluster') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($missingElements as $k => $element): ?>
<tr>
<td><?= h($element['key']) ?></td>
<td><?= h($element['value']) ?></td>
<td>
<?php
echo $this->Form->input('element-'.$k, array(
'label' => __('Import'),
'type' => 'checkbox',
'checked' => true
));
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if (empty($missingElements)): ?>
<div class="row">
<div class="span12">
<div class="alert alert-success">
<strong><?= __('You are all set!') ?></strong> <span><?= sprintf(__('There are no new elements to be added from the parent cluster'), h($forkVersion)) ?></span>
</div>
</div>
</div>
</div>
<?php else: ?>
<h4><?= __('Elements in parent fork but not in this cluster') ?></h4>
<?php echo $this->Form->create('GalaxyCluster');?>
<div class="row">
<div class="span8">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th><?= __('Key'); ?></th>
<th><?= __('Value'); ?></th>
<th><?= __('Import element into the cluster') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($missingElements as $k => $element): ?>
<tr>
<td><?= h($element['key']) ?></td>
<td><?= h($element['value']) ?></td>
<td>
<?php
echo $this->Form->input('element-'.$k, array(
'label' => __('Import'),
'type' => 'checkbox',
'value' => json_encode($element),
'checked' => true
));
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<?php
echo $this->Form->button(__('Update'), array('class' => 'btn btn-primary'));
echo $this->Form->end();