Refactor inventory and worklog templates for improved rendering and pagination; enhance table display with better responsiveness and usability
This commit is contained in:
parent
bdd2a43c8b
commit
b68c25a05a
8 changed files with 48 additions and 184 deletions
72
routes.py
72
routes.py
|
@ -162,8 +162,8 @@ def index():
|
|||
|
||||
# Count items per condition
|
||||
expected_conditions = [
|
||||
'Deployed', 'Disposed', 'Inoperable', 'Partially Inoperable',
|
||||
'Removed', 'Unverified', 'Working'
|
||||
'Deployed','Inoperable', 'Partially Inoperable',
|
||||
'Unverified', 'Working'
|
||||
]
|
||||
pivot = df['condition'].value_counts().reindex(expected_conditions, fill_value=0)
|
||||
|
||||
|
@ -204,7 +204,6 @@ FILTER_MAP = {
|
|||
|
||||
@main.route("/inventory")
|
||||
def list_inventory():
|
||||
page = request.args.get('page', default=1, type=int)
|
||||
filter_by = request.args.get('filter_by', type=str)
|
||||
id = request.args.get('id', type=int)
|
||||
|
||||
|
@ -272,17 +271,15 @@ def inventory_index():
|
|||
|
||||
@main.route("/inventory_item/<int:id>")
|
||||
def inventory_item(id):
|
||||
worklog_page = request.args.get("worklog_page", default=1, type=int)
|
||||
inventory_query = db.session.query(Inventory)
|
||||
item = eager_load_inventory_relationships(inventory_query).filter(Inventory.id == id).first()
|
||||
brands = db.session.query(Brand).all()
|
||||
users = eager_load_user_relationships(db.session.query(User)).all()
|
||||
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)
|
||||
worklog = eager_load_worklog_relationships(worklog_query).all()
|
||||
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']
|
||||
|
||||
if item:
|
||||
title = f"Inventory Record - {item.identifier}"
|
||||
|
@ -291,9 +288,7 @@ def inventory_item(id):
|
|||
|
||||
return render_template("inventory.html", title=title, item=item,
|
||||
brands=brands, users=users, rooms=rooms,
|
||||
worklog=worklog,
|
||||
worklog_pagination=worklog_pagination,
|
||||
worklog_page=worklog_page,
|
||||
worklog=worklog,
|
||||
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
|
||||
|
@ -301,16 +296,14 @@ def inventory_item(id):
|
|||
|
||||
@main.route("/users")
|
||||
def list_users():
|
||||
page = request.args.get('page', default=1, type=int)
|
||||
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,
|
||||
title="Users",
|
||||
headers=user_headers,
|
||||
row_fn=lambda i: [fn(i) for fn in user_headers.values()],
|
||||
endpoint="main.list_users",
|
||||
entry_route="user"
|
||||
users = query.all()
|
||||
return render_template(
|
||||
'table.html',
|
||||
header = user_headers,
|
||||
rows = [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in users],
|
||||
title = "Users",
|
||||
entry_route = 'user'
|
||||
)
|
||||
|
||||
@main.route("/user/<int:id>")
|
||||
|
@ -327,14 +320,13 @@ def user(id):
|
|||
.filter(Inventory.owner_id == id)
|
||||
.filter(Inventory.condition.in_(ACTIVE_STATUSES))
|
||||
)
|
||||
inventory_pagination = make_paginated_data(inventory_query, asset_page, 10)
|
||||
inventory = inventory_pagination['items']
|
||||
|
||||
inventory = inventory_query.all()
|
||||
filtered_inventory_headers = {k: v for k, v in inventory_headers.items() if k not in ['Date Entered', 'Inventory #', 'Serial #',
|
||||
'Bar Code #', 'Condition', 'Owner', 'Notes',
|
||||
'Brand', 'Model', 'Shared?', 'Location']}
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog)).filter(WorkLog.contact_id == id)
|
||||
worklog_pagination = make_paginated_data(worklog_query, worklog_page, 10)
|
||||
worklog = worklog_pagination['items']
|
||||
worklog = worklog_query.order_by(WorkLog.start_time.desc()).all()
|
||||
filtered_worklog_headers = {k: v for k, v in worklog_headers.items() if k not in ['Contact', 'Follow Up?', 'Quick Analysis?']}
|
||||
return render_template(
|
||||
"user.html",
|
||||
|
@ -342,27 +334,21 @@ def user(id):
|
|||
user=user, users=users, rooms=rooms, assets=inventory,
|
||||
inventory_headers=filtered_inventory_headers,
|
||||
inventory_rows=[{"id": item.id, "cells": [fn(item) for fn in filtered_inventory_headers.values()]} for item in inventory],
|
||||
inventory_pagination=inventory_pagination,
|
||||
asset_page=asset_page,
|
||||
worklog=worklog,
|
||||
worklog_headers=filtered_worklog_headers,
|
||||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog],
|
||||
worklog_pagination=worklog_pagination,
|
||||
worklog_page=worklog_page
|
||||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog]
|
||||
)
|
||||
|
||||
@main.route("/worklog")
|
||||
def list_worklog(page=1):
|
||||
page = request.args.get('page', default=1, type=int)
|
||||
query = eager_load_worklog_relationships(db.session.query(WorkLog))
|
||||
return render_paginated_table(
|
||||
query=query,
|
||||
page=page,
|
||||
return render_template(
|
||||
'table.html',
|
||||
header=worklog_headers,
|
||||
rows=[{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in query.all()],
|
||||
title="Work Log",
|
||||
headers=worklog_headers,
|
||||
row_fn=lambda i: [fn(i) for fn in worklog_headers.values()],
|
||||
endpoint="main.list_worklog",
|
||||
entry_route="worklog_entry"
|
||||
entry_route='worklog_entry'
|
||||
)
|
||||
|
||||
@main.route("/worklog/<int:id>")
|
||||
|
@ -377,9 +363,6 @@ def worklog_entry(id):
|
|||
@main.route("/search")
|
||||
def search():
|
||||
query = request.args.get('q', '').strip()
|
||||
inventory_page = request.args.get('inventory_page', default=1, type=int)
|
||||
user_page = request.args.get('user_page', default=1, type=int)
|
||||
worklog_page = request.args.get('worklog_page', default=1, type=int)
|
||||
|
||||
if not query:
|
||||
return redirect(url_for('index'))
|
||||
|
@ -396,7 +379,7 @@ def search():
|
|||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%")
|
||||
))
|
||||
inventory_pagination = make_paginated_data(inventory_query, inventory_page)
|
||||
inventory_results = inventory_query.all()
|
||||
user_query = eager_load_user_relationships(db.session.query(User).join(UserAlias, User.supervisor)).filter(
|
||||
or_(
|
||||
User.first_name.ilike(f"%{query}%"),
|
||||
|
@ -404,7 +387,7 @@ def search():
|
|||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%")
|
||||
))
|
||||
user_pagination = make_paginated_data(user_query, user_page)
|
||||
user_results = user_query.all()
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog).join(UserAlias, WorkLog.contact).join(InventoryAlias, WorkLog.work_item)).filter(
|
||||
or_(
|
||||
WorkLog.notes.ilike(f"%{query}%"),
|
||||
|
@ -414,26 +397,23 @@ def search():
|
|||
InventoryAlias.serial.ilike(f"%{query}%"),
|
||||
InventoryAlias.barcode.ilike(f"%{query}%")
|
||||
))
|
||||
worklog_pagination = make_paginated_data(worklog_query, worklog_page)
|
||||
worklog_results = worklog_query.all()
|
||||
|
||||
results = {
|
||||
'inventory': {
|
||||
'results': inventory_query,
|
||||
'headers': inventory_headers,
|
||||
'rows': [{"id": item.id, "cells": [fn(item) for fn in inventory_headers.values()]} for item in inventory_pagination['items']],
|
||||
'pagination': inventory_pagination
|
||||
'rows': [{"id": item.id, "cells": [fn(item) for fn in inventory_headers.values()]} for item in inventory_results]
|
||||
},
|
||||
'users': {
|
||||
'results': user_query,
|
||||
'headers': user_headers,
|
||||
'rows': [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in user_pagination['items']],
|
||||
'pagination': user_pagination
|
||||
'rows': [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in user_results]
|
||||
},
|
||||
'worklog': {
|
||||
'results': worklog_query,
|
||||
'headers': worklog_headers,
|
||||
'rows': [{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in worklog_pagination['items']],
|
||||
'pagination': worklog_pagination
|
||||
'rows': [{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in worklog_results]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue