Merge branch 'master' of disposed.de:scattport

This commit is contained in:
Eike Foken
2011-09-10 12:42:09 +02:00
15 changed files with 212 additions and 51 deletions

View File

@@ -27,7 +27,7 @@
class Dashboard extends CI_Controller { class Dashboard extends CI_Controller {
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
@@ -35,7 +35,46 @@ class Dashboard extends CI_Controller {
} }
public function index() { public function index() {
$this->load->view('dashboard'); $tpl['action_buttons'] = array(
array(
'icon' => 'tango/folder-new.png',
'text' => _('New project'),
'target' => site_url('projects/create'),
),
array(
'icon' => 'tango/document-open.png',
'text' => _('Recent results'),
'target' => site_url('jobs/results'),
),
);
$tpl['recent_buttons'] = array(
array(
'count' => 4,
'text' => _('Jobs finished'),
'title' => sprintf(_('%d jobs finished recently'), 3),
'target' => '#',
),
array(
'count' => 2,
'text' => _('Newly shared projects'),
'title' => sprintf(_('You were invited to join %d projects'), 2),
'target' => '#',
),
array(
'count' => 1,
'text' => _('Job running'),
'title' => sprintf(_('There is %d job currently running'), 1),
'target' => '#',
),
array(
'count' => 2,
'text' => _('Jobs pending'),
'title' => sprintf(_('There are %2 job currently pending'), 1),
'target' => '#',
),
);
$this->load->view('dashboard', $tpl);
} }
} }

View File

@@ -108,7 +108,9 @@ class Xmlrpc extends CI_Controller {
$update = array( $update = array(
'os' => $parameters[0], 'os' => $parameters[0],
'workload' => $parameters[1], 'uptime' => $parameters[1],
'workload' => $parameters[3],
'hardware' => $parameters[2],
'last_update' => mysql_now() 'last_update' => mysql_now()
); );
$this->server->update($server->id, $update); $this->server->update($server->id, $update);

View File

@@ -35,5 +35,68 @@ if ( ! function_exists('mysql_now'))
} }
} }
/**
* Function to calculate date or time difference.
*
* Function to calculate date or time difference. Returns an array or
* false on error.
*
* @author J de Silva <giddomains@gmail.com>
* @copyright Copyright &copy; 2005, J de Silva
* @link http://www.gidnetwork.com/b-16.html Get the date / time difference with PHP
* @param string $start
* @param string $end
* @return array
*/
if ( ! function_exists('time_diff'))
{
function time_diff($start, $end)
{
$uts['start'] = strtotime($start);
$uts['end'] = strtotime($end);
if ($uts['start'] !== -1 && $uts['end'] !== -1) {
if ($uts['end'] >= $uts['start']) {
$diff = $uts['end'] - $uts['start'];
$diff = intval($diff);
return ($diff);
}
}
return (false);
}
}
/**
* Function to convert seconds to a pretty string.
*
* @author Karsten Heiken <karsten@disposed.de>
* @param integer $secs the amount of seconds
* @param boolean $includeseconds should seconds be appended to the string?
* @return string
*/
if ( ! function_exists('secondsToString'))
{
function secondsToString($secs, $includeseconds = false)
{
$days = intval($secs / 86400);
$hours = intval($secs / 3600 % 24);
$minutes = intval($secs / 60 % 60);
$seconds = intval($secs % 60);
if (($minutes + $hours + $days) < 1)
return (sprintf(_('%d seconds'), $seconds));
else if (($minutes + $hours) < 1)
$string = sprintf(_('%d minutes'), $minutes);
else if ($days < 1)
$string = sprintf(_('%d hours, %d minutes'), $hours, $minutes);
else
$string = sprintf(_('%d days, %d hours, %d minutes'), $days, $hours,
$minutes);
if ($includeseconds)
$string .= ' ' . sprintf(_('and %d seconds'), $seconds);
return $string;
}
}
/* End of file MY_date_helper.php */ /* End of file MY_date_helper.php */
/* Location: ./application/helpers/MY_date_helper.php */ /* Location: ./application/helpers/MY_date_helper.php */

View File

