dsql-admin/dsql-app/.local_dist/server/chunks/8842.js

1 line
26 KiB
JavaScript
Raw Normal View History

2024-12-09 12:27:08 +00:00
"use strict";exports.id=8842,exports.ids=[8842],exports.modules={30469:(e,t,a)=>{a.d(t,{A:()=>o});var s=a(8732),l=a(82015),i=a.n(l),r=a(32415),n=a(83147),d=a(63715);function c({paradigm:e,payload:t,setLoading:a,table:s,database:l}){a(!0),(0,d.A)("/api/exportTableData",{method:"POST",body:{paradigm:e,dbName:l.db_slug,tableName:s.tableName,payload:t}},!0).then(t=>{if(t.success){if("export"==e){let e=new Blob([JSON.stringify(t.data||[],null,4)],{type:"application/json"}),a=URL.createObjectURL(e),i=document.createElement("a");i.href=a,i.style.display="none",i.download=`${l.db_slug}-${s.tableName}-${Date.now()}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i)}else"import"==e&&(window.alert("Data Imported Successfully"),window.location.reload())}else t.msg&&window.alert(t.msg)}).catch(e=>{console.log(e)}).finally(()=>{a(!1)})}function o({database:e,table:t}){let[a,l]=i().useState(!1),[d,o]=i().useState(!0),u=i().useRef(null);return i().useRef(null),(0,s.jsxs)("div",{className:"relative",children:[a&&(0,s.jsx)(r.A,{width:"15px"}),(0,s.jsx)("div",{className:"button outlined gray",onClick:a=>{c({paradigm:"export",database:e,setLoading:l,table:t})},children:"Export"}),(0,s.jsx)("div",{className:"button outlined gray",onClick:a=>{u.current?.addEventListener("change",a=>{l(!0);let s=a.target;if(!s.files?.[0]){window.alert("No FIles selected"),l(!1);return}n.A({inputFile:s.files[0]}).then(a=>{window.confirm(`Use this file '${a.fileName}' as your import file?`)?c({paradigm:"import",payload:a.fileBase64,database:e,setLoading:l,table:t}):l(!1),o(!1),setTimeout(()=>{o(!0)},200)})}),u.current?.click()},children:"Import"}),d&&(0,s.jsx)("input",{type:"file",name:"json_file_input",id:"json_file_input",accept:".json",className:"hidden",ref:u})]})}},29766:(e,t,a)=>{a.d(t,{A:()=>x});var s=a(8732),l=a(82015),i=a.n(l),r=a(41836),n=a(95939),d=a(43656),c=a(51548),o=a(32415),u=a(2817),m=a(63715);function p({database:e,table:t,setOpenPopover:a,dbSchemaData:l,query:r}){let[n,d]=i().useState(!1);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{className:"ghost p-3 justify-start",onClick:()=>{d(!0),setTimeout(()=>{a&&a(!1)},200)},children:"Sync Data"}),(0,s.jsx)(u.A,{open:n,setOpen:d,children:(0,s.jsx)(h,{database:e,table:t,dbSchemaData:l,query:r})})]})}function h({database:e,table:t,query:a,dbSchemaData:l}){let[r,n]=i().useState(l),[u,p]=i().useState("Push"),[h,x]=i().useState(r?.[0]),[f,b]=i().useState(h?.tables),[g,j]=i().useState(f?.[0]),[N,y]=i().useState(!1),[w,v]=i().useState(!1);return(0,s.jsxs)("div",{className:"stack gap-2 relative w-full",children:[N||!r&&(0,s.jsx)(o.A,{width:"20px"}),(0,s.jsx)("h3",{className:"m-0 text-lg",children:"Sync Data with another table"}),w?(0,s.jsxs)("span",{className:"info green inline",children:["The selected table matches ",(0,s.jsx)("b",{children:t.tableFullName})," ","schema"]}):(0,s.jsxs)("span",{className:"info warning inline",children:["The selected table is not compatible with"," ",(0,s.jsx)("b",{children:t.tableFullName})]}),r&&(0,s.jsxs)("form",{onSubmit:s=>{!function({e,setLoading:t,database:a,table:s,query:l}){e.preventDefault(),t(!0);let i=e.target,r=i.paradigm?.value,n=i.database?.value,d=i.table?.value,c={paradigm:r,src:{db:a.db_slug,table:s.tableName},dst:{db:n,table:d},delegated:l.delegated};if(!window.confirm("Pull"==r?"NOTE: This operation will override the current database entries. Continue?":"NOTE: This operation will override the selected database entries. Continue?")){setTimeout(()=>{t(!1)},1e3);return}(0,m.A)("/api/sync-table-data",{method:"POST",body:{...c}},!0).then(e=>{e.success?(window.alert("Data Sync Successful"),window.location.reload()):e.msg&&window.alert("ERROR: "+e.msg)}).finally(()=>{setTimeout(()=>{t(!1)},1e3)})}({e:s,database:e,setLoading:y,table:t,query:a})},className:"w-full stack gap-2 items-stretch",children:[(0,s.jsxs)("div",{className:"stack gap-2 my-2",children:[(0,s.jsx)(d.A,{radioValues:[{title:"Push",payload:"Push",default:!0},{title:"Pull",payload:"Pull"}],name:"paradigm",smallText:!0,flexRow:!0,onChangeHandler:e=>{p(e.target.valu