reworked dashboard
This commit is contained in:
@@ -5,6 +5,18 @@ import os
|
||||
from werkzeug.utils import secure_filename
|
||||
from sqlalchemy import func, case, literal_column, text
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
import sys
|
||||
|
||||
# Set up logging to show in console
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.StreamHandler(sys.stdout)
|
||||
]
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def init_routes(main_bp):
|
||||
@main_bp.route('/')
|
||||
@@ -16,6 +28,7 @@ def init_routes(main_bp):
|
||||
@main_bp.route('/dashboard')
|
||||
@login_required
|
||||
def dashboard():
|
||||
logger.info("Loading dashboard...")
|
||||
# Get 3 most recent users
|
||||
recent_contacts = User.query.order_by(User.created_at.desc()).limit(3).all()
|
||||
# Count active and inactive users
|
||||
@@ -24,10 +37,13 @@ def init_routes(main_bp):
|
||||
|
||||
# Room count and size logic
|
||||
if current_user.is_admin:
|
||||
logger.info("Loading admin dashboard...")
|
||||
room_count = Room.query.count()
|
||||
# Get total file and folder counts for admin
|
||||
file_count = RoomFile.query.filter_by(type='file').count()
|
||||
folder_count = RoomFile.query.filter_by(type='folder').count()
|
||||
logger.info(f"Admin stats - Files: {file_count}, Folders: {folder_count}")
|
||||
|
||||
# Get total size of all files including trash
|
||||
total_size = db.session.query(func.sum(RoomFile.size)).filter(RoomFile.type == 'file').scalar() or 0
|
||||
# Get recent activity for all files
|
||||
@@ -39,10 +55,21 @@ def init_routes(main_bp):
|
||||
Room, RoomFile.room_id == Room.id
|
||||
).join(
|
||||
User, RoomFile.uploaded_by == User.id
|
||||
).filter(
|
||||
RoomFile.deleted == False,
|
||||
RoomFile.uploaded_at.isnot(None)
|
||||
).order_by(
|
||||
RoomFile.uploaded_at.desc()
|
||||
).limit(10).all()
|
||||
|
||||
logger.info(f"Recent activity query results: {len(recent_activity)}")
|
||||
if len(recent_activity) == 0:
|
||||
# Debug query to see what files exist
|
||||
all_files = RoomFile.query.filter_by(deleted=False).all()
|
||||
logger.info(f"Total non-deleted files: {len(all_files)}")
|
||||
for file in all_files[:5]: # Log first 5 files for debugging
|
||||
logger.info(f"File: {file.name}, Uploaded: {file.uploaded_at}, Type: {file.type}")
|
||||
|
||||
# Format the activity data
|
||||
formatted_activity = []
|
||||
for file, room, user in recent_activity:
|
||||
@@ -57,7 +84,8 @@ def init_routes(main_bp):
|
||||
'can_download': True # Admin can download everything
|
||||
}
|
||||
formatted_activity.append(activity)
|
||||
recent_activity = formatted_activity
|
||||
formatted_activities = formatted_activity
|
||||
logger.info(f"Formatted activities: {len(formatted_activities)}")
|
||||
# Get storage usage by file type including trash
|
||||
storage_by_type = db.session.query(
|
||||
case(
|
||||
@@ -122,11 +150,24 @@ def init_routes(main_bp):
|
||||
).join(
|
||||
User, RoomFile.uploaded_by == User.id
|
||||
).filter(
|
||||
RoomFile.room_id.in_(room_ids)
|
||||
RoomFile.room_id.in_(room_ids),
|
||||
RoomFile.deleted == False,
|
||||
RoomFile.uploaded_at.isnot(None) # Ensure uploaded_at is not null
|
||||
).order_by(
|
||||
RoomFile.uploaded_at.desc()
|
||||
).limit(10).all()
|
||||
|
||||
logger.info(f"Recent activity query results (non-admin): {len(recent_activity)}")
|
||||
if len(recent_activity) == 0:
|
||||
# Debug query to see what files exist
|
||||
all_files = RoomFile.query.filter(
|
||||
RoomFile.room_id.in_(room_ids),
|
||||
RoomFile.deleted == False
|
||||
).all()
|
||||
logger.info(f"Total non-deleted files in accessible rooms: {len(all_files)}")
|
||||
for file in all_files[:5]: # Log first 5 files for debugging
|
||||
logger.info(f"File: {file.name}, Uploaded: {file.uploaded_at}, Type: {file.type}")
|
||||
|
||||
# Format the activity data
|
||||
formatted_activity = []
|
||||
user_perms = {p.room_id: p for p in RoomMemberPermission.query.filter(
|
||||
@@ -147,7 +188,7 @@ def init_routes(main_bp):
|
||||
'can_download': perm.can_download if perm else False
|
||||
}
|
||||
formatted_activity.append(activity)
|
||||
recent_activity = formatted_activity
|
||||
formatted_activities = formatted_activity
|
||||
# Get storage usage by file type for accessible rooms including trash
|
||||
storage_by_type = db.session.query(
|
||||
case(
|
||||
@@ -204,7 +245,6 @@ def init_routes(main_bp):
|
||||
file_count=file_count,
|
||||
folder_count=folder_count,
|
||||
total_size=total_size,
|
||||
recent_activity=recent_activity,
|
||||
storage_by_type=storage_by_type,
|
||||
trash_count=trash_count,
|
||||
starred_count=starred_count,
|
||||
|
||||
Reference in New Issue
Block a user