Skip to content

Commit

Permalink
added PersonView to query nominate (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed May 28, 2024
1 parent 58a0219 commit 1a87cb6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 35 deletions.
67 changes: 39 additions & 28 deletions snapquery/person_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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
Expand All @@ -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
"""
Expand Down Expand Up @@ -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():
Expand Down
18 changes: 16 additions & 2 deletions snapquery/qimport_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = ""
Expand Down Expand Up @@ -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):
"""
Expand Down
24 changes: 19 additions & 5 deletions snapquery/snapquery_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Created on 2024-05-03
@author: wf
"""

from pathlib import Path

from fastapi import HTTPException
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1a87cb6

Please sign in to comment.