Implement job lists

This commit is contained in:
Eike Foken
2011-09-20 22:35:24 +02:00
parent aebde4aa79
commit 4b2ca67e68
5 changed files with 236 additions and 13 deletions

View File

@@ -39,7 +39,37 @@ class Jobs extends MY_Controller {
}
/**
* Starts a job for the specified experiment.
* Shows a list all jobs.
*/
public function index() {
$jobs = $this->job->getRecent();
$data['running_jobs'] = array();
foreach ($jobs as $job) {
if ($job['status'] == 'running' && $job['started_by'] == $this->session->userdata('user_id')) {
$data['running_jobs'][] = $job;
}
}
$data['finished_jobs'] = array();
foreach ($jobs as $job) {
if ($job['status'] == 'complete' && $job['started_by'] == $this->session->userdata('user_id')) {
$data['finished_jobs'][] = $job;
}
}
$data['pending_jobs'] = array();
foreach ($jobs as $job) {
if ($job['status'] == 'pending' && $job['started_by'] == $this->session->userdata('user_id')) {
$data['pending_jobs'][] = $job;
}
}
$this->load->view('jobs/list', $data);
}
/**
* Allows users to start a job for the specified experiment.
*
* @param string $experimentId
*/
@@ -57,6 +87,29 @@ class Jobs extends MY_Controller {
}
}
/**
* Allows users to cancel the specified job.
*
* @param string $jobId
*/
public function cancel($jobId) {
$this->job->delete($jobId);
redirect('jobs');
}
/**
* Allows users to mark all finished jobs as seen.
*/
public function mark_all_seen() {
$jobs = $this->job->getRecent();
foreach ($jobs as $job) {
if ($job['status'] == 'complete' && $job['started_by'] == $this->session->userdata('user_id')) {
$this->job->markSeen($job['id']);
}
}
redirect('jobs', 303);
}
/**
* Get jobs belonging to projects owned by the user.
*/
@@ -114,3 +167,6 @@ class Jobs extends MY_Controller {
));
}
}
/* End of file jobs.php */
/* Location: ./application/controllers/jobs.php */

View File

@@ -66,6 +66,22 @@ class Job extends CI_Model {
return $this->db->where('id', $job_id)->update('jobs', $data);
}
/**
* Marks a finished job as seen.
*
* @param string $jobId
* @return boolean Returns TRUE on success.
*/
public function markSeen($jobId) {
$this->db->where('started_by', $this->session->userdata('user_id'));
$this->db->where('finished_at !=', 0);
$this->db->where('id', $jobId);
$query = $this->db->update('jobs', array('seen' => 1));
return $this->db->affected_rows() > 0;
}
/**
* Gets a specific job.
*
@@ -91,7 +107,7 @@ class Job extends CI_Model {
public function getRecent($projectId = '') {
$this->db->select('jobs.*, experiments.project_id, experiments.name');
$this->db->join('experiments', 'jobs.experiment_id = experiments.id', 'left');
//$this->db->where('finished_at', 0);
$this->db->order_by('created_at DESC');
if (!empty($projectId)) {
$this->db->where('project_id', $projectId);

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,131 @@
<?php $this->load->view('header');?>
<div id="content">
<div class="title">
<h2><?=_('Jobs');?></h2>
</div>
<ul class="tabs">
<li class="active"><a href="#finished"><?=sprintf(ngettext('%d finished job', '%d finished jobs', count($finished_jobs)), count($finished_jobs));?></a></li>
<li><a href="#running"><?=sprintf(ngettext('%d running job', '%d running jobs', count($running_jobs)), count($running_jobs));?></a></li>
<li><a href="#pending"><?=sprintf(ngettext('%d pending job', '%d pending jobs', count($pending_jobs)), count($pending_jobs));?></a></li>
</ul>
<div class="tab_container">
<div id="finished" class="tab_content">
<h3><?=_('List of all finished jobs');?></h3>
<table class="tableList">
<thead>
<tr>
<th scope="col"><?=_('Name');?></th>
<th scope="col"><?=_('Finished at');?></th>
<th scope="col"><?=_('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
if (count($finished_jobs) > 0):
foreach ($finished_jobs as $job):
?>
<tr>
<td>
<?=anchor('experiments/detail/' . $job['experiment_id'], $job['name']);?>
<?=($job['seen'] == 0) ? image_asset('icons/new-text.png', 'class="icon"') : '';?>
</td>
<td><?=relative_time($job['finished_at']);?></td>
<td>
<a href="<?=site_url('results/experiment/' . $job['experiment_id']);?>" title="<?= sprintf(_('Show results for this experiment'), $job['name']);?>"><?=_('Show results');?></a>
</td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="3"><?=_('No finished jobs found.');?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
<h3><?=_('Actions');?></h3>
<p>
<a href="<?=site_url('jobs/mark_all_seen');?>" class="button"><?=_('Mark all as seen');?></a>
<a class="button disabled search"><?=_('Search job');?></a>
</p>
</div>
<div id="running" class="tab_content">
<h3><?=_('List of all running jobs');?></h3>
<table class="tableList">
<thead>
<tr>
<th scope="col"><?=_('Name');?></th>
<th scope="col"><?=_('Started at');?></th>
<th scope="col"><?=_('Progress');?></th>
</tr>
</thead>
<tbody>
<?php
if (count($running_jobs) > 0):
foreach ($running_jobs as $job):
?>
<tr>
<td><?=anchor('experiments/detail/' . $job['experiment_id'], $job['name']);?></td>
<td><?=relative_time($job['started_at']);?></td>
<td><?=$job['progress'];?>%</td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="3"><?=_('No running jobs found.');?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
<div id="pending" class="tab_content">
<h3><?=_('List of all pending jobs');?></h3>
<table class="tableList">
<thead>
<tr>
<th scope="col"><?=_('Name');?></th>
<th scope="col"><?=_('Created at');?></th>
<th scope="col"><?=_('Actions');?></th>
</tr>
</thead>
<tbody>
<?php
if (count($pending_jobs) > 0):
foreach ($pending_jobs as $job):
?>
<tr>
<td><?=anchor('experiments/detail/' . $job['experiment_id'], $job['name']);?></td>
<td><?=relative_time($job['created_at']);?></td>
<td>
<?=anchor('jobs/cancel/' . $job['id'], _('Cancel'));?>
</td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="3"><?=_('No pending jobs found.');?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
</div>
</div>
<?php $this->load->view('footer');?>

View File

@@ -41,6 +41,11 @@ li {
margin-left: 20px;
}
img.icon {
vertical-align: middle;
margin: 0 2px;
}
.editable {
background: #fffbcc;
}
@@ -569,6 +574,11 @@ a.copy {
padding-left: 30px;
}
a.clear {
background: url(../images/icons/broom.png) 10px center no-repeat #f3f3f3;
padding-left: 30px;
}
a.job_start {
background: url(../images/icons/server--arrow.png) 10px center no-repeat #f3f3f3;
padding-left: 30px;