87 lines
3.2 KiB
Python
87 lines
3.2 KiB
Python
from __future__ import annotations
|
|
import uuid, time
|
|
from typing import List, Dict, Any
|
|
from flask import Blueprint, render_template, request, redirect, url_for
|
|
|
|
from webapp.storage.orders import load_orders, add_order, mark_done
|
|
from webapp.services.blueprints import resolve_blueprint_id
|
|
|
|
bp = Blueprint("structures", __name__)
|
|
|
|
STRUCTURES = ["Athanor", "Raitaru", "Astrahus", "Fortizar", "Keepstar", "Tatara", "Sotiyo"]
|
|
SYSTEMS = ["Jita", "Perimeter", "Amarr", "Dodixie", "Rens", "Hek", "OGV-AS", "B-9C24", "K-6K16", "PUIG-F"]
|
|
IND_STRUCTS = ["Station", "Raitaru", "Azbel", "Sotiyo"]
|
|
IND_RIGS = ["None", "T1", "T2"]
|
|
REAC_STRUCTS= ["Athanor", "Tatara"]
|
|
REAC_RIGS = ["None", "T1", "T2"]
|
|
|
|
def _split_orders() -> Dict[str, List[Dict[str, Any]]]:
|
|
orders = load_orders()
|
|
open_orders = [o for o in orders if o.get("status") == "open"]
|
|
done_orders = [o for o in orders if o.get("status") == "done"]
|
|
open_orders.sort(key=lambda o: o.get("created_at",""), reverse=True)
|
|
done_orders.sort(key=lambda o: o.get("done_at","") or "", reverse=True)
|
|
return {"open": open_orders, "done": done_orders}
|
|
|
|
@bp.route("/strukturen", methods=["GET", "POST"])
|
|
def structures():
|
|
if request.method == "POST":
|
|
structure = request.form.get("structure","").strip()
|
|
quantity = int(request.form.get("quantity") or 1)
|
|
me = int(request.form.get("me") or 0)
|
|
system = request.form.get("system","Jita")
|
|
ind_struct= request.form.get("industry_structure","Station")
|
|
ind_rig = request.form.get("industry_rig","None")
|
|
reac_struct = request.form.get("reaction_structure","Athanor")
|
|
reac_rig = request.form.get("reaction_rig","None")
|
|
notes = request.form.get("notes","")
|
|
|
|
oid = uuid.uuid4().hex
|
|
now = time.strftime("%Y-%m-%dT%H:%M:%S%z", time.gmtime())
|
|
bp_id = resolve_blueprint_id(structure)
|
|
|
|
add_order({
|
|
"id": oid,
|
|
"status": "open",
|
|
"created_at": now,
|
|
"structure": structure,
|
|
"system": system,
|
|
"industry_structure": ind_struct,
|
|
"industry_rig": ind_rig,
|
|
"reaction_structure": reac_struct,
|
|
"reaction_rig": reac_rig,
|
|
"quantity": quantity,
|
|
"me": me,
|
|
"notes": notes,
|
|
"blueprint_type_id": bp_id
|
|
})
|
|
return redirect(url_for("structures.structures"))
|
|
|
|
parts = _split_orders()
|
|
return render_template(
|
|
"structures.html",
|
|
structures=STRUCTURES,
|
|
systems=SYSTEMS,
|
|
ind_structs=IND_STRUCTS,
|
|
ind_rigs=IND_RIGS,
|
|
reac_structs=REAC_STRUCTS,
|
|
reac_rigs=REAC_RIGS,
|
|
open_orders=parts["open"],
|
|
done_orders=parts["done"],
|
|
selected_system="Jita",
|
|
selected_ind_struct="Station",
|
|
selected_ind_rig="None",
|
|
selected_reac_struct="Athanor",
|
|
selected_reac_rig="None",
|
|
)
|
|
|
|
# ←← NEU/ WICHTIG: exakte Unterseiten-Route
|
|
@bp.get("/strukturen/mineralien")
|
|
def mineralien():
|
|
return render_template("minerals.html")
|
|
|
|
@bp.post("/strukturen/done/<order_id>")
|
|
def done(order_id: str):
|
|
mark_done(order_id)
|
|
return redirect(url_for("structures.structures"))
|