cmms/frontend/dist/assets/TeamsListView-BMyhC_wf.js

2 lines
10 KiB
JavaScript

import{q as J,r as x,c as u,o as K,i as B,w as l,s as O,v as Q,g as m,b as a,d as o,a as k,j as b,ae as X,t as v,e as n,F as c,k as h,ai as Y}from"./index-BUdRbiwj.js";import{F as Z,a as ee}from"./FPPageHeader-CTG2L28r.js";import{F as j}from"./FPInput-CzR_dWoe.js";import{F as ae}from"./FPStats-BGfZcDZc.js";import{F as te}from"./FPTable-CU8C_NYc.js";import{F as se}from"./FPModal-DWGF1LV8.js";import{F as H}from"./FPBadge-BKY5dPnL.js";import{u as le,a as oe}from"./roles-f1XEGBFr.js";import"./FPCard-qHzcEQAE.js";const ne={class:"p-6"},re={key:0,class:"flex justify-center py-12"},ie={key:1,class:"bg-red-50 border border-red-200 rounded-lg p-6 mb-6"},de={class:"flex items-start"},ue={class:"text-red-700 mb-4"},me={class:"flex items-center"},ve={class:"font-medium text-gray-900"},ce={class:"text-sm text-gray-600"},pe={class:"text-sm text-gray-900"},ge={class:"flex items-center space-x-2"},fe={key:0},ke={key:0},be={key:0},he={key:0,class:"space-y-6"},ye={class:"grid grid-cols-1 gap-4"},we={key:0},xe={class:"text-sm text-gray-900"},Ce={class:"flex justify-end space-x-2"},He={__name:"TeamsListView",setup(_e){O(),Q();const z=J(),r=le(),y=oe(),p=x(!1),d=x("view"),g=x(null),M=x(window.innerWidth<768),i=x({name:"",description:"",enabled:!0}),w=x(!1),T=u(()=>r.loading),P=u(()=>r.error);u(()=>y.userPermissions.canViewUsers);const E=u(()=>y.userPermissions.canCreateUsers);u(()=>y.userPermissions.canEditUsers),u(()=>y.userPermissions.canDeleteUsers);const C=u(()=>y.userPermissions.canEditUsers),U=u(()=>{var e,s;const t=Array.isArray((e=r.teams)==null?void 0:e.content)?r.teams.content:[];return[{name:"Total Teams",value:((s=r.teams)==null?void 0:s.totalElements)||t.length,variant:"primary"},{name:"Active",value:t.filter(f=>f.enabled).length,variant:"success"},{name:"Inactive",value:t.filter(f=>!f.enabled).length,variant:"error"}]}),_=u(()=>{var t;return Array.isArray((t=r.teams)==null?void 0:t.content)?r.teams.content:[]}),A=u(()=>{var t,e,s;return{currentPage:(((t=r.teams)==null?void 0:t.currentPage)||0)+1,total:((e=r.teams)==null?void 0:e.totalElements)||0,pageSize:((s=r.teams)==null?void 0:s.pageSize)||10}}),R=[{key:"name",label:"Team",sortable:!0},{key:"members",label:"Members",sortable:!0},{key:"status",label:"Status",sortable:!0}],S=async()=>{try{console.log("Initializing teams data..."),z.user&&y.setCurrentUser(z.user),await r.searchTeams(),console.log("Teams data loaded successfully")}catch(t){console.error("Failed to initialize teams data:",t)}},F=async()=>{console.log("Refreshing teams data..."),await r.searchTeams()},D=async()=>{try{await S()}catch(t){console.error("Retry failed:",t)}},L=async({column:t,direction:e})=>{console.log("Sort:",t,e)},N=async t=>{console.log("Page change:",t)},I=t=>{V(t)},$=()=>{i.value={name:"",description:"",enabled:!0},g.value=null,d.value="create",p.value=!0},V=t=>{g.value={...t},i.value={...t},d.value="view",p.value=!0},q=t=>{C.value&&(g.value={...t},i.value={...t},d.value="edit",p.value=!0)},W=t=>{C.value&&console.log("Manage team members:",t.name)},G=async()=>{try{w.value=!0,d.value==="create"?(console.log("Creating team:",i.value),await r.createTeam(i.value)):(console.log("Updating team:",i.value),await r.updateTeam(g.value.id,i.value)),p.value=!1,await F()}catch(t){console.error("Failed to save team:",t)}finally{w.value=!1}};return K(async()=>{await S()}),(t,e)=>(m(),B(Z,null,{header:l(()=>[o(ee,{title:"Teams",description:"Manage teams and team assignments",breadcrumbs:[{text:"People",to:"/people"},{text:"Teams",to:null}]},{actions:l(()=>[o(n(c),{variant:"outline",size:"sm",onClick:F},{default:l(()=>e[4]||(e[4]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("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),h(" Refresh ",-1)])),_:1,__:[4]}),o(n(c),{variant:"primary",size:"sm",onClick:$,disabled:!E.value},{default:l(()=>e[5]||(e[5]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),h(" Create Team ",-1)])),_:1,__:[5]},8,["disabled"])]),stats:l(()=>[o(n(ae),{stats:U.value},null,8,["stats"])]),_:1})]),default:l(()=>[a("div",ne,[T.value&&!_.value.length?(m(),k("div",re,e[6]||(e[6]=[a("div",{class:"text-center"},[a("div",{class:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600 mx-auto mb-4"}),a("p",{class:"text-gray-600"},"Loading teams...")],-1)]))):P.value&&!_.value.length?(m(),k("div",ie,[a("div",de,[e[9]||(e[9]=a("svg",{class:"w-6 h-6 text-red-400 mr-3 mt-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.728-.833-2.498 0L4.316 16.5c-.77.833.192 2.5 1.732 2.5z"})],-1)),a("div",null,[e[8]||(e[8]=a("h3",{class:"text-lg font-medium text-red-800 mb-2"},"Failed to Load Teams",-1)),a("p",ue,v(P.value),1),o(n(c),{variant:"outline",size:"sm",onClick:D},{default:l(()=>e[7]||(e[7]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("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),h(" Retry ",-1)])),_:1,__:[7]})])])])):b("",!0),X(a("div",null,[o(n(te),{columns:R,data:_.value,loading:T.value,pagination:A.value,"empty-message":"No teams found",onSortChange:L,onPageChange:N,onRowClick:I},{"column-name":l(({row:s})=>[a("div",me,[e[10]||(e[10]=a("div",{class:"w-10 h-10 rounded-full bg-primary-100 flex items-center justify-center mr-3"},[a("svg",{class:"w-5 h-5 text-primary-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"})])],-1)),a("div",null,[a("h4",ve,v(s.name),1),a("p",ce,v(s.description||"No description"),1)])])]),"column-members":l(({row:s})=>[a("div",pe,v(s.memberCount||0),1)]),"column-status":l(({row:s})=>[o(n(H),{variant:s.enabled?"success":"error"},{default:l(()=>[h(v(s.enabled?"Active":"Inactive"),1)]),_:2},1032,["variant"])]),"row-actions":l(({row:s})=>[a("div",ge,[o(n(c),{variant:"ghost",size:"sm",onClick:f=>V(s),title:"View Details"},{default:l(()=>[e[11]||(e[11]=a("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})],-1)),M.value?b("",!0):(m(),k("span",fe,"View"))]),_:2,__:[11]},1032,["onClick"]),o(n(c),{variant:"ghost",size:"sm",onClick:f=>q(s),title:"Edit Team",disabled:!C.value},{default:l(()=>[e[12]||(e[12]=a("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})],-1)),M.value?b("",!0):(m(),k("span",ke,"Edit"))]),_:2,__:[12]},1032,["onClick","disabled"]),o(n(c),{variant:"ghost",size:"sm",onClick:f=>W(s),title:"Manage Members",disabled:!C.value},{default:l(()=>[e[13]||(e[13]=a("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"})],-1)),M.value?b("",!0):(m(),k("span",be,"Members"))]),_:2,__:[13]},1032,["onClick","disabled"])])]),_:1},8,["data","loading","pagination"])],512),[[Y,!T.value||_.value.length]])]),o(n(se),{modelValue:p.value,"onUpdate:modelValue":e[3]||(e[3]=s=>p.value=s),title:d.value==="view"?"Team Details":d.value==="create"?"Create Team":"Edit Team",size:"lg"},{footer:l(()=>{var s;return[a("div",Ce,[o(n(c),{variant:"outline",onClick:e[2]||(e[2]=f=>p.value=!1),disabled:w.value},{default:l(()=>[h(v(d.value==="view"?"Close":"Cancel"),1)]),_:1},8,["disabled"]),d.value!=="view"?(m(),B(n(c),{key:0,variant:"primary",onClick:G,disabled:!((s=i.value.name)!=null&&s.trim())||w.value,loading:w.value},{default:l(()=>[h(v(w.value?"Saving...":d.value==="create"?"Create Team":"Save Changes"),1)]),_:1},8,["disabled","loading"])):b("",!0)])]}),default:l(()=>[g.value||d.value==="create"?(m(),k("div",he,[a("div",ye,[a("div",null,[e[14]||(e[14]=a("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Team Name",-1)),o(n(j),{modelValue:i.value.name,"onUpdate:modelValue":e[0]||(e[0]=s=>i.value.name=s),readonly:d.value==="view",placeholder:"Enter team name"},null,8,["modelValue","readonly"])]),a("div",null,[e[15]||(e[15]=a("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Description",-1)),o(n(j),{modelValue:i.value.description,"onUpdate:modelValue":e[1]||(e[1]=s=>i.value.description=s),readonly:d.value==="view",placeholder:"Enter team description"},null,8,["modelValue","readonly"])]),a("div",null,[e[16]||(e[16]=a("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Status",-1)),o(n(H),{variant:i.value.enabled?"success":"error"},{default:l(()=>[h(v(i.value.enabled?"Active":"Inactive"),1)]),_:1},8,["variant"])]),d.value==="view"&&g.value?(m(),k("div",we,[e[17]||(e[17]=a("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Members",-1)),a("div",xe,v(g.value.memberCount||0)+" member(s) ",1)])):b("",!0)])])):b("",!0)]),_:1},8,["modelValue","title"])]),_:1}))}};export{He as default};