Skip to content

Add ViewModeSwitcher control#392

Open
BastianLedererIcinga wants to merge 3 commits into
mainfrom
feature/viewmode-switcher
Open

Add ViewModeSwitcher control#392
BastianLedererIcinga wants to merge 3 commits into
mainfrom
feature/viewmode-switcher

Conversation

@BastianLedererIcinga

Copy link
Copy Markdown
Contributor

resolve #340

The ViewModeSwitcher from icingadb-web and its styles are copied, only type declarations were added/narrowed.

The Controls trait is added with a createViewModeSwitcher() function.

For now the handleControls() function suggested in #340 is implemented, which calls handleRequest() on the ViewModeSwitcher and any other controls added to trackedControls. This allows controllers to choose when handleRequest() runs, so they can load a preferred view mode and subscribe a handler to save
the view mode to preferences beforehand.

I have also given the promise-like idea some thought, and it shouldn't be hard to implement either, the controls that need it could cache that their ON_SUBMIT fired, and override on or provide a separate function to execute handlers registered afterwards immediately. I am unsure which version to prefer, but I think the latter is a bit more confusing, especially when redirects are used in the handlers, callers will still have to pay close attention to when the request is handled.

For the basic functionality of the Controls trait I wrote some tests with claude, I also tried the ViewModeSwitcher together LimitControl that changes the default according to the view-mode in a local controller and it worked fine.

@cla-bot cla-bot Bot added the cla/signed label Jun 29, 2026
@BastianLedererIcinga BastianLedererIcinga force-pushed the feature/viewmode-switcher branch from ae88160 to f3ac3a2 Compare June 29, 2026 12:47
@BastianLedererIcinga BastianLedererIcinga force-pushed the feature/viewmode-switcher branch 2 times, most recently from 693285d to 737bb92 Compare June 30, 2026 06:17
Migrate icingadb-web's `ViewModeSwitcher` and its styles.
Add a `Controls` trait that provides the factory function
`createViewmodeSwitcher()` and a `handleControls()` function
to handle the requests of all tracked controls.

@sukhwinder33445 sukhwinder33445 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view mode switcher is no longer aligned to the right as it was before:
Before:
Image

Now:
Image

Please fix the alignment and style.

Comment thread src/Common/Controls.php
@@ -0,0 +1,75 @@
<?php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To create a view mode switcher, I used the following code you shared with me, in a controller:

use Controls;
//...
$viewModeSwitcher->on(ViewModeSwitcher::ON_SUBMIT, function (ViewModeSwitcher $switcher): void {
    $this->redirectNow(
        Url::fromRequest()->setParam($switcher->getViewModeParam(), $switcher->getViewMode())
    );
});

$viewMode = $viewModeSwitcher->getViewMode();

$limitControl = new LimitControl(Url::fromRequest());
if ($viewMode === 'minimal') {
    $limitControl->setDefaultLimit(LimitControl::DEFAULT_LIMIT * 2);
}

$this->trackControl($limitControl);
$this->handleControls($this->getServerRequest());

//...
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);

This seems boilerplate code to write in each controller when we want a ViewModeSwitcher.
At least the adjustment of the default limit for LimitControl in minimal mode could be centralized. Also, the PaginationControl (page numbers) currently isn't adjusted when the user selects minimal mode, the limit switches from 25 to 50, but the number of pages stays the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce ipl\Web\Control\ViewModeSwitcher

2 participants