Refactor Admin Dashboard and organize Counts module

This commit is contained in:
Javier
2026-01-30 10:30:17 -06:00
parent d6e9f20757
commit a6d8767c28
10 changed files with 172 additions and 135 deletions

View File

@@ -10,6 +10,50 @@ def get_active_session(session_id):
return None
return sess
@counting_bp.route('/counts/admin')
@login_required
def admin_dashboard():
"""Admin dashboard for Counts module"""
# Security check: Ensure user is admin/owner
if session.get('role') not in ['owner', 'admin']:
flash('Access denied. Admin role required.', 'danger')
return redirect(url_for('counting.index'))
show_archived = request.args.get('show_archived', '0') == '1'
# This SQL was moved from app.py
if show_archived:
sessions_list = query_db('''
SELECT s.*, u.full_name as created_by_name,
COUNT(DISTINCT lc.location_count_id) as total_locations,
SUM(CASE WHEN lc.status = 'completed' THEN 1 ELSE 0 END) as completed_locations,
SUM(CASE WHEN lc.status = 'in_progress' THEN 1 ELSE 0 END) as in_progress_locations
FROM CountSessions s
LEFT JOIN Users u ON s.created_by = u.user_id
LEFT JOIN LocationCounts lc ON s.session_id = lc.session_id
WHERE s.status IN ('active', 'archived')
GROUP BY s.session_id
ORDER BY s.status ASC, s.created_timestamp DESC
''')
else:
sessions_list = query_db('''
SELECT s.*, u.full_name as created_by_name,
COUNT(DISTINCT lc.location_count_id) as total_locations,
SUM(CASE WHEN lc.status = 'completed' THEN 1 ELSE 0 END) as completed_locations,
SUM(CASE WHEN lc.status = 'in_progress' THEN 1 ELSE 0 END) as in_progress_locations
FROM CountSessions s
LEFT JOIN Users u ON s.created_by = u.user_id
LEFT JOIN LocationCounts lc ON s.session_id = lc.session_id
WHERE s.status = 'active'
GROUP BY s.session_id
ORDER BY s.created_timestamp DESC
''')
return render_template('counts/admin_dashboard.html', sessions=sessions_list, show_archived=show_archived)
@counting_bp.route('/counts')
@login_required
def index():
@@ -33,7 +77,7 @@ def index():
ORDER BY created_timestamp DESC
''')
return render_template('staff_dashboard.html', sessions=active_sessions)
return render_template('counts/staff_dashboard.html', sessions=active_sessions)
@counting_bp.route('/count/<int:session_id>')
@@ -91,7 +135,7 @@ def my_counts(session_id):
ORDER BY lc.end_timestamp DESC
''', [session_id, session['user_id']])
return render_template('my_counts.html',
return render_template('counts/my_counts.html',
count_session=sess,
active_bins=active_bins,
completed_bins=completed_bins)
@@ -219,7 +263,7 @@ def count_location(session_id, location_count_id):
ORDER BY lot_number
''', [session_id, location['location_name'], location_count_id])
return render_template('count_location.html',
return render_template('counts/count_location.html',
session_id=session_id,
location=location,
scans=scans,