@@ -81,7 +81,17 @@ class Job extends CI_Model {
$this->db->where('project_id', $projectId); $this->db->where('project_id', $projectId);
} }
return $this->db->get('jobs')->result_array(); $jobs = $this->db->get('jobs')->result_array();
return array_map(function($var) {
if($var['started_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'pending';
} elseif($var['finished_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'running';
} else {
$var['status'] = 'complete';
}
return $var;
}, $jobs);
} }
/** /**

View File

@@ -52,7 +52,11 @@ class Server extends CI_Model {
* @return array List of all available servers. * @return array List of all available servers.
*/ */
public function getAll() { public function getAll() {
return $this->db->get('servers')->result_array(); $servers = $this->db->get('servers')->result_array();
return array_map(function($var) {
$var['available'] = time_diff($var['last_update'], mysql_now()) < 120 ? true : false;
return $var;
}, $servers);
} }
/** /**
@@ -97,7 +101,12 @@ class Server extends CI_Model {
* @param string $serverId * @param string $serverId
*/ */
public function getById($serverId) { public function getById($serverId) {
return $this->db->get_where('servers', array('id' => $serverId))->row(); $this->load->helper('date');
$server = $this->db->get_where('servers', array('id' => $serverId))->row();
$server->uptimestring = secondsToString($server->uptime);
$server->lastheartbeat = sprintf(_('%s ago'),
secondsToString(time_diff($server->last_update, mysql_now())));
return $server;
} }
} }

View File

@@ -17,10 +17,11 @@
<h3>Technical information</h3> <h3>Technical information</h3>
<h4>Hardware &amp; OS</h4> <h4>Hardware &amp; OS</h4>
<p> <p>
CPU: Intel Xeon E5540, 2533 MHz<br /> CPU: <?=$server->hardware;?><br />
Uptime: 254 Tage, 13 Stunden<br /> Uptime: <?=$server->uptimestring;?><br />
OS: Debian/GNU 5.0r1<br /> OS: <?=$server->os;?><br />
Workload: 2.01, 1.05, 0.85 Workload: <?=sprintf('%.02f', $server->workload);?><br />
Last heartbeat: <?=$server->lastheartbeat;?>
</p> </p>
<h4>ScattPort-Statistics</h4> <h4>ScattPort-Statistics</h4>

View File

