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

Add link when using iframes to have iframes without using the grafana-renderer and still have links to Grafana #318

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 25 additions & 14 deletions application/forms/Config/GeneralConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function createElements(array $formData)
);
}

if (isset($formData['grafana_accessmode']) && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_accessmode'])) {
$this->addElement(
'number',
'grafana_height',
Expand All @@ -271,15 +271,26 @@ public function createElements(array $formData)
'description' => $this->translate('The default graph height in pixels.')
)
);
$this->addElement(
'number',
'grafana_width',
array(
'value' => '640',
'label' => $this->translate('Graph width'),
'description' => $this->translate('The default graph width in pixels.')
)
);
if ( $formData['grafana_accessmode'] != 'iframe' ) {
$this->addElement(
'number',
'grafana_width',
array(
'value' => '640',
'label' => $this->translate('Graph width'),
'description' => $this->translate('The default graph width in pixels.')
)
);
}
}

if (isset($formData['grafana_accessmode'])) {
if ($formData['grafana_accessmode'] === 'indirectproxy') {
$desc = 'Image is a link to the dashboard on the Grafana server.';
}
else {
$desc = 'Above image is a link to the dashboard on the Grafana server.';
}
$this->addElement(
'select',
'grafana_enableLink',
Expand All @@ -290,12 +301,12 @@ public function createElements(array $formData)
'yes' => $this->translate('Yes'),
'no' => $this->translate('No'),
),
'description' => $this->translate('Image is an link to the dashboard on the Grafana server.'),
'description' => $this->translate($desc),
'class' => 'autosubmit'
)
);
}
if (isset($formData['grafana_enableLink']) && ( $formData['grafana_enableLink'] === 'yes') && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_enableLink']) && ( $formData['grafana_enableLink'] === 'yes')) {
$this->addElement(
'select',
'grafana_usepublic',
Expand All @@ -311,7 +322,7 @@ public function createElements(array $formData)
)
);
}
if (isset($formData['grafana_usepublic']) && ( $formData['grafana_usepublic'] === 'yes' ) && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_usepublic']) && ( $formData['grafana_usepublic'] === 'yes' )) {
$this->addElement(
'text',
'grafana_publichost',
Expand Down Expand Up @@ -345,4 +356,4 @@ public function createElements(array $formData)
)
);
}
}
}
16 changes: 10 additions & 6 deletions library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview
[
"src" => $iFramesrc,
"alt" => rawurlencode($serviceName),
"width" => "100%",
"height" => $this->height,
"style" => "width: 100%; border: none;"
"style" => "border: none;"
]
);

$previewHtml->add($iframeHtml);
}
return true;
Expand Down Expand Up @@ -482,10 +482,14 @@ public function getPreviewHtml(Model $object, $report = false)
$this->orgId,
$this->panelId
);

$link = new Link($previewHtml, $url, ["target" => "_blank"]);

$html->add($link);
if ($this->accessMode !== "iframe") {
$link = new Link($previewHtml, $url, ["target" => "_blank"]);
$html->add($link);
} else {
$link = new Link(" => see in Grafana", $url, ["target" => "_blank"]);
$html->add($link);
$html->addHtml($previewHtml);
};
}

$return_html->add($html);
Expand Down