This change adds a single page application front-end to GARM. It uses a generated REST client, built from the swagger definitions, the websocket interface for live updates of entities and eager loading of everything except runners, as users may have many runners and we don't want to load hundreds of runners in memory. Proper pagination should be implemented in the API, in future commits, to avoid loading lots of elements for no reason. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
1 line
7.7 KiB
JavaScript
1 line
7.7 KiB
JavaScript
import"../chunks/DsnmJJEf.js";import{i as Le}from"../chunks/B3Pzt0F_.js";import{p as Ne,o as We,A as qe,l as He,a as je,f as A,h as Ge,b as M,t as q,c as x,d as Re,g as e,m as l,s as o,u as s,$ as Ve,j as f,r as g,k as d,v as le,y as Je,B as de,q as m,n as Ke}from"../chunks/D8EpLgQ1.js";import{i as h,s as Qe,a as Xe}from"../chunks/5WA7h8uK.js";import{c as Ye,g as _}from"../chunks/CiE1LlKV.js";import{p as Ze}from"../chunks/C41YH50Q.js";import{g as ce}from"../chunks/CTf6mQoE.js";import{b as H}from"../chunks/CoIRRsD9.js";import{U as et}from"../chunks/CclkODgu.js";import{D as ue}from"../chunks/KQ2xQpA3.js";import{E as tt,P as at,a as nt}from"../chunks/BmGWMSQm.js";import{D as ot,I as rt}from"../chunks/DDhBTdDt.js";import{g as fe}from"../chunks/BGVHQGl-.js";import{W as it}from"../chunks/Dbd6PPbz.js";import{C as st}from"../chunks/CwqI2jFH.js";import{w as j}from"../chunks/u94nIB4-.js";import{t as C}from"../chunks/BEkVdVE1.js";var lt=A('<div class="p-6 text-center"><div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"></div> <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">Loading organization...</p></div>'),dt=A('<div class="rounded-md bg-red-50 dark:bg-red-900 p-4"><p class="text-sm font-medium text-red-800 dark:text-red-200"> </p></div>'),ct=A("<!> <!> <!> <!> <!> <!>",1),ut=A('<div class="space-y-6"><nav class="flex" aria-label="Breadcrumb"><ol class="inline-flex items-center space-x-1 md:space-x-3"><li class="inline-flex items-center"><a class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white"><svg class="w-3 h-3 mr-2.5" fill="currentColor" viewBox="0 0 20 20"><path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z"></path></svg> Organizations</a></li> <li><div class="flex items-center"><svg class="w-3 h-3 text-gray-400 mx-1" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg> <span class="ml-1 text-sm font-medium text-gray-500 md:ml-2 dark:text-gray-400"> </span></div></li></ol></nav> <!></div> <!> <!> <!> <!>',1);function Tt(ge,me){Ne(me,!1);const[pe,ve]=Qe(),G=()=>Xe(Ze,"$page",pe),w=l();let a=l(null),c=l([]),p=l([]),F=l(!0),I=l(""),O=l(!1),D=l(!1),E=l(!1),T=l(!1),u=l(null),P=null,b=l();async function R(){if(e(w))try{o(F,!0),o(I,"");const[t,n,r]=await Promise.all([_.getOrganization(e(w)),_.listOrganizationPools(e(w)).catch(()=>[]),_.listOrganizationInstances(e(w)).catch(()=>[])]);o(a,t),o(c,n),o(p,r)}catch(t){o(I,t instanceof Error?t.message:"Failed to load organization")}finally{o(F,!1)}}function ye(t,n){const{events:r}=t;return{...n,events:r}}async function he(t){if(e(a))try{await _.updateOrganization(e(a).id,t),await R(),C.success("Organization Updated",`Organization ${e(a).name} has been updated successfully.`),o(O,!1)}catch(n){throw n}}async function _e(){if(e(a)){try{await _.deleteOrganization(e(a).id),ce(`${H}/organizations`)}catch(t){o(I,t instanceof Error?t.message:"Failed to delete organization")}o(D,!1)}}async function be(){if(e(u))try{await _.deleteInstance(e(u).name),C.success("Instance Deleted",`Instance ${e(u).name} has been deleted successfully.`),o(E,!1),o(u,null)}catch(t){const n=t instanceof Error?t.message:"Failed to delete instance";C.error("Delete Failed",n),o(E,!1),o(u,null)}}function ze(t){o(u,t),o(E,!0)}function $e(){o(T,!0)}async function xe(t){try{if(!e(a))return;await _.createOrganizationPool(e(a).id,t.detail),C.success("Pool Created",`Pool has been created successfully for organization ${e(a).name}.`),o(T,!1)}catch(n){throw n}}function V(){e(b)&&Je(b,e(b).scrollTop=e(b).scrollHeight)}function we(t){if(t.operation==="update"){const n=t.payload;if(e(a)&&n.id===e(a).id){const r=e(a).events?.length||0,i=n.events?.length||0;o(a,ye(e(a),n)),i>r&&setTimeout(()=>{V()},100)}}else if(t.operation==="delete"){const n=t.payload.id||t.payload;e(a)&&e(a).id===n&&ce(`${H}/organizations`)}}function Ie(t){if(!e(a))return;const n=t.payload;if(n.org_id===e(a).id){if(t.operation==="create")o(c,[...e(c),n]);else if(t.operation==="update")o(c,e(c).map(r=>r.id===n.id?n:r));else if(t.operation==="delete"){const r=n.id||n;o(c,e(c).filter(i=>i.id!==r))}}}function Ee(t){if(!e(a)||!e(c))return;const n=t.payload;if(e(c).some(i=>i.id===n.pool_id)){if(t.operation==="create")o(p,[...e(p),n]);else if(t.operation==="update")o(p,e(p).map(i=>i.id===n.id?n:i));else if(t.operation==="delete"){const i=n.id||n;o(p,e(p).filter(L=>L.id!==i))}}}We(()=>{R().then(()=>{e(a)?.events?.length&&setTimeout(()=>{V()},100)});const t=j.subscribeToEntity("organization",["update","delete"],we),n=j.subscribeToEntity("pool",["create","update","delete"],Ie),r=j.subscribeToEntity("instance",["create","update","delete"],Ee);P=()=>{t(),n(),r()}}),qe(()=>{P&&(P(),P=null)}),He(()=>G(),()=>{o(w,G().params.id)}),je(),Le();var J=ut();Ge(t=>{q(()=>Ve.title=`${e(a),s(()=>e(a)?`${e(a).name} - Organization Details`:"Organization Details")??""} - GARM`)});var S=M(J),B=f(S),K=f(B),U=f(K),Oe=f(U);g(U);var Q=d(U,2),X=f(Q),Y=d(f(X),2),De=f(Y,!0);g(Y),g(X),g(Q),g(K),g(B);var Te=d(B,2);{var Pe=t=>{var n=lt();x(t,n)},ke=t=>{var n=de(),r=M(n);{var i=z=>{var $=dt(),k=f($),N=f(k,!0);g(k),g($),q(()=>le(N,e(I))),x(z,$)},L=z=>{var $=de(),k=M($);{var N=W=>{var ae=ct(),ne=M(ae);{let v=m(()=>(e(a),s(()=>e(a).name||"Organization"))),y=m(()=>(e(a),s(()=>e(a).endpoint?.name))),Ue=m(()=>(Ke(fe),e(a),s(()=>fe(e(a).endpoint?.endpoint_type||"unknown"))));ot(ne,{get title(){return e(v)},get subtitle(){return`Endpoint: ${e(y)??""}`},get forgeIcon(){return e(Ue)},onEdit:()=>o(O,!0),onDelete:()=>o(D,!0)})}var oe=d(ne,2);tt(oe,{get entity(){return e(a)},entityType:"organization"});var re=d(oe,2);{let v=m(()=>(e(a),s(()=>e(a).id||""))),y=m(()=>(e(a),s(()=>e(a).name||"")));it(re,{entityType:"organization",get entityId(){return e(v)},get entityName(){return e(y)}})}var ie=d(re,2);{let v=m(()=>(e(a),s(()=>e(a).id||""))),y=m(()=>(e(a),s(()=>e(a).name||"")));at(ie,{get pools(){return e(c)},entityType:"organization",get entityId(){return e(v)},get entityName(){return e(y)},$$events:{addPool:$e}})}var se=d(ie,2);rt(se,{get instances(){return e(p)},entityType:"organization",onDeleteInstance:ze});var Be=d(se,2);{let v=m(()=>(e(a),s(()=>e(a)?.events)));nt(Be,{get events(){return e(v)},get eventsContainer(){return e(b)},set eventsContainer(y){o(b,y)},$$legacy:!0})}x(W,ae)};h(k,W=>{e(a)&&W(N)},!0)}x(z,$)};h(r,z=>{e(I)?z(i):z(L,!1)},!0)}x(t,n)};h(Te,t=>{e(F)?t(Pe):t(ke,!1)})}g(S);var Z=d(S,2);{var Me=t=>{et(t,{get entity(){return e(a)},entityType:"organization",$$events:{close:()=>o(O,!1),submit:n=>he(n.detail)}})};h(Z,t=>{e(O)&&e(a)&&t(Me)})}var ee=d(Z,2);{var Ce=t=>{ue(t,{title:"Delete Organization",message:"Are you sure you want to delete this organization? This action cannot be undone and will remove all associated pools and instances.",get itemName(){return e(a),s(()=>e(a).name)},$$events:{close:()=>o(D,!1),confirm:_e}})};h(ee,t=>{e(D)&&e(a)&&t(Ce)})}var te=d(ee,2);{var Ae=t=>{ue(t,{title:"Delete Instance",message:"Are you sure you want to delete this instance? This action cannot be undone.",get itemName(){return e(u),s(()=>e(u).name)},$$events:{close:()=>{o(E,!1),o(u,null)},confirm:be}})};h(te,t=>{e(E)&&e(u)&&t(Ae)})}var Fe=d(te,2);{var Se=t=>{{let n=m(()=>(e(a),s(()=>e(a).id||"")));st(t,{initialEntityType:"organization",get initialEntityId(){return e(n)},$$events:{close:()=>o(T,!1),submit:xe}})}};h(Fe,t=>{e(T)&&e(a)&&t(Se)})}q(()=>{Ye(Oe,"href",`${H}/organizations`),le(De,(e(a),s(()=>e(a)?e(a).name:"Loading...")))}),x(ge,J),Re(),ve()}export{Tt as component};
|