ux refine
This commit is contained in:
+18
-2
@@ -82,6 +82,10 @@ def _image_response_or_404(target) -> Response:
|
||||
return Response(content=target.image_blob, media_type=target.image_mime_type)
|
||||
|
||||
|
||||
def _wants_add_next(submit_action: str | None) -> bool:
|
||||
return submit_action == "save_and_add_next"
|
||||
|
||||
|
||||
def _build_search_results(db: Session, query: str) -> list[dict]:
|
||||
keyword = f"%{query.lower()}%"
|
||||
results: list[dict] = []
|
||||
@@ -333,6 +337,7 @@ def create_app() -> FastAPI:
|
||||
note: str | None = Form(default=None),
|
||||
quantity: str | None = Form(default=None),
|
||||
is_container: str | None = Form(default=None),
|
||||
submit_action: str | None = Form(default=None),
|
||||
image_file: UploadFile | None = File(default=None),
|
||||
db: Session = Depends(get_db),
|
||||
) -> RedirectResponse:
|
||||
@@ -348,7 +353,13 @@ def create_app() -> FastAPI:
|
||||
db.add(item)
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return RedirectResponse(url=f"/items/{item.id}", status_code=status.HTTP_303_SEE_OTHER)
|
||||
if _wants_add_next(submit_action):
|
||||
redirect_url = f"/boxes/{box.id}/items/new"
|
||||
elif item.is_container:
|
||||
redirect_url = f"/items/{item.id}"
|
||||
else:
|
||||
redirect_url = f"/boxes/{box.id}"
|
||||
return RedirectResponse(url=redirect_url, status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
def show_item(item_id: int, request: Request, db: Session = Depends(get_db)):
|
||||
@@ -436,6 +447,7 @@ def create_app() -> FastAPI:
|
||||
name: str = Form(...),
|
||||
note: str | None = Form(default=None),
|
||||
quantity: str | None = Form(default=None),
|
||||
submit_action: str | None = Form(default=None),
|
||||
image_file: UploadFile | None = File(default=None),
|
||||
db: Session = Depends(get_db),
|
||||
) -> RedirectResponse:
|
||||
@@ -451,7 +463,11 @@ def create_app() -> FastAPI:
|
||||
db.add(subitem)
|
||||
db.commit()
|
||||
db.refresh(subitem)
|
||||
return RedirectResponse(url=f"/items/{item.id}", status_code=status.HTTP_303_SEE_OTHER)
|
||||
if _wants_add_next(submit_action):
|
||||
redirect_url = f"/items/{item.id}/subitems/new"
|
||||
else:
|
||||
redirect_url = f"/items/{item.id}"
|
||||
return RedirectResponse(url=redirect_url, status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
@app.get("/subitems/{subitem_id}/image")
|
||||
def get_subitem_image(subitem_id: int, db: Session = Depends(get_db)) -> Response:
|
||||
|
||||
@@ -63,6 +63,12 @@ button,
|
||||
padding: 10px 14px;
|
||||
}
|
||||
|
||||
.button-secondary {
|
||||
background: #eef3f8;
|
||||
color: #1f2937;
|
||||
border: 1px solid #cbd5e1;
|
||||
}
|
||||
|
||||
.button:hover,
|
||||
button:hover {
|
||||
opacity: 0.92;
|
||||
@@ -280,6 +286,12 @@ button:hover {
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,13 @@
|
||||
</button>
|
||||
</section>
|
||||
{% endif %}
|
||||
<button type="submit">{{ submit_label }}</button>
|
||||
<div class="form-actions">
|
||||
<button type="submit" name="submit_action" value="save">{{ submit_label }}</button>
|
||||
{% if not item %}
|
||||
<button type="submit" name="submit_action" value="save_and_add_next" class="button-secondary">
|
||||
保存并添加下一个
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -72,6 +72,13 @@
|
||||
</button>
|
||||
</section>
|
||||
{% endif %}
|
||||
<button type="submit">{{ submit_label }}</button>
|
||||
<div class="form-actions">
|
||||
<button type="submit" name="submit_action" value="save">{{ submit_label }}</button>
|
||||
{% if not subitem %}
|
||||
<button type="submit" name="submit_action" value="save_and_add_next" class="button-secondary">
|
||||
保存并添加下一个
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user