divan/web/src/pages/mod/order/[id].astro
Anas Rashid cde754412e Arranging content (#41): reorder a book or section's works and sub-sections, a poet's books
- Its own permission (arrange), separate from editing; same L2 -> L1 -> admin pipeline as a work's text
  (revisions with entity 'order'), one line per item; only the order counts and every item stays listed.
- Publishing writes divan-data/divan/<url>.order, commits it and updates the site's positions.
- ترتیب دیں on poet and book/section pages; a sortable list (drag, ↑ ↓, اول, آخر); /mod/order/:id history.
- An unchanged arrangement is not kept, as with texts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 14:02:26 +02:00

47 lines
2.4 KiB
Plaintext

---
// A book/section's arrangements (#41): its current order, published versions and drafts; "ترتیب دیں" starts a draft
import Base from '../../../layouts/Base.astro';
import ModNav from '../../../components/ModNav.astro';
import { asUser, COOKIE } from '../../../lib/auth';
import { STATUS, when } from '../../../lib/mod';
import { ud } from '../../../lib/urdu';
const me = Astro.locals.user;
if (!me) return Astro.redirect(`/signin?next=${Astro.url.pathname}`);
const token = Astro.cookies.get(COOKIE)!.value, id = Number(Astro.params.id) || 0;
let error = '';
if (Astro.request.method === 'POST') {
const r = await asUser(token, `/api/mod/order/${id}/draft`, {});
if (r.ok) return Astro.redirect(`/mod/rev/${r.data.id}`);
error = r.data.error ?? 'کچھ غلط ہو گیا';
}
const res = await asUser(token, `/api/mod/order/${id}`);
if (!res.ok) return new Response(res.data.error ?? 'نہیں ملا', { status: res.status });
const { section, version, history, count, may } = res.data;
---
<Base title={`ترتیب: ${section.title}`}>
<h1>ترتیب: {section.title}</h1>
<ModNav />
<p class="center"><a href={section.url}>{section.parent_id ? 'کتاب یا باب' : 'شاعر کا صفحہ'}</a> · {ud(count)} چیزیں ·
{version ? `موجودہ ترتیب: ورژن ${ud(version)}` : 'ویکی ماخذ کی ترتیب (ابھی دیوان کی کوئی ترتیب نہیں)'}</p>
{error && <p class="form-error" role="alert">{error}</p>}
{may.arrange && count > 1 && <form method="post" class="center"><button class="save-like">ترتیب دیں</button></form>}
<table class="admin-table">
<thead><tr><th>ورژن</th><th>حالت</th><th>خلاصہ</th><th>لکھنے والے</th><th>جائزہ</th><th>اشاعت</th><th>تاریخ</th></tr></thead>
<tbody>
{history.map((h: any) => (
<tr>
<td><a href={`/mod/rev/${h.id}`}>{h.version ? ud(h.version) : '—'}</a></td>
<td><span class={`status s-${h.status}`}>{STATUS[h.status]}</span></td>
<td>{h.summary}</td>
<td><bdi dir="ltr">{h.author_email}</bdi></td>
<td><bdi dir="ltr">{h.reviewer_email ?? ''}</bdi></td>
<td><bdi dir="ltr">{h.publisher_email ?? ''}</bdi></td>
<td><bdi dir="ltr">{when(h.published_at ?? h.created_at)}</bdi></td>
</tr>
))}
</tbody>
</table>
{history.length === 0 && <p class="muted center">ابھی ترتیب میں کوئی تبدیلی نہیں۔</p>}
</Base>