Updating git

This commit is contained in:
2025-08-10 11:29:39 +02:00
parent 8eca1da3ca
commit 5820efb7f1
14 changed files with 263 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
import json
import logging
from fasthtml.core import EventStream
from fasthtml.fastapp import fast_app
from starlette.datastructures import UploadFile
@@ -136,3 +137,10 @@ def post(session, _id: str, state: str, args: str = None):
logger.debug(f"Entering on_state_changed with args {_id=}, {state=}, {args=}")
instance = InstanceManager.get(session, _id)
return instance.manage_state_changed(state, args)
@rt(Routes.YieldRow)
async def get(session, _id: str):
logger.debug(f"Entering {Routes.YieldRow} with args {_id=}")
instance = InstanceManager.get(session, _id)
return EventStream(instance.mk_async_lasy_body_content())

View File

@@ -20,9 +20,10 @@ from components.datagrid_new.db_management import DataGridDbManager
from components.datagrid_new.settings import DataGridRowState, DataGridColumnState, \
DataGridFooterConf, DataGridState, DataGridSettings, DatagridView
from components_helpers import mk_icon, mk_ellipsis
from core.fasthtml_helper import MyDiv, mk_my_ellipsis, MySpan, mk_my_icon
from core.instance_manager import InstanceManager
from core.settings_management import SettingsManager
from core.utils import get_unique_id, make_safe_id
from core.utils import get_unique_id, make_safe_id, timed, profile_function
logger = logging.getLogger("DataGrid")
@@ -386,6 +387,7 @@ class DataGrid(BaseComponent):
id=f"scb_{self._id}",
)
@profile_function
def mk_table(self, oob=False):
htmx_extra_params = {
"hx-on::before-settle": f"onAfterSettle('{self._id}', event);",
@@ -439,7 +441,8 @@ class DataGrid(BaseComponent):
_mk_keyboard_management(),
Div(
self.mk_table_header(),
self.mk_table_body(),
# self.mk_table_body(),
self.mk_table_body_lasy(),
self.mk_table_footer(),
cls="dt2-inner-table"),
cls="dt2-table",
@@ -479,6 +482,22 @@ class DataGrid(BaseComponent):
id=f"th_{self._id}"
)
def mk_table_body_lasy(self):
df = self._get_filtered_df()
max_height = self._compute_body_max_height()
return Div(
# *self.mk_lasy_body_content(df),
hx_ext="sse",
sse_connect=f"{ROUTE_ROOT}{Routes.YieldRow}",
hx_swap="beforeend show:bottom",
sse_swap="message",
cls="dt2-body",
style=f"max-height:{max_height}px;",
id=f"tb_{self._id}",
hx_vals=f'{{"_id": "{self._id}"}}',
)
def mk_table_body(self):
df = self._get_filtered_df()
max_height = self._compute_body_max_height()
@@ -507,31 +526,49 @@ class DataGrid(BaseComponent):
id=f"tf_{self._id}"
)
async def mk_async_lasy_body_content(self, df):
for row_index in df.index:
yield sse_message(Div(
*[self.mk_body_cell(col_pos, row_index, col_def) for col_pos, col_def in enumerate(self._state.columns)],
cls="dt2-row",
data_row=f"{row_index}",
id=f"tr_{self._id}-{row_index}",
))
def mk_lasy_body_content(self, df):
return [Div(
*[self.mk_body_cell(col_pos, row_index, col_def) for col_pos, col_def in enumerate(self._state.columns)],
cls="dt2-row",
data_row=f"{row_index}",
id=f"tr_{self._id}-{row_index}",
) for row_index in df.index]
def mk_body_cell(self, col_pos, row_index, col_def: DataGridColumnState):
if not col_def.usable:
return None
if not col_def.visible:
return Div(cls="dt2-col-hidden")
return MyDiv(cls="dt2-col-hidden")
content = self.mk_body_cell_content(col_pos, row_index, col_def)
return Div(content,
data_col=col_def.col_id,
style=f"width:{col_def.width}px;",
cls="dt2-cell")
return MyDiv(content,
data_col=col_def.col_id,
style=f"width:{col_def.width}px;",
cls="dt2-cell")
@profile_function
def mk_body_cell_content(self, col_pos, row_index, col_def: DataGridColumnState):
def mk_bool(value):
return Div(mk_icon(icon_checked if value else icon_unchecked, can_select=False),
cls="dt2-cell-content-checkbox")
return MyDiv(mk_my_icon(icon_checked if value else icon_unchecked, can_select=False),
cls="dt2-cell-content-checkbox")
def mk_text(value):
return mk_ellipsis(value, cls="dt2-cell-content-text")
return mk_my_ellipsis(value, cls="dt2-cell-content-text")
def mk_number(value):
return mk_ellipsis(value, cls="dt2-cell-content-number")
return mk_my_ellipsis(value, cls="dt2-cell-content-number")
def process_cell_content(value):
value_str = str(value)
@@ -545,9 +582,9 @@ class DataGrid(BaseComponent):
return value_str
len_keyword = len(keyword)
res = [Span(value_str[:index])] if index > 0 else []
res += [Span(value_str[index:index + len_keyword], cls="dt2-highlight-1")]
res += [Span(value_str[index + len_keyword:])] if len(value_str) > len_keyword else []
res = [MySpan(value_str[:index])] if index > 0 else []
res += [MySpan(value_str[index:index + len_keyword], cls="dt2-highlight-1")]
res += [MySpan(value_str[index + len_keyword:])] if len(value_str) > len_keyword else []
return tuple(res)
column_type = col_def.type
@@ -822,6 +859,7 @@ class DataGrid(BaseComponent):
return True
@timed
def __ft__(self):
return Div(
Div(
@@ -844,7 +882,7 @@ class DataGrid(BaseComponent):
@staticmethod
def new(session, data, index=None):
datagrid = DataGrid(session, DataGrid.create_component_id(session))
#dataframe = DataFrame(data, index=index)
# dataframe = DataFrame(data, index=index)
dataframe = DataFrame(data)
datagrid.init_from_dataframe(dataframe)
return datagrid

View File

@@ -33,6 +33,7 @@ class Routes:
UpdateView = "/update_view"
ShowFooterMenu = "/show_footer_menu"
UpdateState = "/update_state"
YieldRow = "/yield-row"
class ColumnType(Enum):
@@ -44,11 +45,13 @@ class ColumnType(Enum):
Choice = "Choice"
List = "List"
class ViewType(Enum):
Table = "Table"
Chart = "Chart"
Form = "Form"
class FooterAggregation(Enum):
Sum = "Sum"
Mean = "Mean"
@@ -59,4 +62,4 @@ class FooterAggregation(Enum):
FilteredMean = "FilteredMean"
FilteredMin = "FilteredMin"
FilteredMax = "FilteredMax"
FilteredCount = "FilteredCount"
FilteredCount = "FilteredCount"