Skip to content

Commit 5864d1f

Browse files
committed
Code review changes
1 parent c14c7a5 commit 5864d1f

7 files changed

Lines changed: 14 additions & 42 deletions

File tree

configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/** @var \Icinga\Application\Modules\Module $this */
77

88
$this->provideConfigTab('backends', array(
9-
'title' => $this->translate('Configure the Chrome/WebDriver connection'),
9+
'title' => $this->translate('Configure Chrome/WebDriver connections'),
1010
'label' => $this->translate('Backends'),
1111
'url' => 'config/backends'
1212
));

library/Pdfexport/Backend/Chromedriver.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ protected function setContent(PrintableHtmlDocument $document): void
2828
parent::setContent($document);
2929

3030
$module = Icinga::app()->getModuleManager()->getModule('pdfexport');
31-
if (! method_exists($module, 'getJsDir')) {
32-
$jsPath = join(DIRECTORY_SEPARATOR, [$module->getBaseDir(), 'public', 'js']);
33-
} else {
34-
$jsPath = $module->getJsDir();
35-
}
36-
37-
$activeScripts = file_get_contents($jsPath . '/activate-scripts.js');
31+
$activeScripts = file_get_contents($module->getJsDir() . '/activate-scripts.js');
3832

3933
$this->driver->execute(
4034
Command::executeScript($activeScripts),

library/Pdfexport/Backend/HeadlessChromeBackend.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,7 @@ protected function setContent(PrintableHtmlDocument $document): void
372372
]);
373373

374374
$module = Icinga::app()->getModuleManager()->getModule('pdfexport');
375-
if (! method_exists($module, 'getJsDir')) {
376-
$jsPath = join(DIRECTORY_SEPARATOR, [$module->getBaseDir(), 'public', 'js']);
377-
} else {
378-
$jsPath = $module->getJsDir();
379-
}
380-
381-
$waitForLayout = file_get_contents($jsPath . '/wait-for-layout.js');
375+
$waitForLayout = file_get_contents($module->getJsDir() . '/wait-for-layout.js');
382376

383377
$promisedResult = $this->communicate($page, 'Runtime.evaluate', [
384378
'awaitPromise' => true,

library/Pdfexport/ChromeDevTools/ChromeDevTools.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ public function __construct(
1717

1818
public function execute(Command $command): mixed
1919
{
20-
$params = [
21-
'cmd' => $command->name,
22-
'params' => $command->parameters,
23-
];
24-
25-
$customCommand = new CustomCommand(
20+
return $this->driver->execute(new CustomCommand(
2621
'POST',
2722
'/session/:sessionId/goog/cdp/execute',
28-
$params,
29-
);
30-
31-
return $this->driver->execute($customCommand);
23+
[
24+
'cmd' => $command->name,
25+
'params' => $command->parameters,
26+
],
27+
));
3228
}
3329
}

library/Pdfexport/PrintableHtmlDocument.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,8 @@ function ($matches) use ($app) {
525525
protected function createLayoutScript(): ValidHtml
526526
{
527527
$module = Icinga::app()->getModuleManager()->getModule('pdfexport');
528-
if (! method_exists($module, 'getJsDir')) {
529-
$jsPath = join(DIRECTORY_SEPARATOR, [$module->getBaseDir(), 'public', 'js']);
530-
} else {
531-
$jsPath = $module->getJsDir();
532-
}
533528

529+
$jsPath = $module->getJsDir();
534530
$layoutJS = file_get_contents($jsPath . '/layout.js') . "\n\n\n";
535531
$layoutJS .= file_get_contents($jsPath . '/layout-plugins/page-breaker.js') . "\n\n\n";
536532

library/Pdfexport/WebDriver/ElementPresentCondition.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public function apply(WebDriver $driver): bool
2121
Command::findElement($this->mechanism, $this->value),
2222
);
2323

24-
if (isset($response['ELEMENT']) || isset($response[self::WEBDRIVER_ELEMENT_IDENTIFIER])) {
25-
return true;
26-
}
27-
28-
return false;
24+
return isset($response['ELEMENT']) || isset($response[self::WEBDRIVER_ELEMENT_IDENTIFIER]);
2925
}
3026

3127
public static function byCssSelector(string $selector): static

public/js/activate-scripts.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
function activateScripts(node) {
5-
if (isScript(node) === true) {
6-
node.parentNode.replaceChild(cloneScript(node) , node);
5+
if (node.tagName === 'SCRIPT') {
6+
node.parentNode.replaceChild(cloneScript(node), node);
77
} else {
88
var i = -1, children = node.childNodes;
99
while (++i < children.length) {
@@ -15,7 +15,7 @@ function activateScripts(node) {
1515
}
1616

1717
function cloneScript(node) {
18-
var script = document.createElement("script");
18+
var script = document.createElement('script');
1919
script.text = node.innerHTML;
2020

2121
var i = -1, attrs = node.attributes, attr;
@@ -25,8 +25,4 @@ function cloneScript(node) {
2525
return script;
2626
}
2727

28-
function isScript(node) {
29-
return node.tagName === 'SCRIPT';
30-
}
31-
3228
activateScripts(document.documentElement);

0 commit comments

Comments
 (0)