Implement job lists
This commit is contained in:
@@ -29,20 +29,50 @@
|
|||||||
class Jobs extends MY_Controller {
|
class Jobs extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('job');
|
$this->load->model('job');
|
||||||
$this->load->model('experiment');
|
$this->load->model('experiment');
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a job for the specified experiment.
|
* Shows a list all jobs.
|
||||||
*
|
*/
|
||||||
* @param string $experimentId
|
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
|
||||||
|
*/
|
||||||
public function start($experimentId = '') {
|
public function start($experimentId = '') {
|
||||||
$experiment = $this->experiment->getByID($experimentId);
|
$experiment = $this->experiment->getByID($experimentId);
|
||||||
if (isset($experiment['id'])) {
|
if (isset($experiment['id'])) {
|
||||||
@@ -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.
|
* 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 */
|
||||||
|
|||||||
@@ -66,6 +66,22 @@ class Job extends CI_Model {
|
|||||||
return $this->db->where('id', $job_id)->update('jobs', $data);
|
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.
|
* Gets a specific job.
|
||||||
*
|
*
|
||||||
@@ -91,7 +107,7 @@ class Job extends CI_Model {
|
|||||||
public function getRecent($projectId = '') {
|
public function getRecent($projectId = '') {
|
||||||
$this->db->select('jobs.*, experiments.project_id, experiments.name');
|
$this->db->select('jobs.*, experiments.project_id, experiments.name');
|
||||||
$this->db->join('experiments', 'jobs.experiment_id = experiments.id', 'left');
|
$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)) {
|
if (!empty($projectId)) {
|
||||||
$this->db->where('project_id', $projectId);
|
$this->db->where('project_id', $projectId);
|
||||||
@@ -99,9 +115,9 @@ class Job extends CI_Model {
|
|||||||
|
|
||||||
$jobs = $this->db->get('jobs')->result_array();
|
$jobs = $this->db->get('jobs')->result_array();
|
||||||
return array_map(function($var) {
|
return array_map(function($var) {
|
||||||
if($var['started_at'] == '0000-00-00 00:00:00') {
|
if ($var['started_at'] == '0000-00-00 00:00:00') {
|
||||||
$var['status'] = 'pending';
|
$var['status'] = 'pending';
|
||||||
} elseif($var['finished_at'] == '0000-00-00 00:00:00') {
|
} else if ($var['finished_at'] == '0000-00-00 00:00:00') {
|
||||||
$var['status'] = 'running';
|
$var['status'] = 'running';
|
||||||
} else {
|
} else {
|
||||||
$var['status'] = 'complete';
|
$var['status'] = 'complete';
|
||||||
|
|||||||
10
application/views/jobs/index.html
Executable file
10
application/views/jobs/index.html
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>403 Forbidden</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Directory access is forbidden.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
131
application/views/jobs/list.php
Normal file
131
application/views/jobs/list.php
Normal 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');?>
|
||||||
@@ -41,6 +41,11 @@ li {
|
|||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img.icon {
|
||||||
|
vertical-align: middle;
|
||||||
|
margin: 0 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.editable {
|
.editable {
|
||||||
background: #fffbcc;
|
background: #fffbcc;
|
||||||
}
|
}
|
||||||
@@ -569,6 +574,11 @@ a.copy {
|
|||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.clear {
|
||||||
|
background: url(../images/icons/broom.png) 10px center no-repeat #f3f3f3;
|
||||||
|
padding-left: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
a.job_start {
|
a.job_start {
|
||||||
background: url(../images/icons/server--arrow.png) 10px center no-repeat #f3f3f3;
|
background: url(../images/icons/server--arrow.png) 10px center no-repeat #f3f3f3;
|
||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
|
|||||||
Reference in New Issue
Block a user