Refactor inventory filtering and enhance templates with select inputs for improved data handling
This commit is contained in:
parent
ffaae2541f
commit
684a98b216
4 changed files with 26 additions and 13 deletions
Binary file not shown.
27
routes.py
27
routes.py
|
@ -136,8 +136,8 @@ def link(text, endpoint, **values):
|
|||
|
||||
FILTER_MAP = {
|
||||
'user': Inventory.owner_id,
|
||||
'room': Inventory.location_id,
|
||||
'brand': Inventory.brand_id,
|
||||
'location': Inventory.location_id,
|
||||
'type': Inventory.type_id,
|
||||
}
|
||||
|
||||
@main.route("/inventory")
|
||||
|
@ -157,10 +157,10 @@ def list_inventory():
|
|||
if column is not None:
|
||||
if filter_by == 'user':
|
||||
filter_name = db.session.query(User).filter(User.id == id).first().full_name
|
||||
elif filter_by == 'room':
|
||||
elif filter_by == 'location':
|
||||
filter_name = db.session.query(Room).filter(Room.id == id).first().full_name
|
||||
else:
|
||||
filter_name = db.session.query(Brand).filter(Brand.id == id).first().name
|
||||
filter_name = db.session.query(Item).filter(Item.id == id).first().description
|
||||
query = query.filter(column == id)
|
||||
else:
|
||||
return "Invalid filter_by parameter", 400
|
||||
|
@ -168,7 +168,7 @@ def list_inventory():
|
|||
return render_paginated_table(
|
||||
query=query,
|
||||
page=page,
|
||||
title=f"Inventory ({filter_name})" if filter_by else "Inventory",
|
||||
title=f"Inventory Listing ({filter_name})" if filter_by else "Inventory Listing",
|
||||
headers=inventory_headers,
|
||||
row_fn=lambda i: [fn(i) for fn in inventory_headers.values()],
|
||||
endpoint="main.list_inventory",
|
||||
|
@ -186,13 +186,20 @@ def inventory_index():
|
|||
users = db.session.query(User.id, User.first_name, User.last_name).order_by(User.first_name, User.last_name).all()
|
||||
listing = chunk_list([(user.id, f"{user.first_name or ''} {user.last_name or ''}".strip()) for user in users], 12)
|
||||
elif category == 'location':
|
||||
pass
|
||||
rooms = (
|
||||
db.session.query(Room.id, Room.name, RoomFunction.description)
|
||||
.join(RoomFunction, Room.function_id == RoomFunction.id)
|
||||
.order_by(Room.name, RoomFunction.description)
|
||||
.all()
|
||||
)
|
||||
listing = chunk_list([(room.id, f"{room.name or ''} - {room.description or ''}".strip()) for room in rooms], 12)
|
||||
elif category == 'type':
|
||||
pass
|
||||
types = db.session.query(Item.id, Item.description).order_by(Item.description).all()
|
||||
listing = chunk_list(types, 12)
|
||||
elif category:
|
||||
return f"Dude, why {category}?"
|
||||
|
||||
return render_template('inventory_index.html', title="Inventory Index", category=category, listing=listing)
|
||||
return render_template('inventory_index.html', title=f"Inventory ({category.capitalize()} Index)" if category else "Inventory", category=category, listing=listing)
|
||||
|
||||
@main.route("/inventory_item/<int:id>")
|
||||
def inventory_item(id):
|
||||
|
@ -204,6 +211,7 @@ def inventory_item(id):
|
|||
rooms = eager_load_room_relationships(db.session.query(Room)).all()
|
||||
worklog_query = db.session.query(WorkLog).filter(WorkLog.work_item_id == id)
|
||||
worklog_pagination = make_paginated_data(worklog_query, worklog_page, 5)
|
||||
types = db.session.query(Item).all()
|
||||
filtered_worklog_headers = {k: v for k, v in worklog_headers.items() if k not in ['Work Item', 'Contact', 'Follow Up?', 'Quick Analysis?']}
|
||||
worklog = worklog_pagination['items']
|
||||
|
||||
|
@ -219,12 +227,13 @@ def inventory_item(id):
|
|||
worklog_page=worklog_page,
|
||||
worklog_headers=filtered_worklog_headers,
|
||||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog],
|
||||
types=types
|
||||
)
|
||||
|
||||
@main.route("/users")
|
||||
def list_users():
|
||||
page = request.args.get('page', default=1, type=int)
|
||||
query = eager_load_user_relationships(db.session.query(User))
|
||||
query = eager_load_user_relationships(db.session.query(User)).order_by(User.last_name, User.first_name)
|
||||
return render_paginated_table(
|
||||
query=query,
|
||||
page=page,
|
||||
|
|
|
@ -60,9 +60,13 @@ submit_button=True) }}
|
|||
<input type="text" class="form-control" name="model" placeholder="-" value="{{ item.model }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="category" class="form-label">Category</label>
|
||||
<input type="text" class="form-control" name="category" placeholder="-"
|
||||
value="{{ item.item.description }}">
|
||||
<label for="type" class="form-label">Category</label>
|
||||
<select name="type" id="type" class="form-select">
|
||||
<option>-</option>
|
||||
{% for t in types %}
|
||||
<option value="{{ t.id }}"{% if t.id == item.type_id %} selected{% endif %}>{{ t.description }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
@ -83,7 +83,7 @@ title=title
|
|||
<div class="row my-3">
|
||||
{% for id, name in line %}
|
||||
<div class="col text-center">
|
||||
<a href="{{ url_for('main.list_inventory', filter_by='user', id=id) }}" class="link-success link-underline-opacity-0">{{ name }}</a>
|
||||
<a href="{{ url_for('main.list_inventory', filter_by=category, id=id) }}" class="link-success link-underline-opacity-0">{{ name }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue