|
1
|
|
-var te=Object.defineProperty;var le=(o,C,e)=>C in o?te(o,C,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[C]=e;var O=(o,C,e)=>le(o,typeof C!="symbol"?C+"":C,e);import{h as p,r as y,e as m,o as d,b as S,d as u,F as q,a,t as f,u as l,w as n,f as j,q as ae,c as T,g as J,n as oe,l as se,v as ie,i as Q,z as ne,x as re,k as de}from"./vue.esm-bundler.js?ver=1.3.20";import{d as ue}from"./common.js?ver=1.3.20";import{I as X,S as ee}from"./IconButton.js?ver=1.3.20";import{_ as I}from"./DynamicIcon.js?ver=1.3.20";import{R as G}from"./Rest.js?ver=1.3.20";import{n as P}from"./Notify.js?ver=1.3.20";import{t as r}from"./Translator.js?ver=1.3.20";import{M as ce}from"./Model.js?ver=1.3.20";const ve={class:"fct-file-uploader-wrap"},fe={key:0,class:"fct-file-upload-rename"},pe={class:"fct-form-group"},me={for:"filename_input"},_e={style:{display:"flex","justify-content":"space-between"}},ge={key:0},he={class:"fct-btn-group sm fct-file-upload-rename-actions"},be={key:0,class:"fct-form-group"},ke={key:1,class:"fct-file-upload-list-empty"},ye={class:"el-upload__text"},Fe=["innerHTML"],Se={key:1,class:"fct-file-upload-progress"},we={class:"upload-progress-head"},Ue={class:"upload-progress-body"},Be={key:0,class:"fct-file-upload-name"},De={class:"fct-file-upload-text"},Ce={key:0},xe={__name:"FileUploader",props:{driver:String,storageDriverModel:Object},emits:["onUploaded"],setup(o,{expose:C,emit:e}){const s=o,w=e,x=p(),M=p(null),U=p(""),N=p(),_=p([]),g=p(!1),V=p(0),F=()=>window.fluentCartRestVars.rest.url+"/files/upload",A=()=>({name:U.value,driver:s.driver,bucket:x.value}),H=c=>c.name.length>160?(P.error(r("Filename too long. Maximum 160 characters allowed")),_.value=[],c.value=null,U.value="",g.value=!1,V.value=0,!1):!0,$=c=>{c!=null&&c.message&&P.success(c.message),_.value=[],N.value=null,U.value="",g.value=!1,V.value=0};C({reset:$});const R=c=>{N.value=c,U.value=c.name.replace(/\.[^/.]+$/,"")},K=()=>{M.value.handleRemove(N.value),$()},h=(c,b,k)=>{V.value=parseInt(c.percent+"")},t=(c,b,k)=>{var L,z;$(c),(z=(L=s.storageDriverModel)==null?void 0:L.fileUploaded)==null||z.call(L,c),w("onUploaded",c,b,k)},i=()=>{g.value=!0,M.value.submit()},D=c=>U.value+"."+c.split(".").pop(),E=()=>({"X-WP-Nonce":G.getNonce()});return(c,b)=>{const k=y("el-input"),L=y("el-button"),z=y("el-option"),W=y("el-select"),Y=y("el-upload"),v=y("el-progress");return d(),m("div",ve,[_.value.length>0?(d(),m(q,{key:0},[g.value?S("",!0):(d(),m("div",fe,[u("div",pe,[u("label",me,f(c.$t("File Name")),1),a(k,{id:"filename_input",modelValue:U.value,"onUpdate:modelValue":b[0]||(b[0]=B=>U.value=B)},null,8,["modelValue"]),u("div",_e,[u("div",null,[U.value.length>160?(d(),m("span",ge,f(l(r)("File name Must not exceed %s characters",160)),1)):S("",!0)]),u("div",null,f(U.value.length)+"/160 ",1)])]),u("div",he,[a(L,{type:"primary",onClick:i,disabled:U.value.length>160},{default:n(()=>[j(f(c.$t("Upload")),1)]),_:1},8,["disabled"]),a(X,{onClick:ae($,["prevent"]),tag:"button"},{default:n(()=>[a(I,{name:"Delete"})]),_:1})])]))],64)):S("",!0),u("div",{class:oe({hidden:_.value.length>0})},[o.storageDriverModel.hasBucket(o.driver)?(d(),m("div",be,[u("label",null,f(l(r)("Select Bucket")),1),a(W,{filterable:"",modelValue:x.value,"onUpdate:modelValue":b[1]||(b[1]=B=>x.value=B),placeholder:l(r)("Select"),"popper-class":"fct-bucket-list-popover"},{default:n(()=>[(d(!0),m(q,null,J(o.storageDriverModel.data.buckets[o.driver],(B,Z)=>(d(),T(z,{key:Z,label:B.label,value:B.value},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder"])])):S("",!0),o.storageDriverModel.hasBucket(o.driver)&&!x.value?(d(),m("div",ke,f(l(r)("Please select a bucket to upload files.")),1)):S("",!0),!o.storageDriverModel.hasBucket(o.driver)||x.value?(d(),T(Y,{key:2,class:"fct-file-uploader",ref_key:"uploaderRef",ref:M,data:A(),"file-list":_.value,"onUpdate:fileList":b[2]||(b[2]=B=>_.value=B),drag:"",action:F(),"on-progress":h,"on-success":t,"on-error":(B,Z,Xe)=>{B.toString().includes("Request Entity Too Large")?l(P).error(l(r)("File too large")):l(P).error(l(r)("Cant upload the file")),_.value=[],U.value="",g.value=!1,V.value=0},"auto-upload":!1,"on-change":R,multiple:!1,limit:1,"show-file-list":!1,headers:E(),"before-upload":H},{default:n(()=>[a(X,{circle:"",bg:"primary",soft:""},{default:n(()=>[a(I,{name:"Upload"})]),_:1}),u("div",ye,[u("span",{innerHTML:l(r)("Drag & Drop or %1$s Browse/Upload %2$s Files","<em>","</em>")},null,8,Fe),u("span",null,f(l(r)("Any Format upto %s",l(ee).serverMaxUploadSize())),1)])]),_:1},8,["data","file-list","action","on-error","headers"])):S("",!0)],2),g.value?(d(),m("div",Se,[u("div",we,[a(X,{bg:"info",soft:"",size:"small"},{default:n(()=>[a(I,{name:"Files"})]),_:1})]),u("div",Ue,[_.value.length>0?(d(),m("div",Be,f(D(_.value[0].name)),1)):S("",!0),a(v,{"stroke-width":5,percentage:V.value,striped:"","striped-flow":"",duration:40},{default:n(()=>[u("div",De,[_.value.length>0?(d(),m("span",Ce,f(l(ue)(_.value[0].size*(V.value/100),_.value[0].size)),1)):S("",!0),u("span",null,f(l(r)("%s% Uploaded",V.value)),1)])]),_:1},8,["percentage"])]),u("div",{class:"fct-file-upload-progress-cancel",onClick:K},[a(I,{name:"Close"})])])):S("",!0)])}}},Le={key:0,class:"fct-form-group"},Me={class:"fct-file-upload-search-wrap"},Ve={key:0},$e={key:1,class:"fct-file-upload-list"},ze={class:"file-name"},Ne={key:1},Re={key:2,class:"fct-file-upload-list-empty"},Te={__name:"FileList",props:{driver:String,buckets:Array,storageDriverModel:Object,multiple:{type:Boolean,default:!0}},emits:["onFileSelected"],setup(o,{emit:C}){const e=o,s=p([]),w=p(!1),x=()=>{w.value=!0,s.value=[],U.value=[],g([]),e.storageDriverModel.getFileList(e.driver,M.value,F.value).then(t=>{s.value=t}).catch(t=>{P.error(t)}).finally(()=>{w.value=!1})},M=p(""),U=p([]),N=p(!1),_=p(!1),g=t=>{_.value=!1;const i=t.map(D=>(D.name.length>185&&(_.value=!0),{name:D.name,size:D.size,bucket:D.bucket,driver:D.driver}));i.value=t,N.value=i.value.length>0,$("onFileSelected",i,_.value)},V=se(()=>s.value&&s.value.errors&&Object.keys(s.value.errors).length>0),F=p(""),A=p(null),H=t=>t.includes("_____fluent-cart_____")?t.split("_____fluent-cart_____")[0]:t.split("__fluent-cart__")[0];ie(()=>e.driver,()=>{g([])});const $=C,R=p(null),K=t=>{w.value=!0;const i=t.file;i.bucket!==F.value?(F.value=i.bucket,s.value=[i]):s.value.unshift(i),g([...U.value,i]),w.value=!1,re(()=>{R.value&&R.value.toggleRowSelection(t.file,!0)})};Q(()=>{e.storageDriverModel.hasBucket(e.driver)||x(),e.storageDriverModel.onFileUploaded(K,e.driver)});const h=async(t,i)=>{t.deleting=!0,await G.delete("files/delete",{file_path:t.name,driver:e.driver,bucket:F.value}).then(D=>{P.success(D.message),s.value.splice(i,1),g([])}).catch(D=>{P.error(D.message)}).finally(()=>{t.deleting=!1})};return(t,i)=>{const D=y("el-option"),E=y("el-select"),c=y("el-input"),b=y("el-table-column"),k=y("el-skeleton-item"),L=y("el-skeleton"),z=y("el-table"),W=y("el-radio"),Y=y("el-popconfirm");return d(),m(q,null,[o.storageDriverModel.hasBucket(o.driver)?(d(),m("div",Le,[u("label",null,f(l(r)("Select Bucket")),1),a(E,{filterable:"",clearable:"",modelValue:F.value,"onUpdate:modelValue":i[0]||(i[0]=v=>F.value=v),placeholder:l(r)("Type to search"),"popper-class":"fct-bucket-list-popover",onChange:x,disabled:w.value},{default:n(()=>[(d(!0),m(q,null,J(o.storageDriverModel.data.buckets[o.driver],(v,B)=>(d(),T(D,{key:B,label:v.label,value:v.value,loading:o.storageDriverModel.isBucketLoading(o.driver)},null,8,["label","value","loading"]))),128))]),_:1},8,["modelValue","placeholder","disabled"])])):S("",!0),!o.storageDriverModel.hasBucket(o.driver)||F.value&&o.storageDriverModel.isBucketLoaded(o.driver)?(d(),m(q,{key:1},[u("div",Me,[a(c,{modelValue:M.value,"onUpdate:modelValue":i[1]||(i[1]=v=>M.value=v),class:"fct-file-search-input",placeholder:l(r)("Search and hit enter"),clearable:"",onKeyup:i[2]||(i[2]=ne(()=>{x()},["enter"]))},null,8,["modelValue","placeholder"])]),w.value?(d(),m("div",Ve,[a(z,{data:[1,2,3,4,5]},{default:n(()=>[a(b,{type:"selection",width:"45"}),a(b,{label:l(r)("File Name")},{default:n(()=>[a(L,{animated:""},{template:n(()=>[a(k,{varient:"p",class:"max-w-[190px]"})]),_:1})]),_:1},8,["label"]),a(b,{label:l(r)("Size"),width:"150"},{default:n(()=>[a(L,{animated:""},{template:n(()=>[a(k,{varient:"p",class:"max-w-[100px]"})]),_:1})]),_:1},8,["label"])]),_:1})])):S("",!0),w.value?S("",!0):(d(),m("div",$e,[V.value?(d(),m("div",Ne,[u("p",null,f(l(r)("Error: Unable to load the file list.")),1)])):(d(),T(z,{key:0,ref_key:"tableRef",ref:R,data:s.value.filter(v=>v.size>0),onSelectionChange:g},{empty:n(()=>[u("span",null,f(l(r)("No file found.")),1)]),default:n(()=>[o.multiple?(d(),T(b,{key:0,type:"selection",width:"45",selectable:v=>!v.deleting&&v.size>0,onSelectionChange:g},null,8,["selectable"])):(d(),T(b,{key:1,label:"",width:"45"},{default:n(v=>[a(W,{modelValue:A.value,"onUpdate:modelValue":i[3]||(i[3]=B=>A.value=B),label:v.row,disabled:v.row.size==0,onChange:B=>g([v.row])},null,8,["modelValue","label","disabled","onChange"])]),_:1})),a(b,{label:l(r)("File Name")},{default:n(v=>[u("span",ze,f(H(v.row.name)),1)]),_:1},8,["label"]),a(b,{label:l(r)("Size"),width:"150"},{default:n(v=>[u("span",null,f(l(ee).readableFileSizeFromBytes(v.row.size)),1)]),_:1},8,["label"]),a(b,{label:l(r)("Actions"),width:"80"},{default:n(v=>[a(Y,{title:l(r)("Are you sure you want to delete this file? This action is not recoverable."),"confirm-button-text":l(r)("Yes, Confirm!"),"cancel-button-text":l(r)("Cancel"),onConfirm:B=>h(v.row,v.$index),width:"250","popper-class":"fct-delete-confirm-popover"},{reference:n(()=>[a(X,{size:"small",tag:"button",disabled:v.row.deleting},{default:n(()=>[a(I,{name:"Delete"})]),_:2},1032,["disabled"])]),_:2},1032,["title","confirm-button-text","cancel-button-text","onConfirm"])]),_:1},8,["label"])]),_:1},8,["data"]))]))],64)):S("",!0),!F.value&&o.storageDriverModel.hasBucket(o.driver)?(d(),m("div",Re,f(l(r)("Please select a bucket to view the files.")),1)):S("",!0)],64)}}};class Oe extends ce{constructor(){super(...arguments);O(this,"data",{drivers:{},selectedDriver:"",isDriversLoaded:!1,loadingDriver:!1,buckets:{},bucketLoadingStates:{},loadingFiles:!1,onFileUploadedCallbacks:{}});O(this,"getActiveDrivers",()=>{this.data.drivers=[],G.get("settings/storage-drivers/active-drivers").then(e=>{this.data.drivers=e.drivers,this.data.drivers.length>0&&(this.data.selectedDriver.value=this.data.drivers[0].route),Object.values(this.data.drivers).forEach(s=>{s.has_bucket&&(this.data.buckets[s.route]=s.buckets,this.data.bucketLoadingStates[s.route]=!0)})}).catch(e=>{console.log(e,"errors")}).finally(()=>{this.data.isDriversLoaded=!0})});O(this,"getBuckets",e=>this.data.bucketLoadingStates[e]===!1?(this.loadBucketList(e),[]):this.data.buckets[e]?this.data.buckets[e]:[]);O(this,"loadBucketList",e=>{this.isBucketLoaded(e)||this.isBucketLoading(e)||(this.data.bucketLoadingStates[e]="loading",G.get("files/bucket-list",{driver:e}).then(s=>{this.data.bucketLoadingStates[e]=!0,this.data.buckets[e]=s.buckets}).catch(s=>{this.data.bucketLoadingStates[e]=!1}).finally(()=>{}))});O(this,"getFileList",async(e,s="",w)=>{if(s=s.trim(),this.hasBucket(e)&&!w)return[];let x=[];return this.data.loadingFiles=!0,await G.get("files",{driver:e,activeBucket:w,search:s}).then(M=>{x=M.files}).catch(M=>{P.error(M)}).finally(()=>{this.data.loadingFiles=!1}),x});O(this,"onFileUploaded",(e,s)=>{typeof e=="function"&&!this.data.onFileUploadedCallbacks.hasOwnProperty(s)&&(this.data.onFileUploadedCallbacks[s]=e)});O(this,"fileUploaded",e=>{const s=e.file.driver;!s||!this.data.onFileUploadedCallbacks.hasOwnProperty(s)||typeof this.data.onFileUploadedCallbacks[s]=="function"&&this.data.onFileUploadedCallbacks[s](e)})}get drivers(){return Object.values(this.data.drivers)}hasBucket(e){return this.data.buckets.hasOwnProperty(e)}isBucketLoading(e){return this.data.bucketLoadingStates[e]==="loading"}isBucketLoaded(e){return this.data.bucketLoadingStates[e]===!0}}function Ie(){return Oe.init()}const Pe={class:"fct-driver-wrap"},Ee={class:"fct-driver-content"},Ae={key:0,class:"empty-driver-text"},je={class:"fct-driver-tabs-label"},qe={class:"fct-driver-arrow-icon"},He={class:"fct-driver-tabs-label"},Ke={key:0},Ge={class:"fct-driver-tabs-label"},We={key:0,class:"dialog-footer"},it={__name:"FileUploaderDialog",props:{isDisabled:String,uploadBtnText:{default:r("Choose File")},uploadBtnIcon:{default:"Upload"},uploadBtnSize:{type:String,default:"large"},isMultiple:{type:Boolean,default:!0}},emits:["onUploaded","onFileSelected"],setup(o,{emit:C}){const e=o,s=C,w=p(!1),x=p(),M=de().ctx,U=p([]),N=p("local"),_=p([]),g=[];p(!1);const V=p(!1),F=Ie();Q(()=>{F.getActiveDrivers()});const A=h=>{N.value=h,F.getBuckets(h)},H=()=>{if(!g.value||g.value.length===0){M.handleMessage(r("Please select a file"),"error","fct-file-upload-message");return}if(_.value=[],e.isMultiple)g.value.forEach(h=>{const t=h.name;let i=t.split("_____fluent-cart_____")[0];i=i.split("__fluent-cart__")[0],_.value.push({id:"",title:i,type:t.slice(t.lastIndexOf(".")+1),driver:h.driver,bucket:h.bucket,file_name:t,file_size:h.size,settings:{download_limit:"",download_expiry:"",bucket:h.bucket},serial:""})});else{const h=g.value[0],t=h.name;let i=t.split("_____fluent-cart_____")[0];i=i.split("__fluent-cart__")[0],_.value.push({id:"",title:i,type:t.slice(t.lastIndexOf(".")+1),driver:h.driver,bucket:h.bucket,file_name:t,file_size:h.size,settings:{download_limit:"",download_expiry:"",bucket:h.bucket},serial:""})}w.value=!1,V.value=!1,s("onFileSelected",_)},$=p("list"),R=p(!1),K=(h,t)=>{g.value=h,V.value=g.value.length>0,R.value=t};return(h,t)=>{const i=y("el-button"),D=y("router-link"),E=y("el-tab-pane"),c=y("el-tabs"),b=y("el-dialog");return d(),m("div",Pe,[a(i,{class:"fct-upload-btn",type:"info",plain:"",onClick:t[0]||(t[0]=k=>w.value=!0),disabled:o.isDisabled,size:o.uploadBtnSize},{default:n(()=>[o.uploadBtnIcon?(d(),T(I,{key:0,name:o.uploadBtnIcon},null,8,["name"])):S("",!0),j(" "+f(o.uploadBtnText),1)]),_:1},8,["disabled","size"]),a(b,{modelValue:w.value,"onUpdate:modelValue":t[6]||(t[6]=k=>w.value=k),"append-to-body":!0,title:l(r)("Storage Providers"),"modal-class":"fct-file-upload-dialog",onClose:()=>{}},{default:n(()=>[u("div",Ee,[l(F).drivers.length<1?(d(),m("span",Ae,[j(f(l(r)("No active storage provider found!"))+" ",1),a(D,{to:"/settings/storage"},{default:n(()=>[j(f(l(r)("Go to setting to active")),1)]),_:1})])):S("",!0),l(F).drivers.length>0?(d(),T(c,{key:1,class:"fct-driver-tabs",modelValue:N.value,"onUpdate:modelValue":t[4]||(t[4]=k=>N.value=k),"tab-position":"left",onTabChange:A},{default:n(()=>[(d(!0),m(q,null,J(l(F).drivers,k=>(d(),T(E,{name:k.route,key:k.route},{label:n(()=>[u("div",je,[a(I,{name:k.title==="S3"?"FolderCloud":"Folder"},null,8,["name"]),u("span",null,f(k.title),1),u("div",qe,[a(I,{name:"ChevronRight"})])])]),default:n(()=>[a(c,{modelValue:$.value,"onUpdate:modelValue":t[3]||(t[3]=L=>$.value=L),class:"fct-file-tabs","tab-position":"top"},{default:n(()=>[a(E,{name:"list"},{label:n(()=>[u("div",He,f(l(r)("Select Files")),1)]),default:n(()=>[a(Te,{storageDriverModel:l(F),buckets:U.value,driver:k.route,onOnFileSelected:t[1]||(t[1]=(L,z)=>{K(L,z)}),multiple:o.isMultiple},null,8,["storageDriverModel","buckets","driver","multiple"]),R.value?(d(),m("span",Ke,f(l(r)("File name must not exceed %s characters",160)),1)):S("",!0)]),_:2},1024),a(E,{name:"upload"},{label:n(()=>[u("div",Ge,f(l(r)("Upload")),1)]),default:n(()=>[a(xe,{storageDriverModel:l(F),onOnUploaded:t[2]||(t[2]=(L,z,W)=>{$.value="list"}),driver:k.route,ref_for:!0,ref:k.route==="local"?x.value:""},null,8,["storageDriverModel","driver"])]),_:2},1024)]),_:2},1032,["modelValue"])]),_:2},1032,["name"]))),128))]),_:1},8,["modelValue"])):S("",!0)]),l(F).drivers.length>0?(d(),m("div",We,[a(i,{onClick:t[5]||(t[5]=k=>w.value=!1),type:"info",soft:""},{default:n(()=>[j(f(l(r)("Cancel")),1)]),_:1}),a(i,{type:"primary",onClick:H,disabled:!V.value||R.value},{default:n(()=>[j(f(l(r)("Confirm")),1)]),_:1},8,["disabled"])])):S("",!0)]),_:1},8,["modelValue","title"])])}}};export{it as _}; |
|
1
|
+var ee=Object.defineProperty;var te=(r,C,e)=>C in r?ee(r,C,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[C]=e;var R=(r,C,e)=>te(r,typeof C!="symbol"?C+"":C,e);import{h as p,l as J,r as k,e as S,o as c,b as w,d as u,F as Y,a as l,t as m,u as a,w as o,f as j,q as le,c as B,n as ae,v as se,i as Z,z as oe,x as ne,k as ie,g as re}from"./vue.esm-bundler.js?ver=1.6.5";import{S as Q,e as de}from"./common.js?ver=1.6.5";import{I as W}from"./IconButton.js?ver=1.6.5";import{_ as N}from"./DynamicIcon.js?ver=1.6.5";import{R as X}from"./Rest.js?ver=1.6.5";import{n as T}from"./Notify.js?ver=1.6.5";import{t as n}from"./Translator.js?ver=1.6.5";import{M as ue}from"./Model.js?ver=1.6.5";const ce={class:"fct-file-uploader-wrap"},fe={key:0,class:"fct-file-upload-rename"},ve={class:"fct-form-group"},pe={for:"filename_input"},_e={style:{display:"flex","justify-content":"space-between"}},me={key:0},ge={class:"fct-btn-group sm fct-file-upload-rename-actions"},he={class:"el-upload__text"},be=["innerHTML"],ke={key:1,class:"fct-file-upload-progress"},ye={class:"upload-progress-head"},Fe={class:"upload-progress-body"},we={key:0,class:"fct-file-upload-name"},Se={class:"fct-file-upload-text"},Ue={key:0},P=160,Ce={__name:"FileUploader",props:{driver:String,storageDriverModel:Object},emits:["onUploaded"],setup(r,{expose:C,emit:e}){const s=r,y=e,L=p(null),U=p(""),M=p(),b=p([]),F=p(!1),h=p(0),x=J(()=>{const d=U.value.length;return d>0&&d<=P}),A=()=>window.fluentCartRestVars.rest.url+"/files/upload",H=()=>({name:U.value,driver:s.driver}),E=()=>x.value?!0:(T.error(n("Filename too long. Maximum %1$s characters allowed",P)),F.value=!1,h.value=0,!1),$=d=>{d!=null&&d.message&&T.success(d.message),b.value=[],M.value=null,U.value="",F.value=!1,h.value=0};C({reset:$});const q=d=>{M.value=d;const i=d.name.replace(/\.[^/.]+$/,"");i.length>P?U.value=i.slice(0,P):U.value=i},_=()=>{L.value.handleRemove(M.value),$()},t=(d,i,z)=>{h.value=parseInt(d.percent+"")},v=(d,i,z)=>{var V,O;$(d),(O=(V=s.storageDriverModel)==null?void 0:V.fileUploaded)==null||O.call(V,d),y("onUploaded",d,i,z)},f=()=>{F.value=!0,L.value.submit()},I=d=>U.value+"."+d.split(".").pop(),D=()=>({"X-WP-Nonce":X.getNonce()});return(d,i)=>{const z=k("el-input"),V=k("el-button"),O=k("el-alert"),g=k("el-upload"),G=k("el-progress");return c(),S("div",ce,[b.value.length>0?(c(),S(Y,{key:0},[F.value?w("",!0):(c(),S("div",fe,[u("div",ve,[u("label",pe,m(d.$t("File Name")),1),l(z,{id:"filename_input",modelValue:U.value,"onUpdate:modelValue":i[0]||(i[0]=K=>U.value=K),maxlength:P},null,8,["modelValue"]),u("div",_e,[u("div",null,[x.value?w("",!0):(c(),S("span",me,m(a(n)("File name Must not exceed %s characters",P)),1))]),u("div",null,m(U.value.length)+"/"+m(P),1)])]),u("div",ge,[l(V,{type:"primary",onClick:f,disabled:!x.value},{default:o(()=>[j(m(d.$t("Upload")),1)]),_:1},8,["disabled"]),l(W,{onClick:le($,["prevent"]),tag:"button"},{default:o(()=>[l(N,{name:"Delete"})]),_:1})])]))],64)):w("",!0),u("div",{class:ae({hidden:b.value.length>0})},[r.storageDriverModel.needsReconfigure(r.driver)?(c(),B(O,{key:0,type:"warning",closable:!1,title:a(n)("S3 needs to be reconfigured. Please go to S3 settings and re-save your bucket selection."),"show-icon":"",class:"mb-3"},null,8,["title"])):w("",!0),r.storageDriverModel.needsReconfigure(r.driver)?w("",!0):(c(),B(g,{key:1,class:"fct-file-uploader",ref_key:"uploaderRef",ref:L,data:H(),"file-list":b.value,"onUpdate:fileList":i[1]||(i[1]=K=>b.value=K),drag:"",action:A(),"on-progress":t,"on-success":v,"on-error":(K,He,qe)=>{K.toString().includes("Request Entity Too Large")?a(T).error(a(n)("File too large")):a(T).error(a(n)("Cant upload the file")),b.value=[],U.value="",F.value=!1,h.value=0},"auto-upload":!1,"on-change":q,multiple:!1,limit:1,"show-file-list":!1,headers:D(),"before-upload":E},{default:o(()=>[l(W,{circle:"",bg:"primary",soft:""},{default:o(()=>[l(N,{name:"Upload"})]),_:1}),u("div",he,[u("span",{innerHTML:a(n)("Drag & Drop or %1$s Browse/Upload %2$s Files","<em>","</em>")},null,8,be),u("span",null,m(a(n)("Any Format upto %s",a(Q).serverMaxUploadSize())),1)])]),_:1},8,["data","file-list","action","on-error","headers"]))],2),F.value?(c(),S("div",ke,[u("div",ye,[l(W,{bg:"info",soft:"",size:"small"},{default:o(()=>[l(N,{name:"Files"})]),_:1})]),u("div",Fe,[b.value.length>0?(c(),S("div",we,m(I(b.value[0].name)),1)):w("",!0),l(G,{"stroke-width":5,percentage:h.value,striped:"","striped-flow":"",duration:40},{default:o(()=>[u("div",Se,[b.value.length>0?(c(),S("span",Ue,m(a(de)(b.value[0].size*(h.value/100),b.value[0].size)),1)):w("",!0),u("span",null,m(a(n)("%1$s Uploaded",`${h.value}%`)),1)])]),_:1},8,["percentage"])]),u("div",{class:"fct-file-upload-progress-cancel",onClick:_},[l(N,{name:"Close"})])])):w("",!0)])}}},xe={class:"fct-file-upload-search-wrap"},De={key:0},Le={key:1,class:"fct-file-upload-list"},Me={class:"file-name"},$e={key:1},ze={__name:"FileList",props:{driver:String,buckets:Array,storageDriverModel:Object,multiple:{type:Boolean,default:!0}},emits:["onFileSelected"],setup(r,{emit:C}){const e=r,s=p([]),y=p(!1),L=()=>{y.value=!0,s.value=[],M.value=[],h([]),e.storageDriverModel.getFileList(e.driver,U.value).then(t=>{s.value=t}).catch(t=>{T.error(t)}).finally(()=>{y.value=!1})},U=p(""),M=p([]),b=p(!1),F=p(!1),h=t=>{F.value=!1;const v=t.map(f=>(f.name.length>185&&(F.value=!0),{name:f.name,path:f.path||f.name,size:f.size,bucket:f.bucket,driver:f.driver}));M.value=t,b.value=M.value.length>0,E("onFileSelected",v,F.value)},x=J(()=>s.value&&s.value.errors&&Object.keys(s.value.errors).length>0),A=p(null),H=t=>t.includes("_____fluent-cart_____")?t.split("_____fluent-cart_____")[0]:t.split("__fluent-cart__")[0];se(()=>e.driver,()=>{h([])});const E=C,$=p(null),q=t=>{y.value=!0;const v=t.file;s.value.unshift(v),h([...M.value,v]),y.value=!1,ne(()=>{$.value&&$.value.toggleRowSelection(t.file,!0)})};Z(()=>{e.storageDriverModel.needsReconfigure(e.driver)||L(),e.storageDriverModel.onFileUploaded(q,e.driver)});const _=async(t,v)=>{t.deleting=!0,await X.delete("files/delete",{file_path:t.path||t.name,driver:e.driver,bucket:t.bucket||""}).then(f=>{T.success(f.message),s.value.splice(v,1),h([])}).catch(f=>{T.error(f.message)}).finally(()=>{t.deleting=!1})};return(t,v)=>{const f=k("el-alert"),I=k("el-input"),D=k("el-table-column"),d=k("el-skeleton-item"),i=k("el-skeleton"),z=k("el-table"),V=k("el-radio"),O=k("el-popconfirm");return c(),S(Y,null,[r.storageDriverModel.needsReconfigure(r.driver)?(c(),B(f,{key:0,type:"warning",closable:!1,title:a(n)("S3 needs to be reconfigured. Please go to S3 settings and re-save your bucket selection."),"show-icon":""},null,8,["title"])):w("",!0),r.storageDriverModel.needsReconfigure(r.driver)?w("",!0):(c(),S(Y,{key:1},[u("div",xe,[l(I,{modelValue:U.value,"onUpdate:modelValue":v[0]||(v[0]=g=>U.value=g),class:"fct-file-search-input",placeholder:a(n)("Search and hit enter"),clearable:"",onKeyup:v[1]||(v[1]=oe(()=>{L()},["enter"]))},null,8,["modelValue","placeholder"])]),y.value?(c(),S("div",De,[l(z,{data:[1,2,3,4,5]},{default:o(()=>[l(D,{type:"selection",width:"45"}),l(D,{label:a(n)("File Name")},{default:o(()=>[l(i,{animated:""},{template:o(()=>[l(d,{varient:"p",class:"max-w-[190px]"})]),_:1})]),_:1},8,["label"]),l(D,{label:a(n)("Size"),width:"150"},{default:o(()=>[l(i,{animated:""},{template:o(()=>[l(d,{varient:"p",class:"max-w-[100px]"})]),_:1})]),_:1},8,["label"])]),_:1})])):w("",!0),y.value?w("",!0):(c(),S("div",Le,[x.value?(c(),S("div",$e,[u("p",null,m(a(n)("Error: Unable to load the file list.")),1)])):(c(),B(z,{key:0,ref_key:"tableRef",ref:$,data:s.value.filter(g=>g.size>0),onSelectionChange:h},{empty:o(()=>[u("span",null,m(a(n)("No file found.")),1)]),default:o(()=>[r.multiple?(c(),B(D,{key:0,type:"selection",width:"45",selectable:g=>!g.deleting&&g.size>0,onSelectionChange:h},null,8,["selectable"])):(c(),B(D,{key:1,label:"",width:"45"},{default:o(g=>[l(V,{modelValue:A.value,"onUpdate:modelValue":v[2]||(v[2]=G=>A.value=G),label:g.row,disabled:g.row.size==0,onChange:G=>h([g.row])},null,8,["modelValue","label","disabled","onChange"])]),_:1})),l(D,{label:a(n)("File Name")},{default:o(g=>[u("span",Me,m(H(g.row.path||g.row.name)),1)]),_:1},8,["label"]),l(D,{label:a(n)("Size"),width:"150"},{default:o(g=>[u("span",null,m(a(Q).readableFileSizeFromBytes(g.row.size)),1)]),_:1},8,["label"]),l(D,{label:a(n)("Actions"),width:"80"},{default:o(g=>[l(O,{title:a(n)("Are you sure you want to delete this file? This action is not recoverable."),"confirm-button-text":a(n)("Yes, Confirm!"),"cancel-button-text":a(n)("Cancel"),onConfirm:G=>_(g.row,g.$index),width:"250","popper-class":"fct-delete-confirm-popover"},{reference:o(()=>[l(W,{size:"small",tag:"button",disabled:g.row.deleting},{default:o(()=>[l(N,{name:"Delete"})]),_:2},1032,["disabled"])]),_:2},1032,["title","confirm-button-text","cancel-button-text","onConfirm"])]),_:1},8,["label"])]),_:1},8,["data"]))]))],64))],64)}}};class Ve extends ue{constructor(){super(...arguments);R(this,"data",{drivers:{},selectedDriver:"",isDriversLoaded:!1,loadingDriver:!1,buckets:{},bucketLoadingStates:{},needsReconfigure:{},loadingFiles:!1,onFileUploadedCallbacks:{}});R(this,"getActiveDrivers",()=>{this.data.drivers=[],X.get("settings/storage-drivers/active-drivers").then(e=>{this.data.drivers=e.drivers,this.data.drivers.length>0&&(this.data.selectedDriver.value=this.data.drivers[0].route),Object.values(this.data.drivers).forEach(s=>{s.has_bucket&&(this.data.buckets[s.route]=s.buckets,this.data.bucketLoadingStates[s.route]=!0,this.data.needsReconfigure[s.route]=!!s.need_reconfigure)})}).catch(e=>{}).finally(()=>{this.data.isDriversLoaded=!0})});R(this,"getBuckets",e=>this.data.bucketLoadingStates[e]===!1?(this.loadBucketList(e),[]):this.data.buckets[e]?this.data.buckets[e]:[]);R(this,"loadBucketList",e=>{this.isBucketLoaded(e)||this.isBucketLoading(e)||(this.data.bucketLoadingStates[e]="loading",X.get("files/bucket-list",{driver:e}).then(s=>{this.data.bucketLoadingStates[e]=!0,this.data.buckets[e]=s.buckets}).catch(s=>{this.data.bucketLoadingStates[e]=!1}).finally(()=>{}))});R(this,"getFileList",async(e,s="")=>{if(s=s.trim(),this.hasBucket(e)&&this.needsReconfigure(e))return[];let y=[];return this.data.loadingFiles=!0,await X.get("files",{driver:e,search:s}).then(L=>{y=L.files}).catch(L=>{T.error(L)}).finally(()=>{this.data.loadingFiles=!1}),y});R(this,"onFileUploaded",(e,s)=>{typeof e=="function"&&!this.data.onFileUploadedCallbacks.hasOwnProperty(s)&&(this.data.onFileUploadedCallbacks[s]=e)});R(this,"fileUploaded",e=>{const s=e.file.driver;!s||!this.data.onFileUploadedCallbacks.hasOwnProperty(s)||typeof this.data.onFileUploadedCallbacks[s]=="function"&&this.data.onFileUploadedCallbacks[s](e)})}get drivers(){return Object.values(this.data.drivers)}hasBucket(e){return this.data.buckets.hasOwnProperty(e)}needsReconfigure(e){return!!this.data.needsReconfigure[e]}isBucketLoading(e){return this.data.bucketLoadingStates[e]==="loading"}isBucketLoaded(e){return this.data.bucketLoadingStates[e]===!0}}function Be(){return Ve.init()}const Re={class:"fct-driver-wrap"},Ne={class:"fct-driver-content"},Te={key:0,class:"empty-driver-text"},Ee={class:"fct-driver-tabs-label"},Ie={class:"fct-driver-arrow-icon"},Oe={class:"fct-driver-tabs-label"},Pe={key:0},Ae={class:"fct-driver-tabs-label"},je={key:0,class:"dialog-footer"},lt={__name:"FileUploaderDialog",props:{isDisabled:String,uploadBtnText:{default:n("Choose File")},uploadBtnIcon:{default:"Upload"},uploadBtnSize:{type:String,default:"large"},isMultiple:{type:Boolean,default:!0}},emits:["onUploaded","onFileSelected"],setup(r,{emit:C}){const e=r,s=C,y=p(!1),L=p(),U=ie().ctx,M=p("local"),b=p([]),F=p([]);p(!1);const h=p(!1),x=Be();Z(()=>{x.getActiveDrivers()});const A=_=>{M.value=_},H=()=>{if(!F.value||F.value.length===0){U.handleMessage(n("Please select a file"),"error","fct-file-upload-message");return}if(b.value=[],e.isMultiple)F.value.forEach(_=>{const t=_.name,v=_.path||t;let f=t.split("_____fluent-cart_____")[0];f=f.split("__fluent-cart__")[0],b.value.push({id:"",title:f,type:t.slice(t.lastIndexOf(".")+1),driver:_.driver,bucket:_.bucket,file_name:t,file_path:v,file_size:_.size,settings:{download_limit:"",download_expiry:"",bucket:_.bucket},serial:""})});else{const _=F.value[0],t=_.name,v=_.path||t;let f=t.split("_____fluent-cart_____")[0];f=f.split("__fluent-cart__")[0],b.value.push({id:"",title:f,type:t.slice(t.lastIndexOf(".")+1),driver:_.driver,bucket:_.bucket,file_name:t,file_path:v,file_size:_.size,settings:{download_limit:"",download_expiry:"",bucket:_.bucket},serial:""})}y.value=!1,h.value=!1,s("onFileSelected",b.value)},E=p("list"),$=p(!1),q=(_,t)=>{F.value=_,h.value=F.value.length>0,$.value=t};return(_,t)=>{const v=k("el-button"),f=k("router-link"),I=k("el-tab-pane"),D=k("el-tabs"),d=k("el-dialog");return c(),S("div",Re,[l(v,{class:"fct-upload-btn",type:"info",plain:"",onClick:t[0]||(t[0]=i=>y.value=!0),disabled:r.isDisabled,size:r.uploadBtnSize},{default:o(()=>[r.uploadBtnIcon?(c(),B(N,{key:0,name:r.uploadBtnIcon},null,8,["name"])):w("",!0),j(" "+m(r.uploadBtnText),1)]),_:1},8,["disabled","size"]),l(d,{modelValue:y.value,"onUpdate:modelValue":t[6]||(t[6]=i=>y.value=i),"append-to-body":!0,title:a(n)("Storage Providers"),"modal-class":"fct-file-upload-dialog",onClose:()=>{}},{default:o(()=>[u("div",Ne,[a(x).drivers.length<1?(c(),S("span",Te,[j(m(a(n)("No active storage provider found!"))+" ",1),l(f,{to:"/settings/storage"},{default:o(()=>[j(m(a(n)("Go to setting to active")),1)]),_:1})])):w("",!0),a(x).drivers.length>0?(c(),B(D,{key:1,class:"fct-driver-tabs",modelValue:M.value,"onUpdate:modelValue":t[4]||(t[4]=i=>M.value=i),"tab-position":"left",onTabChange:A},{default:o(()=>[(c(!0),S(Y,null,re(a(x).drivers,i=>(c(),B(I,{name:i.route,key:i.route},{label:o(()=>[u("div",Ee,[l(N,{name:i.title==="S3"?"FolderCloud":"Folder"},null,8,["name"]),u("span",null,m(i.title),1),u("div",Ie,[l(N,{name:"ChevronRight"})])])]),default:o(()=>[l(D,{modelValue:E.value,"onUpdate:modelValue":t[3]||(t[3]=z=>E.value=z),class:"fct-file-tabs","tab-position":"top"},{default:o(()=>[l(I,{name:"list"},{label:o(()=>[u("div",Oe,m(a(n)("Select Files")),1)]),default:o(()=>[l(ze,{storageDriverModel:a(x),driver:i.route,onOnFileSelected:t[1]||(t[1]=(z,V)=>{q(z,V)}),multiple:r.isMultiple},null,8,["storageDriverModel","driver","multiple"]),$.value?(c(),S("span",Pe,m(a(n)("File name must not exceed %s characters",160)),1)):w("",!0)]),_:2},1024),l(I,{name:"upload"},{label:o(()=>[u("div",Ae,m(a(n)("Upload")),1)]),default:o(()=>[l(Ce,{storageDriverModel:a(x),onOnUploaded:t[2]||(t[2]=(z,V,O)=>{E.value="list"}),driver:i.route,ref_for:!0,ref:i.route==="local"?L.value:""},null,8,["storageDriverModel","driver"])]),_:2},1024)]),_:2},1032,["modelValue"])]),_:2},1032,["name"]))),128))]),_:1},8,["modelValue"])):w("",!0)]),a(x).drivers.length>0?(c(),S("div",je,[l(v,{onClick:t[5]||(t[5]=i=>y.value=!1),type:"info",soft:""},{default:o(()=>[j(m(a(n)("Cancel")),1)]),_:1}),l(v,{type:"primary",onClick:H,disabled:!h.value||$.value},{default:o(()=>[j(m(a(n)("Confirm")),1)]),_:1},8,["disabled"])])):w("",!0)]),_:1},8,["modelValue","title"])])}}};export{lt as _}; |