feat(admin): nav per 3 ruoli, blog filtrato per autore + colonna autore
This commit is contained in:
+11
-2
@@ -31,8 +31,17 @@ const user = Astro.locals.user;
|
|||||||
<div class="abar">
|
<div class="abar">
|
||||||
<strong>InsanityLab · Admin</strong>
|
<strong>InsanityLab · Admin</strong>
|
||||||
<span>
|
<span>
|
||||||
{user && user.role === 'editor' && <>{`Ciao, ${user.username}`} <a href="/admin/content">Contenuti</a> <a href="/admin/logout">Esci</a></>}
|
{user && (
|
||||||
{user && user.role !== 'editor' && <>{`Ciao, ${user.username}`} <a href="/admin">Articoli</a> <a href="/admin/content">Contenuti</a> <a href="/admin/new">Nuovo</a> <a href="/admin/logout">Esci</a> <a href="/blog" target="_blank">Vedi sito ↗</a></>}
|
<>
|
||||||
|
{`Ciao, ${user.username}`}
|
||||||
|
<a href="/admin">Articoli</a>
|
||||||
|
{(user.role === 'superuser' || user.role === 'admin') && <a href="/admin/content">Contenuti</a>}
|
||||||
|
{user.role === 'admin' && <a href="/admin/users">Utenti</a>}
|
||||||
|
<a href="/admin/new">Nuovo</a>
|
||||||
|
<a href="/admin/logout">Esci</a>
|
||||||
|
<a href="/blog" target="_blank">Vedi sito ↗</a>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="awrap"><slot /></div>
|
<div class="awrap"><slot /></div>
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
---
|
---
|
||||||
import Admin from '../../layouts/Admin.astro';
|
import Admin from '../../layouts/Admin.astro';
|
||||||
import { getDb } from '../../lib/db';
|
import { getDb } from '../../lib/db';
|
||||||
import { listAllPosts } from '../../lib/posts';
|
import { listAllPosts, listByAuthor } from '../../lib/posts';
|
||||||
|
import { listUsers } from '../../lib/auth';
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
const posts = listAllPosts(getDb());
|
const user = Astro.locals.user!;
|
||||||
|
const isManager = user.role === 'superuser' || user.role === 'admin';
|
||||||
|
const posts = isManager ? listAllPosts(getDb()) : listByAuthor(getDb(), user.id);
|
||||||
|
const nameById = new Map(listUsers(getDb()).map((u) => [u.id, u.username]));
|
||||||
const fmt = new Intl.DateTimeFormat('it-IT', { dateStyle: 'short', timeStyle: 'short' });
|
const fmt = new Intl.DateTimeFormat('it-IT', { dateStyle: 'short', timeStyle: 'short' });
|
||||||
---
|
---
|
||||||
<Admin title="Articoli">
|
<Admin title="Articoli">
|
||||||
<h1>Articoli</h1>
|
<h1>Articoli</h1>
|
||||||
<p><a class="abtn" href="/admin/new">+ Nuovo articolo</a></p>
|
<p><a class="abtn" href="/admin/new">+ Nuovo articolo</a></p>
|
||||||
<table>
|
<table>
|
||||||
<thead><tr><th>Titolo</th><th>Categoria</th><th>Stato</th><th>Aggiornato</th><th></th></tr></thead>
|
<thead><tr><th>Titolo</th><th>Categoria</th>{isManager && <th>Autore</th>}<th>Stato</th><th>Aggiornato</th><th></th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{posts.map((p) => (
|
{posts.map((p) => (
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href={`/admin/edit/${p.id}`}>{p.title}</a></td>
|
<td><a href={`/admin/edit/${p.id}`}>{p.title}</a></td>
|
||||||
<td>{p.category}</td>
|
<td>{p.category}</td>
|
||||||
|
{isManager && <td>{p.author_id ? (nameById.get(p.author_id) ?? 'Staff InsanityLab') : 'Staff InsanityLab'}</td>}
|
||||||
<td><span class:list={['pill', { 'pill--draft': p.draft }]}>{p.draft ? 'Bozza' : 'Pubblicato'}</span></td>
|
<td><span class:list={['pill', { 'pill--draft': p.draft }]}>{p.draft ? 'Bozza' : 'Pubblicato'}</span></td>
|
||||||
<td>{fmt.format(new Date(p.updated_at.replace(' ', 'T') + 'Z'))}</td>
|
<td>{fmt.format(new Date(p.updated_at.replace(' ', 'T') + 'Z'))}</td>
|
||||||
<td><button class="abtn abtn--danger" data-del={p.id}>Elimina</button></td>
|
<td><button class="abtn abtn--danger" data-del={p.id}>Elimina</button></td>
|
||||||
|
|||||||
Reference in New Issue
Block a user