Addint submit and toast behavior.
This commit is contained in:
parent
fc4d3ebfe6
commit
dbf0d6169a
6 changed files with 137 additions and 22 deletions
|
|
@ -96,7 +96,9 @@ def init_entry_routes(app):
|
|||
fields["fields"] = ["id", "contact", "work_item", "start_time", "end_time", "complete"]
|
||||
fields_spec = [
|
||||
{"name": "id", "label": "", "type": "display", "label_spec": "Work Item #{id}",
|
||||
"attrs": {"class": "display-6 mb-3"}, "row": "label"},
|
||||
"attrs": {"class": "display-6 mb-3"}, "row": "label", "wrap": {"class": "col"}},
|
||||
{"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html",
|
||||
"wrap": {"class": "col text-end me-2"}, "attrs": {"data-model": model}},
|
||||
{"name": "contact", "row": "ownership", "wrap": {"class": "col"}, "label": "Contact",
|
||||
"label_spec": "{label}", "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}},
|
||||
{"name": "work_item", "row": "ownership", "wrap": {"class": "col"}, "label": "Work Item",
|
||||
|
|
@ -111,7 +113,7 @@ def init_entry_routes(app):
|
|||
"type": "template", "template": "update_list.html"},
|
||||
]
|
||||
layout = [
|
||||
{"name": "label", "order": 0},
|
||||
{"name": "label", "order": 0, "attrs": {"class": "row align-items-center"}},
|
||||
{"name": "ownership", "order": 10, "attrs": {"class": "row mb-2"}},
|
||||
{"name": "timestamps", "order": 20, "attrs": {"class": "row d-flex align-items-center"}},
|
||||
{"name": "updates", "order": 30, "attrs": {"class": "row"}},
|
||||
|
|
@ -132,7 +134,6 @@ def init_entry_routes(app):
|
|||
updates_cls.is_deleted == False)
|
||||
.order_by(updates_cls.timestamp.asc()))
|
||||
all_updates = updates_q.all()
|
||||
print(all_updates)
|
||||
|
||||
for f in fields_spec:
|
||||
if f.get("name") == "updates" and f.get("type") == "template":
|
||||
|
|
@ -141,8 +142,6 @@ def init_entry_routes(app):
|
|||
f["template_ctx"] = ctx
|
||||
break
|
||||
|
||||
print(fields_spec)
|
||||
|
||||
form = render_form(
|
||||
cls,
|
||||
obj.as_dict(),
|
||||
|
|
@ -150,13 +149,34 @@ def init_entry_routes(app):
|
|||
instance=obj,
|
||||
fields_spec=fields_spec,
|
||||
layout=layout,
|
||||
submit_attrs={"class": "btn btn-primary mt-3"},
|
||||
submit_attrs={"class": "d-none", "disabled": True},
|
||||
)
|
||||
# sanity log
|
||||
u = getattr(obj, "updates", None)
|
||||
print("WORKLOG UPDATES loaded? ",
|
||||
"None" if u is None else f"len={len(list(u))} ids={[n.id for n in list(u)]}")
|
||||
|
||||
return render_template("entry.html", form=form)
|
||||
|
||||
@bp_entry.post("/entry/<model>/<int:id>")
|
||||
def update_entry(model, id):
|
||||
try:
|
||||
if model not in ["inventory", "user", "worklog"]:
|
||||
raise TypeError("Invalid model.")
|
||||
payload = request.get_json()
|
||||
cls = crudkit.crud.get_model(model)
|
||||
|
||||
if model == "inventory":
|
||||
pass
|
||||
elif model == "user":
|
||||
pass
|
||||
elif model == "worklog":
|
||||
pass
|
||||
else:
|
||||
raise TypeError("Invalid model.")
|
||||
|
||||
service = crudkit.crud.get_service(cls)
|
||||
item = service.get(id)
|
||||
print(item.as_dict(), payload)
|
||||
|
||||
return {"status": "success", "payload": payload}
|
||||
except Exception as e:
|
||||
return {"status": "failure", "error": str(e)}
|
||||
|
||||
app.register_blueprint(bp_entry)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue