PageSourceSearch

https://8004.ch/assets/AdminTags-egNX5UpG.js

js 8004.ch collected 2026-10-02 20:50:29 UTC 10,229 bytes, 1 lines download raw bytes

1import{r as i,j as t,s as c}from"./index-DeJ875KO.js";import{u as K}from"./AdminContext-DezprucX.js";import{N as R}from"./NurLesen-D6aOATEr.js";import{b as U}from"./bestaetige-CpNFuPQa.js";import"./authFetch-B7xfneuy.js";const z=[{key:"for_events",label:"Veranstaltungen"},{key:"for_news",label:"News"},{key:"for_dossiers",label:"Dossiers"},{key:"for_products",label:"Produkte"},{key:"for_surveys",label:"Umfragen"},{key:"for_documents",label:"Dokumente"},{key:"for_verein",label:"Verein"}];function W(){return t.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:t.jsx("path",{d:"M7 2a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zM7 8a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zm-6 6a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4z"})})}function Z(){const{permissions:g}=K(),s=g.perm_news||g.perm_events||g.perm_products,[d,f]=i.useState([]),[F,H]=i.useState(!0),[v,w]=i.useState(null),[u,j]=i.useState(""),[N,y]=i.useState(!1),[_,x]=i.useState(null),[k,S]=i.useState(""),[D,$]=i.useState(null),[E,T]=i.useState(null),[m,b]=i.useState(null),[M,p]=i.useState(null),[a,C]=i.useState("all"),L=a==="all"?d:d.filter(e=>e[a]===!0);async function h(){w(null);const{data:e,error:r}=await c.from("tags").select("id, name, sort_order, is_primary, for_events, for_news, for_dossiers, for_products, for_surveys, for_documents, for_verein").order("sort_order").order("name");r&&w(r.message),f(e??[]),H(!1)}i.useEffect(()=>{h()},[]);async function q(e){e.preventDefault(),u.trim()&&(y(!0),await c.from("tags").insert({name:u.trim(),sort_order:d.length}),j(""),await h(),y(!1))}async function A(e){if(!k.trim()){x(null);return}await c.from("tags").update({name:k.trim()}).eq("id",e),x(null),await h()}async function B(e){await U("Tag löschen? Er wird von allen Einträgen entfernt.")&&($(e),await c.from("tags").delete().eq("id",e),await h(),$(null))}async function I(e,r){const n=!e[r];T(`${e.id}-${String(r)}`),await c.from("tags").update({[r]:n}).eq("id",e.id),f(o=>o.map(l=>l.id===e.id?{...l,[r]:n}:l)),T(null)}function O(e,r){e.preventDefault(),p(r)}async function P(e){if(m===null||m===e){b(null),p(null);return}const r=[...d],[n]=r.splice(m,1);r.splice(e,0,n),f(r),b(null),p(null),await Promise.all(r.map((o,l)=>c.from("tags").update({sort_order:l}).eq("id",o.id)))}function V(){b(null),p(null)}return t.jsxs("div",{children:[t.jsx(R,{recht:"perm_news",auch:["perm_events","perm_products"],was:"Tags"}),t.jsx("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:"Tags"})}),t.jsxs("p",{className:"text-sm text-zinc-500 dark:text-zinc-400 mb-4",children:["Tags werden zentral hier verwaltet. Die Checkboxen bestimmen, in welchen Bereichen ein Tag verfügbar ist. Als ",t.jsx("strong",{className:"font-medium text-zinc-600 dark:text-zinc-300",children:"Hauptkategorie"})," markierte Tags dienen als Kategorie einer Veranstaltung (bestimmen Farbe + Symbol) und können nicht umbenannt werden."]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-6",children:[t.jsx("span",{className:"text-xs font-medium text-zinc-400 dark:text-zinc-500 uppercase tracking-wider mr-1",children:"Filter:"}),t.jsxs("button",{type:"button",onClick:()=>C("all"),className:`px-3 py-1 text-xs font-medium rounded-full border transition-colors ${a==="all"?"bg-zinc-900 dark:bg-white text-white dark:text-zinc-900 border-zinc-900 dark:border-white":"bg-white dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 border-zinc-300 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-700"}`,children:["Alle (",d.length,")"]}),z.map(({key:e,label:r})=>{const n=d.filter(l=>l[e]).length,o=a===e;return t.jsxs("button",{type:"button",onClick:()=>C(o?"all":e),className:`px-3 py-1 text-xs font-medium rounded-full border transition-colors ${o?"bg-red-600 text-white border-red-600":"bg-white dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 border-zinc-300 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-700"}`,children:[r," (",n,")"]},String(e))})]}),s&&t.jsxs("form",{onSubmit:q,className:"flex gap-2 mb-6",children:[t.jsx("input",{value:u,onChange:e=>j(e.target.value),placeholder:"Neuer Tag…",className:"flex-1 px-3 py-2 rounded-lg border border-zinc-300 dark:border-zinc-700 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 text-sm focus:outline-none focus:ring-2 focus:ring-red-500 focus:border-transparent"}),t.jsx("button",{type:"submit",disabled:N||!u.trim(),className:"px-4 py-2 bg-red-600 hover:bg-red-700 disabled:opacity-50 text-white text-sm font-medium rounded-lg transition-colors",children:N?"Hinzufügen…":"Hinzufügen"})]}),v&&t.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-xs text-red-700 dark:text-red-400 font-mono break-all",children:v}),F?t.jsx("div",{className:"py-20 text-center text-zinc-400 text-sm",children:"Lädt…"}):d.length===0?t.jsx("p",{className:"text-sm text-zinc-400 dark:text-zinc-500 italic",children:"Noch keine Tags erstellt."}):L.length===0?t.jsx("p",{className:"text-sm text-zinc-400 dark:text-zinc-500 italic",children:"Keine Tags für diesen Filter."}):t.jsxs("div",{className:"rounded-xl border border-zinc-200 dark:border-zinc-800 overflow-x-auto",children:[a!=="all"&&t.jsx("div",{className:"px-4 py-2 bg-amber-50 dark:bg-amber-950/20 border-b border-amber-200 dark:border-amber-900 text-xs text-amber-700 dark:text-amber-400",children:"Reihenfolge ändern ist nur ohne Filter möglich (Filter zurücksetzen mit „Alle“)."}),t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-zinc-50 dark:bg-zinc-800/50 border-b border-zinc-200 dark:border-zinc-800",children:t.jsxs("tr",{children:[s&&t.jsx("th",{className:"w-8 px-3 py-3"}),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:"px-3 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider text-center whitespace-nowrap",children:"Hauptkategorie"}),z.map(({key:e,label:r})=>t.jsx("th",{className:"px-3 py-3 text-xs font-semibold text-zinc-400 uppercase tracking-wider text-center whitespace-nowrap",children:r},String(e))),s&&t.jsx("th",{className:"w-40"})]})}),t.jsx("tbody",{className:"divide-y divide-zinc-100 dark:divide-zinc-800",children:L.map((e,r)=>t.jsxs("tr",{draggable:s&&_!==e.id&&a==="all",onDragStart:s&&a==="all"?()=>b(r):void 0,onDragOver:s&&a==="all"?n=>O(n,r):void 0,onDrop:s&&a==="all"?()=>P(r):void 0,onDragEnd:s&&a==="all"?V:void 0,className:`transition-colors ${M===r&&m!==r?"bg-red-50 dark:bg-red-950/20":m===r?"opacity-40 bg-zinc-50 dark:bg-zinc-800/50":"hover:bg-zinc-50 dark:hover:bg-zinc-800/30"}`,children:[s&&t.jsx("td",{className:`px-3 py-3 text-zinc-300 dark:text-zinc-600 select-none ${a==="all"?"cursor-grab active:cursor-grabbing":"opacity-30 curs
1or-not-allowed"}`,children:t.jsx(W,{})}),t.jsx("td",{className:"px-4 py-3",children:_===e.id?t.jsxs("div",{className:"flex gap-2 items-center",children:[t.jsx("input",{autoFocus:!0,value:k,onChange:n=>S(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),A(e.id)),n.key==="Escape"&&x(null)},className:"px-2 py-1 rounded border border-zinc-300 dark:border-zinc-700 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white text-sm focus:outline-none focus:ring-1 focus:ring-red-500"}),t.jsx("button",{type:"button",onClick:()=>A(e.id),className:"text-xs text-red-600 dark:text-red-400 hover:underline font-medium",children:"Speichern"}),t.jsx("button",{type:"button",onClick:()=>x(null),className:"text-xs text-zinc-400 hover:underline",children:"Abbrechen"})]}):t.jsx("span",{className:"font-medium text-zinc-900 dark:text-white",children:e.name})}),t.jsx("td",{className:"px-3 py-3 text-center",children:s?t.jsx("button",{type:"button",disabled:E===`${e.id}-is_primary`,onClick:()=>I(e,"is_primary"),className:`w-5 h-5 rounded border-2 transition-colors mx-auto flex items-center justify-center ${e.is_primary?"bg-red-600 border-red-600 text-white":"border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800"} disabled:opacity-50`,"aria-label":`${e.name} als Hauptkategorie ${e.is_primary?"deaktivieren":"aktivieren"}`,children:e.is_primary&&t.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})})}):t.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e.is_primary?"bg-red-500":"bg-zinc-200 dark:bg-zinc-700"}`})}),z.map(({key:n})=>t.jsx("td",{className:"px-3 py-3 text-center",children:s?t.jsx("button",{type:"button",disabled:E===`${e.id}-${String(n)}`,onClick:()=>I(e,n),className:`w-5 h-5 rounded border-2 transition-colors mx-auto flex items-center justify-center ${e[n]?"bg-red-600 border-red-600 text-white":"border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-800"} disabled:opacity-50`,"aria-label":`${e.name} für ${String(n)} ${e[n]?"deaktivieren":"aktivieren"}`,children:e[n]&&t.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})})}):t.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e[n]?"bg-red-500":"bg-zinc-200 dark:bg-zinc-700"}`})},String(n))),s&&t.jsx("td",{className:"px-4 py-3",children:e.is_primary?t.jsx("div",{className:"flex items-center justify-end",children:t.jsx("span",{className:"text-[11px] text-zinc-400 dark:text-zinc-500 italic",children:"Hauptkategorie — Name fix"})}):t.jsxs("div",{className:"flex items-center justify-end gap-4",children:[t.jsx("button",{type:"button",onClick:()=>{x(e.id),S(e.name)},className:"text-xs text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 transition-colors",children:"Umbenennen"}),t.jsx("button",{type:"button",onClick:()=>B(e.id),disabled:D===e.id,className:"text-xs text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 disabled:opacity-50 transition-colors",children:D===e.id?"…":"Löschen"})]})})]},e.id))})]})]})]})}export{Z as AdminTags};

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.