Skip to content

Commit

Permalink
Add different redirect options
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 6, 2023
1 parent 72bb31c commit 07e4cfb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Compat/CompatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ipl\Web\Compat;

use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Application\Version;
use InvalidArgumentException;
use Icinga\Web\Controller;
use ipl\Html\BaseHtmlElement;
Expand Down Expand Up @@ -420,6 +421,59 @@ public function sendExtraUpdates(array $updates)
$this->getResponse()->setHeader('X-Icinga-Extra-Updates', join(',', $extraUpdates));
}

/**
* Close the modal content and refresh the related view
*
* NOTE: When you use this with older Icinga Web versions (< 2.12), you will need to specify a valid redirect url,
* that will produce the same result as using the `__REFRESH__` redirect with the latest Icinga Web version.
*
* This is supposed to be used in combination with a modal view and closes only the modal content,
* and refreshes the modal opener (regardless of whether it is col1 or col2).
*
* @param null|Url|string $url
* @param array $extraUpdates
*/
public function closeModalAndRefreshRelatedView($url = null, array $extraUpdates = []): void
{
$this->sendExtraUpdates($extraUpdates);

if (version_compare(Version::VERSION, '2.12.0', '<')) {
if (! $url) {
throw new InvalidArgumentException('No redirect url provided');
}

$this->redirectNow($url);
} else {
$this->redirectNow('__REFRESH__');
}
}

/**
* Close the modal content and refresh all the remaining views
*
* NOTE: When you use this with older Icinga Web versions (< 2.12), you will need to specify a valid redirect url,
* that will produce the same result as using the `__REFRESH__` redirect with the latest Icinga Web version.
*
* This is supposed to be used in combination with a modal view and closes only the modal content. It refreshes
* the modal opener (regardless of whether it is col1 or col2) and sends extra updates for col1.
*
* @param null|Url|string $url
*/
public function closeModalAndRefreshRemainingViews($url = null): void
{
$this->closeModalAndRefreshRelatedView($url, ['#col1']);
}

/**
* Redirect using `__CLOSE__`
*
* Change to a single column layout and refresh col1
*/
public function switchToSingleColumnLayout(): void
{
$this->redirectNow('__CLOSE__');
}

public function postDispatch()
{
if (empty($this->parts)) {
Expand Down

0 comments on commit 07e4cfb

Please sign in to comment.