dsql-admin/dsql-app/.local_dist/server/chunks/194.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

1 line
7.4 KiB
JavaScript

"use strict";exports.id=194,exports.ids=[194],exports.modules={61347:(e,a,t)=>{let l;t.d(a,{A:()=>b});var s=t(8732),i=t(82015),d=t.n(i),n=t(24872),r=t(10621),c=t(46169),u=t(72390);async function o({e,setLoading:a,dbImage:t,database:l,user:s}){a(!0);let i={db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null,db_name:e.target.database_name?.value?.match(/./)?e.target.database_name.value:null,db_slug:e.target.database_slug?.value?.match(/./)?e.target.database_slug.value:null,db_full_name:l.db_full_name,id:l.id,active_clone:l.active_clone,active_clone_parent_db:l.active_clone_parent_db};if(t){if("string"==typeof t)i.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:i.db_slug.replace(/_/g,"-"),type:"image"}},!0);i.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else i.db_image="/images/database-placeholder.png";(0,c.A)("/api/updateUserDatabase",{method:"post",body:i},!0).then(e=>{e.success?(0,u.A)().then(()=>{window.location.pathname=`/admin/${s?.id}/databases`,setTimeout(()=>{a(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{a(!1)},1e3))})}async function m({e,setLoading:a,dbImage:t,keepUpdated:l,keepDataUpdated:s,query:i,user:d}){a(!0);let n={db_name:e.target.database_name.value,db_slug:e.target.database_slug.value,db_description:e.target.database_description?.value?.match(/./)?e.target.database_description.value:null};if(t){if("string"==typeof t)n.db_image=t;else if("object"==typeof t){let e=await (0,c.A)("/api/addUserMedia",{method:"post",body:{media:[t],folder:n.db_slug.replace(/_/g,"-"),type:"image"}},!0);n.db_image=e?.mediaData[0]?.media_thumbnail_url?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}i?.duplicate&&(n.duplicate=i.duplicate,n.keepUpdated=!!l&&l,n.keepDataUpdated=!!s&&s),(0,c.A)("/api/createUserDatabase",{method:"POST",body:n},!0).then(e=>{e.success?(0,u.A)().then(()=>{window.location.pathname=`/admin/${d?.id}/databases/${n.db_slug}`}):setTimeout(()=>{a(!1)},1e3)})}var p=t(2913);function b({user:e,dbImage:a,setDbImage:t,database:i,setLoading:c,query:u}){async function b(a){return i?.db_slug===a?null:await (0,n.A)({tableName:"user_databases",columnName:"db_slug",value:a,userId:e.id})}let[g,h]=d().useState(null),[f,_]=d().useState(!1),[x,w]=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:t=>{t.preventDefault(),i?o({e:t,setLoading:c,dbImage:a,database:i,user:e}):m({e:t,setLoading:c,dbImage:a,keepUpdated:f,keepDataUpdated:x,query:u,user:e})},children:[g&&(0,s.jsx)(r.A,{message:g}),(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"),h(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(()=>{b(e).then(e=>{e?.result?(t.database_slug.classList.add("warning"),h("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),h(null))})},300)}},defaultValue:i?i.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"),h(null)):a.classList.add("warning");let t=a.value;window.clearTimeout(l),l=setTimeout(()=>{b(t).then(e=>{e?.result?(a.classList.add("warning"),h("Duplicate Database Name")):(a.classList.remove("warning"),h(null))})},300)},defaultValue:i?i.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:i?i.db_description:""})]}),u?.duplicate&&(0,s.jsx)(d().Fragment,{children:(0,s.jsxs)("div",{className:"card col items-start",children:[(0,s.jsx)(p.A,{checkBoxValues:[{payload:"Keep New Database Updated?",title:"Keep New Database Updated?",name:"clone_database",onChangeHandler:e=>{e.target.checked?_(!0):_(!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:[i?"Update":"Create"," Database"]})]})}},89088:(e,a,t)=>{t.d(a,{A:()=>c});var l=t(8732),s=t(82015),i=t.n(s),d=t(65842),n=t(91140),r=t(55904);function c({user:e,dbImage:a,setDbImage:t,database:s}){let c=i().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:a?"string"==typeof a?a:a.imageBase64Full:"/images/database-placeholder.png",alt:"Database Image",width:100,className:"w-full h-full object-cover",ref:c,"data-imagepreview":"image"})}),(0,l.jsxs)("div",{className:"w-full flex-col",id:"edit-database-image-option-wrapper",children:[(0,l.jsxs)(r.A,{column:!0,className:"w-full",children:[(0,l.jsx)("button",{className:"outlined w-full whitespace-normal",onClick:e=>{(0,n.PB)("user-media-popup")},children:"Choose Image from uploads"}),(0,l.jsx)("button",{className:"outlined secondary w-full whitespace-normal",onClick:e=>{let a=e.target;a?.closest("#edit-database-image-option-wrapper")?.querySelector("input")?.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];t(await (0,d.A)({imageInputFile:a,maxWidth:400}))}})]})]})}},2913:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({name:e,checkBoxValues:a,setAlert:t,labelColor:s,flexRow:i,baseText:d,smallText:n,className:r}){return(0,l.jsx)("div",{className:"flex items-start gap-x-4"+(i?" flex-row flex-wrap gap-y-2 ":" flex-col gap-y-4 ")+(r||""),children:a.map((a,i)=>{let{payload:r,title:c,onChangeHandler:u,fixed:o,jsx:m}=a,p=a.name?`${e}-${a.name}`:r?e+"-"+r:e;return(0,l.jsxs)("div",{className:"flex items-center"+(a.default&&o?" pointer-events-none":"")+(n?" gap-1 ":" gap-2 ")+(a?.className?a.className:""),children:[(0,l.jsx)("input",{className:"m-0"+(n?" w-4 h-4":" w-5 h-5"),type:"checkbox",defaultChecked:!!a.default,name:p,id:p,onChange:e=>{t&&t(null),u&&u(e,a)},value:r,style:{minWidth:"20px"},...a.props}),m||(0,l.jsx)("label",{htmlFor:p,className:"m-0 "+(s||"text-slate-800 dark:text-white/80")+(d||n?" text-base":" text-lg"),children:c})]},i+1)})})}t(82015)},24872:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(46169);async function s({tableName:e,columnName:a,value:t,dbFullName:s,dispatch:i,userId:d,dbId:n}){return await (0,l.A)(`/api/checkDuplicateData?tableName=${e}&type=${a}&value=${t}${s?"&dbFullName="+s:""}${d?"&userId="+d:""}${n?"&dbId="+n:""}`)}}};