zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
2 lines (1 loc) • 6.91 kB
JavaScript
import{_ as A,e6 as E,a as k,I as x,e as p,z as c,w as i,b as n,F as w,ar as y,H as g,G as v,u as I,U as _,V as G,h,f as u,K as V,R,T as S,k as m,t as f,J as F,O as T,M as U,at as D,ai as M,i as b,a7 as B,e7 as d,dC as q,az as N,x as L}from"./index-DwzE-W2i.js";const j={mixins:[x],props:{modelValue:Boolean,associations:Array,node:Object},watch:{modelValue(){this.$refs.form&&this.$refs.form.resetValidation(),this.resetGroup(),this.associationError="",this.associationCheckResult=null,this.forceAssociation=!1},group:{deep:!0,async handler(){(await this.$refs.form?.validate())?.valid&&(this.forceAssociation=!1,this.allowedAssociation())}}},computed:{...k(L,["controllerNode","nodes"]),filteredNodes(){return this.node.protocol===N.ZWaveLongRange?[this.controllerNode]:this.nodes.filter(t=>t.id!==this.node.id&&t.protocol!==N.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},canForceAssociation(){return this.associationCheckResult===d.Forbidden_SecurityClassMismatch||this.associationCheckResult===d.Forbidden_DestinationSecurityClassNotGranted||this.associationCheckResult===d.Forbidden_NoSupportedCCs},_value:{get(){return this.modelValue},set(t){this.$emit("update:modelValue",t)}}},data(){return{valid:!0,group:{},associationError:"",associationCheckResult:null,forceAssociation:!1,defaultGroup:{endpoint:null},required:t=>!!t||"This field is required"}},methods:{getAssociationAddress:E,async handleAdd(){(await this.$refs.form.validate()).valid&&this.$emit("add",this.group,this.forceAssociation)},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;this.associationCheckResult=o,o===d.OK?this.associationError="":o===d.Forbidden_SecurityClassMismatch?this.associationError=`Association not allowed: Node ${this.node.id} does not have the same security class as Node ${e}!`:o===d.Forbidden_DestinationSecurityClassNotGranted?this.associationError=`Association not allowed: Node ${this.node.id} was not granted the highest security class of Node ${e}!`:o===d.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: ${q(d,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}}},O={class:"text-subtitle-1 pa-0 ma-0"},z={class:"text-subtitle-1 pa-0 ma-0"};function W(t,e,a,l,s,r){return c(),p(B,{modelValue:r._value,"onUpdate:modelValue":e[7]||(e[7]=o=>r._value=o),"max-width":"500px",persistent:""},{default:i(()=>[n(w,null,{default:i(()=>[n(y,null,{default:i(()=>[...e[8]||(e[8]=[g("span",{class:"text-h5"},"New Association",-1)])]),_:1}),n(v,null,{default:i(()=>[n(I,{"grid-list-md":""},{default:i(()=>[n(_,{modelValue:s.valid,"onUpdate:modelValue":e[5]||(e[5]=o=>s.valid=o),ref:"form","validate-on":"lazy"},{default:i(()=>[n(G,null,{default:i(()=>[n(u,{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(u,{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})=>[m(f(o.raw.title),1)]),item:i(({item:o,props:C})=>[n(R,S(C,{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?(c(),p(u,{key:0,cols:"12"},{default:i(()=>[g("p",O,[e[9]||(e[9]=m(" Max associations: ",-1)),g("strong",null,f(r.maxNodes),1)]),g("p",z,[e[10]||(e[10]=m(" Actual associations: ",-1)),g("strong",null,f(r.nodesInGroup),1)])]),_:1})):h("",!0),r.nodesInGroup<r.maxNodes?(c(),p(u,{key:1,class:"pa-0"},{default:i(()=>[n(u,{cols:"12"},{default:i(()=>[n(F,{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?(c(),p(u,{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})):h("",!0),s.associationError?(c(),p(u,{key:1,cols:"12"},{default:i(()=>[n(T,{text:"",density:"compact",type:"error"},{default:i(()=>[m(f(s.associationError),1)]),_:1}),r.canForceAssociation?(c(),p(U,{key:0,modelValue:s.forceAssociation,"onUpdate:modelValue":e[4]||(e[4]=o=>s.forceAssociation=o),label:"I know what I'm doing - bypass this check",density:"compact",color:"warning",hint:"Warning: This association may not work correctly","persistent-hint":""},null,8,["modelValue"])):h("",!0)]),_:1})):h("",!0)]),_:1})):h("",!0)]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}),n(D,null,{default:i(()=>[n(M),n(b,{color:"blue-darken-1",variant:"text",onClick:e[6]||(e[6]=o=>t.$emit("close"))},{default:i(()=>[...e[11]||(e[11]=[m("Cancel",-1)])]),_:1}),n(b,{color:"blue-darken-1",variant:"text",disabled:r.nodesInGroup>=r.maxNodes||!!s.associationError&&!s.forceAssociation,onClick:r.handleAdd},{default:i(()=>[...e[12]||(e[12]=[m("ADD",-1)])]),_:1},8,["disabled","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])}const P=A(j,[["render",W]]);export{P as default};