Feb 02 2026: implement issue following preferences
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Notifications{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row mb-3 align-items-center">
|
||||
<div class="col">
|
||||
<h4 class="mb-0">
|
||||
<i class="bi bi-bell-fill text-primary me-2"></i>Notifications
|
||||
{% if unread_count > 0 %}
|
||||
<span class="badge bg-danger ms-1" style="font-size:.6rem;vertical-align:middle;">
|
||||
{{ unread_count }} unread
|
||||
</span>
|
||||
{% endif %}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col-auto d-flex gap-2">
|
||||
<a href="{{ url_for('notifications.preferences') }}" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-gear"></i> Preferences
|
||||
</a>
|
||||
{% if unread_count > 0 %}
|
||||
<form method="post" action="{{ url_for('notifications.mark_all_read') }}" class="mb-0">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="btn btn-outline-primary btn-sm">
|
||||
<i class="bi bi-check2-all"></i> Mark all read
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ── Filter tabs ── #}
|
||||
<ul class="nav nav-tabs mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if filter_read == 'all' %}active{% endif %}"
|
||||
href="{{ url_for('notifications.index', filter='all') }}">All</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if filter_read == 'unread' %}active{% endif %}"
|
||||
href="{{ url_for('notifications.index', filter='unread') }}">Unread</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if filter_read == 'read' %}active{% endif %}"
|
||||
href="{{ url_for('notifications.index', filter='read') }}">Read</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{# ── Notification list ── #}
|
||||
{% if notifications.items %}
|
||||
<div class="card shadow-sm">
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for n in notifications.items %}
|
||||
<li class="list-group-item px-3 py-3
|
||||
{% if not n.is_read %}list-group-item-light border-start border-primary border-3{% endif %}">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="flex-grow-1">
|
||||
<div class="d-flex align-items-center gap-2 mb-1">
|
||||
{% if not n.is_read %}
|
||||
<span class="badge bg-primary" style="font-size:.65rem;">New</span>
|
||||
{% endif %}
|
||||
<span class="fw-semibold" style="font-size:.9rem;">{{ n.title }}</span>
|
||||
</div>
|
||||
<p class="mb-1 text-secondary" style="font-size:.85rem;">{{ n.body }}</p>
|
||||
<small class="text-muted">
|
||||
<i class="bi bi-clock me-1"></i>{{ n.created_at.strftime('%b %d, %Y %I:%M %p') }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="d-flex gap-2 ms-3 flex-shrink-0">
|
||||
{% if n.link %}
|
||||
<a href="{{ n.link }}" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-arrow-right"></i> View
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if not n.is_read %}
|
||||
<form method="post"
|
||||
action="{{ url_for('notifications.mark_read', notif_id=n.id) }}"
|
||||
class="mb-0">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary"
|
||||
title="Mark as read">
|
||||
<i class="bi bi-check2"></i>
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{# ── Pagination ── #}
|
||||
{% if notifications.pages > 1 %}
|
||||
<nav class="mt-3">
|
||||
<ul class="pagination pagination-sm justify-content-center">
|
||||
<li class="page-item {% if not notifications.has_prev %}disabled{% endif %}">
|
||||
<a class="page-link"
|
||||
href="{{ url_for('notifications.index', page=notifications.prev_num, filter=filter_read) }}">
|
||||
« Prev
|
||||
</a>
|
||||
</li>
|
||||
{% for p in notifications.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
|
||||
{% if p %}
|
||||
<li class="page-item {% if p == notifications.page %}active{% endif %}">
|
||||
<a class="page-link"
|
||||
href="{{ url_for('notifications.index', page=p, filter=filter_read) }}">{{ p }}</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<li class="page-item {% if not notifications.has_next %}disabled{% endif %}">
|
||||
<a class="page-link"
|
||||
href="{{ url_for('notifications.index', page=notifications.next_num, filter=filter_read) }}">
|
||||
Next »
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<div class="text-center py-5 text-muted">
|
||||
<i class="bi bi-bell-slash fs-1 d-block mb-3"></i>
|
||||
<p class="mb-0">No notifications found.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,201 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Notification Preferences{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row mb-3 align-items-center">
|
||||
<div class="col">
|
||||
<h4 class="mb-0">
|
||||
<i class="bi bi-gear-fill text-secondary me-2"></i>Notification Preferences
|
||||
</h4>
|
||||
<p class="text-muted mb-0 mt-1" style="font-size:.85rem;">
|
||||
Control how and when you receive notifications for each event type.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<a href="{{ url_for('notifications.index') }}" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-bell"></i> View Notifications
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-light">
|
||||
<div class="row fw-semibold text-muted" style="font-size:.8rem;">
|
||||
<div class="col-md-4">Event</div>
|
||||
<div class="col-md-2 text-center">Email Alerts</div>
|
||||
<div class="col-md-2 text-center">Digest Mode</div>
|
||||
<div class="col-md-3 text-center">Digest Frequency</div>
|
||||
<div class="col-md-1"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for event_type, label in event_types.items() %}
|
||||
{% set pref = prefs_map.get(event_type) %}
|
||||
{% set email_on = pref.email_enabled if pref else True %}
|
||||
{% set digest_on = pref.digest_mode if pref else False %}
|
||||
{% set freq = pref.digest_frequency if pref else 'daily' %}
|
||||
|
||||
<li class="list-group-item px-3 py-3" id="row-{{ event_type }}">
|
||||
<div class="row align-items-center">
|
||||
|
||||
{# Event label #}
|
||||
<div class="col-md-4">
|
||||
<span class="fw-semibold" style="font-size:.9rem;">{{ label }}</span>
|
||||
</div>
|
||||
|
||||
{# Email toggle #}
|
||||
<div class="col-md-2 text-center">
|
||||
<div class="form-check form-switch d-inline-block">
|
||||
<input class="form-check-input email-toggle"
|
||||
type="checkbox"
|
||||
name="email_{{ event_type }}"
|
||||
id="email_{{ event_type }}"
|
||||
value="1"
|
||||
data-event="{{ event_type }}"
|
||||
{% if email_on %}checked{% endif %}>
|
||||
<label class="form-check-label visually-hidden"
|
||||
for="email_{{ event_type }}">Email</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Digest mode toggle #}
|
||||
<div class="col-md-2 text-center">
|
||||
<div class="form-check form-switch d-inline-block">
|
||||
<input class="form-check-input digest-toggle"
|
||||
type="checkbox"
|
||||
name="digest_{{ event_type }}"
|
||||
id="digest_{{ event_type }}"
|
||||
value="1"
|
||||
data-event="{{ event_type }}"
|
||||
{% if digest_on %}checked{% endif %}
|
||||
{% if not email_on %}disabled{% endif %}>
|
||||
<label class="form-check-label visually-hidden"
|
||||
for="digest_{{ event_type }}">Digest</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Digest frequency #}
|
||||
<div class="col-md-3 text-center">
|
||||
<select class="form-select form-select-sm freq-select"
|
||||
name="freq_{{ event_type }}"
|
||||
id="freq_{{ event_type }}"
|
||||
style="width:auto;margin:auto;"
|
||||
{% if not email_on or not digest_on %}disabled{% endif %}>
|
||||
<option value="hourly" {% if freq == 'hourly' %}selected{% endif %}>Hourly</option>
|
||||
<option value="daily" {% if freq == 'daily' %}selected{% endif %}>Daily</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{# Status label #}
|
||||
<div class="col-md-1 text-end">
|
||||
<span class="badge status-badge
|
||||
{% if not email_on %}bg-secondary
|
||||
{% elif digest_on %}bg-warning text-dark
|
||||
{% else %}bg-success{% endif %}"
|
||||
style="font-size:.65rem;"
|
||||
id="badge-{{ event_type }}">
|
||||
{% if not email_on %}Off
|
||||
{% elif digest_on %}Digest
|
||||
{% else %}Live{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check2-circle me-1"></i>Save Preferences
|
||||
</button>
|
||||
<a href="{{ url_for('notifications.index') }}" class="btn btn-outline-secondary">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="card mt-4 border-0 bg-light">
|
||||
<div class="card-body py-2 px-3">
|
||||
<p class="mb-1" style="font-size:.8rem;"><strong>Email Alerts:</strong>
|
||||
Send an immediate email every time this event occurs.</p>
|
||||
<p class="mb-1" style="font-size:.8rem;"><strong>Digest Mode:</strong>
|
||||
Hold notifications and deliver them in a single batched email on your chosen schedule.</p>
|
||||
<p class="mb-0" style="font-size:.8rem;"><strong>Off:</strong>
|
||||
In-app notifications still appear in the bell — only email is suppressed.</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
document.querySelectorAll('.email-toggle').forEach(function (emailChk) {
|
||||
emailChk.addEventListener('change', function () {
|
||||
var event = this.dataset.event;
|
||||
var digestChk = document.getElementById('digest_' + event);
|
||||
var freqSelect = document.getElementById('freq_' + event);
|
||||
var badge = document.getElementById('badge_' + event) ||
|
||||
document.getElementById('badge-' + event);
|
||||
|
||||
var emailOn = this.checked;
|
||||
var digestOn = digestChk.checked;
|
||||
|
||||
// Cascade: disabling email disables digest and frequency
|
||||
digestChk.disabled = !emailOn;
|
||||
freqSelect.disabled = !emailOn || !digestOn;
|
||||
|
||||
if (!emailOn) {
|
||||
digestChk.checked = false;
|
||||
digestOn = false;
|
||||
}
|
||||
|
||||
updateBadge(badge, emailOn, digestOn);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.digest-toggle').forEach(function (digestChk) {
|
||||
digestChk.addEventListener('change', function () {
|
||||
var event = this.dataset.event;
|
||||
var freqSelect = document.getElementById('freq_' + event);
|
||||
var badge = document.getElementById('badge_' + event) ||
|
||||
document.getElementById('badge-' + event);
|
||||
var emailChk = document.getElementById('email_' + event);
|
||||
|
||||
var emailOn = emailChk.checked;
|
||||
var digestOn = this.checked;
|
||||
|
||||
freqSelect.disabled = !emailOn || !digestOn;
|
||||
|
||||
updateBadge(badge, emailOn, digestOn);
|
||||
});
|
||||
});
|
||||
|
||||
function updateBadge(badge, emailOn, digestOn) {
|
||||
if (!badge) return;
|
||||
badge.className = badge.className
|
||||
.replace(/bg-\S+/g, '')
|
||||
.replace(/text-\S+/g, '')
|
||||
.trim();
|
||||
|
||||
if (!emailOn) {
|
||||
badge.classList.add('bg-secondary');
|
||||
badge.textContent = 'Off';
|
||||
} else if (digestOn) {
|
||||
badge.classList.add('bg-warning', 'text-dark');
|
||||
badge.textContent = 'Digest';
|
||||
} else {
|
||||
badge.classList.add('bg-success');
|
||||
badge.textContent = 'Live';
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user