|
15 | 15 | ) |
16 | 16 | from nicegui import run as nicegui_run |
17 | 17 |
|
18 | | -from aignostics.platform import ItemOutput, ItemResult, ItemState, RunState |
| 18 | +from aignostics.platform import ItemOutput, ItemResult, ItemState, RunState, Run |
19 | 19 | from aignostics.third_party.showinfm.showinfm import show_in_file_manager |
20 | 20 | from aignostics.utils import GUILocalFilePicker, get_user_data_directory |
| 21 | +from aignx.codegen.models import ArtifactOutput |
21 | 22 |
|
22 | 23 | if TYPE_CHECKING: |
23 | 24 | from aignx.codegen.models import RunReadResponse |
@@ -430,9 +431,10 @@ def csv_view_dialog_content(title: str | None, url: str | None) -> None: |
430 | 431 | with ui.row(align_items="end").classes("w-full"), ui.column(align_items="end").classes("w-full"): |
431 | 432 | ui.button("Close", on_click=csv_view_dialog.close) |
432 | 433 |
|
433 | | - def csv_dialog_open(title: str, url: str) -> None: |
| 434 | + def csv_dialog_open(title: str, artifact_id: str) -> None: |
434 | 435 | """Open the CSV dialog.""" |
435 | | - csv_view_dialog_content.refresh(title=title, url=url) |
| 436 | + download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id) |
| 437 | + csv_view_dialog_content.refresh(title=title, url=download_url) |
436 | 438 | csv_view_dialog.open() |
437 | 439 |
|
438 | 440 | @ui.refreshable |
@@ -478,15 +480,16 @@ def tiff_view_dialog_content(title: str | None, url: str | None) -> None: |
478 | 480 | with ui.row(align_items="end").classes("w-full"), ui.column(align_items="end").classes("w-full"): |
479 | 481 | ui.button("Close", on_click=tiff_view_dialog.close) |
480 | 482 |
|
481 | | - def tiff_dialog_open(title: str, url: str) -> None: |
| 483 | + def tiff_dialog_open(title: str, artifact_id: str) -> None: |
482 | 484 | """Open the TIFF dialog. |
483 | 485 |
|
484 | 486 | Args: |
485 | 487 | title (str): The title of the TIFF dialog. |
486 | | - url (str): The URL of the TIFF image. |
| 488 | + artifact_id: (str): The ID of the artifact containing the TIFF to display. |
487 | 489 |
|
488 | 490 | """ |
489 | | - tiff_view_dialog_content.refresh(title=title, url=url) |
| 491 | + download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id) |
| 492 | + tiff_view_dialog_content.refresh(title=title, url=download_url) |
490 | 493 | tiff_view_dialog.open() |
491 | 494 |
|
492 | 495 | @ui.refreshable |
@@ -516,6 +519,10 @@ def custom_metadata_dialog_open(title: str, custom_metadata: dict[str, Any]) -> |
516 | 519 | custom_metadata_dialog_content.refresh(title=title, custom_metadata=custom_metadata) |
517 | 520 | custom_metadata_dialog.open() |
518 | 521 |
|
| 522 | + def open_browser(_, artifact_id): |
| 523 | + download_url = Run.for_run_id(run_id).get_artifact_download_url(artifact_id) |
| 524 | + webbrowser.open(download_url) |
| 525 | + |
519 | 526 | async def open_qupath( |
520 | 527 | project: Path | None = None, image: Path | str | None = None, button: ui.button | None = None |
521 | 528 | ) -> None: |
@@ -760,29 +767,28 @@ def render_item(item: ItemResult) -> None: # noqa: C901, PLR0912, PLR0915 |
760 | 767 | icon=mime_type_to_icon(mime_type), |
761 | 768 | group="artifacts", |
762 | 769 | ).classes("w-full"): |
763 | | - if artifact.download_url: |
764 | | - url = artifact.download_url |
| 770 | + if artifact.output == ArtifactOutput.AVAILABLE: |
| 771 | + artifact_id = artifact.output_artifact_id |
765 | 772 | title = artifact.name |
766 | 773 | metadata = artifact.metadata |
767 | 774 | with ui.button_group(): |
768 | 775 | if mime_type == "image/tiff": |
769 | 776 | ui.button( |
770 | 777 | "Preview", |
771 | 778 | icon=mime_type_to_icon(mime_type), |
772 | | - on_click=lambda _, url=url, title=title: tiff_dialog_open(title, url), |
| 779 | + on_click=lambda _, artifact_id=artifact_id, title=title: tiff_dialog_open(title, artifact_id), |
773 | 780 | ) |
774 | 781 | if mime_type == "text/csv": |
775 | 782 | ui.button( |
776 | 783 | "Preview", |
777 | 784 | icon=mime_type_to_icon(mime_type), |
778 | | - on_click=lambda _, url=url, title=title: csv_dialog_open(title, url), |
779 | | - ) |
780 | | - if url: |
781 | | - ui.button( |
782 | | - text="Download", |
783 | | - icon="cloud_download", |
784 | | - on_click=lambda _, url=url: webbrowser.open(url), |
| 785 | + on_click=lambda _, artifact_id=artifact_id, title=title: csv_dialog_open(title, artifact_id), |
785 | 786 | ) |
| 787 | + ui.button( |
| 788 | + text="Download", |
| 789 | + icon="cloud_download", |
| 790 | + on_click=lambda _, artifact_id=artifact_id: open_browser(_, artifact_id), |
| 791 | + ) |
786 | 792 | if metadata: |
787 | 793 | ui.button( |
788 | 794 | text="Schema", |
|
0 commit comments