notifications on dashboard

This commit is contained in:
2025-06-04 11:01:06 +02:00
parent 7f97d90f04
commit e948a9e55f
5 changed files with 83 additions and 15 deletions

View File

@@ -57,6 +57,9 @@ def init_routes(main_bp):
active_count = User.query.filter_by(is_active=True).count()
inactive_count = User.query.filter_by(is_active=False).count()
# Get recent notifications
recent_notifications = Notif.query.filter_by(user_id=current_user.id).order_by(Notif.timestamp.desc()).limit(5).all()
# Get recent events (last 7)
if current_user.is_admin:
recent_events = Event.query.order_by(Event.timestamp.desc()).limit(7).all()
@@ -314,7 +317,8 @@ def init_routes(main_bp):
message_count=message_count,
attachment_count=attachment_count,
conversation_total_size=conversation_total_size, # Conversation storage size
recent_conversations=recent_conversations)
recent_conversations=recent_conversations,
recent_notifications=recent_notifications)
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads', 'profile_pics')
if not os.path.exists(UPLOAD_FOLDER):

View File

@@ -0,0 +1,48 @@
{% macro notification_overview(unread_count, recent_notifications) %}
<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-bell me-2"></i>Notifications</h5>
<a href="{{ url_for('main.notifications') }}" class="btn btn-primary btn-sm">View All</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-envelope me-2 icon-primary"></i>
<span class="text-muted">Unread:</span>
</div>
<div class="fw-bold text-primary">{{ unread_count }}</div>
</div>
</div>
{% if recent_notifications %}
<hr class="my-3">
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="mb-0 text-muted">Recent Notifications</h6>
</div>
<div class="list-group list-group-flush">
{% for notification in recent_notifications %}
<div 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 {% if not notification.read %}text-primary{% endif %}">{{ notification.title }}</div>
<small class="text-muted">
{{ notification.message }}
• {{ notification.created_at.strftime('%Y-%m-%d %H:%M') }}
</small>
</div>
{% if not notification.read %}
<span class="badge bg-primary rounded-pill">New</span>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="text-muted small text-center mt-3">No recent notifications</div>
{% endif %}
</div>
</div>
</div>
{% endmacro %}

View File

@@ -25,6 +25,7 @@
{% from 'components/trash_type.html' import trash_type %}
{% from 'components/recent_activity.html' import recent_activity %}
{% from 'components/conversation_storage.html' import conversation_storage %}
{% from 'components/notification_overview.html' import notification_overview %}
<style>
.masonry {
@@ -42,22 +43,37 @@
width: 100%;
margin-bottom: 1.5rem;
}
.section-title {
color: var(--primary-color);
margin-bottom: 1.5rem;
font-size: 1.5rem;
font-weight: 600;
}
</style>
<div class="masonry">
{{ 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) }}
<!-- {{ contact_status(active_count, inactive_count) }} -->
{% endif %}
{{ starred_files(starred_count, file_count) }}
{{ trash(trash_count, pending_deletion, oldest_trash_date, trash_size) }}
{{ trash_type(trash_by_type) }}
<!-- Storage Section -->
<div class="mb-4">
<h2 class="section-title">Storage Overview</h2>
<div class="masonry">
{{ storage_overview(room_count, file_count, folder_count, total_size) }}
{{ storage_usage(storage_by_type) }}
{{ conversation_storage(conversation_count, message_count, attachment_count, conversation_total_size, recent_conversations) }}
{{ trash(trash_count, pending_deletion, oldest_trash_date, trash_size) }}
{{ trash_type(trash_by_type) }}
</div>
</div>
<!-- Other Components Section -->
<div>
<h2 class="section-title">Activity & Statistics</h2>
<div class="masonry">
{{ recent_activity(recent_events, is_admin) }}
{{ starred_files(starred_count, file_count) }}
{{ notification_overview(unread_notifications, recent_notifications) }}
{% if current_user.is_admin %}
{{ contacts(recent_contacts) }}
{% endif %}
</div>
</div>
{% endblock %}