UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

3 lines (2 loc) 5.81 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./NodeScheduler-DhoaRPN1.js","./index-B9yS4Bcc.js","./index-Bm7DxUwf.css","./VDataTable-CKSj76XP.js","./sort-CSOGXH9I.js","./VTable-BXtGlLLl.js","./VTable-CQyv0wyO.css","./VDataTable-DNwLG7iF.css"])))=>i.map(i=>d[i]); import{_ as b,I as k,d as v,z as m,r as V,o as r,l as C,w as o,U as c,c as f,p as g,t as S,b as h,W as w,i as _,k as p,Q as x,h as E}from"./index-B9yS4Bcc.js";import{V as I}from"./VDataTable-CKSj76XP.js";import"./sort-CSOGXH9I.js";import"./VTable-BXtGlLLl.js";const U={mixins:[k],props:{node:Object},components:{NodeScheduler:v(()=>m(()=>import("./NodeScheduler-DhoaRPN1.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]),import.meta.url))},data(){return{statuses:[{title:"Available",value:0},{title:"Enabled",value:1},{title:"Disabled",value:2}],loading:!1,editingState:{}}},computed:{headers(){const t=[{title:"User Id",key:"id"},{title:"Code",key:"code"},{title:"Status",key:"status"}];return this.node.schedule&&t.push({title:"Scheduling",key:"schedule"}),t},values(){var t;return((t=this.node.values)==null?void 0:t.filter(e=>e.commandClass===99))||[]},userCodes(){if(!this.values)return[];const t=[];for(const e of this.values){const s=e.propertyKey,n=t[s]||this.getBaseItem(s),i=e.property;if(i==="userCode")n.code=e.value;else if(i==="userIdStatus")n.status=e.value;else continue;t[s]=n}return t.filter(e=>!!e)}},methods:{startEditing(t,e){const s=t.id;this.editingState[s]||(this.editingState[s]={editingCode:!1,newCode:"",editingStatus:!1,newStatus:""});const n=this.editingState[s];e==="code"?(n.editingCode=!0,n.newCode=t.code||""):e==="status"&&(n.editingStatus=!0,n.newStatus=t.status)},cancelEditing(t,e){const s=t.id;this.editingState[s]&&(e==="code"?this.editingState[s].editingCode=!1:e==="status"&&(this.editingState[s].editingStatus=!1))},async setEnabled(t){const e=!t.schedule.enabled;(await this.app.apiRequest("setEnabledSchedule",[this.node.id,e,t.id])).success||this.showSnackbar(`User ID ${t.id} ${e?"enabled":"disabled"}`,"success")},getStatus(t){var e;return(e=this.statuses.find(s=>s.value===t))==null?void 0:e.text},getSlots(t){const e=[];for(const s in this.node.schedule)e.push(...this.node.schedule[s].slots.filter(n=>n.userId===t).map(n=>({...n,type:s})));return e},getBaseItem(t){var s;const e={id:t};if(this.node.schedule){const n=this.getSlots(t);e.schedule={type:((s=n.find(i=>i.enabled))==null?void 0:s.type)||"daily",slots:n,enabled:this.node.userCodes.enabled.includes(t)}}return e},getValueId(t,e){return this.values.find(s=>s.propertyKey===t&&s.property===e)},async setUserCode(t){const e=this.editingState[t.id].newCode,s=this.getValueId(t.id,"userCode");s&&(s.newValue=e,this.$emit("updateValue",s),this.cancelEditing(t,"code"))},async setUserStatus(t){const e=this.editingState[t.id].newStatus,s=this.getValueId(t.id,"userIdStatus");s&&(s.newValue=e,this.$emit("updateValue",s),this.cancelEditing(t,"status"))}}},B=["onClick"],D={key:1},M=["onClick"],T={key:1},N={class:"mb-0"},z={class:"text-capitalize"},A=["colspan"],P={key:1,class:"text-center ma-3"};function R(t,e,s,n,i,a){const y=V("node-scheduler");return r(),C(I,{headers:a.headers,items:a.userCodes,"items-per-page":-1,"mobile-breakpoint":0,"item-key":"id","footer-props":{showFirstLastPage:!0},dense:"","show-expand":!!s.node.schedule,"expand-on-click":""},{"item.code":o(({item:d})=>{var l;return[c("div",null,[(l=i.editingState[d.id])!=null&&l.editingCode?(r(),f("div",D,[h(w,{modelValue:i.editingState[d.id].newCode,"onUpdate:modelValue":u=>i.editingState[d.id].newCode=u,label:"Code",style:{"max-width":"250px"},"single-line":""},{append:o(()=>[h(_,{class:"mr-2",color:"success",style:{cursor:"pointer"},onClick:g(u=>a.setUserCode(d),["stop"])},{default:o(()=>e[0]||(e[0]=[p(" check ")])),_:2,__:[0]},1032,["onClick"]),h(_,{color:"error",style:{cursor:"pointer"},onClick:g(u=>a.cancelEditing(d,"code"),["stop"])},{default:o(()=>e[1]||(e[1]=[p(" close ")])),_:2,__:[1]},1032,["onClick"])]),_:2},1032,["modelValue","onUpdate:modelValue"])])):(r(),f("span",{key:0,style:{cursor:"pointer"},onClick:g(u=>a.startEditing(d,"code"),["stop"])},S(d.code||"-------"),9,B))])]}),"item.status":o(({item:d})=>{var l;return[c("div",null,[(l=i.editingState[d.id])!=null&&l.editingStatus?(r(),f("div",T,[h(x,{modelValue:i.editingState[d.id].newStatus,"onUpdate:modelValue":u=>i.editingState[d.id].newStatus=u,items:i.statuses,style:{"max-width":"250px"},label:"Status","single-line":""},{append:o(()=>[h(_,{class:"mr-2",color:"success",style:{cursor:"pointer"},onClick:g(u=>a.setUserStatus(d),["stop"])},{default:o(()=>e[2]||(e[2]=[p(" check ")])),_:2,__:[2]},1032,["onClick"]),h(_,{color:"error",style:{cursor:"pointer"},onClick:g(u=>a.cancelEditing(d,"status"),["stop"])},{default:o(()=>e[3]||(e[3]=[p(" close ")])),_:2,__:[3]},1032,["onClick"])]),_:2},1032,["modelValue","onUpdate:modelValue","items"])])):(r(),f("span",{key:0,onClick:g(u=>a.startEditing(d,"status"),["stop"])},S(a.getStatus(d.status)||"-------"),9,M))])]}),"item.schedule":o(({item:d})=>[h(E,{size:"x-small",variant:"flat",color:d.schedule.enabled?"success":"error",onClick:l=>a.setEnabled(d)},{default:o(()=>[p(S(d.schedule.enabled?"Enabled":"Disabled"),1)]),_:2},1032,["color","onClick"]),c("p",N,[e[4]||(e[4]=p(" Mode: ")),c("b",z,S(d.schedule.type||"---"),1),e[5]||(e[5]=p(" Slots:")),c("b",null,S(d.schedule.slots.filter(l=>l.type===d.schedule.type).length),1)])]),"expanded-row":o(({columns:d,item:l})=>[c("td",{colspan:d.length},[s.node.userCodes.available.includes(l.id)?(r(),C(y,{key:0,node:s.node,_user:l,activeMode:l.schedule.type},null,8,["node","_user","activeMode"])):(r(),f("p",P,e[6]||(e[6]=[c("b",null,"Enable this User Id in order to set schedules",-1)])))],8,A)]),_:2},1032,["headers","items","show-expand"])}const j=b(U,[["render",R]]);export{j as default};