Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use svg to render cert expiration progress bar #193

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions library/X509/ExpirationWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace Icinga\Module\X509;

use Icinga\Chart\ProgressBar;
use Icinga\Date\DateFormatter;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlString;
use ipl\Html\HtmlElement;

class ExpirationWidget extends BaseHtmlElement
{
/** @var int Is used to limit the svg sections of a single progress bar */
public const MAX_SVG_SECTIONS = 60;

protected $tag = 'div';

protected $from;
Expand Down Expand Up @@ -66,21 +69,13 @@ protected function assemble()
$state = 'state-ok';
}

$this->add([
Html::tag(
'span',
['class' => '', 'style' => 'font-size: 0.9em;', 'title' => $dateTip],
$message
),
Html::tag(
'div',
['class' => 'progress-bar dont-print'],
Html::tag(
'div',
['style' => sprintf('width: %.2F%%;', $ratio), 'class' => "bg-stateful {$state}"],
new HtmlString(' ')
)
)
]);
$progressBar = new ProgressBar(['class' => 'progress-bar'], 35);
$progressBar
->markComplete((int) ($ratio * static::MAX_SVG_SECTIONS / 100.0))
->setCompletedCssClass($state)
->setSections(static::MAX_SVG_SECTIONS);

$this->addHtml(HtmlElement::create('span', ['class' => 'progress-bar-label', 'title' => $dateTip], $message));
$this->addHtml($progressBar);
}
}
32 changes: 23 additions & 9 deletions public/css/module.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@
}
}

.progress-bar {
background-color: @gray-lighter;
border-radius: 2px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25) inset;
height: 0.5em;

> div {
border-radius: 2px;
height: 100%;
svg.progress-bar {
height: 1.5em;
width: 100%;
filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.25));

.state-none > * {
fill: @gray-lighter;
}

.state-ok {
fill: @color-ok;
}

.state-warning {
fill: @state-warning;
}

.state-critical {
fill: @color-critical;
}
}

Expand All @@ -54,6 +64,10 @@

.expiration-col {
width: 18em;

span.progress-bar-label {
font-size: 0.9em;
}
}

.icon-col > i {
Expand Down