PageSourceSearch

https://8004.ch/assets/AdminDossiers-BSUlq-vP.js

js 8004.ch collected 2026-09-25 07:31:40 UTC 5,112 bytes, 1 lines download raw bytes

1import{r as l,s as c,j as t}from"./index-CLTM18rh.js";import{S as E}from"./SortableGroupedList-Hif2-Fmb.js";import{u as G}from"./AdminContext-B2hLlcqc.js";import{I as M}from"./InlineTagEditor-CgFtiFD0.js";import{N as q}from"./NurLesen-BKsmfvXD.js";import{R as B}from"./Filterleiste-Dovi1-bW.js";import"./bestaetige-CpNFuPQa.js";import"./klappzustand-DoGK2Y88.js";import"./chevron-right-D-hIC4R2.js";import"./authFetch-u5HjDcUX.js";function P(f){const m=new Map;for(const n of f){const a=n.group_name??"";m.has(a)||m.set(a,{items:[],gso:n.group_sort_order??0}),m.get(a).items.push(n)}return Array.from(m.entries()).map(([n,{items:a,gso:g}])=>({id:n,label:n||"Alle Dossiers",sort_order:g,items:a})).sort((n,a)=>n.sort_order-a.sort_order)}function X({onEdit:f,onNew:m}){const{permissions:n}=G(),a=n.perm_dossiers,[g,h]=l.useState([]),[y,N]=l.useState([]),[z,j]=l.useState(!0),[D,k]=l.useState(null),[_,R]=l.useState("active"),[v,A]=l.useState({active:0,archived:0}),w=l.useCallback(async()=>{j(!0);const[{data:s},{data:r},{data:o}]=await Promise.all([c.from("dossiers").select("id, title, is_archived, sort_order, group_name, group_sort_order, owner_id").order("group_sort_order").order("sort_order").order("created_at",{ascending:!1}),c.from("tags").select("id, name").eq("for_dossiers",!0).order("sort_order").order("name"),c.from("dossier_tags").select("dossier_id, tag_id")]),i=Array.from(new Set((s??[]).map(e=>e.owner_id).filter(e=>!!e))),d=new Map;if(i.length>0){const{data:e}=await c.from("profiles").select("id, display_name").in("id",i);for(const u of e??[])d.set(u.id,u.display_name)}const x=new Map((r??[]).map(e=>[e.id,e])),p=new Map;for(const e of o??[]){const u=x.get(e.tag_id);u&&(p.has(e.dossier_id)||p.set(e.dossier_id,[]),p.get(e.dossier_id).push(u))}const b=(s??[]).map(e=>({...e,tags:p.get(e.id)??[],owner_name:e.owner_id?d.get(e.owner_id)??null:null}));A({active:b.filter(e=>!e.is_archived).length,archived:b.filter(e=>e.is_archived).length});const L=b.filter(e=>_==="active"?!e.is_archived:e.is_archived);h(P(L)),N(r??[]),j(!1)},[_]);l.useEffect(()=>{w()},[w]);async function I(s){k(s),await c.from("dossiers").delete().eq("id",s),await w(),k(null)}function S(s,r){h(o=>o.map(i=>({...i,items:i.items.map(d=>d.id!==s?d:{...d,tags:y.filter(x=>r.includes(x.id))})})))}async function T(s,r){h(o=>o.map(i=>i.id!==s?i:{...i,items:r.map((d,x)=>({...i.items.find(p=>p.id===d),sort_order:x}))})),await Promise.all(r.map((o,i)=>c.from("dossiers").update({sort_order:i}).eq("id",o)))}async function C(s){h(r=>s.map((o,i)=>({...r.find(d=>d.id===o),sort_order:i}))),await Promise.all(s.map((r,o)=>c.from("dossiers").update({group_sort_order:o}).eq("group_name",r)))}return t.jsxs("div",{children:[t.jsx(q,{recht:"perm_dossiers"}),t.jsxs("div",{className:"flex items-center justify-between mb-6",children:[t.jsx("h1",{className:"text-xl font-bold text-zinc-900 dark:text-white",children:"Dossiers"}),a&&t.jsxs("button",{onClick:m,className:"flex items-center gap-2 px-4 py-2 bg-red-600 hover:bg-red-700 text-white text-sm font-medium rounded-lg transition-colors",children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Neues Dossier"]})]}),t.jsx(B,{aktiv:_,onWechsel:R,reiter:[{key:"active",label:"Aktiv",anzahl:v.active},{key:"rueckblick",label:"Rückblick",anzahl:v.archived}]}),z?t.jsx("div",{className:"py-20 text-center text-zinc-400 text-sm",children:"Lädt…"}):t.jsx(E,{groups:g,deletingId:D,emptyText:"Noch keine Dossiers.",onReorderItems:T,onReorderGroups:C,onEdit:a?f:void 0,onDelete:a?I:void 0,getItemLabel:s=>s.title,columnHeaders:t.jsxs(t.Fragment,{children:[t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider",children:"Titel"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider hidden md:table-cell",children:"Tags"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider hidden md:table-cell",children:"Verantwortlich"}),t.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider hidden lg:table-cell",children:"Ablage"})]}),renderCells:s=>t.jsxs(t.Fragment,{children:[t.jsx("td",{className:`px-4 py-3 font-medium text-zinc-900 dark:text-white ${s.is_archived?"opacity-50":""}`,children:s.title}),t.jsx("td",{className:"px-4 py-3 hidden md:table-cell",children:t.jsx(M,{itemId:s.id,tagIds:s.tags.map(r=>r.id),allTags:y,junctionTable:"dossier_tags",itemKey:"dossier_id",onChange:r=>S(s.id,r),readOnly:!a})}),t.jsx("td",{className:"px-4 py-3 hidden md:table-cell text-sm",children:s.owner_name?t.jsx("span",{className:"text-zinc-700 dark:text-zinc-300",children:s.owner_name}):t.jsx("span",{className:"text-zinc-400 dark:text-zinc-500 italic",children:"—"})}),t.jsx("td",{className:"px-4 py-3 text-zinc-500 dark:text-zinc-400 hidden lg:table-cell text-xs",children:s.is_archived?"Rückblick":"Aktiv"})]})})]})}export{X as AdminDossiers};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.