Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Apr 12, 2024
1 parent 387a625 commit 3a25f56
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 66 deletions.
104 changes: 40 additions & 64 deletions library/Jira/Web/RenderingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,50 @@ class RenderingHelper
{
protected $api;

/** @var ?Link Host link */
protected $hostLink;

/** @var ?Link Service link */
protected $serviceLink;

/**
* Set the link of monitored host
*
* @param Link $hostLink
*
* @return $this
*/
public function setHostLink(Link $hostLink): RenderingHelper
{
$this->hostLink = $hostLink;

return $this;
}
/** @var string Backend used for object link Host|Service */
private $backend;

/**
* Set the link of monitored service
* Get the link of monitored host
*
* @param Link $serviceLink
* @param $host
*
* @return $this
* @return ?Url
*/
public function setServiceLink(Link $serviceLink): RenderingHelper
public function getHostLink(string $host): ?Link

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.

Check failure on line 32 in library/Jira/Web/RenderingHelper.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

PHPDoc tag @return with type ipl\Web\Url|null is not subtype of native type ipl\Web\Widget\Link|null.
{
$this->serviceLink = $serviceLink;

return $this;
}
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
return new Link(
[new Icon('server'), $host],
Url::fromPath('icingadb/host', ['name' => $host])
);
}

/**
* Get the link of monitored host
*
* @return ?Link
*/
public function getHostLink(): ?Link
{
return $this->hostLink;
return new Link(
[new Icon('laptop'), $host],
Url::fromPath('monitoring/host/show', ['host' => $host])
);
}

/**
* Get the link of monitored service
*
* @return ?Link
*/
public function getServiceLink(): ?Link
public function getServiceLink(string $host, string $service): ?Link
{
return $this->serviceLink;
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
return new Link(
[new Icon('cog'), $service],
Url::fromPath('icingadb/service/show', ['name' => $service, 'host.name' => $host]),
['icon' => new Icon('cog')]
);
}

return new Link(
[new Icon('cog'), $service],
Url::fromPath('monitoring/host/show', ['host' => $host, 'service' => $service])
);
}


Expand Down Expand Up @@ -115,8 +107,7 @@ public function formatBody(string $body): HtmlString
$url = Url::fromPath($match[2]);
$link = new Link(
$match[1],
$url,
['target' => '_blank']
$url
);

if ($url->hasParam('service') || $url->hasParam('host.name')) {
Expand All @@ -136,32 +127,17 @@ public function formatBody(string $body): HtmlString
['target' => '_blank']
);
}

$serviceLink = clone $link;
$serviceLink->setContent([new Icon('cog'), $match[1]])
->addAttributes(['title' => t('Show Icinga Service State')]);
$this->setServiceLink($serviceLink);
} else {
$icon = new Icon('server');
if (strpos($match[2], 'icingaweb2/monitoring') !== false) {
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
$link = new Link(
$match[1],
Url::fromPath(
'icingadb/host',
['name' => $url->getParam('host')]
),
['target' => '_blank']
);
} else {
$icon = new Icon('laptop');
}
} elseif (strpos($match[2], 'icingaweb2/monitoring') !== false) {
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
$link = new Link(
$match[1],
Url::fromPath(
'icingadb/host',
['name' => $url->getParam('host')]
),
['target' => '_blank']
);
}

$hostLink = clone $link;
$hostLink->setContent([$icon, $match[1]])
->addAttributes(['title' => t('Show Icinga Host State')]);
$this->setHostLink($hostLink);
}

$urls[] = $link->render();
Expand Down
4 changes: 2 additions & 2 deletions library/Jira/Web/Table/IssueDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ protected function assemble()
if ($host !== null) {
$this->addNameValueRow(
$this->translate('Host'),
$this->helper->getHostLink()
$this->helper->getHostLink($host)
);
}
if ($service !== null) {
$this->addNameValueRow(
$this->translate('Service'),
$this->helper->getServiceLink()
$this->helper->getServiceLink($host, $service)
);
}
if ($user !== null) {
Expand Down

0 comments on commit 3a25f56

Please sign in to comment.