show build duration on Dashboard -> Latest Builds

if a build is not pending then its duration will be displayed next to last updated time, with time units: 1h 28m 52s
This commit is contained in:
Julien Dephix 2017-03-16 13:36:48 +01:00 committed by Dmitry Khomutov
parent 89817f456f
commit 7165e8de3c
4 changed files with 52 additions and 12 deletions

View file

@ -830,7 +830,7 @@ class Build extends Model
if (empty($this->currentBuildPath)) {
$buildDirectory = $this->getId() . '_' . substr(md5(microtime(true)), 0, 5);
$this->currentBuildPath =
$this->currentBuildPath =
RUNTIME_DIR .
'builds' .
DIRECTORY_SEPARATOR .
@ -883,6 +883,32 @@ class Build extends Model
return $end->getTimestamp() - $start->getTimestamp();
}
/**
* get time a build has been running for in hour/minute/seconds format (e.g. 1h 21m 45s)
* @return string
*/
public function getPrettyDuration()
{
$start = $this->getStarted();
if (!$start) {
$start = new \DateTime();
}
$end = $this->getFinished();
if (!$end) {
$end = new \DateTime();
}
$diff = date_diff($start, $end);
$parts = [];
foreach (['y', 'm', 'd', 'h', 'i', 's'] as $time_part) {
if ($diff->{$time_part} != 0) {
$parts[] = $diff->{$time_part} . ($time_part == 'i' ? 'm' : $time_part);
}
}
return implode(" ", $parts);
}
/**
* Create a working copy by cloning, copying, or similar.
*

View file

@ -48,7 +48,14 @@
<li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?= $updated->format('H:i:s'); ?></span>
<span class="time"><i class="fa fa-clock-o"></i>
<?php
echo $updated->format('H:i:s');
if ($build->getStatus() != \PHPCensor\Model\Build::STATUS_PENDING) {
echo ' (' . $build->getPrettyDuration() . ')';
}
?>
</span>
<h3 class="timeline-header">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?>
@ -62,7 +69,7 @@
</h3>
<div class="timeline-body">
<a href="<?php echo $build->getBranchLink();?>"><?php echo $build->getProject()->getBranch(); ?></a> -
<a href="<?php echo $build->getBranchLink();?>"><?php echo $build->getProject()->getBranch(); ?></a> -
<?php
if ($build->getCommitId() !== 'Manual') {
print sprintf(

View file

@ -63,9 +63,9 @@
if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated;
?>
<li class="time-label">
<span class="bg-gray">
<?= $last->format('Y-m-d'); ?>
</span>
<span class="bg-gray">
<?= $last->format('Y-m-d'); ?>
</span>
</li>
<?php endif; ?>
@ -74,7 +74,14 @@
<li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?= $updated->format('H:i:s'); ?></span>
<span class="time"><i class="fa fa-clock-o"></i>
<?php
echo $updated->format('H:i:s');
if ($build->getStatus() != \PHPCensor\Model\Build::STATUS_PENDING) {
echo ' (' . $build->getPrettyDuration() . ')';
}
?>
</span>
<h3 class="timeline-header">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?>
@ -88,7 +95,7 @@
</h3>
<div class="timeline-body">
<a href="<?php echo $build->getBranchLink();?>"><?php echo $build->getProject()->getBranch(); ?></a> -
<a href="<?php echo $build->getBranchLink();?>"><?php echo $build->getProject()->getBranch(); ?></a> -
<?php
if ($build->getCommitId() !== 'Manual') {
print sprintf(

View file

@ -170,7 +170,7 @@
<span><?php print $group['title']; ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<?php if (count($group['projects'])): ?>
<ul class="treeview-menu">
<?php foreach($group['projects'] as $project): ?>
@ -183,10 +183,10 @@
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
<li class="treeview">
<a href="#">
<i class="fa fa-archive"></i> <span><?php Lang::out('archived_menu'); ?></span>
@ -249,7 +249,7 @@
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/jQueryUI/jquery-ui.min.js" type="text/javascript"></script>
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="<?php print APP_URL; ?>assets/vendor/raphael/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="<?php print APP_URL; ?>assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/chartjs/Chart.min.js" type="text/javascript"></script>
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>