import{V as Q,D as C}from"./datatables.net-vue3-B28JL-vi.js";import{_ as Y}from"./DeleteDialog-GXib_x-K.js";import{$ as m}from"./jquery-BALIvAru.js";import{e as d,z as t,f as i,h as y,o as u,p,W as J,X as N,k as x,r as W,P as T,Y as G,F as U,A,g as S,Z,n as K,U as H,V as I,_ as P,c as L,b as R,w as k,N as ee}from"./vue-CSzJdJby.js";import{_ as M}from"./Error-BXO_ADNF.js";import{_ as V}from"./ModalDialog-BxAzqKGJ.js";import{T as te}from"./bootstrap.esm-BOBBXxos.js";import"./highlight.js-CWp04Ajj.js";const se={class:"alert text-body-secondary mx-auto pa-6"},ne={class:"text-center"},oe=["innerHTML"],ae=["innerHTML"],ie={class:"text-center"},re={key:0},le=["innerHTML"],ue=["innerHTML"],ce=t("br",null,null,-1),de={key:1},me=["innerHTML"],_e=["innerHTML"],ge=t("br",null,null,-1),z={__name:"InstanceDetails",props:["pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb"],setup(o){return(v,l)=>(u(),d("div",se,[t("h2",ne,[t("span",{innerHTML:o.pg_host},null,8,oe),i(":"),t("span",{innerHTML:o.pg_port},null,8,ae)]),i(),t("p",ie,[o.cpu&&o.mem_gb?(u(),d("span",re,[t("span",{innerHTML:o.cpu},null,8,le),i(" CPU - "),t("span",{innerHTML:o.mem_gb},null,8,ue),i(" GB memory"),ce])):y("",!0),i(),o.pg_version_summary&&o.pg_data?(u(),d("strong",de,[t("span",{innerHTML:o.pg_version_summary},null,8,me),i(" serving "),t("span",{innerHTML:o.pg_data},null,8,_e),i(".")])):y("",!0),ge])]))}},pe={class:"modal-body p-3"},ve={class:"row"},fe={key:0,class:"row"},be={class:"col"},he={class:"row"},ye={class:"col-sm-6"},we={class:"row"},$e={class:"col"},xe=t("label",{class:"form-label"},"Environment",-1),Te=["id"],ke=["value","title"],je=t("div",{id:"tooltip-container"},null,-1),Se={class:"row pt-3"},He={class:"col-sm-12"},Le={class:"form-check"},Me=["id","disabled"],Ne=["for"],Ue={key:0,id:"divPlugins",class:"col-sm-6"},Ae=["for"],Ce={class:"form-check"},Ie=["value","id","checked","disabled","title"],Pe=["for"],Re={class:"row"},Ve={class:"mb-3 col-sm-12"},ze=["for"],De=["id","disabled"],Oe={class:"modal-footer"},Xe=t("button",{type:"button",class:"btn btn-outline-secondary","data-bs-dismiss":"modal"},"Cancel",-1),Ee=["id","disabled"],Be={key:0,class:"fa fa-spinner fa-spin loader"},D={__name:"InstanceForm",props:["submit_text","waiting","disabled","type","environments","pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb","signature_status","comment","notify","environment","plugins"],emits:["submit"],setup(o,{emit:v}){const l=o,f=p(null),r=p({environment:l.environment,comment:l.comment,notify:l.notify});J(()=>{r.value.environment=l.environment,r.value.comment=l.comment,r.value.notify=l.notify}),N(()=>{[...f.value.querySelectorAll('[data-bs-toggle="tooltip"]')].map(c=>new Tooltip(c))});function _(){const b=m(f.value).find("input:checkbox[name=plugins]:checked").toArray().map(e=>e.value),c={...r.value,plugins:b};s("submit",c)}const s=v;return(b,c)=>(u(),d("form",{onSubmit:I(_,["prevent"]),ref_key:"root",ref:f},[t("div",pe,[t("div",ve,[x(z,{pg_host:o.pg_host,pg_port:o.pg_port,pg_version_summary:o.pg_version_summary,pg_data:o.pg_data,cpu:o.cpu,mem_gb:o.mem_gb},null,8,["pg_host","pg_port","pg_version_summary","pg_data","cpu","mem_gb"])]),i(),b.$slots.default?(u(),d("div",fe,[t("div",be,[W(b.$slots,"default")])])):y("",!0),i(),t("div",he,[t("div",ye,[t("div",we,[t("div",$e,[xe,i(),T(t("select",{id:"selectEnvironment"+o.type,"onUpdate:modelValue":c[0]||(c[0]=e=>r.value.environment=e),class:"form-select"},[(u(!0),d(U,null,A(l.environments,e=>(u(),d("option",{value:e.name,title:e.description},S(e.name),9,ke))),256))],8,Te),[[G,r.value.environment]]),i(),je])]),i(),t("div",Se,[t("div",He,[t("div",Le,[T(t("input",{id:"inputNotify"+o.type,class:"form-check-input",type:"checkbox","onUpdate:modelValue":c[1]||(c[1]=e=>r.value.notify=e),disabled:o.waiting},null,8,Me),[[Z,r.value.notify]]),i(),t("label",{for:"inputNotify"+o.type,class:"form-label"},"Notify users of any status alert.",8,Ne)])])])]),i(),o.plugins.length>0?(u(),d("div",Ue,[t("label",{for:"selectPlugins"+o.type,class:"form-label"},"Plugins",8,Ae),i(),(u(!0),d(U,null,A(o.plugins,e=>(u(),d("div",Ce,[t("input",{class:K(["form-check-input",{disabled:e.disabled}]),type:"checkbox",value:e.name,id:`pluginCheckbox_${e.name}`,checked:e.selected,disabled:o.disabled||e.disabled,title:e.disabled?"Plugin disabled by agent.":null,name:"plugins"},null,10,Ie),i(),t("label",{class:"form-check-label",for:`pluginCheckbox_${e.name}`},S(e.name),9,Pe)]))),256))])):y("",!0)]),i(),t("div",Re,[t("div",Ve,[t("label",{for:"inputComment"+o.type,class:"form-label"},"Comment",8,ze),i(),T(t("textarea",{id:"inputComment"+o.type,class:"form-control",rows:"3","onUpdate:modelValue":c[2]||(c[2]=e=>r.value.comment=e),disabled:o.waiting},`
          `,8,De),[[H,r.value.comment]])])])]),i(),t("div",Oe,[Xe,i(),t("button",{id:"buttonSubmit"+o.type,class:"btn btn-success ms-auto",type:"submit",disabled:o.disabled},[i(S(o.submit_text)+" ",1),o.waiting?(u(),d("i",Be)):y("",!0)],8,Ee)])],544))}},Fe={key:0},qe={class:"modal-body"},Qe=t("p",{class:"alert alert-info"},`
            temBoard requires an agent to manage a PostgreSQL instance. Follow documentation to setup the agent next to
            your PostgreSQL instance. Set here agent address and port, not PostgreSQL.
          `,-1),Ye={class:"row"},Je={class:"mb-3 col-sm-6"},We=t("label",{for:"inputAgentAddress",class:"form-label"},"Agent address",-1),Ge=["disabled"],Ze={class:"mb-3 col-sm-6"},Ke=t("label",{for:"inputAgentPort",class:"form-label"},"Agent port",-1),et=["disabled"],tt={class:"modal-footer"},st=t("button",{type:"button",class:"btn btn-outline-secondary","data-bs-dismiss":"modal"},"Cancel",-1),nt=["disabled"],ot={key:0,class:"fa fa-spinner fa-spin loader"},at={key:1},it={__name:"NewInstanceWizard",setup(o){const v=p(null),l=p(null),f=p(null),r=p(!1),_={wizard_step:"discover",agent_address:null,agent_port:null,comment:"",notify:!0,environment:null,cpu:null,discover_data:null,discover_etag:null,mem_gb:null,pg_data:null,pg_host:null,pg_port:null,pg_version_summary:null,server_environments:[],server_plugins:[],signature_status:null},s=P({..._}),b=L(()=>Array.from(s.server_plugins,a=>({name:a,disabled:s.discover_data.temboard.plugins.indexOf(a)===-1,selected:s.discover_data.temboard.plugins.indexOf(a)!==-1})));N(()=>{m('[data-bs-toggle="tooltip"]',v.value.$el).tooltip()});function c(){r.value=!0,m.when(m.ajax({url:`/json/instances/${s.agent_address}/${s.agent_port}/discover`,type:"get",contentType:"application/json",dataType:"json",error:a=>{l.value.fromXHR(a)},success:(a,g,h)=>{if(a.signature_status=="invalid"){l.value.setHTML(`
                <p><strong>Signature missmatch !</strong></p>

                <p>Agent is not configured for this UI. You must accept
                <strong>this</strong> UI signing key in agent configuration. See
                installation documentation.</p>
              `);return}s.discover_data=a,s.discover_etag=h.getResponseHeader("ETag"),s.cpu=a.system.cpu_count;var j=a.system.memory/1024/1024/1024;s.mem_gb=j.toFixed(2),s.pg_version_summary=a.postgres.version_summary,s.pg_data=a.postgres.data_directory,s.pg_host=a.system.fqdn,s.pg_port=a.postgres.port,s.signature_status=a.signature_status}}),m.ajax({url:"/json/environments",error:a=>{l.value.fromXHR(a)},success:a=>{s.server_environments=a}}),m.ajax({url:"/json/plugins",error:a=>{l.value.fromXHR(a)},success:a=>{s.server_plugins=a}})).always(()=>{r.value=!1}).done(()=>{s.wizard_step="register"})}function e(a){r.value=!0,m.ajax({url:"/json/instances",method:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify({...a,agent_address:s.agent_address,agent_port:s.agent_port,discover:s.discover_data,discover_etag:s.discover_etag})}).fail(g=>{r.value=!1,l.value.fromXHR(g)}).done(()=>{window.location.reload()})}function $(){Object.assign(s,_)}return(a,g)=>(u(),R(V,{id:"modalNewInstance",title:"Register New Instance",onClosed:$,ref_key:"root",ref:v},{default:k(()=>[s.wizard_step=="discover"?(u(),d("div",Fe,[t("form",{onSubmit:I(c,["prevent"])},[t("div",qe,[Qe,i(),x(M,{ref_key:"error",ref:l,showTitle:!1},null,512),i(),t("div",Ye,[t("div",Je,[We,i(),T(t("input",{disabled:r.value,id:"inputAgentAddress",type:"text","onUpdate:modelValue":g[0]||(g[0]=h=>s.agent_address=h),class:"form-control",placeholder:"ex: db.entreprise.lan"},null,8,Ge),[[H,s.agent_address,void 0,{lazy:!0,trim:!0}]])]),i(),t("div",Ze,[Ke,i(),T(t("input",{disabled:r.value,id:"inputAgentPort",type:"text","onUpdate:modelValue":g[1]||(g[1]=h=>s.agent_port=h),class:"form-control",placeholder:"ex: 2345"},null,8,et),[[H,s.agent_port,void 0,{lazy:!0,number:!0,trim:!0}]])])])]),i(),t("div",tt,[st,i(),t("button",{id:"buttonDiscover",class:"btn btn-success ms-auto",type:"submit",disabled:r.value},[i(`
            Discover
            `),r.value?(u(),d("i",ot)):y("",!0)],8,nt)])],32)])):y("",!0),i(),s.wizard_step=="register"?(u(),d("div",at,[x(D,{ref_key:"formCmp",ref:f,submit_text:"Register",type:"New",pg_host:s.pg_host,pg_port:s.pg_port,pg_data:s.pg_data,pg_version_summary:s.pg_version_summary,cpu:s.cpu,mem_gb:s.mem_gb,signature_status:s.signature_status,environment:s.environment,environments:s.server_environments,plugins:b.value,notify:s.notify,comment:s.comment,waiting:r.value,onSubmit:e},{default:k(()=>[x(M,{ref_key:"error",ref:l,showTitle:!1},null,512)]),_:1},8,["pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb","signature_status","environment","environments","plugins","notify","comment","waiting"])])):y("",!0)]),_:1},512))}},rt={__name:"UpdateInstanceDialog",setup(o,{expose:v}){function l(n,w){$=n,a=w,f.value.show()}v({open:l});const f=p(null),r=p(null),_=p(!0),s=p(!1),b=L(()=>_.value||s.value),c={comment:"",notify:!0,cpu:null,environments:[],environment:null,mem_gb:null,pg_data:null,pg_host:null,pg_port:null,pg_version_summary:null,server_plugins:[],current_plugins:[],agent_plugins:[],signature_status:null},e=P({...c});let $=null,a=null,g,h;const j=L(()=>Array.from(e.server_plugins,n=>({name:n,disabled:e.agent_plugins.length>0&&e.agent_plugins.indexOf(n)===-1,selected:e.current_plugins.indexOf(n)!==-1})));N(()=>{[...f.value.querySelectorAll('[data-bs-toggle="tooltip"]')].map(w=>new te(w))});function O(){return m.when(m.ajax({url:`/json/instances/${$}/${a}`,error:n=>{r.value.fromXHR(n),s.value=!0},success:n=>{e.notify=n.notify,e.comment=n.comment,e.pg_host=n.hostname,e.pg_port=n.pg_port,e.current_plugins=n.plugins,e.environment=n.environment}}),m.ajax({url:"/json/environments",error:n=>{r.value.fromXHR(n),s.value=!0},success:n=>{e.environments=n}}),m.ajax({url:"/json/plugins",error:n=>{r.value.fromXHR(n),s.value=!0},success:n=>{e.server_plugins=n}}),X()).always(()=>{_.value=!1})}function X(){return m.ajax({url:`/json/instances/${$}/${a}/discover`,type:"get",contentType:"application/json",dataType:"json"}).fail(n=>{r.value.fromXHR(n)}).done((n,w,F)=>{if(n.signature_status=="invalid"){r.value.setHTML(`
              <p><strong>Signature missmatch !</strong></p>

              <p>Agent is not configured for this UI. You must accept
              <strong>this</strong> UI signing key in agent configuration. See
              installation documentation.</p>
            `);return}g=n,h=F.getResponseHeader("ETag"),e.agent_plugins=n.temboard.plugins,e.cpu=n.system.cpu_count;const q=n.system.memory/1024/1024/1024;e.mem_gb=q.toFixed(2),e.pg_version_summary=n.postgres.version_summary,e.pg_data=n.postgres.data_directory,e.pg_host=n.system.fqdn,e.pg_port=n.postgres.port,e.signature_status=n.signature_status})}function E(n){_.value=!0,m.ajax({url:`/json/instances/${$}/${a}`,method:"PUT",contentType:"application/json",dataType:"json",data:JSON.stringify({...n,discover:g,discover_etag:h})}).fail(w=>{_.value=!1,r.value.fromXHR(w)}).done(()=>{window.location.reload()})}function B(){Object.assign(e,c),r.value.clear(),_.value=!0,s.value=!1}return(n,w)=>(u(),R(V,{ref_key:"root",ref:f,title:"Update Instance",onOpening:O,onClosed:B},{default:k(()=>[x(D,{submit_text:"Update",type:"Update",pg_host:e.pg_host,pg_port:e.pg_port,pg_data:e.pg_data,pg_version_summary:e.pg_version_summary,cpu:e.cpu,mem_gb:e.mem_gb,signature_status:e.signature_status,environments:e.environments,environment:e.environment,plugins:j.value,notify:e.notify,comment:e.comment,waiting:_.value,disabled:b.value,onSubmit:E},{default:k(()=>[x(M,{ref_key:"error",ref:r},null,512)]),_:1},8,["pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb","signature_status","environments","environment","plugins","notify","comment","waiting","disabled"])]),_:1},512))}};Q.use(C);ee({components:{"new-instance-wizard":it,"update-instance-dialog":rt,deletedialog:Y,instancedetails:z},created(){this.$nextTick(()=>{const o=new C("#tableInstances",{pageLength:50,stateSave:!0,columns:[{width:"auto"},{width:"auto"},{width:"auto"},{width:"6rem"},{width:"6rem",orderable:!1}],layout:{topStart:"search",topEnd:[{buttons:[{attr:{title:"Download inventory as CSV",id:"buttonDownload","data-bs-toggle":"tooltip"},className:"btn btn-sm btn-secondary",text:'<i class="fa fa-download"></i>',action:function(){const v=m(".dt-search input",o.table().container()).val(),l=new URLSearchParams({filter:v});window.location.replace("/instances.csv?"+l.toString())}}]},{buttons:[{text:"New instance",className:"btn btn-sm btn-success ms-1",attr:{id:"buttonNewInstance","data-bs-toggle":"modal","data-bs-target":"#modalNewInstance"}}]}]}})})}}).mount("#vue-app");
