PageSourceSearch

https://app-dev.terrahub.ai/assets/MacchinePage-D8IARJbT.js

js terrahub.ai collected 2026-10-05 15:54:35 UTC 9,068 bytes, 1 lines download raw bytes

1import{r as c,F as a,b5 as F,c2 as O,c0 as H,aA as P,ay as _,bc as U}from"./vendor-DyJ_Ifk1.js";import{B as N}from"./index-D8ZSZKG8.js";import{I as n}from"./input-DJY3Acsb.js";import{L as t}from"./label-DUD9zWo3.js";import{B as L}from"./badge-Bq9uePdP.js";import{N as z}from"./NativeSelect-Dh9-1ZLF.js";import{f as q,D as G,a as V,b as $,c as J}from"./dialog-DnWIba8x.js";import{T as K,b as Q,c as y,d as j,e as W,f as m}from"./table-C0Henui9.js";import{C as X,R as D}from"./ConfermaDialog-BivWR5uR.js";import{I as Y}from"./ImportFatturaButton-C_Jci9Z6.js";import{a as w,e as R}from"./anagrafica-CqHCeU_N.js";import{f as Z}from"./format-iMlVYE7E.js";import{S as aa}from"./SchedaAnagrafica-BiQVmlrr.js";import"./Attenzione-BZgxB1cE.js";import"./PageHero-B77T8MLR.js";import"./AnagraficaNav-CxsdgH63.js";import"./SezioneSubNav-CtYVHi7L.js";import"./useFunzionalita-D3Mx2ijM.js";const A=["Trattore","Mietitrebbia","Irroratrice / barra da diserbo","Atomizzatore","Aratro","Erpice","Seminatrice","Trapiantatrice","Trinciatrice","Fresa","Rimorchio","Botte / cisterna","Caricatore / telescopico","Motocoltivatore","Decespugliatore","Altro"];function ea({cuaa:h}){const[e,S]=c.useState([]),[b,s]=c.useState(!1),[C,x]=c.useState(null),[f,u]=c.useState(!1),[d,l]=c.useState(null),[i,v]=c.useState(null),[o,p]=c.useState(!1),[g,E]=c.useState("");async function T(){s(!0),x(null);try{const r=await w.listMacchinari(h);S(r.items||[])}catch(r){x(R(r))}finally{s(!1)}}c.useEffect(()=>{h&&T()},[h]);async function B(){if(!(!i||o)){p(!0),x(null);try{await w.removeMacchinario(i._id),v(null),await T()}catch(r){x(R(r)),v(null)}finally{p(!1)}}}const M=g.trim().toLowerCase(),k=M?e.filter(r=>[r.nome,r.categoria,r.marca,r.modello,r.targa].filter(Boolean).some(I=>String(I).toLowerCase().includes(M))):e;return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[a.jsxs("div",{className:"relative w-full max-w-xs",children:[a.jsx(F,{className:"absolute left-2 top-2.5 h-4 w-4 text-gray-400"}),a.jsx(n,{className:"pl-8",placeholder:"Cerca per nome, categoria, targa…",value:g,onChange:r=>E(r.target.value)})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Y,{tipo:"macchine"}),a.jsxs(N,{onClick:()=>{l(null),u(!0)},children:[a.jsx(O,{className:"h-4 w-4"})," Nuova macchina"]})]})]}),C&&a.jsx("div",{className:"rounded-md bg-red-50 border border-red-200 text-red-700 text-sm p-3",children:C}),a.jsx("div",{className:"rounded-lg border bg-white",children:a.jsxs(K,{children:[a.jsx(Q,{children:a.jsxs(y,{children:[a.jsx(j,{children:"Nome"}),a.jsx(j,{children:"Categoria"}),a.jsx(j,{children:"Marca e modello"}),a.jsx(j,{children:"Targa"}),a.jsx(j,{className:"text-right",children:"Ore"}),a.jsx(j,{children:"Ultima revisione"}),a.jsx(j,{})]})}),a.jsxs(W,{children:[b&&a.jsx(y,{children:a.jsx(m,{colSpan:7,className:"text-center py-8 text-gray-500",children:"Caricamento…"})}),!b&&k.length===0&&a.jsx(y,{children:a.jsx(m,{colSpan:7,className:"text-center py-8 text-gray-500",children:M?"Nessuna macchina corrisponde alla ricerca.":"Nessuna macchina. Aggiungi la prima con «Nuova macchina»."})}),!b&&k.map(r=>a.jsxs(y,{className:r.stato==="dismesso"?"opacity-60":"",children:[a.jsxs(m,{className:"font-medium",children:[r.nome,r.stato==="dismesso"&&a.jsx(L,{variant:"outline",className:"ml-2",children:"dismesso"})]}),a.jsx(m,{children:a.jsx(L,{variant:"secondary",children:r.categoria})}),a.jsxs(m,{className:"text-sm text-gray-600",children:[[r.marca,r.modello].filter(Boolean).join(" ")||"—",r.anno?a.jsxs("span",{className:"text-gray-400",children:[" · ",r.anno]}):null]}),a.jsx(m,{className:"text-sm text-gray-600",children:r.targa||"—"}),a.jsx(m,{className:"text-right text-sm tabular-nums text-gray-600",children:r.oreLavoro!=null?`${r.oreLavoro} h`:"—"}),a.jsx(m,{className:"text-sm text-gray-600",children:r.ultimaRevisione?Z(r.ultimaRevisione):"—"}),a.jsxs(m,{className:"text-right whitespace-nowrap",children:[a.jsx(N,{variant:"ghost",size:"icon",onClick:()=>{l(r),u(!0)},title:"Modifica",children:a.jsx(H,{className:"h-4 w-4 text-gray-600"})}),a.jsx(N,{variant:"ghost",size:"icon",onClick:()=>v(r),title:"Elimina",children:a.jsx(P,{className:"h-4 w-4 text-red-600"})})]})]},r._id))]})]})})]}),a.jsx(X,{open:!!i,title:"Elimina macchina",description:"La macchina verrà rimossa dal parco macchine.",confirmLabel:"Elimina",busy:o,onConfirm:B,onCancel:()=>!o&&v(null),children:i&&a.jsxs(a.Fragment,{children:[a.jsx(D,{label:"Macchina",value:i.nome}),a.jsx(D,{label:"Categoria",value:i.categoria})]})}),a.jsx(q,{open:f,onOpenChange:u,children:a.jsx(G,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:f&&a.jsx(sa,{cuaa:h,editing:d,onClose:()=>u(!1),onSaved:async()=>{u(!1),await T()}},(d==null?void 0:d._id)||"new")})})]})}function sa({cuaa:h,editing:e,onClose:S,onSaved:b}){const[s,C]=c.useState({nome:(e==null?void 0:e.nome)??"",categoria:(e==null?void 0:e.categoria)??"Trattore",marca:(e==null?void 0:e.marca)??"",modello:(e==null?void 0:e.modello)??"",anno:(e==null?void 0:e.anno)??"",targa:(e==null?void 0:e.targa)??"",matricola:(e==null?void 0:e.matricola)??"",potenzaCv:(e==null?void 0:e.potenzaCv)??"",oreLavoro:(e==null?void 0:e.oreLavoro)??"",ultimaRevisione:e!=null&&e.ultimaRevisione?String(e.ultimaRevisione).slice(0,10):"",stato:(e==null?void 0:e.stato)??"attivo",note:(e==null?void 0:e.note)??""}),[x,f]=c.useState(!1),[u,d]=c.useState(null),l=o=>p=>C(g=>({...g,[o]:p.target.value})),i=o=>o===""||o==null?null:Number(o);async function v(){if(d(null),!s.nome.trim()||!s.categoria.trim()){d("Nome e categoria sono obbligatori.");return}f(!0);const o={nome:s.nome.trim(),categoria:s.categoria.trim(),marca:s.marca.trim()||null,modello:s.modello.trim()||null,anno:i(s.anno),targa:s.targa.trim()||null,matricola:s.matricola.trim()||null,potenzaCv:i(s.potenzaCv),oreLavoro:i(s.oreLavoro),ultimaRevisione:s.ultimaRevisione?new Date(s.ultimaRevisione).toISOString():null,
1stato:s.stato,note:s.note.trim()||null};try{e?await w.updateMacchinario(e._id,o):await w.createMacchinario(h,o),await b()}catch(p){d(R(p))}finally{f(!1)}}return a.jsxs(a.Fragment,{children:[a.jsxs(V,{children:[a.jsx($,{children:e?"Modifica macchina":"Nuova macchina"}),a.jsx(J,{children:"I campi contrassegnati con * sono obbligatori."})]}),a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Nome / denominazione *"}),a.jsx(n,{value:s.nome,onChange:l("nome"),placeholder:"es. Trattore aziendale"})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Categoria *"}),a.jsxs(z,{value:s.categoria,onChange:l("categoria"),children:[s.categoria&&!A.includes(s.categoria)&&a.jsx("option",{value:s.categoria,children:s.categoria}),A.map(o=>a.jsx("option",{value:o,children:o},o))]})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Marca"}),a.jsx(n,{value:s.marca,onChange:l("marca"),placeholder:"es. New Holland"})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Modello"}),a.jsx(n,{value:s.modello,onChange:l("modello")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Anno"}),a.jsx(n,{type:"number",min:"1900",max:"2100",step:"1",value:s.anno,onChange:l("anno")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Targa"}),a.jsx(n,{value:s.targa,onChange:l("targa")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Matricola / telaio"}),a.jsx(n,{value:s.matricola,onChange:l("matricola")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Potenza (CV)"}),a.jsx(n,{type:"number",min:"0",step:"1",value:s.potenzaCv,onChange:l("potenzaCv")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Ore di lavoro"}),a.jsx(n,{type:"number",min:"0",step:"1",value:s.oreLavoro,onChange:l("oreLavoro")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Ultima revisione"}),a.jsx(n,{type:"date",value:s.ultimaRevisione,onChange:l("ultimaRevisione")})]}),a.jsxs("div",{children:[a.jsx(t,{className:"mb-1 block",children:"Stato"}),a.jsxs(z,{value:s.stato,onChange:l("stato"),children:[a.jsx("option",{value:"attivo",children:"Attivo"}),a.jsx("option",{value:"dismesso",children:"Dismesso"})]})]}),a.jsxs("div",{className:"sm:col-span-2",children:[a.jsx(t,{className:"mb-1 block",children:"Note"}),a.jsx(n,{value:s.note,onChange:l("note")})]})]}),u&&a.jsx("div",{className:"mt-3 rounded-md bg-red-50 border border-red-200 text-red-700 text-sm p-2",children:u}),a.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[a.jsx(N,{variant:"outline",onClick:S,disabled:x,children:"Annulla"}),a.jsxs(N,{onClick:v,disabled:x,children:[x?a.jsx(_,{className:"h-4 w-4 animate-spin"}):null,e?"Salva modifiche":"Aggiungi macchina"]})]})]})}function Ca(){return a.jsx(aa,{title:"Macchine",icon:U,intro:"Trattori, irroratrici e attrezzature, con revisioni e contaore.",children:h=>a.jsx(ea,{cuaa:h})})}export{Ca as default};

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.