source: Klonkt/src/views/pages/admin.ejs@ 053bf51

main
Last change on this file since 053bf51 was 053bf51, checked in by Robin <roboburr@…>, 7 weeks ago

Feature: web push slice 2, enable/disable UI + service worker delivery

The visible half of docs/webpush-design.md: an owner can now turn on
notifications per device, pick what to be notified about, and send a test.

  • Routes: GET /push/vapid (the public key, public by design), POST /push/subscribe|/unsubscribe|/alerts|/test (logged-in; a subscription row is personal, only its creator may touch it). Mounted before the /:slug catch-all, like /paid.
  • Service worker: push handler (shows the encrypted JSON payload {type,title,body,url}; same-type bursts collapse via tag) and notificationclick (focus an open tab and navigate, else open a window). Cache name bumped to v19.
  • Beheer -> Notificaties (/admin/push): per-device toggle, alert-type checkboxes (saved prefs shown for the current device), test button, linked-devices list with remove, iOS install hint (push needs an installed PWA there), plain <script> so injectCspNonce provides the real nonce.
  • Not premium-gated: notifications are infrastructure, not an extra.

Verified live on a dev server: /push/vapid serves the generated key,
storage/.vapid is 0600, sw.js carries both handlers, and an unauthenticated
subscribe is refused.

Changed files:
src/server.js

  • mount /push + /admin/push; sw.js push/notificationclick handlers, v19

src/views/pages/admin.ejs

  • "Notificaties" button (always visible, not premium)

New file:
src/routes/push.js

  • vapid/subscribe/unsubscribe/alerts/test

src/routes/admin-push.js

  • the Beheer page (requireSiteManager)

