Compare commits
2 Commits
ResolvingP
...
957a92f903
| Author | SHA1 | Date | |
|---|---|---|---|
| 957a92f903 | |||
| 33970c9c97 |
@@ -1,4 +1,4 @@
|
|||||||
from core.utils import get_user_id
|
from core.utils import get_user_id, get_unique_id
|
||||||
|
|
||||||
|
|
||||||
class BaseComponent:
|
class BaseComponent:
|
||||||
@@ -51,3 +51,12 @@ class BaseComponentSingleton(BaseComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def create_component_id(cls, session):
|
def create_component_id(cls, session):
|
||||||
return f"{cls.COMPONENT_INSTANCE_ID}{session['user_id']}"
|
return f"{cls.COMPONENT_INSTANCE_ID}{session['user_id']}"
|
||||||
|
|
||||||
|
|
||||||
|
class BaseComponentMultipleInstance(BaseComponent):
|
||||||
|
COMPONENT_INSTANCE_ID = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_component_id(cls, session):
|
||||||
|
component_id = cls.COMPONENT_INSTANCE_ID or cls.__name__
|
||||||
|
return get_unique_id(f"{component_id}{session['user_id']}")
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from fasthtml.components import Div, sse_message
|
|
||||||
from fasthtml.core import EventStream
|
|
||||||
from fasthtml.fastapp import fast_app
|
from fasthtml.fastapp import fast_app
|
||||||
from starlette.datastructures import UploadFile
|
from starlette.datastructures import UploadFile
|
||||||
|
|
||||||
@@ -141,12 +138,6 @@ def post(session, _id: str, state: str, args: str = None):
|
|||||||
return instance.manage_state_changed(state, args)
|
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_body_content_sse())
|
|
||||||
|
|
||||||
@rt(Routes.GetPage)
|
@rt(Routes.GetPage)
|
||||||
def get(session, _id: str, page_index: int):
|
def get(session, _id: str, page_index: int):
|
||||||
logger.debug(f"Entering {Routes.GetPage} with args {_id=}, {page_index=}")
|
logger.debug(f"Entering {Routes.GetPage} with args {_id=}, {page_index=}")
|
||||||
|
|||||||
@@ -400,7 +400,6 @@ class DataGrid(BaseComponent):
|
|||||||
id=f"scb_{self._id}",
|
id=f"scb_{self._id}",
|
||||||
)
|
)
|
||||||
|
|
||||||
@timed
|
|
||||||
def mk_table(self, oob=False):
|
def mk_table(self, oob=False):
|
||||||
htmx_extra_params = {
|
htmx_extra_params = {
|
||||||
"hx-on::before-settle": f"onAfterSettle('{self._id}', event);",
|
"hx-on::before-settle": f"onAfterSettle('{self._id}', event);",
|
||||||
|
|||||||
@@ -118,38 +118,6 @@ class DataGridCommandManager(BaseCommandManager):
|
|||||||
"data_tooltip": tooltip_msg,
|
"data_tooltip": tooltip_msg,
|
||||||
"cls": self.merge_class(cls, "mmt-tooltip")
|
"cls": self.merge_class(cls, "mmt-tooltip")
|
||||||
}
|
}
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def merge(*items):
|
|
||||||
# """
|
|
||||||
# Merges multiple dictionaries into a single dictionary by combining their key-value pairs.
|
|
||||||
# If a key exists in multiple dictionaries and its value is a string, the values are concatenated.
|
|
||||||
# If the key's value is not a string, an error is raised.
|
|
||||||
#
|
|
||||||
# :param items: dictionaries to be merged. If all items are None, None is returned.
|
|
||||||
# :return: A single dictionary containing the merged key-value pairs from all input dictionaries.
|
|
||||||
# :raises NotImplementedError: If a key's value is not a string and exists in multiple input dictionaries.
|
|
||||||
# """
|
|
||||||
# if all(item is None for item in items):
|
|
||||||
# return None
|
|
||||||
#
|
|
||||||
# res = {}
|
|
||||||
# for item in [item for item in items if item is not None]:
|
|
||||||
#
|
|
||||||
# for key, value in item.items():
|
|
||||||
# if not key in res:
|
|
||||||
# res[key] = value
|
|
||||||
# else:
|
|
||||||
# if isinstance(res[key], str):
|
|
||||||
# res[key] += " " + value
|
|
||||||
# else:
|
|
||||||
# raise NotImplementedError("")
|
|
||||||
#
|
|
||||||
# return res
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def merge_class(cls1, cls2):
|
|
||||||
# return (cls1 + " " + cls2) if cls2 else cls1
|
|
||||||
|
|
||||||
|
|
||||||
class FilterAllCommands(BaseCommandManager):
|
class FilterAllCommands(BaseCommandManager):
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class Routes:
|
|||||||
UpdateView = "/update_view"
|
UpdateView = "/update_view"
|
||||||
ShowFooterMenu = "/show_footer_menu"
|
ShowFooterMenu = "/show_footer_menu"
|
||||||
UpdateState = "/update_state"
|
UpdateState = "/update_state"
|
||||||
YieldRow = "/yield-row"
|
|
||||||
GetPage = "/page"
|
GetPage = "/page"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
src/components/entryselector/EntrySelectorApp.py
Normal file
17
src/components/entryselector/EntrySelectorApp.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from fasthtml.fastapp import fast_app
|
||||||
|
|
||||||
|
from components.entryselector.constants import Routes
|
||||||
|
from core.instance_manager import debug_session, InstanceManager
|
||||||
|
|
||||||
|
logger = logging.getLogger("EntrySelectorApp")
|
||||||
|
|
||||||
|
repositories_app, rt = fast_app()
|
||||||
|
|
||||||
|
|
||||||
|
@rt(Routes.Select)
|
||||||
|
def get(session, _id: str, entry: str):
|
||||||
|
logger.debug(f"Entering {Routes.Select} with args {debug_session(session)}, {_id=}, {entry=}")
|
||||||
|
instance = InstanceManager.get(session, _id)
|
||||||
|
return instance.select_entry(entry)
|
||||||
0
src/components/entryselector/__init__.py
Normal file
0
src/components/entryselector/__init__.py
Normal file
0
src/components/entryselector/assets/__init__.py
Normal file
0
src/components/entryselector/assets/__init__.py
Normal file
15
src/components/entryselector/commands.py
Normal file
15
src/components/entryselector/commands.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from components.BaseCommandManager import BaseCommandManager
|
||||||
|
from components.entryselector.constants import Routes, ROUTE_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
class EntrySelectorCommandManager(BaseCommandManager):
|
||||||
|
def __init__(self, owner):
|
||||||
|
super().__init__(owner)
|
||||||
|
|
||||||
|
def select_entry(self, entry):
|
||||||
|
return {
|
||||||
|
"hx-get": f"{ROUTE_ROOT}{Routes.Select}",
|
||||||
|
"hx-target": f"#{self._owner.content_id}",
|
||||||
|
"hx-swap": "innerHTML",
|
||||||
|
"hx-vals": f'{{"_id": "{self._id}", "entry": "{entry}"}}',
|
||||||
|
}
|
||||||
46
src/components/entryselector/components/EntrySelector.py
Normal file
46
src/components/entryselector/components/EntrySelector.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from fasthtml.components import *
|
||||||
|
|
||||||
|
from components.BaseComponent import BaseComponentMultipleInstance
|
||||||
|
from components.entryselector.commands import EntrySelectorCommandManager
|
||||||
|
|
||||||
|
logger = logging.getLogger("EntrySelector")
|
||||||
|
|
||||||
|
|
||||||
|
class EntrySelector(BaseComponentMultipleInstance):
|
||||||
|
def __init__(self, session, _id, owner, content_id, data=None, hooks=None, key=None, boundaries=None):
|
||||||
|
super().__init__(session, _id)
|
||||||
|
self._key = key
|
||||||
|
self._owner = owner # debugger component
|
||||||
|
self.data = data
|
||||||
|
self.content_id = content_id
|
||||||
|
self.hooks = hooks
|
||||||
|
self._boundaries = boundaries if boundaries else {"width": "300"}
|
||||||
|
self._commands = EntrySelectorCommandManager(self)
|
||||||
|
|
||||||
|
def set_data(self, data):
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
def set_boundaries(self, boundaries):
|
||||||
|
self._boundaries = boundaries
|
||||||
|
|
||||||
|
def select_entry(self, entry):
|
||||||
|
logger.debug(f"Selecting entry {entry}")
|
||||||
|
# return self._owner.select_entry(entry)
|
||||||
|
|
||||||
|
def _mk_content(self):
|
||||||
|
if self.data is None:
|
||||||
|
return [Div("no entry")]
|
||||||
|
|
||||||
|
return [Div(index,
|
||||||
|
**self._commands.select_entry(index),
|
||||||
|
cls="es-entry") for index in range(self.data)]
|
||||||
|
|
||||||
|
def __ft__(self):
|
||||||
|
return Div(
|
||||||
|
*self._mk_content(),
|
||||||
|
style=f"width: {self._boundaries['width']}px;",
|
||||||
|
cls="flex",
|
||||||
|
id=f"{self._id}",
|
||||||
|
)
|
||||||
0
src/components/entryselector/components/__init__.py
Normal file
0
src/components/entryselector/components/__init__.py
Normal file
5
src/components/entryselector/constants.py
Normal file
5
src/components/entryselector/constants.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ROUTE_ROOT = "/es" # for EntrySelector
|
||||||
|
|
||||||
|
|
||||||
|
class Routes:
|
||||||
|
Select = "/select"
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
from fasthtml.common import *
|
from fasthtml.common import *
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
from components.BaseComponent import BaseComponent
|
from components.BaseComponent import BaseComponent
|
||||||
|
from components.entryselector.components.EntrySelector import EntrySelector
|
||||||
from components.workflows.constants import COMPONENT_TYPES, PROCESSOR_TYPES
|
from components.workflows.constants import COMPONENT_TYPES, PROCESSOR_TYPES
|
||||||
from components_helpers import mk_dialog_buttons
|
from components_helpers import mk_dialog_buttons
|
||||||
|
from core.instance_manager import InstanceManager
|
||||||
from core.jira import JiraRequestTypes, DEFAULT_SEARCH_FIELDS
|
from core.jira import JiraRequestTypes, DEFAULT_SEARCH_FIELDS
|
||||||
from utils.DbManagementHelper import DbManagementHelper
|
from utils.DbManagementHelper import DbManagementHelper
|
||||||
|
|
||||||
@@ -25,6 +26,14 @@ class WorkflowDesignerProperties(BaseComponent):
|
|||||||
self._component = None
|
self._component = None
|
||||||
self.update_layout()
|
self.update_layout()
|
||||||
self.update_component(self._owner.get_state().selected_component_id)
|
self.update_component(self._owner.get_state().selected_component_id)
|
||||||
|
self._input_entry_selector = InstanceManager.new(self._session,
|
||||||
|
EntrySelector,
|
||||||
|
owner=self,
|
||||||
|
content_id=f"pic_{self._id}", data=100)
|
||||||
|
self._output_entry_selector = InstanceManager.new(self._session,
|
||||||
|
EntrySelector,
|
||||||
|
owner=self,
|
||||||
|
content_id=f"poc_{self._id}")
|
||||||
|
|
||||||
def update_layout(self):
|
def update_layout(self):
|
||||||
if self._owner.get_state().properties_input_width is None:
|
if self._owner.get_state().properties_input_width is None:
|
||||||
@@ -66,7 +75,8 @@ class WorkflowDesignerProperties(BaseComponent):
|
|||||||
|
|
||||||
def _mk_input(self):
|
def _mk_input(self):
|
||||||
return Div(
|
return Div(
|
||||||
"Input",
|
self._input_entry_selector,
|
||||||
|
Div(id=f"pic_{self._id}"),
|
||||||
id=f"pi_{self._id}",
|
id=f"pi_{self._id}",
|
||||||
style=f"width: {self.layout.input_width}px;",
|
style=f"width: {self.layout.input_width}px;",
|
||||||
cls="wkf-properties-input"
|
cls="wkf-properties-input"
|
||||||
@@ -74,7 +84,8 @@ class WorkflowDesignerProperties(BaseComponent):
|
|||||||
|
|
||||||
def _mk_output(self):
|
def _mk_output(self):
|
||||||
return Div(
|
return Div(
|
||||||
"Output",
|
self._output_entry_selector,
|
||||||
|
"Output Content",
|
||||||
id=f"po_{self._id}",
|
id=f"po_{self._id}",
|
||||||
style=f"width: {self.layout.output_width}px;",
|
style=f"width: {self.layout.output_width}px;",
|
||||||
cls="wkf-properties-output"
|
cls="wkf-properties-output"
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ class InstanceManager:
|
|||||||
|
|
||||||
return InstanceManager._instances[key]
|
return InstanceManager._instances[key]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def new(session, instance_type, **kwargs):
|
||||||
|
return InstanceManager.get(session, instance_type.create_component_id(session), instance_type, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def register(session: dict | None, instance, instance_id: str = None):
|
def register(session: dict | None, instance, instance_id: str = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
33
src/main.py
33
src/main.py
@@ -1,7 +1,5 @@
|
|||||||
# global layout
|
# global layout
|
||||||
import logging.config
|
import logging.config
|
||||||
import random
|
|
||||||
from asyncio import sleep
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from fasthtml.common import *
|
from fasthtml.common import *
|
||||||
@@ -55,9 +53,6 @@ links = [
|
|||||||
Link(href="./assets/daisyui-5-themes.css", rel="stylesheet", type="text/css"),
|
Link(href="./assets/daisyui-5-themes.css", rel="stylesheet", type="text/css"),
|
||||||
Script(src="./assets/tailwindcss-browser@4.js"),
|
Script(src="./assets/tailwindcss-browser@4.js"),
|
||||||
|
|
||||||
# SSE
|
|
||||||
Script(src="https://unpkg.com/htmx-ext-sse@2.2.1/sse.js"),
|
|
||||||
|
|
||||||
# Old drawer layout
|
# Old drawer layout
|
||||||
Script(src="./assets/DrawerLayout.js", defer=True),
|
Script(src="./assets/DrawerLayout.js", defer=True),
|
||||||
Link(rel="stylesheet", href="./assets/DrawerLayout.css"),
|
Link(rel="stylesheet", href="./assets/DrawerLayout.css"),
|
||||||
@@ -151,6 +146,7 @@ register_component("theme_controller", "components.themecontroller", "ThemeContr
|
|||||||
register_component("main_layout", "components.drawerlayout", "DrawerLayoutApp")
|
register_component("main_layout", "components.drawerlayout", "DrawerLayoutApp")
|
||||||
register_component("undo_redo", "components.undo_redo", "UndoRedoApp")
|
register_component("undo_redo", "components.undo_redo", "UndoRedoApp")
|
||||||
register_component("tabs", "components.tabs", "TabsApp") # before repositories
|
register_component("tabs", "components.tabs", "TabsApp") # before repositories
|
||||||
|
register_component("entryselector", "components.entryselector", "EntrySelectorApp")
|
||||||
register_component("applications", "components.applications", "ApplicationsApp")
|
register_component("applications", "components.applications", "ApplicationsApp")
|
||||||
register_component("repositories", "components.repositories", "RepositoriesApp")
|
register_component("repositories", "components.repositories", "RepositoriesApp")
|
||||||
register_component("workflows", "components.workflows", "WorkflowsApp")
|
register_component("workflows", "components.workflows", "WorkflowsApp")
|
||||||
@@ -219,7 +215,7 @@ app, rt = fast_app(
|
|||||||
# -------------------------
|
# -------------------------
|
||||||
# Profiling middleware
|
# Profiling middleware
|
||||||
# -------------------------
|
# -------------------------
|
||||||
@app.middleware("http")
|
# @app.middleware("http")
|
||||||
async def timing_middleware(request, call_next):
|
async def timing_middleware(request, call_next):
|
||||||
import time
|
import time
|
||||||
start_total = time.perf_counter()
|
start_total = time.perf_counter()
|
||||||
@@ -276,31 +272,6 @@ def get(session):
|
|||||||
DrawerLayoutOld(pages),)
|
DrawerLayoutOld(pages),)
|
||||||
|
|
||||||
|
|
||||||
shutdown_event = signal_shutdown()
|
|
||||||
|
|
||||||
|
|
||||||
async def number_generator():
|
|
||||||
while True: # not shutdown_event.is_set():
|
|
||||||
data = Article(random.randint(1, 100))
|
|
||||||
print(data)
|
|
||||||
yield sse_message(data)
|
|
||||||
await sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
@rt("/sse")
|
|
||||||
def get():
|
|
||||||
return Titled("SSE Random Number Generator",
|
|
||||||
P("Generate pairs of random numbers, as the list grows scroll downwards."),
|
|
||||||
Div(hx_ext="sse",
|
|
||||||
sse_connect="/number-stream",
|
|
||||||
hx_swap="beforeend show:bottom",
|
|
||||||
sse_swap="message"))
|
|
||||||
|
|
||||||
|
|
||||||
@rt("/number-stream")
|
|
||||||
async def get(): return EventStream(number_generator())
|
|
||||||
|
|
||||||
|
|
||||||
@rt('/toasting')
|
@rt('/toasting')
|
||||||
def get(session):
|
def get(session):
|
||||||
# Normally one toast is enough, this allows us to see
|
# Normally one toast is enough, this allows us to see
|
||||||
|
|||||||
Reference in New Issue
Block a user