Verified Commit 57a0e2b0 authored by Jakob Moser's avatar Jakob Moser
Browse files

Start adding admin UI

parent 3796ca7a
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
from collections.abc import Sequence

from textual.app import ComposeResult
from textual.containers import Container, Grid, VerticalGroup
from textual.screen import ModalScreen
from textual.validation import Length
from textual.widgets import Button, Footer, Input, Label, MaskedInput


class AddPerson(ModalScreen):
    BINDINGS = [
        ("escape", "app.pop_screen", "Abbrechen"),
    ]

    def compose(self) -> ComposeResult:
        with VerticalGroup():
            with Grid():
                yield Label("Name")
                yield Input(
                    placeholder="Lara-Mi", id="name", validators=[Length(minimum=1)]
                )

                yield Label("CL-Account")
                yield MaskedInput(
                    template="<" + "a" * 32,
                    placeholder="holner",
                    id="cl_account_name",
                    validators=[Length(minimum=1)],
                )

                yield Label("Karten-ID")
                yield MaskedInput(
                    template="HH:HH:HH:HH:HH:HH:HH",
                    placeholder="12:34:56:78:90:ab:cd",
                    id="card_id",
                )

            with Container():
                yield Button("Hinzufügen", variant="primary", id="add_person")

        yield Footer()

    @property
    def _person_inputs(self) -> Sequence[Input]:
        selectors = ("#name", "#cl_account_name", "#card_id")
        return tuple(self.query_one(s, Input) for s in selectors)

    def _close(self) -> None:
        person_details = tuple(i.value for i in self._person_inputs)
        self.dismiss(person_details)

    def _close_if_complete(self) -> None:
        invalid_field_found = self._focus_next_invalid_field()
        if not invalid_field_found:
            self._close()

    def _focus_next_invalid_field(self) -> bool:
        for field in self._person_inputs:
            if not field.is_valid or field.value == "":
                field.focus()
                return True

        return False

    def on_button_pressed(self, event: Button.Pressed) -> None:
        match event.button.id:
            case "add_person":
                self._close_if_complete()

    def on_input_changed(self, event: Input.Changed) -> None:
        match event.input.id:
            case "cl_account_name":
                event.input.placeholder = "holner" if event.input.value == "" else ""

    def on_input_submitted(self, event: Input.Submitted) -> None:
        self._close_if_complete()
+3 −0
Original line number Diff line number Diff line
from poolpay.admin.PoolPayAdminApp import PoolPayAdminApp

app = PoolPayAdminApp()
+3 −0
Original line number Diff line number Diff line
from poolpay.admin import app

app.run()
+44 −0
Original line number Diff line number Diff line
Main {
    margin: 1 2;
}

Button {
    width: 25;
}

#persons {
    margin-top: 1;
}

AddPerson {
    align: center middle;

    VerticalGroup {
        border: solid $primary;
        padding: 1 2;

        background: $boost;

        Grid {
            grid-size: 2;
            grid-gutter: 1;
            grid-columns: auto 43;
            height: auto;
        }

        Label {
            padding: 1 0;
        }

        width: 60;
    }

    Button {
        margin-top: 2;
    }

    Container {
        align: center bottom;
        height: auto;
    }
}