Skip to content

Commit 0660ac8

Browse files
authored
OP#10323: Show no progressbar for a load requested outside any page
Loading an otconfig with track files over HTTP always failed: OTCloud hands its UI Worker an otconfig through a plain endpoint, whose task carries no NiceGUI slot, and NiceguiProgressbar.open() resolved context.client, which raises on an empty slot stack. A missing page context now counts as having no browser to show the dialog in, like the startup preload already did.
1 parent 9bee976 commit 0660ac8

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎OTAnalytics/plugin_ui/nicegui_gui/nicegui/progressbar.py‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ def is_open(self) -> bool:
8484
def open(self) -> None:
8585
"""Build and show the progressbar dialog.
8686
87-
Does nothing without a browser to show it in, which is the case while
88-
input files given on the command line are preloaded at startup, and
89-
nothing when there is no progress left to show, because only progress
90-
closes the dialog again.
87+
Does nothing without a browser to show it in, and nothing when there is
88+
no progress left to show, because only progress closes the dialog again.
9189
"""
92-
if context.client.is_auto_index_client or self._state.finished:
90+
if not _has_browser_to_show_in() or self._state.finished:
9391
return
9492
with ui.dialog().props("persistent") as dialog, ui.card().classes("w-96"):
9593
self._dialog = dialog
@@ -202,3 +200,16 @@ def __call__(self, sequence: Sequence, description: str, unit: str) -> Iterable:
202200
return AutoIncrementingProgressbar(
203201
sequence, progressbar.counter, progressbar.notify, step_percentage=1
204202
)
203+
204+
205+
def _has_browser_to_show_in() -> bool:
206+
"""Whether the current task renders into a page a browser is looking at.
207+
208+
Two callers have none: preloading input files given on the command line at
209+
startup, which runs in the auto-index client before any page is served, and
210+
a load requested over HTTP rather than from a page, such as OTCloud handing
211+
its UI Worker an otconfig, whose task has no NiceGUI slot at all.
212+
"""
213+
if not context.slot_stack:
214+
return False
215+
return not context.client.is_auto_index_client

‎tests/unit/OTAnalytics/plugin_ui/nicegui_gui/nicegui/test_progressbar.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the in-browser progressbar of the webui."""
22

3+
import asyncio
34
from dataclasses import dataclass
45

56
import pytest
@@ -240,6 +241,24 @@ async def test_shows_nothing_when_no_browser_is_connected(
240241

241242
assert target.is_open is False
242243

244+
@pytest.mark.asyncio
245+
async def test_shows_nothing_when_opened_outside_any_page(
246+
self, user: User, resource_manager: ResourceManager
247+
) -> None:
248+
"""A load requested over HTTP, not from a page, has no browser to show in.
249+
250+
OTCloud hands the UI Worker an otconfig through a plain HTTP endpoint,
251+
whose task carries no NiceGUI slot at all.
252+
253+
#Requirement https://openproject.platomo.de/wp/10281
254+
"""
255+
given = create_given(resource_manager)
256+
target = create_target(given, total=2)
257+
258+
await asyncio.create_task(open_outside_any_page(target))
259+
260+
assert target.is_open is False
261+
243262
@pytest.mark.asyncio
244263
async def test_still_tracks_progress_when_no_browser_is_connected(
245264
self, user: User, resource_manager: ResourceManager
@@ -253,3 +272,8 @@ async def test_still_tracks_progress_when_no_browser_is_connected(
253272
target.complete("first.mp4")
254273

255274
assert target.state.message == "Downloading 1 / 2 files"
275+
276+
277+
async def open_outside_any_page(progressbar: NiceguiProgressbar) -> None:
278+
"""Open the progressbar in a fresh task, whose NiceGUI slot stack is empty."""
279+
progressbar.open()

0 commit comments

Comments
 (0)