dsql-admin/dsql-app/.local_dist/static/chunks/6272-34d9d0c839440fe4.js
Benjamin Toby 81cf010cb5 Updates
2025-01-14 16:27:08 +01:00

1 line
8.1 KiB
JavaScript

"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6272],{7168:(e,a,t)=>{let l;t.d(a,{A:()=>g});var s=t(4848),i=t(6540),d=t(8589),n=t(6234),c=t(9020),o=t(65);async function r(e){var a,t,l,s,i,d,n;let{e:r,setLoading:u,dbImage:m,database:p,user:b}=e;u(!0);let g={db_description:(null===(t=r.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?r.target.database_description.value:null,db_name:(null===(s=r.target.database_name)||void 0===s?void 0:null===(l=s.value)||void 0===l?void 0:l.match(/./))?r.target.database_name.value:null,db_slug:(null===(d=r.target.database_slug)||void 0===d?void 0:null===(i=d.value)||void 0===i?void 0:i.match(/./))?r.target.database_slug.value:null,db_full_name:p.db_full_name,id:p.id,active_clone:p.active_clone,active_clone_parent_db:p.active_clone_parent_db};if(m){if("string"==typeof m)g.db_image=m;else if("object"==typeof m){let e=await (0,c.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,c.A)("/api/updateUserDatabase",{method:"post",body:g},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname="/admin/".concat(null==b?void 0:b.id,"/databases"),setTimeout(()=>{u(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{u(!1)},1e3))})}var u=t(1335);let m=t.n(u)().fetch.fetchApi;async function p(e){var a,t,l;let{e:s,setLoading:i,dbImage:d,keepUpdated:n,keepDataUpdated:c,query:r,user:u}=e;i(!0);let p={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(d){if("string"==typeof d)p.db_image=d;else if("object"==typeof d){let e=await m("/api/addUserMedia",{method:"post",body:{media:[d],folder:p.db_slug.replace(/_/g,"-"),type:"image"}},!0);p.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==r?void 0:r.duplicate)&&(p.duplicate=r.duplicate,p.keepUpdated=!!n&&n,p.keepDataUpdated=!!c&&c),m("/api/createUserDatabase",{method:"POST",body:p},!0).then(e=>{e.success?(0,o.A)().then(()=>{window.location.pathname="/admin/".concat(null==u?void 0:u.id,"/databases/").concat(p.db_slug)}):setTimeout(()=>{i(!1)},1e3)})}var b=t(2408);function g(e){let{user:a,dbImage:t,setDbImage:c,database:o,setLoading:u,query:m}=e;async function g(e){return(null==o?void 0:o.db_slug)===e?null:await (0,d.A)({tableName:"user_databases",columnName:"db_slug",value:e,userId:a.id})}let[h,v]=i.useState(null),[f,_]=i.useState(!1),[x,w]=i.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(),o?r({e,setLoading:u,dbImage:t,database:o,user:a}):p({e,setLoading:u,dbImage:t,keepUpdated:f,keepDataUpdated:x,query:m,user:a})},children:[h&&(0,s.jsx)(n.A,{message:h}),(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:o?o.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:o?o.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:o?o.db_description:""})]}),(null==m?void 0:m.duplicate)&&(0,s.jsx)(i.Fragment,{children:(0,s.jsxs)("div",{className:"card col items-start",children:[(0,s.jsx)(b.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:[o?"Update":"Create"," Database"]})]})}},3605:(e,a,t)=>{t.d(a,{A:()=>c});var l=t(4848),s=t(6540),i=t(2659),d=t(5655),n=t(900);function c(e){let{user:a,dbImage:t,setDbImage:c,database:o}=e,r=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:r,"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,d.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=>{var a;let t=null===(a=e.target.files)||void 0===a?void 0:a[0];c(await (0,i.A)({imageInputFile:t,maxWidth:400}))}})]})]})}},2408:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(4848);function s(e){let{name:a,checkBoxValues:t,setAlert:s,labelColor:i,flexRow:d,baseText:n,smallText:c,className:o}=e;return(0,l.jsx)("div",{className:"flex items-start gap-x-4"+(d?" flex-row flex-wrap gap-y-2 ":" flex-col gap-y-4 ")+(o||""),children:t.map((e,t)=>{let{payload:d,title:o,onChangeHandler:r,fixed:u,jsx:m}=e,p=e.name?"".concat(a,"-").concat(e.name):d?a+"-"+d:a;return(0,l.jsxs)("div",{className:"flex items-center"+(e.default&&u?" pointer-events-none":"")+(c?" gap-1 ":" gap-2 ")+((null==e?void 0:e.className)?e.className:""),children:[(0,l.jsx)("input",{className:"m-0"+(c?" w-4 h-4":" w-5 h-5"),type:"checkbox",defaultChecked:!!e.default,name:p,id:p,onChange:a=>{s&&s(null),r&&r(a,e)},value:d,style:{minWidth:"20px"},...e.props}),m||(0,l.jsx)("label",{htmlFor:p,className:"m-0 "+(i||"text-slate-800 dark:text-white/80")+(n||c?" text-base":" text-lg"),children:o})]},t+1)})})}t(6540)},8589:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(9020);async function s(e){let{tableName:a,columnName:t,value:s,dbFullName:i,dispatch:d,userId:n,dbId:c}=e;return await (0,l.A)("/api/checkDuplicateData?tableName=".concat(a,"&type=").concat(t,"&value=").concat(s).concat(i?"&dbFullName="+i:"").concat(n?"&userId="+n:"").concat(c?"&dbId="+c:""))}}}]);