cmms/frontend/dist/assets/useUniversalCalendar-2CJQga...

4 lines
5.6 KiB
JavaScript

import{u as $}from"./useWorkOrders-B61P5JA7.js";import{u as k,a as H}from"./usePreventiveMaintenanceDisplay-Bhncwa9c.js";import{r as a,c as s}from"./index-BUdRbiwj.js";function K(){const d=k(),{workOrders:R,searchWorkOrders:P}=$(),{formatFrequency:w}=H(),F=a(new Date),A=a("month"),u=a(null),D=a(!1),i=a(!1),O={WORK_ORDER:{label:"Work Order",color:"#3B82F6",icon:"work-order",borderColor:"#2563EB"},PREVENTIVE_MAINTENANCE:{label:"Preventive Maintenance",color:"#10B981",icon:"maintenance",borderColor:"#059669"},ASSET_INSPECTION:{label:"Asset Inspection",color:"#F59E0B",icon:"inspection",borderColor:"#D97706"},SCHEDULED_DOWNTIME:{label:"Scheduled Downtime",color:"#EF4444",icon:"downtime",borderColor:"#DC2626"}},E=(e=[])=>e.filter(t=>t.dueDate||t.scheduledDate).map(t=>{var n,o;return{id:`wo-${t.id}`,title:t.title||`Work Order #${t.workOrderId}`,start:new Date(t.dueDate||t.scheduledDate),end:t.estimatedDuration?new Date(new Date(t.dueDate||t.scheduledDate).getTime()+t.estimatedDuration*6e4):new Date(new Date(t.dueDate||t.scheduledDate).getTime()+60*6e4),backgroundColor:C(t),borderColor:x(t),textColor:"#FFFFFF",extendedProps:{type:"WORK_ORDER",originalData:t,status:t.status,priority:t.priority,assignedTo:t.assignedTo,description:t.description,location:(n=t.location)==null?void 0:n.name,asset:(o=t.asset)==null?void 0:o.name}}}),p=(e=[])=>e.filter(t=>t.nextDue&&t.status==="ACTIVE").map(t=>({id:`pm-${t.id}`,title:t.name,start:new Date(t.nextDue),end:t.estimatedDuration?new Date(new Date(t.nextDue).getTime()+t.estimatedDuration*6e4):new Date(new Date(t.nextDue).getTime()+60*6e4),backgroundColor:g(t),borderColor:h(t),textColor:"#FFFFFF",extendedProps:{type:"PREVENTIVE_MAINTENANCE",originalData:t,priority:t.priority,frequency:w(t.frequency,t.frequencyValue),description:t.description,instructions:t.instructions,assetName:t.assetName||t.asset,estimatedDuration:t.estimatedDuration}})),C=e=>e.priority==="CRITICAL"?"#DC2626":{OPEN:"#3B82F6",IN_PROGRESS:"#F59E0B",ON_HOLD:"#EF4444",COMPLETED:"#10B981",CANCELLED:"#6B7280"}[e.status]||"#3B82F6",x=e=>e.priority==="CRITICAL"?"#B91C1C":{OPEN:"#2563EB",IN_PROGRESS:"#D97706",ON_HOLD:"#DC2626",COMPLETED:"#059669",CANCELLED:"#4B5563"}[e.status]||"#2563EB",g=e=>({LOW:"#10B981",MEDIUM:"#3B82F6",HIGH:"#F59E0B",CRITICAL:"#EF4444"})[e.priority]||"#10B981",h=e=>({LOW:"#059669",MEDIUM:"#2563EB",HIGH:"#D97706",CRITICAL:"#DC2626"})[e.priority]||"#059669",r=s(()=>{const e=E(R.value),t=p(d.schedules);return[...e,...t].sort((n,o)=>new Date(n.start)-new Date(o.start))}),m=e=>{const t=new Date(e).toDateString();return r.value.filter(n=>new Date(n.start).toDateString()===t)},l=(e,t)=>{const n=new Date(e),o=new Date(t);return r.value.filter(c=>{const M=new Date(c.start);return M>=n&&M<=o})},v=s(()=>{const e=new Date,t=new Date(e.getTime()+7*24*60*60*1e3);return l(e,t).slice(0,10)}),I=s(()=>m(new Date)),y=s(()=>{const e=new Date;return r.value.filter(t=>new Date(t.start)<e&&!B(t))}),B=e=>e.extendedProps.type==="WORK_ORDER"?e.extendedProps.status==="COMPLETED":!1,L=(e="month")=>({headerToolbar:{left:"prev,next today",center:"title",right:"dayGridMonth,timeGridWeek,timeGridDay,listWeek"},initialView:b(e),height:"auto",eventDisplay:"block",dayMaxEvents:3,moreLinkClick:"popover",nowIndicator:!0,eventClick:T,dateClick:N,slotMinTime:"06:00:00",slotMaxTime:"22:00:00",businessHours:{daysOfWeek:[1,2,3,4,5],startTime:"08:00",endTime:"17:00"}}),b=e=>({month:"dayGridMonth",week:"timeGridWeek",day:"timeGridDay",list:"listWeek"})[e]||"dayGridMonth",T=e=>{u.value={...e.event.extendedProps,title:e.event.title,start:e.event.start,end:e.event.end,id:e.event.id},D.value=!0},N=e=>{console.log("Date clicked:",e.date)},S=async(e,t)=>{i.value=!0;try{await P({filterFields:[{field:"dueDate",operation:"BETWEEN",values:[e.toISOString(),t.toISOString()]}]}),await d.fetchSchedules({filters:{nextDue:{gte:e.toISOString(),lte:t.toISOString()}}})}catch(n){console.error("Failed to load calendar data:",n)}finally{i.value=!1}},W=async()=>{const e=new Date,t=new Date(e.getFullYear(),e.getMonth()-1,1),n=new Date(e.getFullYear(),e.getMonth()+2,0);await S(t,n)},V=s(()=>{const e=r.value;return{total:e.length,workOrders:e.filter(t=>t.extendedProps.type==="WORK_ORDER").length,preventiveMaintenance:e.filter(t=>t.extendedProps.type==="PREVENTIVE_MAINTENANCE").length,upcoming:v.value.length,overdue:y.value.length,today:I.value.length}}),G=(e="csv",t=null,n=null)=>{let o=r.value;switch(t&&n&&(o=l(t,n)),e){case"csv":return f(o);case"json":return JSON.stringify(o,null,2);case"ics":return _(o);default:return f(o)}},f=e=>{const t=["Title","Type","Start","End","Priority","Status","Description"],n=e.map(o=>[o.title,o.extendedProps.type,o.start.toISOString(),o.end.toISOString(),o.extendedProps.priority||"N/A",o.extendedProps.status||"N/A",o.extendedProps.description||""]);return[t,...n].map(o=>o.map(c=>`"${c}"`).join(",")).join(`
`)},_=e=>{const t=["BEGIN:VCALENDAR","VERSION:2.0","PRODID:-//CMMS//Calendar//EN","CALSCALE:GREGORIAN"];return e.forEach(n=>{t.push("BEGIN:VEVENT",`DTSTART:${n.start.toISOString().replace(/[:-]/g,"").split(".")[0]}Z`,`DTEND:${n.end.toISOString().replace(/[:-]/g,"").split(".")[0]}Z`,`SUMMARY:${n.title}`,`DESCRIPTION:${n.extendedProps.description||""}`,`UID:${n.id}@cmms.local`,"END:VEVENT")}),t.push("END:VCALENDAR"),t.join(`\r
`)};return{currentDate:F,currentView:A,selectedEvent:u,showEventModal:D,loading:i,allCalendarEvents:r,upcomingEvents:v,todaysEvents:I,overdueEvents:y,eventStatistics:V,eventTypes:O,getEventsForDate:m,getEventsForDateRange:l,getCalendarConfig:L,loadCalendarData:S,refreshCalendarData:W,handleEventClick:T,handleDateClick:N,exportCalendarEvents:G,convertWorkOrdersToEvents:E,convertPMSchedulesToEvents:p,getWorkOrderColor:C,getPMColor:g}}export{K as u};