From 2e7d7b91291e7b81691dc7e5cc2119cb33409a2a Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 6 Jun 2023 13:14:50 +0200 Subject: [PATCH] CheckStatistics: Show TimePeriod name if available --- application/controllers/HostController.php | 2 +- application/controllers/ServiceController.php | 3 ++- library/Icingadb/Model/Host.php | 3 ++- library/Icingadb/Model/Service.php | 3 ++- library/Icingadb/Widget/Detail/CheckStatistics.php | 9 +++++++++ public/css/widget/check-statistics.less | 5 +++++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index ae5944d6..e7b1a2af 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -40,7 +40,7 @@ class HostController extends Controller { $name = $this->params->getRequired('name'); - $query = Host::on($this->getDb())->with(['state', 'icon_image']); + $query = Host::on($this->getDb())->with(['state', 'icon_image', 'timeperiod']); $query ->setResultSetClass(VolatileStateResults::class) ->filter(Filter::equal('host.name', $name)); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 2933d933..9a10dccf 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -41,7 +41,8 @@ class ServiceController extends Controller 'state', 'icon_image', 'host', - 'host.state' + 'host.state', + 'timeperiod' ]); $query ->setResultSetClass(VolatileStateResults::class) diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index 7a14b1e6..e1296c80 100644 --- a/library/Icingadb/Model/Host.php +++ b/library/Icingadb/Model/Host.php @@ -199,7 +199,8 @@ class Host extends Model $relations->belongsTo('eventcommand', Eventcommand::class); $relations->belongsTo('checkcommand', Checkcommand::class); $relations->belongsTo('timeperiod', Timeperiod::class) - ->setCandidateKey('check_timeperiod_id'); + ->setCandidateKey('check_timeperiod_id') + ->setJoinType('LEFT'); $relations->belongsTo('action_url', ActionUrl::class) ->setCandidateKey('action_url_id') ->setForeignKey('id'); diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 97a110d0..c57b6ba1 100644 --- a/library/Icingadb/Model/Service.php +++ b/library/Icingadb/Model/Service.php @@ -188,7 +188,8 @@ class Service extends Model $relations->belongsTo('host', Host::class)->setJoinType('LEFT'); $relations->belongsTo('checkcommand', Checkcommand::class); $relations->belongsTo('timeperiod', Timeperiod::class) - ->setCandidateKey('check_timeperiod_id'); + ->setCandidateKey('check_timeperiod_id') + ->setJoinType('LEFT'); $relations->belongsTo('eventcommand', Eventcommand::class); $relations->belongsTo('action_url', ActionUrl::class) ->setCandidateKey('action_url_id') diff --git a/library/Icingadb/Widget/Detail/CheckStatistics.php b/library/Icingadb/Widget/Detail/CheckStatistics.php index 31e79ad9..a3e78e62 100644 --- a/library/Icingadb/Widget/Detail/CheckStatistics.php +++ b/library/Icingadb/Widget/Detail/CheckStatistics.php @@ -191,6 +191,15 @@ class CheckStatistics extends Card t('Scheduling Source') . ':', $this->object->state->scheduling_source ?? (new EmptyState(t('n. a.')))->setTag('span') )); + + if ($this->object->timeperiod->id) { + $footer->add(new HorizontalKeyValue( + t('Timeperiod') . ':', + $this->object->timeperiod->display_name ?? $this->object->timeperiod->name + )); + + $footer->addAttributes(['class' => 'space-between']); + } } protected function assembleHeader(BaseHtmlElement $header) diff --git a/public/css/widget/check-statistics.less b/public/css/widget/check-statistics.less index 6e1a43d1..47db8185 100644 --- a/public/css/widget/check-statistics.less +++ b/public/css/widget/check-statistics.less @@ -7,6 +7,11 @@ justify-content: center; border-top: 1px solid @gray-light; + &.space-between { + justify-content: space-between; + padding: 0 0.5em; + } + .key { width: auto; margin-right: .28125em; //calculated   width