diff --git a/snapquery/person_selector.py b/snapquery/person_selector.py index ea44ec9..91dd7ff 100644 --- a/snapquery/person_selector.py +++ b/snapquery/person_selector.py @@ -15,31 +15,31 @@ from snapquery.pid import PIDs, PIDValue -class PersonSuggestion(Element): +class PersonView(Element): """ - Display a Person + Display a person """ - def __init__(self, person: Person, on_select: Callable[[Person], Any]): + def __init__(self, person: Person): self.pids = PIDs() self.pid_values = self._create_pid_values(person) super().__init__(tag="div") self.person = person - self._on_select_callback = on_select - with ui.item(on_click=self.on_select) as self.person_card: - with ui.item_section().props("avatar"): - with ui.avatar(): - if person.image: - ui.image(source=person.image) - with ui.item_section(): - with ui.row(): - self.person_label = ui.label(self.person.label) - with ui.row(): - self.person_name = ui.label( - f"{self.person.given_name} {self.person.family_name}" - ) - with ui.row(): - self._show_identifier() + with self: + with ui.item() as self.person_card: + with ui.item_section().props("avatar"): + with ui.avatar(): + if person.image: + ui.image(source=person.image) + with ui.item_section(): + with ui.row(): + self.person_label = ui.label(self.person.label) + with ui.row(): + self.person_name = ui.label( + f"{self.person.given_name} {self.person.family_name}" + ) + with ui.row(): + self._show_identifier() def _create_pid_values(self, person: Person) -> List[PIDValue]: """ @@ -53,12 +53,6 @@ def _create_pid_values(self, person: Person) -> List[PIDValue]: pid_values.append(PIDValue(pid=pid, value=pid_value)) return pid_values - def on_select(self): - """ - Handle selection of the suggestion card - """ - return self._on_select_callback(self.person) - def _show_identifier(self): """ Display all identifiers of the person @@ -78,12 +72,31 @@ def _show_identifier(self): ) +class PersonSuggestion(PersonView): + """ + Display a Person + """ + + def __init__(self, person: Person, on_select: Callable[[Person], Any]): + super().__init__(person=person) + self._on_select_callback = on_select + self.person_card.on_click(self.on_select) + + def on_select(self): + """ + Handle selection of the suggestion card + """ + return self._on_select_callback(self.person) + + class PersonSelector: """ Select a person with auto-suggestion """ - def __init__(self, solution: WebSolution, selection_callback: Callable[[Person], Any]): + def __init__( + self, solution: WebSolution, selection_callback: Callable[[Person], Any] + ): """ Constructor """ @@ -161,9 +174,7 @@ def update_suggestion_list(self, container: ui.element, suggestions: List[Person ui.item_label("Suggestions").props("header").classes("text-bold") ui.separator() for person in suggestions[:10]: - PersonSuggestion( - person=person, on_select=self.selection_callback - ) + PersonSuggestion(person=person, on_select=self.selection_callback) if len(suggestions) > 10: with ui.item(): diff --git a/snapquery/qimport_view.py b/snapquery/qimport_view.py index 682c0b1..d71d7b7 100644 --- a/snapquery/qimport_view.py +++ b/snapquery/qimport_view.py @@ -4,9 +4,13 @@ @author: wf """ +from typing import Optional + from lodstorage.query import Query, QuerySyntaxHighlight from nicegui import ui +from snapquery.models.person import Person +from snapquery.person_selector import PersonView from snapquery.qimport import QueryImport from snapquery.snapquery_core import NamedQuery @@ -16,7 +20,13 @@ class QueryImportView: display Query Import UI """ - def __init__(self, solution=None, allow_importing_from_url: bool = True): + def __init__( + self, + solution=None, + person: Optional[Person] = None, + allow_importing_from_url: bool = True, + ): + self.person = person self.solution = solution self.allow_importing_from_url = allow_importing_from_url self.namespace = "" @@ -60,7 +70,11 @@ def setup_ui(self): ui.tooltip("Descriptive title of the query") ui.textarea(label="description").bind_value(self, "description") self.named_query_link = ui.html() - self.query_row = ui.row() + self.query_row = ui.row().classes("w-full h-full ") + with self.query_row: + ui.textarea(label="query").bind_value(self, "query").classes( + "w-full h-full border-solid m-5 border-gray-dark border-2 rounded-md" + ) def on_import_button(self, _args): """ diff --git a/snapquery/snapquery_webserver.py b/snapquery/snapquery_webserver.py index 5490c39..a534b00 100644 --- a/snapquery/snapquery_webserver.py +++ b/snapquery/snapquery_webserver.py @@ -2,6 +2,7 @@ Created on 2024-05-03 @author: wf """ + from pathlib import Path from fastapi import HTTPException @@ -17,7 +18,7 @@ from snapquery.models.person import Person from snapquery.orcid import OrcidAuth from snapquery.qimport_view import QueryImportView -from snapquery.person_selector import PersonSelector +from snapquery.person_selector import PersonSelector, PersonView from snapquery.snapquery_core import NamedQueryManager, QueryBundle from snapquery.snapquery_view import NamedQuerySearch, NamedQueryView from snapquery.stats_view import QueryStatsView @@ -330,13 +331,26 @@ def show(): """ show the nominate ui """ + def selection_callback(person: Person): self.container.clear() with self.container: - ui.label(text="Nominate your Query").classes("text-xl") - ui.link(text="see the documentation for detailed information on the nomination procedure", new_tab=True, target="https://wiki.bitplan.com/index.php/Snapquery#nominate") - self.query_import_view = QueryImportView(self, allow_importing_from_url=False) - self.person_selector = PersonSelector(solution=self, selection_callback=selection_callback) + with ui.row().classes("w-full"): + with ui.column(): + ui.label(text="Nominate your Query").classes("text-xl") + ui.link( + text="see the documentation for detailed information on the nomination procedure", + new_tab=True, + target="https://wiki.bitplan.com/index.php/Snapquery#nominate", + ) + PersonView(person).classes("ml-auto bg-slate-100 rounded-md") + self.query_import_view = QueryImportView( + self, allow_importing_from_url=False + ) + + self.person_selector = PersonSelector( + solution=self, selection_callback=selection_callback + ) await self.setup_content_div(show)