src/views/pages/admin-push.ejs

  • device toggle, prefs, test, device list, iOS hint

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 11.0 KB
Line 
1<div class="container admin-page">
2 <h1><%= t('admin.title') %></h1>
3 <%
4 var _premOn = (typeof premiumEnabled !== 'undefined' && premiumEnabled);
5 var _premActive = _premOn && (typeof isPremium !== 'undefined' && isPremium);
6 var _premCls = _premActive ? 'on' : (_premOn ? 'off' : 'free');
7 var _premLbl = _premActive ? ('★ ' + t('adash.prem_active'))
8 : (_premOn ? ('⚠ ' + t('adash.prem_unlinked'))
9 : t('adash.prem_layeroff'));
10 %>
11 <a class="prem-badge <%= _premCls %>" href="/admin/settings" title="<%= t('admin.b_settings') %>"><%= _premLbl %></a>
12 <style>
13 .prem-badge{display:inline-flex;align-items:center;gap:.35rem;font-size:.78rem;font-weight:700;letter-spacing:.02em;padding:.3rem .85rem;border-radius:999px;text-decoration:none;border:1px solid transparent;margin:.1rem 0 .3rem}
14 .prem-badge.on{background:rgba(232,176,75,.16);color:var(--accent);border-color:rgba(232,176,75,.45)}
15 .prem-badge.off{background:rgba(239,68,68,.12);color:#ef9a9a;border-color:rgba(239,68,68,.35)}
16 .prem-badge.free{background:var(--paper-2);color:var(--ink-muted);border-color:var(--rule)}
17 .prem-badge:hover{filter:brightness(1.08)}
18 </style>
19 <% if (tenancy === 'hub') { %>
20 <p class="admin-tagline"><%= t('admin.tagline_hub') %></p>
21 <% } else { %>
22 <p class="admin-tagline"><%= t('admin.tagline_solo') %></p>
23 <% } %>
24
25 <nav class="admin-quick-links" aria-label="<%= t('nav.admin') %>">
26 <% if (tenancy === 'hub') { %>
27 <a href="/admin/sites" class="btn"><%= t('admin.b_sites') %></a>
28 <a href="/admin/users" class="btn"><%= t('admin.b_users') %></a>
29 <a href="/admin/media" class="btn"><%= t('admin.b_media') %></a>
30 <% if (typeof audioEnabled === 'undefined' || audioEnabled) { %>
31 <a href="/admin/playlists" class="btn"><%= t('admin.b_playlists') %></a>
32 <% } %>
33 <% if (primarySite) { %><a href="/admin/seo" class="btn"><%= t('admin.b_seo') %></a><% } %>
34 <a href="/admin/settings" class="btn"><%= t('admin.b_settings') %></a>
35 <% } else { %>
36 <a href="/posts/new" class="btn"><%= t('admin.b_newpost') %></a>
37 <a href="/admin/media" class="btn"><%= t('admin.b_media') %></a>
38 <% if (primarySite) { %>
39 <a href="/admin/sites/<%= primarySite.slug %>/edit" class="btn"><%= t('admin.b_look') %></a>
40 <% } else { %>
41 <a href="/admin/sites/new" class="btn"><%= t('admin.b_makesite') %></a>
42 <% } %>
43 <% if (primarySite) { %><a href="/admin/seo" class="btn"><%= t('admin.b_seo') %></a><% } %>
44 <a href="/admin/settings" class="btn"><%= t('admin.b_settings') %></a>
45 <% } %>
46 <% if (typeof premiumUnlocked === 'undefined' || premiumUnlocked) { %>
47 <a href="/admin/stats" class="btn"><%= t('admin.b_stats') %></a>
48 <a href="/admin/paid" class="btn">Betaalde posts</a>
49 <a href="/admin/newsletter" class="btn"><%= t('admin.b_newsletter') %></a>
50 <% if (tenancy !== 'hub' && primarySite) { %><a href="/pers" class="btn" target="_blank"><%= t('admin.b_perskit') %></a><% } %>
51 <% if (tenancy !== 'hub' && primarySite) { %><a href="/downloads" class="btn" target="_blank"><%= t('admin.b_downloads') %></a><% } %>
52 <% if (tenancy !== 'hub' && primarySite) { %><a href="/links" class="btn" target="_blank"><%= t('admin.b_linkbio') %></a><% } %>
53 <a href="/admin/shows" class="btn"><%= t('admin.b_agenda') %></a>
54 <% } %>
55 <%# Fediverse pages (News / Notifications / My replies / Blocking) are reached via the
56 "Fediverse" nav button + the bell + the tabbed section — not duplicated here. %>
57 <a href="/admin/push" class="btn">Notificaties</a>
58 <a href="/admin/updates" class="btn"><%= t('admin.b_updates') %></a>
59 <a href="/admin/handleiding" class="btn"><%= t('admin.b_help') %></a>
60 </nav>
61
62 <div class="admin-stats">
63 <% if (tenancy === 'hub') { %>
64 <div class="stat-card"><div class="stat-num"><%= stats.users %></div><div class="stat-label"><%= t('admin.st_users') %></div></div>
65 <div class="stat-card"><div class="stat-num"><%= stats.sites %></div><div class="stat-label"><%= t('admin.st_sites') %></div></div>
66 <% } %>
67 <div class="stat-card"><div class="stat-num"><%= stats.posts %></div><div class="stat-label"><%= t('admin.st_posts') %></div></div>
68 <div class="stat-card"><div class="stat-num"><%= stats.published %></div><div class="stat-label"><%= t('admin.st_published') %></div></div>
69 </div>
70
71 <% if (typeof posts !== 'undefined' && posts && posts.length) { %>
72 <% var _drafts = posts.filter(function(p){ return p.isDraft; }).length; %>
73 <h2><%= t('admin.sec_posts') %><% if (_drafts) { %> <span class="pl-draftcount"><%= _drafts %> <%= t('admin.draft').toLowerCase() %><%= _drafts === 1 ? '' : 's' %></span><% } %></h2>
74 <ul class="post-admin-list">
75 <% posts.forEach(function(p) { %>
76 <li class="pal-row<%= p.isDraft ? ' is-draft' : '' %>">
77 <a class="pal-title" href="<%= p.editUrl %>">
78 <% if (p.isDraft) { %><span class="pal-badge"><%= t('admin.draft') %></span><% } %>
79 <span class="pal-name"><%= p.title || '(zonder titel)' %></span>
80 </a>
81 <span class="pal-actions">
82 <a class="pal-link" href="<%= p.editUrl %>"><%= t('admin.edit') %></a>
83 <% if (!p.isDraft) { %><a class="pal-link" href="<%= p.viewUrl %>"><%= t('admin.view') %></a><% } %>
84 </span>
85 </li>
86 <% }); %>
87 </ul>
88 <% } %>
89
90 <% if (sites && sites.length) { %>
91 <h2><%= t('admin.sec_sites') %></h2>
92 <table class="admin-table">
93 <thead>
94 <tr><th><%= t('admin.th_slug') %></th><th><%= t('admin.th_title') %></th><th><%= t('admin.th_owner') %></th><th><%= t('admin.th_created') %></th></tr>
95 </thead>
96 <tbody>
97 <% sites.forEach(function(s) { %>
98 <tr>
99 <td><code><%= s.slug %></code></td>
100 <td><%= s.title %></td>
101 <td><%= s.owner_username || '—' %></td>
102 <td><%= formatDate(s.created_at) %></td>
103 </tr>
104 <% }); %>
105 </tbody>
106 </table>
107 <% } %>
108
109 <% if (users && users.length) { %>
110 <h2><%= t('admin.sec_users') %></h2>
111 <table class="admin-table">
112 <thead>
113 <tr><th><%= t('admin.th_username') %></th><th><%= t('admin.th_email') %></th><th><%= t('admin.th_role') %></th><th><%= t('admin.th_joined') %></th></tr>
114 </thead>
115 <tbody>
116 <% users.forEach(function(u) { %>
117 <tr>
118 <td><%= u.username %></td>
119 <td><%= u.email %></td>
120 <td><span class="role-pill role-<%= u.role %>"><%= u.role %></span></td>
121 <td><%= formatDate(u.created_at) %></td>
122 </tr>
123 <% }); %>
124 </tbody>
125 </table>
126 <% } %>
127
128</div>
129
130<style>
131.admin-page { max-width: 1000px; margin: 3rem auto; padding: 0 1rem; }
132.admin-page h1 { font-family: var(--font-display, serif); font-size: 2rem; margin: 0 0 0.25rem; }
133.admin-page h2 { font-family: var(--font-display, serif); font-size: 1.4rem; margin: 2rem 0 0.75rem; }
134.admin-tagline { color: var(--ink-muted); margin: 0 0 2rem; }
135.admin-tagline em { font-style: normal; opacity: 0.7; }
136
137/* Posts/concepten-lijst */
138.pl-draftcount { font-family: var(--font-ui, system-ui); font-size: 0.8rem; font-weight: 700; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.1rem 0.55rem; border-radius: 99px; vertical-align: middle; }
139.post-admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
140.pal-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.9rem; border: 1px solid var(--rule); border-radius: 10px; background: var(--paper-2); transition: border-color 120ms; }
141.pal-row:hover { border-color: var(--accent); }
142.pal-row.is-draft { border-left: 3px solid var(--accent); }
143.pal-title { display: inline-flex; align-items: center; gap: 0.6rem; min-width: 0; color: var(--ink); text-decoration: none; font-weight: 600; }
144.pal-title:hover { color: var(--accent); }
145.pal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
146.pal-badge { flex-shrink: 0; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.1rem 0.5rem; border-radius: 99px; }
147.pal-actions { display: flex; gap: 0.75rem; flex-shrink: 0; }
148.pal-link { color: var(--ink-muted); font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
149.pal-link:hover { color: var(--accent); text-decoration: underline; }
150
151/* Quick-links grid — mobile-first.
152 auto-fit + minmax means: as many equal columns as fit, each at least 140px.
153 Mobile (~360-440px): 2 per row.
154 Tablet (~480-700px): 3 per row.
155 Desktop (≥ ~720px): all 5 in a single row. */
156.admin-quick-links {
157 display: grid;
158 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
159 gap: 0.5rem;
160 margin: 0 0 1.5rem;
161 padding: 0;
162}
163.admin-quick-links .btn {
164 justify-content: center;
165 padding: 0.7rem 0.9rem;
166 font-weight: 600;
167 text-align: center;
168}
169.admin-quick-links .btn:hover {
170 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
171 border-color: var(--accent);
172}
173
174.admin-stats {
175 display: grid;
176 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
177 gap: 0.75rem;
178 margin-bottom: 1rem;
179}
180.stat-card {
181 background: var(--paper-2);
182 border: 1px solid var(--rule);
183 border-radius: 8px;
184 padding: 1rem 1.25rem;
185 text-align: center;
186}
187.stat-num {
188 font-size: 2rem;
189 font-weight: 700;
190 color: var(--accent);
191 line-height: 1;
192 font-family: var(--font-display, serif);
193}
194.stat-label {
195 color: var(--ink-muted);
196 font-size: 0.85rem;
197 text-transform: uppercase;
198 letter-spacing: 0.05em;
199 margin-top: 0.25rem;
200}
201
202.admin-table {
203 width: 100%;
204 border-collapse: collapse;
205 background: var(--paper-2);
206 border: 1px solid var(--rule);
207 border-radius: 8px;
208 overflow: hidden;
209}
210.admin-table th, .admin-table td {
211 padding: 0.6rem 0.9rem;
212 text-align: left;
213 border-bottom: 1px solid var(--rule);
214}
215.admin-table th {
216 background: var(--paper);
217 font-weight: 600;
218 font-size: 0.85rem;
219 text-transform: uppercase;
220 letter-spacing: 0.05em;
221 color: var(--ink-muted);
222}
223.admin-table tr:last-child td { border-bottom: 0; }
224.admin-table code { background: var(--paper); padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85rem; }
225
226.role-pill {
227 display: inline-block;
228 padding: 0.1rem 0.5rem;
229 border-radius: 10px;
230 font-size: 0.75rem;
231 text-transform: uppercase;
232 letter-spacing: 0.05em;
233 background: var(--paper);
234 color: var(--ink-muted);
235}
236.role-pill.role-god { background: var(--accent); color: white; }
237.role-pill.role-admin { background: var(--paper); color: var(--accent); border: 1px solid var(--accent); }
238
239.admin-todo {
240 margin: 2rem 0 0;
241 padding: 0.75rem 1rem;
242 background: var(--paper-2);
243 border-left: 3px solid var(--accent);
244 border-radius: 4px;
245 font-size: 0.9rem;
246 color: var(--ink-muted);
247}
248
249@media (max-width: 600px) {
250 .admin-table { font-size: 0.85rem; }
251 .admin-table th, .admin-table td { padding: 0.45rem 0.6rem; }
252}
253</style>
Note: See TracBrowser for help on using the repository browser.