Implement copying and uppdating experiments
This commit is contained in:
@@ -47,14 +47,12 @@ class Experiments extends MY_Controller {
|
||||
* @param string $projectId
|
||||
*/
|
||||
public function create($projectId = '', $copyId = '') {
|
||||
// TODO: Handle copying of experiments
|
||||
|
||||
$project = $this->project->getByID($projectId);
|
||||
|
||||
if (empty($projectId) || !isset($project['id'])){
|
||||
if (empty($projectId) || !isset($project['id'])) {
|
||||
show_404();
|
||||
}
|
||||
|
||||
|
||||
$programs = $this->program->getAll();
|
||||
|
||||
// get the parameters for a specific program
|
||||
@@ -125,6 +123,12 @@ class Experiments extends MY_Controller {
|
||||
$data['programs'] = $programs;
|
||||
$data['project'] = $project;
|
||||
|
||||
// handle copying of experiments
|
||||
if (!empty($copyId)) {
|
||||
$data['copy'] = $this->experiment->getById($copyId);
|
||||
$data['copy_params'] = $this->experiment->getParameters($copyId);
|
||||
}
|
||||
|
||||
$this->load->view('experiments/new', $data);
|
||||
}
|
||||
|
||||
@@ -155,6 +159,13 @@ class Experiments extends MY_Controller {
|
||||
|
||||
$this->load->helper('typography');
|
||||
|
||||
// update parameters
|
||||
foreach ($_POST as $key => $value) {
|
||||
if (preg_match('/^param-[0-9a-z]+/', $key)) {
|
||||
$this->experiment->updateParameter($this->input->post($key), $experiment['id'], substr($key, 6, 16));
|
||||
}
|
||||
}
|
||||
|
||||
$data['experiment'] = $experiment;
|
||||
$data['parameters'] = $this->experiment->getParameters($experiment['id']);
|
||||
$data['job'] = $this->job->getByExperimentId($experiment['id']);
|
||||
|
||||
@@ -96,7 +96,7 @@ class Experiment extends CI_Model {
|
||||
return false;
|
||||
}
|
||||
|
||||
$experiment = $this->get($experimentId);
|
||||
$experiment = $this->getById($experimentId);
|
||||
$parameter = $this->db->get_where('parameters', array('id' => $data['parameter_id']))->row_array();
|
||||
|
||||
if (isset($experiment['id']) && $experiment['program_id'] == $parameter['program_id']) {
|
||||
@@ -106,6 +106,30 @@ class Experiment extends CI_Model {
|
||||
return $this->db->affected_rows() == 1 ? $experimentId : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a specific parameter for the specified experiment.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $experimentId
|
||||
* @param string $parameterId
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateParameter($value, $experimentId, $parameterId) {
|
||||
if (!empty($value)) {
|
||||
// replace into, to overwrite existing parameters
|
||||
$this->db->query("REPLACE INTO `experiments_parameters`"
|
||||
. " (`experiment_id`, `parameter_id`, `value`) VALUES"
|
||||
. " ('{$experimentId}', '{$parameterId}', '{$value}')");
|
||||
} else {
|
||||
// delete table entry, if value is empty
|
||||
$this->db->where('experiment_id', $experimentId);
|
||||
$this->db->where('parameter_id', $parameterId);
|
||||
$this->db->delete('experiments_parameters');
|
||||
}
|
||||
|
||||
return $this->db->affected_rows() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all parameters for the specified experiment.
|
||||
*
|
||||
@@ -116,7 +140,8 @@ class Experiment extends CI_Model {
|
||||
$programId = $this->db->get_where('experiments', array('id' => $experimentId))->row()->program_id;
|
||||
|
||||
$query = $this->db->query("SELECT `experiments_parameters`.*, `parameters`.`readable`,"
|
||||
. " `parameters`.`name`, `parameters`.`type`, `parameters`.`unit`"
|
||||
. " `parameters`.`name`, `parameters`.`type`, `parameters`.`unit`,"
|
||||
. " `parameters`.`description`, `parameters`.`id` AS parameter_id"
|
||||
. " FROM `parameters` LEFT JOIN `experiments_parameters`"
|
||||
. " ON (`experiments_parameters`.`parameter_id` = `parameters`.`id`"
|
||||
. " AND `experiment_id` = '{$experimentId}') WHERE `program_id` = '{$programId}' ORDER BY `sort_number` ASC");
|
||||
|
||||
@@ -31,44 +31,46 @@
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<h3><?=_('Configuration');?></h3>
|
||||
<table class="tableList">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="40%"><?=_('Parameter');?></th>
|
||||
<th scope="col" width="40%"><?=_('Value');?></th>
|
||||
<th scope="col"><?=_('Unit');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<form name="editExperiment" method="post" action="<?=site_url('experiments/detail/' . $experiment['id']);?>">
|
||||
<h3><?=_('Configuration');?></h3>
|
||||
<table class="tableList">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" width="40%"><?=_('Parameter');?></th>
|
||||
<th scope="col" width="40%"><?=_('Value');?></th>
|
||||
<th scope="col"><?=_('Unit');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($parameters as $param):
|
||||
?>
|
||||
<tr>
|
||||
<td width="40%"><?=$param['readable'];?></td>
|
||||
<td width="41%">
|
||||
<input type="text" name="param-<?=$param['parameter_id'];?>" class="long text" value="<?=(!empty($_POST['param-' . $param['parameter_id']]) ? $this->input->post('param-' . $param['parameter_id']) : $param['value']);?>" />
|
||||
<tr>
|
||||
<td width="40%"><?=$param['readable'];?></td>
|
||||
<td width="41%">
|
||||
<input type="text" name="param-<?=$param['parameter_id'];?>" class="long text" value="<?=(!empty($_POST['param-' . $param['parameter_id']]) ? $this->input->post('param-' . $param['parameter_id']) : $param['value']);?>" />
|
||||
<?php
|
||||
if (!empty($param['description'])):
|
||||
?>
|
||||
<span class="form_info">
|
||||
<a href="<?=site_url('ajax/parameter_help/' . $param['parameter_id']);?>" name="<?=_('Description');?>" id="<?=$param['parameter_id'];?>" class="jtip"> </a>
|
||||
</span>
|
||||
<span class="form_info">
|
||||
<a href="<?=site_url('ajax/parameter_help/' . $param['parameter_id']);?>" name="<?=_('Description');?>" id="<?=$param['parameter_id'];?>" class="jtip"> </a>
|
||||
</span>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<?=form_error('params');?>
|
||||
</td>
|
||||
<td><?=$param['unit'];?></td>
|
||||
</tr>
|
||||
<?=form_error('params');?>
|
||||
</td>
|
||||
<td><?=$param['unit'];?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<a href="javascript:void(0);" class="button save"><?=_('Save changes');?></a>
|
||||
</p>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<a href="javascript:void(0);" onclick="$('form[name=editExperiment]').submit();" class="button save"><?=_('Save changes');?></a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -69,11 +69,11 @@
|
||||
<h4><?=_('Application to use for the computation');?></h4>
|
||||
<input type="hidden" name="program_id" id="program_id" value="<?=set_value('program_id');?>" />
|
||||
<?=form_error('program_id');?>
|
||||
<p>
|
||||
<p class="programs">
|
||||
<?php
|
||||
foreach ($programs as $program):
|
||||
?>
|
||||
<a class="button" href="javascript:void(0);" onclick="$('.program-parameters').hide();$('#<?=$program['id'];?>-params').show();$('.button').removeClass('locked');$(this).addClass('locked');$('input[name=program_id]').val('<?=$program['id'];?>');return false;"><?=$program['name'];?></a>
|
||||
<a class="button" id="program-<?=$program['id'];?>" href="javascript:void(0);" onclick="$('.program-parameters').hide();$('#<?=$program['id'];?>-params').show();$('.button').removeClass('locked');$(this).addClass('locked');$('input[name=program_id]').val('<?=$program['id'];?>');return false;"><?=$program['name'];?></a>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
@@ -95,26 +95,28 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($parameters[$program['id']] as $param):
|
||||
?>
|
||||
<tr>
|
||||
<td><?=$param['readable'];?></td>
|
||||
<td>
|
||||
<input type="text" name="param-<?=$param['id'];?>" class="long text" value="<?=(!empty($_POST['param-' . $param['id']]) ? $this->input->post('param-' . $param['id']) : $param['default_value']);?>" />
|
||||
<input type="text" name="param-<?=$param['id'];?>" class="long text" value="<?=(!empty($_POST['param-' . $param['id']]) ? $this->input->post('param-' . $param['id']) : (isset($copy_params[$i]['value'])) ? $copy_params[$i]['value'] : $param['default_value']);?>" />
|
||||
<?php
|
||||
if (!empty($param['description'])):
|
||||
if (!empty($param['description'])):
|
||||
?>
|
||||
<span class="form_info">
|
||||
<a href="<?=site_url('ajax/parameter_help/' . $param['id']);?>" name="<?=_('Description');?>" id="<?=$param['id'];?>" class="jtip"> </a>
|
||||
</span>
|
||||
<?php
|
||||
endif;
|
||||
endif;
|
||||
?>
|
||||
<?=form_error('params');?>
|
||||
</td>
|
||||
<td><?=$param['unit'];?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
@@ -132,4 +134,11 @@
|
||||
|
||||
</div>
|
||||
|
||||
<?php if (isset($copy['id'])): ?>
|
||||
<script type="text/javascript">
|
||||
$('#program-<?=$copy['program_id'];?>').addClass('locked');
|
||||
$('#<?=$copy['program_id'];?>-params').show();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $this->load->view('footer');?>
|
||||
|
||||
Reference in New Issue
Block a user