Skip to content

Allow switching between relative and absolute timestamps#1322

Open
BastianLedererIcinga wants to merge 44 commits intomainfrom
feature/history-view-timestamps
Open

Allow switching between relative and absolute timestamps#1322
BastianLedererIcinga wants to merge 44 commits intomainfrom
feature/history-view-timestamps

Conversation

@BastianLedererIcinga
Copy link
Copy Markdown
Contributor

@BastianLedererIcinga BastianLedererIcinga commented Jan 19, 2026

resolves #1065

For the views:

  • Host History
  • Service History
  • Notifications
  • Event Overview

A new control is added that allows to switch between relative and absolute timestamps.
Screenshot from 2026-01-16 10-08-57
The mode can also be switched by clicking one of timestamps.
Whenever the mode is changed it is added to the url and saved in the user's session and preferences.

For timestamps that are older than one hour absolute time is always displayed, since that aligns with the previous behavior.
Absolute timestamps now always show the time of day, to display the dates a seperate line is added.
Screenshot from 2026-01-16 10-31-58
To ensure this line is also added when loading more entries the timestamp of the latest entry is added to the load-more url.

The relative timestamps rely on the new implementation in Icinga/ipl-web#350.

Additionally a bug in the Service History is fixed.
The sort parameter was not included in the loadMoreUrl, so descending order was always used when adding new elements.

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jan 19, 2026
@BastianLedererIcinga BastianLedererIcinga marked this pull request as draft January 19, 2026 14:38
@BastianLedererIcinga BastianLedererIcinga self-assigned this Jan 19, 2026
@BastianLedererIcinga BastianLedererIcinga force-pushed the feature/history-view-timestamps branch 2 times, most recently from 6f5fc61 to 72f5b88 Compare January 21, 2026 09:28
@BastianLedererIcinga BastianLedererIcinga marked this pull request as ready for review January 22, 2026 14:44
Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

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

Please also prevent text selection in case the time tags are interactive, that's common practice for such widgets.

And I had a bug I did't track down yet: After some time or interactions, switching between relative/absolute didn't work anymore. The toggle updated accordingly, but neither pressing the toggle nor the time tags did update the time. A refresh fixes it. But I didn't look at the JS in detail yet, maybe I can easily spot the problem once I do this, so please focus on the other comments first.

Comment thread run.php Outdated
Comment thread public/css/list/item-list.less Outdated
Comment thread library/Icingadb/Widget/ItemList/LoadMoreObjectList.php Outdated
Comment thread public/js/timestamp-mode.js Outdated
@BastianLedererIcinga
Copy link
Copy Markdown
Contributor Author

And I had a bug I did't track down yet: After some time or interactions, switching between relative/absolute didn't work anymore. The toggle updated accordingly, but neither pressing the toggle nor the time tags did update the time. A refresh fixes it. But I didn't look at the JS in detail yet, maybe I can easily spot the problem once I do this, so please focus on the other comments first.

I came across a bug that might have been what you describe.
Prior to Icinga/ipl-web@7144566 the Time widget always used UTC when created from a UNIX timestamp.
This caused the following behavior:
When the timestamps were initially loaded as relative switching to absolute works once, but switching back to relative has no effect, at least for the Europe/Berlin timezone, because of the timezone difference.

This bug never occurs when the backend creates absolute time, because the TimeAgo widgets aren't used.

A reload would fix this while the toggle is set to absolute time, if set to relative it would briefly appear to fix the problem since the newly generated timestamps have the correct content, but switching timestamp mode will lead to the same problem as before.

Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

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

again, php only, css + js after my break :)

Comment thread application/controllers/HistoryController.php Outdated
Comment thread application/controllers/HistoryController.php Outdated
Comment thread library/Icingadb/View/EventRenderer.php
Comment thread library/Icingadb/View/EventRenderer.php Outdated
Comment thread library/Icingadb/View/EventRenderer.php Outdated
Comment thread library/Icingadb/Web/Controller.php Outdated
Comment thread library/Icingadb/Web/Controller.php
Comment thread library/Icingadb/Widget/ItemList/LoadMoreObjectList.php Outdated
Comment thread library/Icingadb/Widget/ItemList/LoadMoreObjectList.php Outdated
Comment thread library/Icingadb/Widget/ItemList/LoadMoreObjectList.php Outdated
Comment thread public/css/list/item-list.less Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread library/Icingadb/Widget/ItemList/LoadMoreObjectList.php Outdated
Comment thread library/Icingadb/Widget/ItemList/HistoryObjectList.php
Comment thread public/js/timestamp-mode.js Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment on lines +61 to +62
el.removeAttribute('data-absolute-time');
el.setAttribute('data-relative-time', 'ago');
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.

Seems to be obsolete (by now) please remove. The lines below as well.

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.

Scratch that, but please make sure this works how Icinga/ipl-web#350 expects it to.

@BastianLedererIcinga
Copy link
Copy Markdown
Contributor Author

