1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3293],{14589:(e,a,t)=>{t.d(a,{A:()=>c});var l=t(74848),s=t(96540),d=t(620),i=t(87810);t(97711),t(45165);var n=t(97157),r=t(42543);function c(e){let{user:a,dbImage:t,setDbImage:c,query:o}=s.useContext(i.AddDatabaseContext);if(!a)return(0,l.jsx)(s.Fragment,{});let[u,m]=s.useState(null),[h,p]=s.useState(!1);return(0,l.jsx)("section",{className:"card",children:(0,l.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 gap-6 items-stretch",children:[h&&(0,l.jsx)(d.A,{}),(0,l.jsxs)("div",{className:"flex-col items-start",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left w-full",children:"New Database Information"}),a&&t&&c&&(0,l.jsx)(n.A,{user:a,dbImage:t,setDbImage:c,setLoading:p,query:o})]}),a&&t&&c&&(0,l.jsx)(r.A,{user:a,dbImage:t,setDbImage:c})]})})}},97157:(e,a,t)=>{let l;t.d(a,{A:()=>h});var s=t(74848),d=t(96540),i=t(97711),n=t(41696);t(40961);var r=t(23698),c=t(17531);async function o(e){var a,t,l,s,d,i,n;let{e:o,setLoading:u,dbImage:m,database:h,user:p}=e;u(!0);let g={db_description:(null===(t=o.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?o.target.database_description.value:null,db_name:(null===(s=o.target.database_name)||void 0===s?void 0:null===(l=s.value)||void 0===l?void 0:l.match(/./))?o.target.database_name.value:null,db_slug:(null===(i=o.target.database_slug)||void 0===i?void 0:null===(d=i.value)||void 0===d?void 0:d.match(/./))?o.target.database_slug.value:null,db_full_name:h.db_full_name,id:h.id,active_clone:h.active_clone,active_clone_parent_db:h.active_clone_parent_db};if(m){if("string"==typeof m)g.db_image=m;else if("object"==typeof m){let e=await (0,r.A)("/api/addUserMedia",{method:"post",body:{media:[m],folder:g.db_slug.replace(/_/g,"-"),type:"image"}},!0);g.db_image=(null==e?void 0:null===(n=e.mediaData[0])||void 0===n?void 0:n.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else g.db_image="/images/database-placeholder.png";(0,r.A)("/api/updateUserDatabase",{method:"post",body:g},!0).then(e=>{e.success?(0,c.A)().then(()=>{window.location.pathname="/admin/".concat(null==p?void 0:p.id,"/databases"),setTimeout(()=>{u(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{u(!1)},1e3))})}async function u(e){var a,t,l;let{e:s,setLoading:d,dbImage:i,keepUpdated:n,keepDataUpdated:o,query:u,user:m}=e;d(!0);let h={db_name:s.target.database_name.value,db_slug:s.target.database_slug.value,db_description:(null===(t=s.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?s.target.database_description.value:null};if(i){if("string"==typeof i)h.db_image=i;else if("object"==typeof i){let e=await (0,r.A)("/api/addUserMedia",{method:"post",body:{media:[i],folder:h.db_slug.replace(/_/g,"-"),type:"image"}},!0);h.db_image=(null==e?void 0:null===(l=e.mediaData[0])||void 0===l?void 0:l.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}(null==u?void 0:u.duplicate)&&(h.duplicate=u.duplicate,h.keepUpdated=!!n&&n,h.keepDataUpdated=!!o&&o),(0,r.A)("/api/createUserDatabase",{method:"post",body:h},!0).then(e=>{e.success?(0,c.A)().then(()=>{window.location.pathname="/admin/".concat(null==m?void 0:m.id,"/databases/").concat(h.db_slug)}):setTimeout(()=>{d(!1)},1e3)})}var m=t(21458);function h(e){let{user:a,dbImage:t,setDbImage:r,database:c,setLoading:h,query:p}=e;async function g(e){return(null==c?void 0:c.db_slug)===e?null:await (0,i.A)({tableName:"user_databases",columnName:"db_slug",value:e,userId:a.id})}let[b,v]=d.useState(null),[x,f]=d.useState(!1),[y,_]=d.useState(!1);return(0,s.jsxs)("form",{className:"w-full max-w-none xl:max-w-lg flex flex-col items-start gap-4 relative",onSubmit:e=>{e.preventDefault(),c?o({e,setLoading:h,dbImage:t,database:c,user:a}):u({e,setLoading:h,dbImage:t,keepUpdated:x,keepDataUpdated:y,query:p,user:a})},children:[b&&(0,s.jsx)(n.A,{message:b}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_name",children:"Name"}),(0,s.jsx)("input",{type:"text",name:"database_name",id:"database_name",placeholder:"Database Name",onInput:async e=>{let a=e.target,t=a.closest("form");if(a.value.match(/./)?(a.classList.remove("warning"),v(null)):a.classList.add("warning"),t){t.database_slug.value=a.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,"");let e=t.database_slug.value;window.clearTimeout(l),l=setTimeout(()=>{g(e).then(e=>{(null==e?void 0:e.result)?(t.database_slug.classList.add("warning"),v("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),v(null))})},300)}},defaultValue:c?c.db_name:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_slug",children:"Slug"}),(0,s.jsx)("input",{type:"text",name:"database_slug",id:"database_slug",placeholder:"Database Slug",onInput:e=>{let a=e.target;a.value.match(/./)?(a.classList.remove("warning"),v(null)):a.classList.add("warning");let t=a.value;window.clearTimeout(l),l=setTimeout(()=>{g(t).then(e=>{(null==e?void 0:e.result)?(a.classList.add("warning"),v("Duplicate Database Name")):(a.classList.remove("warning"),v(null))})},300)},defaultValue:c?c.db_slug:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_description",children:"Description (optional)"}),(0,s.jsx)("textarea",{name:"database_description",id:"database_description",placeholder:"Short Description of database",defaultValue:c?c.db_description:""})]}),(null==p?void 0:p.duplicate)&&(0,s.jsx)(d.Fragment,{children:(0,s.jsxs)("div",{className:"card col items-start",children:[(0,s.jsx)(m.A,{checkBoxValues:[{payload:"Keep New Database Updated?",title:"Keep New Database Updated?",name:"clone_database",onChangeHandler:e=>{e.target.checked?f(!0):f(!1)}}]}),(0,s.jsx)("span",{className:"text-sm italic text-slate-600 dark:text-slate-300",children:"By checking this box the new Database stays up to date with changes to the structure of the parent Database"})]})}),(0,s.jsxs)("button",{type:"submit",className:"w-full",children:[c?"Update":"Create"," Database"]})]})}},42543:(e,a,t)=>{t.d(a,{A:()=>r});var l=t(74848),s=t(96540),d=t(65113),i=t(45165),n=t(60557);function r(e){let{user:a,dbImage:t,setDbImage:r,database:c}=e,o=s.useRef();return(0,l.jsxs)("div",{className:"card no-hover col items-center justify-center",children:[(0,l.jsx)("h4",{className:"m-0",children:"Database Image"}),(0,l.jsx)("div",{className:"bg-white rounded-full overflow-hidden w-24 h-24",children:(0,l.jsx)("img",{src:t?"string"==typeof t?t:t.imageBase64Full:"/images/database-placeholder.png",alt:"Database Image",width:100,className:"w-full h-full object-cover",ref:o,"data-imagepreview":"image"})}),(0,l.jsxs)("div",{className:"w-full flex-col",id:"edit-database-image-option-wrapper",children:[(0,l.jsxs)(n.A,{column:!0,className:"w-full",children:[(0,l.jsx)("button",{className:"outlined w-full whitespace-normal",onClick:e=>{(0,i.PB)("user-media-popup")},children:"Choose Image from uploads"}),(0,l.jsx)("button",{className:"outlined secondary w-full whitespace-normal",onClick:e=>{var a,t;let l=e.target;null==l||null===(t=l.closest("#edit-database-image-option-wrapper"))||void 0===t||null===(a=t.querySelector("input"))||void 0===a||a.click()},children:"Choose Image from Computer"})]}),(0,l.jsx)("input",{type:"file",accept:".png,.jpg,.jpeg,.webp",placeholder:"Choose Database Image",className:"hidden",onChange:async e=>{let a=e.target.files[0];r(await (0,d.A)({imageInputFile:a,maxWidth:400}))}})]})]})}},13834:(e,a,t)=>{t.d(a,{A:()=>r});var l=t(74848),s=t(96540),d=t(23698),i=t(45165),n=t(620);function r(e){let{setDbImage:a}=e,[t,r]=s.useState(!0),[c,o]=s.useState(null);return s.useEffect(()=>{(0,d.A)("/api/getUserMedia").then(e=>{r(!1),o(e.media)})},[]),(0,l.jsxs)(i.Ay,{title:"user-media-popup",children:[t&&(0,l.jsx)(n.A,{width:"20px"}),(0,l.jsx)("h4",{className:"m-0 text-lg",children:"Your Uploaded Images"}),(0,l.jsx)("div",{className:"grid grid-cols-2",children:c&&c[0]&&c.filter(e=>"image"==e.media_type).map((e,t)=>(0,l.jsx)("div",{className:"w-full h-44 cursor-pointer hover:opacity-70",onClick:t=>{a(e.media_thumbnail_url||null),(0,i.fs)()},children:(0,l.jsx)("img",{src:e.media_thumbnail_url,alt:"User Media",className:"w-full h-full object-contain"})},t+1))})]})}t(35160)},41696:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(74848);function s(e){let{message:a}=e;return(0,l.jsxs)("div",{className:"p-2 bg-orange-50 w-full justify-center rounded text-sm text-orange-700 border border-orange-400 border-solid",children:[(0,l.jsx)("img",{src:"/images/warning.png",alt:"Warning Image Icon",width:22,className:"-my-2"}),(0,l.jsx)("span",{children:a})]})}t(96540)},97711:(e,a,t)=>{t.d(a,{A:()=>s}),t(40961);var l=t(23698);async function s(e){let{tableName:a,columnName:t,value:s,dbFullName:d,dispatch:i,userId:n,dbId:r}=e;return await (0,l.A)("/api/checkDuplicateData?tableName=".concat(a,"&type=").concat(t,"&value=").concat(s).concat(d?"&dbFullName="+d:"").concat(n?"&userId="+n:"").concat(r?"&dbId="+r:""))}},65113:(e,a,t)=>{t.d(a,{A:()=>l});async function l(e){let a,t,{imageInputFile:l,maxWidth:s}=e,d=document.querySelector("[data-imagepreview='image']"),i=l.name.replace(/\..*/,""),n=document.createElement("canvas"),r=l.type,c=s||null,o=URL.createObjectURL(l),u=new Image;return u.src=o,a=await new Promise((e,a)=>{u.onerror=function(){URL.revokeObjectURL(this.src),console.log("Cannot load image")},u.onload=function(){if(URL.revokeObjectURL(this.src),c){let e=c/u.naturalWidth;n.width=u.naturalWidth<c?u.naturalWidth:c,n.height=u.naturalWidth<c?u.naturalHeight:u.naturalHeight*e}else n.width=u.naturalWidth,n.height=u.naturalHeight;let a=n.getContext("2d");null==a||a.drawImage(u,0,0,n.width,n.height);let t=n.toDataURL(r,.95);d&&document.querySelectorAll("[data-imagepreview='image']").forEach(e=>{e.src=t}),e(t)}}),t=await new Promise((e,a)=>{n.toBlob(a=>{e(null==a?void 0:a.size)},r,.95)}),{imageBase64:a.replace(/.*?base64,/,""),imageBase64Full:a,imageName:i,imageSize:t}}},86625:(e,a,t)=>{var l=t(24994);a.A=void 0;var s=l(t(44888)),d=t(74848);a.A=(0,s.default)((0,d.jsx)("path",{d:"M16.62 2.99c-.49-.49-1.28-.49-1.77 0L6.54 11.3c-.39.39-.39 1.02 0 1.41l8.31 8.31c.49.49 1.28.49 1.77 0s.49-1.28 0-1.77L9.38 12l7.25-7.25c.48-.48.48-1.28-.01-1.76"}),"ArrowBackIosRounded")},34181:(e,a,t)=>{var l=t(24994);a.A=void 0;var s=l(t(44888)),d=t(74848);a.A=(0,s.default)([(0,d.jsx)("path",{d:"M22 15c0-1.66-1.34-3-3-3h-1.5v-.5C17.5 8.46 15.04 6 12 6c-.77 0-1.49.17-2.16.46L20.79 17.4c.73-.55 1.21-1.41 1.21-2.4M2 14c0 2.21 1.79 4 4 4h9.73l-8-8H6c-2.21 0-4 1.79-4 4",opacity:".3"},"0"),(0,d.jsx)("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.33 0-2.57.36-3.65.97l1.49 1.49C10.51 6.17 11.23 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 .99-.48 1.85-1.21 2.4l1.41 1.41c1.09-.92 1.8-2.27 1.8-3.81 0-2.64-2.05-4.78-4.65-4.96M3 5.27l2.77 2.77h-.42C2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h11.73l2 2 1.41-1.41L4.41 3.86zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4z"},"1")],"CloudOffTwoTone")},45014:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("BookText",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20",key:"t4utmx"}],["path",{d:"M8 7h6",key:"1f0q6e"}],["path",{d:"M8 11h8",key:"vwpz6n"}]])},59140:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]])},2894:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("FileKey2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v6",key:"rc0qvx"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"4",cy:"16",r:"2",key:"1ehqvc"}],["path",{d:"m10 10-4.5 4.5",key:"7fwrp6"}],["path",{d:"m9 11 1 1",key:"wa6s5q"}]])},79508:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]])},79753:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]])},1915:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},87273:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},5922:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("ShieldEllipsis",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]])},76897:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(95737).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},87810:(e,a,t)=>{t.r(a),t.d(a,{AddDatabaseContext:()=>m,__N_SSP:()=>u,default:()=>h});var l=t(74848),s=t(96540),d=t(51187),i=t(99862),n=t(4709),r=t(14589);function c(e){let{query:a,duplicateDb:t,user:d}=s.useContext(m),c=(null==a?void 0:a.duplicate)?(0,l.jsxs)("span",{children:["Duplicate"," ",(0,l.jsx)("a",{href:"/admin/".concat(null==d?void 0:d.id,"/databases/").concat(null==t?void 0:t.db_slug),target:"_blank",children:null==t?void 0:t.db_name})," ","Database"]}):"Add A New Database";return(0,l.jsxs)(s.Fragment,{children:[(0,l.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,l.jsxs)("div",{className:"flex-wrap",children:[(0,l.jsx)(i.A,{}),(0,l.jsx)("h1",{className:"text-3xl m-0",children:c})]}),(0,l.jsx)(n.A,{user:d})]}),(0,l.jsx)(r.A,{})]})}var o=t(13834),u=!0;let m=s.createContext({});function h(e){let{user:a,databases:t,query:i,duplicateDb:n}=e,r=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("title",{children:"Add Database | Datasquirel"}),(0,l.jsx)("meta",{name:"description",content:"Add a database"})]}),[u,h]=s.useState("/images/database-placeholder.png");return(0,l.jsx)(d.A,{head:r,user:a,children:(0,l.jsxs)(m.Provider,{value:{user:a,databases:t,dbImage:u,setDbImage:h,query:i,duplicateDb:n},children:[(0,l.jsx)(c,{}),(0,l.jsx)(o.A,{setDbImage:h})]})})}}}]); |