PageSourceSearch

https://spotz.global/assets/crm.filer-DTqJN-kN.js

js spotz.global collected 2026-10-09 22:06:08 UTC 5,498 bytes, 1 lines download raw bytes

1import{r as m,j as e,L as w}from"./index-bQZ6-MOf.js";import{u as K}from"./useQuery-BAgesPRj.js";import{u as v}from"./createServerFn-CU39I-WU.js";import{l as P,g as z,f as q,a as O,b as E}from"./AttachmentManager-VlY9FJ4W.js";import{C as R}from"./card-CBB0DeSN.js";import{I as U}from"./input-BVxfNuVn.js";import{B as k}from"./button-FZYZqtg_.js";import{B as M}from"./badge-DX37h3iV.js";import{T as Q,a as W,b as x,c as d,d as $,e as n}from"./table-BHcxPV8I.js";import{D as G,a as J,b as V,c as X}from"./dialog-D_gBSd9w.js";import{t as u}from"./index-bl41CerC.js";import{L as _}from"./loader-circle-CKIcQc3r.js";import{D as Y}from"./download-CNV669kQ.js";import{A as Z}from"./arrow-up-down-BtEZjHD0.js";import"./suspense-IMGYCAfs.js";import"./useMutation-BqblAeBb.js";import"./auth-middleware-24HItX2r.js";import"./utils-BQHNewu7.js";import"./file-text-Dn6GVqtF.js";import"./paperclip-DyKBC2yl.js";import"./eye-jSbaXCnC.js";import"./trash-2-CSPNkB6s.js";import"./index-BPzT5xwB.js";function ve(){const C=v(P),h=v(z),[p,T]=m.useState(""),[i,S]=m.useState({key:"created_at",dir:"desc"}),[a,l]=m.useState({open:!1,url:null,fileName:"",mimeType:null}),{data:f=[],isLoading:L}=K({queryKey:["crm-all-attachments"],queryFn:async()=>{try{return await C()}catch(t){return u.error(t?.message??"Kunne ikke hente filer"),[]}}}),j=m.useMemo(()=>{const t=p.trim().toLowerCase(),s=f.filter(r=>!t||r.file_name?.toLowerCase().includes(t)||r.entity_title?.toLowerCase().includes(t)),c=i.dir==="asc"?1:-1;return[...s].sort((r,H)=>{const N=r[i.key]??"",b=H[i.key]??"";return i.key==="size_bytes"?(Number(N)-Number(b))*c:String(N).localeCompare(String(b),"nb")*c})},[f,p,i]),D=t=>S(s=>s.key===t?{key:t,dir:s.dir==="asc"?"desc":"asc"}:{key:t,dir:"asc"}),F=async(t,s,c)=>{l({open:!0,url:null,fileName:s,mimeType:c});try{const r=await h({data:{id:t}});l({open:!0,url:r.url,fileName:r.fileName,mimeType:r.mimeType})}catch(r){l({open:!1,url:null,fileName:"",mimeType:null}),u.error(r?.message??"Kunne ikke åpne forhåndsvisning")}},B=async t=>{try{const s=await h({data:{id:t,download:!0}});window.open(s.url,"_blank","noopener")}catch(s){u.error(s?.message??"Kunne ikke laste ned filen")}},o=({k:t,label:s})=>e.jsx(d,{children:e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 hover:text-foreground",onClick:()=>D(t),children:[s," ",e.jsx(Z,{className:"w-3 h-3"})]})}),y=(a.mimeType??"").toLowerCase(),g=a.fileName.split(".").pop()?.toLowerCase()??"",I=y.startsWith("image/")||["png","jpg","jpeg","gif","webp","svg"].includes(g),A=y==="application/pdf"||g==="pdf";return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h2",{className:"text-2xl font-serif",children:"Filer"})}),e.jsx(U,{placeholder:"Søk i filnavn eller tilknytning…",value:p,onChange:t=>T(t.target.value),className:"max-w-md"}),e.jsx(R,{className:"p-2",children:L?e.jsx("div",{className:"py-6 flex justify-center",children:e.jsx(_,{className:"w-5 h-5 animate-spin"})}):e.jsxs(Q,{children:[e.jsx(W,{children:e.jsxs(x,{children:[e.jsx(o,{k:"file_name",label:"Filnavn"}),e.jsx(d,{children:"Knyttet til"}),e.jsx(o,{k:"entity_type",label:"Type"}),e.jsx(d,{children:"Format"}),e.jsx(o,{k:"created_at",label:"Opplastet"}),e.jsx(o,{k:"size_bytes",label:"Størrelse"}),e.jsx(d,{className:"text-right",children:"Handlinger"})]})}),e.jsxs($,{children:[j.map(t=>{const s=q(t.mime_type,t.file_name);return e.jsxs(x,{children:[e.jsx(n,{children:e.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 hover:underline text-left",onClick:()=>F(t.id,t.file_name,t.mime_type),children:[e.jsx(s,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"truncate max-w-[18rem]",children:t.file_name})]})}),e.jsxs(n,{children:[t.entity_type==="project"?e.jsx(w,{to:"/crm/prosjekter/$id",params:{id:t.entity_id},className:"hover:underline",children:t.entity_title}):e.jsx(w,{to:"/crm/oppgaver",className:"hover:underline",children:t.entity_title}),t.entity_subtype&&e.jsx(M,{variant:"outline",className:"ml-2",children:t.entity_subtype})]}),e.jsx(n,{children:t.entity_type==="task"?"Oppgave":"Prosjekt"}),e.jsx(n,{className:"text-muted-foreground text-xs",children:t.mime_type??"—"}),e.jsx(n,{children:O(t.created_at)}),e.jsx(n,{children:E(Number(t.size_bytes))}),e.jsx(n,{className:"text-right",children:e.jsx(k,{variant:"ghost",size:"sm",title:"Last ned",onClick:()=>B(t.id),children:e.jsx(Y,{className:"w-4 h-4"})})})]},t.id)}),j.length===0&&e.jsx(x,{children:e.jsx(n,{colSpan:7,className:"text-center text-sm text-muted-foreground py-6",children:"Ingen filer."})})]})]})}),e.jsx(G,{open:a.open,onOpenChange:t=>l(s=>({...s,open:t})),children:e.jsxs(J,{className:"max-w-4xl",children:[e.jsx(V,{children:e.jsx(X,{className:"truncate",children:a.fileName})}),a.url?I?e.jsx("img",{src:a.url,alt:a.fileName,className:"max-h-[70vh] w-full object-contain rounded-md"}):A?e.jsx("iframe",{src:a.url,title:a.fileName,className:"w-full h-[70vh] rounded-md border border-border"}):e.jsxs("div",{className:"h-64 flex flex-col items-center justify-center gap-3 text-muted-foreground",children:[e.jsx("p",{className:"text-sm",children:"Forhåndsvisning er ikke tilgjengelig for dette formatet."}),e.jsx(k,{asChild:!0,children:e.jsxs("a",{href:a.url,download:a.fileName,children:["Last ned ",a.fileName]})})]}):e.jsx("div",{className:"h-64 flex items-center justify-center",children:e.jsx(_,{className:"w-5 h-5 animate-spin"})})]})})]})}export{ve as component};

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.