From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- library/Icingadb/Widget/Detail/DowntimeDetail.php | 206 ++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 library/Icingadb/Widget/Detail/DowntimeDetail.php (limited to 'library/Icingadb/Widget/Detail/DowntimeDetail.php') diff --git a/library/Icingadb/Widget/Detail/DowntimeDetail.php b/library/Icingadb/Widget/Detail/DowntimeDetail.php new file mode 100644 index 0000000..9e50f7f --- /dev/null +++ b/library/Icingadb/Widget/Detail/DowntimeDetail.php @@ -0,0 +1,206 @@ + ['object-detail', 'downtime-detail']]; + + protected $tag = 'div'; + + public function __construct(Downtime $downtime) + { + $this->downtime = $downtime; + } + + protected function createCancelDowntimeForm() + { + $action = Links::downtimesDelete(); + $action->setFilter(Filter::equal('name', $this->downtime->name)); + + return (new DeleteDowntimeForm()) + ->setObjects([$this->downtime]) + ->populate(['redirect' => '__BACK__']) + ->setAction($action->getAbsoluteUrl()); + } + + protected function createTimeline(): DowntimeCard + { + return new DowntimeCard($this->downtime); + } + + protected function assemble() + { + $this->add(Html::tag('h2', t('Comment'))); + $this->add(Html::tag('div', [ + new Icon('user'), + Html::sprintf( + t('%s commented: %s', ' ..: '), + $this->downtime->author, + new MarkdownText($this->downtime->comment) + ) + ])); + + $this->add(Html::tag('h2', t('Details'))); + + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + $this->addHtml(new HorizontalKeyValue( + t('Type'), + $this->downtime->is_flexible ? t('Flexible') : t('Fixed') + )); + if ($this->downtime->object_type === 'host') { + $this->addHtml(new HorizontalKeyValue(t('Host'), [ + $this->downtime->host->name, + ' ', + new StateBall($this->downtime->host->state->getStateText()) + ])); + } else { + $this->addHtml(new HorizontalKeyValue(t('Service'), Html::sprintf( + t('%s on %s', ' on '), + [ + $this->downtime->service->name, + ' ', + new StateBall($this->downtime->service->state->getStateText()) + ], + $this->downtime->host->name + ))); + } + } + + if ($this->downtime->triggered_by_id !== null || $this->downtime->parent_id !== null) { + if ($this->downtime->triggered_by_id !== null) { + $label = t('Triggered By'); + $relatedDowntime = $this->downtime->triggered_by; + } else { + $label = t('Parent'); + $relatedDowntime = $this->downtime->parent; + } + + $this->addHtml(new HorizontalKeyValue( + $label, + HtmlElement::create('span', ['class' => 'accompanying-text'], TemplateString::create( + $relatedDowntime->is_flexible + ? t('{{#link}}Flexible Downtime{{/link}} for %s') + : t('{{#link}}Fixed Downtime{{/link}} for %s'), + ['link' => new Link(null, Links::downtime($relatedDowntime), ['class' => 'subject'])], + ($relatedDowntime->object_type === 'host' + ? $this->createHostLink($relatedDowntime->host, true) + : $this->createServiceLink($relatedDowntime->service, $relatedDowntime->host, true)) + )) + )); + } + + $this->add(new HorizontalKeyValue( + t('Created'), + WebDateFormatter::formatDateTime($this->downtime->entry_time->getTimestamp()) + )); + $this->add(new HorizontalKeyValue( + t('Start time'), + $this->downtime->start_time + ? WebDateFormatter::formatDateTime($this->downtime->start_time->getTimestamp()) + : new EmptyState(t('Not started yet')) + )); + $this->add(new HorizontalKeyValue( + t('End time'), + $this->downtime->end_time + ? WebDateFormatter::formatDateTime($this->downtime->end_time->getTimestamp()) + : new EmptyState(t('Not started yet')) + )); + $this->add(new HorizontalKeyValue( + t('Scheduled Start'), + WebDateFormatter::formatDateTime($this->downtime->scheduled_start_time->getTimestamp()) + )); + $this->add(new HorizontalKeyValue( + t('Scheduled End'), + WebDateFormatter::formatDateTime($this->downtime->scheduled_end_time->getTimestamp()) + )); + $this->add(new HorizontalKeyValue( + t('Scheduled Duration'), + DateFormatter::formatDuration($this->downtime->scheduled_duration / 1000) + )); + if ($this->downtime->is_flexible) { + $this->add(new HorizontalKeyValue( + t('Flexible Duration'), + DateFormatter::formatDuration($this->downtime->flexible_duration / 1000) + )); + } + + $query = Downtime::on($this->getDb())->with([ + 'host', + 'host.state', + 'service', + 'service.host', + 'service.host.state', + 'service.state' + ]) + ->limit(3) + ->filter(Filter::equal('parent_id', $this->downtime->id)) + ->orFilter(Filter::equal('triggered_by_id', $this->downtime->id)); + $this->applyRestrictions($query); + + $children = $query->peekAhead()->execute(); + if ($children->hasResult()) { + $this->addHtml( + new HtmlElement('h2', null, Text::create(t('Children'))), + new DowntimeList($children), + (new ShowMore($children, Links::downtimes()->setQueryString( + QueryString::render(Filter::any( + Filter::equal('downtime.parent.name', $this->downtime->name), + Filter::equal('downtime.triggered_by.name', $this->downtime->name) + )) + )))->setBaseTarget('_next') + ); + } + + $this->add(Html::tag('h2', t('Progress'))); + $this->add($this->createTimeline()); + + if ( + getenv('ICINGAWEB_EXPORT_FORMAT') !== 'pdf' + && $this->isGrantedOn( + 'icingadb/command/downtime/delete', + $this->downtime->{$this->downtime->object_type} + ) + ) { + $this->add($this->createCancelDowntimeForm()); + } + } +} -- cgit v1.2.3