-from dash import Dash, html, dcc, Input, Output, State, ctx
+from dash import Dash, html, dcc, Input, Output, State, ctx, ALL
import requests
+from datetime import datetime, timedelta
app = Dash(
__name__,
assets_folder="../../assets/",
)
+templates_div = html.Div(id="templates", className="d-flex gap-2", children=[])
app.layout = html.Div(
- [
+ className="container-md",
+ children=[
html.Div(
- className="mb-3",
children=[
+ html.Label("Label Text", className="form-label"),
+ dcc.Textarea(
+ id="label-text",
+ style={"width": "100%"},
+ className="form-control form-control-lg",
+ placeholder="Text for label",
+ rows="5",
+ ),
html.Div(
- className="mb-3",
- children=[
- html.Label("Label Text", className="form-label"),
- dcc.Textarea(
- id="label-text",
- style={"width": "100%"},
- className="form-control",
- placeholder="Text for label",
- ),
- html.Div(
- id="label-help",
- className="form-text",
- children=["Multiple lines print as shown"],
- ),
- ],
+ id="label-help",
+ className="form-text",
+ children=["Multiple lines print as shown"],
),
+ ],
+ ),
+ html.Div(
+ className="row",
+ children=[
html.Div(
- className="mb-3",
+ className="col-sm-2",
children=[
html.Label("Font size", className="form-label"),
dcc.Input(
],
),
html.Div(
- className="mb-3",
+ className="col-sm-2",
children=[
html.Label("Copies", className="form-label"),
dcc.Input(
),
],
),
- html.Button(
- "Print", name="print", id="print", className="btn btn-primary"
+ html.Div(
+ className="col-sm-8 align-self-center",
+ children=[
+ html.Button(
+ "Print",
+ name="print",
+ id="print",
+ type="submit",
+ className="btn btn-primary btn-lg",
+ )
+ ],
),
- html.Div(id="print-result"),
],
),
- ]
+ html.Div(
+ className="row", children=[html.Div(id="print-result", className="mb-3")]
+ ),
+ html.Div(
+ id="template-section",
+ className="container",
+ children=[
+ html.Label("Form Templates", className="form-label"),
+ templates_div,
+ ],
+ ),
+ ],
)
res = requests.post("http://localhost:8000/v1/queue", json=queue_item)
return res.text, 1
+
+
+def bottle_template():
+ today = datetime.now()
+ tomorrow = today + timedelta(days=1)
+ return f"BM 4 floz\nexp {today.strftime('%b %d')}\nuse {tomorrow.strftime('%b %d')}"
+
+
+def puree_template():
+ tomorrow = datetime.now() + timedelta(days=1)
+ return f"\nPurée\nuse {tomorrow.strftime('%b %d')}"
+
+
+templates = {
+ "bottle": {"label": "Bottle", "function": bottle_template},
+ "rayleigh": {"label": "Rayleigh", "value": "Rayleigh\nArmstrong-Dodgen"},
+ "kepler": {"label": "Kepler", "value": "Kepler\nArmstrong-Dodgen"},
+ "puree": {"label": "Purée", "function": puree_template},
+}
+
+for name, template in templates.items():
+ templates_div.children.append(
+ html.Button(
+ template["label"],
+ name=name,
+ id={"type": "template_button", "name": name},
+ className="btn btn-secondary",
+ )
+ )
+
+
+@app.callback(
+ Output("label-text", "value"),
+ Input({"type": "template_button", "name": ALL}, "n_clicks"),
+)
+def template_button(button):
+ if ctx.triggered_id is None:
+ return
+ if "name" not in ctx.triggered_id:
+ return
+ name = ctx.triggered_id["name"]
+ if name not in templates:
+ return
+ template = templates[name]
+ if "value" in template:
+ return template["value"]
+ if "function" in template:
+ return template["function"]()
+ return "No template defined"