@@ -21,7 +21,7 @@
<? <?
foreach ($servers as $server): foreach ($servers as $server):
if ($server['available']) { if ($server['available']) {
if ($server['workload'] > 2) { if ($server['workload'] > 0.8) {
$server['class'] = "pending"; $server['class'] = "pending";
$server['status'] = 'busy'; $server['status'] = 'busy';
} else { } else {

View File

@@ -1,30 +1,63 @@
<?php $this->load->view('header');?> <?php $this->load->view('header');?>
<div id="content"> <div id="content">
<div id="dashboard">
<div class="title"> <div class="title">
<h2><?=_('Dashboard');?></h2> <h2><?=_('Dashboard');?></h2>
</div>
<div class="box">
<h3><?=_('Quick actions');?></h3>
<p>
<?
if(count($action_buttons) > 0):
$i = 1;
foreach ($action_buttons as $button):
if($i == 1 && (count($action_buttons) == 1))
$button['class'] = '';
elseif($i == count($action_buttons))
$button['class'] = 'right';
elseif($i == 1)
$button['class'] = 'left';
else
$button['class'] = 'middle';
?><a class="button <?=$button['class'];?> big" href="<?=$button['target'];?>"><strong><?=image_asset($button['icon']);?></strong><br /><?=$button['text'];?></a><?
$i++;
endforeach;
endif;
?>
</p>
</div>
<div class="box">
<h3><?=_('Recent events');?></h3>
<p>
<?
if(count($recent_buttons) > 0):
$i = 1;
foreach ($recent_buttons as $button):
if($i == 1 && (count($recent_buttons) == 1))
$button['class'] = '';
elseif($i == count($recent_buttons))
$button['class'] = 'right';
elseif($i == 1)
$button['class'] = 'left';
else
$button['class'] = 'middle';
?><a class="button <?=$button['class'];?> big" href="<?=$button['target'];?>" title="<?=$button['title'];?>"><strong><?=$button['count'];?></strong><br /><?=$button['text'];?></a><?
$i++;
endforeach;
endif;
?>
</p>
</div>
<div class="box">
<h3><?=_('Administration');?></h3>
<p>
<a class="button left big" href="#"><?=_('Manage servers');?></a><a class="button middle big" href="<?=site_url('admin/programs');?>"><?=_('Manage programs');?></a><a class="button right big" href="<?=site_url('admin/users');?>"><?=_('Manage users');?></a>
</p>
</div>
</div> </div>
<div class="box">
<h3><?=_('Projects');?></h3>
<p>
<a class="button left big" href="projects/create"><?=_('Create a project');?></a><a class="button middle big" href="projects"><?=_('Show projects');?></a><a class="button right big" href="#"><?=_('Search projects');?></a>
</p>
</div>
<div class="box">
<h3><?=_('Experiments');?></h3>
<p>
<a class="button left big" href="#"><?=_('Newest results');?></a><a class="button middle big" href="#"><?=_('Running jobs');?></a>
</p>
</div>
<div class="box">
<h3><?=_('Administration');?></h3>
<p>
<a class="button left big" href="#"><?=_('Manage servers');?></a><a class="button middle big" href="<?=site_url('admin/programs');?>"><?=_('Manage programs');?></a><a class="button right big" href="<?=site_url('admin/users');?>"><?=_('Manage users');?></a>
</p>
</div>
</div> </div>
<?php $this->load->view('footer');?> <?php $this->load->view('footer');?>

View File

@@ -175,16 +175,4 @@
</form> </form>
</div> </div>
<div class="title">
<h2><?=_('Recent events');?></h2>
</div>
<div class="box">
<ul id="blog">
<li><h4><a href="#" title="<?=_('Calculation done');?>"><?=_('Calculation done');?></a> <abbr title="22.07.2011">22.07.2011</abbr></h4><p><?=sprintf(_('Calculation successfully finished for project &quot;%s&quot;'), 'Gerstenkorn');?></i></p></li>
<li><h4><a href="#" title="<?=_('Calculation done');?>"><?=_('Calculation done');?></a> <abbr title="22.07.2011">22.07.2011</abbr></h4><p><?=sprintf(_('Calculation successfully finished for project &quot;%s&quot;'), 'Gerstenkorn');?></i></p></li>
<li><h4><a href="#" title="<?=_('Calculation done');?>"><?=_('Calculation done');?></a> <abbr title="22.07.2011">22.07.2011</abbr></h4><p><?=sprintf(_('Calculation successfully finished for project &quot;%s&quot;'), 'Gerstenkorn');?></i></p></li>
</ul>
</div>
</div> </div>

View File

@@ -88,8 +88,7 @@
<thead> <thead>
<tr> <tr>
<th scope="col"><?=_('Experiment');?></th> <th scope="col"><?=_('Experiment');?></th>
<th scope="col"><?=_('Started');?></th> <th scope="col"><?=_('Status');?></th>
<th scope="col"><?=_('Finished');?></th>
<th scope="col"><?=_('Actions');?></th> <th scope="col"><?=_('Actions');?></th>
</tr> </tr>
</thead> </thead>
@@ -97,11 +96,20 @@
<?php <?php
if (count($jobs) > 0): if (count($jobs) > 0):
foreach ($jobs as $job): foreach ($jobs as $job):
if($job['status'] == 'pending') {
$job['humanstatus'] = _('Pending');
$job['cssclass'] = 'closed';
} elseif($job['status'] == 'running') {
$job['humanstatus'] = _('Simulation running');
$job['cssclass'] = 'pending';
} elseif($job['status'] == 'complete') {
$job['humanstatus'] = _('Simulation complete');
$job['cssclass'] = 'active';
}
?> ?>
<tr> <tr>
<td><?=$job['name'];?></td> <td><?=$job['name'];?></td>
<td><?=$job['started_at'];?></td> <td><span class="<?=$job['cssclass'];?>"><?=$job['humanstatus'];?></span></td>
<td><?=$job['finished_at'] != '0000-00-00 00:00:00' ? $job['finished_at'] : _('Currently running');?></td>
<td> <td>
<a href="<?=site_url('experiments/results/' . $job['id']);?>" title="<?= sprintf(_('Show results for this experiment'), $job['name']);?>"><?=_('Show results');?></a> | <a href="<?=site_url('experiments/results/' . $job['id']);?>" title="<?= sprintf(_('Show results for this experiment'), $job['name']);?>"><?=_('Show results');?></a> |
<a href="<?=site_url('experiments/edit/' . $job['id']);?>" title="<?= sprintf(_('Edit this experiment'), $job['name']);?>"><?=_('Edit');?></td> <a href="<?=site_url('experiments/edit/' . $job['id']);?>" title="<?= sprintf(_('Edit this experiment'), $job['name']);?>"><?=_('Edit');?></td>

View File

@@ -676,3 +676,11 @@ html ul.tabs li.active a:hover {
.jtip { .jtip {
cursor: help; cursor: help;
} }
#dashboard a.button {
text-align: center;
}
#dashboard a.button strong {
font-size: 2.5em;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1008 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB