Files
Depl0y-Custom/src/frontend/dist/assets/VirtualMachines-B0qwUkBJ.js
T
Alphaeus Mote be6d358086 Initial Commit
2025-11-19 08:09:34 -05:00

2 lines
8.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{_ as O,g as K,c as r,o as a,a as s,d as f,h as P,i as z,b as v,m as B,t as i,F as U,p as j,e as E,v as G,q as W,w as H,s as J,u as Q,x as X,r as y,j as Y,y as Z,k as $,l as D}from"./index-DpP9cWht.js";const tt={name:"VirtualMachines",setup(){const h=J(),e=Q(),c=X(),t=y([]),F=y(!1),C=y("vmid"),b=y("asc"),M=y(h.query.status||null),k=y(!1),u=y(null),V=y(""),m=async()=>{F.value=!0;try{const l=await D.vms.list();t.value=l.data,g()}catch(l){console.error("Failed to fetch VMs:",l)}finally{F.value=!1}},o=l=>{C.value===l?b.value=b.value==="asc"?"desc":"asc":(C.value=l,b.value="asc"),g()},g=()=>{t.value.sort((l,d)=>{let n=l[C.value],w=d[C.value];return typeof n=="string"&&(n=n.toLowerCase(),w=w.toLowerCase()),b.value==="asc"?n>w?1:n<w?-1:0:n<w?1:n>w?-1:0})},x=async(l,d)=>{try{await D.vms.startByVmid(l,d),c.success(`VM ${l} started successfully`),setTimeout(m,1e3)}catch(n){console.error("Failed to start VM:",n),c.error("Failed to start VM")}},T=async(l,d)=>{try{await D.vms.stopByVmid(l,d),c.success(`VM ${l} stopped successfully`),setTimeout(m,1e3)}catch(n){console.error("Failed to stop VM:",n),c.error("Failed to stop VM")}},_=async(l,d)=>{if(confirm(`Are you sure you want to power off VM ${l}? This is equivalent to pulling the power plug.`))try{await D.vms.powerOffByVmid(l,d),c.success(`VM ${l} powered off successfully`),setTimeout(m,1e3)}catch(n){console.error("Failed to power off VM:",n),c.error("Failed to power off VM")}},I=async(l,d)=>{try{await D.vms.restartByVmid(l,d),c.success(`VM ${l} restarting...`),setTimeout(m,1e3)}catch(n){console.error("Failed to restart VM:",n),c.error("Failed to restart VM")}},S=l=>{u.value=l,V.value="",k.value=!0},p=()=>{k.value=!1,u.value=null,V.value=""},N=async()=>{var l,d;if(V.value!==String(u.value.vmid)){c.error("VM ID confirmation does not match");return}try{await D.vms.deleteByVmid(u.value.vmid,u.value.node),c.success(`VM ${u.value.vmid} deleted successfully`),p(),m()}catch(n){console.error("Failed to delete VM:",n),c.error(`Failed to delete VM: ${((d=(l=n.response)==null?void 0:l.data)==null?void 0:d.detail)||n.message}`)}},L=l=>{if(!l)return"0 B";const d=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(l)/Math.log(1024));return Math.round(l/Math.pow(1024,n)*100)/100+" "+d[n]},R=l=>({running:"badge-success",stopped:"badge-danger",paused:"badge-warning",suspended:"badge-warning",unknown:"badge-secondary"})[l.toLowerCase()]||"badge-info",q=Y(()=>M.value?t.value.filter(l=>l.status.toLowerCase()===M.value.toLowerCase()):t.value),A=()=>{M.value=null,e.push("/vms")};return Z(()=>h.query.status,l=>{M.value=l||null}),$(()=>{m();const l=setInterval(m,3e4);return()=>clearInterval(l)}),{vms:t,loading:F,sortField:C,sortDirection:b,statusFilter:M,filteredVMs:q,showDeleteConfirmModal:k,vmToDelete:u,deleteConfirmInput:V,sortBy:o,startVM:x,stopVM:T,powerOffVM:_,restartVM:I,showDeleteModal:S,closeDeleteModal:p,deleteVM:N,formatBytes:L,getStatusBadgeClass:R,clearFilter:A}}},et={class:"vms-page"},st={class:"card"},ot={class:"card-header"},lt={key:0,class:"filter-bar"},nt={class:"filter-info"},rt={class:"filter-count"},at={key:1,class:"loading-spinner"},it={key:2,class:"text-center text-muted"},dt={key:3,class:"text-center text-muted"},ct={key:4,class:"table-container"},ut={class:"table"},mt={key:0,class:"sort-indicator"},ft={key:0,class:"sort-indicator"},Mt={key:0,class:"sort-indicator"},vt={key:0,class:"sort-indicator"},yt={class:"badge badge-info"},bt={class:"text-sm"},Vt={class:"flex gap-1"},gt=["onClick"],Ct=["onClick"],kt=["onClick"],wt=["onClick"],Dt=["onClick"],Ft={class:"modal-header"},ht={class:"modal-body"},pt={class:"text-danger mb-1"},Bt={class:"form-group"},xt=["placeholder"],Tt={class:"modal-footer"},_t=["disabled"];function It(h,e,c,t,F,C){var M,k,u,V,m;const b=K("router-link");return a(),r("div",et,[s("div",st,[s("div",ot,[e[14]||(e[14]=s("h3",null,"Virtual Machines",-1)),P(b,{to:"/vms/create",class:"btn btn-primary"},{default:z(()=>[...e[13]||(e[13]=[v("+ Create VM",-1)])]),_:1})]),t.statusFilter?(a(),r("div",lt,[s("div",nt,[e[15]||(e[15]=s("span",{class:"filter-label"},"Filtered by status:",-1)),s("span",{class:B(["badge",t.getStatusBadgeClass(t.statusFilter)])},i(t.statusFilter),3),s("span",rt,"("+i(t.filteredVMs.length)+" VMs)",1)]),s("button",{onClick:e[0]||(e[0]=(...o)=>t.clearFilter&&t.clearFilter(...o)),class:"btn btn-sm btn-secondary"}," Clear Filter ")])):f("",!0),t.loading?(a(),r("div",at)):t.filteredVMs.length===0&&t.vms.length===0?(a(),r("div",it,[...e[16]||(e[16]=[s("p",null,"No virtual machines yet.",-1),s("p",{class:"text-sm"},"Create your first VM to get started.",-1)])])):t.filteredVMs.length===0&&t.statusFilter?(a(),r("div",dt,[s("p",null,"No "+i(t.statusFilter)+" VMs found.",1),s("button",{onClick:e[1]||(e[1]=(...o)=>t.clearFilter&&t.clearFilter(...o)),class:"btn btn-sm btn-secondary mt-1"}," Show All VMs ")])):(a(),r("div",ct,[s("table",ut,[s("thead",null,[s("tr",null,[s("th",{onClick:e[2]||(e[2]=o=>t.sortBy("vmid")),class:"sortable"},[e[17]||(e[17]=v(" VMID ",-1)),t.sortField==="vmid"?(a(),r("span",mt,i(t.sortDirection==="asc"?"▲":"▼"),1)):f("",!0)]),s("th",{onClick:e[3]||(e[3]=o=>t.sortBy("name")),class:"sortable"},[e[18]||(e[18]=v(" Name ",-1)),t.sortField==="name"?(a(),r("span",ft,i(t.sortDirection==="asc"?"▲":"▼"),1)):f("",!0)]),s("th",{onClick:e[4]||(e[4]=o=>t.sortBy("node")),class:"sortable"},[e[19]||(e[19]=v(" Node ",-1)),t.sortField==="node"?(a(),r("span",Mt,i(t.sortDirection==="asc"?"▲":"▼"),1)):f("",!0)]),e[21]||(e[21]=s("th",null,"Resources",-1)),s("th",{onClick:e[5]||(e[5]=o=>t.sortBy("status")),class:"sortable"},[e[20]||(e[20]=v(" Status ",-1)),t.sortField==="status"?(a(),r("span",vt,i(t.sortDirection==="asc"?"▲":"▼"),1)):f("",!0)]),e[22]||(e[22]=s("th",null,"Actions",-1))])]),s("tbody",null,[(a(!0),r(U,null,j(t.filteredVMs,o=>(a(),r("tr",{key:o.vmid},[s("td",null,[s("strong",null,i(o.vmid),1)]),s("td",null,i(o.name),1),s("td",null,[s("span",yt,i(o.node),1)]),s("td",bt,i(o.cpus)+" CPU / "+i(t.formatBytes(o.maxmem))+" RAM / "+i(t.formatBytes(o.maxdisk))+" Disk ",1),s("td",null,[s("span",{class:B(["badge",t.getStatusBadgeClass(o.status)])},i(o.status),3)]),s("td",null,[s("div",Vt,[o.status==="running"?(a(),r("button",{key:0,onClick:g=>t.stopVM(o.vmid,o.node),class:"btn btn-warning btn-sm"}," Stop ",8,gt)):f("",!0),o.status==="running"?(a(),r("button",{key:1,onClick:g=>t.restartVM(o.vmid,o.node),class:"btn btn-info btn-sm"}," Restart ",8,Ct)):f("",!0),o.status==="running"?(a(),r("button",{key:2,onClick:g=>t.powerOffVM(o.vmid,o.node),class:"btn btn-danger btn-sm"}," Power Off ",8,kt)):f("",!0),o.status==="stopped"?(a(),r("button",{key:3,onClick:g=>t.startVM(o.vmid,o.node),class:"btn btn-primary btn-sm"}," Start ",8,wt)):f("",!0),s("button",{onClick:g=>t.showDeleteModal(o),class:"btn btn-danger btn-sm",title:"Delete VM"}," Delete ",8,Dt)])])]))),128))])])]))]),t.showDeleteConfirmModal?(a(),r("div",{key:0,class:"modal-overlay",onClick:e[12]||(e[12]=(...o)=>t.closeDeleteModal&&t.closeDeleteModal(...o))},[s("div",{class:"modal-content",onClick:e[11]||(e[11]=H(()=>{},["stop"]))},[s("div",Ft,[e[23]||(e[23]=s("h3",null,"Confirm VM Deletion",-1)),s("button",{onClick:e[6]||(e[6]=(...o)=>t.closeDeleteModal&&t.closeDeleteModal(...o)),class:"btn-close"},"×")]),s("div",ht,[s("p",pt,[e[24]||(e[24]=s("strong",null,"Warning:",-1)),v(" This will permanently delete VM "+i((M=t.vmToDelete)==null?void 0:M.vmid)+" ("+i((k=t.vmToDelete)==null?void 0:k.name)+") from Proxmox. ",1)]),e[27]||(e[27]=s("p",{class:"text-muted mb-2"},"This action cannot be undone.",-1)),s("div",Bt,[s("label",null,[e[25]||(e[25]=v("Type the VM ID ",-1)),s("strong",null,i((u=t.vmToDelete)==null?void 0:u.vmid),1),e[26]||(e[26]=v(" to confirm:",-1))]),E(s("input",{"onUpdate:modelValue":e[7]||(e[7]=o=>t.deleteConfirmInput=o),type:"text",class:"form-control",placeholder:`Type ${(V=t.vmToDelete)==null?void 0:V.vmid} to confirm`,onKeyup:e[8]||(e[8]=W((...o)=>t.deleteVM&&t.deleteVM(...o),["enter"]))},null,40,xt),[[G,t.deleteConfirmInput]])])]),s("div",Tt,[s("button",{onClick:e[9]||(e[9]=(...o)=>t.closeDeleteModal&&t.closeDeleteModal(...o)),class:"btn btn-secondary"},"Cancel"),s("button",{onClick:e[10]||(e[10]=(...o)=>t.deleteVM&&t.deleteVM(...o)),class:"btn btn-danger",disabled:t.deleteConfirmInput!==String((m=t.vmToDelete)==null?void 0:m.vmid)}," Delete VM ",8,_t)])])])):f("",!0)])}const Nt=O(tt,[["render",It],["__scopeId","data-v-872f930a"]]);export{Nt as default};