Create company page tab "Beteiligte Personen" (#330)

This commit is contained in:
KM-R 2023-11-06 21:40:48 +01:00 committed by GitHub
parent 4323522b96
commit d6fabfff1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 0 deletions

View File

@ -249,6 +249,9 @@ def create_tabs(session: Session, selected_company_id: int) -> html:
value="tab-2",
className="tab-style",
selected_className="selected-tab-style",
children=[
person_relations_layout(selected_company_id, session)
],
),
dcc.Tab(
label="Stimmung",
@ -270,6 +273,59 @@ def create_tabs(session: Session, selected_company_id: int) -> html:
)
def person_relations_layout(selected_company_id: int, session: Session) -> html:
"""Create person relation tab.
Args:
selected_company_id: Id of the chosen company in the dropdown.
session: A session connecting to the database.
Returns:
The html div to create the person relations tab of the company page.
"""
relations = data_elements.get_person_relations_of_one_company(
selected_company_id, session
)
if relations.empty:
return html.Div(
className="choose-metric",
children=[
html.H3(
className="metrics-title",
children=[
"Für dieses Unternehmen wurden leider keine beteiligten Personen gefunden."
],
)
],
)
table = (
relations[["firstname", "lastname", "relation", "date_from", "date_to"]]
.fillna("n.a.")
.rename(
columns={
"firstname": "Vorname",
"lastname": "Nachname",
"relation": "Rolle",
"date_from": "Von",
"date_to": "Bis",
}
)
)
return dash_table.DataTable(
table.to_dict("records"),
[{"name": i, "id": i} for i in table.columns],
style_table={
"width": "80%",
"marginLeft": "auto",
"marginRight": "auto",
"padding": "20px",
"color": COLORS["raisin-black"],
},
style_cell={"textAlign": "center"},
style_header={"backgroundColor": COLORS["light"], "fontWeight": "bold"},
)
def network_layout(selected_company_id: int) -> html:
"""Create network tab.

View File

@ -116,3 +116,39 @@ def get_options(session: Session | None) -> dict[int, str]:
all_options = pd.concat([persons_options, companies_options])
return all_options.sort_values(ascending=True).to_dict()
def get_person_relations_of_one_company(
selected_company_id: int, session: Session
) -> pd.DataFrame:
"""Collects all person relations of one company.
Args:
selected_company_id: Id of the company.
session: A session connecting to the database.
Returns:
A dataframe containing all person relations of the selected company.
"""
data = (
session.query(
entities.Company.id,
entities.PersonRelation.relation,
entities.PersonRelation.date_from,
entities.PersonRelation.date_to,
entities.Person.id,
entities.Person.lastname,
entities.Person.firstname,
)
.join(
entities.PersonRelation,
entities.PersonRelation.company_id == entities.Company.id,
)
.join(
entities.Person,
entities.PersonRelation.person_id == entities.Person.id,
)
.filter(entities.Company.id == selected_company_id) # type: ignore
.all()
)
return pd.DataFrame(data)