316 lines
14 KiB
HTML
316 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
|
<!-- iOS / iPadOS web app meta tags -->
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
<meta name="mobile-web-app-capable" content="yes">
|
|
<title>{% block title %}Janitorial QC System{% endblock %}</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/ipad_responsive.css') }}">
|
|
{% block extra_css %}{% endblock %}
|
|
<style>
|
|
/* ── Notification bell styles ── */
|
|
.notif-bell-wrapper { position: relative; }
|
|
.notif-badge {
|
|
position: absolute;
|
|
top: 2px; right: 2px;
|
|
font-size: 0.6rem;
|
|
min-width: 16px; height: 16px; line-height: 16px;
|
|
padding: 0 4px; border-radius: 8px;
|
|
pointer-events: none;
|
|
}
|
|
.notif-dropdown {
|
|
width: 380px;
|
|
max-height: 520px;
|
|
overflow-y: auto;
|
|
padding: 0;
|
|
}
|
|
.notif-item {
|
|
border-left: 3px solid transparent;
|
|
transition: background 0.15s;
|
|
cursor: pointer;
|
|
}
|
|
.notif-item.unread {
|
|
border-left-color: #0d6efd;
|
|
background-color: #f0f6ff;
|
|
}
|
|
.notif-item:hover { background-color: #e8f0fe; }
|
|
.notif-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 2px; }
|
|
.notif-body { font-size: 0.78rem; color: #555; white-space: normal; }
|
|
.notif-time { font-size: 0.7rem; color: #999; }
|
|
.notif-empty { padding: 24px; text-align: center; color: #aaa; font-size: 0.85rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
{% if current_user.is_authenticated %}
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="{{ url_for('dashboard.index') }}">
|
|
<i class="bi bi-clipboard-check"></i> Janitorial QC
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav me-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('dashboard.index') }}">Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('facilities.list_facilities') }}">Facilities</a>
|
|
</li>
|
|
{% if current_user.role in ['admin', 'supervisor', 'project_manager'] %}
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('projects.index') }}">Projects</a>
|
|
</li>
|
|
{% endif %}
|
|
{% if current_user.role != 'customer' %}
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('templates.index') }}">Templates</a>
|
|
</li>
|
|
{% endif %}
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('inspections.index') }}">Inspections</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('reports.index') }}">Reports</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('issues.index') }}">Issues</a>
|
|
</li>
|
|
{% if current_user.role == 'admin' %}
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('auth.list_users') }}">Users</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="{{ url_for('audit.index') }}">Audit Trail</a>
|
|
</li>
|
|
{% endif %}
|
|
</ul>
|
|
<ul class="navbar-nav align-items-center">
|
|
|
|
<!-- ── Notification Bell ── -->
|
|
<li class="nav-item dropdown me-2">
|
|
<a class="nav-link position-relative notif-bell-wrapper"
|
|
href="#"
|
|
id="notifDropdown"
|
|
role="button"
|
|
data-bs-toggle="dropdown"
|
|
aria-expanded="false"
|
|
title="Notifications">
|
|
<i class="bi bi-bell fs-5"></i>
|
|
{% if unread_notification_count > 0 %}
|
|
<span class="badge bg-danger notif-badge" id="notif-count-badge">
|
|
{{ unread_notification_count if unread_notification_count <= 99 else '99+' }}
|
|
</span>
|
|
{% else %}
|
|
<span class="badge bg-danger notif-badge d-none" id="notif-count-badge"></span>
|
|
{% endif %}
|
|
</a>
|
|
<div class="dropdown-menu dropdown-menu-end notif-dropdown shadow"
|
|
id="notif-dropdown-menu">
|
|
<!-- Header -->
|
|
<div class="d-flex justify-content-between align-items-center
|
|
px-3 py-2 border-bottom">
|
|
<span class="fw-semibold" style="font-size:.9rem;">Notifications</span>
|
|
<button class="btn btn-link btn-sm p-0 text-muted text-decoration-none"
|
|
id="mark-all-read-btn" style="font-size:.75rem;">
|
|
Mark all as read
|
|
</button>
|
|
</div>
|
|
<!-- Items -->
|
|
<div id="notif-list">
|
|
<div class="notif-empty">Loading…</div>
|
|
</div>
|
|
<!-- Footer -->
|
|
<div class="border-top d-flex justify-content-between px-3 py-2"
|
|
style="font-size:.8rem;">
|
|
<a href="{{ url_for('notifications.index') }}"
|
|
class="text-decoration-none">
|
|
<i class="bi bi-list-ul me-1"></i>View all
|
|
</a>
|
|
<a href="{{ url_for('notifications.preferences') }}"
|
|
class="text-decoration-none text-muted">
|
|
<i class="bi bi-gear me-1"></i>Preferences
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
<!-- ── End Notification Bell ── -->
|
|
|
|
<!-- User menu -->
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
|
|
role="button" data-bs-toggle="dropdown">
|
|
<i class="bi bi-person-circle"></i> {{ current_user.username }}
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end">
|
|
<li>
|
|
<a class="dropdown-item"
|
|
href="{{ url_for('auth.profile') }}">
|
|
<i class="bi bi-person-circle me-1"></i>My Profile
|
|
</a>
|
|
</li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li>
|
|
<a class="dropdown-item"
|
|
href="{{ url_for('notifications.preferences') }}">
|
|
<i class="bi bi-bell-slash me-1"></i>Notification Preferences
|
|
</a>
|
|
</li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li>
|
|
<a class="dropdown-item" href="{{ url_for('auth.logout') }}">
|
|
<i class="bi bi-box-arrow-right me-1"></i>Logout
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
{% endif %}
|
|
|
|
<div class="container-fluid mt-4">
|
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
|
{% if messages %}
|
|
{% for category, message in messages %}
|
|
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
|
|
{{ message }}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endwith %}
|
|
|
|
{% block content %}{% endblock %}
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
{% block extra_js %}{% endblock %}
|
|
|
|
{% if current_user.is_authenticated %}
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
|
|
const FEED_URL = '{{ url_for("notifications.feed") }}';
|
|
const MARK_READ_BASE = '/notifications/';
|
|
const MARK_ALL_URL = '{{ url_for("notifications.mark_all_read") }}';
|
|
const CSRF_TOKEN = '{{ csrf_token() }}';
|
|
const POLL_INTERVAL = 60000; // 60 seconds
|
|
|
|
const badge = document.getElementById('notif-count-badge');
|
|
const listEl = document.getElementById('notif-list');
|
|
const markAllBtn = document.getElementById('mark-all-read-btn');
|
|
|
|
function updateBadge(count) {
|
|
if (count > 0) {
|
|
badge.textContent = count > 99 ? '99+' : count;
|
|
badge.classList.remove('d-none');
|
|
} else {
|
|
badge.textContent = '';
|
|
badge.classList.add('d-none');
|
|
}
|
|
}
|
|
|
|
function renderNotifications(notifications) {
|
|
if (!notifications.length) {
|
|
listEl.innerHTML = '<div class="notif-empty">'
|
|
+ '<i class="bi bi-check2-circle me-1"></i>You\'re all caught up!</div>';
|
|
return;
|
|
}
|
|
|
|
listEl.innerHTML = notifications.map(n => `
|
|
<div class="d-block text-decoration-none text-dark notif-item px-3 py-2 border-bottom
|
|
${n.is_read ? '' : 'unread'}"
|
|
data-notif-id="${n.id}"
|
|
data-link="${escapeAttr(n.link || '')}">
|
|
<div class="notif-title">${escapeHtml(n.title)}</div>
|
|
<div class="notif-body">${escapeHtml(n.body)}</div>
|
|
<div class="notif-time">${escapeHtml(n.created_at)}</div>
|
|
</div>
|
|
`).join('');
|
|
|
|
listEl.querySelectorAll('.notif-item').forEach(el => {
|
|
el.addEventListener('click', function () {
|
|
const id = this.dataset.notifId;
|
|
const link = this.dataset.link;
|
|
markRead(id, () => {
|
|
this.classList.remove('unread');
|
|
if (link) window.location.href = link;
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
if (!str) return '';
|
|
return str.replace(/&/g,'&').replace(/</g,'<')
|
|
.replace(/>/g,'>').replace(/"/g,'"');
|
|
}
|
|
function escapeAttr(str) { return escapeHtml(str); }
|
|
|
|
window.fetchNotifications = function fetchNotifications() {
|
|
fetch(FEED_URL, { credentials: 'same-origin' })
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
updateBadge(data.unread_count);
|
|
window._jqcNotifications = data.notifications;
|
|
const dropdownEl = document.getElementById('notifDropdown');
|
|
if (dropdownEl.getAttribute('aria-expanded') === 'true') {
|
|
renderNotifications(data.notifications);
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
function markRead(id, callback) {
|
|
fetch(`${MARK_READ_BASE}${id}/mark-read`, {
|
|
method: 'POST',
|
|
headers: { 'X-CSRFToken': CSRF_TOKEN, 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
})
|
|
.then(r => r.json())
|
|
.then(() => { if (callback) callback(); fetchNotifications(); })
|
|
.catch(() => { if (callback) callback(); });
|
|
}
|
|
|
|
document.getElementById('notifDropdown').addEventListener('show.bs.dropdown', function () {
|
|
if (window._jqcNotifications) {
|
|
renderNotifications(window._jqcNotifications);
|
|
} else {
|
|
fetchNotifications();
|
|
}
|
|
});
|
|
|
|
markAllBtn.addEventListener('click', function (e) {
|
|
e.stopPropagation();
|
|
fetch(MARK_ALL_URL, {
|
|
method: 'POST',
|
|
headers: { 'X-CSRFToken': CSRF_TOKEN },
|
|
credentials: 'same-origin',
|
|
})
|
|
.then(r => r.json())
|
|
.then(() => {
|
|
updateBadge(0);
|
|
listEl.querySelectorAll('.notif-item.unread').forEach(el => el.classList.remove('unread'));
|
|
if (window._jqcNotifications) {
|
|
window._jqcNotifications.forEach(n => n.is_read = true);
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
});
|
|
|
|
fetchNotifications();
|
|
setInterval(fetchNotifications, POLL_INTERVAL);
|
|
})();
|
|
</script>
|
|
{% endif %}
|
|
</body>
|
|
</html> |