source: Klonkt/src/views/pages/admin.ejs@ b807a85

main
Last change on this file since b807a85 was bdc3c1e, checked in by roboburr <roboburr@…>, 3 months ago

Always guarantee a primary site (solo/hub/circle) via ensurePrimarySite

An admin created via a script (or an empty sites table) left an instance
without a site → no settings, dashboard crashed. New boot-time helper
ensurePrimarySite() idempotently creates a default site when there is an
admin but no site. Dashboard shows "Create your site" as an extra fallback
if no site exists unexpectedly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

  • Property mode set to 100644
File size: 8.3 KB
Line 
1<div class="container admin-page">
2 <h1>Beheer</h1>
3 <% if (tenancy === 'hub') { %>
4 <p class="admin-tagline">Hub-modus — bedrijfssite met gebruikers, elk hun eigen Klonkt Hub.</p>
5 <% } else { %>
6 <p class="admin-tagline">Solo-modus — jouw site.</p>
7 <% } %>
8
9 <nav class="admin-quick-links" aria-label="Beheer-snelkoppelingen">
10 <% if (tenancy === 'hub') { %>
11 <a href="/admin/sites" class="btn">🌐 Sites</a>
12 <a href="/admin/users" class="btn">👥 Gebruikers</a>
13 <a href="/admin/audio" class="btn">🎵 Audio</a>
14 <a href="/admin/playlists" class="btn">📃 Playlists</a>
15 <a href="/admin/comments" class="btn">💬 Reacties</a>
16 <a href="/admin/settings" class="btn">⚙️ Instellingen</a>
17 <% } else { %>
18 <a href="/posts/new" class="btn">✍️ Nieuwe post</a>
19 <a href="/admin/audio" class="btn">🎵 Audio</a>
20 <a href="/admin/comments" class="btn">💬 Reacties</a>
21 <% if (primarySite) { %>
22 <a href="/admin/sites/<%= primarySite.slug %>/edit" class="btn">🎨 Uiterlijk</a>
23 <% } else { %>
24 <a href="/admin/sites/new" class="btn">🎨 Maak je site aan</a>
25 <% } %>
26 <% if (tenancy === 'circle') { %>
27 <a href="/admin/circle" class="btn">🔗 Cirkel</a>
28 <% } %>
29 <a href="/admin/settings" class="btn">⚙️ Instellingen</a>
30 <% } %>
31 <a href="/admin/updates" class="btn">🔄 Updates</a>
32 </nav>
33
34 <div class="admin-stats">
35 <% if (tenancy === 'hub') { %>
36 <div class="stat-card"><div class="stat-num"><%= stats.users %></div><div class="stat-label">Gebruikers</div></div>
37 <div class="stat-card"><div class="stat-num"><%= stats.sites %></div><div class="stat-label">Sites</div></div>
38 <% } %>
39 <div class="stat-card"><div class="stat-num"><%= stats.posts %></div><div class="stat-label">Posts</div></div>
40 <div class="stat-card"><div class="stat-num"><%= stats.published %></div><div class="stat-label">Gepubliceerd</div></div>
41 </div>
42
43 <% if (typeof posts !== 'undefined' && posts && posts.length) { %>
44 <% var _drafts = posts.filter(function(p){ return p.isDraft; }).length; %>
45 <h2>Posts<% if (_drafts) { %> <span class="pl-draftcount"><%= _drafts %> concept<%= _drafts === 1 ? '' : 'en' %></span><% } %></h2>
46 <ul class="post-admin-list">
47 <% posts.forEach(function(p) { %>
48 <li class="pal-row<%= p.isDraft ? ' is-draft' : '' %>">
49 <a class="pal-title" href="<%= p.editUrl %>">
50 <% if (p.isDraft) { %><span class="pal-badge">Concept</span><% } %>
51 <span class="pal-name"><%= p.title || '(zonder titel)' %></span>
52 </a>
53 <span class="pal-actions">
54 <a class="pal-link" href="<%= p.editUrl %>">Bewerken</a>
55 <% if (!p.isDraft) { %><a class="pal-link" href="<%= p.viewUrl %>">Bekijk</a><% } %>
56 </span>
57 </li>
58 <% }); %>
59 </ul>
60 <% } %>
61
62 <% if (sites && sites.length) { %>
63 <h2>Sites</h2>
64 <table class="admin-table">
65 <thead>
66 <tr><th>Slug</th><th>Title</th><th>Owner</th><th>Created</th></tr>
67 </thead>
68 <tbody>
69 <% sites.forEach(function(s) { %>
70 <tr>
71 <td><code><%= s.slug %></code></td>
72 <td><%= s.title %></td>
73 <td><%= s.owner_username || '—' %></td>
74 <td><%= formatDate(s.created_at) %></td>
75 </tr>
76 <% }); %>
77 </tbody>
78 </table>
79 <% } %>
80
81 <% if (users && users.length) { %>
82 <h2>Users</h2>
83 <table class="admin-table">
84 <thead>
85 <tr><th>Username</th><th>Email</th><th>Role</th><th>Joined</th></tr>
86 </thead>
87 <tbody>
88 <% users.forEach(function(u) { %>
89 <tr>
90 <td><%= u.username %></td>
91 <td><%= u.email %></td>
92 <td><span class="role-pill role-<%= u.role %>"><%= u.role %></span></td>
93 <td><%= formatDate(u.created_at) %></td>
94 </tr>
95 <% }); %>
96 </tbody>
97 </table>
98 <% } %>
99
100</div>
101
102<style>
103.admin-page { max-width: 1000px; margin: 3rem auto; padding: 0 1rem; }
104.admin-page h1 { font-family: var(--font-display, serif); font-size: 2rem; margin: 0 0 0.25rem; }
105.admin-page h2 { font-family: var(--font-display, serif); font-size: 1.4rem; margin: 2rem 0 0.75rem; }
106.admin-tagline { color: var(--ink-muted); margin: 0 0 2rem; }
107.admin-tagline em { font-style: normal; opacity: 0.7; }
108
109/* Posts/concepten-lijst */
110.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; }
111.post-admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
112.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; }
113.pal-row:hover { border-color: var(--accent); }
114.pal-row.is-draft { border-left: 3px solid var(--accent); }
115.pal-title { display: inline-flex; align-items: center; gap: 0.6rem; min-width: 0; color: var(--ink); text-decoration: none; font-weight: 600; }
116.pal-title:hover { color: var(--accent); }
117.pal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
118.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; }
119.pal-actions { display: flex; gap: 0.75rem; flex-shrink: 0; }
120.pal-link { color: var(--ink-muted); font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
121.pal-link:hover { color: var(--accent); text-decoration: underline; }
122
123/* Quick-links grid — mobile-first.
124 auto-fit + minmax means: as many equal columns as fit, each at least 140px.
125 Mobile (~360-440px): 2 per row.
126 Tablet (~480-700px): 3 per row.
127 Desktop (≥ ~720px): all 5 in a single row. */
128.admin-quick-links {
129 display: grid;
130 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
131 gap: 0.5rem;
132 margin: 0 0 1.5rem;
133 padding: 0;
134}
135.admin-quick-links .btn {
136 justify-content: center;
137 padding: 0.7rem 0.9rem;
138 font-weight: 600;
139 text-align: center;
140}
141.admin-quick-links .btn:hover {
142 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
143 border-color: var(--accent);
144}
145
146.admin-stats {
147 display: grid;
148 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
149 gap: 0.75rem;
150 margin-bottom: 1rem;
151}
152.stat-card {
153 background: var(--paper-2);
154 border: 1px solid var(--rule);
155 border-radius: 8px;
156 padding: 1rem 1.25rem;
157 text-align: center;
158}
159.stat-num {
160 font-size: 2rem;
161 font-weight: 700;
162 color: var(--accent);
163 line-height: 1;
164 font-family: var(--font-display, serif);
165}
166.stat-label {
167 color: var(--ink-muted);
168 font-size: 0.85rem;
169 text-transform: uppercase;
170 letter-spacing: 0.05em;
171 margin-top: 0.25rem;
172}
173
174.admin-table {
175 width: 100%;
176 border-collapse: collapse;
177 background: var(--paper-2);
178 border: 1px solid var(--rule);
179 border-radius: 8px;
180 overflow: hidden;
181}
182.admin-table th, .admin-table td {
183 padding: 0.6rem 0.9rem;
184 text-align: left;
185 border-bottom: 1px solid var(--rule);
186}
187.admin-table th {
188 background: var(--paper);
189 font-weight: 600;
190 font-size: 0.85rem;
191 text-transform: uppercase;
192 letter-spacing: 0.05em;
193 color: var(--ink-muted);
194}
195.admin-table tr:last-child td { border-bottom: 0; }
196.admin-table code { background: var(--paper); padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85rem; }
197
198.role-pill {
199 display: inline-block;
200 padding: 0.1rem 0.5rem;
201 border-radius: 10px;
202 font-size: 0.75rem;
203 text-transform: uppercase;
204 letter-spacing: 0.05em;
205 background: var(--paper);
206 color: var(--ink-muted);
207}
208.role-pill.role-god { background: var(--accent); color: white; }
209.role-pill.role-admin { background: var(--paper); color: var(--accent); border: 1px solid var(--accent); }
210
211.admin-todo {
212 margin: 2rem 0 0;
213 padding: 0.75rem 1rem;
214 background: var(--paper-2);
215 border-left: 3px solid var(--accent);
216 border-radius: 4px;
217 font-size: 0.9rem;
218 color: var(--ink-muted);
219}
220
221@media (max-width: 600px) {
222 .admin-table { font-size: 0.85rem; }
223 .admin-table th, .admin-table td { padding: 0.45rem 0.6rem; }
224}
225</style>
Note: See TracBrowser for help on using the repository browser.