import{r as _,w as H,a as C,b as j,c as h,n as k,V as R}from"./vue.esm.01cc5dc9.js";import{E as x}from"./Error.abf8cb86.js";import{n as v}from"./plugin-vue2_normalizer.ed7092a9.js";import{M as P}from"./ModalDialog.90697371.js";import{d as N,a as G,b as U,E as z}from"./dataTables.bootstrap4.32115d05.js";import"./_commonjsHelpers.04e31c8c.js";const F={__name:"InstanceDetails",props:["pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb"],setup(p){return{__sfc:!0}}};var L=function(){var t=this,e=t._self._c;return t._self._setupProxy,e("div",{staticClass:"alert alert-light mx-auto pa-6"},[e("h2",{staticClass:"text-center"},[e("span",{domProps:{innerHTML:t._s(t.pg_host)}}),t._v(":"),e("span",{domProps:{innerHTML:t._s(t.pg_port)}})]),e("p",{staticClass:"text-center"},[t.cpu&&t.mem_gb?e("span",[e("span",{domProps:{innerHTML:t._s(t.cpu)}}),t._v(" CPU - "),e("span",{domProps:{innerHTML:t._s(t.mem_gb)}}),t._v(" GB memory"),e("br")]):t._e(),t.pg_version_summary&&t.pg_data?e("strong",[e("span",{domProps:{innerHTML:t._s(t.pg_version_summary)}}),t._v(" serving "),e("span",{domProps:{innerHTML:t._s(t.pg_data)}}),t._v(".")]):t._e(),e("br")])])},O=[],E=v(F,L,O,!1,null,null,null,null);const T=E.exports,X={__name:"DeleteInstanceDialog",setup(p,{expose:t}){const e=_(null),s=_(null),n=_(!1),l=_(null),a=_(null);let o=null,c=null;function i(d,u){o=d,c=u,$(e.value.$el).modal("show"),$.ajax({url:["/json/settings/instance",o,c].join("/")}).fail(g=>{n.value=!1,s.value.fromXHR(g)}).done(g=>{l.value=g.hostname,a.value=g.pg_port,n.value=!1})}function m(){n.value=!0,$.ajax({url:"/json/settings/delete/instance",type:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify({agent_address:o,agent_port:c})}).fail(d=>{n.value=!1,s.value.fromXHR(d)}).done(()=>{window.location.reload()})}return t({open:i}),{__sfc:!0,root:e,error:s,waiting:n,pg_host:l,pg_port:a,agent_address:o,agent_port:c,open:i,delete_:m,Error:x,InstanceDetails:T,ModalDialog:P}}};var q=function(){var t=this,e=t._self._c,s=t._self._setupProxy;return e(s.ModalDialog,{ref:"root",attrs:{id:"modalDeleteInstance",title:"Delete Instance"}},[e("div",{staticClass:"modal-body"},[e(s.Error,{ref:"error",attrs:{showTitle:!1}}),e("p",{staticClass:"text-center"},[e("strong",[t._v("Please confirm the deletion of the following instance:")])]),e(s.InstanceDetails,{attrs:{pg_host:s.pg_host,pg_port:s.pg_port}})],1),e("div",{staticClass:"modal-footer"},[e("button",{staticClass:"btn btn-outline-secondary",attrs:{type:"button","data-dismiss":"modal"}},[t._v("Cancel")]),e("button",{staticClass:"btn btn-danger ml-auto",attrs:{id:"buttonDelete",type:"button",disabled:s.waiting},on:{click:s.delete_}},[t._v(" Yes, delete this instance "),s.waiting?e("i",{staticClass:"fa fa-spinner fa-spin loader"}):t._e()])])])},Y=[],J=v(X,q,Y,!1,null,null,null,null);const Q=J.exports,V={__name:"InstanceForm",props:["submit_text","waiting","pg_host","pg_port","pg_data","pg_version_summary","cpu","mem_gb","signature_status","agent_key","comment","notify","groups","plugins"],emits:["submit"],setup(p,{expose:t,emit:e}){const s=p,n=_(null),l=_(null);H(()=>s.comment,i=>{l.value=i}),C(()=>{$('[data-toggle="tooltip"]',n.value.$el).tooltip(),$("#selectGroups").data("multiselect")&&($("#selectGroups").multiselect(s.waiting?"disable":"enable"),$("#selectPlugins").multiselect(s.waiting?"disable":"enable"))});function a(){const i={templates:{button:`
            <button type="button"
                    class="multiselect dropdown-toggle border-secondary"
                    data-toggle="dropdown">
              <span class="multiselect-selected-text"></span> <b class="caret"></b>
            </button>
            `,li:`
            <li class="dropdown-item">
              <label class="w-100"></label>
            </li>
            `},numberDisplayed:1};$("#selectGroups").multiselect(i),$("#selectPlugins").multiselect(i)}function o(){$("#selectGroups").multiselect("destroy"),$("#selectPlugins").multiselect("destroy")}function c(){const i={agent_key:s.agent_key,groups:$("#selectGroups").val(),plugins:$("#selectPlugins").val(),notify:s.notify,comment:l.value};e("submit",i)}return t({setup_multiselects:a,teardown_multiselects:o}),{__sfc:!0,props:s,root:n,commentModel:l,setup_multiselects:a,teardown_multiselects:o,submit:c,emit:e,InstanceDetails:T}}};var B=function(){var t=this,e=t._self._c,s=t._self._setupProxy;return e("form",{ref:"root",on:{submit:function(n){return n.preventDefault(),s.submit.apply(null,arguments)}}},[e("div",{staticClass:"modal-body p-3"},[e("div",{staticClass:"row"},[e(s.InstanceDetails,{attrs:{pg_host:t.pg_host,pg_port:t.pg_port,pg_version_summary:t.pg_version_summary,pg_data:t.pg_data,cpu:t.cpu,mem_gb:t.mem_gb}})],1),t.$slots.default?e("div",{staticClass:"row"},[e("div",{staticClass:"col"},[t._t("default")],2)]):t._e(),t.signature_status==="unchecked"?e("div",{staticClass:"row"},[e("div",{staticClass:"form-group col-sm-12"},[t._m(0),e("input",{directives:[{name:"model",rawName:"v-model",value:t.agent_key,expression:"agent_key"}],staticClass:"form-control",attrs:{id:"inputAgentKey",placeholder:"Find it in agent configuration file.",required:"",disabled:t.waiting},domProps:{value:t.agent_key},on:{input:function(n){n.target.composing||(t.agent_key=n.target.value)}}})])]):t._e(),e("div",{staticClass:"row"},[t.groups.length>0?e("div",{staticClass:"form-group col-sm-6",attrs:{id:"divGroups"}},[e("label",{attrs:{for:"selectGroups"}},[t._v("Groups")]),e("select",{attrs:{id:"selectGroups",disabled:t.waiting,multiple:"",required:""}},t._l(t.groups,function(n){return e("option",{key:n.name,domProps:{selected:n.selected?"selected":null,value:n.name}},[t._v(" "+t._s(n.name)+" ")])}),0),e("div",{attrs:{id:"tooltip-container"}})]):t._e(),t.plugins.length>0?e("div",{staticClass:"form-group col-sm-6",attrs:{id:"divPlugins"}},[e("label",{staticClass:"control-label",attrs:{for:"selectPlugins"}},[t._v("Plugins")]),e("select",{attrs:{id:"selectPlugins",disabled:t.waiting,multiple:"multiple"}},t._l(t.plugins,function(n){return e("option",{key:n.name,class:{disabled:n.disabled},attrs:{disabled:n.disabled?"disabled":null,title:n.disabled?"Plugin disabled by agent.":null},domProps:{value:n.name,selected:n.selected}},[t._v(" "+t._s(n.name)+" ")])}),0)]):t._e()]),e("div",{staticClass:"row"},[e("div",{staticClass:"col-sm-12"},[e("div",{staticClass:"form-check"},[e("input",{directives:[{name:"model",rawName:"v-model",value:t.notify,expression:"notify"}],staticClass:"form-check-input",attrs:{id:"inputNotify",type:"checkbox",disabled:t.waiting},domProps:{checked:Array.isArray(t.notify)?t._i(t.notify,null)>-1:t.notify},on:{change:function(n){var l=t.notify,a=n.target,o=!!a.checked;if(Array.isArray(l)){var c=null,i=t._i(l,c);a.checked?i<0&&(t.notify=l.concat([c])):i>-1&&(t.notify=l.slice(0,i).concat(l.slice(i+1)))}else t.notify=o}}}),e("label",{staticClass:"control-label",attrs:{for:"inputNotify"}},[t._v("Notify users of any status alert.")])])])]),e("div",{staticClass:"row"},[e("div",{staticClass:"form-group col-sm-12"},[e("label",{staticClass:"control-label",attrs:{for:"inputComment"}},[t._v("Comment")]),e("textarea",{directives:[{name:"model",rawName:"v-model",value:s.commentModel,expression:"commentModel"}],staticClass:"form-control",attrs:{id:"inputComment",rows:"3",disabled:t.waiting},domProps:{value:s.commentModel},on:{input:function(n){n.target.composing||(s.commentModel=n.target.value)}}})])])]),e("div",{staticClass:"modal-footer"},[e("button",{staticClass:"btn btn-outline-secondary",attrs:{type:"button","data-dismiss":"modal"}},[t._v("Cancel")]),e("button",{staticClass:"btn btn-success ml-auto",attrs:{id:"buttonSubmit",type:"submit",disabled:t.waiting}},[t._v(" "+t._s(t.submit_text)+" "),t.waiting?e("i",{staticClass:"fa fa-spinner fa-spin loader"}):t._e()])])])},K=[function(){var p=this,t=p._self._c;return p._self._setupProxy,t("label",{staticClass:"control-label",attrs:{for:"inputAgentKey"}},[p._v(" Agent secret key "),t("i",{staticClass:"fa fa-info-circle text-muted",attrs:{id:"cpu-info","data-toggle":"tooltip",title:"Using agent secret key is deprecated. You should upgrade agent to version 8."}})])}],W=v(V,B,K,!1,null,null,null,null);const I=W.exports,Z={__name:"NewInstanceWizard",setup(p){const t=_(null),e=_(null),s=_(null),n=_(!1),l={wizard_step:"discover",agent_address:null,agent_port:null,agent_key:"",comment:"",notify:!0,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_groups:[],server_plugins:[],signature_status:null},a=j({...l}),o=h(()=>Array.from(a.server_groups,u=>({name:u.name,disabled:!1,selected:!1}))),c=h(()=>Array.from(a.server_plugins,u=>({name:u,disabled:a.discover_data.temboard.plugins.indexOf(u)===-1,selected:a.discover_data.temboard.plugins.indexOf(u)!==-1})));C(()=>{$('[data-toggle="tooltip"]',t.value.$el).tooltip(),a.wizard_step==="register"&&c&&!$("#selectGroups").data("multiselect")&&k(s.value.setup_multiselects),a.wizard_step==="register"&&$("#selectGroups").data("multiselect")&&($("#selectGroups").multiselect(n.value?"disable":"enable"),$("#selectPlugins").multiselect(n.value?"disable":"enable"))});function i(){n.value=!0,$.ajax({url:["/json/discover/instance",a.agent_address,a.agent_port].join("/"),type:"get",contentType:"application/json",dataType:"json"}).fail(u=>{n.value=!1,e.value.fromXHR(u)}).done((u,g,b)=>{if(u.signature_status=="invalid"){e.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>
            `),n.value=!1;return}a.discover_data=u,a.discover_etag=b.getResponseHeader("ETag"),a.cpu=u.system.cpu_count;var y=u.system.memory/1024/1024/1024;a.mem_gb=y.toFixed(2),a.pg_version_summary=u.postgres.version_summary,a.pg_data=u.postgres.data_directory,a.pg_host=u.system.fqdn,a.pg_port=u.postgres.port,a.signature_status=u.signature_status,$.ajax({url:"/json/settings/all/group/instance"}).fail(f=>{n.value=!1,e.value.fromXHR(f)}).done(f=>{a.server_groups=f.groups,a.server_plugins=f.loaded_plugins,n.value=!1,a.wizard_step="register"})})}function m(u){n.value=!0,$.ajax({url:"/json/settings/instance",method:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify({...u,new_agent_address:a.agent_address,new_agent_port:a.agent_port,discover:a.discover_data,discover_etag:a.discover_etag})}).fail(g=>{n.value=!1,e.value.fromXHR(g)}).done(()=>{window.location.reload()})}function d(){Object.assign(a,l),s.value&&s.value.teardown_multiselects()}return{__sfc:!0,root:t,error:e,formCmp:s,waiting:n,initialState:l,state:a,groups:o,plugins:c,discover:i,register:m,reset:d,Error:x,InstanceForm:I,ModalDialog:P}}};var tt=function(){var t=this,e=t._self._c,s=t._self._setupProxy;return e(s.ModalDialog,{ref:"root",attrs:{id:"modalNewInstance",title:"Register New Instance"},on:{closed:s.reset}},[s.state.wizard_step=="discover"?e("div",{},[e("form",{on:{submit:function(n){return n.preventDefault(),s.discover.apply(null,arguments)}}},[e("div",{staticClass:"modal-body"},[e("p",{staticClass:"alert alert-info"},[t._v(" 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. ")]),e(s.Error,{ref:"error",attrs:{showTitle:!1}}),e("div",{staticClass:"row"},[e("div",{staticClass:"form-group col-sm-6"},[e("label",{staticClass:"control-label",attrs:{for:"inputAgentAddress"}},[t._v("Agent address")]),e("input",{directives:[{name:"model",rawName:"v-model.lazy.trim",value:s.state.agent_address,expression:"state.agent_address",modifiers:{lazy:!0,trim:!0}}],staticClass:"form-control",attrs:{disabled:s.waiting,id:"inputAgentAddress",type:"text",placeholder:"ex: db.entreprise.lan"},domProps:{value:s.state.agent_address},on:{change:function(n){t.$set(s.state,"agent_address",n.target.value.trim())},blur:function(n){return t.$forceUpdate()}}})]),e("div",{staticClass:"form-group col-sm-6"},[e("label",{staticClass:"control-label",attrs:{for:"inputAgentPort"}},[t._v("Agent port")]),e("input",{directives:[{name:"model",rawName:"v-model.lazy.number.trim",value:s.state.agent_port,expression:"state.agent_port",modifiers:{lazy:!0,number:!0,trim:!0}}],staticClass:"form-control",attrs:{disabled:s.waiting,id:"inputAgentPort",type:"text",placeholder:"ex: 2345"},domProps:{value:s.state.agent_port},on:{change:function(n){t.$set(s.state,"agent_port",t._n(n.target.value.trim()))},blur:function(n){return t.$forceUpdate()}}})])])],1),e("div",{staticClass:"modal-footer"},[e("button",{staticClass:"btn btn-outline-secondary",attrs:{type:"button","data-dismiss":"modal"}},[t._v("Cancel")]),e("button",{staticClass:"btn btn-success ml-auto",attrs:{id:"buttonDiscover",type:"submit",disabled:s.waiting}},[t._v(" Discover "),s.waiting?e("i",{staticClass:"fa fa-spinner fa-spin loader"}):t._e()])])])]):t._e(),s.state.wizard_step=="register"?e("div",{},[e(s.InstanceForm,{ref:"formCmp",attrs:{submit_text:"Register",pg_host:s.state.pg_host,pg_port:s.state.pg_port,pg_data:s.state.pg_data,pg_version_summary:s.state.pg_version_summary,cpu:s.state.cpu,mem_gb:s.state.mem_gb,signature_status:s.state.signature_status,groups:s.groups,plugins:s.plugins,notify:s.state.notify,comment:s.state.comment,agent_key:s.state.agent_key,waiting:s.waiting},on:{submit:s.register}},[e(s.Error,{ref:"error",attrs:{showTitle:!1}})],1)],1):t._e()])},et=[],st=v(Z,tt,et,!1,null,null,null,null);const nt=st.exports,at={__name:"UpdateInstanceDialog",setup(p,{expose:t}){const e=_(null),s=_(null),n=_(null),l=_(!1),a={agent_key:"",comment:"",notify:!0,cpu:null,server_groups:[],current_groups:[],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},o=j({...a});let c=null,i=null,m,d;const u=h(()=>Array.from(o.server_plugins,r=>({name:r,disabled:o.agent_plugins.length>0&&o.agent_plugins.indexOf(r)===-1,selected:o.current_plugins.indexOf(r)!==-1}))),g=h(()=>Array.from(o.server_groups,r=>({name:r.name,selected:o.current_groups.indexOf(r.name)!==-1})));C(()=>{$('[data-toggle="tooltip"]',e.value.$el).tooltip(),$("#selectGroups").data("multiselect")&&($("#selectGroups").multiselect(l.value?"disable":"enable"),$("#selectPlugins").multiselect(l.value?"disable":"enable"))});function b(){return $.ajax({url:["/json/discover/instance",c,i].join("/"),type:"get",contentType:"application/json",dataType:"json"}).fail(r=>{l.value=!1,s.value.fromXHR(r)}).done((r,w,S)=>{if(r.signature_status=="invalid"){s.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>
            `),l.value=!1;return}m=r,d=S.getResponseHeader("ETag"),o.agent_plugins=r.temboard.plugins,o.cpu=r.system.cpu_count;const M=r.system.memory/1024/1024/1024;o.mem_gb=M.toFixed(2),o.pg_version_summary=r.postgres.version_summary,o.pg_data=r.postgres.data_directory,o.pg_host=r.system.fqdn,o.pg_port=r.postgres.port,o.signature_status=r.signature_status})}function y(r,w){s.value.clear(),l.value=!0,c=r,i=w,$(e.value.$el).modal("show"),f().done(()=>{b().complete(()=>{k(n.value.setup_multiselects),l.value=!1})})}function f(){return $.ajax({url:["/json/settings/instance",c,i].join("/")}).fail(r=>{l.value=!1,s.value.fromXHR(r)}).done(r=>{o.notify=r.notify,o.comment=r.comment,o.agent_key=r.agent_key,o.pg_host=r.hostname,o.pg_port=r.pg_port,o.server_groups=r.server_groups,o.server_plugins=r.server_plugins,o.current_plugins=r.plugins,o.current_groups=r.groups})}function D(r){l.value=!0,m.signature_status==="valid"&&(r.agent_key=null),$.ajax({url:["/json/settings/instance",c,i].join("/"),method:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify({...r,new_agent_address:c,new_agent_port:i,discover:m,discover_etag:d})}).fail(w=>{l.value=!1,s.value.fromXHR(w)}).done(()=>{window.location.reload()})}function A(){Object.assign(o,a),n.value.teardown_multiselects()}return t({open:y}),{__sfc:!0,root:e,error:s,formCmp:n,waiting:l,initialForm:a,form:o,agent_address:c,agent_port:i,discover_data:m,discover_etag:d,plugins:u,groups:g,discover_agent:b,open:y,fetch_current_data:f,update:D,reset:A,Error:x,ModalDialog:P,InstanceForm:I}}};var ot=function(){var t=this,e=t._self._c,s=t._self._setupProxy;return e(s.ModalDialog,{ref:"root",attrs:{id:"modalUpdateInstance",title:"Update Instance"},on:{closed:s.reset}},[e(s.InstanceForm,{ref:"formCmp",attrs:{submit_text:"Update",pg_host:s.form.pg_host,pg_port:s.form.pg_port,pg_data:s.form.pg_data,pg_version_summary:s.form.pg_version_summary,cpu:s.form.cpu,mem_gb:s.form.mem_gb,signature_status:s.form.signature_status,groups:s.groups,plugins:s.plugins,notify:s.form.notify,comment:s.form.comment,agent_key:s.form.agent_key,waiting:s.waiting},on:{submit:s.update}},[e(s.Error,{ref:"error"})],1)],1)},rt=[],lt=v(at,ot,rt,!1,null,null,null,null);const it=lt.exports;N(window,$);G(window,$);U(window,$);window.app=new R({el:"#vue-app",components:{"delete-instance-dialog":Q,"environment-migration-dialog":z,"new-instance-wizard":nt,"update-instance-dialog":it},created(){this.$nextTick(()=>{var p=$("#tableInstances").DataTable({lengthChange:!1,pageLength:50,buttons:[{attr:{title:"Download inventory as CSV",id:"buttonDownload","data-toggle":"tooltip"},className:"btn btn-sm btn-secondary mx-1",text:'<i class="fa fa-download"></i>',action:function(){var t=$("#tableInstances_filter input").val(),e=new URLSearchParams({filter:t});window.location.replace("/settings/instances.csv?"+e.toString())}}],stateSave:!0});p.buttons().container().appendTo($("#tableInstances_filter"))})}});
