UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

3 lines (2 loc) 11.2 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BaseFab-LOhS57gL.js","./index-B9yS4Bcc.js","./index-Bm7DxUwf.css","./VFab-OEmwwbnb.js","./VFab-MHxCNJTw.css","./BaseFab-BUyXt8fM.css","./prismeditor.esm-DJboYDZ5.js"])))=>i.map(i=>d[i]); import{_ as A,L as D,I as N,d as b,a as B,u as P,C as f,aa as v,l as u,w as o,V as R,r as F,o as c,b as i,f as x,i as p,k as l,t as _,U as g,e as S,ab as I,ac as j,ad as z,ae as Z,Z as y,p as m,q as k,c as w,af as C,M as L,ag as O,ah as M,ai as q,h as V,z as E}from"./index-B9yS4Bcc.js";import{V as K}from"./VTreeview-gSGU9saB.js";const W=D.get("Store"),Y={name:"Store",mixins:[N],components:{BaseFab:b(()=>E(()=>import("./BaseFab-LOhS57gL.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url)),PrismEditor:b(()=>E(()=>import("./prismeditor.esm-DJboYDZ5.js"),__vite__mapDeps([6,1,2]),import.meta.url).then(t=>t.PrismEditor))},watch:{selected(){this.fetchFile()}},computed:{selected(){if(this.active.length)return this.active[0]},storePath(){var t;return(t=this.items[0])==null?void 0:t.path},fabItems(){const t=[{icon:"restore",color:"success",action:()=>this.restoreZip(),tooltip:"Restore"},{icon:"upload",color:"warning",action:()=>this.uploadFile(),tooltip:"Upload File"},{icon:"backup",color:"purple",action:()=>this.backupStore(),tooltip:"Backup"},{icon:"refresh",color:"warning",action:()=>this.refreshTree(),tooltip:"Refresh"}];return this.selectedFiles.length>0&&(t.push({icon:"file_download",color:"primary",action:()=>this.downloadSelectedZip(),tooltip:"Download selected"}),t.push({icon:"delete",color:"error",action:()=>this.deleteSelected(),tooltip:"Delete selected"})),t}},data(){return{fab:!1,selectedFiles:[],allowedExt:["json","jsonl","txt","log","js","ts"],active:[],items:[],openFolders:[],fileContent:"",notSupported:!1,loadingStore:!0,loadingFile:!1}},methods:{...B(P,["showSnackbar"]),async deleteFile(t){if(await this.app.confirm("Attention",`Are you sure you want to delete the file <code>${t.name}</code>?`,"alert"))try{const e=await f.deleteFile(t.path);if(e.success)this.showSnackbar("File deleted successfully","success"),await this.refreshTree(!0);else throw Error(e.message)}catch(e){this.showSnackbar(e.message,"error")}},async deleteSelected(){const t=this.selectedFiles.map(e=>e.path);if(await this.app.confirm("Attention",`Are you sure you want to delete ${t.length} files?`,"alert"))try{const e=await f.deleteMultiple(t);if(e.success)this.showSnackbar("Files deleted successfully","success"),await this.refreshTree(!0);else throw Error(e.message)}catch(e){this.showSnackbar(e.message,"error")}},async downloadSelectedZip(){const t=this.selectedFiles.map(e=>e.path);try{const e=await f.downloadZip(t);await this.downloadZip(e,"zwave-js-ui-store.zip")}catch(e){this.showSnackbar(e.message,"error")}},async downloadZip(t,e){const d=/filename="([^"]+){1}"/g.exec(t.headers["content-disposition"])[1]||e;if(window.navigator&&window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),d);else{const s=window.URL.createObjectURL(new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})),a=document.createElement("a");a.href=s,a.setAttribute("download",d),document.body.appendChild(a),a.click()}},async downloadFile(){if(this.selected){const t=this.selected.name.split(".").slice(0,-1).join(".");this.app.exportConfiguration(this.fileContent,t,this.selected.ext)}},async backupStore(){if(await this.app.confirm("Backup store","Are you sure you want to backup the store? This backup will contain all useful files and settings.","info",{width:500,cancelText:"No",confirmText:"Yes"}))try{const e=await f.backupStore();await this.downloadZip(e,`store-backup_${Date.now()}.zip`),this.refreshTree()}catch(e){this.showSnackbar(e.message,"error")}},async restoreZip(){const t=await this.app.confirm("Restore zip","","info",{confirmText:"Restore",inputs:[{type:"file",label:"Zip file",required:!0,key:"file",accept:"application/zip"}]});if(t.file)try{const e=new FormData;e.append("upload",t.file),e.append("restore","true");const n=await f.storeUpload(e);if(!n.success)throw new Error(n.message||"Restore failed");await this.refreshTree(),this.showSnackbar("Restore successful","success")}catch(e){this.showSnackbar(e.message||e,"error")}},async uploadFile(t){const e=t?t.path.replace(this.storePath,""):"",n=await this.app.confirm("Upload file",`Destination folder: <code>${e||"root"}</code>`,"info",{confirmText:"Upload",width:500,inputs:[{type:"file",label:"File",required:!0,key:"file"}]});if(n.file)try{const d=new FormData;d.append("upload",n.file),e&&d.append("folder",e);const s=await f.storeUpload(d);if(!s.success)throw new Error(s.message||"Upload failed");await this.refreshTree(),this.showSnackbar("Upload successful","success")}catch(d){this.showSnackbar(d.message||d,"error")}},async writeFile(t,e=!1){const n=t&&typeof t=="string",d=this.fileContent||"";if(n){const s=e?"Directory":"File",{name:a}=await this.app.confirm("New "+s,"","info",{confirmText:"Create",inputs:[{type:"text",label:s+" name",required:!0,key:"name",hint:`Insert the ${s} name`}]});if(!a)return;t=t+"/"+a}else if(this.selected)t=this.selected.path;else{this.showSnackbar("No file selected","error");return}if(n||await this.app.confirm("Attention",`Are you sure you want to overwrite the content of the file <code>${this.selected.name}<code>?`,"alert"))try{const s=await f.writeFile(n?"":d,{path:t,isNew:n,isDirectory:e});if(s.success)this.showSnackbar(`${e?"Directory":"File"} ${n?"created":"updated"} successfully`,"success"),await this.refreshTree();else throw Error(s.message)}catch(s){this.showSnackbar(s.message,"error")}},highlighter(t){return v.highlight(t,v.languages.js)},async fetchFile(){if(this.selected&&this.selected.path&&!this.selected.children){this.fileContent="",this.notSupported=!1,this.loadingFile=!0;try{if(!this.allowedExt.includes(this.selected.ext))throw Error(`Preview of .${this.selected.ext} files is not supported`);const t=await f.getFile(this.selected.path);if(t.success)this.fileContent=t.data;else throw Error(t.message)}catch(t){this.notSupported=!0,this.showSnackbar(t.message,"error")}this.loadingFile=!1}},async getFolderItems(t){try{const e=await f.getFile(t.path);if(e.success)t.children=e.data;else throw Error(e.message)}catch(e){this.showSnackbar(e.message,"error")}},async refreshTree(t){try{const e=await f.getStore();if(e.success)this.items=e.data;else throw Error(e.message)}catch(e){this.showSnackbar("Error while fetching store files: "+e.message,"error"),W.error(e)}this.loadingStore=!1,this.loadingFile=!1,t&&(this.active=[]),this.openFolders=[this.items[0]]}},async mounted(){await this.refreshTree()}},G={class:"text-subtitle-2"},H={class:"text-caption text-grey"},J={key:1},Q={key:0,class:"text-h6 text-grey-lighten-1 font-weight-light align-self-center"},X={key:1,class:"text-h6 text-grey-lighten-1 font-weight-light align-self-center"},$={class:"file-content pa-4 pb-8"},ee={key:0,class:"sticky-bottom pa-0"};function te(t,e,n,d,s,a){const T=F("base-fab"),U=F("prism-editor");return c(),u(R,{class:"full-height pa-0",fluid:""},{default:o(()=>[i(S,{"no-gutters":""},{default:o(()=>[i(x,{class:"sticky-top fill-remaining-space overflow-y-auto",cols:"6",md:"5",lg:"4",xl:"3"},{default:o(()=>[s.loadingStore?(c(),w("div",J,[i(C,{indeterminate:"",color:"primary",style:{"align-self":"center"}})])):(c(),u(K,{key:0,activated:s.active,"onUpdate:activated":e[0]||(e[0]=r=>s.active=r),selected:s.selectedFiles,"onUpdate:selected":e[1]||(e[1]=r=>s.selectedFiles=r),items:s.items,activatable:"",selectable:"","item-value":"path",opened:s.openFolders,"onUpdate:opened":e[2]||(e[2]=r=>s.openFolders=r),"load-children":a.getFolderItems,"return-object":"",style:{"max-height":"calc(100vh - 64px)","overflow-y":"auto"}},{prepend:o(({item:r,open:h})=>[r.children?(c(),u(p,{key:0,color:"warning"},{default:o(()=>[l(_(h?"folder_open":"folder"),1)]),_:2},1024)):(c(),u(p,{key:1,color:"primary"},{default:o(()=>e[5]||(e[5]=[l(" text_snippet ")])),_:1,__:[5]}))]),title:o(({item:r})=>[g("span",G,_(r.name),1),g("div",H,_(r.size!=="n/a"?r.size:""),1)]),append:o(({item:r})=>[i(S,{"justify-end":"",class:"ma-1"},{default:o(()=>[r.children?(c(),u(I,{key:0,location:"bottom"},{activator:o(({props:h})=>[i(p,j(z(h)),{default:o(()=>e[6]||(e[6]=[l("more_vert")])),_:2,__:[6]},1040)]),default:o(()=>[i(Z,{class:"py-0",density:"compact"},{default:o(()=>[i(y,{density:"compact",onClick:m(h=>a.writeFile(r.path,!0),["stop"]),title:"New Folder"},{prepend:o(()=>[i(p,{color:"warning"},{default:o(()=>e[7]||(e[7]=[l("create_new_folder")])),_:1,__:[7]})]),_:2},1032,["onClick"]),i(y,{density:"compact",onClick:m(h=>a.writeFile(r.path,!1),["stop"]),title:"New File"},{prepend:o(()=>[i(p,{color:"primary"},{default:o(()=>e[8]||(e[8]=[l("post_add")])),_:1,__:[8]})]),_:2},1032,["onClick"]),r.isRoot?k("",!0):(c(),u(y,{key:0,density:"compact",onClick:m(h=>a.deleteFile(r),["stop"]),title:"Delete"},{prepend:o(()=>[i(p,{color:"error"},{default:o(()=>e[9]||(e[9]=[l("delete")])),_:1,__:[9]})]),_:2},1032,["onClick"])),i(y,{density:"compact",onClick:m(h=>a.uploadFile(r),["stop"]),title:"Upload File"},{prepend:o(()=>[i(p,{color:"success"},{default:o(()=>e[10]||(e[10]=[l("upload")])),_:1,__:[10]})]),_:2},1032,["onClick"])]),_:2},1024)]),_:2},1024)):(c(),u(p,{key:1,color:"error",onClick:m(h=>a.deleteFile(r),["stop"])},{default:o(()=>e[11]||(e[11]=[l("delete")])),_:2,__:[11]},1032,["onClick"]))]),_:2},1024)]),_:1},8,["activated","selected","items","opened","load-children"])),i(T,{modelValue:s.fab,"onUpdate:modelValue":e[3]||(e[3]=r=>s.fab=r),location:"bottom end","icon-open":"settings","icon-close":"close",items:a.fabItems},null,8,["modelValue","items"])]),_:1}),i(L,{class:"mx-0",vertical:""}),i(x,{class:"text-center overflow-y-auto d-flex justify-center"},{default:o(()=>[!a.selected||!a.selected.ext?(c(),w("div",Q,[i(p,{color:"grey-lighten-4",size:"x-large"},{default:o(()=>e[12]||(e[12]=[l(" text_snippet ")])),_:1,__:[12]}),e[13]||(e[13]=g("br",null,null,-1)),e[14]||(e[14]=l(" Please select a file "))])):s.loadingFile?(c(),w("div",X,[i(C,{indeterminate:"",color:"primary"})])):(c(),w("div",{class:"fill-remaining-space flex-grow-1",key:a.selected.path},[g("div",$,[s.notSupported?k("",!0):(c(),u(U,{key:0,onKeydown:O(m(a.writeFile,["ctrl","prevent"]),["s"]),class:"custom-font",lineNumbers:"",modelValue:s.fileContent,"onUpdate:modelValue":e[4]||(e[4]=r=>s.fileContent=r),highlight:a.highlighter},null,8,["onKeydown","modelValue","highlight"]))]),s.notSupported?k("",!0):(c(),w("div",ee,[i(M,null,{default:o(()=>[i(q),i(V,{color:"purple",variant:"text",onClick:a.writeFile},{default:o(()=>[e[16]||(e[16]=l(" SAVE ")),i(p,{end:""},{default:o(()=>e[15]||(e[15]=[l("save")])),_:1,__:[15]})]),_:1,__:[16]},8,["onClick"]),i(V,{color:"success",variant:"text",onClick:a.downloadFile},{default:o(()=>[e[18]||(e[18]=l(" DOWNLOAD ")),i(p,{end:""},{default:o(()=>e[17]||(e[17]=[l("file_download")])),_:1,__:[17]})]),_:1,__:[18]},8,["onClick"])]),_:1})]))]))]),_:1})]),_:1})]),_:1})}const ie=A(Y,[["render",te],["__scopeId","data-v-5059789c"]]);export{ie as default};