PageSourceSearch

https://8004.ch/assets/AdminVereine-Mv9Yq6XX.js

js 8004.ch collected 2026-09-25 07:31:36 UTC 4,856 bytes, 1 lines download raw bytes

1import{r as u,j as t,s as x}from"./index-CLTM18rh.js";import{u as M}from"./AdminContext-B2hLlcqc.js";import{I as L}from"./InlineTagEditor-CgFtiFD0.js";import{S}from"./SortableGroupedList-Hif2-Fmb.js";import{N as T}from"./NurLesen-BKsmfvXD.js";import"./bestaetige-CpNFuPQa.js";import"./klappzustand-DoGK2Y88.js";import"./chevron-right-D-hIC4R2.js";import"./authFetch-u5HjDcUX.js";function A(v,h){const f=new Map(h.map((r,a)=>[r.id,a])),c=new Map;for(const r of h)c.set(r.id,{label:r.name,sortIdx:f.get(r.id)??0,items:[]});const g=[];for(const r of v){const a=[...r.tags].sort((m,p)=>(f.get(m.id)??999)-(f.get(p.id)??999));if(a.length===0)g.push(r);else{const m=c.get(a[0].id);m?m.items.push(r):g.push(r)}}const l=[];for(const[r,{label:a,sortIdx:m,items:p}]of c)p.length>0&&l.push({id:r,label:a,sort_order:m,items:[...p].sort((j,_)=>j.sort_order-_.sort_order)});return g.length>0&&l.push({id:"__other__",label:"Weitere",sort_order:9999,items:[...g].sort((r,a)=>r.sort_order-a.sort_order)}),l.sort((r,a)=>r.sort_order-a.sort_order)}function $({onEdit:v,onNew:h}){const{permissions:f}=M(),c=f.perm_vereine,[g,l]=u.useState([]),[r,a]=u.useState([]),[m,p]=u.useState(!0),[j,_]=u.useState(null);async function k(){p(!0);const[{data:e},{data:s},{data:i}]=await Promise.all([x.from("vereine").select("id, name, active, sort_order").order("sort_order").order("name"),x.from("tags").select("id, name").eq("for_verein",!0).order("sort_order").order("name"),x.from("verein_tags").select("verein_id, tag_id")]),n=new Map((s??[]).map(o=>[o.id,o])),d=new Map;for(const o of i??[]){const b=n.get(o.tag_id);b&&(d.has(o.verein_id)||d.set(o.verein_id,[]),d.get(o.verein_id).push(b))}l((e??[]).map(o=>({...o,tags:d.get(o.id)??[]}))),a(s??[]),p(!1)}u.useEffect(()=>{k()},[]);async function y(e){_(e),await x.from("vereine").delete().eq("id",e),await k(),_(null)}async function w(e,s){await x.from("vereine").update({active:!s}).eq("id",e),l(i=>i.map(n=>n.id===e?{...n,active:!s}:n))}function N(e,s){l(i=>i.map(n=>n.id!==e?n:{...n,tags:r.filter(d=>s.includes(d.id))}))}async function I(e,s){l(i=>i.map(n=>{const d=s.indexOf(n.id);return d>=0?{...n,sort_order:d}:n})),await Promise.all(s.map((i,n)=>x.from("vereine").update({sort_order:n}).eq("id",i)))}async function z(e){const s=e.filter(i=>i!=="__other__");a(i=>{const n=s.map(o=>i.find(b=>b.id===o)).filter(Boolean),d=i.filter(o=>!s.includes(o.id));return[...n,...d]}),await Promise.all(s.map((i,n)=>x.from("tags").update({sort_order:n}).eq("id",i)))}const E=u.useMemo(()=>A(g,r),[g,r]);return t.jsxs("div",{children:[t.jsx(T,{recht:"perm_vereine"}),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:"Vereine & Institutionen"}),c&&t.jsxs("button",{onClick:h,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"})}),"Neuer Eintrag"]})]}),m?t.jsx("div",{className:"py-20 text-center text-zinc-400 text-sm",children:"Lädt…"}):t.jsx(S,{groups:E,deletingId:j,emptyText:"Noch keine Einträge.",onReorderItems:I,onReorderGroups:z,onEdit:c?v:void 0,onDelete:c?y:void 0,getItemLabel:e=>e.name,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:"Name"}),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",children:"Status"})]}),renderCells:e=>t.jsxs(t.Fragment,{children:[t.jsx("td",{className:`px-4 py-3 font-medium text-zinc-900 dark:text-white ${e.active?"":"opacity-50"}`,children:e.name}),t.jsx("td",{className:"px-4 py-3 hidden md:table-cell",children:t.jsx(L,{itemId:e.id,tagIds:e.tags.map(s=>s.id),allTags:r,junctionTable:"verein_tags",itemKey:"verein_id",onChange:s=>N(e.id,s),readOnly:!c})}),t.jsx("td",{className:"px-4 py-3",children:c?t.jsx("button",{onClick:()=>w(e.id,e.active),className:`text-xs font-medium px-2 py-0.5 rounded-full transition-colors ${e.active?"bg-green-100 dark:bg-green-950/40 text-green-700 dark:text-green-400 hover:bg-green-200":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 hover:bg-zinc-200"}`,children:e.active?"Aktiv":"Inaktiv"}):t.jsx("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${e.active?"bg-green-100 dark:bg-green-950/40 text-green-700 dark:text-green-400":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500"}`,children:e.active?"Aktiv":"Inaktiv"})})]})})]})}export{$ as AdminVereine};

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.