import{p as r,s as ee,c as f,q as te,e as _,z as e,n as l,V as C,f as n,g as h,j as y,P as q,U as se,F as V,A as B,k as D,w as v,o as k,Z as O,h as ae,$ as ne,a0 as le,N as oe}from"./vue-CSzJdJby.js";import{_ as ie}from"./ring-alt-BtllWDs8.js";import{a as re}from"./index-ncPPdFzC.js";import{M as ce}from"./bootstrap.esm-BOBBXxos.js";import{p as de}from"./bootstrap-vue-next-CqKfh9PT.js";import{H as R}from"./highlight.js-CWp04Ajj.js";import{s as ue}from"./default-DS69DB32.js";import{$ as j}from"./jquery-BALIvAru.js";import{l as i}from"./lodash-uc_7-CSk.js";import{_ as pe}from"./ModalDialog-BxAzqKGJ.js";import{f as fe}from"./duration-BgSd64Xa.js";import{_ as ve}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./index-C25aB_MX.js";const m=w=>(ne("data-v-4ee5654f"),w=w(),le(),w),me={class:"nav nav-tabs"},be={class:"nav-item"},ge={class:"nav-item"},_e={class:"nav-item"},he={class:"row d-flex justify-content-between"},ye={class:"col-auto"},ke={class:"d-inline-block","data-bs-toggle":"tooltip",title:"Terminate the backends selected below"},we={class:"col-auto align-self-center"},xe=m(()=>e("i",{class:"fa fa-play"},null,-1)),Se=m(()=>e("div",{class:"col-auto"},[e("a",{class:"btn collapse-toggle dropdown-toggle collapsed","data-bs-toggle":"collapse",href:"#filters",role:"button","aria-expanded":"false","aria-controls":"filters"},`
          filters
        `)],-1)),Ce={class:"row"},Te={class:"col-12 collapse",id:"filters"},Me={class:"justify-content-end d-flex"},Le={class:"mb-1"},qe={id:"state-filter",class:"justify-content-end d-flex"},De=m(()=>e("div",{class:"pe-1"},[e("label",null,[e("strong",null,"States:")])],-1)),je={class:"form-check form-check-inline"},$e=["id","value"],Ae=["for"],He={class:"row"},Ie={class:"col-12"},Pe=["innerHTML"],Ne=["disabled","value"],Ue={class:"position-relative clipboard-parent"},Ve=["onClick"],Be=["innerHTML"],Oe=["title","innerHTML"],Re=m(()=>e("p",{class:"text-center text-body-secondary"},"Showing 300 longest queries.",-1)),Ee={class:"modal-body"},Fe={class:"badge text-bg-primary"},Je={class:"modal-body"},We={key:0,class:"row"},ze=m(()=>e("div",{class:"col-4 offset-4"},[e("div",{class:"progress"},[e("div",{class:"progress-bar progress-bar-striped",style:{width:"100%"}},"Please wait ...")])],-1)),Ye=[ze],Ge={class:"modal-footer"},Ke=["disabled"],Ze=m(()=>e("button",{type:"button",class:"btn btn-outline-secondary","data-bs-dismiss":"modal"},"Cancel",-1)),Qe=2,Xe={__name:"Activity",setup(w){R.registerLanguage("sql",ue);let T=null,$;const c=r({});let M=r(!1),b=r(!1);const o=r("running"),u=r(!1),d=r([]),L=r(null),A=["active","idle","idle in transaction","idle in transaction (aborted)","fastpath function call","disabled"],x=r(JSON.parse(localStorage.getItem("temboardActivityStateFilters"))||A);let H;ee(()=>{H=new ce(j("#terminateModal"))});function S(){const t=new Date;T=j.ajax({url:"/proxy/"+agent_address+"/"+agent_port+"/activity",type:"GET",beforeSend:function(){M.value=!0},async:!0,contentType:"application/json",success:function(a){clearError(),c.value=a},error:function(a,s){s!="abort"&&showError(a)},complete:function(){M.value=!1;const a=Qe*1e3-(new Date-t);$=window.setTimeout(S,a)}})}S();function E(){j.ajax({url:"/proxy/"+agent_address+"/"+agent_port+"/activity/kill",type:"POST",async:!0,contentType:"application/json",dataType:"json",data:JSON.stringify({pids:d.value}),success:function(){H.hide(),b.value=!1,d.value=[],u.value=!1,S()},error:function(t){b.value=!1,console.log(t.status)}})}String.prototype.trunc=String.prototype.trunc||function(t){return this.length>t?this.substr(0,t-1)+"&hellip;":this};function I(t){const a=parseFloat(t);if(i.isFinite(a)){const s=t.slice(-1);return a*Math.pow(2,["B","K","M","G","T","P","E","Z","Y"].indexOf(s)*10)}return t}function F(t){return fe(t*1e3,!0)}function J(t){return t&&t.trunc(12)}function W(t){if(t=="active")return"text-success fw-bold";if(t.indexOf("idle in transaction")!=-1)return"text-danger fw-bold"}function z(){u.value=!0,T&&T.abort(),window.clearTimeout($)}function P(){u.value=!1,d.value=[],S()}const Y=f(()=>i.filter(Z.value,t=>i.includes(x.value,t.state)&&i.some(i.map(i.values(t),i.upperCase),a=>i.includes(a,i.upperCase(L.value)))));function G(t){return R.highlight(t,{language:"sql"}).value}const K=f(()=>{let t=[{label:"",key:"check"},{label:"PID",key:"pid",class:"text-end"},{label:"Database",key:"database"},{label:"User",key:"user",orderable:!1},{label:"Application",key:"application_name"},{label:"CPU",key:"cpu",class:"text-end"},{label:"mem",key:"memory",class:"text-end"},{label:"Read/s",key:"read_s",class:"text-end",formatter:I},{label:"Write/s",key:"write_s",class:"text-end",formatter:I},{label:"IOW",key:"iow",sortable:!0,class:"text-center"}];return o.value=="running"?t=t.concat([{label:"W",key:"wait",class:"text-center"}]):t=t.concat([{label:"Lock Rel.",data:"relation",class:"text-end"},{label:"Lock Mode",key:"mode"},{label:"Lock Type",key:"type"}]),t=t.concat([{label:"State",key:"state",sortable:!0,class:"text-center",tdClass:W},{label:"Time",key:"duration",class:"text-end",formatter:F,sortable:!0},{label:"Query",key:"query",class:"query",sortable:!0,tdAttr:{"data-bs-toggle":"popover","data-bs-trigger":"hover"}}]),t}),g=f(()=>d.value.length>0),Z=f(()=>c.value[o.value]?c.value[o.value].rows:[]),N=f(()=>c.value.waiting?c.value.waiting.rows.length:void 0),U=f(()=>c.value.blocking?c.value.blocking.rows.length:void 0);te(x,t=>{localStorage.setItem("temboardActivityStateFilters",JSON.stringify(t))});function Q(){b.value=void 0}return(t,a)=>(k(),_("div",null,[e("ul",me,[e("li",be,[e("a",{href:"#",class:l([{active:o.value=="running"},"nav-link running"]),onClick:a[0]||(a[0]=C(s=>o.value="running",["prevent"]))},`
          Running`,2)]),n(),e("li",ge,[e("a",{href:"#",class:l([{active:o.value=="waiting"},"nav-link waiting"]),onClick:a[1]||(a[1]=C(s=>o.value="waiting",["prevent"]))},[n(`
          Waiting
          `),e("div",{id:"waiting-count",class:l(["badge",N.value>0?"bg-warning":"bg-light"]),style:{"min-width":"2em"}},h(N.value||" "),3)],2)]),n(),e("li",_e,[e("a",{href:"#",class:l([{active:o.value=="blocking"},"nav-link blocking"]),onClick:a[2]||(a[2]=C(s=>o.value="blocking",["prevent"]))},[n(`Blocking
          `),e("div",{id:"blocking-count",class:l(["badge",U.value>0?"bg-warning":"bg-light"]),style:{"min-width":"2em"}},h(U.value||" "),3)],2)])]),n(),e("div",he,[e("div",ye,[e("span",ke,[e("button",{id:"killButton",type:"button",class:l(["btn btn-danger",{disabled:!g.value}]),"data-bs-toggle":"modal","data-bs-target":"#terminateModal"},`
            Terminate
          `,2)])]),n(),e("div",we,[e("span",{id:"autoRefreshResume",class:l(["d-text-body-secondary",{"d-none":!g.value}])},[e("a",{class:"btn btn-secondary",role:"button",href:"",onClick:C(P,["prevent"])},[xe,n(" resume auto refresh")])],2),n(),e("span",{class:l(["text-body-secondary",{"d-none":g.value}])},[e("img",{src:ie,width:"24",class:l(["fa-fw",{"d-none":!y(M)}])},null,2),n(`
          Auto refresh
          `),e("span",{class:l({"d-none":u.value})},"2s",2),n(),e("span",{class:l({"d-none":!u.value})},"paused",2)],2)]),n(),Se]),n(),e("div",Ce,[e("div",Te,[e("div",Me,[e("div",Le,[q(e("input",{type:"text",placeholder:"Search",class:"form-control","onUpdate:modelValue":a[3]||(a[3]=s=>L.value=s)},null,512),[[se,L.value]])])]),n(),e("form",qe,[De,n(),(k(),_(V,null,B(A,s=>e("div",je,[q(e("input",{class:"form-check-input",type:"checkbox",id:`state-filter-${s}`,value:s,checked:"","onUpdate:modelValue":a[4]||(a[4]=p=>x.value=p)},null,8,$e),[[O,x.value]]),n(),e("label",{class:"form-check-label",for:`state-filter-${s}`},h(s),9,Ae)])),64))])])]),n(),e("div",He,[e("div",Ie,[D(y(de),{striped:"",small:"",items:Y.value,fields:K.value,class:"table-query mt-1 small",onRowHovered:z,onRowUnhovered:a[6]||(a[6]=s=>!g.value&&P()),"sort-by":"duration","sort-desc":""},{"cell()":v(s=>[e("span",{innerHTML:s.value,class:l({"text-danger fw-bold":s.value=="Y"})},null,10,Pe)]),"cell(check)":v(s=>[q(e("input",{type:"checkbox",disabled:!u.value&&!g.value,class:"input-xs","onUpdate:modelValue":a[5]||(a[5]=p=>d.value=p),value:s.item.pid,title:"Select to terminate"},null,8,Ne),[[O,d.value]])]),"cell(query)":v(s=>[e("div",Ue,[D(y(re),{legacy:!0},{default:v(({copy:p,copied:X})=>[e("span",{class:"copy invisible position-absolute top-0 right-0 pe-1 ps-1 bg-secondary text-white rounded",title:"Copy to clipboard",onClick:tt=>p(s.item.query)},h(X?"Copied":"Copy"),9,Ve)]),_:2},1024),n(),e("pre",{class:"sql hljs",innerHTML:G(s.value)},null,8,Be)])]),"cell(state)":v(s=>[e("span",{title:s.value,innerHTML:J(s.value)},null,8,Oe)]),_:1},8,["items","fields"]),n(),Re])]),n(),D(pe,{id:"terminateModal",title:"Terminate Backend",onClosed:Q},{default:v(()=>[e("div",Ee,[n(`
        Please confirm you want to terminated the following backend PIDs:
        `),(k(!0),_(V,null,B(d.value,s=>(k(),_("span",Fe,h(s),1))),256))]),n(),e("div",Je,[y(b)?(k(),_("div",We,Ye)):ae("",!0)]),n(),e("div",Ge,[e("button",{id:"submitKill",type:"button",class:"btn btn-danger",disabled:y(b),onClick:E},`
          Yes, terminate
        `,8,Ke),n(),Ze])]),_:1})]))}},et=ve(Xe,[["__scopeId","data-v-4ee5654f"]]);oe({components:{activity:et}}).mount("#app");
