2 lines
7.6 KiB
JavaScript
2 lines
7.6 KiB
JavaScript
import{u as F,C as n,a as c,b as s,c as T}from"./useCategoryDisplay-DtoUGbrc.js";import{r as w,c as j,o as H,i as L,w as d,f as z,g as h,b as e,a as x,af as I,aR as V,d as v,Q as N,t as p,e as R,F as k,k as E,l as U}from"./index-QAlcqU00.js";import{F as Y,a as W}from"./FPPageHeader-CFIwZZgQ.js";const G={class:"p-6"},K={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"},Q={class:"bg-white rounded-lg shadow-sm border border-gray-200 hover:shadow-md hover:border-primary-300 transition-all duration-200 cursor-pointer"},$={class:"p-6"},J={class:"flex items-center mb-4"},q={class:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},X=["d"],Z={class:"text-lg font-semibold text-gray-900"},ee={class:"text-sm text-gray-500"},te={key:0,class:"grid grid-cols-3 gap-4 mt-4 pt-4 border-t border-gray-100"},se={class:"text-center"},oe={class:"text-lg font-semibold text-gray-900"},ae={class:"text-center"},ie={class:"text-lg font-semibold text-green-600"},re={class:"text-center"},le={class:"text-lg font-semibold text-gray-400"},ne={key:1,class:"grid grid-cols-3 gap-4 mt-4 pt-4 border-t border-gray-100"},ce={class:"mt-8 bg-white rounded-lg shadow-sm border border-gray-200 p-6"},de={class:"grid grid-cols-1 md:grid-cols-3 gap-4"},ve={__name:"CategoriesIndexView",setup(me){const m=F(),{getCategoryStats:S}=T(),{addNotification:r}=U(),_=w(!1),y=w(!1),C=w(!1),g=[{type:s.WORK_ORDER,label:c[s.WORK_ORDER],description:n[s.WORK_ORDER],to:"/categories/work-order-categories",color:"#3B82F6",iconPath:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"},{type:s.ASSET,label:c[s.ASSET],description:n[s.ASSET],to:"/categories/asset-categories",color:"#10B981",iconPath:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"},{type:s.PART,label:c[s.PART],description:n[s.PART],to:"/categories/part-categories",color:"#F59E0B",iconPath:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"},{type:s.COST,label:c[s.COST],description:n[s.COST],to:"/categories/cost-categories",color:"#EF4444",iconPath:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1"},{type:s.METER,label:c[s.METER],description:n[s.METER],to:"/categories/meter-categories",color:"#8B5CF6",iconPath:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"},{type:s.PURCHASE_ORDER,label:c[s.PURCHASE_ORDER],description:n[s.PURCHASE_ORDER],to:"/categories/purchase-order-categories",color:"#06B6D4",iconPath:"M3 3h2l.4 2M7 13h10l4-8H5.4m1.6 8L5 3H3m4 10v6a1 1 0 001 1h8a1 1 0 001-1v-6m-9 0h10"}],f=j(()=>{const o={};return g.forEach(t=>{const l=m.getCategoriesByType(t.type);o[t.type]=S(l)}),o}),M=async()=>{_.value=!0;try{const o=g.map(t=>m.initializeWithDefaults(t.type));await Promise.allSettled(o),r({type:"success",title:"Default Categories Initialized",message:"Default categories have been created for all category types"})}catch(o){r({type:"error",title:"Initialization Failed",message:o.message||"Failed to initialize default categories"})}finally{_.value=!1}},O=async()=>{y.value=!0;try{const o=g.map(t=>m.refreshCategories(t.type));await Promise.allSettled(o),r({type:"info",title:"Categories Refreshed",message:"All categories have been refreshed from the server"})}catch(o){r({type:"error",title:"Refresh Failed",message:o.message||"Failed to refresh categories"})}finally{y.value=!1}},P=async()=>{C.value=!0;try{const o={};g.forEach(b=>{const B=m.getCategoriesByType(b.type);o[b.label]=B.map(i=>({Name:i.name,Description:i.description||"",Type:b.label,Color:i.color,Icon:i.icon,Status:i.isActive?"Active":"Inactive","Sort Order":i.sortOrder,"Created At":new Date(i.createdAt).toLocaleDateString(),"Updated At":new Date(i.updatedAt).toLocaleDateString()}))});const l=`all_categories_${new Date().toISOString().split("T")[0]}.json`,a=JSON.stringify(o,null,2),D=new Blob([a],{type:"application/json"}),A=window.URL.createObjectURL(D),u=document.createElement("a");u.href=A,u.download=l,document.body.appendChild(u),u.click(),document.body.removeChild(u),window.URL.revokeObjectURL(A),r({type:"success",title:"Export Complete",message:`All categories exported as ${l}`})}catch(o){r({type:"error",title:"Export Failed",message:o.message||"Failed to export categories"})}finally{C.value=!1}};return H(async()=>{await m.fetchAllCategories()}),(o,t)=>{const l=z("router-link");return h(),L(Y,null,{header:d(()=>[v(W,{title:"Categories Management",description:"Organize and manage different types of categories for your CMMS system",breadcrumbs:[{text:"Settings",to:"/settings"},{text:"Categories",to:null}]})]),default:d(()=>[e("div",G,[e("div",K,[(h(),x(I,null,V(g,a=>v(l,{key:a.type,to:a.to,class:"block"},{default:d(()=>[e("div",Q,[e("div",$,[e("div",J,[e("div",{class:"w-12 h-12 rounded-lg flex items-center justify-center text-white mr-4",style:N({backgroundColor:a.color})},[(h(),x("svg",q,[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:a.iconPath},null,8,X)]))],4),e("div",null,[e("h3",Z,p(a.label),1),e("p",ee,p(a.description),1)])]),f.value[a.type]?(h(),x("div",te,[e("div",se,[e("div",oe,p(f.value[a.type].total),1),t[0]||(t[0]=e("div",{class:"text-xs text-gray-500"},"Total",-1))]),e("div",ae,[e("div",ie,p(f.value[a.type].active),1),t[1]||(t[1]=e("div",{class:"text-xs text-gray-500"},"Active",-1))]),e("div",re,[e("div",le,p(f.value[a.type].inactive),1),t[2]||(t[2]=e("div",{class:"text-xs text-gray-500"},"Inactive",-1))])])):(h(),x("div",ne,t[3]||(t[3]=[e("div",{class:"text-center"},[e("div",{class:"w-8 h-6 bg-gray-200 rounded animate-pulse mx-auto"}),e("div",{class:"text-xs text-gray-500 mt-1"},"Total")],-1),e("div",{class:"text-center"},[e("div",{class:"w-8 h-6 bg-gray-200 rounded animate-pulse mx-auto"}),e("div",{class:"text-xs text-gray-500 mt-1"},"Active")],-1),e("div",{class:"text-center"},[e("div",{class:"w-8 h-6 bg-gray-200 rounded animate-pulse mx-auto"}),e("div",{class:"text-xs text-gray-500 mt-1"},"Inactive")],-1)])))])])]),_:2},1032,["to"])),64))]),e("div",ce,[t[7]||(t[7]=e("h3",{class:"text-lg font-semibold text-gray-900 mb-4"},"Quick Actions",-1)),e("div",de,[v(R(k),{variant:"outline",onClick:M,loading:_.value,class:"justify-center"},{default:d(()=>t[4]||(t[4]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4-4m0 0L8 8m4-4v12"})],-1),E(" Initialize All Defaults ",-1)])),_:1,__:[4]},8,["loading"]),v(R(k),{variant:"outline",onClick:O,loading:y.value,class:"justify-center"},{default:d(()=>t[5]||(t[5]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1),E(" Refresh All Categories ",-1)])),_:1,__:[5]},8,["loading"]),v(R(k),{variant:"outline",onClick:P,loading:C.value,class:"justify-center"},{default:d(()=>t[6]||(t[6]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),E(" Export All Categories ",-1)])),_:1,__:[6]},8,["loading"])])])])]),_:1})}}};export{ve as default};
|