Added ajax for the dashboard and timeline on main page
This commit is contained in:
parent
3f80c8e4ba
commit
40b5de70e5
15 changed files with 415 additions and 212 deletions
132
src/PHPCensor/View/Home/ajax-dashboard-project.phtml
Normal file
132
src/PHPCensor/View/Home/ajax-dashboard-project.phtml
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$statuses = [];
|
||||
$failures = 0;
|
||||
$subcls = 'yellow';
|
||||
$cls = '';
|
||||
$success = null;
|
||||
$failure = null;
|
||||
|
||||
if (count($builds)) {
|
||||
// Get the most recent build status to determine the main block colour.
|
||||
$last_build = $builds[0];
|
||||
$status = $last_build->getStatus();
|
||||
switch($status) {
|
||||
case 0:
|
||||
$subcls = 'blue';
|
||||
break;
|
||||
case 1:
|
||||
$subcls = 'yellow';
|
||||
break;
|
||||
case 2:
|
||||
$subcls = 'green';
|
||||
break;
|
||||
case 3:
|
||||
$subcls = 'red';
|
||||
break;
|
||||
}
|
||||
// Use the last 5 builds to determine project health:
|
||||
$failures = 0;
|
||||
|
||||
foreach ($builds as $build) {
|
||||
switch ($build->getStatus()) {
|
||||
case 0:
|
||||
$statuses[] = 'pending';
|
||||
break;
|
||||
case 1:
|
||||
$statuses[] = 'running';
|
||||
break;
|
||||
case 2:
|
||||
$statuses[] = 'ok';
|
||||
$success = is_null($success) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $success;
|
||||
break;
|
||||
case 3:
|
||||
$failures++;
|
||||
$statuses[] = 'failed';
|
||||
$failure = is_null($failure) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $failure;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$buildCount = count($builds);
|
||||
$lastSuccess = $successful;
|
||||
$lastFailure = $failed;
|
||||
$message = Lang::get('no_builds_yet');
|
||||
$shortMessage = Lang::get('no_builds_yet');
|
||||
|
||||
if ($buildCount > 0) {
|
||||
if ($failures > 0) {
|
||||
$shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount);
|
||||
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
|
||||
|
||||
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
|
||||
$message .= Lang::get('last_successful_build', Lang::formatDateTime($lastSuccess->getFinished()));
|
||||
} else {
|
||||
$message .= Lang::get('never_built_successfully');
|
||||
}
|
||||
} else {
|
||||
$message = Lang::get('all_builds_passed', $buildCount);
|
||||
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
|
||||
|
||||
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
|
||||
$message .= Lang::get('last_failed_build', Lang::formatDateTime($lastFailure->getFinished()));
|
||||
} else {
|
||||
$message .= Lang::get('never_failed_build');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="small-box small-box-full bg-<?php print $subcls; ?>">
|
||||
|
||||
<div class="inner">
|
||||
<h3>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
|
||||
<?php print $project->getTitle(); ?>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
<?php print $message; ?>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
|
||||
</div>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer small-box-footer-project">
|
||||
<?php Lang::out('view_project'); ?> (<?php print $counts; ?>) <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
|
||||
<?php for ($idx=0; $idx < 5; $idx++) {
|
||||
if (empty($builds[$idx])) {
|
||||
echo '<span class="small-box-footer-build small-box-footer bg-blue"><i class="fa fa-minus"></i></span>';
|
||||
} else {
|
||||
$build = $builds[$idx];
|
||||
$link = APP_URL . 'build/view/' . $build->id;
|
||||
switch ($build->getStatus()) {
|
||||
case 0:
|
||||
$class = 'bg-blue';
|
||||
$icon = 'fa-minus';
|
||||
break;
|
||||
case 1:
|
||||
$class = 'bg-yellow';
|
||||
$icon = 'fa-clock-o';
|
||||
break;
|
||||
case 2:
|
||||
$class = 'bg-green';
|
||||
$icon = 'fa-check';
|
||||
break;
|
||||
case 3:
|
||||
$class = 'bg-red';
|
||||
$icon = 'fa-times';
|
||||
break;
|
||||
}
|
||||
echo '<a href="' . $link .'" class="small-box-footer-build small-box-footer ' . $class . '"><i class="fa ' . $icon . '"></i></a>';
|
||||
}
|
||||
} ?>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
88
src/PHPCensor/View/Home/ajax-timeline.phtml
Normal file
88
src/PHPCensor/View/Home/ajax-timeline.phtml
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<ul class="timeline">
|
||||
<?php $last = new \DateTime('-1 Year'); ?>
|
||||
|
||||
<?php
|
||||
foreach ($builds as $build):
|
||||
switch ($build->getStatus()) {
|
||||
case \PHPCensor\Model\Build::STATUS_NEW:
|
||||
$updated = $build->getCreated();
|
||||
$label = Lang::get('pending');
|
||||
$color = 'blue';
|
||||
break;
|
||||
|
||||
case \PHPCensor\Model\Build::STATUS_RUNNING:
|
||||
$updated = $build->getStarted();
|
||||
$label = Lang::get('running');
|
||||
$color = 'yellow';
|
||||
break;
|
||||
|
||||
case \PHPCensor\Model\Build::STATUS_SUCCESS:
|
||||
$updated = $build->getFinished();
|
||||
$label = Lang::get('success');
|
||||
$color = 'green';
|
||||
break;
|
||||
|
||||
case \PHPCensor\Model\Build::STATUS_FAILED:
|
||||
$updated = $build->getFinished();
|
||||
$label = Lang::get('failed');
|
||||
$color = 'red';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$updated) {
|
||||
$updated = $build->getCreated();
|
||||
}
|
||||
|
||||
if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated;
|
||||
?>
|
||||
<li class="time-label">
|
||||
<span class="bg-gray">
|
||||
<?php print Lang::formatDateTime($last, 'll'); ?>
|
||||
</span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- /.timeline-label -->
|
||||
<!-- timeline item -->
|
||||
<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> <?php print Lang::formatDateTime($updated, 'LT'); ?></span>
|
||||
<h3 class="timeline-header">
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
|
||||
<?php print $build->getProject()->getTitle(); ?>
|
||||
</a>
|
||||
-
|
||||
<a href="<?php print APP_URL; ?>build/view/<?php print $build->getId(); ?>">
|
||||
Build #<?php print $build->getId(); ?>
|
||||
</a>
|
||||
-
|
||||
<?php print $label; ?>
|
||||
</h3>
|
||||
|
||||
<div class="timeline-body">
|
||||
<?php
|
||||
if ($build->getCommitId() !== 'Manual') {
|
||||
print sprintf(
|
||||
'<a href="%s" target="_blank">%s (%s)</a>',
|
||||
$build->getCommitLink(),
|
||||
substr($build->getCommitId(), 0, 7),
|
||||
$build->getCommitterEmail()
|
||||
);
|
||||
} else {
|
||||
print Lang::get('manual_build');
|
||||
}
|
||||
?>
|
||||
- <?php print $build->getCommitMessage(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<!-- END timeline item -->
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<li>
|
||||
<i class="fa fa-clock-o"></i>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -80,7 +80,7 @@ foreach($projects as $project):
|
|||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="project-box" id="project-box-<?php print $project->getId(); ?>">
|
||||
<div class="small-box small-box-full bg-<?php print $subcls; ?>">
|
||||
|
||||
<div class="inner">
|
||||
|
|
@ -131,5 +131,6 @@ foreach($projects as $project):
|
|||
} ?>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
<h3 class="box-title"><?php Lang::out('latest_builds'); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<div class="box-body" id="timeline-box">
|
||||
<ul class="timeline">
|
||||
<?php $last = new \DateTime('-1 Year'); ?>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
|
||||
<div class="alert alert-danger">
|
||||
<p><strong>Adding requirements to the PHP Censor composer.json file is no longer recommended as a method of installing your required testing tools.</strong><br>
|
||||
For this reason, we have removed the ability for PHP Censor to modify the composer.json file for you.
|
||||
We recommend that you install testing tools using your project's own composer.json file, by adding them to the "require-dev" section of the file.</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="box">
|
||||
<div class="box-header">
|
||||
<h3 class="box-title"><?php Lang::out('enabled_plugins'); ?></h3>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php Lang::out('name'); ?></th>
|
||||
<th><?php Lang::out('class'); ?></th>
|
||||
<th><?php Lang::out('provided_by_package'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($plugins as $plugin): ?>
|
||||
<tr>
|
||||
<td><?php print $plugin->name; ?></td>
|
||||
<td><?php print $plugin->class; ?></td>
|
||||
<td><?php print $plugin->source; ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="box">
|
||||
<div class="box-header">
|
||||
<h3 class="box-title"><?php Lang::out('installed_packages'); ?></h3>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php Lang::out('title'); ?></th>
|
||||
<th><?php Lang::out('version'); ?></th>
|
||||
<th width="1"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($installedPackages as $package => $version): ?>
|
||||
<tr>
|
||||
<td><?php echo $package; ?></td>
|
||||
<td><?php echo $version; ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue