Extend project and trial management

This commit is contained in:
Eike Foken
2011-08-19 01:44:23 +02:00
parent 64659ca207
commit b2a9b8b087
11 changed files with 231 additions and 229 deletions

View File

@@ -201,6 +201,29 @@ $config['parameters/create'] = array(
),
);
/**
* Rules for creating trials.
*
* @var array
*/
$config['trials/create'] = array(
array(
'field' => 'name',
'label' => _('Trial name'),
'rules' => 'required|min_length[3]|max_length[60]|trim',
),
array(
'field' => 'description',
'label' => _('Description'),
'rules' => 'required|trim',
),
array(
'field' => 'program_id',
'label' => _('Program'),
'rules' => 'required|alpha_numeric|trim',
),
);
/* End of file form_validation.php */
/* Location: ./application/config/form_validation.php */

View File

@@ -1,5 +1,4 @@
<?php
/*
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
*
@@ -23,7 +22,9 @@
*/
/**
*
* @author Karsten Heiken <karsten@disposed.de>
* @author Eike Foken <kontakt@eikefoken.de>
*/
class Projects extends CI_Controller {
@@ -43,7 +44,7 @@ class Projects extends CI_Controller {
$projects = $this->project->getAll();
$tpl['projects'] = $projects;
$this->load->view('project/list', $tpl);
$this->load->view('projects/list', $tpl);
}
/**
@@ -100,7 +101,7 @@ class Projects extends CI_Controller {
$data['model']['success'] = isset($modelUploaded) && $modelUploaded ? true : false;
$data['config']['success'] = isset($configUploaded) && $configUploaded ? true: false;
$this->load->view('project/new', $data);
$this->load->view('projects/new', $data);
} else {
$data = array(
'name' => $this->input->post('name'),
@@ -112,17 +113,9 @@ class Projects extends CI_Controller {
$data['project_id'] = $this->project->create($data);
if (isset($data['project_id'])) {
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
$projectpath = $userpath . $data['project_id'] . '/';
if (!is_dir($projectpath)) {
if (!is_dir($userpath)) {
mkdir($userpath, 0777);
chmod($userpath, 0777);
}
mkdir($projectpath, 0777);
chmod($projectpath, 0777);
}
$this->load->helper('directory');
$projectPath = FCPATH.'uploads/'.$this->session->userdata('user_id').'/'.$data['project_id'].'/';
mkdirs($projectPath);
if ($modelUploaded) {
copy($modelData['full_path'], $projectpath . $modelData['file_name']);
@@ -132,10 +125,10 @@ class Projects extends CI_Controller {
}
$this->messages->add($projectpath, 'notice');
redirect('/projects/detail/' . $data['project_id'], 301);
redirect('/projects/detail/' . $data['project_id'], 303);
} else {
$this->messages->add(_('The project could not be created.'), 'error');
$this->load->view('project/new');
$this->load->view('projects/new');
}
}
}
@@ -143,22 +136,22 @@ class Projects extends CI_Controller {
/**
* Shows the project details
*
* @param integer $prj_id The ID of the project to show
* @param integer $id The ID of the project to show
*/
public function detail($prj_id) {
$project = $this->project->getById($prj_id);
public function detail($id) {
$this->load->helper('typography');
$project = $this->project->getById($id);
if (!$project) {
$this->messages->add(_('The project could not be loaded.'), 'error');
redirect('projects', 301);
redirect('projects', 303);
}
$this->session->set_userdata('active_project', $prj_id);
$trials = $this->trial->getByProjectId($prj_id);
$data['project'] = $project;
$data['trials'] = $this->trial->getByProjectId($id);
$data['jobsDone'] = null;
$tpl['project'] = $project;
$tpl['trials'] = $trials;
$tpl['jobsDone'] = null;
$this->load->view('project/detail', $tpl);
$this->load->view('projects/detail', $data);
}
/**
@@ -166,11 +159,11 @@ class Projects extends CI_Controller {
*
* @param integer $projectId
*/
public function delete($projectId) {
$this->project->delete($projectId);
$this->session->unset_userdata('active_project');
public function delete($id) {
if ($this->project->delete($id)) {
$this->messages->add(_('The project was deleted.'), 'success');
redirect('projects');
}
redirect('projects', 303);
}
}

View File

@@ -42,9 +42,13 @@ class Trials extends CI_Controller {
}
/**
* Create a new project.
* Allows users to create new trials.
*
* @param string $projectId
*/
public function create($projectId = '') {
public function create($projectId = '', $copyId = '') {
// TODO: Handle copying of trials
$project = $this->project->getByID($projectId);
if (empty($projectId) || !isset($project['id'])){
@@ -58,22 +62,8 @@ class Trials extends CI_Controller {
$parameters[$program['id']] = $this->parameter->getAll($program['id']);
}
$config = array(
array(
'field' => 'name',
'label' => _('Trial name'),
'rules' => 'required|min_length[3]|max_length[60]|trim',
),
array(
'field' => 'description',
'label' => _('Description'),
'rules' => 'required|trim',
),
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() === true) {
// TODO: handle file upload
if ($this->form_validation->run('trials/create') === true) {
// TODO: Handle file upload
$data = array(
'name' => $this->input->post('name'),
@@ -83,43 +73,32 @@ class Trials extends CI_Controller {
'creator_id' => $this->session->userdata('user_id'),
);
$result = $this->trial->create($data);
if ($result) {
$trialId = $this->trial->create($data);
if ($trialId) {
foreach ($_POST as $key => $value) {
if (preg_match('/^param-[0-9a-z]+/', $key) && !empty($value)) {
$param['parameter_id'] = substr($key, 6, 16);
$param['value'] = $this->input->post($key);
$this->trial->addParameter($param, $result);
$this->trial->addParameter($param, $trialId);
}
}
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
$projectpath = $userpath . $projectId . '/';
$trialpath = $projectpath . $result . '/';
if(!is_dir($trialpath)) {
if (!is_dir($projectpath)) {
if(!is_dir($userpath)) {
mkdir($userpath);
chmod($userpath, 0777);
}
mkdir($projectpath);
chmod($projectpath, 0777);
}
mkdir($trialpath);
chmod($trialpath, 0777);
}
$this->load->helper('directory');
$trialPath = FCPATH.'uploads/'.$this->session->userdata('user_id').'/'.$projectId.'/'. $trialId.'/';
mkdirs($trialPath);
redirect('trials/detail/' . $result, 'refresh');
redirect('trials/detail/' . $trialId, 'refresh');
} else {
$this->messages->add(_('The trial could not be created.'), 'error');
}
}
$tpl['parameters'] = $parameters;
$tpl['programs'] = $programs;
$tpl['project'] = $project;
$data = array(); // empty the data array
$data['parameters'] = $parameters;
$data['programs'] = $programs;
$data['project'] = $project;
$this->load->view('trial/new', $tpl);
$this->load->view('trial/new', $data);
}
}

View File

@@ -36,15 +36,19 @@ class Trial extends CI_Model {
* @return bool was the insert successful
*/
public function create($data) {
do {
if (!isset($data['project_id'])) {
return false;
}
do { // generate unique hash
$data['id'] = random_hash();
} while ($this->db->where('id', $data['id'])->from('trials')->count_all_results() > 0);
if ($this->db->insert('trials', $data))
if ($this->db->insert('trials', $data)) {
return $data['id'];
else
return FALSE;
} else {
return false;
}
}
/**

View File

@@ -1,93 +0,0 @@
<?php $this->load->view('header'); ?>
<div id="content">
<div class="title">
<h2><?= _('Project details') ?></h2>
</div>
<div class="box">
<h3><?= _('Description') ?></h3>
<div class="editInPlace"><?=nl2br($project['description']);?></div>
<p></p>
<h3><?= _('Trials') ?></h3>
<table class="tableList">
<thead>
<tr>
<th scope="col"><?= _('Trial') ?></th>
<th scope="col"><?= _('Jobs') ?></th>
<th scope="col"><?= _('Actions') ?></th>
</tr>
</thead>
<tbody>
<?
if(count($trials) > 0):
foreach($trials as $trial):
?>
<tr>
<td><a href="<?=site_url('trials/'.$trial['id'])?>"title="<?= sprintf(_('Show trial &quot;%s&quot'), $trial['name'])?>"><?=$trial['name']?></a></td>
<td><span class="active"><?= _('Completed') ?></span></td>
<td>
<a href="<?=site_url('trials/results/'.$trial['id'])?>" title="<?= sprintf(_('Show results for the trial &quot;%s&quot'), $trial['name'])?>"><?= _('Show results') ?></a> |
<a href="<?=site_url('trials/edit/'.$trial['id'])?>" title="<?= sprintf(_('Edit trial &quot;%s&quot;'), $trial['name']) ?>"><?= _('Edit') ?></a> |
<a href="<?=site_url('trials/delete/'.$trial['id'])?>" title="<?= sprintf(_('Delete trial &quot;%s&quot;'), $trial['name']) ?>"><?= _('Delete') ?></a></td>
</tr>
<?
endforeach;
else:
?>
<tr>
<td colspan="3"><?= _('No trials available.') ?></td>
</tr>
<?
endif;
?>
</tbody>
</table>
<p><a class="button add" href="<?=site_url('trials/create/'.$project['id'])?>"><?= _('Create a new trial') ?></a>
</div>
<div class="title">
<h2><?= _('Recent jobs') ?></h2>
</div>
<div class="box">
<table class="tableList">
<thead>
<tr>
<th scope="col"><?= _('Trial') ?></th>
<th scope="col"><?= _('Finished') ?></th>
<th scope="col"><?= _('Actions') ?></th>
</tr>
</thead>
<tbody>
<?
if(count($jobsDone) > 0):
foreach($jobsDone as $job):
?>
<tr>
<td>Versuchsname</td>
<td>Heute, 09:32</td>
<td>
<a href="<?=site_url('trials/results/'.$trial['id'])?>" title="<?= sprintf(_('Show results for the trial &quot;%s&quot'), $trial['name'])?>"><?= _('Show results') ?></a> |
<a href="<?=site_url('trials/edit/'.$trial['id'])?>" title="<?= sprintf(_('Edit trial &quot;%s&quot;'), $trial['name']) ?>"><?= _('Edit') ?></td>
</tr>
<?
endforeach;
else:
?>
<tr>
<td colspan="3"><?= _('No jobs found.') ?></td>
</tr>
<?
endif;
?>
</tbody>
</table>
</div>
</div>
<?php $this->load->view('footer'); ?>

View File

@@ -1,39 +0,0 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?= _('Project overview') ?></h2>
</div>
<div class="box">
<table class="tableList paginated sortable">
<thead>
<tr>
<th scope="col"><?= _('Project') ?></th>
<th scope="col"><?= _('Owner') ?></th>
<th scope="col"><?= _('Jobs') ?></th>
<th scope="col"><?= _('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php
foreach($projects as $project):
?>
<tr>
<td><a href="<?=site_url('projects/detail/' . $project['id'])?>"><abbr title="<?=$project['description']?>"><?=$project['name']?></abbr></a></td>
<td><?=$project['firstname'] . " " . $project['lastname']?></td>
<td><span class="active"><?= _('Successfully finished') ?></span></td>
<td><a href="#"><?= _('Show results') ?></a> | <?=anchor('projects/delete/' . $project['id'], _('Delete'));?>
</td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</div>
<?php $this->load->view('footer');?>

View File

@@ -0,0 +1,95 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?=_('Project details');?></h2>
</div>
<div class="box">
<h3><?=_('Description');?></h3>
<div class="editInPlace"><?=auto_typography($project['description']);?></div>
<p></p>
<h3><?=_('Trials');?></h3>
<table class="tableList">
<thead>
<tr>
<th scope="col"><?=_('Trial');?></th>
<th scope="col"><?=_('Jobs');?></th>
<th scope="col"><?=_('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
if (count($trials) > 0):
foreach ($trials as $trial):
?>
<tr>
<td><a href="<?=site_url('trials/' . $trial['id']);?>" title="<?=sprintf(_("Show trial '%s'"), $trial['name']);?>"><?=$trial['name'];?></a></td>
<td><span class="active"><?=_('Completed');?></span></td>
<td>
<a href="<?=site_url('trials/results/' . $trial['id']);?>" title="<?=sprintf(_('Show results for the trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Show results');?></a> |
<a href="<?=site_url('trials/create/' . $project['id'] . '/' . $trial['id']);?>" title="<?=sprintf(_('Copy trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Copy');?></a> |
<a href="<?=site_url('trials/edit/' . $trial['id']);?>" title="<?=sprintf(_('Edit trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Edit');?></a> |
<a href="<?=site_url('trials/delete/' . $trial['id']);?>" title="<?=sprintf(_('Delete trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Delete');?></a>
</td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="3"><?=_('No trials available.');?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
<p><a class="button add" href="<?=site_url('trials/create/' . $project['id']);?>"><?=_('Create a new trial');?></a>
</div>
<div class="title">
<h2><?=_('Recent jobs');?></h2>
</div>
<div class="box">
<table class="tableList">
<thead>
<tr>
<th scope="col"><?=_('Trial');?></th>
<th scope="col"><?=_('Finished');?></th>
<th scope="col"><?=_('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
if (count($jobsDone) > 0):
foreach ($jobsDone as $job):
?>
<tr>
<td>Versuchsname</td>
<td>Heute, 09:32</td>
<td>
<a href="<?=site_url('trials/results/' . $trial['id']);?>" title="<?= sprintf(_('Show results for the trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Show results');?></a> |
<a href="<?=site_url('trials/edit/' . $trial['id']);?>" title="<?= sprintf(_('Edit trial &quot;%s&quot;'), $trial['name']);?>"><?=_('Edit');?></td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="3"><?=_('No jobs found.');?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
</div>
<?php $this->load->view('footer');?>

View File

@@ -0,0 +1,39 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?=_('Project overview');?></h2>
</div>
<div class="box">
<table class="tableList paginated sortable">
<thead>
<tr>
<th scope="col"><?=_('Project');?></th>
<th scope="col"><?=_('Owner');?></th>
<th scope="col"><?=_('Jobs');?></th>
<th scope="col"><?=_('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
foreach($projects as $project):
?>
<tr>
<td><a href="<?=site_url('projects/detail/' . $project['id'] . '?active_project=' . $project['id']);?>"><abbr title="<?=$project['description'];?>"><?=$project['name'];?></abbr></a></td>
<td><?=$project['firstname'] . " " . $project['lastname'];?></td>
<td><span class="active"><?=_('Successfully finished');?></span></td>
<td><a href="#"><?=_('Show results');?></a> | <?=anchor('projects/delete/' . $project['id'], _('Delete'));?>
</td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</div>
<?php $this->load->view('footer');?>

View File

@@ -66,6 +66,7 @@
?>
<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>
<?
foreach ($programs as $program):