zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
2 lines (1 loc) • 6.15 kB
JavaScript
import{_ as x,e6 as A,a as v,I as C,e as p,z as m,w as i,b as n,F as w,as as y,H as g,G as _,u as k,T as I,V as G,h as f,f as d,K as V,Q as R,R as S,k as u,t as h,J as T,O as U,au as B,ah as D,i as N,a6 as q,e7 as c,dC as F,aA as E,x as L}from"./index-B8xHYEBg.js";const M={mixins:[C],props:{modelValue:Boolean,associations:Array,node:Object},watch:{modelValue(){this.$refs.form&&this.$refs.form.resetValidation(),this.resetGroup(),this.associationError=""},group:{deep:!0,async handler(){(await this.$refs.form?.validate())?.valid&&this.allowedAssociation()}}},computed:{...v(L,["controllerNode","nodes"]),filteredNodes(){return this.node.protocol===E.ZWaveLongRange?[this.controllerNode]:this.nodes.filter(t=>t.id!==this.node.id&&t.protocol!==E.ZWaveLongRange).sort((t,e)=>t._name.localeCompare(e._name))},endpoints(){return this.getEndpointItems(this.node)},targetEndpoints(){return this.getEndpointItems(this.group.target,!0)},maxNodes(){return this.group.group?this.group.group.maxNodes:-1},nodesInGroup(){return this.group.group?this.associations.filter(t=>t.groupId===this.group.group.value&&t.endpoint===this.group.endpoint).length:0},endpointGroups(){let t=[];try{t=this.node.groups;const e=this.group.endpoint;t=t.filter(a=>a.endpoint===e||e===null&&a.endpoint===0&&!a.multiChannel)}catch{}return t},_value:{get(){return this.modelValue},set(t){this.$emit("update:modelValue",t)}}},data(){return{valid:!0,group:{},associationError:"",defaultGroup:{endpoint:null},required:t=>!!t||"This field is required"}},methods:{getAssociationAddress:A,async handleAdd(){(await this.$refs.form.validate()).valid&&this.$emit("add",this.group)},async allowedAssociation(){const t=this.group,e=isNaN(t.target)?t.target?.id:parseInt(t.target);if(isNaN(e)){this.associationError="";return}const a=t.group;if(!a){this.associationError="";return}const l={nodeId:e};a.multiChannel&&t.targetEndpoint>=0&&(l.endpoint=t.targetEndpoint);const s=[this.getAssociationAddress({nodeId:this.node.id,endpoint:t.endpoint}),a.value,l],r=await this.app.apiRequest("checkAssociation",s,{showInfo:!1});if(r.success){const o=r.result;o===c.OK?this.associationError="":o===c.Forbidden_SecurityClassMismatch?this.associationError=`Association not allowed: Node ${this.node.id} does not have the same security class as Node ${e}!`:o===c.Forbidden_DestinationSecurityClassNotGranted?this.associationError=`Association not allowed: Node ${this.node.id} was not granted the highest security class of Node ${e}!`:o===c.Forbidden_NoSupportedCCs?this.associationError=`Association not allowed: Node ${this.node.id} sends no commands in this group that Node ${e} supports!`:this.associationError=`Association not allowed: ${F(c,o)}`}},resetGroup(){this.group=Object.assign({},this.defaultGroup)},getEndpointLabel(t,e){if(t&&t.endpoints){const a=t.endpoints.find(l=>l.index===e);if(a)return a.label}return"Endpoint "+e},getEndpointItems(t,e=!1){const a=[];if(e&&a.unshift({title:"No Endpoint",value:null}),t&&t.endpoints)for(const l of t.endpoints)a.push({title:l.label,value:l.index});return a}}},j={class:"text-subtitle-1 pa-0 ma-0"},O={class:"text-subtitle-1 pa-0 ma-0"};function z(t,e,a,l,s,r){return m(),p(q,{modelValue:r._value,"onUpdate:modelValue":e[6]||(e[6]=o=>r._value=o),"max-width":"500px",persistent:""},{default:i(()=>[n(w,null,{default:i(()=>[n(y,null,{default:i(()=>[...e[7]||(e[7]=[g("span",{class:"text-h5"},"New Association",-1)])]),_:1}),n(_,null,{default:i(()=>[n(k,{"grid-list-md":""},{default:i(()=>[n(I,{modelValue:s.valid,"onUpdate:modelValue":e[4]||(e[4]=o=>s.valid=o),ref:"form","validate-on":"lazy"},{default:i(()=>[n(G,null,{default:i(()=>[n(d,{cols:"12"},{default:i(()=>[n(V,{label:"Node Endpoint",hint:"Used to filter available groups",modelValue:s.group.endpoint,"onUpdate:modelValue":e[0]||(e[0]=o=>s.group.endpoint=o),"persistent-hint":"",items:r.endpoints},null,8,["modelValue","items"])]),_:1}),n(d,{cols:"12"},{default:i(()=>[n(V,{label:"Group",hint:"Node/Endpoint Group association to Add/Remove","persistent-hint":"",modelValue:s.group.group,"onUpdate:modelValue":e[1]||(e[1]=o=>s.group.group=o),items:r.endpointGroups,rules:[s.required],"return-object":""},{selection:i(({item:o})=>[u(h(o.raw.title),1)]),item:i(({item:o,props:b})=>[n(R,S(b,{title:o.raw.title,subtitle:o.raw.endpoint>=0?r.getEndpointLabel(a.node,o.raw.endpoint):"No Endpoint"}),null,16,["title","subtitle"])]),_:1},8,["modelValue","items","rules"])]),_:1}),s.group.group?(m(),p(d,{key:0,cols:"12"},{default:i(()=>[g("p",j,[e[8]||(e[8]=u(" Max associations: ",-1)),g("strong",null,h(r.maxNodes),1)]),g("p",O,[e[9]||(e[9]=u(" Actual associations: ",-1)),g("strong",null,h(r.nodesInGroup),1)])]),_:1})):f("",!0),r.nodesInGroup<r.maxNodes?(m(),p(d,{key:1,class:"pa-0"},{default:i(()=>[n(d,{cols:"12"},{default:i(()=>[n(T,{label:"Target Node",modelValue:s.group.target,"onUpdate:modelValue":e[2]||(e[2]=o=>s.group.target=o),items:r.filteredNodes,"return-object":"",rules:[s.required],hint:"Node to add to the association group","persistent-hint":"","item-title":"_name"},null,8,["modelValue","items","rules"])]),_:1}),s.group.group&&s.group.group.multiChannel?(m(),p(d,{key:0,cols:"12"},{default:i(()=>[n(V,{modelValue:s.group.targetEndpoint,"onUpdate:modelValue":e[3]||(e[3]=o=>s.group.targetEndpoint=o),modelModifiers:{number:!0},"persistent-hint":"",label:"Target Endpoint",hint:"Target node endpoint",items:r.targetEndpoints},null,8,["modelValue","items"])]),_:1})):f("",!0),s.associationError?(m(),p(d,{key:1,cols:"12"},{default:i(()=>[n(U,{text:"",density:"compact",type:"error"},{default:i(()=>[u(h(s.associationError),1)]),_:1})]),_:1})):f("",!0)]),_:1})):f("",!0)]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}),n(B,null,{default:i(()=>[n(D),n(N,{color:"blue-darken-1",variant:"text",onClick:e[5]||(e[5]=o=>t.$emit("close"))},{default:i(()=>[...e[10]||(e[10]=[u("Cancel",-1)])]),_:1}),n(N,{color:"blue-darken-1",variant:"text",disabled:r.nodesInGroup>=r.maxNodes||!!s.associationError,onClick:r.handleAdd},{default:i(()=>[...e[11]||(e[11]=[u("ADD",-1)])]),_:1},8,["disabled","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])}const P=x(M,[["render",z]]);export{P as default};