storage cards on dash
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
from flask import render_template, Blueprint, redirect, url_for, request, flash, Response, jsonify, session
|
||||
from flask_login import current_user, login_required
|
||||
from models import User, db, Room, RoomFile, RoomMemberPermission, SiteSettings, Event
|
||||
from models import User, db, Room, RoomFile, RoomMemberPermission, SiteSettings, Event, Conversation, Message, MessageAttachment
|
||||
from routes.auth import require_password_change
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
@@ -49,7 +49,20 @@ def init_routes(main_bp):
|
||||
if current_user.is_admin:
|
||||
recent_events = Event.query.order_by(Event.timestamp.desc()).limit(7).all()
|
||||
else:
|
||||
recent_events = Event.query.filter_by(user_id=current_user.id).order_by(Event.timestamp.desc()).limit(7).all()
|
||||
# Get events where user is the actor OR events from conversations they are a member of
|
||||
recent_events = Event.query.filter(
|
||||
db.or_(
|
||||
Event.user_id == current_user.id, # User's own actions
|
||||
db.and_(
|
||||
Event.event_type.in_(['conversation_create', 'message_create']), # Conversation-related events
|
||||
Event.details['conversation_id'].astext.in_(
|
||||
db.session.query(Conversation.id)
|
||||
.join(Conversation.members)
|
||||
.filter(User.id == current_user.id)
|
||||
)
|
||||
)
|
||||
)
|
||||
).order_by(Event.timestamp.desc()).limit(7).all()
|
||||
|
||||
# Room count and size logic
|
||||
if current_user.is_admin:
|
||||
@@ -253,6 +266,21 @@ def init_routes(main_bp):
|
||||
RoomFile.deleted==True
|
||||
).group_by('extension').all()
|
||||
|
||||
# Get conversation statistics
|
||||
if current_user.is_admin:
|
||||
conversation_count = Conversation.query.count()
|
||||
message_count = Message.query.count()
|
||||
attachment_count = MessageAttachment.query.count()
|
||||
conversation_total_size = db.session.query(db.func.sum(MessageAttachment.size)).scalar() or 0
|
||||
recent_conversations = Conversation.query.order_by(Conversation.created_at.desc()).limit(5).all()
|
||||
else:
|
||||
# For regular users, only show their conversations
|
||||
conversation_count = Conversation.query.filter(Conversation.members.any(id=current_user.id)).count()
|
||||
message_count = Message.query.join(Conversation).filter(Conversation.members.any(id=current_user.id)).count()
|
||||
attachment_count = MessageAttachment.query.join(Message).join(Conversation).filter(Conversation.members.any(id=current_user.id)).count()
|
||||
conversation_total_size = db.session.query(db.func.sum(MessageAttachment.size)).join(Message).join(Conversation).filter(Conversation.members.any(id=current_user.id)).scalar() or 0
|
||||
recent_conversations = Conversation.query.filter(Conversation.members.any(id=current_user.id)).order_by(Conversation.created_at.desc()).limit(5).all()
|
||||
|
||||
return render_template('dashboard/dashboard.html',
|
||||
recent_contacts=recent_contacts,
|
||||
active_count=active_count,
|
||||
@@ -260,7 +288,7 @@ def init_routes(main_bp):
|
||||
room_count=room_count,
|
||||
file_count=file_count,
|
||||
folder_count=folder_count,
|
||||
total_size=total_size,
|
||||
total_size=total_size, # Room storage size
|
||||
storage_by_type=storage_by_type,
|
||||
trash_count=trash_count,
|
||||
starred_count=starred_count,
|
||||
@@ -269,7 +297,12 @@ def init_routes(main_bp):
|
||||
pending_deletion=pending_deletion,
|
||||
trash_by_type=trash_by_type,
|
||||
recent_events=recent_events,
|
||||
is_admin=current_user.is_admin)
|
||||
is_admin=current_user.is_admin,
|
||||
conversation_count=conversation_count,
|
||||
message_count=message_count,
|
||||
attachment_count=attachment_count,
|
||||
conversation_total_size=conversation_total_size, # Conversation storage size
|
||||
recent_conversations=recent_conversations)
|
||||
|
||||
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads', 'profile_pics')
|
||||
if not os.path.exists(UPLOAD_FOLDER):
|
||||
|
||||
69
templates/components/conversation_storage.html
Normal file
69
templates/components/conversation_storage.html
Normal file
@@ -0,0 +1,69 @@
|
||||
{% from 'common/macros.html' import format_size %}
|
||||
|
||||
{% macro conversation_storage(conversation_count, message_count, attachment_count, total_size, recent_conversations) %}
|
||||
<div class="masonry-card">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h5 class="card-title mb-0"><i class="fas fa-comments me-2"></i>Conversation Storage</h5>
|
||||
<a href="{{ url_for('conversations.conversations') }}" class="btn btn-primary btn-sm">Browse</a>
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-comments me-2 icon-primary"></i>
|
||||
<span class="text-muted">Conversations:</span>
|
||||
</div>
|
||||
<div class="fw-bold text-primary">{{ conversation_count }}</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-comment me-2 icon-primary"></i>
|
||||
<span class="text-muted">Messages:</span>
|
||||
</div>
|
||||
<div class="fw-bold text-primary">{{ message_count }}</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-paperclip me-2 icon-primary"></i>
|
||||
<span class="text-muted">Attachments:</span>
|
||||
</div>
|
||||
<div class="fw-bold text-primary">{{ attachment_count }}</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-hdd me-2 icon-primary"></i>
|
||||
<span class="text-muted">Total Size:</span>
|
||||
</div>
|
||||
<div class="fw-bold text-primary">{{ format_size(total_size) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if recent_conversations %}
|
||||
<hr class="my-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h6 class="mb-0 text-muted">Recent Activity</h6>
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
{% for conversation in recent_conversations %}
|
||||
<a href="{{ url_for('conversations.conversation', conversation_id=conversation.id) }}" class="list-group-item list-group-item-action px-0">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<div class="fw-bold text-primary">{{ conversation.name }}</div>
|
||||
<small class="text-muted">
|
||||
{{ conversation.messages|length }} messages
|
||||
{% if conversation.messages|length > 0 %}
|
||||
• Last message {{ conversation.messages[-1].created_at.strftime('%Y-%m-%d %H:%M') }}
|
||||
{% endif %}
|
||||
</small>
|
||||
</div>
|
||||
<i class="fas fa-chevron-right text-muted"></i>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h5 class="card-title mb-0"><i class="fas fa-chart-pie me-2"></i>Storage Usage</h5>
|
||||
<h5 class="card-title mb-0"><i class="fas fa-chart-pie me-2"></i>Room Storage</h5>
|
||||
<a href="{{ url_for('rooms.rooms') }}" class="btn btn-primary btn-sm">View Details</a>
|
||||
</div>
|
||||
{% if storage_by_type %}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h5 class="card-title mb-0"><i class="fas fa-trash me-2"></i>Trash Storage Overview</h5>
|
||||
<h5 class="card-title mb-0"><i class="fas fa-trash me-2"></i>Trash Storage</h5>
|
||||
<a href="{{ url_for('main.trash') }}" class="btn btn-primary btn-sm">View All</a>
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
{% from 'components/trash.html' import trash %}
|
||||
{% from 'components/trash_type.html' import trash_type %}
|
||||
{% from 'components/recent_activity.html' import recent_activity %}
|
||||
{% from 'components/conversation_storage.html' import conversation_storage %}
|
||||
|
||||
<style>
|
||||
.masonry {
|
||||
@@ -47,6 +48,7 @@
|
||||
{{ storage_overview(room_count, file_count, folder_count, total_size) }}
|
||||
{{ storage_usage(storage_by_type) }}
|
||||
{{ recent_activity(recent_events, is_admin) }}
|
||||
{{ conversation_storage(conversation_count, message_count, attachment_count, conversation_total_size, recent_conversations) }}
|
||||
|
||||
{% if current_user.is_admin %}
|
||||
{{ contacts(recent_contacts) }}
|
||||
|
||||
BIN
uploads/Screenshot_2025-05-27_103137.png
Normal file
BIN
uploads/Screenshot_2025-05-27_103137.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 131 KiB |
BIN
uploads/test.png
Normal file
BIN
uploads/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user