Skip to content

Add ViewModeSwitcher control - #392

Merged
nilmerg merged 4 commits into
mainfrom
feature/viewmode-switcher
Aug 11, 2026
Merged

Add ViewModeSwitcher control#392
nilmerg merged 4 commits into
mainfrom
feature/viewmode-switcher

Conversation

@BastianLedererIcinga

@BastianLedererIcinga BastianLedererIcinga commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

resolve #340

A ViewModeSwitcher class similar to the one in icingadb-web is added. It was reworked so that adding and removing view modes can be done without declaring a subclass.
To allow this the ViewMode class is added, which contains name, icon, titles for active/inactive state and the default page size.

The Controls trait is added with a createViewModeSwitcher() function.
It registers a listener to ViewModeSwitcher::ON_REQUEST, which populates the ViewModeSwitcher with the view mode from the url and emits ON_VIEW_MODE_SET.
If the view mode is changed, a ViewModeSwitcher::ON_SUBMIT listener emits ON_VIEW_MODE_CHANGE with the ViewModeSwitcher, its previous view mode and a $redirectUrl that listeners may modify.

The handleControls() function suggested in #340 is implemented, which calls handleRequest() for all controls passed to trackControl() , in case of the ViewModeSwitcher this is done by the factory method.

The CompatController registers listeners on the trait's events in the createLimitControl() and createPaginationControl() factories, to adjust the default limit, page size to teh current view mode, and correct the current page when the view mode is changed.

SearchControls::createSearchBar() is adjusted to shift the view mode param before building its filter, because the Controls trait does not have access to the UrlParams.

@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
@BastianLedererIcinga
BastianLedererIcinga force-pushed the feature/viewmode-switcher branch from 737bb92 to 8e6f962 Compare July 9, 2026 12:33

@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

@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.

Apart from the changes I’ve pointed out, the code looks fine to me.

Comment thread src/Common/Controls.php Outdated
Comment thread src/Control/ViewModeSwitcher.php Outdated
Comment thread src/Common/Controls.php Outdated
@sukhwinder33445

Copy link
Copy Markdown
Contributor

@nilmerg please have a look.

@nilmerg nilmerg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not really convinced that this follows what I proposed in the issue. The view mode dependent limit change is not automatically done anymore, and the dynamic correction of the current page is missing. Custom rules, so to say, are also not even considered.

And where's:

So the new implementation should allow to add new modes as well as to remove default modes.

It also misses basic accessibility support, as the id protection has no fallback. Since it is now a library part I consider this a must, as unique ID's are not a requirement of Icinga Web, only the part that it must be based on the container id. ipl-html also provides a fallback in case of the new decorator implementation for this very reason: A sane default.

So this is far from finished, I'm afraid.

Comment thread asset/css/controls.less
Comment thread asset/css/view-mode-switcher.less Outdated
Comment thread asset/css/view-mode-switcher.less Outdated
Comment thread asset/css/view-mode-switcher.less Outdated
Comment thread src/Common/Controls.php Outdated
Comment thread src/Compat/CompatController.php Outdated
Comment thread src/Common/Controls.php
Comment thread src/Common/Controls.php
Comment thread src/Compat/CompatController.php Outdated
Comment thread src/Control/ViewModeSwitcher.php Outdated

@nilmerg nilmerg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks fine now, thank you. Though, I will first check any dependent implementation before merging it.

Comment thread tests/Common/ControlsTest.php Outdated
Comment thread src/Compat/CompatController.php
Comment thread src/Compat/CompatController.php
Comment thread src/Control/ViewModeSwitcher.php Outdated
Comment thread src/Control/ViewModeSwitcher.php

@nilmerg nilmerg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🎉

@nilmerg nilmerg added this to the v1.0.0 milestone Aug 11, 2026
Migrate icingadb-web's `ViewModeSwitcher`, and modify it to use
`ViewMode` instances to represent each view-mode.

This allows consumers to customize available view-modes without
a subclass.
Add a `Controls` trait, that provides a `createViewModeSwitcher()`
factory, which emits the events `view-mode-set` and `view-mode-change`

The request of the created `ViewModeSwitcher` and other controls the
trait may provide in the future can all be handled with `Controls::handleRequests()`
If a child class uses `Controls::createViewModeSwitcher()` to
create a `ViewModeSwitcher`, the page size of the current `ViewMode`
is used as default in `createLimitControl()` and `createPaginationControl()`

If a changed view mode also changed the page size, the current page is corrected
so that the previously first element is always visbible on the corrected page.

Both changes rely on events emmited by the `Controls` trait and will not
affect child classes that don't use the trait.
If `Controls::createViewModeSwitcher()` was used to create a `ViewModeSwitcher`,
the factory did not shift its view mode param, so it is explicitly shifted here
so it isn't used for the created filter.
@nilmerg
nilmerg merged commit bd8f29c into main Aug 11, 2026
25 of 26 checks passed
@nilmerg
nilmerg deleted the feature/viewmode-switcher branch August 11, 2026 13:44
nilmerg added a commit to Icinga/icinga-notifications-web that referenced this pull request Sep 4, 2026
This PR implements the Notification History list and per-notification
detail view.

Changes:

- Added `NotificationHistory` model + renderer + detail widget, with new
controllers for list/detail views.
- Extended incident detail with a `Notification History` tab and scoped
search suggestions.
- Added supporting enums, condition description helper, styling, and
PHPUnit tests.

resolves #475
### require:
- Icinga/icinga-notifications#472
- Icinga/ipl-web#392
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

3 participants