Skip to content

partials

controller.views.partials

Partial views module for the controller app.

Functions

app_tree_view_summary(request)

Renders the app tree view summary.

Source code in controller/views/partials.py
@login_required
def app_tree_view_summary(request: HttpRequest) -> HttpResponse:
    """Renders the app tree view summary."""
    return render(
        request=request,
        context=dict(tree=app_tree.get_app_tree(request.user.username)),
        template_name="controller/partials/app_tree_summary_partial.html",
    )

app_tree_view_table(request)

View that renders the app tree view table.

Source code in controller/views/partials.py
@login_required
def app_tree_view_table(request: HttpRequest) -> HttpResponse:
    """View that renders the app tree view table."""
    table = tables.AppTreeTable(app_tree.get_app_tree(request.user.username).to_list())
    return render(
        request=request,
        context=dict(table=table),
        template_name="controller/partials/app_tree_table_partial.html",
    )

dialog(request)

Dialog to gather the input arguments required by the event.

Source code in controller/views/partials.py
@login_required
def dialog(request: HttpRequest) -> HttpResponse:
    """Dialog to gather the input arguments required by the event."""
    event = request.POST.get("event", None)

    form = forms.get_form_for_event(event)() if event else Form()
    has_args = len(form.fields) > 0

    return render(
        request=request,
        context=dict(
            event=event,
            has_args=has_args,
            form=form,
        ),
        template_name="controller/partials/arguments_dialog.html",
    )

make_fsm_flowchart(states, current_state)

Create Mermaid syntax for a flowchart of FSM states and transitions.

Parameters:

Name Type Description Default
states dict[str, dict[str, str]]

The FSM states and events.

required
current_state str

The current state of the FSM.

required

Returns:

Name Type Description
str str

Mermaid syntax for the flowchart.

Source code in controller/views/partials.py
def make_fsm_flowchart(states: dict[str, dict[str, str]], current_state: str) -> str:
    """Create Mermaid syntax for a flowchart of FSM states and transitions.

    Args:
        states (dict[str, dict[str, str]]): The FSM states and events.
        current_state (str): The current state of the FSM.

    Returns:
        str: Mermaid syntax for the flowchart.
    """
    link = 0
    chart = "flowchart TD\n"
    chart += "classDef default stroke:black,stroke-width:2px\n"
    chart += "linkStyle default background-color:#b5b3ae,stroke-width:2px\n"
    for state, events in states.items():
        for event, target in events.items():
            chart += f"{state}({state}) -->|{event}| {target}({target})\n"
            if state == current_state:
                chart += f"style {state} fill:#93c54b,color:#325d88\n"
                chart += f"linkStyle {link} background-color:#93c54b,color:#325d88\n"
            link += 1

    return chart

state_machine(request)

Triggers a chan.

Source code in controller/views/partials.py
@login_required
def state_machine(request: HttpRequest) -> HttpResponse:
    """Triggers a chan."""
    event = request.POST.get("event", None)
    arguments: dict[str, Any] = {  # type: ignore[explicit-any]
        k: v
        for k, v in request.POST.items()
        if k not in ["csrfmiddlewaretoken", "event"]
    }
    if event:
        form = forms.get_form_for_event(event)(arguments)
        if form.is_valid():
            ci.send_event(event, form.cleaned_data)
        else:
            raise ValueError(f"Invalid form: {form.errors}")

    states = fsm.get_fsm_architecture()
    current_state = ci.get_fsm_state()
    table = tables.FSMTable.from_dict(states, current_state)
    flowchart = make_fsm_flowchart(states, current_state)

    return render(
        request=request,
        context=dict(table=table, flowchart=flowchart),
        template_name="controller/partials/state_machine.html",
    )