I have only tested the new changes with local modifications to ipl-web since some of the required changes have not yet been made in Icinga/ipl-web#350. But they should address all your comments, except the one with the missing load-more update...

Feel free to tell me whenever you are fine with a force push and I will resolve the conflicts.

Copy link
Copy Markdown
Contributor

@sukhwinder33445 sukhwinder33445 left a comment

Choose a reason for hiding this comment

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

I have noticed the following issues:

  • The searchbar is not working properly.
  • The refresh button does not preserve the load more params.

This is just a quick overview. I’ll take a closer look at it tomorrow.

Comment thread library/Icingadb/Web/Control/TimestampToggle.php Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread library/Icingadb/View/EventRenderer.php Outdated
Comment thread library/Icingadb/View/NotificationRenderer.php
Comment thread library/Icingadb/Widget/ItemList/HistoryObjectList.php Outdated
Comment thread library/Icingadb/Widget/ItemList/HistoryObjectList.php Outdated
Comment thread library/Icingadb/Widget/ItemList/HistoryObjectList.php Outdated
Comment thread library/Icingadb/Web/Control/TimestampToggle.php Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread library/Icingadb/Web/Control/TimestampToggle.php Outdated
To allow users to switch between relative and absolute timestamps
a new checkbox-control to switch between the two modes is added.
Add a property to EventRenderer and NotificationRenderer
that allows to choose whether to use relative or absolute timestamps.
assembleExtendedInfo() adds the timestamps of the chosen format.
The given timestamp mode is passed to the Renderer.
A sperator is added between entries of different days,
to achieve this the last timestamp is added to the LoadMoreURL.
createTimeStampControl() checks url, session and preferences
for the preffered timestampMode stores it in a property
and creates a TimestampToggle for the selected mode.
Changed controllers use the new TimestampToggle control
And the adjusted LoadMoreObjectList
The js switches the timestamps between relative and absolute
when the dedicated control or a timestamp itself is clicked.
The backend is notified of the changed mode.
timestampAction saves the new preference in the session and
to the user's preferences
When saving a changed viewmode all other icingadb prefernces
were previously deleted.
Since this affects the new timestamp preference prefernces
with different names than 'view_modes' will be kept as they are.
Add a sample of a relative timestamps to the timestamp-toggle element.
This The digits in this sample are then replaced with the current
minutes and seconds when switching to relative time in the frontend.
When inside a dashboad controls are not added so the timestamps
themselves also should no longer be highlated and clicking them
has no effect.
instead of relying on css classes for selecting the time
elements use data-attributes.
Previously when reloading the page the latest-entry parameter
would cause problems when adding the day-separatos.
Now it is reset alongside the query offset.
Previously Url::setParams() was used to set the name and host.name,
since the funtion overwrites all parameters the sort parameter
was not included in the loadMoreUrl.
Url::setParam() only sets/overwrites the given parameter,
the sort parameter is no longer affected and load-more works as expected.
When the icinga.config.timezone is changed the timezone in the dateFromatter
must be updated to generate correct relative timestamps.
Use the content of a `TimeAgo` widget for the relative sample to ensure
the format used matches the one ipl-web expects.

Setting a non english locale for `TimestampToggle::dateFormatter` does not work
it can be hardcoded to `en-US` sicne its output is never displayed.
It also replaces the `Controller::useRelativeTimestamps` property
Add missing docstring
Use arrays when setting several css classes
Remve unused id
Rename from `LoadMoreObjectList` to `HistoryObjectList`
Add missing docstring
Register events in `init()`
add missing docstrings and use the `Time` widget for absolute time
Ensure the separator is added in the correct position for any
timezone and the format adjusts to the configured Locale
@BastianLedererIcinga BastianLedererIcinga force-pushed the feature/history-view-timestamps branch from 06bf3f1 to 91d7c75 Compare April 16, 2026 05:44
It is not supported by php 8.2
Comment thread library/Icingadb/Web/Controller.php Outdated
Comment thread library/Icingadb/Web/Controller.php Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread public/js/timestamp-mode.js Outdated
Comment thread library/Icingadb/Web/Controller.php Outdated
Comment thread library/Icingadb/Web/Controller.php Outdated
Comment thread library/Icingadb/Web/Control/TimestampToggle.php
Comment thread library/Icingadb/Web/Control/TimestampToggle.php Outdated
Comment thread library/Icingadb/Web/Control/TimestampToggle.php Outdated
Comment thread library/Icingadb/Web/Control/TimestampToggle.php
@sukhwinder33445
Copy link
Copy Markdown
Contributor

  • The refresh button does not preserve the load more params.

I checked again and unfortunately this is a bug in the main branch, so it must be fixed in a separate PR.

Comment thread run.php
Comment thread public/js/timestamp-toggle.js
Comment thread public/js/timestamp-mode.js Outdated
Comment thread library/Icingadb/Widget/ItemList/HistoryObjectList.php Outdated
Comment thread library/Icingadb/View/NotificationRenderer.php Outdated
Comment thread library/Icingadb/View/EventRenderer.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Please give us back the timestamps in history view

3 participants