Files
yakpanel-core/YakPanel-server/frontend/dist/assets/NodePage-DOIEhdrc.js
2026-04-07 10:03:25 +05:30

2 lines
5.3 KiB
JavaScript

import{r,j as e,M as c,a3 as R}from"./index-Cvh4tLHo.js";import{M as h}from"./Modal-CCihVZTY.js";import{A as B}from"./AdminAlert-Bt3L8_zJ.js";import{A as u}from"./AdminButton-BKglG8kI.js";import{A as D}from"./AdminTable-BQ5Lf7EC.js";import{E as I}from"./EmptyState-D6lCh4WN.js";import{P as v}from"./PageHeader-D6k34vvM.js";function O(n){if(!n||n<0)return"—";const m=Math.floor(n/1e3);if(m<60)return`${m}s`;const o=Math.floor(m/60);return o<60?`${o}m`:`${Math.floor(o/60)}h`}function q(n){return n?(n/1024/1024).toFixed(1)+" MB":"—"}function P({show:n}){return n?e.jsx("span",{className:"spinner-border spinner-border-sm",role:"status"}):null}function Q(){const[n,m]=r.useState([]),[o,p]=r.useState(null),[k,f]=r.useState(!0),[N,i]=r.useState(""),[d,a]=r.useState(null),[C,x]=r.useState(!1),[j,b]=r.useState(""),[g,y]=r.useState(""),[S,A]=r.useState(!1),l=()=>{f(!0),Promise.all([c("/node/processes"),c("/node/version")]).then(([s,t])=>{m(s.processes||[]),p(t.version||null),i(s.error||t.error||"")}).catch(s=>i(s.message)).finally(()=>f(!1))};r.useEffect(()=>{l()},[]);const M=s=>{a(s),c(`/node/${s}/start`,{method:"POST"}).then(l).catch(t=>i(t.message)).finally(()=>a(null))},E=s=>{a(s),c(`/node/${s}/stop`,{method:"POST"}).then(l).catch(t=>i(t.message)).finally(()=>a(null))},$=s=>{a(s),c(`/node/${s}/restart`,{method:"POST"}).then(l).catch(t=>i(t.message)).finally(()=>a(null))},T=s=>{s.preventDefault(),j.trim()&&(A(!0),R(j.trim(),g.trim()||void 0).then(()=>{x(!1),b(""),y(""),l()}).catch(t=>i(t.message)).finally(()=>A(!1)))},F=(s,t)=>{confirm(`Delete PM2 process "${t}"?`)&&(a(s),c(`/node/${s}`,{method:"DELETE"}).then(l).catch(L=>i(L.message)).finally(()=>a(null)))},w=s=>(s==null?void 0:s.toLowerCase())==="online"||(s==null?void 0:s.toLowerCase())==="launching";return k?e.jsxs(e.Fragment,{children:[e.jsx(v,{title:"Node.js"}),e.jsx("p",{className:"text-secondary",children:"Loading…"})]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{title:"Node.js",actions:e.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-2",children:[o?e.jsxs("span",{className:"small text-secondary me-2",children:["Node: ",o]}):null,e.jsxs(u,{variant:"primary",size:"sm",onClick:()=>x(!0),children:[e.jsx("i",{className:"ti ti-plus me-1","aria-hidden":!0}),"Add Process"]}),e.jsxs(u,{variant:"secondary",size:"sm",onClick:l,children:[e.jsx("i",{className:"ti ti-rotate-clockwise me-1","aria-hidden":!0}),"Refresh"]})]})}),e.jsxs(h,{show:C,onHide:()=>x(!1),centered:!0,children:[e.jsx(h.Header,{closeButton:!0,children:e.jsx(h.Title,{children:"Add PM2 Process"})}),e.jsxs("form",{onSubmit:T,children:[e.jsxs(h.Body,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Script path"}),e.jsx("input",{value:j,onChange:s=>b(s.target.value),placeholder:"/www/wwwroot/app.js",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-0",children:[e.jsx("label",{className:"form-label",children:"Name (optional)"}),e.jsx("input",{value:g,onChange:s=>y(s.target.value),placeholder:"myapp",className:"form-control"})]})]}),e.jsxs(h.Footer,{children:[e.jsx(u,{type:"button",variant:"secondary",onClick:()=>x(!1),children:"Cancel"}),e.jsx(u,{type:"submit",variant:"primary",disabled:S,children:S?"Starting…":"Start"})]})]})]}),N?e.jsx(B,{variant:"warning",className:"mb-3",children:N}):null,e.jsxs("div",{className:"alert alert-secondary small mb-3",children:["PM2 process manager. Install with: ",e.jsx("code",{className:"font-monospace",children:"npm install -g pm2"})]}),e.jsx("div",{className:"card",children:e.jsxs(D,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"PID"}),e.jsx("th",{children:"Uptime"}),e.jsx("th",{children:"Memory"}),e.jsx("th",{className:"text-end",children:"Actions"})]})}),e.jsx("tbody",{children:n.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-0",children:e.jsx(I,{title:"No PM2 processes",description:'Click "Add Process" or run pm2 start app.js on the server.'})})}):n.map(s=>e.jsxs("tr",{children:[e.jsx("td",{className:"font-monospace",children:s.name}),e.jsx("td",{children:e.jsx("span",{className:w(s.status)?"text-success":"text-secondary",children:s.status})}),e.jsx("td",{children:s.pid||"—"}),e.jsx("td",{children:O(s.uptime)}),e.jsx("td",{children:q(s.memory)}),e.jsx("td",{className:"text-end",children:e.jsxs("span",{className:"d-inline-flex gap-1 justify-content-end",children:[w(s.status)?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn btn-link btn-sm text-warning p-1",title:"Restart",disabled:d===s.id,onClick:()=>$(s.id),children:d===s.id?e.jsx(P,{show:!0}):e.jsx("i",{className:"ti ti-rotate-clockwise","aria-hidden":!0})}),e.jsx("button",{type:"button",className:"btn btn-link btn-sm text-danger p-1",title:"Stop",disabled:d===s.id,onClick:()=>E(s.id),children:e.jsx("i",{className:"ti ti-square","aria-hidden":!0})})]}):e.jsx("button",{type:"button",className:"btn btn-link btn-sm text-success p-1",title:"Start",disabled:d===s.id,onClick:()=>M(s.id),children:d===s.id?e.jsx(P,{show:!0}):e.jsx("i",{className:"ti ti-player-play","aria-hidden":!0})}),e.jsx("button",{type:"button",className:"btn btn-link btn-sm text-secondary p-1",title:"Delete",disabled:d===s.id,onClick:()=>F(s.id,s.name),children:e.jsx("i",{className:"ti ti-trash","aria-hidden":!0})})]})})]},s.id))})]})})]})}export{Q as NodePage};