File manager - Edit - /home/autoph/.trash/assets/index-90689d84.js
Back
import{C as x}from"./ProposalService-5c26a38a.js";import{L as A}from"./index-77d1df54.js";import{B as T}from"./index-749eb373.js";import{I as q}from"./index-ce1a8b93.js";import{_ as R,r as i,o as s,c as f,g as m,b as a,f as r,w as j,e as u,d as h,I as g,h as v,J as D}from"./index-3ad01394.js";import{C as N,E as G,D as z}from"./DeleteButton-d97e7094.js";import{V as L}from"./ViewButton-0380d719.js";/* empty css */import{L as O}from"./Loading-cf989e31.js";import{I as Q}from"./index-e8bb200d.js";import{F as I}from"./index-a9f8494f.js";import{S as Y,U as H}from"./UpdateButton-4a93f10c.js";import{C as J}from"./CloseButton-7091266e.js";import{F as W,l as K}from"./lodash-8d7fbae2.js";import{T as X}from"./index-72a8b0b2.js";import{T as Z}from"./index-3d1d64ac.js";import{c as $,a as E,e as ee,f as te,V as oe}from"./array-2d279bb5.js";import{S as se}from"./SupplierService-d05f52f1.js";import{F as k}from"./FileService-438217d5.js";import{M as ie}from"./Multiselect-76dc7c6f.js";import{f as re}from"./file-type-pdf-a9709057.js";import{f as ne}from"./file-type-excel-3a83eaab.js";import{P as le}from"./index-7e82e20c.js";import"./vue-cleave.min-5b24c519.js";import"./_commonjsHelpers-de833af9.js";import"./xhebrhsj-6516ec76.js";import"./es.string.replace-2e300990.js";const ae=5e3*1024,ce={components:{FormModal:I,FormGroup:W,TextInput:X,Textarea:Z,SubmitButton:Y,UpdateButton:H,CloseButton:J,ViewButton:L,Loading:O,Multiselect:ie,Button:T},data(){return{pdf_file_view:re,excel_file_view:ne,vendorOptions:[],form:{vendor_id:"",validity_date:"",notes:"",file_attachment:null,address:"",imageView:null,file_code:""},errors:{vendor_id:"",validity_date:"",note:"",file_attachment:""},state:{isEdit:!1,isSaving:!1,isLoading:!1,isDownloading:!1},dateToday:new Date().toISOString().slice(0,10)}},computed:{},methods:{fileDownload(t){this.state.isDownloading||(this.state.isDownloading=!0,k.Download(t).then(e=>{if(e.status===200){const c=window.URL.createObjectURL(new Blob([e.data])),d=document.createElement("a");d.href=c,d.setAttribute("download",t),document.body.appendChild(d),d.click(),d.remove()}else e.status===204?this.$swal.fire({title:"Ooops! Something is wrong!",text:"File not found.",icon:"error"}):console.error("Unexpected error:",e.status)}).catch(e=>{console.error("Error downloading file:",e)}).finally(()=>{this.state.isDownloading=!1}))},async fetchSuppliers(){await se.fetchRecords().then(t=>{t.status==200&&(this.vendorOptions=t.data.data.map(e=>({value:e.id,label:e.code+" - "+e.name})))}).catch(t=>{console.log(t)})},async loadRecord(t){console.log("this is the data",t),this.resetForm(),this.state.isEdit=!0,this.form=t,this.form.imageView=await k.Reader("proposal",t.file_code),console.log(this.form.imageView)},closeModal(){this.state.showModal=!1,this.resetForm()},resetForm(){this.state.isEdit=!1,this.form={vendor_id:"",validity_date:"",note:"",file_attachment:null,file_code:""},this.errors={}},reload(){this.$emit("reload")},async saveRecord(){this.state.isSaving=!0;let t=new FormData;Object.keys(this.form).forEach(e=>{t.append(e,this.form[e])}),this.state.isEdit?(this.form.id,console.log("editing..."),console.log(t),await x.update2(t).then(e=>{e.status==201?(this.$swal.fire({title:"Great!",text:"Record successfully updated.",icon:"success",timer:2e3}),this.state.showModal=!1):(this.$swal.fire({title:"Ooops! something is wrong.",text:"Please contact system administrator",icon:"error",timer:2e3}),this.state.showModal=!1)}).catch(e=>{console.log(e),e.response.status==422?this.$swal.fire({title:"Ooops! something is wrong.",text:e.response.data.message,icon:"warning"}):this.$swal.fire({title:"Ooops! something is wrong.",text:"Please contact system administrator",icon:"error",timer:2e3})}).finally(()=>{this.state.isSaving=!1,this.reload()})):(console.log("creating..."),console.log(t),await x.create(t).then(e=>{e.status==201&&(this.$swal.fire({title:"Great!",text:"Record successfully saved.",icon:"success",timer:2e3}),this.state.showModal=!1,this.state.isLoading=!1,this.resetForm(),this.reload())}).catch(e=>{this.$swal.fire({title:"Ooops! something is wrong.",text:"Please contact system administrator",icon:"error",timer:2e3})}))},async submitForm(){try{const t=$().shape({vendor_id:E().required("Vendor field is required."),validity_date:ee().nullable().transform((e,c)=>c===""?null:e).required("Validity date is required."),file_attachment:this.form.file_attachment==null&&this.form.file_code==""?te().required("File attachment proposal is required.").test("fileSize","File size is too large",e=>e?e.size<=ae:!0):"",notes:E().required("Notes is required.").min(10)});await t.validate(this.form,{abortEarly:!1}),console.log(t),this.$swal.fire({title:"Are you sure you want to save this record?",text:"",icon:"question",showCancelButton:!0,confirmButtonColor:"#34c38f",cancelButtonColor:"#f46a6a",confirmButtonText:"Yes",cancelButtonText:"No"}).then(e=>{e.value&&this.saveRecord()})}catch(t){if(t instanceof oe){const e={};t.inner.forEach(c=>{e[c.path]=c.message}),this.errors=e}this.state.isSaving=!1}},reset(){this.currentStatus=STATUS_INITIAL,this.uploadedFiles=[],this.uploadError=null},handleMainImageUpload(){const t=event.target.files[0];this.form.file_attachment=t;const e=new FileReader;e.onload=()=>{console.log(t.type),t.type.startsWith("image/")?this.form.imageView=e.result:t.type==="application/pdf"?this.form.imageView=this.pdf_file_view:t.type==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"&&(this.form.imageView=this.excel_file_view)},e.readAsDataURL(t)},clearViewAttachment(){this.form.imageView=null}},mounted(){this.fetchSuppliers()}},de={class:"lg:p-2"},ue={class:"relative"},fe={key:0,class:"text-danger-500"},me={class:"my-6 grid grid-cols-2"},he={class:"relative mb-4"},pe={class:"w-full flex justify-between"},ge=r("div",{class:"bg-white rounded border border-gray-300 p-0 flex flex-grow items-center justify-between"},[r("span",{class:"mr-2 pl-2 text-sm text-slate-500"},"Choose a file..."),r("button",{type:"button",class:"px-4 py-2 bg-slate-200 text-slate-500 rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 pointer-events-auto"}," Browse ")],-1),_e={class:"flex justify-start items-center"},we={key:0,class:"text-danger-500"},ye={class:"h-[200px] w-[200px] rounded-md bg-slate-100 p-2 mx-auto"},ve=["src"],be={key:0,class:"text-danger-500"},Ce={class:"flex gap-1 justify-end"};function xe(t,e,c,d,o,l){const _=i("Loading"),P=i("Multiselect"),w=i("FormGroup"),b=i("TextInput"),B=i("Button"),F=i("ViewButton"),y=i("SubmitButton"),S=i("UpdateButton"),V=i("CloseButton"),M=i("FormModal");return s(),f(M,{title:o.state.isEdit?"Edit Record":"Create Record",active:o.state.showModal,onSubmit:t.confirmSubmit,onClose:l.closeModal,themeClass:o.state.isEdit?"bg-primary-600":"bg-primary-800",sizeClass:"lg:w-1/2"},{default:m(()=>[o.state.isEdit&&o.state.isLoading?(s(),f(_,{key:0,text:"Fetching record"})):a("",!0),r("div",de,[r("form",{onSubmit:e[5]||(e[5]=j((...p)=>t.confirmSubmit&&t.confirmSubmit(...p),["prevent"])),class:"space-y-4",enctype:"multipart/form-data"},[o.state.isEdit&&o.state.isLoading?(s(),f(_,{key:0,text:"Fetching record"})):a("",!0),o.state.isSaving?(s(),f(_,{key:1,text:"Saving record"})):a("",!0),u(w,{label:"Vendor/Supplier",isRequired:!0},{default:m(()=>[r("div",ue,[u(P,{modelValue:o.form.vendor_id,"onUpdate:modelValue":e[0]||(e[0]=p=>o.form.vendor_id=p),"close-on-select":!0,searchable:!0,id:"vendor_id",options:o.vendorOptions},null,8,["modelValue","options"])]),o.errors.vendor_id?(s(),h("span",fe,g(o.errors.vendor_id),1)):a("",!0)]),_:1}),u(w,{label:"Validity date",isRequired:!0},{default:m(()=>[u(b,{type:"date",placeholder:"Input validity date",modelValue:o.form.validity_date,"onUpdate:modelValue":e[1]||(e[1]=p=>o.form.validity_date=p),error:o.errors.validity_date,classInput:"h-[48px]"},null,8,["modelValue","error"])]),_:1}),u(w,{label:"Attachment",isRequired:!0},{default:m(()=>[r("div",me,[r("div",he,[r("div",pe,[r("input",{type:"file",name:"fileAttach",id:"fileAttach",onChange:e[2]||(e[2]=p=>l.handleMainImageUpload()),class:"absolute inset-0 opacity-0 w-full h-full cursor-pointer pointer-events-auto",multiple:""},null,32),ge,u(B,{onClick:e[3]||(e[3]=p=>l.clearViewAttachment()),btnClass:"bg-red-500 mx-1 text-gray-100 min-h-3 pt-2"},{default:m(()=>[v("Clear")]),_:1})]),r("div",_e,[o.form.fileExtension?(s(),f(F,{key:0,title:"Download Attachment"})):a("",!0),v(" "+g(o.form.file_code),1)]),o.errors.file_attachment?(s(),h("span",we,g(o.errors.file_attachment),1)):a("",!0)]),r("div",ye,[o.form.imageView?(s(),h("img",{key:0,src:o.form.imageView,class:"object-contain w-full h-full rounded-lg"},null,8,ve)):a("",!0)])])]),_:1}),u(w,{label:"Notes"},{default:m(()=>[u(b,{type:"text",placeholder:"Add notes",modelValue:o.form.notes,"onUpdate:modelValue":e[4]||(e[4]=p=>o.form.notes=p),error:o.errors.notes,classInput:"h-[56px]"},null,8,["modelValue","error"]),o.errors.note?(s(),h("span",be,g(o.errors.note),1)):a("",!0)]),_:1}),r("div",Ce,[o.state.isEdit?(s(),f(S,{key:1,onClick:l.submitForm},null,8,["onClick"])):(s(),f(y,{key:0,onClick:l.submitForm},null,8,["onClick"])),u(V,{onClick:l.closeModal},null,8,["onClick"])])],32)])]),_:1},8,["title","active","onSubmit","onClose","themeClass"])}const ke=R(ce,[["render",xe]]),Pe={components:{Loading:O},props:{file:String},data(){return{pdfContent:null,excelContent:null,state:{isLoadingfile:!1}}},watch:{file:{immediate:!0,handler(t){t&&this.fetchPDF(t)}}},methods:{async fetchPDF(t){this.state.isLoadingfile=!0;try{const e=await k.Reader2("proposal",t);this.pdfContent=`data:application/pdf;base64,${e}`,this.state.isLoadingfile=!1}catch(e){console.error("Error streaming file: ",e)}this.state.isLoadingfile=!1}}},Be={key:0},Fe=["src"],Se={key:1},Ve=["src"];function Me(t,e,c,d,o,l){const _=i("Loading");return s(),h(D,null,[o.state.isLoadingfile?(s(),f(_,{key:0,text:"Preparing pdf file."})):a("",!0),r("div",null,[o.pdfContent?(s(),h("div",Be,[r("embed",{src:o.pdfContent,type:"application/pdf",width:"100%",height:"1500px"},null,8,Fe)])):a("",!0),o.excelContent?(s(),h("div",Se,[r("iframe",{src:o.excelContent,width:"100%",height:"600px",frameborder:"0"},null,8,Ve)])):a("",!0),v(" "+g(o.excelContent),1)])],64)}const Re=R(Pe,[["render",Me]]),Oe={setup(){},components:{Layout:A,CreateButton:N,Loading:O,InputGroup:Q,EditButton:G,DeleteButton:z,ViewButton:L,Form:ke,Pagination:le,Icon:q,FormModal:I,PDFViewer:Re},data(){return{title:"Proposal",breadcrumbs:[{text:"Home",href:"/"},{text:"Proposal",active:!0}],columns:[{label:"#",field:"#"},{label:"Ref. Code",field:"ref_code"},{label:"Vendor/Supplier",field:"supplier"},{label:"File",field:"file_code"},{label:"Validity",field:"validity_date"},{label:"Notes",field:"notes"},{label:"Action",field:"action"}],perPageOptions:[{value:"10",label:"10"},{value:"50",label:"50"},{value:"100",label:"100"}],state:{isLoading:!1,isMounted:!1,showModal:!1,isDeleting:!1},selectedFile:null,items:[],totalItems:0,attachMent:null,fileExtenstion:null,pdfContent:null,excelContent:null,Btntitle:"",error:[],searchQuery:"",serverOptions:{page:1,rowsPerPage:10,sortBy:"id",sortType:"desc"}}},watch:{serverOptions:{handler(){console.log(`perPage: ${this.serverOptions.rowsPerPage}`),this.fetchRecords()},deep:!0},searchQuery:K.debounce(function(){this.fetchRecords()},800)},computed:{perPage:function(){return this.serverOptions.rowsPerPage}},methods:{getExtension(t){this.attachMent=t;const e=this.attachMent.split(".").pop();return console.log("Unknown file"),e},async fetchRecords(){this.state.isLoading=!0,this.state.isMounted=!1,await x.fetchRecords({keyword:this.searchQuery,page:this.serverOptions.page,per_page:this.serverOptions.rowsPerPage,sortBy:this.serverOptions.sortBy,sortType:this.serverOptions.sortType}).then(t=>{console.log(t);let e=t.data.data;this.items=e,this.items=e.map((c,d)=>(console.log(this.fileExtenstion),console.log(c),{...c,"#":(this.serverOptions.page-1)*this.serverOptions.rowsPerPage+(d+1),fileExtension:this.getExtension(c.file_code)})),this.totalItems=t.data.total}).finally(()=>{this.state.isLoading=!1,this.state.isMounted=!0})},handlePageChange(t){console.log(t),console.log(this.serverOptions.page),this.serverOptions.page!=t&&(this.serverOptions.page=t)},handlePerPageChange(t){this.serverOptions.page=1,this.serverOptions.rowsPerPage=t},onSortChange(t){console.log(t),t[0].type!="none"&&(this.serverOptions.sortBy=t[0].field,this.serverOptions.sortType=t[0].type)},async deleteRecord(t){this.$swal.fire({title:"Are you sure?",text:"You want to delete this record?",icon:"warning",showCancelButton:!0,confirmButtonColor:"#34c38f",cancelButtonColor:"#f46a6a",confirmButtonText:"Yes, delete it!",background:this.$store.themeSettingsStore.isDark?"#1e293b":"#fff"}).then(e=>{e.value&&(this.state.isDeleting=!0,x.remove(t).then(c=>{console.log(c),c.status==200&&(this.$swal.fire({title:"Yaaay!",text:"Record has been deleted successfully.",type:"success",icon:"success",timer:2e3}),this.fetchRecords())}))}).catch(e=>{e.response&&e.response.status==401&&this.$swal.fire({title:"Ooops! something is wrong.",text:"Error deleting record. Please contact system administrator",type:"error",icon:"error",timer:2e3})}).finally(()=>{this.state.isDeleting=!1})},createRecord(){this.$refs.form.resetForm(),this.$refs.form.state.showModal=!0},editRecord(t){this.$refs.form.resetForm(),this.$refs.form.loadRecord(t),this.$refs.form.state.showModal=!0},closeModal(){this.state.showModal=!1,this.resetData(),this.fetchRecords()},resetData(){this.state={isLoading:!1,isMounted:!1,isResetError:!1,isSubmitted:!1,showModal:!1},this.categoryData={category_code:"",category_desc:""},this.error=[]},StreamFile(t){console.log(t),this.selectedFile=t,this.state.showModal=!0},fileDownload(t){k.Download(t).then(e=>{if(e.status===200){const c=window.URL.createObjectURL(new Blob([e.data])),d=document.createElement("a");d.href=c,d.setAttribute("download",t),document.body.appendChild(d),d.click(),d.remove()}else e.status===204?this.$swal.fire({title:"Ooops! Something is wrong!",text:"File not found.",icon:"error"}):console.error("Unexpected error:",e.status)}).catch(e=>{console.error("Error downloading file:",e)})}},mounted(){this.fetchRecords()}},Ee={key:0,class:"flex gap-1"},De={key:1,class:"transition ease-in-out delay-150 hover:-translate-y-1 hover:scale-110 hover: duration-300 ..."},Le={key:2},Ie={class:"text-slate-300"},Ue=r("br",null,null,-1),Ae={key:3},Te={class:"py-4 flex justify-end"};function qe(t,e,c,d,o,l){const _=i("PDFViewer"),P=i("FormModal"),w=i("InputGroup"),b=i("CreateButton"),B=i("EditButton"),F=i("DeleteButton"),y=i("ViewButton"),S=i("Pagination"),V=i("vue-good-table"),M=i("Loading"),p=i("Form"),U=i("Layout");return s(),h(D,null,[r("div",null,[u(P,{active:o.state.showModal,onClose:l.closeModal,themeClass:"bg-primary-600",sizeClass:"lg:w-100"},{default:m(()=>[u(_,{file:o.selectedFile},null,8,["file"])]),_:1},8,["active","onClose"])]),u(U,{header:o.title,headerIcon:"mdi:file-cabinet",breadcrumbs:o.breadcrumbs},{search:m(()=>[u(w,{modelValue:o.searchQuery,"onUpdate:modelValue":e[0]||(e[0]=n=>o.searchQuery=n),class:"w-full focus:border-cyan-500 pt-1 pr-4",placeholder:"Search",type:"text",prependIcon:"heroicons-outline:search",merged:""},null,8,["modelValue"])]),action:m(()=>[t.$ability.can("add","company")?(s(),f(b,{key:0,onClick:l.createRecord},null,8,["onClick"])):a("",!0)]),default:m(()=>[r("div",null,[u(V,{styleClass:"vgt-table lesspadding v-middle",columns:o.columns,rows:o.items,mode:"remote",search:!0,"sort-options":{enabled:!0},"pagination-options":{enabled:!0},onSortChange:l.onSortChange,"max-height":"600px"},{"table-row":m(n=>[n.column.field=="action"?(s(),h("div",Ee,[t.$ability.can("edit","proposal")?(s(),f(B,{key:0,onClick:C=>l.editRecord(n.row)},null,8,["onClick"])):a("",!0),t.$ability.can("delete","proposal")?(s(),f(F,{key:1,title:"Remove",onClick:C=>l.deleteRecord(n.row.id)},null,8,["onClick"])):a("",!0)])):a("",!0),n.column.field=="ref_code"?(s(),h("div",De,[r("small",null,g(n.row.ref_code),1)])):a("",!0),n.column.field=="supplier"?(s(),h("div",Le,[r("small",Ie,"("+g(n.row.supplier_code)+")",1),Ue,v(" "+g(n.row.supplier_name),1)])):a("",!0),n.column.field=="file_code"?(s(),h("div",Ae,[n.row.fileExtension=="pdf"?(s(),f(y,{key:0,title:"View Attachment",onClick:C=>l.StreamFile(n.row.file_code)},null,8,["onClick"])):n.row.fileExtension=="jpg"?(s(),f(y,{key:1,title:"View Attachment",onClick:C=>l.StreamFile(n.row.file_code)},null,8,["onClick"])):(s(),f(y,{key:2,title:"Download Attachment",onClick:C=>l.fileDownload(n.row.file_code)},null,8,["onClick"])),v(" "+g(n.row.file_code),1)])):a("",!0)]),"pagination-bottom":m(n=>[r("div",Te,[u(S,{total:o.totalItems,current:o.serverOptions.page,"per-page":o.serverOptions.rowsPerPage,onPageChanged:l.handlePageChange,pageChanged:n.pageChanged,perPageChanged:o.serverOptions.rowsPerPage,enableSelect:"",perPageOptions:o.perPageOptions,onChangePerPage:l.handlePerPageChange},null,8,["total","current","per-page","onPageChanged","pageChanged","perPageChanged","perPageOptions","onChangePerPage"])])]),_:1},8,["columns","rows","onSortChange"]),o.state.isLoading?(s(),f(M,{key:0,text:"Fetching records"})):a("",!0),u(p,{onCloseModal:e[1]||(e[1]=n=>o.state.showModal=!1),ref:"form",onReload:e[2]||(e[2]=n=>l.fetchRecords())},null,512)])]),_:1},8,["header","breadcrumbs"])],64)}const ht=R(Oe,[["render",qe]]);export{ht as default};
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings