Fix trial creation

This commit is contained in:
Eike Foken
2011-09-08 00:10:52 +02:00
parent 7b98b416ee
commit 33e116ed60
3 changed files with 68 additions and 55 deletions

View File

@@ -255,6 +255,11 @@ $config['trials/create'] = array(
'label' => _('Program'), 'label' => _('Program'),
'rules' => 'required|alpha_numeric|trim', 'rules' => 'required|alpha_numeric|trim',
), ),
array(
'field' => '3dmodel',
'label' => _('3D model'),
'rules' => 'file_allowed_type[obj]',
),
); );
/* End of file form_validation.php */ /* End of file form_validation.php */

View File

@@ -35,7 +35,6 @@ class Trials extends CI_Controller {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->load->library('form_validation'); $this->load->library('form_validation');
$this->load->library('upload');
$this->load->model('parameter'); $this->load->model('parameter');
$this->load->model('program'); $this->load->model('program');
$this->load->model('project'); $this->load->model('project');
@@ -63,18 +62,17 @@ class Trials extends CI_Controller {
$parameters[$program['id']] = $this->parameter->getAll($program['id']); $parameters[$program['id']] = $this->parameter->getAll($program['id']);
} }
if ($this->form_validation->run('trials/create') === true) { if (is_null($project['default_model'])) {
$config = array( $this->load->config('form_validation');
'upload_path' => '/tmp', foreach ($this->config->item('trials/create') as $rule) { // restore old rules
'allowed_types' => '*', $this->form_validation->set_rules($rule['field'], $rule['label'], $rule['rules']);
'max_size' => 64*1024, // set maximum file size to 64 megabytes }
'file_name' => 'default',
);
$this->upload->initialize($config);
if (!$this->upload->do_upload('3dmodel')) { $this->form_validation->set_rules('3dmodel', _('3d model'), 'file_required|file_allowed_type[obj]');
$this->messages->add(_('There was an error while uploading the selected 3d model.'), 'error'); }
} else {
// run form validation
if ($this->form_validation->run('trials/create') === true) {
$data = array( $data = array(
'name' => $this->input->post('name'), 'name' => $this->input->post('name'),
'description' => $this->input->post('description'), 'description' => $this->input->post('description'),
@@ -83,37 +81,48 @@ class Trials extends CI_Controller {
'creator_id' => $this->session->userdata('user_id'), 'creator_id' => $this->session->userdata('user_id'),
); );
$trialId = $this->trial->create($data); $data['trial_id'] = $this->trial->create($data);
if ($trialId) {
if (isset($data['trial_id'])) {
$this->load->helper('directory');
$trialPath = FCPATH . 'uploads/' . $projectId . '/' . $data['trial_id'] . '/';
mkdirs($trialPath);
$config = array(
'upload_path' => $trialPath,
'allowed_types' => '*',
'overwrite' => true,
'file_name' => 'default',
);
$this->load->library('upload', $config);
if ($_FILES['3dmodel']['tmp_name'] != '') {
if ($this->upload->do_upload('3dmodel')) {
$model = $this->upload->data();
} else {
$this->messages->add(_('The selected model could not be uploaded.'), 'error');
}
}
// save parameters to db
foreach ($_POST as $key => $value) { foreach ($_POST as $key => $value) {
if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) { if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) {
$param['parameter_id'] = substr($key, 6, 16); $param['parameter_id'] = substr($key, 6, 16);
$param['value'] = $this->input->post($key); $param['value'] = $this->input->post($key);
$this->trial->addParameter($param, $trialId); $this->trial->addParameter($param, $data['trial_id']);
} }
} }
$this->load->helper('directory'); // TODO: Don't start jobs automatically
$trialPath = FCPATH . 'uploads/' . $projectId . '/' . $trialId . '/';
mkdirs($trialPath);
$model = $this->upload->data();
if (!copy($model['full_path'], $trialPath . $model['file_name'])) {
$this->messages->add(_('The selected 3d model could not be copied to trial path.'), 'error');
}
$program = $this->program->getById($data['program_id']); $program = $this->program->getById($data['program_id']);
$this->load->library('program_runner', array('program_driver' => $program['driver'])); $this->load->library('program_runner', array('program_driver' => $program['driver']));
$this->program_runner->createJob($trialId); $this->program_runner->createJob($data['trial_id']);
//redirect('trials/detail/' . $trialId, 'refresh'); redirect('/projects/detail/' . $projectId, 303);
redirect('projects/detail/' . $projectId, 303);
} else { } else {
$this->messages->add(_('The trial could not be created.'), 'error'); $this->messages->add(_('The trial could not be created.'), 'error');
} }
} }
}
$data = array(); // empty the data array $data = array(); // empty the data array
$data['parameters'] = $parameters; $data['parameters'] = $parameters;

