feat(library): add class filtering and sorting to library loans admin view
Release Inventarsystem / release-docker (push) Successful in 2m17s
Release Inventarsystem / release-docker (push) Successful in 2m17s
- Add class filter dropdown and class column to borrowings table - Implement interactive client-side column sorting for tables - Update backend route to resolve and map user class information
This commit is contained in:
+49
-6
@@ -3314,7 +3314,7 @@ def library_loans_admin():
|
||||
if 'username' not in session:
|
||||
flash('Ihnen ist es nicht gestattet auf dieser Internetanwendung, die eben besuchte Adrrese zu nutzen, versuchen sie es erneut nach dem sie sich mit einem berechtigten Nutzer angemeldet haben!', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
|
||||
current_permissions = us.get_effective_permissions(session['username'])
|
||||
|
||||
if not current_permissions['pages'].get('library_loans_admin', False):
|
||||
@@ -3342,10 +3342,12 @@ def library_loans_admin():
|
||||
db = client[MONGODB_DB]
|
||||
items_col = db['items']
|
||||
ausleihungen_col = db['ausleihungen']
|
||||
users_col = db['users']
|
||||
|
||||
library_items = list(items_col.find(
|
||||
{'ItemType': {'$in': LIBRARY_ITEM_TYPES}, 'Deleted': {'$ne': True}},
|
||||
{'Name': 1, 'Code_4': 1, 'Anschaffungskosten': 1, 'Condition': 1, 'HasDamage': 1, 'DamageReports': 1, 'Verfuegbar': 1, 'User': 1, 'ItemType': 1, 'Author': 1, 'ISBN': 1}
|
||||
{'Name': 1, 'Code_4': 1, 'Anschaffungskosten': 1, 'Condition': 1, 'HasDamage': 1, 'DamageReports': 1,
|
||||
'Verfuegbar': 1, 'User': 1, 'ItemType': 1, 'Author': 1, 'ISBN': 1}
|
||||
))
|
||||
item_map = {str(item['_id']): item for item in library_items if item.get('_id')}
|
||||
item_ids = list(item_map.keys())
|
||||
@@ -3354,28 +3356,68 @@ def library_loans_admin():
|
||||
if item_ids:
|
||||
active_records = list(ausleihungen_col.find(
|
||||
{'Item': {'$in': item_ids}, 'Status': {'$in': ['active', 'planned', 'completed']}},
|
||||
{'User': 1, 'Item': 1, 'Status': 1, 'Start': 1, 'End': 1, 'Period': 1, 'Notes': 1, 'InvoiceData': 1}
|
||||
{'User': 1, 'Item': 1, 'Status': 1, 'Start': 1, 'End': 1, 'Period': 1, 'Notes': 1, 'InvoiceData': 1,
|
||||
'Klasse': 1, 'Class': 1, 'school_class': 1}
|
||||
).sort('Start', -1))
|
||||
|
||||
user_map = {}
|
||||
if active_records:
|
||||
raw_users = list({r.get('User') for r in active_records if r.get('User')})
|
||||
decrypted_users = []
|
||||
for ru in raw_users:
|
||||
try:
|
||||
du = decrypt_text(ru) if ru else ''
|
||||
if du:
|
||||
decrypted_users.append(du)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
query_identifiers = list(set(raw_users + decrypted_users))
|
||||
if query_identifiers:
|
||||
user_docs = list(users_col.find(
|
||||
{'$or': [
|
||||
{'Username': {'$in': query_identifiers}},
|
||||
{'Name': {'$in': query_identifiers}},
|
||||
{'User': {'$in': query_identifiers}}
|
||||
]},
|
||||
{'Username': 1, 'Name': 1, 'User': 1, 'Klasse': 1, 'Class': 1, 'school_class': 1}
|
||||
))
|
||||
for u in user_docs:
|
||||
cls = u.get('Klasse') or u.get('Class') or u.get('school_class') or ''
|
||||
if cls:
|
||||
if u.get('Username'): user_map[u['Username']] = cls
|
||||
if u.get('Name'): user_map[u['Name']] = cls
|
||||
if u.get('User'): user_map[u['User']] = cls
|
||||
|
||||
active_item_ids = set()
|
||||
loan_entries = []
|
||||
for record in active_records:
|
||||
item_id = str(record.get('Item') or '')
|
||||
item_doc = item_map.get(item_id)
|
||||
if item_id and record.get('Status') == 'active':
|
||||
active_item_ids.add(item_id)
|
||||
|
||||
item_doc = item_map.get(item_id)
|
||||
if not item_doc:
|
||||
continue
|
||||
|
||||
invoice_data = record.get('InvoiceData') or {}
|
||||
condition_value = str(item_doc.get('Condition', '')).strip().lower()
|
||||
item_has_damage = bool(item_doc.get('HasDamage')) or condition_value == 'destroyed' or bool(item_doc.get('DamageReports'))
|
||||
item_has_damage = bool(item_doc.get('HasDamage')) or condition_value == 'destroyed' or bool(
|
||||
item_doc.get('DamageReports'))
|
||||
damage_reports = item_doc.get('DamageReports', []) or []
|
||||
|
||||
raw_user = record.get('User', '')
|
||||
decrypted_user = decrypt_text(raw_user) if raw_user else ''
|
||||
|
||||
user_class = (
|
||||
record.get('Klasse')
|
||||
or record.get('Class')
|
||||
or record.get('school_class')
|
||||
or user_map.get(raw_user, '')
|
||||
or user_map.get(decrypted_user, '')
|
||||
or ''
|
||||
)
|
||||
|
||||
loan_entries.append({
|
||||
'id': str(record.get('_id')),
|
||||
'item_id': item_id,
|
||||
@@ -3384,7 +3426,8 @@ def library_loans_admin():
|
||||
'item_author': item_doc.get('Author', ''),
|
||||
'item_isbn': item_doc.get('ISBN', ''),
|
||||
'item_cost_raw': item_doc.get('Anschaffungskosten', ''),
|
||||
'user': decrypted_user,
|
||||
'user': decrypted_user,
|
||||
'klasse': user_class,
|
||||
'status': record.get('Status', ''),
|
||||
'start': fmt_dt(record.get('Start')),
|
||||
'end': fmt_dt(record.get('End')),
|
||||
|
||||
Reference in New Issue
Block a user