From 390b9da29e18b9720e3f7840e00d356688c172b9 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Tue, 1 Jul 2025 03:37:49 +0300 Subject: [PATCH] feat: allow to use 0 as auto refresh interval with special meaning (#148) --- docs/configuration.rst | 2 +- package/share/ahriman/settings/ahriman.ini.d/00-web.ini | 3 ++- package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 | 2 ++ src/ahriman/web/views/index.py | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index bc657973..f779365c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -166,7 +166,7 @@ Reporting to web service related settings. In most cases there is fallback to we Web server settings. This feature requires ``aiohttp`` libraries to be installed. * ``address`` - optional address in form ``proto://host:port`` (``port`` can be omitted in case of default ``proto`` ports), will be used instead of ``http://{host}:{port}`` in case if set, string, optional. This option is required in case if ``OAuth`` provider is used. -* ``autorefresh_intervals`` - enable page auto refresh options, space separated list of integers, optional. The first defined interval will be used as default. If no intervals set, the auto refresh buttons will be disabled. +* ``autorefresh_intervals`` - enable page auto refresh options, space separated list of integers, optional. The first defined interval will be used as default. If no intervals set, the auto refresh buttons will be disabled. If first element of the list equals ``0``, auto refresh will be disabled by default. * ``enable_archive_upload`` - allow to upload packages via HTTP (i.e. call of ``/api/v1/service/upload`` uri), boolean, optional, default ``no``. * ``host`` - host to bind, string, optional. * ``index_url`` - full URL of the repository index page, string, optional. diff --git a/package/share/ahriman/settings/ahriman.ini.d/00-web.ini b/package/share/ahriman/settings/ahriman.ini.d/00-web.ini index 84d03bf1..804584a3 100644 --- a/package/share/ahriman/settings/ahriman.ini.d/00-web.ini +++ b/package/share/ahriman/settings/ahriman.ini.d/00-web.ini @@ -29,7 +29,8 @@ allow_read_only = yes ; address = http://${web:host}:${web:port} ;address = http://${web:host}:${web:port} ; Enable page auto refresh. Intervals are given in seconds. Default interval is always the first element of the list. -; If no intervals set, auto refresh will be disabled. +; If no intervals set, auto refresh will be disabled. 0 can only be the first element and will disable auto refresh +; by default. autorefresh_intervals = 5 1 10 30 60 ; Enable file upload endpoint used by some triggers. ;enable_archive_upload = no diff --git a/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 b/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 index b528d08d..52a3639c 100644 --- a/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 +++ b/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 @@ -154,6 +154,8 @@ // finally create timer task return setInterval(callback, interval); } + } else { + toggle.checked = false; // no active interval found, disable toggle } return null; // return null to assign to keep method sane diff --git a/src/ahriman/web/views/index.py b/src/ahriman/web/views/index.py index 7a9411ec..f8d560a5 100644 --- a/src/ahriman/web/views/index.py +++ b/src/ahriman/web/views/index.py @@ -74,10 +74,11 @@ class IndexView(BaseView): autorefresh_intervals = [ { "interval": interval * 1000, # milliseconds - "is_active": index == 0, + "is_active": index == 0, # first element is always default "text": pretty_interval(interval), } for index, interval in enumerate(self.configuration.getintlist("web", "autorefresh_intervals", fallback=[])) + if interval > 0 # special case if 0 exists and first, refresh will not be turned on by default ] return {