mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-22 22:12:53 +02:00
Added a web-frontend to add companies to the search queue. (#375)
This webfrontent adds a company to the search que or resets the search que entry to be searched again. This will allow for directed growth or an initiallisation. --------- Co-authored-by: Tristan Nolde <tristan.nolde@yahoo.de>
This commit is contained in:
parent
8e6b28b311
commit
96d216fb74
@ -1,3 +1,7 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.normal_h3 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ __version__: Final[str] = _DISTRIBUTION_METADATA["Version"]
|
|||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def layout() -> list[html]:
|
def layout() -> html.Div:
|
||||||
"""Defines the layout of the about page.
|
"""Defines the layout of the about page.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -30,22 +30,25 @@ def layout() -> list[html]:
|
|||||||
git_revision = git_revision.replace(_, "")
|
git_revision = git_revision.replace(_, "")
|
||||||
|
|
||||||
git_revision = git_revision.strip()
|
git_revision = git_revision.strip()
|
||||||
return [
|
|
||||||
header_elements.create_selection_header("About"),
|
return html.Div(
|
||||||
html.H3("About Us"),
|
children=[
|
||||||
html.H3("Description"),
|
header_elements.create_selection_header("About"),
|
||||||
html.P(_DISTRIBUTION_METADATA["Summary"]),
|
html.H3("About Us", className="normal_h3"),
|
||||||
html.H3("Key Features"),
|
html.H3("Description"),
|
||||||
html.Ul(
|
html.P(_DISTRIBUTION_METADATA["Summary"]),
|
||||||
[
|
html.H3("Key Features", className="normal_h3"),
|
||||||
html.Li("Some feature."),
|
html.Ul(
|
||||||
]
|
[
|
||||||
),
|
html.Li("Some feature."),
|
||||||
html.H3("Version"),
|
]
|
||||||
html.Ul(
|
),
|
||||||
[
|
html.H3("Version", className="normal_h3"),
|
||||||
html.Li(f"Software Version: {__version__}"),
|
html.Ul(
|
||||||
html.Li(f"Build from GiT Revision: {git_revision}"),
|
[
|
||||||
]
|
html.Li(f"Software Version: {__version__}"),
|
||||||
),
|
html.Li(f"Build from GiT Revision: {git_revision}"),
|
||||||
]
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
66
src/aki_prj23_transparenzregister/ui/pages/search_queue.py
Normal file
66
src/aki_prj23_transparenzregister/ui/pages/search_queue.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""A page giving some details about this application including versioning."""
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
import dash
|
||||||
|
from dash import Input, Output, callback, dcc, html
|
||||||
|
from dash._callback import NoUpdate
|
||||||
|
|
||||||
|
from aki_prj23_transparenzregister.ui import header_elements
|
||||||
|
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
||||||
|
from aki_prj23_transparenzregister.utils.sql import entities
|
||||||
|
|
||||||
|
dash.register_page(__name__, path_template="/search/", title="Add data mining Job")
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def layout() -> html.Div:
|
||||||
|
"""Defines the layout of the about page.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list of html element making up this page.
|
||||||
|
"""
|
||||||
|
return html.Div(
|
||||||
|
children=[
|
||||||
|
header_elements.create_selection_header("Search more companies"),
|
||||||
|
html.H3(
|
||||||
|
"Please enter a Company to add to the search queue.",
|
||||||
|
className="normal_h3",
|
||||||
|
),
|
||||||
|
html.P(
|
||||||
|
"If a term is entered to the search queue data for that company will be searched for on the next run."
|
||||||
|
),
|
||||||
|
html.P(
|
||||||
|
"If the company was already searched for this is being reset and the priority is increased."
|
||||||
|
),
|
||||||
|
html.P(
|
||||||
|
"Please note that it can take a day until your queried data is mined and processed."
|
||||||
|
),
|
||||||
|
dcc.Input(id="input-text", type="text", placeholder="", debounce=True),
|
||||||
|
html.P("", id="response"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@callback(
|
||||||
|
Output("response", "children"),
|
||||||
|
Input("input-text", "value"),
|
||||||
|
)
|
||||||
|
def add_company_to_search_que(input_text: str | None) -> NoUpdate | list[str | html.B]:
|
||||||
|
"""Adds a company to the search que."""
|
||||||
|
if not input_text:
|
||||||
|
return dash.no_update
|
||||||
|
db = SessionHandler.session
|
||||||
|
if not db:
|
||||||
|
raise ValueError("No session created.")
|
||||||
|
db_result = (
|
||||||
|
db.query(entities.MissingCompany)
|
||||||
|
.filter(entities.MissingCompany.name == input_text)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if db_result:
|
||||||
|
db_result.number_of_links += 1000
|
||||||
|
db_result.searched_for = False
|
||||||
|
else:
|
||||||
|
db.add(entities.MissingCompany(name=input_text, number_of_links=1000))
|
||||||
|
db.commit()
|
||||||
|
return ["Added: ", html.B(input_text), " to the search que."]
|
@ -1,5 +1,5 @@
|
|||||||
"""Tests if the about page can be created."""
|
"""Tests if the about page can be created."""
|
||||||
from dash.development.base_component import Component
|
from dash import html
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.ui import app
|
from aki_prj23_transparenzregister.ui import app
|
||||||
from aki_prj23_transparenzregister.ui.pages import about
|
from aki_prj23_transparenzregister.ui.pages import about
|
||||||
@ -10,6 +10,4 @@ _ = app
|
|||||||
def test_layout() -> None:
|
def test_layout() -> None:
|
||||||
"""Checks if the about page can be created."""
|
"""Checks if the about page can be created."""
|
||||||
result = about.layout()
|
result = about.layout()
|
||||||
assert isinstance(result, list)
|
assert isinstance(result, html.Div)
|
||||||
for e in result:
|
|
||||||
assert isinstance(e, Component)
|
|
||||||
|
64
tests/ui/search_queue_test.py
Normal file
64
tests/ui/search_queue_test.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
"""Tests if the search que page can be created."""
|
||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
|
import dash
|
||||||
|
import pytest
|
||||||
|
from dash import html
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from aki_prj23_transparenzregister.ui import app
|
||||||
|
from aki_prj23_transparenzregister.ui.pages import search_queue
|
||||||
|
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
||||||
|
from aki_prj23_transparenzregister.utils.sql import entities
|
||||||
|
|
||||||
|
_ = app
|
||||||
|
|
||||||
|
|
||||||
|
def test_layout() -> None:
|
||||||
|
"""Checks if the about page can be created."""
|
||||||
|
result = search_queue.layout()
|
||||||
|
assert isinstance(result, html.Div)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("input_text", ["", None])
|
||||||
|
def test_empty(input_text: str | None) -> None:
|
||||||
|
"""Tests if nothing happens on an empty string."""
|
||||||
|
assert search_queue.add_company_to_search_que(input_text) == dash.no_update
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("input_text", ["test"])
|
||||||
|
def test_missing_db(input_text: str | None) -> None:
|
||||||
|
"""Tests what happens if no db is defined."""
|
||||||
|
with pytest.raises(ValueError, match="No session created."):
|
||||||
|
search_queue.add_company_to_search_que(input_text)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def _set_session(full_db: Session) -> Generator[None, None, None]:
|
||||||
|
"""Sets a session for the dash application to be used."""
|
||||||
|
SessionHandler.session = full_db
|
||||||
|
yield
|
||||||
|
SessionHandler.session = None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("_set_session")
|
||||||
|
@pytest.mark.parametrize("name", ["added-company", "second", "third"])
|
||||||
|
def test_add_company_to_queue(name: str) -> None:
|
||||||
|
"""Adds a company to the search que via the webgui."""
|
||||||
|
db = SessionHandler.session
|
||||||
|
assert db
|
||||||
|
assert not (
|
||||||
|
db.query(entities.MissingCompany)
|
||||||
|
.filter(entities.MissingCompany.name == name)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
for n_lines in [1000, 2000, 3000]:
|
||||||
|
search_queue.add_company_to_search_que(name)
|
||||||
|
result = (
|
||||||
|
db.query(entities.MissingCompany)
|
||||||
|
.filter(entities.MissingCompany.name == name)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
assert result
|
||||||
|
assert result.number_of_links == n_lines # noqa: PLR2004
|
||||||
|
del result
|
Loading…
x
Reference in New Issue
Block a user