zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
3 lines (2 loc) • 11 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BaseFab-BwvwxwY8.js","./index-DwzE-W2i.js","./index-B2zoqM3Y.css","./VFab-BoiUHyPJ.js","./VFab-ByB_rPoF.css","./BaseFab-BUyXt8fM.css","./prismeditor.esm-9uQaY7hi.js"])))=>i.map(i=>d[i]);
import{_ as N,d as v,I as R,e as u,w as s,b as i,f as F,c as w,V as x,ab as U,ac as A,h as k,R as g,o as m,l as p,k as n,ad as P,ae as B,H as y,t as b,af as _,E as I,s as S,ag as j,ah as z,ai as L,i as C,u as O,C as f,L as Z,aj as V,ak as M,al as q,y as E,z as c}from"./index-DwzE-W2i.js";import{V as K}from"./VTreeview-BYmR7iQJ.js";const H=Z.get("Store"),W={name:"Store",mixins:[R],components:{BaseFab:v(()=>E(()=>import("./BaseFab-BwvwxwY8.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url)),PrismEditor:v(()=>E(()=>import("./prismeditor.esm-9uQaY7hi.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(){return this.items[0]?.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:{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 l=M(t,e);if(window.navigator&&window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),l);else{const d=window.URL.createObjectURL(new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}));q(d,l)}},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 l=await f.storeUpload(e);if(!l.success)throw new Error(l.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,""):"",l=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(l.file)try{const d=new FormData;d.append("upload",l.file),e&&d.append("folder",e);const o=await f.storeUpload(d);if(!o.success)throw new Error(o.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 l=t&&typeof t=="string",d=this.fileContent||"";if(l){const o=e?"Directory":"File",{name:a}=await this.app.confirm("New "+o,"","info",{confirmText:"Create",inputs:[{type:"text",label:o+" name",required:!0,key:"name",hint:`Insert the ${o} name`}]});if(!a)return;t=t+"/"+a}else if(this.selected)t=this.selected.path;else{this.showSnackbar("No file selected","error");return}if(l||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 o=await f.writeFile(l?"":d,{path:t,isNew:l,isDirectory:e});if(o.success)this.showSnackbar(`${e?"Directory":"File"} ${l?"created":"updated"} successfully`,"success"),await this.refreshTree();else throw Error(o.message)}catch(o){this.showSnackbar(o.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"),H.error(e)}this.loadingStore=!1,this.loadingFile=!1,t&&(this.active=[]),this.openFolders=[this.items[0]]}},async mounted(){await this.refreshTree()}},Y={class:"text-subtitle-2"},G={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"};function te(t,e,l,d,o,a){const T=S("prism-editor"),D=S("base-fab");return c(),u(O,{class:"full-height pa-0",fluid:""},{default:s(()=>[i(x,{"no-gutters":""},{default:s(()=>[i(F,{class:"sticky-top fill-remaining-space overflow-y-auto",cols:"6",md:"5",lg:"4",xl:"3"},{default:s(()=>[o.loadingStore?(c(),w("div",J,[i(_,{indeterminate:"",color:"primary",style:{"align-self":"center"}})])):(c(),u(K,{key:0,activated:o.active,"onUpdate:activated":e[0]||(e[0]=r=>o.active=r),selected:o.selectedFiles,"onUpdate:selected":e[1]||(e[1]=r=>o.selectedFiles=r),items:o.items,activatable:"",selectable:"","select-strategy":"leaf","item-value":"path",opened:o.openFolders,"onUpdate:opened":e[2]||(e[2]=r=>o.openFolders=r),"load-children":a.getFolderItems,"return-object":"",style:{"max-height":"calc(100vh - 64px)","overflow-y":"auto"}},{prepend:s(({item:r,open:h})=>[r.children?(c(),u(p,{key:0,color:"warning"},{default:s(()=>[n(b(h?"folder_open":"folder"),1)]),_:2},1024)):(c(),u(p,{key:1,color:"primary"},{default:s(()=>[...e[5]||(e[5]=[n(" text_snippet ",-1)])]),_:1}))]),title:s(({item:r})=>[y("span",Y,b(r.name),1),y("div",G,b(r.size!=="n/a"?r.size:""),1)]),append:s(({item:r})=>[i(x,{"justify-end":"",class:"ma-1"},{default:s(()=>[r.children?(c(),u(U,{key:0,location:"bottom"},{activator:s(({props:h})=>[i(p,P(B(h)),{default:s(()=>[...e[6]||(e[6]=[n("more_vert",-1)])]),_:1},16)]),default:s(()=>[i(A,{class:"py-0",density:"compact"},{default:s(()=>[i(g,{density:"compact",onClick:m(h=>a.writeFile(r.path,!0),["stop"]),title:"New Folder"},{prepend:s(()=>[i(p,{color:"warning"},{default:s(()=>[...e[7]||(e[7]=[n("create_new_folder",-1)])]),_:1})]),_:1},8,["onClick"]),i(g,{density:"compact",onClick:m(h=>a.writeFile(r.path,!1),["stop"]),title:"New File"},{prepend:s(()=>[i(p,{color:"primary"},{default:s(()=>[...e[8]||(e[8]=[n("post_add",-1)])]),_:1})]),_:1},8,["onClick"]),r.isRoot?k("",!0):(c(),u(g,{key:0,density:"compact",onClick:m(h=>a.deleteFile(r),["stop"]),title:"Delete"},{prepend:s(()=>[i(p,{color:"error"},{default:s(()=>[...e[9]||(e[9]=[n("delete",-1)])]),_:1})]),_:1},8,["onClick"])),i(g,{density:"compact",onClick:m(h=>a.uploadFile(r),["stop"]),title:"Upload File"},{prepend:s(()=>[i(p,{color:"success"},{default:s(()=>[...e[10]||(e[10]=[n("upload",-1)])]),_:1})]),_:1},8,["onClick"])]),_:2},1024)]),_:2},1024)):(c(),u(p,{key:1,color:"error",onClick:m(h=>a.deleteFile(r),["stop"])},{default:s(()=>[...e[11]||(e[11]=[n("delete",-1)])]),_:1},8,["onClick"]))]),_:2},1024)]),_:1},8,["activated","selected","items","opened","load-children"]))]),_:1}),i(I,{class:"mx-0",vertical:""}),i(F,{class:"text-center overflow-y-auto d-flex justify-center"},{default:s(()=>[!a.selected||!a.selected.ext?(c(),w("div",Q,[i(p,{color:"grey-lighten-4",size:"x-large"},{default:s(()=>[...e[12]||(e[12]=[n(" text_snippet ",-1)])]),_:1}),e[13]||(e[13]=y("br",null,null,-1)),e[14]||(e[14]=n(" Please select a file ",-1))])):o.loadingFile?(c(),w("div",X,[i(_,{indeterminate:"",color:"primary"})])):(c(),w("div",{class:"fill-remaining-space flex-grow-1",key:a.selected.path},[y("div",$,[o.notSupported?k("",!0):(c(),u(T,{key:0,onKeydown:j(m(a.writeFile,["ctrl","prevent"]),["s"]),class:"custom-font",lineNumbers:"",modelValue:o.fileContent,"onUpdate:modelValue":e[3]||(e[3]=r=>o.fileContent=r),highlight:a.highlighter},null,8,["onKeydown","modelValue","highlight"]))]),o.notSupported?k("",!0):(c(),w("div",ee,[i(z,null,{default:s(()=>[i(L),i(C,{color:"purple",variant:"text",onClick:a.writeFile},{default:s(()=>[e[16]||(e[16]=n(" SAVE ",-1)),i(p,{end:""},{default:s(()=>[...e[15]||(e[15]=[n("save",-1)])]),_:1})]),_:1},8,["onClick"]),i(C,{color:"success",variant:"text",onClick:a.downloadFile},{default:s(()=>[e[18]||(e[18]=n(" DOWNLOAD ",-1)),i(p,{end:""},{default:s(()=>[...e[17]||(e[17]=[n("file_download",-1)])]),_:1})]),_:1},8,["onClick"])]),_:1})]))]))]),_:1})]),_:1}),i(D,{modelValue:o.fab,"onUpdate:modelValue":e[4]||(e[4]=r=>o.fab=r),style:{"margin-bottom":"65px"},location:"bottom end","icon-open":"settings","icon-close":"close",items:a.fabItems},null,8,["modelValue","items"])]),_:1})}const ie=N(W,[["render",te],["__scopeId","data-v-288686e8"]]);export{ie as default};