1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4034],{6206:(e,l,t)=>{t.d(l,{A:()=>c});var a=t(4848),s=t(6540),n=t(1710),i=t(3078),r=t(9020);function d(e){let{paradigm:l,payload:t,setLoading:a,table:s,database:n}=e;a(!0),(0,r.A)("/api/exportTableData",{method:"POST",body:{paradigm:l,dbName:n.db_slug,tableName:s.tableName,payload:t}},!0).then(e=>{if(e.success){if("export"==l){let l=new Blob([JSON.stringify(e.data||[],null,4)],{type:"application/json"}),t=URL.createObjectURL(l),a=document.createElement("a");a.href=t,a.style.display="none",a.download="".concat(n.db_slug,"-").concat(s.tableName,"-").concat(Date.now(),".json"),document.body.appendChild(a),a.click(),document.body.removeChild(a)}else"import"==l&&(window.alert("Data Imported Successfully"),window.location.reload())}else e.msg&&window.alert(e.msg)}).catch(e=>{console.log(e)}).finally(()=>{a(!1)})}function c(e){let{database:l,table:t}=e,[r,c]=s.useState(!1),[o,u]=s.useState(!0),m=s.useRef(null);return s.useRef(null),(0,a.jsxs)("div",{className:"relative",children:[r&&(0,a.jsx)(n.A,{width:"15px"}),(0,a.jsx)("div",{className:"button outlined gray",onClick:e=>{d({paradigm:"export",database:l,setLoading:c,table:t})},children:"Export"}),(0,a.jsx)("div",{className:"button outlined gray",onClick:e=>{var a,s;null===(a=m.current)||void 0===a||a.addEventListener("change",e=>{var a;c(!0);let s=e.target;if(!(null===(a=s.files)||void 0===a?void 0:a[0])){window.alert("No FIles selected"),c(!1);return}(0,i.A)({inputFile:s.files[0]}).then(e=>{window.confirm("Use this file '".concat(e.fileName,"' as your import file?"))?d({paradigm:"import",payload:e.fileBase64,database:l,setLoading:c,table:t}):c(!1),u(!1),setTimeout(()=>{u(!0)},200)})}),null===(s=m.current)||void 0===s||s.click()},children:"Import"}),o&&(0,a.jsx)("input",{type:"file",name:"json_file_input",id:"json_file_input",accept:".json",className:"hidden",ref:m})]})}},3425:(e,l,t)=>{t.d(l,{A:()=>p});var a=t(4848),s=t(6540),n=t(5143),i=t(3238),r=t(1671),d=t(6959),c=t(1710),o=t(9878),u=t(9020),m=t(2543),h=t.n(m);function x(e){let{database:l,table:t,setOpenPopover:n,dbSchemaData:i,query:r}=e,[d,c]=s.useState(!1);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{className:"ghost p-3 justify-start",onClick:()=>{c(!0),setTimeout(()=>{n&&n(!1)},200)},children:"Sync Data"}),(0,a.jsx)(o.A,{open:d,setOpen:c,children:(0,a.jsx)(b,{database:l,table:t,dbSchemaData:i,query:r})})]})}function b(e){let{database:l,table:t,query:n,dbSchemaData:i}=e,[o,m]=s.useState(i),[x,b]=s.useState("Push"),[p,v]=s.useState(null==o?void 0:o[0]),[f,g]=s.useState(null==p?void 0:p.tables),[j,N]=s.useState(null==f?void 0:f[0]),[y,w]=s.useState(!1),[T,S]=s.useState(!1);return s.useEffect(()=>{h().isEqual(null==t?void 0:t.fields,null==j?void 0:j.fields)?S(!0):S(!1)},[j,v]),s.useEffect(()=>{n.delegated&&(0,u.A)("/api/get-authorized-databases").then(e=>{e.success&&e.payload&&m(e.payload)})},[]),(0,a.jsxs)("div",{className:"stack gap-2 relative w-full",children:[y||!o&&(0,a.jsx)(c.A,{width:"20px"}),(0,a.jsx)("h3",{className:"m-0 text-lg",children:"Sync Data with another table"}),T?(0,a.jsxs)("span",{className:"info green inline",children:["The selected table matches ",(0,a.jsx)("b",{children:t.tableFullName})," ","schema"]}):(0,a.jsxs)("span",{className:"info warning inline",children:["The selected table is not compatible with"," ",(0,a.jsx)("b",{children:t.tableFullName})]}),o&&(0,a.jsxs)("form",{onSubmit:e=>{!function(e){var l,t,a;let{e:s,setLoading:n,database:i,table:r,query:d}=e;s.preventDefault(),n(!0);let c=s.target,o=null===(l=c.paradigm)||void 0===l?void 0:l.value,m=null===(t=c.database)||void 0===t?void 0:t.value,h=null===(a=c.table)||void 0===a?void 0:a.value,x={paradigm:o,src:{db:i.db_slug,table:r.tableName},dst:{db:m,table:h},delegated:d.delegated};if(!window.confirm("Pull"==o?"NOTE: This operation will override the current database entries. Continue?":"NOTE: This operation will override the selected database entries. Continue?")){setTimeout(()=>{n(!1)},1e3);return}(0,u.A)("/api/sync-table-data",{method:"POST",body:{...x}},!0).then(e=>{e.success?(window.alert("Data Sync Successful"),window.location.reload()):e.msg&&window.alert("ERROR: "+e.msg)}).finally(()=>{setTimeout(()=>{n(!1)},1e3)})}({e,database:l,setLoading:w,table:t,query:n})},className:"w-full stack gap-2 items-stretch",children:[(0,a.jsxs)("div",{className:"stack gap-2 my-2",children:[(0,a.jsx)(r.A,{radioValues:[{title:"Push",payload:"Push",default:!0},{title:"Pull",payload:"Pull"}],name:"paradigm",smallText:!0,flexRow:!0,onChangeHandler:e=>{b(e.target.value)}}),(0,a.jsx)("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:"Push"==x?(0,a.jsxs)(a.Fragment,{children:["Sync data from the current table(",(0,a.jsx)("b",{children:t.tableFullName}),") to the selected table below"]}):(0,a.jsxs)(a.Fragment,{children:["Sync data from the selected table below to the current table(",(0,a.jsx)("b",{children:t.tableFullName}),")"]})})]}),(0,a.jsx)(d.A,{selectOptions:o.filter(e=>e.dbFullName!==l.db_full_name).map(e=>({title:e.dbName,payload:e.dbSlug})),name:"database",onChangeHandler:e=>{let l=o.find(l=>l.dbSlug==e.target.value);if(l){var t;v(l),g(l.tables),N(null===(t=l.tables)||void 0===t?void 0:t[0])}}}),(0,a.jsx)(d.A,{selectOptions:f.map(e=>({title:e.tableFullName,payload:e.tableName})),name:"table",onChangeHandler:e=>{let l=f.find(l=>l.tableName===e.target.value);l&&N(l)}}),(0,a.jsx)("button",{className:T?"":"disabled",children:"Sync"})]})]})}function p(e){let{database:l,table:t,dbSchemaData:r,query:d}=e,[c,o]=s.useState(!1);return(0,a.jsx)(n.Popover,{isOpen:c,onClickOutside:()=>o(!1),positions:["bottom"],align:"end",content:(0,a.jsxs)("div",{className:"stack items-stretch bg-white rounded shadow-md gap-0 min-w-[200px]",children:[(0,a.jsx)(x,{database:l,table:t,setOpenPopover:o,dbSchemaData:r,query:d}),(0,a.jsx)("hr",{className:"m-0"})]}),containerClassName:"z-[1000]",children:(0,a.jsx)("button",{onClick:()=>{o(!c)},className:"outlined gray px-2 py-1.5",children:(0,a.jsx)(i.A,{})})})}},4639:(e,l,t)=>{let a;t.d(l,{A:()=>p});var s=t(4848),n=t(6540),i=t(8032),r=t(4279),d=t(6959),c=t(9268),o=t(9020),u=t(1710);function m(e){var l,t,i,m;let{data:h}=e,{table:x,entries:b,activeEntries:p,setActiveEntries:v,confirmedDelegetedUser:f,database:g,targetField:j,searchTerm:N}=n.useContext(r.TableEntriesContext);null==f||f.delegated,null==f||null===(l=f.priviledges)||void 0===l||l.match(/Edit Tables/i),null==f||null===(t=f.priviledges)||void 0===t||t.match(/Delete Tables/i),null==f||null===(i=f.priviledges)||void 0===i||i.match(/Create Tables/i);let[y,w]=n.useState(!1),T=n.useRef();n.useEffect(()=>{T.current&&T.current.focus()},[]);let[S,A]=n.useState(null);function E(e){var l,t;if(w(!0),p&&v(null),!(null==e?void 0:e.toString().match(/./))){setTimeout(()=>{v&&v(b||[]),w(!1)},500);return}window.clearTimeout(a);let s=null==x?void 0:x.fields.filter(e=>e.fieldName===(null==j?void 0:j.current)),n=s&&s[0]&&(null===(t=s[0].dataType)||void 0===t?void 0:t.match(/int/i))||(null==j?void 0:null===(l=j.current)||void 0===l?void 0:l.match(/^id$/))?"equal":"like";a=setTimeout(()=>{w(!1),(0,o.A)("/api/queryEntriesSearchTerm?db=".concat(null==g?void 0:g.db_full_name,"&table=").concat(null==x?void 0:x.tableName,"&field=").concat(null==j?void 0:j.current,"&term=").concat(e,"&operator=").concat(n)).then(e=>{"number"==typeof e.count&&A(e.count),e.success&&v&&v(e.result),w(!1)})},500)}return(0,s.jsxs)("div",{className:"w-full flex-col items-stretch",children:[(0,s.jsxs)("form",{onSubmit:e=>{e.preventDefault(),(null==N?void 0:N.current)&&E(N.current)},className:"flex flex-row items-stretch gap-4 w-full",children:[(0,s.jsx)("div",{className:"max-w-xs",children:(0,s.jsx)(d.A,{required:!0,selectOptions:x?x.fields.map(e=>({title:e.fieldName||"",payload:e.fieldName||""})):[],name:"database_tables",onChangeHandler:e=>{j&&(j.current=e.target.value)},title:"Select Field",defaultValue:null==j?void 0:j.current,id:"entries-search-field-select"})}),(0,s.jsx)("div",{className:"grow",children:(0,s.jsx)(c.A,{title:"Search Term",placeholder:"Enter search term that corresponds with the selected field type ...",onInputHandler:e=>{var l;let t=e.target;(null===(l=t.value)||void 0===l?void 0:l.match(/./))&&N?N.current=t.value:N&&(N.current=null),E(t.value)},elementRef:T,id:"entries-search-input"})}),y&&(0,s.jsx)("div",{className:"relative items-center justify-center",children:(0,s.jsx)("div",{className:"relative mt-5 w-6",children:(0,s.jsx)(u.A,{width:"20px"})})})]}),(null==N?void 0:null===(m=N.current)||void 0===m?void 0:m.match(/./))&&(0,s.jsx)("div",{className:"py-4",children:(0,s.jsxs)("span",{className:"text-lg",children:["number"==typeof S?S>0?(0,s.jsxs)("b",{children:[S," "]}):(0,s.jsx)(s.Fragment,{children:"No "}):"... ","Search result",S&&1!==S?"s":""," for"," ",(0,s.jsxs)("b",{children:['"',N.current,'"']})]})})]})}var h=t(6206),x=t(3425),b=t(2276);function p(e){var l,t,a,r,d;let{user:c,entries:o,database:p,table:v,setTargetEntry:f,dbSchemaData:g,richTextEditors:j,jsonTextEditors:N,dataTypes:y,title:w,confirmedDelegetedUser:T,query:S,search:A,entriesCount:E}=e;null==T||T.delegated,null==T||null===(l=T.priviledges)||void 0===l||l.match(/Edit Tables/i),null==T||null===(t=T.priviledges)||void 0===t||t.match(/Delete Tables/i),null==T||null===(a=T.priviledges)||void 0===a||a.match(/Create Tables/i),null==T||null===(r=T.priviledges)||void 0===r||r.match(/Edit Entries/i),null==T||null===(d=T.priviledges)||void 0===d||d.match(/Delete Entries/i);let{active_clone:_,active_clone_parent_db:F,remote_connected:C}=p;return(0,s.jsx)(n.Fragment,{children:(0,s.jsxs)("section",{className:"paper gray gray-bg",children:[w&&(0,s.jsxs)("div",{className:"justify-between w-full flex-wrap px-4 sm:px-0 pt-4 sm:pt-0",children:[(0,s.jsx)("h2",{className:"text-xl m-0",children:w}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("a",{className:"button flex gap-2 items-center",href:"/admin/".concat(null==c?void 0:c.id,"/databases/").concat(p.db_slug,"/tables/").concat(v.tableName,"/entries/add-entry"),children:[(0,s.jsx)("span",{className:"symbol",children:"+"}),(0,s.jsx)("span",{children:"Add New Entry"})]}),(0,s.jsx)(h.A,{database:p,table:v}),(0,s.jsx)(x.A,{database:p,table:v,dbSchemaData:g,query:S})]})]}),A&&(0,s.jsx)(m,{}),(0,s.jsxs)("div",{className:"w-full flex-col gap-6",children:[(null==o?void 0:o[0])&&o.map(e=>(0,s.jsx)(n.Fragment,{children:(0,s.jsx)(i.A,{user:c,database:p,table:v,dbSchemaData:g,richTextEditors:j,dataTypes:y,entry:e,query:S,confirmedDelegetedUser:T,jsonTextEditors:N})},e.id)),!o&&(0,s.jsx)("div",{className:"w-full h-[300px]",children:(0,s.jsx)(u.A,{position:"relative"})}),o&&!(null==o?void 0:o[0])&&(0,s.jsxs)("a",{href:"/admin/".concat(null==c?void 0:c.id,"/databases/").concat(p.db_slug,"/tables/").concat(v.tableName,"/entries/add-entry"),className:"border-dotted border-slate-200 border-2 p-4 w-full flex-col rounded flex items-center hover:border-primary/50 gap-2",children:[(0,s.jsx)("span",{className:"text-slate-400 text-center",children:"No Entries Added Yet."}),(0,s.jsx)(b.A,{}),(0,s.jsx)("span",{className:"text-center",children:"Add an Entry to this Table"})]}),E&&E>10?(0,s.jsx)("a",{href:"/admin/".concat(null==c?void 0:c.id,"/databases/").concat(p.db_slug,"/tables/").concat(v.tableName,"/entries"),className:"button outlined gray w-full -mb-4",children:(0,s.jsx)("span",{children:"See All Entries"})}):null,(null==o?void 0:o[0])&&w&&(0,s.jsxs)("a",{className:"button flex gap-2 items-center w-full justify-center mt-2 more-padding",href:"/admin/".concat(null==c?void 0:c.id,"/databases/").concat(p.db_slug,"/tables/").concat(v.tableName,"/entries/add-entry"),style:{borderStyle:"dotted",borderWidth:"2px"},children:[(0,s.jsx)("span",{className:"symbol",children:"+"}),(0,s.jsx)("span",{children:"Add New Entry"})]})]})]})})}},1671:(e,l,t)=>{t.d(l,{A:()=>s});var a=t(4848);function s(e){let{radioValues:l,name:t,onChangeHandler:s,setAlert:n,flexRow:i,labelColor:r,baseText:d,smallText:c,className:o}=e;try{return(0,a.jsx)("div",{className:"flex items-start gap-4 flex-wrap "+(i?"":" flex-col ")+(o||""),children:l.map((e,l)=>{let{payload:i,title:o,jsx:u}=e,m=!1===i?i:i||o||null;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("input",{className:"m-0"+(d?" w-5 h-5":c?" w-4 h-4":" w-6 h-6"),type:"radio",defaultChecked:!!e.default,name:t,id:t+"_"+m,onChange:l=>{n&&n(null),e.onChangeHandler?e.onChangeHandler(l):s&&s(l)},value:"string"==typeof m?m:void 0}),u||(0,a.jsx)("label",{htmlFor:t+"_"+m,className:"text-lg m-0 "+(r||"text-slate-800")+(d?" text-base":c?" text-sm":" text-lg"),children:o})]},l+1)})})}catch(e){return console.log("ERROR in FormRadio =>",e),(0,a.jsx)("div",{children:"Form Radio Error"})}}t(6540)},7700:(e,l,t)=>{t.d(l,{A:()=>n});var a=t(4848),s=t(6540);function n(e){let{table:l,database:t,user:n,activeDbClone:i}=e,r=(null==l?void 0:l.childTableDbFullName)?l.childTableDbFullName.replace(new RegExp(/datasquirel_user_\d+_/),""):null,d=l.childTableDbFullName===t.db_full_name;return r?(0,a.jsxs)("span",{className:"info small green gap-1"+((null==t?void 0:t.active_clone)?" -mt-6":""),style:{fontWeight:"500"},children:["This Table is an active clone of"," ",(0,a.jsx)("a",{href:"/admin/".concat(null==n?void 0:n.id,"/databases/").concat(r,"/tables/").concat(l.childTableName),target:"_blank",className:"button gray outlined small-text",style:{display:"inline-block",fontSize:"12px",padding:"3px 7px"},children:(0,a.jsx)("b",{children:l.childTableName})})," ","in"," ",d?(0,a.jsxs)("span",{children:["this current database(",(0,a.jsx)("b",{children:t.db_name}),")."]}):(0,a.jsxs)(s.Fragment,{children:[(0,a.jsx)("a",{href:"/admin/".concat(null==n?void 0:n.id,"/databases/").concat(r),target:"_blank",className:"button gray outlined small-text",style:{display:"inline-block",fontSize:"12px",padding:"3px 7px"},children:(0,a.jsx)("b",{children:r})}),(0,a.jsx)("span",{children:"database."})]})," ",(null==t?void 0:t.active_clone)?"":"Only Foreign keys and Entries can be updated."]}):(0,a.jsx)(s.Fragment,{})}},4279:(e,l,t)=>{let a;t.r(l),t.d(l,{TableEntriesContext:()=>w,__N_SSP:()=>y,default:()=>T});var s=t(4848),n=t(6540),i=t(4725),r=t(5844),d=t(3647),c=t(5139),o=t(4639),u=t(8064),m=t(7700),h=t(2438),x=t(1710),b=t(9020),p=t(6206),v=t(3425);function f(){var e,l,a;let{user:i,database:x,table:b,dbSchemaData:f,setTargetEntry:j,richTextEditors:N,jsonTextEditors:y,query:T,confirmedDelegetedUser:S,activeEntries:A,entriesCount:E,setActiveEntries:_}=n.useContext(w),F=t(4327);return null==S||S.delegated,null==S||null===(e=S.priviledges)||void 0===e||e.match(/Edit Tables/i),null==S||null===(l=S.priviledges)||void 0===l||l.match(/Delete Tables/i),null==S||null===(a=S.priviledges)||void 0===a||a.match(/Create Tables/i),(0,s.jsxs)(n.Fragment,{children:[(0,s.jsxs)("div",{className:"flex-col items-start gap-0 w-full relative z-50",children:[(0,s.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,s.jsxs)("div",{className:"flex-wrap",children:[(0,s.jsx)(r.A,{}),(0,s.jsx)("h1",{className:"text-3xl m-0",children:(0,s.jsxs)("span",{className:"flex items-center flex-wrap gap-2",children:["All Entries In"," ",(0,s.jsxs)("span",{className:"bg-slate-100 dark:bg-slate-800 px-2 py-1 border border-solid border-slate-400 dark:border-slate-600 rounded relative",children:[b.tableFullName,(0,s.jsx)("div",{className:"absolute -top-5 -right-4",children:(0,s.jsx)(c.A,{slugText:b.tableName,justIcon:!0})})]})," ","Table"]})})]}),(0,s.jsxs)("div",{className:"w-full sm:w-auto",children:[(0,s.jsxs)("a",{href:"/admin/".concat(null==i?void 0:i.id,"/databases/").concat(x.db_slug,"/tables/").concat(b.tableName,"/entries/add-entry"),className:"button flex items-center gap-2 w-full sm:w-auto justify-center",children:[(0,s.jsx)("span",{className:"symbol",children:"+"}),(0,s.jsx)("span",{children:"Add New Entry"})]}),(0,s.jsx)(p.A,{database:x,table:b}),(0,s.jsx)(v.A,{database:x,table:b,dbSchemaData:f,query:T})]})]}),(0,s.jsx)(d.A,{confirmedDelegetedUser:null==T?void 0:T.delegated,user:i})]}),x.active_clone?(0,s.jsx)(u.A,{database:x,user:i}):(0,s.jsx)(s.Fragment,{}),x.remote_connected?(0,s.jsx)(h.p,{database:x}):(0,s.jsx)(s.Fragment,{}),(0,s.jsx)(m.A,{table:b,database:x,user:i}),(0,s.jsx)(o.A,{user:i,entries:A,database:x,table:b,setTargetEntry:j,dbSchemaData:f,richTextEditors:N,dataTypes:F,query:T,confirmedDelegetedUser:S,jsonTextEditors:y,search:!0}),E>20&&(0,s.jsx)(g,{activeEntries:A,setActiveEntries:_,database:x,table:b,entriesCount:E})]})}function g(e){let{activeEntries:l,setActiveEntries:t,database:i,table:r,entriesCount:d}=e,c=n.useContext(w),o=n.useRef(),u=n.useRef(1),m=20*Number(u.current);return(n.useEffect(()=>{let e=(e,l)=>{var s;if(null==e?void 0:null===(s=e[0])||void 0===s?void 0:s.isIntersecting){let e=document.getElementById("entries-search-input"),l=document.getElementById("entries-search-field-select"),s={tableName:r.tableName,dbName:i.db_slug,page:u.current,tableSchema:r,search:e?e.value:void 0,searchField:l?l.value:void 0,delegated:!!c.query.delegated};(0,b.A)("/api/infiniteScroll",{method:"POST",body:s},!0).then(e=>{e.success&&(e.page&&(u.current=e.page),window.clearTimeout(a),a=setTimeout(()=>{var l,a;(null===(l=e.data)||void 0===l?void 0:l[0])&&(null===(a=e.data)||void 0===a?void 0:a[0])&&t(l=>l?[...l,...e.data]:null)},500))}).catch(e=>{console.log("Infinite Scroll Error =>",e)}).finally(()=>{console.log("Infinite Scroll Done. Page",u.current)})}},l={rootMargin:"0px 0px 0px 0px"};setTimeout(()=>{requestAnimationFrame(()=>{let t=new IntersectionObserver(e,l);o.current&&t.observe(o.current)})},1e3)},[]),m>=d)?(0,s.jsx)(n.Fragment,{}):(0,s.jsx)("div",{className:"w-full flex items-center justify-center",ref:o,children:(0,s.jsx)(x.A,{position:"relative",style:{backgroundColor:"transparent"},width:"20px"})})}var j=t(1990),N=t(4477),y=!0;let w=n.createContext({});function T(e){let{user:l,database:t,table:a,dbSchemaData:r,entries:d,query:c,confirmedDelegetedUser:o,entriesCount:u}=e,m="".concat(a.tableFullName," Table Entries | Datasquirel"),h=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("title",{children:m}),(0,s.jsx)("meta",{name:"description",content:"All Entries in table"})]}),[x,b]=n.useState(null),[p,v]=n.useState(d),g=n.useRef("title"),y=n.useRef(null),T=n.useRef([]),S=n.useRef([]);return(0,s.jsx)(i.A,{head:h,extraHeaderContent:(0,s.jsx)(j.A,{database:t,query:c,confirmedDelegetedUser:o,user:l}),children:(0,s.jsxs)(w.Provider,{value:{user:l,database:t,table:a,dbSchemaData:r,entries:d,targetEntry:x,setTargetEntry:b,richTextEditors:T,jsonTextEditors:S,query:c,confirmedDelegetedUser:o,activeEntries:p,setActiveEntries:v,targetField:g,searchTerm:y,entriesCount:u},children:[(0,s.jsx)(f,{}),(0,s.jsx)(N.A,{snug:!0})]})})}}}]); |