Add ViewModeSwitcher control#392
Open
BastianLedererIcinga wants to merge 3 commits into
Open
Conversation
ae88160 to
f3ac3a2
Compare
693285d to
737bb92
Compare
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.
737bb92 to
8e6f962
Compare
| @@ -0,0 +1,75 @@ | |||
| <?php | |||
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


resolve #340
The
ViewModeSwitcherfrom icingadb-web and its styles are copied, only type declarations were added/narrowed.The
Controlstrait is added with acreateViewModeSwitcher()function.For now the
handleControls()function suggested in #340 is implemented, which callshandleRequest()on theViewModeSwitcherand any other controls added totrackedControls. This allows controllers to choose whenhandleRequest()runs, so they can load a preferred view mode and subscribe a handler to savethe 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_SUBMITfired, and overrideonor 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
Controlstrait I wrote some tests with claude, I also tried theViewModeSwitchertogetherLimitControlthat changes the default according to the view-mode in a local controller and it worked fine.