zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
3 lines (2 loc) • 4.57 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DialogAssociation-_VIsH-5V.js","./index-B9yS4Bcc.js","./index-Bm7DxUwf.css"])))=>i.map(i=>d[i]);
import{_ as f,d as h,z as v,I as k,m as _,u as A,a as w,d$ as y,e0 as g,du as I,r as b,o as E,l as N,w as i,b as r,e as x,U as V,h as m,k as d,t as p,i as C,V as R}from"./index-B9yS4Bcc.js";import{V as D}from"./VDataTable-CKSj76XP.js";import"./sort-CSOGXH9I.js";import"./VTable-BXtGlLLl.js";const S={components:{DialogAssociation:h(()=>v(()=>import("./DialogAssociation-_VIsH-5V.js"),__vite__mapDeps([0,1,2]),import.meta.url))},mixins:[k],props:{node:Object},data(){return{associations:[],dialogAssociation:!1,headers:[{title:"Endpoint",key:"endpoint"},{title:"Group",key:"groupId"},{title:"Node",key:"nodeId"},{title:"Target Endpoint",key:"targetEndpoint"},{title:"Actions",key:"actions",sortable:!1}]}},computed:{..._(A,["nodes","nodesMap"])},mounted(){this.getAssociations()},methods:{...w(A,["showSnackbar"]),getAssociationAddress:y,getNodeName(e){const s=this.nodes[this.nodesMap.get(e)];return s?s._name:"NodeID_"+e},getEndpointLabel(e,s){const o=this.nodes[this.nodesMap.get(e)];if(o&&s>=0){const l=o.endpoints.find(n=>n.index===s);if(l)return l.label}return s>=0?"Endpoint "+s:"No Endpoint"},async getAssociations(e=!1){let s=!1;e&&this.node.status!=="Dead"&&(s=await this.app.confirm("Info",`Do you want to force query associations?${this.node.status==="Alive"?"":" This node is Asleep, so you should wake it up first."}`,"info",{confirmText:"Yes",cancelText:"No"}));const o=await this.app.apiRequest("getAssociations",[this.node.id,s]);o.success&&(this.associations=o.result,this.showSnackbar("Associations updated","success"))},async addAssociation(e){const s=isNaN(e.target)?e.target.id:parseInt(e.target),o=e.group,l={nodeId:s};o.multiChannel&&e.targetEndpoint>=0&&(l.endpoint=e.targetEndpoint);const n=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),o.value,[l]],a=await this.app.apiRequest("addAssociations",n);if(a.success){const c=a.result[0];c===g.OK?(this.showSnackbar("Association added","success"),this.getAssociations()):this.showSnackbar(`Error while adding association: ${I(g,c)}`,"error")}this.dialogAssociation=!1},async removeAssociation(e){const s=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),e.groupId,[{nodeId:e.nodeId,endpoint:e.targetEndpoint}]];(await this.app.apiRequest("removeAssociations",s)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())},async removeAllAssociations(){const e=[this.node.id];if(!await this.app.confirm("Attention","Are you sure you want to remove all associations from this node? This will also remove lifeline association if it exists.","alert"))return;(await this.app.apiRequest("removeAllAssociations",e)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())}}},T={class:"d-flex"};function q(e,s,o,l,n,a){const c=b("DialogAssociation");return E(),N(R,{"grid-list-md":""},{default:i(()=>[r(x,{justify:"center",class:"pa-5"},{default:i(()=>[r(D,{headers:n.headers,items:n.associations,"item-key":"id",class:"elevation-1"},{top:i(()=>[V("div",T,[r(m,{variant:"text",color:"success",onClick:s[0]||(s[0]=t=>n.dialogAssociation=!0),class:"mb-2"},{default:i(()=>s[4]||(s[4]=[d("Add")])),_:1,__:[4]}),r(m,{variant:"text",color:"error",onClick:a.removeAllAssociations,class:"mb-2"},{default:i(()=>s[5]||(s[5]=[d("Remove All")])),_:1,__:[5]},8,["onClick"]),r(m,{variant:"text",color:"primary",onClick:s[1]||(s[1]=t=>a.getAssociations(!0)),class:"mb-2"},{default:i(()=>s[6]||(s[6]=[d("Refresh")])),_:1,__:[6]})])]),"item.groupId":i(({item:t})=>[d(p(o.node.groups.find(u=>u.value===t.groupId&&u.endpoint===t.endpoint).title),1)]),"item.nodeId":i(({item:t})=>[d(p(a.getNodeName(t.nodeId)),1)]),"item.endpoint":i(({item:t})=>[d(p(t.endpoint>=0?a.getEndpointLabel(o.node.id,t.endpoint):"None"),1)]),"item.targetEndpoint":i(({item:t})=>[d(p(t.targetEndpoint>=0?a.getEndpointLabel(t.nodeId,t.targetEndpoint):"None"),1)]),"item.actions":i(({item:t})=>[r(C,{size:"small",color:"error",onClick:u=>a.removeAssociation(t)},{default:i(()=>s[7]||(s[7]=[d("delete")])),_:2,__:[7]},1032,["onClick"])]),_:2},1032,["headers","items"])]),_:1}),r(c,{onAdd:a.addAssociation,onClose:s[2]||(s[2]=t=>n.dialogAssociation=!1),modelValue:n.dialogAssociation,"onUpdate:modelValue":s[3]||(s[3]=t=>n.dialogAssociation=t),node:o.node,associations:n.associations},null,8,["onAdd","modelValue","node","associations"])]),_:1})}const j=f(S,[["render",q]]);export{j as default};