View File

@@ -21,29 +21,28 @@
</li> </li>
<li> <li>
<?=form_label(_('Description'), 'description');?> <?=form_label(_('Description'), 'description');?>
<span class="req">*</span> <span class="req">*</span><br />
<label class="note"><?=_('A description is useful if you want to share this trial with co-workers.');?></label>
<div> <div>
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description');?></textarea> <textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description');?></textarea>
<?=form_error('description');?> <?=form_error('description');?>
</div> </div>
<label class="note"><?=_('A description is useful if you want to share this trial with co-workers.');?></label>
</li> </li>
<li> <li>
<h4><?=_('3D model');?></h4> <h4><?=_('3D model');?></h4>
<? <?php
if (file_exists(FCPATH.'uploads/'.$project['id'].'/default.txt')): if (!is_null($project['default_model'])):
?> ?>
<div class="notice"> <div class="notice">
<strong><?=_('There is a default model set for this project.');?></strong><br /> <strong><?=_('There is a default model set for this project.');?></strong><br />
<?=_('If you want to use a different model for this trial, you can upload it here.');?> <?=_('If you want to use a different model for this trial, you can upload it here.');?>
</div> </div>
<? <?php
endif; endif;
?> ?>
<div> <div>
<input type="file" class="file" name="3dmodel" value="<?=set_value('3dmodel');?>" /> <input type="file" class="file" name="3dmodel" value="<?=set_value('3dmodel');?>" />
<?=form_error('3dmodel');?> <?=form_error('3dmodel');?>
<?=$this->upload->display_errors('<span class="error">', '</span>');?>
</div> </div>
</li> </li>
</ul> </ul>
@@ -52,30 +51,30 @@
<div class="box"> <div class="box">
<h3><?=_('Application-specific parameters');?></h3> <h3><?=_('Application-specific parameters');?></h3>
<? <?php
if (isset($defaultconfig)): if (!is_null($project['default_config'])):
?> ?>
<div class="notice"> <div class="notice">
<strong><?=_('There is a default configuration set for this project.');?></strong><br /> <strong><?=_('There is a default configuration set for this project.');?></strong><br />
<?=_('This form contains the default values. You can adjust them for this trial.');?><br /> <?=_('This form contains the default values. You can adjust them for this trial.');?><br />
<?=_('The default configuration will not be modified.');?> <?=_('The default configuration will not be modified.');?>
</div> </div>
<? <?php
endif; endif;
?> ?>
<h4><?=_('Application to use for the computation');?></h4> <h4><?=_('Application to use for the computation');?></h4>
<input type="hidden" name="program_id" id="program_id" value="<?=set_value('program_id');?>" /> <input type="hidden" name="program_id" id="program_id" value="<?=set_value('program_id');?>" />
<?=form_error('program_id');?> <?=form_error('program_id');?>
<p> <p>
<? <?php
foreach ($programs as $program): 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" 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; endforeach;
?> ?>
</p> </p>
<? <?php
foreach ($programs as $program): foreach ($programs as $program):
?> ?>
@@ -91,7 +90,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<? <?php
foreach ($parameters[$program['id']] as $param): foreach ($parameters[$program['id']] as $param):
?> ?>
<tr> <tr>
@@ -111,14 +110,14 @@
</td> </td>
<td><?=$param['unit'];?></td> <td><?=$param['unit'];?></td>
</tr> </tr>
<? <?php
endforeach; endforeach;
?> ?>
</tbody> </tbody>
</table> </table>
</p> </p>
</div> </div>
<? <?php
endforeach; endforeach;
?> ?>
<p> <p>