iobroker.admin 6.2.18 → 6.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/admin/jsonConfig.json5 +0 -4
- package/io-package.json +13 -13
- package/main.js +8 -2
- package/package.json +1 -1
- package/www/asset-manifest.json +15 -15
- package/www/index.html +1 -1
- package/www/static/js/1553.c291692c.chunk.js +709 -0
- package/www/static/js/1553.c291692c.chunk.js.map +1 -0
- package/www/static/js/{5710.72e95b8e.chunk.js → 5710.05cde997.chunk.js} +4 -4
- package/www/static/js/5710.05cde997.chunk.js.map +1 -0
- package/www/static/js/7228.cd98fee1.chunk.js +67 -0
- package/www/static/js/7228.cd98fee1.chunk.js.map +1 -0
- package/www/static/js/{7412.6bf54cc4.chunk.js → 7412.e4b0556a.chunk.js} +5 -5
- package/www/static/js/7412.e4b0556a.chunk.js.map +1 -0
- package/www/static/js/{7858.d768cb91.chunk.js → 7858.b16a767f.chunk.js} +10 -10
- package/www/static/js/7858.b16a767f.chunk.js.map +1 -0
- package/www/static/js/8596.62e5938c.chunk.js +3 -0
- package/www/static/js/8596.62e5938c.chunk.js.map +1 -0
- package/www/static/js/{main.1fb226a1.js → main.b9cd96c6.js} +5 -5
- package/www/static/js/{main.1fb226a1.js.map → main.b9cd96c6.js.map} +1 -1
- package/www/static/js/1553.1c221cad.chunk.js +0 -709
- package/www/static/js/1553.1c221cad.chunk.js.map +0 -1
- package/www/static/js/5710.72e95b8e.chunk.js.map +0 -1
- package/www/static/js/7228.7cff9ec6.chunk.js +0 -67
- package/www/static/js/7228.7cff9ec6.chunk.js.map +0 -1
- package/www/static/js/7412.6bf54cc4.chunk.js.map +0 -1
- package/www/static/js/7858.d768cb91.chunk.js.map +0 -1
- package/www/static/js/8596.803204cf.chunk.js +0 -3
- package/www/static/js/8596.803204cf.chunk.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[7412],{32761:function(kt,ze,h){h.d(ze,{Z:function(){return z}});var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(58503),te=h(66966),K=h(55289),oe=h(13820),L=h(49630),qe=h(65890),Z=h(33577);const X=S=>({tabs:{height:"100%",width:"100%"},panel:{height:"calc(100% - 48px)",width:"100%",display:"block"}});class Ve extends qe.Z{constructor(g){super(g);let u=(window._localStorage||window.localStorage).getItem((this.props.dialogName||"App")+"."+this.props.adapterName)||Object.keys(this.props.schema.items)[0];Object.keys(this.props.schema.items).includes(u)||(u=Object.keys(this.props.schema.items)[0]),this.state={tab:u}}render(){const g=this.props.schema.items;return s().createElement("div",{className:this.props.classes.tabs},s().createElement(oe.Z,{value:this.state.tab,onChange:(u,v)=>{(window._localStorage||window.localStorage).setItem((this.props.dialogName||"App")+"."+this.props.adapterName,v),this.setState({tab:v})}},Object.keys(g).map(u=>{let v;if(this.props.custom){if(this.executeCustom(g[u].hidden,this.props.data,this.props.customObj,this.props.instanceObj))return null;v=this.executeCustom(g[u].disabled,this.props.data,this.props.customObj,this.props.instanceObj)}else{if(this.execute(g[u].hidden,!1))return null;v=this.execute(g[u].disabled,!1)}return s().createElement(L.Z,{wrapped:!0,disabled:v,key:u,value:u,label:this.getText(g[u].label)})})),s().createElement(Z.Z,{isParentTab:!0,key:this.state.tab,index:1001,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,onCommandRunning:this.props.onCommandRunning,commandRunning:this.props.commandRunning,className:this.props.classes.panel,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,customs:this.props.customs,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,systemConfig:this.props.systemConfig,onError:this.props.onError,onChange:this.props.onChange,multiEdit:this.props.multiEdit,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,imagePrefix:this.props.imagePrefix,changeLanguage:this.props.changeLanguage,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:g[this.state.tab]}))}}Ve.propTypes={socket:l().object.isRequired,themeType:l().string,themeName:l().string,style:l().object,className:l().string,data:l().object.isRequired,originalData:l().object,schema:l().object,onError:l().func,onChange:l().func,customs:l().object,adapterName:l().string,instance:l().number,commandRunning:l().bool,onCommandRunning:l().func,dateFormat:l().string,isFloatComma:l().bool,multiEdit:l().bool,imagePrefix:l().string,customObj:l().object,instanceObj:l().object,custom:l().bool,registerOnForceUpdate:l().func.isRequired,forceUpdate:l().func.isRequired,changeLanguage:l().func,systemConfig:l().object,alive:l().bool,common:l().object};var J=(0,G.withStyles)(X)(Ve),me=Object.defineProperty,R=Object.defineProperties,_e=Object.getOwnPropertyDescriptors,Se=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,pe=(S,g,u)=>g in S?me(S,g,{enumerable:!0,configurable:!0,writable:!0,value:u}):S[g]=u,le=(S,g)=>{for(var u in g||(g={}))He.call(g,u)&&pe(S,u,g[u]);if(Se)for(var u of Se(g))he.call(g,u)&&pe(S,u,g[u]);return S},P=(S,g)=>R(S,_e(g)),ie=(S,g,u)=>(pe(S,typeof g!="symbol"?g+"":g,u),u);const V=S=>({root:{width:"100%",height:"100%"}});class B extends C.Component{constructor(g){super(g),ie(this,"onCommandRunning",u=>this.setState({commandRunning:u})),ie(this,"onAlive",(u,v)=>{((v==null?void 0:v.val)||!1)!==this.state.alive&&this.setState({alive:(v==null?void 0:v.val)||!1})}),ie(this,"onChange",(u,v,I,M)=>{if(this.props.onValueChange)this.props.onValueChange(u,v,M),I&&I();else if(u){const k={data:u},N={};Object.keys(u).forEach(q=>!q.startsWith("_")&&(N[q]=u[q])),k.changed=JSON.stringify(N)!==this.state.originalData,this.setState(k,()=>{this.props.onChange(N,k.changed,M),I&&I()})}else M&&this.props.onChange(null,null,M)}),ie(this,"onError",(u,v)=>{const I=JSON.parse(JSON.stringify(this.state.errors));v?I[u]=v:delete I[u],JSON.stringify(I)!==JSON.parse(JSON.stringify(this.state.errors))&&this.setState({errors:I},()=>this.props.onError(!!Object.keys(this.state.errors).length))}),ie(this,"changeLanguage",()=>{this.forceUpdate()}),ie(this,"forceAttrUpdate",(u,v)=>{Array.isArray(u)?u.forEach(I=>this.forceUpdateHandlers[I]&&this.forceUpdateHandlers[I](v)):this.forceUpdateHandlers[u]&&this.forceUpdateHandlers[u](v)}),ie(this,"registerOnForceUpdate",(u,v)=>{v?this.forceUpdateHandlers[u]=v:this.forceUpdateHandlers[u]&&delete this.forceUpdateHandlers[u]}),this.state={originalData:JSON.stringify(this.props.data),changed:!1,errors:{},updateData:this.props.updateData,systemConfig:null,alive:!1,commandRunning:!1,schema:JSON.parse(JSON.stringify(this.props.schema))},this.forceUpdateHandlers={},this.buildDependencies(this.state.schema),this.readData()}static getDerivedStateFromProps(g,u){return g.updateData!==u.updateData?{updateData:g.updateData,originalData:JSON.stringify(g.data),schema:JSON.parse(JSON.stringify(g.schema))}:null}static loadI18n(g,u,v){if(u===!0||u&&typeof u=="string"){const I=K.default.getLanguage(),M=typeof u=="string"?u:"i18n";return g.fileExists(v+".admin",`${M}/${I}.json`).then(k=>k?`${M}/${I}.json`:g.fileExists(v+".admin",`${M}/${I}/translations.json`).then(N=>N?`${M}/${I}/translations.json`:"")).then(k=>k?g.readFile(v+".admin",k).then(N=>{N.file!==void 0&&(N=N.file);try{N=JSON.parse(N),K.default.extendTranslations(N,I)}catch(q){console.error(`Cannot parse language file "${v}.admin/${k}: ${q}`)}}):(console.warn(`Cannot find i18n for ${v} / ${k}`),Promise.resolve()))}else return u&&typeof u=="object"&&K.default.extendTranslations(u),Promise.resolve()}readSettings(){return(this.props.custom||this.props.common)&&this.props.data?Promise.resolve():this.props.socket.getObject(`system.adapter.${this.props.adapterName}.${this.props.instance}`).then(g=>this.setState({common:g.common,data:this.props.data||g.native}))}readData(){this.readSettings().then(()=>this.props.socket.getCompactSystemConfig()).then(g=>this.props.socket.getState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`).then(u=>{this.props.custom?this.setState({systemConfig:g.common,alive:!!(u&&u.val)}):this.setState({systemConfig:g.common,alive:!!(u&&u.val)},()=>this.props.socket.subscribeState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`,this.onAlive))}))}flatten(g,u){return u=u||{},g.items&&Object.keys(g.items).forEach(v=>{u[v]=g.items[v],this.flatten(g.items[v],u)}),u}buildDependencies(g){const u=this.flatten(g);Object.keys(u).forEach(v=>{var I,M,k,N,q,xe,be,se,ue,re;(I=u[v].confirm)!=null&&I.alsoDependsOn&&((M=u[v].confirm)==null||M.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].confirmDependsOn=u[y].confirmDependsOn||[];const Y=P(le({},u[v]),{attr:v});Y.confirm&&(Y.confirm.cancel="Undo"),u[y].confirmDependsOn.push(Y)}})),(k=u[v].onChange)!=null&&k.alsoDependsOn&&((N=u[v].onChange)==null||N.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].onChangeDependsOn=u[y].onChangeDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].onChangeDependsOn.push(Y)}})),(q=u[v].hidden)!=null&&q.alsoDependsOn&&((xe=u[v].hidden)==null||xe.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].hiddenDependsOn=u[y].hiddenDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].hiddenDependsOn.push(Y)}})),(be=u[v].label)!=null&&be.alsoDependsOn&&((se=u[v].label)==null||se.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].labelDependsOn=u[y].labelDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].labelDependsOn.push(Y)}})),(ue=u[v].help)!=null&&ue.alsoDependsOn&&((re=u[v].help)==null||re.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].helpDependsOn=u[y].helpDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].helpDependsOn.push(Y)}}))})}renderItem(g){if(g.type==="tabs")return s().createElement(J,{onCommandRunning:this.onCommandRunning,commandRunning:this.state.commandRunning,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.state.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:JSON.parse(this.state.originalData),schema:g,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,imagePrefix:this.props.imagePrefix,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,changeLanguage:this.changeLanguage,forceUpdate:this.forceAttrUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:(u,v)=>this.onError(u,v)});if(g.type==="panel"||!g.type)return s().createElement(Z.Z,{index:1e3,isParentTab:!0,onCommandRunning:this.onCommandRunning,commandRunning:this.state.commandRunning,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.state.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:JSON.parse(this.state.originalData),schema:g,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,imagePrefix:this.props.imagePrefix,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,changeLanguage:this.changeLanguage,forceUpdate:this.forceAttrUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:(u,v)=>this.onError(u,v)})}render(){return this.state.systemConfig?s().createElement("div",{className:this.props.classes.root},this.renderItem(this.state.schema)):s().createElement(te.Z,null)}}B.propTypes={socket:l().object.isRequired,adapterName:l().string,instance:l().number,common:l().object,customs:l().object,custom:l().bool,customObj:l().object,multiEdit:l().bool,instanceObj:l().object,dateFormat:l().string,isFloatComma:l().bool,imagePrefix:l().string,themeType:l().string,themeName:l().string,style:l().object,className:l().string,data:l().object.isRequired,updateData:l().number,schema:l().object,onError:l().func,onChange:l().func,onValueChange:l().func};var z=(0,G.withStyles)(V)(B)},94437:function(kt,ze,h){var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(23167),te=h(86856),K=h(58503),oe=h.n(K),L=h(94427),qe=h.n(L),Z=h(72170),X=h(62976),Ve=h(16055),J=h(42158),me=h(33919),R=h(4819),_e=Object.defineProperty,Se=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,pe=(B,z,S)=>z in B?_e(B,z,{enumerable:!0,configurable:!0,writable:!0,value:S}):B[z]=S,le=(B,z)=>{for(var S in z||(z={}))He.call(z,S)&&pe(B,S,z[S]);if(Se)for(var S of Se(z))he.call(z,S)&&pe(B,S,z[S]);return B};const P=`
|
|
1
|
+
"use strict";(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[7412],{32761:function(kt,ze,h){h.d(ze,{Z:function(){return z}});var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(58503),te=h(66966),K=h(55289),oe=h(13820),L=h(49630),qe=h(65890),Z=h(33577);const X=S=>({tabs:{height:"100%",width:"100%"},panel:{height:"calc(100% - 48px)",width:"100%",display:"block"}});class Ve extends qe.Z{constructor(g){super(g);let u=(window._localStorage||window.localStorage).getItem((this.props.dialogName||"App")+"."+this.props.adapterName)||Object.keys(this.props.schema.items)[0];Object.keys(this.props.schema.items).includes(u)||(u=Object.keys(this.props.schema.items)[0]),this.state={tab:u}}render(){const g=this.props.schema.items;return s().createElement("div",{className:this.props.classes.tabs},s().createElement(oe.Z,{value:this.state.tab,onChange:(u,v)=>{(window._localStorage||window.localStorage).setItem((this.props.dialogName||"App")+"."+this.props.adapterName,v),this.setState({tab:v})}},Object.keys(g).map(u=>{let v;if(this.props.custom){if(this.executeCustom(g[u].hidden,this.props.data,this.props.customObj,this.props.instanceObj))return null;v=this.executeCustom(g[u].disabled,this.props.data,this.props.customObj,this.props.instanceObj)}else{if(this.execute(g[u].hidden,!1))return null;v=this.execute(g[u].disabled,!1)}return s().createElement(L.Z,{wrapped:!0,disabled:v,key:u,value:u,label:this.getText(g[u].label)})})),s().createElement(Z.Z,{isParentTab:!0,key:this.state.tab,index:1001,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,onCommandRunning:this.props.onCommandRunning,commandRunning:this.props.commandRunning,className:this.props.classes.panel,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,customs:this.props.customs,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,systemConfig:this.props.systemConfig,onError:this.props.onError,onChange:this.props.onChange,multiEdit:this.props.multiEdit,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,imagePrefix:this.props.imagePrefix,changeLanguage:this.props.changeLanguage,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:g[this.state.tab]}))}}Ve.propTypes={socket:l().object.isRequired,themeType:l().string,themeName:l().string,style:l().object,className:l().string,data:l().object.isRequired,originalData:l().object,schema:l().object,onError:l().func,onChange:l().func,customs:l().object,adapterName:l().string,instance:l().number,commandRunning:l().bool,onCommandRunning:l().func,dateFormat:l().string,isFloatComma:l().bool,multiEdit:l().bool,imagePrefix:l().string,customObj:l().object,instanceObj:l().object,custom:l().bool,registerOnForceUpdate:l().func.isRequired,forceUpdate:l().func.isRequired,changeLanguage:l().func,systemConfig:l().object,alive:l().bool,common:l().object};var J=(0,G.withStyles)(X)(Ve),me=Object.defineProperty,R=Object.defineProperties,_e=Object.getOwnPropertyDescriptors,Se=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,pe=(S,g,u)=>g in S?me(S,g,{enumerable:!0,configurable:!0,writable:!0,value:u}):S[g]=u,le=(S,g)=>{for(var u in g||(g={}))He.call(g,u)&&pe(S,u,g[u]);if(Se)for(var u of Se(g))he.call(g,u)&&pe(S,u,g[u]);return S},P=(S,g)=>R(S,_e(g)),ie=(S,g,u)=>(pe(S,typeof g!="symbol"?g+"":g,u),u);const V=S=>({root:{width:"100%",height:"100%"}});class B extends C.Component{constructor(g){super(g),ie(this,"onCommandRunning",u=>this.setState({commandRunning:u})),ie(this,"onAlive",(u,v)=>{((v==null?void 0:v.val)||!1)!==this.state.alive&&this.setState({alive:(v==null?void 0:v.val)||!1})}),ie(this,"onChange",(u,v,I,M)=>{if(this.props.onValueChange)this.props.onValueChange(u,v,M),I&&I();else if(u){const k={data:u},D={};Object.keys(u).forEach(q=>!q.startsWith("_")&&(D[q]=u[q])),k.changed=JSON.stringify(D)!==this.state.originalData,this.setState(k,()=>{this.props.onChange(D,k.changed,M),I&&I()})}else M&&this.props.onChange(null,null,M)}),ie(this,"onError",(u,v)=>{this.errorChached=this.errorChached||JSON.parse(JSON.stringify(this.state.errors));const I=this.errorChached;v?I[u]=v:delete I[u],JSON.stringify(I)!==JSON.stringify(this.state.errors)?(this.errorTimeout&&clearTimeout(this.errorTimeout),this.errorTimeout=setTimeout(()=>this.setState({errors:this.errorChached},()=>{this.errorTimeout=null,this.errorChached=null,this.props.onError(!!Object.keys(this.state.errors).length)}),50)):this.errorChached=null}),ie(this,"changeLanguage",()=>{this.forceUpdate()}),ie(this,"forceAttrUpdate",(u,v)=>{Array.isArray(u)?u.forEach(I=>this.forceUpdateHandlers[I]&&this.forceUpdateHandlers[I](v)):this.forceUpdateHandlers[u]&&this.forceUpdateHandlers[u](v)}),ie(this,"registerOnForceUpdate",(u,v)=>{v?this.forceUpdateHandlers[u]=v:this.forceUpdateHandlers[u]&&delete this.forceUpdateHandlers[u]}),this.state={originalData:JSON.stringify(this.props.data),changed:!1,errors:{},updateData:this.props.updateData,systemConfig:null,alive:!1,commandRunning:!1,schema:JSON.parse(JSON.stringify(this.props.schema))},this.forceUpdateHandlers={},this.buildDependencies(this.state.schema),this.readData()}static getDerivedStateFromProps(g,u){return g.updateData!==u.updateData?{updateData:g.updateData,originalData:JSON.stringify(g.data),schema:JSON.parse(JSON.stringify(g.schema))}:null}static loadI18n(g,u,v){if(u===!0||u&&typeof u=="string"){const I=K.default.getLanguage(),M=typeof u=="string"?u:"i18n";return g.fileExists(v+".admin",`${M}/${I}.json`).then(k=>k?`${M}/${I}.json`:g.fileExists(v+".admin",`${M}/${I}/translations.json`).then(D=>D?`${M}/${I}/translations.json`:"")).then(k=>k?g.readFile(v+".admin",k).then(D=>{D.file!==void 0&&(D=D.file);try{D=JSON.parse(D),K.default.extendTranslations(D,I)}catch(q){console.error(`Cannot parse language file "${v}.admin/${k}: ${q}`)}}):(console.warn(`Cannot find i18n for ${v} / ${k}`),Promise.resolve()))}else return u&&typeof u=="object"&&K.default.extendTranslations(u),Promise.resolve()}readSettings(){return(this.props.custom||this.props.common)&&this.props.data?Promise.resolve():this.props.socket.getObject(`system.adapter.${this.props.adapterName}.${this.props.instance}`).then(g=>this.setState({common:g.common,data:this.props.data||g.native}))}readData(){this.readSettings().then(()=>this.props.socket.getCompactSystemConfig()).then(g=>this.props.socket.getState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`).then(u=>{this.props.custom?this.setState({systemConfig:g.common,alive:!!(u&&u.val)}):this.setState({systemConfig:g.common,alive:!!(u&&u.val)},()=>this.props.socket.subscribeState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`,this.onAlive))}))}flatten(g,u){return u=u||{},g.items&&Object.keys(g.items).forEach(v=>{u[v]=g.items[v],this.flatten(g.items[v],u)}),u}buildDependencies(g){const u=this.flatten(g);Object.keys(u).forEach(v=>{var I,M,k,D,q,xe,be,se,ue,re;(I=u[v].confirm)!=null&&I.alsoDependsOn&&((M=u[v].confirm)==null||M.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].confirmDependsOn=u[y].confirmDependsOn||[];const Y=P(le({},u[v]),{attr:v});Y.confirm&&(Y.confirm.cancel="Undo"),u[y].confirmDependsOn.push(Y)}})),(k=u[v].onChange)!=null&&k.alsoDependsOn&&((D=u[v].onChange)==null||D.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].onChangeDependsOn=u[y].onChangeDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].onChangeDependsOn.push(Y)}})),(q=u[v].hidden)!=null&&q.alsoDependsOn&&((xe=u[v].hidden)==null||xe.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].hiddenDependsOn=u[y].hiddenDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].hiddenDependsOn.push(Y)}})),(be=u[v].label)!=null&&be.alsoDependsOn&&((se=u[v].label)==null||se.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].labelDependsOn=u[y].labelDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].labelDependsOn.push(Y)}})),(ue=u[v].help)!=null&&ue.alsoDependsOn&&((re=u[v].help)==null||re.alsoDependsOn.forEach(y=>{if(!u[y])console.error(`[JsonConfigComponent] Attribute ${y} does not exist!`),y.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${y.replace(/^data\./,"")}" instead of "${y}"`);else{u[y].helpDependsOn=u[y].helpDependsOn||[];const Y=P(le({},u[v]),{attr:v});u[y].helpDependsOn.push(Y)}}))})}renderItem(g){if(g.type==="tabs")return s().createElement(J,{onCommandRunning:this.onCommandRunning,commandRunning:this.state.commandRunning,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.state.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:JSON.parse(this.state.originalData),schema:g,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,imagePrefix:this.props.imagePrefix,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,changeLanguage:this.changeLanguage,forceUpdate:this.forceAttrUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:(u,v)=>this.onError(u,v)});if(g.type==="panel"||!g.type)return s().createElement(Z.Z,{index:1e3,isParentTab:!0,onCommandRunning:this.onCommandRunning,commandRunning:this.state.commandRunning,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.state.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:JSON.parse(this.state.originalData),schema:g,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,imagePrefix:this.props.imagePrefix,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,changeLanguage:this.changeLanguage,forceUpdate:this.forceAttrUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:(u,v)=>this.onError(u,v)})}render(){return this.state.systemConfig?s().createElement("div",{className:this.props.classes.root},this.renderItem(this.state.schema)):s().createElement(te.Z,null)}}B.propTypes={socket:l().object.isRequired,adapterName:l().string,instance:l().number,common:l().object,customs:l().object,custom:l().bool,customObj:l().object,multiEdit:l().bool,instanceObj:l().object,dateFormat:l().string,isFloatComma:l().bool,imagePrefix:l().string,themeType:l().string,themeName:l().string,style:l().object,className:l().string,data:l().object.isRequired,updateData:l().number,schema:l().object,onError:l().func,onChange:l().func,onValueChange:l().func};var z=(0,G.withStyles)(V)(B)},94437:function(kt,ze,h){var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(23167),te=h(86856),K=h(58503),oe=h.n(K),L=h(94427),qe=h.n(L),Z=h(72170),X=h(62976),Ve=h(16055),J=h(42158),me=h(33919),R=h(4819),_e=Object.defineProperty,Se=Object.getOwnPropertySymbols,He=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable,pe=(B,z,S)=>z in B?_e(B,z,{enumerable:!0,configurable:!0,writable:!0,value:S}):B[z]=S,le=(B,z)=>{for(var S in z||(z={}))He.call(z,S)&&pe(B,S,z[S]);if(Se)for(var S of Se(z))he.call(z,S)&&pe(B,S,z[S]);return B};const P=`
|
|
2
2
|
/*!
|
|
3
3
|
* Cropper.js v1.5.12
|
|
4
4
|
* https://fengyuanchen.github.io/cropperjs
|
|
@@ -303,9 +303,9 @@
|
|
|
303
303
|
.cropper-disabled .cropper-point {
|
|
304
304
|
cursor: not-allowed;
|
|
305
305
|
}
|
|
306
|
-
`,ie=B=>({dropZone:{width:"100%",height:100,position:"relative"},dropZoneEmpty:{},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadDiv:{position:"relative",width:"100%",height:300,opacity:.9,marginTop:30,cursor:"pointer",outline:"none"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"calc(100% - 10px)",height:"calc(100% - 10px)",position:"relative",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},disabledOpacity:{opacity:.3,cursor:"default"},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},buttonCropWrapper:{position:"absolute",zIndex:222,right:0,top:50},error:{border:"2px solid red"}});class V extends C.Component{constructor(z){if(super(z),this.state={uploadFile:!1,anchorEl:null,cropHandler:!1},this.cropperRef=(0,C.createRef)(),!window.document.getElementById("cropper-style-json-component")){const S=window.document.createElement("style");S.setAttribute("id","cropper-style-json-component"),S.innerHTML=P,window.document.head.appendChild(S)}}onDrop(z){const{maxSize:S,t:g,onChange:u}=this.props,v=z[0],I=new FileReader;I.onabort=()=>console.log("file reading was aborted"),I.onerror=()=>console.log("file reading has failed"),I.onload=()=>{let M="image/"+v.name.split(".").pop().toLowerCase();if(M==="image/jpg"?M="image/jpeg":M.includes("svg")&&(M="image/svg+xml"),v.size>S)return window.alert(g("ra_File is too big. Max %sk allowed. Try use SVG.",Math.round(S/1024)));const k=`data:${M};base64,${btoa(new Uint8Array(I.result).reduce((N,q)=>N+String.fromCharCode(q),""))}`;u(k)},I.readAsArrayBuffer(v)}render(){const{disabled:z,maxSize:S,classes:g,icon:u,t:v,removeIconFunc:I,accept:M,error:k,crop:N,onChange:q}=this.props,{uploadFile:xe,anchorEl:be,cropHandler:se}=this.state;return R.createElement(G.default,{disabled:z||se,key:"dropzone",multiple:!1,accept:M,maxSize:S,onDragEnter:()=>this.setState({uploadFile:"dragging"}),onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(ue,re)=>{if(this.setState({uploadFile:!1}),!ue.length)window.alert(re&&re[0]&&re[0].errors&&re[0].errors[0]&&re[0].errors[0].message||v("ra_Cannot upload"));else return this.onDrop(ue)}},({getRootProps:ue,getInputProps:re})=>R.createElement("div",le({className:me.default.clsx(g.uploadDiv,xe==="dragging"&&g.uploadDivDragging,g.dropZone,z&&g.disabledOpacity,!u&&g.dropZoneEmpty)},ue()),R.createElement("input",le({},re())),R.createElement("div",{className:me.default.clsx(g.uploadCenterDiv,k&&g.error)},u?I&&!se&&R.createElement("div",{className:g.buttonRemoveWrapper},R.createElement(L.Tooltip,{title:v("ra_Clear")},R.createElement(Z.Z,{size:"large",onClick:y=>{I&&I(),y.stopPropagation()}},R.createElement(X.default,null)))):R.createElement("div",{className:g.uploadCenterTextAndIcon},R.createElement(J.FaFileUpload,{className:g.uploadCenterIcon}),R.createElement("div",{className:g.uploadCenterText},v(xe==="dragging"?"ra_Drop file here":"ra_Place your files here or click here to open the browse dialog"))),u&&N&&R.createElement("div",{className:g.buttonCropWrapper},R.createElement(L.Tooltip,{title:v("ra_Crop")},R.createElement(Z.Z,{size:"large",onClick:y=>{se?this.setState({anchorEl:y.currentTarget}):this.setState({cropHandler:!0}),y.stopPropagation()}},R.createElement(Ve.default,{color:se?"primary":"inherit"}))),R.createElement(L.Menu,{anchorEl:be,keepMounted:!0,open:Boolean(be),onClose:()=>this.setState({anchorEl:null})},R.createElement(L.MenuItem,{onClick:()=>this.setState({anchorEl:null,cropHandler:!1},()=>{var y,Y;const nt=(Y=(y=this.cropperRef)==null?void 0:y.current)==null?void 0:Y.cropper;q(nt.getCroppedCanvas().toDataURL())})},v("ra_Save")),R.createElement(L.MenuItem,{onClick:()=>this.setState({anchorEl:null,cropHandler:!1})},v("ra_Close")))),u&&!se?R.createElement("img",{src:u,className:g.image,alt:"icon"}):null,u&&N&&se?R.createElement(te.Cropper,{ref:this.cropperRef,className:g.image,src:u,initialAspectRatio:1,viewMode:1,guides:!1,minCropBoxHeight:10,minCropBoxWidth:10,background:!1,checkOrientation:!1}):null)))}}V.defaultProps={disabled:!1,maxSize:10*1024,icon:null,removeIconFunc:null,accept:{"image/*":[]},error:!1,onChange:B=>console.log(B),t:B=>B,crop:!1},V.propTypes={classes:l().object,maxSize:l().number,disabled:l().bool,crop:l().bool,error:l().bool,onChange:l().func,accept:l().object,t:l().func},ze.Z=(0,K.withStyles)(ie)(V)},37412:function(kt,ze,h){h.r(ze),h.d(ze,{default:function(){return Co}});var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(58503),te=h(66447),K=h(29480),oe=h(6774),L=h(19974),qe=h(44887),Z=h(78565),X=h(72170),Ve=h(96094),J=h(62976),me=h(91495),R=h(70703),_e=h(56322),Se=h(36609),He=h(13820),he=h(49630),pe=h(43924),le=h(41728),P=h(55289),ie=h(28027),V=h(23060),B=h(87951),z=h.n(B),S=h(66966),g=h(28475),u=h(18226),v=h(12923),I=h(99296),M=h(30464),k=h(2598),N=h(36315),q=h(62664),xe=h(99822),be=h(32761),se=h(65890),ue=h(84998),re=Object.defineProperty,y=(r,e,t)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e,t)=>(y(r,typeof e!="symbol"?e+"":e,t),t),nt=(r,e,t)=>new Promise((a,o)=>{var i=d=>{try{c(t.next(d))}catch(m){o(m)}},n=d=>{try{c(t.throw(d))}catch(m){o(m)}},c=d=>d.done?a(d.value):Promise.resolve(d.value).then(i,n);c((t=t.apply(r,e)).next())});const Zs=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},headingIcon:{marginRight:5,width:32,height:32},titleEnabled:{float:"right",fontSize:16,color:"#7ff57f",textTransform:"uppercase",fontWeight:"bold",paddingLeft:20},scrollDiv:{width:"100%",height:"100%",overflow:"auto"},fullWidth:{width:"100%"},enabledControl:{width:130,display:"inline-block",verticalAlign:"top"},customControls:{width:"calc(100% - 130px)",maxWidth:800,display:"inline-block",verticalAlign:"top",paddingTop:16},accordionOdd:{},accordionEven:{backgroundColor:"rgba(128, 128, 128, 0.1)"},accordionHeaderOdd:{backgroundColor:"rgba(128, 128, 128, 0.2)"},accordionHeaderEven:{backgroundColor:"rgba(128, 128, 128, 0.3)"},accordionHeaderEnabledOdd:{backgroundColor:"rgba(128, 255, 128, 0.2)"},accordionHeaderEnabledEven:{backgroundColor:"rgba(128, 255, 128, 0.2)"},enabledVisible:{display:"inline-block"},enabledInvisible:{display:"none"}}),Rs=".",St=class extends C.Component{constructor(r){super(r),Y(this,"onSave",t=>{if(this.props.objectIDs.length>10&&!this.state.confirmed)return this.cb=t,this.setState({showConfirmation:!0});this.saveOneState([...this.props.objectIDs],()=>{this.changedItems=[],this.cachedNewValues={},this.commonConfig=this.getCommonConfig(),this.setState({confirmed:!1,hasChanges:!1,newValues:{}},()=>{this.props.reportChangedIds(this.changedIds),this.props.onChange(!1,!0),t&&setTimeout(()=>t(),100)})})});let e=(window._localStorage||window.localStorage).getItem("App.customsExpanded")||"[]";try{e=JSON.parse(e)}catch(t){e=[]}this.changedIds=[],this.state={loaded:!1,hasChanges:!1,expanded:e,newValues:{},progress:null,maxOids:null,confirmed:!1,showConfirmation:!1},this.scrollDone=!1,this.lastExpanded=(window._localStorage||window.localStorage).getItem("App.customsLastExpanded")||"",this.scrollDivRef=(0,C.createRef)(),this.changedItems=[],this.jsonConfigs={},this.controls={},this.refTemplate={},this.props.customsInstances.map(t=>this.refTemplate[t]=(0,C.createRef)()),this.customObj=this.props.objectIDs.length>1?{custom:{},native:{}}:JSON.parse(JSON.stringify(this.props.objects[this.props.objectIDs[0]]||null)),this.customObj&&(this.loadAllPromises=this.loadAllCustoms().then(()=>{this.commonConfig=this.getCommonConfig(),this.setState({loaded:!0,newValues:{}})}))}componentDidMount(){this.props.registerSaveFunc&&this.props.registerSaveFunc(this.onSave)}componentWillUnmount(){this.props.registerSaveFunc&&this.props.registerSaveFunc(null)}loadAllCustoms(){const r=[];return this.props.customsInstances.forEach(e=>{const t=e.replace(/\.\d+$/,"").replace("system.adapter.","");this.jsonConfigs[t]===void 0&&(this.jsonConfigs[t]=!1,r.push(this.getCustomTemplate(t)))}),Promise.all(r).then(()=>{this.props.customsInstances.forEach(e=>{var t,a;const o=e.replace(/\.\d+$/,"").replace("system.adapter.","");this.jsonConfigs[o]&&(this.jsonConfigs[o].instanceObjs=this.jsonConfigs[o].instanceObjs||{},this.jsonConfigs[o].instanceObjs[e]={_id:e,common:JSON.parse(JSON.stringify((t=this.props.objects["system.adapter."+e])==null?void 0:t.common)),native:JSON.parse(JSON.stringify((a=this.props.objects["system.adapter."+e])==null?void 0:a.native))})})})}showError(r){this.setState({error:r})}getCustomTemplate(r){var e;const t=this.props.objects["system.adapter."+r]?JSON.parse(JSON.stringify(this.props.objects["system.adapter."+r])):null;return t?(ue.Z.fixAdminUI(t),((e=t.common)==null?void 0:e.adminUI.custom)==="json"?this.props.socket.fileExists(r+".admin","jsonCustom.json5").then(a=>a?this.props.socket.readFile(r+".admin","jsonCustom.json5"):this.props.socket.readFile(r+".admin","jsonCustom.json")).then(a=>{a.file!==void 0&&(a=a.file);try{a=z().parse(a),this.jsonConfigs[r]=this.jsonConfigs[r]||{},this.jsonConfigs[r].json=a}catch(o){console.error(`Cannot parse jsonConfig of ${r}: ${o}`),window.alert(`Cannot parse jsonConfig of ${r}: ${o}`)}return be.Z.loadI18n(this.props.socket,a.i18n,r)}).catch(a=>{console.error(`Cannot load jsonConfig of ${r}: ${a}`),window.alert(`Cannot load jsonConfig of ${r}: ${a}`)}):(console.error(`Adapter ${r} is not yet supported by this version of admin`),window.alert(`Adapter ${r} is not yet supported by this version of admin`),Promise.resolve(null))):(console.error(`Cannot find adapter "${t}"`),Promise.resolve(null))}_executeCustom(r,e,t,a,o,i,n){if(n.includes(i))return;n.push(i);let c=[];if(r&&typeof r=="object"&&(c=r.alsoDependsOn||[],typeof c=="string"&&(c=[c]),r=r.func),c.forEach(d=>{if(o[d])if(o[d].defaultFunc){const m=this._executeCustom(o[d].defaultFunc,e,t,a,o,d,n);m!==void 0&&(e[d]=m)}else return console.error(`[JsonConfigComponent] attribute "${d}" is not required to be includes in "alsoDependsOn" while has static value!`);else return console.error(`[JsonConfigComponent] attribute "${d}" does not exist!`)}),!r)e[i]=o[i].default===void 0?null:o[i].default;else try{const m=new Function("data","originalData","_system","instanceObj","customObj","_socket",r.includes("return")?r:"return "+r)(e||this.props.data,this.props.originalData,this.props.systemConfig,a,t,this.props.socket);e[i]=m}catch(d){console.error(`Cannot execute ${r}: ${d}`),e[i]=!o[i]||o[i].default===void 0?null:o[i].default}}static flattenItems(r,e){return e=e||{},r&&Object.keys(r).forEach(t=>{r[t].items?St.flattenItems(r[t].items,e):e[t]=r[t]}),e}getDefaultValues(r,e){const t={enabled:!1},a=r.split(".")[0];if(this.jsonConfigs[a]&&!this.jsonConfigs[a].disabled){const o=St.flattenItems(this.jsonConfigs[a].json.items);if(o){const i=[],n=Object.keys(o).filter(c=>o[c]);n.forEach(c=>{!o[c].defaultFunc&&o[c].default!==void 0&&(t[c]=o[c].default)}),n.forEach(c=>nt(this,null,function*(){o[c].defaultFunc&&this._executeCustom(o[c].defaultFunc,t,e,this.jsonConfigs[a].instanceObjs[r],o,c,i)}))}}return t}getCommonConfig(){const r=this.props.objectIDs||[],e=this.props.objects,t={};return this.props.customsInstances.forEach(a=>{const o=a.split(".")[0];this.jsonConfigs[o]&&this.jsonConfigs[o].disabled||(t[a]={},r.forEach(i=>{var n;const c=e[i],d=(n=c==null?void 0:c.common)!=null&&n.custom&&c.common.custom[a]||null;if(d)Object.keys(d).forEach(m=>{t[a][m]===void 0?t[a][m]=d[m]:t[a][m]!==d[m]&&(Array.isArray(t[a][m])||(t[a][m]=[t[a][m]]),!t[a][m].includes(d[m])&&t[a][m].push(d[m]))});else{let m=this.getDefaultValues(a,c);m.enabled=!1,Object.keys(m).forEach(f=>{t[a][f]===void 0?t[a][f]=m[f]:t[a][f]!==m[f]&&(Array.isArray(t[a][f])||(t[a][f]=[t[a][f]]),!t[a][f].includes(m[f])&&t[a][f].push(m[f]))})}}),Object.keys(t[a]).forEach(i=>{Array.isArray(t[a][i])&&t[a][i].sort()}))}),t}isChanged(r){return r=r||this.state.newValues,Object.keys(r).find(e=>r[e]===null||r[e]&&Object.keys(r[e]).find(t=>!t.startsWith("_")))}combineNewAndOld(r,e){const t=Object.assign({},this.commonConfig[r]||{},this.state.newValues[r]||{});return e&&Object.keys(t).forEach(a=>{a.startsWith("_")&&delete t[a]}),this.state.newValues[r]===null&&(t.enabled=!1),t}renderOneCustom(r,e,t,a){var o;const i=r.split(".")[0],n=`${Rs}/adapter/${i}/${this.props.objects["system.adapter."+i].common.icon}`,c=this.state.newValues[r]!==void 0&&(!this.state.newValues[r]||this.state.newValues[r].enabled!==void 0)?!!(this.state.newValues[r]&&this.state.newValues[r].enabled):this.state.newValues[r]===null?!1:this.commonConfig[r].enabled,d=Array.isArray(c)&&(!this.state.newValues[r]||this.state.newValues[r].enabled===void 0),m=this.jsonConfigs[i]&&((o=this.jsonConfigs[i].json)==null?void 0:o.disabled),f=this.combineNewAndOld(r);return m&&this.jsonConfigs[i].json.hidden===!0||typeof this.jsonConfigs[i].json.hidden=="string"&&this._executeCustom(this.jsonConfigs[i].json.hidden,f,t,e,this.jsonConfigs[i].json.items,"enabled",[])?null:s().createElement(g.Z,{key:r,id:"Accordion_"+r,className:a%2?this.props.classes.accordionOdd:this.props.classes.accordionEven,expanded:this.state.expanded.includes(r),ref:this.refTemplate[r],onChange:()=>{const p=[...this.state.expanded],j=p.indexOf(r);j===-1?p.push(r):p.splice(j,1),(window._localStorage||window.localStorage).setItem("App.customsExpanded",JSON.stringify(p)),j===-1&&(window._localStorage||window.localStorage).setItem("App.customsLastExpanded",r),this.setState({expanded:p})}},s().createElement(u.Z,{expandIcon:s().createElement(q.default,null),"data-id":r,className:a%2?c?this.props.classes.accordionHeaderEnabledOdd:this.props.classes.accordionHeaderOdd:c?this.props.classes.accordionHeaderEnabledEven:this.props.classes.accordionHeaderEven},s().createElement("img",{src:n,className:this.props.classes.headingIcon,alt:""}),s().createElement(I.Z,{className:this.props.classes.heading},this.props.t("Settings %s",r)),s().createElement("div",{className:(0,V.default)(this.props.classes.titleEnabled,"titleEnabled",c?this.props.classes.enabledVisible:this.props.classes.enabledInvisible)},this.props.t("Enabled"))),s().createElement(v.Z,null,s().createElement("div",{className:this.props.classes.enabledControl},s().createElement(k.Z,{className:this.props.classes.formControl,control:s().createElement(N.Z,{indeterminate:d,checked:!!c,disabled:m,onChange:p=>{this.cachedNewValues=this.cachedNewValues||this.state.newValues;const j=JSON.parse(JSON.stringify(this.cachedNewValues));j[r]=j[r]||{},d||p.target.checked?j[r].enabled=!0:c?j[r]=null:delete j[r],this.cachedNewValues=j,this.setState({newValues:j,hasChanges:this.isChanged(j)},()=>{this.cachedNewValues=null,this.props.onChange&&this.props.onChange(this.state.hasChanges)})}}),label:this.props.t("Enabled")})),s().createElement("div",{className:this.props.classes.customControls},!m&&(c||d)?s().createElement(be.Z,{instanceObj:e,customObj:t,custom:!0,className:"",adapterName:i,instance:parseInt(r.split(".").pop(),10)||0,socket:this.props.socket,theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType,multiEdit:this.props.objectIDs.length>1,schema:this.jsonConfigs[i].json,data:f,onError:p=>this.setState({error:p},()=>this.props.onError&&this.props.onError(p)),onValueChange:(p,j)=>{this.cachedNewValues=this.cachedNewValues||this.state.newValues,console.log(`${p} => ${j}`);const A=JSON.parse(JSON.stringify(this.cachedNewValues));A[r]=A[r]||{},JSON.stringify(se.Z.getValue(this.commonConfig[r],p))===JSON.stringify(j)?(se.Z.setValue(A[r],p,null),Object.keys(A[r]).length||delete A[r]):se.Z.setValue(A[r],p,j),this.cachedNewValues=A,this.setState({newValues:A,hasChanges:this.isChanged(A)},()=>{this.cachedNewValues=null,this.props.onChange&&this.props.onChange(this.state.hasChanges)})}}):null,m&&this.jsonConfigs[i].json.help?typeof this.jsonConfigs[i].json.help=="object"?this.jsonConfigs[i].json.help[this.props.lang]||this.jsonConfigs[i].json.help.en:this.props.t(this.jsonConfigs[i].json.help):null)))}isAllOk(){return!0}renderErrorMessage(){return!!this.state.error&&s().createElement(xe.default,{title:this.props.t("Error"),text:this.state.error,onClose:()=>this.setState({error:""})})}getObject(r,e,t){return r[t]?Promise.resolve(r[t]):this.props.socket.getObject(t).then(a=>(e[t]=JSON.parse(JSON.stringify(a)),r[t]=a,a))}saveOneState(r,e,t,a){if(t=t||{},a=a||{},!r||!r.length){const o=Object.keys(t);if(!o.length)this.setState({maxOids:null},()=>this.props.onProgress(!1)),e&&e();else{this.setState({progress:Math.round((this.state.maxOids-o.length)/this.state.maxOids*50)+50});const i=o.shift();return JSON.stringify(t[i].common)!==JSON.stringify(a[i].common)?(!this.changedIds.includes(i)&&this.changedIds.push(i),this.props.socket.setObject(i,t[i]).then(()=>(delete t[i],delete a[i],this.props.socket.getObject(i).then(n=>{this.props.objects[i]=n,setTimeout(()=>this.saveOneState(r,e,t,a),0)})))):(delete t[i],delete a[i],setTimeout(()=>this.saveOneState(r,e,t,a),0))}}else{const o=this.state.maxOids||r.length;this.state.maxOids===null&&this.setState({maxOids:r.length},()=>this.props.onProgress(!0)),this.setState({progress:Math.round((o-r.length)/o*50)});const i=r.shift();this.getObject(t,a,i).then(n=>{if(!n)return window.alert(`Invalid object ${i}`);n.common&&n.common.custom&&Object.keys(n.common.custom).forEach(d=>{(!n.common.custom[d]||!n.common.custom[d].enabled)&&(n.common.custom[d]=null)});const c=Object.keys(this.state.newValues);for(let d=0;d<c.length;d++){const m=c[d],f=this.combineNewAndOld(m,!0);if(f.enabled===!1)n.common&&n.common.custom&&n.common.custom[m]&&(n.common.custom[m]=null);else if(f.enabled){if(n.common=n.common||{},Array.isArray(f.enabled)&&(!n.common.custom||!n.common.custom[m]||!n.common.custom[m].enabled)){n.common.custom&&n.common.custom[m]&&(n.common.custom[m]=null);continue}if(n.common.custom=n.common.custom||{},!n.common.custom[m]||!n.common.custom[m].enabled){let p=this.getDefaultValues(m,n);n.common.custom[m]=JSON.parse(JSON.stringify(p||{}))}n.common.custom[m].enabled=!0,Object.keys(f).forEach(p=>{(!Array.isArray(f[p])||f[p][0]&&typeof f[p][0]=="object")&&(n.common.custom[m][p]=f[p])})}}setTimeout(()=>this.saveOneState(r,e,t,a),0)})}}renderConfirmationDialog(){return this.state.showConfirmation?s().createElement(le.default,{text:this.props.t("The changes will be applied to %s states. Are you sure?",this.props.objectIDs.length),ok:this.props.t("Yes"),onClose:r=>{r?this.setState({showConfirmation:!1,confirmed:!0},()=>{const e=this.cb;this.cb=null,this.onSave(e)}):(this.cb=null,this.setState({showConfirmation:!1}))}}):!1}render(){if(this.customObj===null)return s().createElement("div",{style:{color:"#F55",fontSize:32}},this.props.t("Object does not exist!"));if(!this.state.loaded)return s().createElement(S.Z,null);let r=0;return s().createElement(M.Z,{className:this.props.classes.paper},this.state.maxOids>1&&s().createElement(S.Z,{color:"secondary",variant:"determinate",value:this.state.progress}),s().createElement("div",{className:this.props.classes.scrollDiv,ref:this.scrollDivRef},this.state.maxOids===null&&Object.keys(this.jsonConfigs).map(e=>this.jsonConfigs[e]?Object.keys(this.jsonConfigs[e].instanceObjs).map(t=>this.renderOneCustom(t,this.jsonConfigs[e].instanceObjs[t],this.customObj,r++)):null)),this.renderErrorMessage(),this.renderConfirmationDialog())}};let xt=St;Y(xt,"AsyncFunction",Object.getPrototypeOf(function(){return nt(this,null,function*(){})}).constructor),xt.propTypes={t:l().func,onChange:l().func,lang:l().string,expertMode:l().bool,objects:l().object,customsInstances:l().array,socket:l().object,objectIDs:l().array,theme:l().object,themeName:l().string,themeType:l().string,registerSaveFunc:l().func,onProgress:l().func,onError:l().func};var Fs=(0,R.default)()((0,G.withStyles)(Zs)(xt)),jt=h(6530),Ot=h(55784),et=h(31452),tt=h(26733),je=h(66116),E=h(41381),Oe=h(71386),Ie=h(67304),Pt=h(56892),W=h(75836),ks=h(42959),lt=h(44583),H=h(59357),T=h(18635),Ps=h(96875),Ws=h(62030),Wt=h(31122),Mt=h(47535),zt=h(33621),Vt=h(67099),Ht=h(48976),Jt=h(22763),Lt=h(33286),Bt=h(46652),Ut=h(19129),Yt=h(5677),Gt=h(77768),ct=h(33919),Ms=h(10722),zs=h(83609),Vs=Object.defineProperty,Hs=(r,e,t)=>e in r?Vs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ht=(r,e,t)=>(Hs(r,typeof e!="symbol"?e+"":e,t),t);const Js=r=>({table:{display:"grid","& tr":{display:"contents"},"& thead":{display:"contents"},"& tbody":{display:"contents"},"& th":{position:"sticky",userSelect:"none"},"& .resize-handle":{display:"block",position:"absolute",cursor:"col-resize",width:7,right:0,top:2,bottom:2,zIndex:1,borderRight:"2px dotted #888","&:hover":{borderColor:"#ccc",borderRightStyle:"solid"},"&.active":{borderColor:"#517ea5",borderRightStyle:"solid"}}}});class Kt extends C.Component{constructor(e){super(e),ht(this,"resizerReset",()=>{for(let t=0;t<this.resizerCurrentWidths.length;t++)this.resizerCurrentWidths[t]=(this.props.initialWidths||[])[t]||"auto";(window._localStorage||window.localStorage).setItem(`App.${this.props.name||"history"}.table`,JSON.stringify(this.resizerCurrentWidths)),this.resizerApplyWidths()}),ht(this,"resizerMouseMove",t=>{if(this.resizerActiveDiv){const a=this.resizerOldWidth+t.clientX-this.resizerPosition,o=this.resizerOldWidthNext-t.clientX+this.resizerPosition;(!this.resizerMin||a>this.resizerMin)&&(!this.resizerMinNext||o>this.resizerMinNext)&&(this.resizerCurrentWidths[this.resizerActiveIndex]=a,this.resizerCurrentWidths[this.resizerActiveIndex+1]=o,this.resizerApplyWidths())}}),ht(this,"resizerMouseUp",()=>{(window._localStorage||window.localStorage).setItem(`App.${this.props.name||"history"}.table`,JSON.stringify(this.resizerCurrentWidths)),this.resizerActiveIndex=null,this.resizerActiveDiv=null,window.removeEventListener("mousemove",this.resizerMouseMove),window.removeEventListener("mouseup",this.resizerMouseUp)}),ht(this,"resizerMouseDown",t=>{if(this.resizerActiveIndex===null||this.resizerActiveIndex===void 0){console.log("Mouse down "+t.target.dataset.index),this.resizerActiveIndex=parseInt(t.target.dataset.index,10),this.resizerActiveDiv=t.target,this.resizerMin=this.props.minWidths?this.props.minWidths[this.resizerActiveIndex]:0,this.resizerMinNext=this.props.minWidths?this.props.minWidths[this.resizerActiveIndex+1]:0,this.resizerPosition=t.clientX;let a;this.resizerCurrentWidths[this.resizerActiveIndex]==="auto"&&(a=a||this.resizerRefTable.current.querySelectorAll("th"),this.resizerCurrentWidths[this.resizerActiveIndex]=a[this.resizerActiveIndex].offsetWidth),this.resizerCurrentWidths[this.resizerActiveIndex+1]==="auto"&&(a=a||this.resizerRefTable.current.querySelectorAll("th"),this.resizerCurrentWidths[this.resizerActiveIndex+1]=a[this.resizerActiveIndex+1].offsetWidth),this.resizerOldWidth=this.resizerCurrentWidths[this.resizerActiveIndex],this.resizerOldWidthNext=this.resizerCurrentWidths[this.resizerActiveIndex+1],window.addEventListener("mousemove",this.resizerMouseMove),window.addEventListener("mouseup",this.resizerMouseUp)}}),this.resizerRefTable=s().createRef(),this.resizerActiveIndex=null,this.resizerActiveDiv=null,this.resizerCurrentWidths=[]}componentDidMount(){this.resizerInstall()}componentWillUnmount(){this.resizerUninstall()}resizerInstall(){if(this.resizerRefTable.current&&!this.resizerRefTable.current._installed){this.resizerRefTable.current._installed=!0;const e=this.resizerRefTable.current.querySelectorAll("th"),t=(window._localStorage||window.localStorage).getItem(`App.${this.props.name||"history"}.table`);if(this.widthFilled=!1,t)try{this.resizerCurrentWidths=JSON.parse(t),this.widthFilled=!0}catch(a){}if(this.widthFilled)if(this.resizerCurrentWidths.length!==e.length)this.resizerCurrentWidths=[],this.widthFilled=!1;else{const a=this.resizerRefTable.current.offsetWidth;let o=0;for(let i=0;i<this.resizerCurrentWidths.length;i++)if(isFinite(this.resizerCurrentWidths[i]))o+=this.resizerCurrentWidths[i];else{o=null;break}o!==null&&Math.abs(o-a)>20&&(this.resizerCurrentWidths=[],this.widthFilled=!1)}for(let a=0;a<e.length;a++)if(!this.widthFilled&&this.resizerCurrentWidths.push(e[a].offsetWidth),a<e.length-1){const o=window.document.createElement("div");o.dataset.index=a.toString(),o.onmousedown=this.resizerMouseDown,o.ondblclick=this.resizerReset,o.title=this.props.dblTitle||"Double click to reset table layout",o.className="resize-handle",e[a].appendChild(o)}this.widthFilled&&this.resizerApplyWidths()}else this.installTimeout=setTimeout(()=>{this.installTimeout=null,this.resizerInstall()},100)}resizerUninstall(){if(this.installTimeout&&clearTimeout(this.installTimeout),this.resizerRefTable.current&&this.resizerRefTable.current._installed){this.resizerRefTable.current._installed=!0;const e=this.resizerRefTable.current.querySelectorAll("th");for(let t=0;t<e.length;t++){const a=e[t].querySelector(".resize-handle");a&&(a.onmousedown=null,a.remove())}}}resizerApplyWidths(){const e=[];if(this.resizerCurrentWidths.length)for(let t=0;t<this.resizerCurrentWidths.length;t++)this.resizerCurrentWidths[t]?e.push(this.resizerCurrentWidths[t]!=="auto"?this.resizerCurrentWidths[t]+"px":"auto"):this.props.initialWidths&&this.props.initialWidths[t]?e.push(this.props.initialWidths[t]!=="auto"?this.props.initialWidths[t]+"px":"auto"):e.push("auto");else if(this.props.initialWidths)for(let t=0;t<this.props.initialWidths.length;t++)this.props.initialWidths[t]?e.push(this.props.initialWidths[t]!=="auto"?this.props.initialWidths[t]+"px":"auto"):e.push("auto");return this.resizerRefTable.current&&e.length&&(this.resizerRefTable.current.style.gridTemplateColumns=e.join(" ")),e.length?e.join(" "):void 0}render(){if(this.props.ready===!1)return s().createElement(zs.Z,null);const e={gridTemplateColumns:this.resizerApplyWidths()};return s().createElement(Ms.Z,{stickyHeader:this.props.stickyHeader,size:this.props.size||"small",className:this.props.classes.table+(this.props.className?" "+this.props.className:""),ref:this.resizerRefTable,style:Object.assign({},this.props.style||{},e)},this.props.children)}}Kt.propTypes={name:l().string,ready:l().bool,stickyHeader:l().bool,size:l().string,className:l().string,style:l().object,initialWidths:l().array,minWidths:l().array,dblTitle:l().string};var Ls=(0,G.withStyles)(Js)(Kt),Bs=h(39323),pt=h(42158),Us=Object.defineProperty,Qt=Object.getOwnPropertySymbols,Ys=Object.prototype.hasOwnProperty,Gs=Object.prototype.propertyIsEnumerable,It=(r,e,t)=>e in r?Us(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Je=(r,e)=>{for(var t in e||(e={}))Ys.call(e,t)&&It(r,t,e[t]);if(Qt)for(var t of Qt(e))Gs.call(e,t)&&It(r,t,e[t]);return r},Ks=(r,e,t)=>(It(r,typeof e!="symbol"?e+"":e,t),t);const Xt={en:zt.Z,fr:Wt.Z,ru:Mt.Z,de:Yt.Z,es:Vt.Z,br:Ut.Z,nl:Gt.Z,it:Lt.Z,pt:Jt.Z,pl:Ht.Z,"zh-cn":Bt.Z};function At(r){return r<10?"00"+r:r<100?"0"+r:r}function st(r){return r<10?"0"+r:r}const Qs=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},tableDiv:{height:`calc(100% - ${r.mixins.toolbar.minHeight+parseInt(r.spacing(1),10)}px)`,overflow:"hidden",width:"100%"},container:{height:"100%"},table:{minWidth:960,width:"100%","& td:nth-of-type(5)":{overflow:"hidden",whiteSpace:"nowrap"},"& tr:nth-child(even)":{backgroundColor:r.palette.mode==="dark"?"#383838":"#b2b2b2"}},row:{userSelect:"none",position:"relative","&:hover":{opacity:.7},"& td":{position:"relative"}},updatedRow:{animation:"updated 1s"},rowInterpolated:{opacity:.5},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:r.palette.primary.main},rowSelected:{background:r.palette.secondary.main,color:r.palette.secondary.contrastText,"& td":{color:r.palette.secondary.contrastText,background:r.palette.secondary.main}},rowFocused:{position:"absolute",pointerEvents:"none",top:0,bottom:0,left:0,right:0,margin:3,border:"1px dotted "+r.palette.action.active},grow:{flexGrow:1},editorTimePicker:{marginLeft:r.spacing(1),width:120},editorDatePicker:{marginLeft:r.spacing(1),width:150},msInput:{width:50,paddingTop:16,marginLeft:5,"& label":{marginTop:15}},cellAckTrue:{color:r.palette.mode==="dark"?"#66ff7f":"#04a821"},cellAckFalse:{color:"#FF6666"},toolbarTime:{width:100,marginTop:9,marginLeft:r.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:r.spacing(1),paddingLeft:r.spacing(1),paddingRight:r.spacing(1),paddingTop:r.spacing(.5),paddingBottom:r.spacing(.5),border:"1px dotted #AAAAAA",borderRadius:r.spacing(1)},noLoadingProgress:{width:"100%",height:4},colValue:{},colAck:{},colFrom:{},colLastChange:{},colTs:{},dateInput:{width:140,marginRight:r.spacing(1)},timeInput:{width:100}});class $t extends C.Component{constructor(e){super(e),Ks(this,"onChange",(d,m)=>{if(d===this.props.obj._id&&m&&this.state.values&&(!this.state.values.length||this.state.values[this.state.values.length-1].ts<m.ts)){const f=[...this.state.values,m];this.setState({values:f})}});let t=(window._localStorage||window.localStorage).getItem("App.relativeRange")||"absolute",a=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteStart"),10)||0,o=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteEnd"),10)||0,i=(window._localStorage||window.localStorage).getItem("App.historySelected")||"",n=parseInt((window._localStorage||window.localStorage).getItem("App.historyLastSelected"),10)||null,c=(window._localStorage||window.localStorage).getItem("App.historyLastSelectedColumn")||null;(!a||!o)&&(!t||t==="absolute")&&(t="30"),a&&o&&(t="absolute");try{i=JSON.parse(i)}catch(d){i=[]}this.state={loaded:!1,min:null,max:null,start:a,end:o,values:null,relativeRange:t,selected:i,lastSelected:n,lastSelectedColumn:c,historyInstance:"",updateOpened:!1,insertOpened:!1,historyInstances:null,defaultHistory:"",lcVisible:!0,qVisible:!0,ackVisible:!0,fromVisible:!0,supportedFeatures:[],dateFormat:"dd.MM.yyyy",edit:{}},this.adminInstance=parseInt(window.location.search.slice(1),10)||0,this.supportedFeaturesPromises={},this.unit=this.props.obj.common&&this.props.obj.common.unit?" "+this.props.obj.common.unit:"",this.timeTimer=null,this.prepareData().then(()=>this.readHistoryRange()).then(()=>{t!=="absolute"?this.setRelativeInterval(this.state.relativeRange,!0):this.readHistory()})}readSupportedFeatures(e){if(e=e||this.state.historyInstance,e){if(this.supportedFeaturesPromises[e])return this.supportedFeaturesPromises[e]}else return Promise.resolve([]);return this.supportedFeaturesPromises[e]=new Promise(t=>{this.readSupportedFeaturesTimeout&&clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=setTimeout(()=>{this.readSupportedFeaturesTimeout=null,t([])},2e3),this.props.socket.sendTo(e,"features",null).then(a=>{this.readSupportedFeaturesTimeout?(this.readSupportedFeaturesTimeout&&clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=null,t(a?a.supportedFeatures||[]:[])):this.setState({supportedFeatures:a?a.supportedFeatures||[]:[]})})}),this.supportedFeaturesPromises[e]}componentDidMount(){this.props.socket.subscribeState(this.props.obj._id,this.onChange)}componentWillUnmount(){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange)}prepareData(){let e;return this.getHistoryInstances().then(t=>(e=t,this.props.socket.getCompactSystemConfig())).then(t=>{const a=t&&t.common&&t.common.defaultHistory;let o=(window._localStorage||window.localStorage).getItem("App.historyInstance")||"";return(!o||!e.find(i=>i.id===o&&i.alive))&&(o=a),(!o||!e.find(i=>i.id===o&&i.alive))&&(o=e.find(i=>i.alive),o&&(o=o.id)),!o&&e.length&&(o=a),this.readSupportedFeatures(o).then(i=>new Promise(n=>{this.setState({historyInstances:e,defaultHistory:a,historyInstance:o,supportedFeatures:i,dateFormat:(t.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y")},()=>n())}))})}getHistoryInstances(){const e=[],t=[];return this.props.customsInstances.forEach(a=>{const o=this.props.objects["system.adapter."+a];if(o&&o.common&&o.common.getHistory){let i={id:a,alive:!1};e.push(i),t.push(`system.adapter.${a}.alive`)}}),t.length?this.props.socket.getForeignStates(t).then(a=>(Object.keys(a).forEach(o=>{const i=e.find(n=>o.endsWith(n.id+".alive"));i&&(i.alive=a[o]&&a[o].val)}),e)):Promise.resolve(e)}readHistory(e,t){return e=e||this.state.start,t=t||this.state.end,this.state.historyInstance?(this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:e,end:t,from:!0,ack:!0,q:!0,addID:!1,aggregate:"none",returnNewestEntries:!0}).then(a=>{let o=[],i=this.rangeValues,n=!1,c=!1,d=!1,m=!1,f=!1;if(i&&i.length&&(!a||!a.length||i[0].ts<a[0].ts)&&(o.push(i[0]),o.push({ts:i[0].ts+1,e:!0}),console.log(`add ${new Date(i[0].ts).toISOString()}: ${i[0].val}`),!c&&i[0].q!==void 0&&(c=!0),!d&&i[0].ack!==void 0&&(d=!0),!m&&i[0].from&&(m=!0),!f&&i[0].c&&(f=!0)),a&&a.length)for(let p=0;p<a.length;p++)a[p]&&(!o.length||o[o.length-1].ts<a[p].ts)?(o.push(a[p]),a[p].from&&(a[p].from.startsWith("system.adapter.")?a[p].from=a[p].from.substring(15):a[p].from.startsWith("system.host.")&&(a[p].from=a[p].from.substring(7))),!n&&a[p].lc&&(n=!0),!c&&a[p].q!==void 0&&(c=!0),!d&&a[p].ack!==void 0&&(d=!0),!m&&a[p].from&&(m=!0),!f&&a[p].c&&(f=!0),console.log(`add value ${new Date(a[p].ts).toISOString()}: ${a[p].val}`)):o[o.length-1].ts===a[p].ts&&o[o.length-1].val!==a[p].ts&&console.error("Strange data!");else o.push({noDataForPeriod:!0});o.length||o.push({noData:!0}),this.setState({loading:!1,values:o,lcVisible:n,fromVisible:m,qVisible:c,ackVisible:d,cVisible:f})})):null}readHistoryRange(){const e=new Date,t=new Date(2e3,0,1);return this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:t.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then(a=>{a.length?((a[0].val===null||a[0].ts===t.getTime())&&a.shift(),a.forEach(o=>o.i=!0),this.rangeValues=a,this.setState({min:a[0].ts,max:a[a.length-1].ts,loading:!1})):(this.rangeValues=[],this.setState({loading:!1}))})}onToggleSelect(e,t,a){let o=[...this.state.selected];const i=o.indexOf(t);if(e.shiftKey&&this.state.lastSelected){let n=-1,c=-1;o=[];for(let d=0;d<this.state.values.length&&!(this.state.values[d].ts===t&&(n=d,c!==n&&o.push(this.state.values[d].ts),n!==-1&&c!==-1)||this.state.values[d].ts===this.state.lastSelected&&(c=d,c!==n&&o.push(this.state.values[d].ts),n!==-1&&c!==-1));d++)(n!==-1||c!==-1)&&o.push(this.state.values[d].ts)}else e.ctrlKey?(i!==-1?o.splice(i,1):o.push(t),o.sort()):o=[t];(window._localStorage||window.localStorage).setItem("App.historyLastSelected",t.toString()),(window._localStorage||window.localStorage).setItem("App.historyLastSelectedColumn",a),(window._localStorage||window.localStorage).setItem("App.historySelected",JSON.stringify(o)),this.setState({selected:o,lastSelected:t,lastSelectedColumn:a})}getTableRows(e){const t=[];for(let a=this.state.values.length-1;a>=0;a--){const o=this.state.values[a],i=o.ts;if(o.e)t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,e.rowInterpolated),key:i,hover:!0},s().createElement(H.Z,null),s().createElement(H.Z,null,"..."),this.state.ackVisible?s().createElement(H.Z,null):null,this.state.fromVisible?s().createElement(H.Z,null):null,this.state.lcVisible?s().createElement(H.Z,null):null));else if(o.noData||o.noDataForPeriod)t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,e.rowNoData),key:o.noData?"nodata":"",hover:!0},s().createElement(H.Z,null),s().createElement(H.Z,null,o.noData?this.props.t("No data in history"):this.props.t("No data in history for selected period")),this.state.ackVisible?s().createElement(H.Z,null):null,this.state.fromVisible?s().createElement(H.Z,null):null,this.state.lcVisible?s().createElement(H.Z,null):null));else{const n=o.i,c=this.state.lastSelected===i;let d=o.val;this.props.isFloatComma&&this.props.obj.common.type==="number"&&d&&(d=d.toString().replace(".",",")),d===null&&(d="null"),d===void 0&&(d="_");const m=this.state.selected.includes(i);t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,n&&e.rowInterpolated,m&&e.rowSelected),key:i+(o.val||"")},s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"ts")},`${new Date(o.ts).toLocaleDateString()} ${new Date(o.ts).toLocaleTimeString()}.${At(o.ts%1e3)}`,c&&this.state.lastSelectedColumn==="ts"?s().createElement("div",{className:e.rowFocused}):""),s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"val")},d+this.unit,c&&this.state.lastSelectedColumn==="val"?s().createElement("div",{className:e.rowFocused}):""),this.state.ackVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"ack"),className:o.ack?e.cellAckTrue:e.cellAckFalse},o.ack?"true":"false",c&&this.state.lastSelectedColumn==="ack"?s().createElement("div",{className:e.rowFocused}):""):null,this.state.fromVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"from")},o.from||"",c&&this.state.lastSelectedColumn==="from"?s().createElement("div",{className:e.rowFocused}):""):null,this.state.lcVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"lc")},o.lc?`${new Date(o.lc).toLocaleDateString()} ${new Date(o.lc).toLocaleTimeString()}.${At(o.ts%1e3)}`:"",c&&this.state.lastSelectedColumn==="lc"?s().createElement("div",{className:e.rowFocused}):""):null))}}return t}shiftTime(){const e=new Date,t=6e4-e.getSeconds()-(1e3-e.getMilliseconds());e.getMilliseconds()&&e.setMilliseconds(1e3),e.getSeconds()&&e.setSeconds(60);const a=e.getTime();let o,i=this.state.relativeRange;if(i==="day")e.setHours(0),e.setMinutes(0),e.setSeconds(0),o=e.getTime();else if(i==="week"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else if(i==="2weeks"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(e.getDate()-7);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else i==="month"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),o=e.getTime()):i==="year"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),e.setMonth(0),o=e.getTime()):i==="12months"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setFullYear(e.getFullYear()-1),o=e.getTime()):(i=parseInt(i,10),o=a-i*6e4);this.setState({start:o,end:a},()=>this.readHistory()),this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},t||6e4)}setRelativeInterval(e,t){if(t||((window._localStorage||window.localStorage).setItem("App.relativeRange",e),this.setState({relativeRange:e})),e==="absolute"){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null;return}else(window._localStorage||window.localStorage).removeItem("App.absoluteStart"),(window._localStorage||window.localStorage).removeItem("App.absolute");const a=new Date;if(!this.timeTimer){const n=6e4-a.getSeconds()-(1e3-a.getMilliseconds());this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},n||6e4)}a.getMilliseconds()&&a.setMilliseconds(1e3),a.getSeconds()&&a.setSeconds(60);const o=a.getTime();let i;if(e==="day")a.setHours(0),a.setMinutes(0),a.setSeconds(0),i=a.getTime();else if(e==="week"){a.setHours(0),a.setMinutes(0),a.setSeconds(0);const n=a.getDay()||7;n!==1&&a.setHours(-24*(n-1)),i=a.getTime()}else if(e==="2weeks"){a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(a.getDate()-7);const n=a.getDay()||7;n!==1&&a.setHours(-24*(n-1)),i=a.getTime()}else e==="month"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(1),i=a.getTime()):e==="year"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(1),a.setMonth(0),i=a.getTime()):e==="12months"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setFullYear(a.getFullYear()-1),i=a.getTime()):(e=parseInt(e,10),i=o-e*6e4);this.setState({start:i,end:o},()=>this.readHistory())}renderTable(){if(this.state.values){const{classes:e}=this.props,t=[200,"auto"],a=[190,100];return this.state.ackVisible&&(t.push(50),a.push(50)),this.state.fromVisible&&(t.push(150),a.push(150)),this.state.lcVisible&&(t.push(200),a.push(190)),s().createElement(Ws.Z,{className:e.container},s().createElement(Ls,{stickyHeader:!0,className:e.table,initialWidths:t,minWidths:a,dblTitle:this.props.t("ra_Double click to reset table layout")},s().createElement(ks.Z,null,s().createElement(lt.Z,null,s().createElement(H.Z,{className:e.colTs},this.props.t("Timestamp")),s().createElement(H.Z,{className:e.colValue},this.props.t("Value")),this.state.ackVisible?s().createElement(H.Z,{className:e.colAck},this.props.t("Ack")):null,this.state.fromVisible?s().createElement(H.Z,{className:e.colFrom},this.props.t("From")):null,this.state.lcVisible?s().createElement(H.Z,{className:e.colLastChange},this.props.t("lc")):null)),s().createElement(Ps.Z,null,this.getTableRows(e))))}else return s().createElement(S.Z,null)}renderConfirmDialog(){return s().createElement(te.Z,{open:!!this.state.areYouSure,onClose:()=>this.setState({areYouSure:!1}),"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description"},s().createElement(K.Z,{id:"alert-dialog-title"}),s().createElement(oe.Z,null,s().createElement(qe.Z,{id:"alert-dialog-description"},this.props.t("Are you sure?")),s().createElement(k.Z,{control:s().createElement(N.Z,{value:this.state.suppressMessage,onChange:()=>this.setState({suppressMessage:!0})}),label:this.props.t("Suppress for 5 minutes")})),s().createElement(L.Z,null,s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({areYouSure:!1,suppressMessage:this.state.suppressMessage&&Date.now()},()=>this.onDelete()),color:"primary",autoFocus:!0,startIcon:s().createElement(me.default,null)},this.props.t("Delete")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({areYouSure:!1}),color:"secondary",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}onDelete(){const e=this.state.selected.map(t=>({state:{ts:t},id:this.props.obj._id}));this.props.socket.sendTo(this.state.historyInstance,"delete",e).then(()=>this.readHistory())}onUpdate(){let e=this.state.edit.val;this.props.obj.common&&(this.props.obj.common.type==="number"?typeof e!="number"&&(e=parseFloat(e.replace(",","."))):this.props.obj.common.type==="boolean"&&(e=e==="true"||e==="TRUE"||e===!0||e==="1"||e===1));const t={val:e,ack:this.state.edit.ack,ts:this.state.selected[0],from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q};Object.keys(t).forEach(a=>{t[a]===void 0&&delete t[a]}),!this.state.lcVisible&&t.lc&&delete t.lc,this.props.socket.sendTo(this.state.historyInstance,"update",[{id:this.props.obj._id,state:t}]).then(()=>this.readHistory())}onInsert(){let e=this.state.edit.val;this.props.obj.common&&(this.props.obj.common.type==="number"?e=parseFloat(e.replace(",",".")):this.props.obj.common.type==="boolean"&&(e=e==="true"||e==="TRUE"||e===!0||e==="1"||e===1));const t=this.state.edit.date;t.setHours(this.state.edit.time.getHours()),t.setMinutes(this.state.edit.time.getMinutes()),t.setSeconds(this.state.edit.time.getSeconds()),t.setMilliseconds(parseInt(this.state.edit.ms,10));const a={ts:t.getTime(),val:e,ack:this.state.edit.ack,from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q||0};!this.state.lcVisible&&a.lc&&delete a.lc,Object.keys(a).forEach(o=>{a[o]===void 0&&delete a[o]}),this.props.socket.sendTo(this.state.historyInstance,"insert",[{id:this.props.obj._id,state:a}]).then(()=>this.readHistory())}formatTime(e){const t=new Date(e);return`${st(t.getHours())}:${st(t.getMinutes())}:${st(t.getSeconds())}.${At(t.getMilliseconds())}`}formatDate(e){const t=new Date(e);return`${st(t.getDate())}.${st(t.getMonth()+1)}.${t.getFullYear()}`}updateEdit(e,t){const a=JSON.parse(JSON.stringify(this.state.edit));a.time=new Date(a.time),a.date=new Date(a.date),a[e]=t,this.setState({edit:a})}renderEditDialog(){return s().createElement(te.Z,{open:this.state.updateOpened||this.state.insertOpened,onClose:()=>this.setState({updateOpened:!1,insertOpened:!1}),"aria-labelledby":"edit-dialog-title","aria-describedby":"edit-dialog-description"},s().createElement(K.Z,{id:"edit-dialog-title"},this.state.updateOpened?this.props.t("Update entry"):this.props.t("Insert entry")),s().createElement(oe.Z,null,s().createElement("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off"},typeof this.state.edit.val=="boolean"?s().createElement(k.Z,{control:s().createElement(N.Z,{checked:this.state.edit.val,onChange:e=>this.updateEdit("val",e.target.checked)}),label:this.props.t("Value")}):s().createElement(T.Z,{variant:"standard",label:this.props.t("Value"),value:this.state.edit.val,onChange:e=>this.updateEdit("val",e.target.value)}),s().createElement("br",null),s().createElement(k.Z,{control:s().createElement(N.Z,{checked:this.state.edit.ack,onChange:e=>this.updateEdit("ack",e.target.checked)}),label:this.props.t("Acknowledged")}),this.state.insertOpened?s().createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:Xt[this.props.lang]},s().createElement(W.ZP,{container:!0,justifyContent:"space-around"},s().createElement(et.M,{className:this.props.classes.editorDatePicker,margin:"normal",label:this.props.t("Date"),inputFormat:this.state.dateFormat,value:this.state.edit.date,onChange:e=>this.updateEdit("date",e),renderInput:e=>s().createElement(T.Z,Je({className:this.props.classes.timeInput,variant:"standard"},e))}),s().createElement(tt.j,{margin:"normal",views:["hours","minutes","seconds"],label:this.props.t("Time"),ampm:!1,format:"HH:mm:ss",className:this.props.classes.editorTimePicker,value:this.state.edit.time,onChange:e=>this.updateEdit("time",e),renderInput:e=>s().createElement(T.Z,Je({className:this.props.classes.timeInput,variant:"standard"},e))}),s().createElement(T.Z,{variant:"standard",classes:{root:this.props.classes.msInput},label:this.props.t("ms"),type:"number",inputProps:{max:999,min:0},value:this.state.edit.ms,onChange:e=>this.updateEdit("ms",e.target.value)}))):null)),s().createElement(L.Z,null,s().createElement(Z.Z,{variant:"contained",onClick:()=>{const e=this.state.updateOpened;this.setState({updateOpened:!1,insertOpened:!1},()=>e?this.onUpdate():this.onInsert())},color:"primary",autoFocus:!0},this.state.updateOpened?this.props.t("Update"):this.props.t("Add")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({updateOpened:!1,insertOpened:!1}),color:"grey"},this.props.t("Cancel"))))}setStartDate(e){e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",e),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",this.state.end),this.setState({start:e,relativeRange:"absolute"},()=>this.readHistory())}setEndDate(e){e=e.getTime(),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",this.state.start),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.setState({end:e,relativeRange:"absolute"},()=>this.readHistory())}renderToolbar(){const e=this.props.classes;return s().createElement(Pt.Z,null,s().createElement(Oe.Z,{variant:"standard",className:e.selectHistoryControl},s().createElement(je.Z,null,this.props.t("History instance")),s().createElement(Ie.Z,{variant:"standard",value:this.state.historyInstance||"",onChange:t=>{const a=t.target.value;(window._localStorage||window.localStorage).setItem("App.historyInstance",a),this.readSupportedFeatures(a).then(o=>this.setState({historyInstance:a,supportedFeatures:o},()=>this.readHistory()))}},this.state.historyInstances.map(t=>s().createElement(E.Z,{key:t.id,value:t.id,className:(0,V.default)(!t.alive&&e.notAliveInstance)},t.id)))),s().createElement(Oe.Z,{variant:"standard",className:e.selectRelativeTime},s().createElement(je.Z,null,this.props.t("Relative")),s().createElement(Ie.Z,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value)},s().createElement(E.Z,{key:"custom",value:"absolute",className:e.customRange},this.props.t("custom range")),s().createElement(E.Z,{key:"1",value:10},this.props.t("last 10 minutes")),s().createElement(E.Z,{key:"2",value:30},this.props.t("last 30 minutes")),s().createElement(E.Z,{key:"3",value:60},this.props.t("last hour")),s().createElement(E.Z,{key:"4",value:"day"},this.props.t("this day")),s().createElement(E.Z,{key:"5",value:24*60},this.props.t("last 24 hours")),s().createElement(E.Z,{key:"6",value:"week"},this.props.t("this week")),s().createElement(E.Z,{key:"7",value:24*60*7},this.props.t("last week")),s().createElement(E.Z,{key:"8",value:"2weeks"},this.props.t("this 2 weeks")),s().createElement(E.Z,{key:"9",value:24*60*14},this.props.t("last 2 weeks")),s().createElement(E.Z,{key:"10",value:"month"},this.props.t("this month")),s().createElement(E.Z,{key:"11",value:30*24*60},this.props.t("last 30 days")),s().createElement(E.Z,{key:"12",value:"year"},this.props.t("this year")),s().createElement(E.Z,{key:"13",value:"12months"},this.props.t("last 12 months")))),s().createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:Xt[this.props.lang]},s().createElement("div",{className:e.toolbarTimeGrid},s().createElement(et.M,{className:e.toolbarDate,disabled:this.state.relativeRange!=="absolute",disableToolbar:!0,variant:"inline",margin:"normal",inputFormat:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.start),onChange:t=>this.setStartDate(t),renderInput:t=>s().createElement(T.Z,Je({className:this.props.classes.dateInput,variant:"standard"},t))}),s().createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.start),onChange:t=>this.setStartDate(t),renderInput:t=>s().createElement(T.Z,Je({className:this.props.classes.timeInput,variant:"standard"},t))})),s().createElement("div",{className:e.toolbarTimeGrid},s().createElement(et.M,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarDate,disableToolbar:!0,inputFormat:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.end),onChange:t=>this.setEndDate(t),renderInput:t=>s().createElement(T.Z,Je({className:this.props.classes.dateInput,variant:"standard"},t))}),s().createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.end),onChange:t=>this.setEndDate(t),renderInput:t=>s().createElement(T.Z,Je({className:this.props.classes.timeInput,variant:"standard"},t))}))),s().createElement("div",{className:e.grow}),this.state.values&&this.state.values.length?s().createElement(X.Z,{size:"large",onClick:()=>this.exportData(),title:this.props.t("Save data as csv")},s().createElement(pt.FaDownload,null)):null,this.state.supportedFeatures.includes("insert")&&this.props.expertMode?s().createElement(X.Z,{size:"large",onClick:()=>{const t=new Date,a={ack:this.state.values[this.state.values.length-1].ack,val:this.state.values[this.state.values.length-1].val,ts:t,date:new Date(t),ms:0,time:new Date(t),q:0};this.setState({edit:a,insertOpened:!0})}},s().createElement(pt.FaPlusSquare,null)):null,this.state.supportedFeatures.includes("update")&&this.props.expertMode?s().createElement(X.Z,{size:"large",disabled:this.state.selected.length!==1,onClick:()=>{const t=JSON.parse(JSON.stringify(this.state.values.find(o=>o.ts===this.state.lastSelected))),a=new Date(t.ts);t.date=new Date(a),t.time=new Date(a),this.setState({edit:t,updateOpened:!0})}},s().createElement(Bs.default,null)):null,this.state.supportedFeatures.includes("delete")&&this.props.expertMode?s().createElement(X.Z,{size:"large",disabled:!this.state.selected.length,onClick:()=>{this.state.suppressMessage&&Date.now()-this.state.suppressMessage<3e5?this.onDelete():this.setState({areYouSure:!0})}},s().createElement(me.default,null)):null)}exportData(){let e=window.document.getElementById("export-file");e||(e=document.createElement("a"),e.setAttribute("id","export-file"),e.style.display="none",document.body.appendChild(e));let t=["timestamp;value;acknowledged;from;"];this.state.values.forEach(a=>!a.i&&!a.e&&t.push([new Date(a.ts).toISOString(),a.val===null||a.val===void 0?"null":a.val.toString(),a.ack?"true":"false",a.from||""].join(";"))),e.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t.join(`
|
|
307
|
-
`))),e.setAttribute("download",ct.default.getObjectName({[this.props.obj._id]:this.props.obj},this.props.obj._id,{language:this.props.lang})+".csv"),e.click(),document.body.removeChild(e)}render(){return this.state.historyInstances?s().createElement(M.Z,{className:this.props.classes.paper},this.state.loading?s().createElement(S.Z,null):s().createElement("div",{className:this.props.classes.noLoadingProgress}),this.renderToolbar(),s().createElement("div",{className:this.props.classes.tableDiv},this.renderTable()),this.renderConfirmDialog(),this.renderEditDialog()):s().createElement(S.Z,null)}}$t.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,obj:l().object,customsInstances:l().array,themeName:l().string,objects:l().object,isFloatComma:l().bool};var Xs=(0,R.default)()((0,G.withStyles)(Qs)($t)),Ae=h(67552),$s=h(56759),qs=h(41544),_s=h(32681),ea=h(92249),ta=h(18308),sa=h(99725),aa=h(55612),oa=h(13351),ia=h(66572),ra=h(27986),na="data:image/png;base64,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",x=h(4819),la=Object.defineProperty,qt=Object.getOwnPropertySymbols,ca=Object.prototype.hasOwnProperty,ha=Object.prototype.propertyIsEnumerable,Dt=(r,e,t)=>e in r?la(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,dt=(r,e)=>{for(var t in e||(e={}))ca.call(e,t)&&Dt(r,t,e[t]);if(qt)for(var t of qt(e))ha.call(e,t)&&Dt(r,t,e[t]);return r},_t=(r,e,t)=>(Dt(r,typeof e!="symbol"?e+"":e,t),t);qs.D([ta.N,sa.N,aa.N,oa.N,ia.N,ea.N,ra.N]);const pa={en:zt.Z,fr:Wt.Z,ru:Mt.Z,de:Yt.Z,es:Vt.Z,br:Ut.Z,nl:Gt.Z,it:Lt.Z,pt:Jt.Z,pl:Ht.Z,"zh-cn":Bt.Z};function da(r){return r<10?"00"+r:r<100?"0"+r:r}function fe(r){return r<10?"0"+r:r}const ma=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden",width:"100%"},chart:{width:"100%",overflow:"hidden"},chartWithToolbar:{height:`calc(100% - ${r.mixins.toolbar.minHeight+parseInt(r.spacing(1),10)}px)`},chartWithoutToolbar:{height:"100%"},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:r.palette.primary.main},splitLineButtonIcon:{marginRight:r.spacing(1)},splitLineButton:{float:"right"},grow:{flexGrow:1},toolbarTime:{width:100,marginTop:9,marginLeft:r.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:r.spacing(1),paddingLeft:r.spacing(1),paddingRight:r.spacing(1),paddingTop:r.spacing(.5),paddingBottom:r.spacing(.5),border:"1px dotted #AAAAAA",borderRadius:r.spacing(1),display:"flex"},buttonIcon:{width:24,height:24},echartsButton:{marginRight:r.spacing(1),height:34,width:34},dateInput:{width:140,marginRight:r.spacing(1)},timeInput:{width:80}}),_=80,De=25;class es extends C.Component{constructor(e){if(super(e),_t(this,"onResize",()=>{this.timerResize&&clearTimeout(this.timerResize),this.timerResize=setTimeout(()=>{this.timerResize=null,this.componentDidUpdate()})}),_t(this,"onChange",(i,n)=>{i===this.props.obj._id&&n&&this.rangeValues&&(!this.rangeValues.length||this.rangeValues[this.rangeValues.length-1].ts<n.ts)&&(!this.state.max||n.ts-this.state.max<12e4)&&(this.chartValues&&this.chartValues.push({val:n.val,ts:n.ts}),this.rangeValues.push({val:n.val,ts:n.ts}),n.ts>=this.chart.min&&n.ts<=this.chart.max+3e5&&this.updateChart())}),this.props.from)this.start=this.props.from;else{const i=new Date;i.setHours(i.getHours()-24*7),this.start=i.getTime()}this.props.end?this.end=this.props.end:this.end=Date.now();let t=(window._localStorage||window.localStorage).getItem("App.relativeRange")||"30",a=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteStart"),10)||0,o=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteEnd"),10)||0;(!a||!o)&&(!t||t==="absolute")&&(t="30"),o&&a&&(t="absolute"),this.state={loaded:!1,historyInstance:this.props.historyInstance||"",historyInstances:null,defaultHistory:"",chartHeight:300,chartWidth:500,relativeRange:t,splitLine:(window._localStorage||window.localStorage).getItem("App.splitLine")==="true",dateFormat:"dd.MM.yyyy",min:a,max:o,maxYLen:0},this.echartsReact=(0,C.createRef)(),this.rangeRef=(0,C.createRef)(),this.readTimeout=null,this.chartValues=null,this.rangeValues=null,this.unit=this.props.obj.common&&this.props.obj.common.unit?" "+this.props.obj.common.unit:"",this.divRef=(0,C.createRef)(),this.chart={},this.onChange=this.onChange.bind(this),this.onResize=this.onResize.bind(this)}componentDidMount(){this.props.socket.subscribeState(this.props.obj._id,this.onChange),window.addEventListener("resize",this.onResize),this.prepareData().then(()=>!this.props.noToolbar&&this.readHistoryRange()).then(()=>this.setRelativeInterval(this.state.relativeRange,!0,()=>this.forceUpdate()))}componentWillUnmount(){this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=null,this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.maxYLenTimeout&&clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange),window.removeEventListener("resize",this.onResize)}prepareData(){let e;return this.props.noToolbar?new Promise(t=>this.setState({dateFormat:this.props.dateFormat.replace(/D/g,"d").replace(/Y/g,"y"),defaultHistory:this.props.defaultHistory,historyInstance:this.props.defaultHistory},()=>t())):this.getHistoryInstances().then(t=>(e=t,this.props.socket.getCompactSystemConfig())).then(t=>this.props.showJumpToEchart?this.props.socket.getAdapterInstances("echarts",!0).then(a=>{const o=!!a.find(c=>c._id.startsWith("system.adapter.echarts.")),i=t&&t.common&&t.common.defaultHistory;let n=(window._localStorage||window.localStorage).getItem("App.historyInstance")||"";(!n||!e.find(c=>c.id===n&&c.alive))&&(n=i),(!n||!e.find(c=>c.id===n&&c.alive))&&(n=e.find(c=>c.alive),n&&(n=n.id)),!n&&e.length&&(n=i),this.setState({dateFormat:(t.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y"),historyInstances:e,defaultHistory:i,historyInstance:n,echartsJump:o})}):Promise.resolve([]))}getHistoryInstances(){const e=[],t=[];return this.props.historyInstance?Promise.resolve(e):(this.props.customsInstances.forEach(a=>{const o=this.props.objects["system.adapter."+a];if(o&&o.common&&o.common.getHistory){let i={id:a,alive:!1};e.push(i),t.push(`system.adapter.${a}.alive`)}}),t.length?this.props.socket.getForeignStates(t).then(a=>(Object.keys(a).forEach(o=>{const i=e.find(n=>o.endsWith(n.id+".alive"));i&&(i.alive=a[o]&&a[o].val)}),e)):Promise.resolve(e))}readHistoryRange(){const e=new Date,t=new Date(2e3,0,1);return this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:t.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then(a=>{var o;a&&((o=a[0])==null?void 0:o.val)===null&&a.shift(),this.rangeValues=a})}readHistory(e,t){const a={instance:this.state.historyInstance,start:e,end:t,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none",returnNewestEntries:!0};return t-e>6e4*24&&!(this.props.obj.common.type==="boolean"||this.props.obj.common.type==="number"&&this.props.obj.common.states)&&(a.aggregate="minmax"),this.props.socket.getHistory(this.props.obj._id,a).then(o=>{let i=[],n=0,c=this.rangeValues,d=null,m=null;for(let f=0;f<o.length;f++){if(c)for(;n<c.length&&c[n].ts<o[f].ts;)i.push(c[n]),n++;!i.length||i[i.length-1].ts<o[f].ts?i.push(o[f]):i[i.length-1].ts===o[f].ts&&i[i.length-1].val!==o[f].ts&&console.error("Strange data!"),(d===null||o[f].val<d)&&(d=o[f].val),(m===null||o[f].val>m)&&(m=o[f].val)}if(c)for(;n<c.length;)i.push(c[n]),console.log(`add range ${new Date(c[n].ts).toISOString()}: ${c[n].val}`),n++;return i.sort((f,p)=>f.ts>p.ts?1:f.ts<p.ts?-1:0),this.chartValues=i,this.minY=d,this.maxY=m,this.minY<10?this.minY=Math.round(this.minY*10)/10:this.minY=Math.ceil(this.minY),this.maxY<10?this.maxY=Math.round(this.maxY*10)/10:this.maxY=Math.ceil(this.maxY),i})}convertData(e){e=e||this.chartValues;const t=[];if(!e.length)return t;for(let a=0;a<e.length;a++){const o={value:[e[a].ts,e[a].val]};e[a].i&&(o.exact=!1),t.push(o)}return this.chart.min||(this.chart.min=e[0].ts,this.chart.max=e[e.length-1].ts),t}getOption(){let e;if(this.minY!==null&&this.minY!==void 0&&(e=(this.minY.toString()+this.unit).length*9+12),this.maxY!==null&&this.maxY!==void 0){const i=(this.maxY.toString()+this.unit).length*9+12;i>e&&(e=i)}if(this.state.maxYLen){const i=this.state.maxYLen*9+12;i>e&&(e=i)}const t={xAxisIndex:0,type:"line",showSymbol:!1,hoverAnimation:!0,animation:!1,data:this.convertData(),lineStyle:{color:"#4dabf5"},areaStyle:{}},a={type:"value",boundaryGap:[0,"100%"],splitLine:{show:this.props.noToolbar||!!this.state.splitLine},splitNumber:Math.round(this.state.chartHeight/50),axisLabel:{formatter:(i,n)=>{let c;return this.props.isFloatComma?c=i.toString().replace(",",".")+this.unit:c=i+this.unit,this.state.maxYLen<c.length&&(this.maxYLenTimeout&&clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=setTimeout(d=>this.setState({maxYLen:d}),200,c.length)),c},showMaxLabel:!0,showMinLabel:!0},axisTick:{alignWithLabel:!0}};if(this.props.obj.common.type==="boolean")t.step="end",a.axisLabel.showMaxLabel=!1,a.axisLabel.formatter=i=>i===1?"TRUE":"FALSE",a.max=1.5,a.interval=1,e=50;else if(this.props.obj.common.type==="number"&&this.props.obj.common.states){t.step="end",a.axisLabel.showMaxLabel=!1,a.axisLabel.formatter=c=>this.props.obj.common.states[c]!==void 0?this.props.obj.common.states[c]:c;const i=Object.keys(this.props.obj.common.states);i.sort(),a.max=parseFloat(i[i.length-1])+.5,a.interval=1;let n="";for(let c=0;c<i.length;c++)typeof this.props.obj.common.states[i[c]]=="string"&&this.props.obj.common.states[i[c]].length>n.length&&(n=this.props.obj.common.states[i[c]]);e=(n.length*9||50)+12}const o=this.chart.withSeconds?Math.round((this.state.chartWidth-De-_)/100):Math.round((this.state.chartWidth-De-_)/60);return{backgroundColor:"transparent",title:{text:this.props.noToolbar?"":ct.default.getObjectNameFromObj(this.props.obj,this.props.lang),padding:[10,0,0,e?e+10:_+10]},grid:{left:e||_,top:8,right:this.props.noToolbar?5:De,bottom:40},tooltip:{trigger:"axis",formatter:i=>{i=i[0];const n=new Date(i.value[0]);let c=i.value[1];return c!==null&&this.props.isFloatComma&&(c=c.toString().replace(".",",")),`${i.exact===!1?"i":""}${n.toLocaleString()}.${da(n.getMilliseconds())}: ${c}${this.unit}`},axisPointer:{animation:!0}},xAxis:{type:"time",splitLine:{show:!1},splitNumber:o,min:this.chart.min,max:this.chart.max,axisTick:{alignWithLabel:!0},axisLabel:{formatter:(i,n)=>{const c=new Date(i);return this.chart.withSeconds?`${fe(c.getHours())}:${fe(c.getMinutes())}:${fe(c.getSeconds())}`:this.chart.withTime?`${fe(c.getHours())}:${fe(c.getMinutes())}
|
|
306
|
+
`,ie=B=>({dropZone:{width:"100%",height:100,position:"relative"},dropZoneEmpty:{},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadDiv:{position:"relative",width:"100%",height:300,opacity:.9,marginTop:30,cursor:"pointer",outline:"none"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"calc(100% - 10px)",height:"calc(100% - 10px)",position:"relative",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},disabledOpacity:{opacity:.3,cursor:"default"},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},buttonCropWrapper:{position:"absolute",zIndex:222,right:0,top:50},error:{border:"2px solid red"}});class V extends C.Component{constructor(z){if(super(z),this.state={uploadFile:!1,anchorEl:null,cropHandler:!1},this.cropperRef=(0,C.createRef)(),!window.document.getElementById("cropper-style-json-component")){const S=window.document.createElement("style");S.setAttribute("id","cropper-style-json-component"),S.innerHTML=P,window.document.head.appendChild(S)}}onDrop(z){const{maxSize:S,t:g,onChange:u}=this.props,v=z[0],I=new FileReader;I.onabort=()=>console.log("file reading was aborted"),I.onerror=()=>console.log("file reading has failed"),I.onload=()=>{let M="image/"+v.name.split(".").pop().toLowerCase();if(M==="image/jpg"?M="image/jpeg":M.includes("svg")&&(M="image/svg+xml"),v.size>S)return window.alert(g("ra_File is too big. Max %sk allowed. Try use SVG.",Math.round(S/1024)));const k=`data:${M};base64,${btoa(new Uint8Array(I.result).reduce((D,q)=>D+String.fromCharCode(q),""))}`;u(k)},I.readAsArrayBuffer(v)}render(){const{disabled:z,maxSize:S,classes:g,icon:u,t:v,removeIconFunc:I,accept:M,error:k,crop:D,onChange:q}=this.props,{uploadFile:xe,anchorEl:be,cropHandler:se}=this.state;return R.createElement(G.default,{disabled:z||se,key:"dropzone",multiple:!1,accept:M,maxSize:S,onDragEnter:()=>this.setState({uploadFile:"dragging"}),onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(ue,re)=>{if(this.setState({uploadFile:!1}),!ue.length)window.alert(re&&re[0]&&re[0].errors&&re[0].errors[0]&&re[0].errors[0].message||v("ra_Cannot upload"));else return this.onDrop(ue)}},({getRootProps:ue,getInputProps:re})=>R.createElement("div",le({className:me.default.clsx(g.uploadDiv,xe==="dragging"&&g.uploadDivDragging,g.dropZone,z&&g.disabledOpacity,!u&&g.dropZoneEmpty)},ue()),R.createElement("input",le({},re())),R.createElement("div",{className:me.default.clsx(g.uploadCenterDiv,k&&g.error)},u?I&&!se&&R.createElement("div",{className:g.buttonRemoveWrapper},R.createElement(L.Tooltip,{title:v("ra_Clear")},R.createElement(Z.Z,{size:"large",onClick:y=>{I&&I(),y.stopPropagation()}},R.createElement(X.default,null)))):R.createElement("div",{className:g.uploadCenterTextAndIcon},R.createElement(J.FaFileUpload,{className:g.uploadCenterIcon}),R.createElement("div",{className:g.uploadCenterText},v(xe==="dragging"?"ra_Drop file here":"ra_Place your files here or click here to open the browse dialog"))),u&&D&&R.createElement("div",{className:g.buttonCropWrapper},R.createElement(L.Tooltip,{title:v("ra_Crop")},R.createElement(Z.Z,{size:"large",onClick:y=>{se?this.setState({anchorEl:y.currentTarget}):this.setState({cropHandler:!0}),y.stopPropagation()}},R.createElement(Ve.default,{color:se?"primary":"inherit"}))),R.createElement(L.Menu,{anchorEl:be,keepMounted:!0,open:Boolean(be),onClose:()=>this.setState({anchorEl:null})},R.createElement(L.MenuItem,{onClick:()=>this.setState({anchorEl:null,cropHandler:!1},()=>{var y,Y;const nt=(Y=(y=this.cropperRef)==null?void 0:y.current)==null?void 0:Y.cropper;q(nt.getCroppedCanvas().toDataURL())})},v("ra_Save")),R.createElement(L.MenuItem,{onClick:()=>this.setState({anchorEl:null,cropHandler:!1})},v("ra_Close")))),u&&!se?R.createElement("img",{src:u,className:g.image,alt:"icon"}):null,u&&D&&se?R.createElement(te.Cropper,{ref:this.cropperRef,className:g.image,src:u,initialAspectRatio:1,viewMode:1,guides:!1,minCropBoxHeight:10,minCropBoxWidth:10,background:!1,checkOrientation:!1}):null)))}}V.defaultProps={disabled:!1,maxSize:10*1024,icon:null,removeIconFunc:null,accept:{"image/*":[]},error:!1,onChange:B=>console.log(B),t:B=>B,crop:!1},V.propTypes={classes:l().object,maxSize:l().number,disabled:l().bool,crop:l().bool,error:l().bool,onChange:l().func,accept:l().object,t:l().func},ze.Z=(0,K.withStyles)(ie)(V)},37412:function(kt,ze,h){h.r(ze),h.d(ze,{default:function(){return Co}});var C=h(4819),s=h.n(C),$e=h(15854),l=h.n($e),G=h(58503),te=h(66447),K=h(29480),oe=h(6774),L=h(19974),qe=h(44887),Z=h(78565),X=h(72170),Ve=h(96094),J=h(62976),me=h(91495),R=h(70703),_e=h(56322),Se=h(36609),He=h(13820),he=h(49630),pe=h(43924),le=h(41728),P=h(55289),ie=h(28027),V=h(23060),B=h(87951),z=h.n(B),S=h(66966),g=h(28475),u=h(18226),v=h(12923),I=h(99296),M=h(30464),k=h(2598),D=h(36315),q=h(62664),xe=h(99822),be=h(32761),se=h(65890),ue=h(84998),re=Object.defineProperty,y=(r,e,t)=>e in r?re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e,t)=>(y(r,typeof e!="symbol"?e+"":e,t),t),nt=(r,e,t)=>new Promise((a,o)=>{var i=d=>{try{c(t.next(d))}catch(m){o(m)}},n=d=>{try{c(t.throw(d))}catch(m){o(m)}},c=d=>d.done?a(d.value):Promise.resolve(d.value).then(i,n);c((t=t.apply(r,e)).next())});const Zs=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},headingIcon:{marginRight:5,width:32,height:32},titleEnabled:{float:"right",fontSize:16,color:"#7ff57f",textTransform:"uppercase",fontWeight:"bold",paddingLeft:20},scrollDiv:{width:"100%",height:"100%",overflow:"auto"},fullWidth:{width:"100%"},enabledControl:{width:130,display:"inline-block",verticalAlign:"top"},customControls:{width:"calc(100% - 130px)",maxWidth:800,display:"inline-block",verticalAlign:"top",paddingTop:16},accordionOdd:{},accordionEven:{backgroundColor:"rgba(128, 128, 128, 0.1)"},accordionHeaderOdd:{backgroundColor:"rgba(128, 128, 128, 0.2)"},accordionHeaderEven:{backgroundColor:"rgba(128, 128, 128, 0.3)"},accordionHeaderEnabledOdd:{backgroundColor:"rgba(128, 255, 128, 0.2)"},accordionHeaderEnabledEven:{backgroundColor:"rgba(128, 255, 128, 0.2)"},enabledVisible:{display:"inline-block"},enabledInvisible:{display:"none"}}),Rs=".",St=class extends C.Component{constructor(r){super(r),Y(this,"onSave",t=>{if(this.props.objectIDs.length>10&&!this.state.confirmed)return this.cb=t,this.setState({showConfirmation:!0});this.saveOneState([...this.props.objectIDs],()=>{this.changedItems=[],this.cachedNewValues={},this.commonConfig=this.getCommonConfig(),this.setState({confirmed:!1,hasChanges:!1,newValues:{}},()=>{this.props.reportChangedIds(this.changedIds),this.props.onChange(!1,!0),t&&setTimeout(()=>t(),100)})})});let e=(window._localStorage||window.localStorage).getItem("App.customsExpanded")||"[]";try{e=JSON.parse(e)}catch(t){e=[]}this.changedIds=[],this.state={loaded:!1,hasChanges:!1,expanded:e,newValues:{},progress:null,maxOids:null,confirmed:!1,showConfirmation:!1},this.scrollDone=!1,this.lastExpanded=(window._localStorage||window.localStorage).getItem("App.customsLastExpanded")||"",this.scrollDivRef=(0,C.createRef)(),this.changedItems=[],this.jsonConfigs={},this.controls={},this.refTemplate={},this.props.customsInstances.map(t=>this.refTemplate[t]=(0,C.createRef)()),this.customObj=this.props.objectIDs.length>1?{custom:{},native:{}}:JSON.parse(JSON.stringify(this.props.objects[this.props.objectIDs[0]]||null)),this.customObj&&(this.loadAllPromises=this.loadAllCustoms().then(()=>{this.commonConfig=this.getCommonConfig(),this.setState({loaded:!0,newValues:{}})}))}componentDidMount(){this.props.registerSaveFunc&&this.props.registerSaveFunc(this.onSave)}componentWillUnmount(){this.props.registerSaveFunc&&this.props.registerSaveFunc(null)}loadAllCustoms(){const r=[];return this.props.customsInstances.forEach(e=>{const t=e.replace(/\.\d+$/,"").replace("system.adapter.","");this.jsonConfigs[t]===void 0&&(this.jsonConfigs[t]=!1,r.push(this.getCustomTemplate(t)))}),Promise.all(r).then(()=>{this.props.customsInstances.forEach(e=>{var t,a;const o=e.replace(/\.\d+$/,"").replace("system.adapter.","");this.jsonConfigs[o]&&(this.jsonConfigs[o].instanceObjs=this.jsonConfigs[o].instanceObjs||{},this.jsonConfigs[o].instanceObjs[e]={_id:e,common:JSON.parse(JSON.stringify((t=this.props.objects["system.adapter."+e])==null?void 0:t.common)),native:JSON.parse(JSON.stringify((a=this.props.objects["system.adapter."+e])==null?void 0:a.native))})})})}showError(r){this.setState({error:r})}getCustomTemplate(r){var e;const t=this.props.objects["system.adapter."+r]?JSON.parse(JSON.stringify(this.props.objects["system.adapter."+r])):null;return t?(ue.Z.fixAdminUI(t),((e=t.common)==null?void 0:e.adminUI.custom)==="json"?this.props.socket.fileExists(r+".admin","jsonCustom.json5").then(a=>a?this.props.socket.readFile(r+".admin","jsonCustom.json5"):this.props.socket.readFile(r+".admin","jsonCustom.json")).then(a=>{a.file!==void 0&&(a=a.file);try{a=z().parse(a),this.jsonConfigs[r]=this.jsonConfigs[r]||{},this.jsonConfigs[r].json=a}catch(o){console.error(`Cannot parse jsonConfig of ${r}: ${o}`),window.alert(`Cannot parse jsonConfig of ${r}: ${o}`)}return be.Z.loadI18n(this.props.socket,a.i18n,r)}).catch(a=>{console.error(`Cannot load jsonConfig of ${r}: ${a}`),window.alert(`Cannot load jsonConfig of ${r}: ${a}`)}):(console.error(`Adapter ${r} is not yet supported by this version of admin`),window.alert(`Adapter ${r} is not yet supported by this version of admin`),Promise.resolve(null))):(console.error(`Cannot find adapter "${t}"`),Promise.resolve(null))}_executeCustom(r,e,t,a,o,i,n){if(n.includes(i))return;n.push(i);let c=[];if(r&&typeof r=="object"&&(c=r.alsoDependsOn||[],typeof c=="string"&&(c=[c]),r=r.func),c.forEach(d=>{if(o[d])if(o[d].defaultFunc){const m=this._executeCustom(o[d].defaultFunc,e,t,a,o,d,n);m!==void 0&&(e[d]=m)}else return console.error(`[JsonConfigComponent] attribute "${d}" is not required to be includes in "alsoDependsOn" while has static value!`);else return console.error(`[JsonConfigComponent] attribute "${d}" does not exist!`)}),!r)e[i]=o[i].default===void 0?null:o[i].default;else try{const m=new Function("data","originalData","_system","instanceObj","customObj","_socket",r.includes("return")?r:"return "+r)(e||this.props.data,this.props.originalData,this.props.systemConfig,a,t,this.props.socket);e[i]=m}catch(d){console.error(`Cannot execute ${r}: ${d}`),e[i]=!o[i]||o[i].default===void 0?null:o[i].default}}static flattenItems(r,e){return e=e||{},r&&Object.keys(r).forEach(t=>{r[t].items?St.flattenItems(r[t].items,e):e[t]=r[t]}),e}getDefaultValues(r,e){const t={enabled:!1},a=r.split(".")[0];if(this.jsonConfigs[a]&&!this.jsonConfigs[a].disabled){const o=St.flattenItems(this.jsonConfigs[a].json.items);if(o){const i=[],n=Object.keys(o).filter(c=>o[c]);n.forEach(c=>{!o[c].defaultFunc&&o[c].default!==void 0&&(t[c]=o[c].default)}),n.forEach(c=>nt(this,null,function*(){o[c].defaultFunc&&this._executeCustom(o[c].defaultFunc,t,e,this.jsonConfigs[a].instanceObjs[r],o,c,i)}))}}return t}getCommonConfig(){const r=this.props.objectIDs||[],e=this.props.objects,t={};return this.props.customsInstances.forEach(a=>{const o=a.split(".")[0];this.jsonConfigs[o]&&this.jsonConfigs[o].disabled||(t[a]={},r.forEach(i=>{var n;const c=e[i],d=(n=c==null?void 0:c.common)!=null&&n.custom&&c.common.custom[a]||null;if(d)Object.keys(d).forEach(m=>{t[a][m]===void 0?t[a][m]=d[m]:t[a][m]!==d[m]&&(Array.isArray(t[a][m])||(t[a][m]=[t[a][m]]),!t[a][m].includes(d[m])&&t[a][m].push(d[m]))});else{let m=this.getDefaultValues(a,c);m.enabled=!1,Object.keys(m).forEach(f=>{t[a][f]===void 0?t[a][f]=m[f]:t[a][f]!==m[f]&&(Array.isArray(t[a][f])||(t[a][f]=[t[a][f]]),!t[a][f].includes(m[f])&&t[a][f].push(m[f]))})}}),Object.keys(t[a]).forEach(i=>{Array.isArray(t[a][i])&&t[a][i].sort()}))}),t}isChanged(r){return r=r||this.state.newValues,Object.keys(r).find(e=>r[e]===null||r[e]&&Object.keys(r[e]).find(t=>!t.startsWith("_")))}combineNewAndOld(r,e){const t=Object.assign({},this.commonConfig[r]||{},this.state.newValues[r]||{});return e&&Object.keys(t).forEach(a=>{a.startsWith("_")&&delete t[a]}),this.state.newValues[r]===null&&(t.enabled=!1),t}renderOneCustom(r,e,t,a){var o;const i=r.split(".")[0],n=`${Rs}/adapter/${i}/${this.props.objects["system.adapter."+i].common.icon}`,c=this.state.newValues[r]!==void 0&&(!this.state.newValues[r]||this.state.newValues[r].enabled!==void 0)?!!(this.state.newValues[r]&&this.state.newValues[r].enabled):this.state.newValues[r]===null?!1:this.commonConfig[r].enabled,d=Array.isArray(c)&&(!this.state.newValues[r]||this.state.newValues[r].enabled===void 0),m=this.jsonConfigs[i]&&((o=this.jsonConfigs[i].json)==null?void 0:o.disabled),f=this.combineNewAndOld(r);return m&&this.jsonConfigs[i].json.hidden===!0||typeof this.jsonConfigs[i].json.hidden=="string"&&this._executeCustom(this.jsonConfigs[i].json.hidden,f,t,e,this.jsonConfigs[i].json.items,"enabled",[])?null:s().createElement(g.Z,{key:r,id:"Accordion_"+r,className:a%2?this.props.classes.accordionOdd:this.props.classes.accordionEven,expanded:this.state.expanded.includes(r),ref:this.refTemplate[r],onChange:()=>{const p=[...this.state.expanded],j=p.indexOf(r);j===-1?p.push(r):p.splice(j,1),(window._localStorage||window.localStorage).setItem("App.customsExpanded",JSON.stringify(p)),j===-1&&(window._localStorage||window.localStorage).setItem("App.customsLastExpanded",r),this.setState({expanded:p})}},s().createElement(u.Z,{expandIcon:s().createElement(q.default,null),"data-id":r,className:a%2?c?this.props.classes.accordionHeaderEnabledOdd:this.props.classes.accordionHeaderOdd:c?this.props.classes.accordionHeaderEnabledEven:this.props.classes.accordionHeaderEven},s().createElement("img",{src:n,className:this.props.classes.headingIcon,alt:""}),s().createElement(I.Z,{className:this.props.classes.heading},this.props.t("Settings %s",r)),s().createElement("div",{className:(0,V.default)(this.props.classes.titleEnabled,"titleEnabled",c?this.props.classes.enabledVisible:this.props.classes.enabledInvisible)},this.props.t("Enabled"))),s().createElement(v.Z,null,s().createElement("div",{className:this.props.classes.enabledControl},s().createElement(k.Z,{className:this.props.classes.formControl,control:s().createElement(D.Z,{indeterminate:d,checked:!!c,disabled:m,onChange:p=>{this.cachedNewValues=this.cachedNewValues||this.state.newValues;const j=JSON.parse(JSON.stringify(this.cachedNewValues));j[r]=j[r]||{},d||p.target.checked?j[r].enabled=!0:c?j[r]=null:delete j[r],this.cachedNewValues=j,this.setState({newValues:j,hasChanges:this.isChanged(j)},()=>{this.cachedNewValues=null,this.props.onChange&&this.props.onChange(this.state.hasChanges)})}}),label:this.props.t("Enabled")})),s().createElement("div",{className:this.props.classes.customControls},!m&&(c||d)?s().createElement(be.Z,{instanceObj:e,customObj:t,custom:!0,className:"",adapterName:i,instance:parseInt(r.split(".").pop(),10)||0,socket:this.props.socket,theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType,multiEdit:this.props.objectIDs.length>1,schema:this.jsonConfigs[i].json,data:f,onError:p=>this.setState({error:p},()=>this.props.onError&&this.props.onError(p)),onValueChange:(p,j)=>{this.cachedNewValues=this.cachedNewValues||this.state.newValues,console.log(`${p} => ${j}`);const A=JSON.parse(JSON.stringify(this.cachedNewValues));A[r]=A[r]||{},JSON.stringify(se.Z.getValue(this.commonConfig[r],p))===JSON.stringify(j)?(se.Z.setValue(A[r],p,null),Object.keys(A[r]).length||delete A[r]):se.Z.setValue(A[r],p,j),this.cachedNewValues=A,this.setState({newValues:A,hasChanges:this.isChanged(A)},()=>{this.cachedNewValues=null,this.props.onChange&&this.props.onChange(this.state.hasChanges)})}}):null,m&&this.jsonConfigs[i].json.help?typeof this.jsonConfigs[i].json.help=="object"?this.jsonConfigs[i].json.help[this.props.lang]||this.jsonConfigs[i].json.help.en:this.props.t(this.jsonConfigs[i].json.help):null)))}isAllOk(){return!0}renderErrorMessage(){return!!this.state.error&&s().createElement(xe.default,{title:this.props.t("Error"),text:this.state.error,onClose:()=>this.setState({error:""})})}getObject(r,e,t){return r[t]?Promise.resolve(r[t]):this.props.socket.getObject(t).then(a=>(e[t]=JSON.parse(JSON.stringify(a)),r[t]=a,a))}saveOneState(r,e,t,a){if(t=t||{},a=a||{},!r||!r.length){const o=Object.keys(t);if(!o.length)this.setState({maxOids:null},()=>this.props.onProgress(!1)),e&&e();else{this.setState({progress:Math.round((this.state.maxOids-o.length)/this.state.maxOids*50)+50});const i=o.shift();return JSON.stringify(t[i].common)!==JSON.stringify(a[i].common)?(!this.changedIds.includes(i)&&this.changedIds.push(i),this.props.socket.setObject(i,t[i]).then(()=>(delete t[i],delete a[i],this.props.socket.getObject(i).then(n=>{this.props.objects[i]=n,setTimeout(()=>this.saveOneState(r,e,t,a),0)})))):(delete t[i],delete a[i],setTimeout(()=>this.saveOneState(r,e,t,a),0))}}else{const o=this.state.maxOids||r.length;this.state.maxOids===null&&this.setState({maxOids:r.length},()=>this.props.onProgress(!0)),this.setState({progress:Math.round((o-r.length)/o*50)});const i=r.shift();this.getObject(t,a,i).then(n=>{if(!n)return window.alert(`Invalid object ${i}`);n.common&&n.common.custom&&Object.keys(n.common.custom).forEach(d=>{(!n.common.custom[d]||!n.common.custom[d].enabled)&&(n.common.custom[d]=null)});const c=Object.keys(this.state.newValues);for(let d=0;d<c.length;d++){const m=c[d],f=this.combineNewAndOld(m,!0);if(f.enabled===!1)n.common&&n.common.custom&&n.common.custom[m]&&(n.common.custom[m]=null);else if(f.enabled){if(n.common=n.common||{},Array.isArray(f.enabled)&&(!n.common.custom||!n.common.custom[m]||!n.common.custom[m].enabled)){n.common.custom&&n.common.custom[m]&&(n.common.custom[m]=null);continue}if(n.common.custom=n.common.custom||{},!n.common.custom[m]||!n.common.custom[m].enabled){let p=this.getDefaultValues(m,n);n.common.custom[m]=JSON.parse(JSON.stringify(p||{}))}n.common.custom[m].enabled=!0,Object.keys(f).forEach(p=>{(!Array.isArray(f[p])||f[p][0]&&typeof f[p][0]=="object")&&(n.common.custom[m][p]=f[p])})}}setTimeout(()=>this.saveOneState(r,e,t,a),0)})}}renderConfirmationDialog(){return this.state.showConfirmation?s().createElement(le.default,{text:this.props.t("The changes will be applied to %s states. Are you sure?",this.props.objectIDs.length),ok:this.props.t("Yes"),onClose:r=>{r?this.setState({showConfirmation:!1,confirmed:!0},()=>{const e=this.cb;this.cb=null,this.onSave(e)}):(this.cb=null,this.setState({showConfirmation:!1}))}}):!1}render(){if(this.customObj===null)return s().createElement("div",{style:{color:"#F55",fontSize:32}},this.props.t("Object does not exist!"));if(!this.state.loaded)return s().createElement(S.Z,null);let r=0;return s().createElement(M.Z,{className:this.props.classes.paper},this.state.maxOids>1&&s().createElement(S.Z,{color:"secondary",variant:"determinate",value:this.state.progress}),s().createElement("div",{className:this.props.classes.scrollDiv,ref:this.scrollDivRef},this.state.maxOids===null&&Object.keys(this.jsonConfigs).map(e=>this.jsonConfigs[e]?Object.keys(this.jsonConfigs[e].instanceObjs).map(t=>this.renderOneCustom(t,this.jsonConfigs[e].instanceObjs[t],this.customObj,r++)):null)),this.renderErrorMessage(),this.renderConfirmationDialog())}};let xt=St;Y(xt,"AsyncFunction",Object.getPrototypeOf(function(){return nt(this,null,function*(){})}).constructor),xt.propTypes={t:l().func,onChange:l().func,lang:l().string,expertMode:l().bool,objects:l().object,customsInstances:l().array,socket:l().object,objectIDs:l().array,theme:l().object,themeName:l().string,themeType:l().string,registerSaveFunc:l().func,onProgress:l().func,onError:l().func};var Fs=(0,R.default)()((0,G.withStyles)(Zs)(xt)),jt=h(6530),Ot=h(55784),et=h(31452),tt=h(26733),je=h(66116),E=h(41381),Oe=h(71386),Ie=h(67304),Pt=h(56892),W=h(75836),ks=h(42959),lt=h(44583),H=h(59357),N=h(18635),Ps=h(96875),Ws=h(62030),Wt=h(31122),Mt=h(47535),zt=h(33621),Vt=h(67099),Ht=h(48976),Jt=h(22763),Lt=h(33286),Bt=h(46652),Ut=h(19129),Yt=h(5677),Gt=h(77768),ct=h(33919),Ms=h(10722),zs=h(83609),Vs=Object.defineProperty,Hs=(r,e,t)=>e in r?Vs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ht=(r,e,t)=>(Hs(r,typeof e!="symbol"?e+"":e,t),t);const Js=r=>({table:{display:"grid","& tr":{display:"contents"},"& thead":{display:"contents"},"& tbody":{display:"contents"},"& th":{position:"sticky",userSelect:"none"},"& .resize-handle":{display:"block",position:"absolute",cursor:"col-resize",width:7,right:0,top:2,bottom:2,zIndex:1,borderRight:"2px dotted #888","&:hover":{borderColor:"#ccc",borderRightStyle:"solid"},"&.active":{borderColor:"#517ea5",borderRightStyle:"solid"}}}});class Kt extends C.Component{constructor(e){super(e),ht(this,"resizerReset",()=>{for(let t=0;t<this.resizerCurrentWidths.length;t++)this.resizerCurrentWidths[t]=(this.props.initialWidths||[])[t]||"auto";(window._localStorage||window.localStorage).setItem(`App.${this.props.name||"history"}.table`,JSON.stringify(this.resizerCurrentWidths)),this.resizerApplyWidths()}),ht(this,"resizerMouseMove",t=>{if(this.resizerActiveDiv){const a=this.resizerOldWidth+t.clientX-this.resizerPosition,o=this.resizerOldWidthNext-t.clientX+this.resizerPosition;(!this.resizerMin||a>this.resizerMin)&&(!this.resizerMinNext||o>this.resizerMinNext)&&(this.resizerCurrentWidths[this.resizerActiveIndex]=a,this.resizerCurrentWidths[this.resizerActiveIndex+1]=o,this.resizerApplyWidths())}}),ht(this,"resizerMouseUp",()=>{(window._localStorage||window.localStorage).setItem(`App.${this.props.name||"history"}.table`,JSON.stringify(this.resizerCurrentWidths)),this.resizerActiveIndex=null,this.resizerActiveDiv=null,window.removeEventListener("mousemove",this.resizerMouseMove),window.removeEventListener("mouseup",this.resizerMouseUp)}),ht(this,"resizerMouseDown",t=>{if(this.resizerActiveIndex===null||this.resizerActiveIndex===void 0){console.log("Mouse down "+t.target.dataset.index),this.resizerActiveIndex=parseInt(t.target.dataset.index,10),this.resizerActiveDiv=t.target,this.resizerMin=this.props.minWidths?this.props.minWidths[this.resizerActiveIndex]:0,this.resizerMinNext=this.props.minWidths?this.props.minWidths[this.resizerActiveIndex+1]:0,this.resizerPosition=t.clientX;let a;this.resizerCurrentWidths[this.resizerActiveIndex]==="auto"&&(a=a||this.resizerRefTable.current.querySelectorAll("th"),this.resizerCurrentWidths[this.resizerActiveIndex]=a[this.resizerActiveIndex].offsetWidth),this.resizerCurrentWidths[this.resizerActiveIndex+1]==="auto"&&(a=a||this.resizerRefTable.current.querySelectorAll("th"),this.resizerCurrentWidths[this.resizerActiveIndex+1]=a[this.resizerActiveIndex+1].offsetWidth),this.resizerOldWidth=this.resizerCurrentWidths[this.resizerActiveIndex],this.resizerOldWidthNext=this.resizerCurrentWidths[this.resizerActiveIndex+1],window.addEventListener("mousemove",this.resizerMouseMove),window.addEventListener("mouseup",this.resizerMouseUp)}}),this.resizerRefTable=s().createRef(),this.resizerActiveIndex=null,this.resizerActiveDiv=null,this.resizerCurrentWidths=[]}componentDidMount(){this.resizerInstall()}componentWillUnmount(){this.resizerUninstall()}resizerInstall(){if(this.resizerRefTable.current&&!this.resizerRefTable.current._installed){this.resizerRefTable.current._installed=!0;const e=this.resizerRefTable.current.querySelectorAll("th"),t=(window._localStorage||window.localStorage).getItem(`App.${this.props.name||"history"}.table`);if(this.widthFilled=!1,t)try{this.resizerCurrentWidths=JSON.parse(t),this.widthFilled=!0}catch(a){}if(this.widthFilled)if(this.resizerCurrentWidths.length!==e.length)this.resizerCurrentWidths=[],this.widthFilled=!1;else{const a=this.resizerRefTable.current.offsetWidth;let o=0;for(let i=0;i<this.resizerCurrentWidths.length;i++)if(isFinite(this.resizerCurrentWidths[i]))o+=this.resizerCurrentWidths[i];else{o=null;break}o!==null&&Math.abs(o-a)>20&&(this.resizerCurrentWidths=[],this.widthFilled=!1)}for(let a=0;a<e.length;a++)if(!this.widthFilled&&this.resizerCurrentWidths.push(e[a].offsetWidth),a<e.length-1){const o=window.document.createElement("div");o.dataset.index=a.toString(),o.onmousedown=this.resizerMouseDown,o.ondblclick=this.resizerReset,o.title=this.props.dblTitle||"Double click to reset table layout",o.className="resize-handle",e[a].appendChild(o)}this.widthFilled&&this.resizerApplyWidths()}else this.installTimeout=setTimeout(()=>{this.installTimeout=null,this.resizerInstall()},100)}resizerUninstall(){if(this.installTimeout&&clearTimeout(this.installTimeout),this.resizerRefTable.current&&this.resizerRefTable.current._installed){this.resizerRefTable.current._installed=!0;const e=this.resizerRefTable.current.querySelectorAll("th");for(let t=0;t<e.length;t++){const a=e[t].querySelector(".resize-handle");a&&(a.onmousedown=null,a.remove())}}}resizerApplyWidths(){const e=[];if(this.resizerCurrentWidths.length)for(let t=0;t<this.resizerCurrentWidths.length;t++)this.resizerCurrentWidths[t]?e.push(this.resizerCurrentWidths[t]!=="auto"?this.resizerCurrentWidths[t]+"px":"auto"):this.props.initialWidths&&this.props.initialWidths[t]?e.push(this.props.initialWidths[t]!=="auto"?this.props.initialWidths[t]+"px":"auto"):e.push("auto");else if(this.props.initialWidths)for(let t=0;t<this.props.initialWidths.length;t++)this.props.initialWidths[t]?e.push(this.props.initialWidths[t]!=="auto"?this.props.initialWidths[t]+"px":"auto"):e.push("auto");return this.resizerRefTable.current&&e.length&&(this.resizerRefTable.current.style.gridTemplateColumns=e.join(" ")),e.length?e.join(" "):void 0}render(){if(this.props.ready===!1)return s().createElement(zs.Z,null);const e={gridTemplateColumns:this.resizerApplyWidths()};return s().createElement(Ms.Z,{stickyHeader:this.props.stickyHeader,size:this.props.size||"small",className:this.props.classes.table+(this.props.className?" "+this.props.className:""),ref:this.resizerRefTable,style:Object.assign({},this.props.style||{},e)},this.props.children)}}Kt.propTypes={name:l().string,ready:l().bool,stickyHeader:l().bool,size:l().string,className:l().string,style:l().object,initialWidths:l().array,minWidths:l().array,dblTitle:l().string};var Ls=(0,G.withStyles)(Js)(Kt),Bs=h(39323),pt=h(42158),Us=Object.defineProperty,Qt=Object.getOwnPropertySymbols,Ys=Object.prototype.hasOwnProperty,Gs=Object.prototype.propertyIsEnumerable,It=(r,e,t)=>e in r?Us(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Je=(r,e)=>{for(var t in e||(e={}))Ys.call(e,t)&&It(r,t,e[t]);if(Qt)for(var t of Qt(e))Gs.call(e,t)&&It(r,t,e[t]);return r},Ks=(r,e,t)=>(It(r,typeof e!="symbol"?e+"":e,t),t);const Xt={en:zt.Z,fr:Wt.Z,ru:Mt.Z,de:Yt.Z,es:Vt.Z,br:Ut.Z,nl:Gt.Z,it:Lt.Z,pt:Jt.Z,pl:Ht.Z,"zh-cn":Bt.Z};function At(r){return r<10?"00"+r:r<100?"0"+r:r}function st(r){return r<10?"0"+r:r}const Qs=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},tableDiv:{height:`calc(100% - ${r.mixins.toolbar.minHeight+parseInt(r.spacing(1),10)}px)`,overflow:"hidden",width:"100%"},container:{height:"100%"},table:{minWidth:960,width:"100%","& td:nth-of-type(5)":{overflow:"hidden",whiteSpace:"nowrap"},"& tr:nth-child(even)":{backgroundColor:r.palette.mode==="dark"?"#383838":"#b2b2b2"}},row:{userSelect:"none",position:"relative","&:hover":{opacity:.7},"& td":{position:"relative"}},updatedRow:{animation:"updated 1s"},rowInterpolated:{opacity:.5},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:r.palette.primary.main},rowSelected:{background:r.palette.secondary.main,color:r.palette.secondary.contrastText,"& td":{color:r.palette.secondary.contrastText,background:r.palette.secondary.main}},rowFocused:{position:"absolute",pointerEvents:"none",top:0,bottom:0,left:0,right:0,margin:3,border:"1px dotted "+r.palette.action.active},grow:{flexGrow:1},editorTimePicker:{marginLeft:r.spacing(1),width:120},editorDatePicker:{marginLeft:r.spacing(1),width:150},msInput:{width:50,paddingTop:16,marginLeft:5,"& label":{marginTop:15}},cellAckTrue:{color:r.palette.mode==="dark"?"#66ff7f":"#04a821"},cellAckFalse:{color:"#FF6666"},toolbarTime:{width:100,marginTop:9,marginLeft:r.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:r.spacing(1),paddingLeft:r.spacing(1),paddingRight:r.spacing(1),paddingTop:r.spacing(.5),paddingBottom:r.spacing(.5),border:"1px dotted #AAAAAA",borderRadius:r.spacing(1)},noLoadingProgress:{width:"100%",height:4},colValue:{},colAck:{},colFrom:{},colLastChange:{},colTs:{},dateInput:{width:140,marginRight:r.spacing(1)},timeInput:{width:100}});class $t extends C.Component{constructor(e){super(e),Ks(this,"onChange",(d,m)=>{if(d===this.props.obj._id&&m&&this.state.values&&(!this.state.values.length||this.state.values[this.state.values.length-1].ts<m.ts)){const f=[...this.state.values,m];this.setState({values:f})}});let t=(window._localStorage||window.localStorage).getItem("App.relativeRange")||"absolute",a=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteStart"),10)||0,o=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteEnd"),10)||0,i=(window._localStorage||window.localStorage).getItem("App.historySelected")||"",n=parseInt((window._localStorage||window.localStorage).getItem("App.historyLastSelected"),10)||null,c=(window._localStorage||window.localStorage).getItem("App.historyLastSelectedColumn")||null;(!a||!o)&&(!t||t==="absolute")&&(t="30"),a&&o&&(t="absolute");try{i=JSON.parse(i)}catch(d){i=[]}this.state={loaded:!1,min:null,max:null,start:a,end:o,values:null,relativeRange:t,selected:i,lastSelected:n,lastSelectedColumn:c,historyInstance:"",updateOpened:!1,insertOpened:!1,historyInstances:null,defaultHistory:"",lcVisible:!0,qVisible:!0,ackVisible:!0,fromVisible:!0,supportedFeatures:[],dateFormat:"dd.MM.yyyy",edit:{}},this.adminInstance=parseInt(window.location.search.slice(1),10)||0,this.supportedFeaturesPromises={},this.unit=this.props.obj.common&&this.props.obj.common.unit?" "+this.props.obj.common.unit:"",this.timeTimer=null,this.prepareData().then(()=>this.readHistoryRange()).then(()=>{t!=="absolute"?this.setRelativeInterval(this.state.relativeRange,!0):this.readHistory()})}readSupportedFeatures(e){if(e=e||this.state.historyInstance,e){if(this.supportedFeaturesPromises[e])return this.supportedFeaturesPromises[e]}else return Promise.resolve([]);return this.supportedFeaturesPromises[e]=new Promise(t=>{this.readSupportedFeaturesTimeout&&clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=setTimeout(()=>{this.readSupportedFeaturesTimeout=null,t([])},2e3),this.props.socket.sendTo(e,"features",null).then(a=>{this.readSupportedFeaturesTimeout?(this.readSupportedFeaturesTimeout&&clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=null,t(a?a.supportedFeatures||[]:[])):this.setState({supportedFeatures:a?a.supportedFeatures||[]:[]})})}),this.supportedFeaturesPromises[e]}componentDidMount(){this.props.socket.subscribeState(this.props.obj._id,this.onChange)}componentWillUnmount(){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange)}prepareData(){let e;return this.getHistoryInstances().then(t=>(e=t,this.props.socket.getCompactSystemConfig())).then(t=>{const a=t&&t.common&&t.common.defaultHistory;let o=(window._localStorage||window.localStorage).getItem("App.historyInstance")||"";return(!o||!e.find(i=>i.id===o&&i.alive))&&(o=a),(!o||!e.find(i=>i.id===o&&i.alive))&&(o=e.find(i=>i.alive),o&&(o=o.id)),!o&&e.length&&(o=a),this.readSupportedFeatures(o).then(i=>new Promise(n=>{this.setState({historyInstances:e,defaultHistory:a,historyInstance:o,supportedFeatures:i,dateFormat:(t.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y")},()=>n())}))})}getHistoryInstances(){const e=[],t=[];return this.props.customsInstances.forEach(a=>{const o=this.props.objects["system.adapter."+a];if(o&&o.common&&o.common.getHistory){let i={id:a,alive:!1};e.push(i),t.push(`system.adapter.${a}.alive`)}}),t.length?this.props.socket.getForeignStates(t).then(a=>(Object.keys(a).forEach(o=>{const i=e.find(n=>o.endsWith(n.id+".alive"));i&&(i.alive=a[o]&&a[o].val)}),e)):Promise.resolve(e)}readHistory(e,t){return e=e||this.state.start,t=t||this.state.end,this.state.historyInstance?(this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:e,end:t,from:!0,ack:!0,q:!0,addID:!1,aggregate:"none",returnNewestEntries:!0}).then(a=>{let o=[],i=this.rangeValues,n=!1,c=!1,d=!1,m=!1,f=!1;if(i&&i.length&&(!a||!a.length||i[0].ts<a[0].ts)&&(o.push(i[0]),o.push({ts:i[0].ts+1,e:!0}),console.log(`add ${new Date(i[0].ts).toISOString()}: ${i[0].val}`),!c&&i[0].q!==void 0&&(c=!0),!d&&i[0].ack!==void 0&&(d=!0),!m&&i[0].from&&(m=!0),!f&&i[0].c&&(f=!0)),a&&a.length)for(let p=0;p<a.length;p++)a[p]&&(!o.length||o[o.length-1].ts<a[p].ts)?(o.push(a[p]),a[p].from&&(a[p].from.startsWith("system.adapter.")?a[p].from=a[p].from.substring(15):a[p].from.startsWith("system.host.")&&(a[p].from=a[p].from.substring(7))),!n&&a[p].lc&&(n=!0),!c&&a[p].q!==void 0&&(c=!0),!d&&a[p].ack!==void 0&&(d=!0),!m&&a[p].from&&(m=!0),!f&&a[p].c&&(f=!0),console.log(`add value ${new Date(a[p].ts).toISOString()}: ${a[p].val}`)):o[o.length-1].ts===a[p].ts&&o[o.length-1].val!==a[p].ts&&console.error("Strange data!");else o.push({noDataForPeriod:!0});o.length||o.push({noData:!0}),this.setState({loading:!1,values:o,lcVisible:n,fromVisible:m,qVisible:c,ackVisible:d,cVisible:f})})):null}readHistoryRange(){const e=new Date,t=new Date(2e3,0,1);return this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:t.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then(a=>{a.length?((a[0].val===null||a[0].ts===t.getTime())&&a.shift(),a.forEach(o=>o.i=!0),this.rangeValues=a,this.setState({min:a[0].ts,max:a[a.length-1].ts,loading:!1})):(this.rangeValues=[],this.setState({loading:!1}))})}onToggleSelect(e,t,a){let o=[...this.state.selected];const i=o.indexOf(t);if(e.shiftKey&&this.state.lastSelected){let n=-1,c=-1;o=[];for(let d=0;d<this.state.values.length&&!(this.state.values[d].ts===t&&(n=d,c!==n&&o.push(this.state.values[d].ts),n!==-1&&c!==-1)||this.state.values[d].ts===this.state.lastSelected&&(c=d,c!==n&&o.push(this.state.values[d].ts),n!==-1&&c!==-1));d++)(n!==-1||c!==-1)&&o.push(this.state.values[d].ts)}else e.ctrlKey?(i!==-1?o.splice(i,1):o.push(t),o.sort()):o=[t];(window._localStorage||window.localStorage).setItem("App.historyLastSelected",t.toString()),(window._localStorage||window.localStorage).setItem("App.historyLastSelectedColumn",a),(window._localStorage||window.localStorage).setItem("App.historySelected",JSON.stringify(o)),this.setState({selected:o,lastSelected:t,lastSelectedColumn:a})}getTableRows(e){const t=[];for(let a=this.state.values.length-1;a>=0;a--){const o=this.state.values[a],i=o.ts;if(o.e)t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,e.rowInterpolated),key:i,hover:!0},s().createElement(H.Z,null),s().createElement(H.Z,null,"..."),this.state.ackVisible?s().createElement(H.Z,null):null,this.state.fromVisible?s().createElement(H.Z,null):null,this.state.lcVisible?s().createElement(H.Z,null):null));else if(o.noData||o.noDataForPeriod)t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,e.rowNoData),key:o.noData?"nodata":"",hover:!0},s().createElement(H.Z,null),s().createElement(H.Z,null,o.noData?this.props.t("No data in history"):this.props.t("No data in history for selected period")),this.state.ackVisible?s().createElement(H.Z,null):null,this.state.fromVisible?s().createElement(H.Z,null):null,this.state.lcVisible?s().createElement(H.Z,null):null));else{const n=o.i,c=this.state.lastSelected===i;let d=o.val;this.props.isFloatComma&&this.props.obj.common.type==="number"&&d&&(d=d.toString().replace(".",",")),d===null&&(d="null"),d===void 0&&(d="_");const m=this.state.selected.includes(i);t.push(s().createElement(lt.Z,{className:(0,V.default)(e.row,e.updatedRow,n&&e.rowInterpolated,m&&e.rowSelected),key:i+(o.val||"")},s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"ts")},`${new Date(o.ts).toLocaleDateString()} ${new Date(o.ts).toLocaleTimeString()}.${At(o.ts%1e3)}`,c&&this.state.lastSelectedColumn==="ts"?s().createElement("div",{className:e.rowFocused}):""),s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"val")},d+this.unit,c&&this.state.lastSelectedColumn==="val"?s().createElement("div",{className:e.rowFocused}):""),this.state.ackVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"ack"),className:o.ack?e.cellAckTrue:e.cellAckFalse},o.ack?"true":"false",c&&this.state.lastSelectedColumn==="ack"?s().createElement("div",{className:e.rowFocused}):""):null,this.state.fromVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"from")},o.from||"",c&&this.state.lastSelectedColumn==="from"?s().createElement("div",{className:e.rowFocused}):""):null,this.state.lcVisible?s().createElement(H.Z,{onClick:f=>!n&&this.onToggleSelect(f,i,"lc")},o.lc?`${new Date(o.lc).toLocaleDateString()} ${new Date(o.lc).toLocaleTimeString()}.${At(o.ts%1e3)}`:"",c&&this.state.lastSelectedColumn==="lc"?s().createElement("div",{className:e.rowFocused}):""):null))}}return t}shiftTime(){const e=new Date,t=6e4-e.getSeconds()-(1e3-e.getMilliseconds());e.getMilliseconds()&&e.setMilliseconds(1e3),e.getSeconds()&&e.setSeconds(60);const a=e.getTime();let o,i=this.state.relativeRange;if(i==="day")e.setHours(0),e.setMinutes(0),e.setSeconds(0),o=e.getTime();else if(i==="week"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else if(i==="2weeks"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(e.getDate()-7);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else i==="month"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),o=e.getTime()):i==="year"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),e.setMonth(0),o=e.getTime()):i==="12months"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setFullYear(e.getFullYear()-1),o=e.getTime()):(i=parseInt(i,10),o=a-i*6e4);this.setState({start:o,end:a},()=>this.readHistory()),this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},t||6e4)}setRelativeInterval(e,t){if(t||((window._localStorage||window.localStorage).setItem("App.relativeRange",e),this.setState({relativeRange:e})),e==="absolute"){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null;return}else(window._localStorage||window.localStorage).removeItem("App.absoluteStart"),(window._localStorage||window.localStorage).removeItem("App.absolute");const a=new Date;if(!this.timeTimer){const n=6e4-a.getSeconds()-(1e3-a.getMilliseconds());this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},n||6e4)}a.getMilliseconds()&&a.setMilliseconds(1e3),a.getSeconds()&&a.setSeconds(60);const o=a.getTime();let i;if(e==="day")a.setHours(0),a.setMinutes(0),a.setSeconds(0),i=a.getTime();else if(e==="week"){a.setHours(0),a.setMinutes(0),a.setSeconds(0);const n=a.getDay()||7;n!==1&&a.setHours(-24*(n-1)),i=a.getTime()}else if(e==="2weeks"){a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(a.getDate()-7);const n=a.getDay()||7;n!==1&&a.setHours(-24*(n-1)),i=a.getTime()}else e==="month"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(1),i=a.getTime()):e==="year"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setDate(1),a.setMonth(0),i=a.getTime()):e==="12months"?(a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setFullYear(a.getFullYear()-1),i=a.getTime()):(e=parseInt(e,10),i=o-e*6e4);this.setState({start:i,end:o},()=>this.readHistory())}renderTable(){if(this.state.values){const{classes:e}=this.props,t=[200,"auto"],a=[190,100];return this.state.ackVisible&&(t.push(50),a.push(50)),this.state.fromVisible&&(t.push(150),a.push(150)),this.state.lcVisible&&(t.push(200),a.push(190)),s().createElement(Ws.Z,{className:e.container},s().createElement(Ls,{stickyHeader:!0,className:e.table,initialWidths:t,minWidths:a,dblTitle:this.props.t("ra_Double click to reset table layout")},s().createElement(ks.Z,null,s().createElement(lt.Z,null,s().createElement(H.Z,{className:e.colTs},this.props.t("Timestamp")),s().createElement(H.Z,{className:e.colValue},this.props.t("Value")),this.state.ackVisible?s().createElement(H.Z,{className:e.colAck},this.props.t("Ack")):null,this.state.fromVisible?s().createElement(H.Z,{className:e.colFrom},this.props.t("From")):null,this.state.lcVisible?s().createElement(H.Z,{className:e.colLastChange},this.props.t("lc")):null)),s().createElement(Ps.Z,null,this.getTableRows(e))))}else return s().createElement(S.Z,null)}renderConfirmDialog(){return s().createElement(te.Z,{open:!!this.state.areYouSure,onClose:()=>this.setState({areYouSure:!1}),"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description"},s().createElement(K.Z,{id:"alert-dialog-title"}),s().createElement(oe.Z,null,s().createElement(qe.Z,{id:"alert-dialog-description"},this.props.t("Are you sure?")),s().createElement(k.Z,{control:s().createElement(D.Z,{value:this.state.suppressMessage,onChange:()=>this.setState({suppressMessage:!0})}),label:this.props.t("Suppress for 5 minutes")})),s().createElement(L.Z,null,s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({areYouSure:!1,suppressMessage:this.state.suppressMessage&&Date.now()},()=>this.onDelete()),color:"primary",autoFocus:!0,startIcon:s().createElement(me.default,null)},this.props.t("Delete")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({areYouSure:!1}),color:"secondary",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}onDelete(){const e=this.state.selected.map(t=>({state:{ts:t},id:this.props.obj._id}));this.props.socket.sendTo(this.state.historyInstance,"delete",e).then(()=>this.readHistory())}onUpdate(){let e=this.state.edit.val;this.props.obj.common&&(this.props.obj.common.type==="number"?typeof e!="number"&&(e=parseFloat(e.replace(",","."))):this.props.obj.common.type==="boolean"&&(e=e==="true"||e==="TRUE"||e===!0||e==="1"||e===1));const t={val:e,ack:this.state.edit.ack,ts:this.state.selected[0],from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q};Object.keys(t).forEach(a=>{t[a]===void 0&&delete t[a]}),!this.state.lcVisible&&t.lc&&delete t.lc,this.props.socket.sendTo(this.state.historyInstance,"update",[{id:this.props.obj._id,state:t}]).then(()=>this.readHistory())}onInsert(){let e=this.state.edit.val;this.props.obj.common&&(this.props.obj.common.type==="number"?e=parseFloat(e.replace(",",".")):this.props.obj.common.type==="boolean"&&(e=e==="true"||e==="TRUE"||e===!0||e==="1"||e===1));const t=this.state.edit.date;t.setHours(this.state.edit.time.getHours()),t.setMinutes(this.state.edit.time.getMinutes()),t.setSeconds(this.state.edit.time.getSeconds()),t.setMilliseconds(parseInt(this.state.edit.ms,10));const a={ts:t.getTime(),val:e,ack:this.state.edit.ack,from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q||0};!this.state.lcVisible&&a.lc&&delete a.lc,Object.keys(a).forEach(o=>{a[o]===void 0&&delete a[o]}),this.props.socket.sendTo(this.state.historyInstance,"insert",[{id:this.props.obj._id,state:a}]).then(()=>this.readHistory())}formatTime(e){const t=new Date(e);return`${st(t.getHours())}:${st(t.getMinutes())}:${st(t.getSeconds())}.${At(t.getMilliseconds())}`}formatDate(e){const t=new Date(e);return`${st(t.getDate())}.${st(t.getMonth()+1)}.${t.getFullYear()}`}updateEdit(e,t){const a=JSON.parse(JSON.stringify(this.state.edit));a.time=new Date(a.time),a.date=new Date(a.date),a[e]=t,this.setState({edit:a})}renderEditDialog(){return s().createElement(te.Z,{open:this.state.updateOpened||this.state.insertOpened,onClose:()=>this.setState({updateOpened:!1,insertOpened:!1}),"aria-labelledby":"edit-dialog-title","aria-describedby":"edit-dialog-description"},s().createElement(K.Z,{id:"edit-dialog-title"},this.state.updateOpened?this.props.t("Update entry"):this.props.t("Insert entry")),s().createElement(oe.Z,null,s().createElement("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off"},typeof this.state.edit.val=="boolean"?s().createElement(k.Z,{control:s().createElement(D.Z,{checked:this.state.edit.val,onChange:e=>this.updateEdit("val",e.target.checked)}),label:this.props.t("Value")}):s().createElement(N.Z,{variant:"standard",label:this.props.t("Value"),value:this.state.edit.val,onChange:e=>this.updateEdit("val",e.target.value)}),s().createElement("br",null),s().createElement(k.Z,{control:s().createElement(D.Z,{checked:this.state.edit.ack,onChange:e=>this.updateEdit("ack",e.target.checked)}),label:this.props.t("Acknowledged")}),this.state.insertOpened?s().createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:Xt[this.props.lang]},s().createElement(W.ZP,{container:!0,justifyContent:"space-around"},s().createElement(et.M,{className:this.props.classes.editorDatePicker,margin:"normal",label:this.props.t("Date"),inputFormat:this.state.dateFormat,value:this.state.edit.date,onChange:e=>this.updateEdit("date",e),renderInput:e=>s().createElement(N.Z,Je({className:this.props.classes.timeInput,variant:"standard"},e))}),s().createElement(tt.j,{margin:"normal",views:["hours","minutes","seconds"],label:this.props.t("Time"),ampm:!1,format:"HH:mm:ss",className:this.props.classes.editorTimePicker,value:this.state.edit.time,onChange:e=>this.updateEdit("time",e),renderInput:e=>s().createElement(N.Z,Je({className:this.props.classes.timeInput,variant:"standard"},e))}),s().createElement(N.Z,{variant:"standard",classes:{root:this.props.classes.msInput},label:this.props.t("ms"),type:"number",inputProps:{max:999,min:0},value:this.state.edit.ms,onChange:e=>this.updateEdit("ms",e.target.value)}))):null)),s().createElement(L.Z,null,s().createElement(Z.Z,{variant:"contained",onClick:()=>{const e=this.state.updateOpened;this.setState({updateOpened:!1,insertOpened:!1},()=>e?this.onUpdate():this.onInsert())},color:"primary",autoFocus:!0},this.state.updateOpened?this.props.t("Update"):this.props.t("Add")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.setState({updateOpened:!1,insertOpened:!1}),color:"grey"},this.props.t("Cancel"))))}setStartDate(e){e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",e),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",this.state.end),this.setState({start:e,relativeRange:"absolute"},()=>this.readHistory())}setEndDate(e){e=e.getTime(),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",this.state.start),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.setState({end:e,relativeRange:"absolute"},()=>this.readHistory())}renderToolbar(){const e=this.props.classes;return s().createElement(Pt.Z,null,s().createElement(Oe.Z,{variant:"standard",className:e.selectHistoryControl},s().createElement(je.Z,null,this.props.t("History instance")),s().createElement(Ie.Z,{variant:"standard",value:this.state.historyInstance||"",onChange:t=>{const a=t.target.value;(window._localStorage||window.localStorage).setItem("App.historyInstance",a),this.readSupportedFeatures(a).then(o=>this.setState({historyInstance:a,supportedFeatures:o},()=>this.readHistory()))}},this.state.historyInstances.map(t=>s().createElement(E.Z,{key:t.id,value:t.id,className:(0,V.default)(!t.alive&&e.notAliveInstance)},t.id)))),s().createElement(Oe.Z,{variant:"standard",className:e.selectRelativeTime},s().createElement(je.Z,null,this.props.t("Relative")),s().createElement(Ie.Z,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value)},s().createElement(E.Z,{key:"custom",value:"absolute",className:e.customRange},this.props.t("custom range")),s().createElement(E.Z,{key:"1",value:10},this.props.t("last 10 minutes")),s().createElement(E.Z,{key:"2",value:30},this.props.t("last 30 minutes")),s().createElement(E.Z,{key:"3",value:60},this.props.t("last hour")),s().createElement(E.Z,{key:"4",value:"day"},this.props.t("this day")),s().createElement(E.Z,{key:"5",value:24*60},this.props.t("last 24 hours")),s().createElement(E.Z,{key:"6",value:"week"},this.props.t("this week")),s().createElement(E.Z,{key:"7",value:24*60*7},this.props.t("last week")),s().createElement(E.Z,{key:"8",value:"2weeks"},this.props.t("this 2 weeks")),s().createElement(E.Z,{key:"9",value:24*60*14},this.props.t("last 2 weeks")),s().createElement(E.Z,{key:"10",value:"month"},this.props.t("this month")),s().createElement(E.Z,{key:"11",value:30*24*60},this.props.t("last 30 days")),s().createElement(E.Z,{key:"12",value:"year"},this.props.t("this year")),s().createElement(E.Z,{key:"13",value:"12months"},this.props.t("last 12 months")))),s().createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:Xt[this.props.lang]},s().createElement("div",{className:e.toolbarTimeGrid},s().createElement(et.M,{className:e.toolbarDate,disabled:this.state.relativeRange!=="absolute",disableToolbar:!0,variant:"inline",margin:"normal",inputFormat:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.start),onChange:t=>this.setStartDate(t),renderInput:t=>s().createElement(N.Z,Je({className:this.props.classes.dateInput,variant:"standard"},t))}),s().createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.start),onChange:t=>this.setStartDate(t),renderInput:t=>s().createElement(N.Z,Je({className:this.props.classes.timeInput,variant:"standard"},t))})),s().createElement("div",{className:e.toolbarTimeGrid},s().createElement(et.M,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarDate,disableToolbar:!0,inputFormat:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.end),onChange:t=>this.setEndDate(t),renderInput:t=>s().createElement(N.Z,Je({className:this.props.classes.dateInput,variant:"standard"},t))}),s().createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.end),onChange:t=>this.setEndDate(t),renderInput:t=>s().createElement(N.Z,Je({className:this.props.classes.timeInput,variant:"standard"},t))}))),s().createElement("div",{className:e.grow}),this.state.values&&this.state.values.length?s().createElement(X.Z,{size:"large",onClick:()=>this.exportData(),title:this.props.t("Save data as csv")},s().createElement(pt.FaDownload,null)):null,this.state.supportedFeatures.includes("insert")&&this.props.expertMode?s().createElement(X.Z,{size:"large",onClick:()=>{const t=new Date,a={ack:this.state.values[this.state.values.length-1].ack,val:this.state.values[this.state.values.length-1].val,ts:t,date:new Date(t),ms:0,time:new Date(t),q:0};this.setState({edit:a,insertOpened:!0})}},s().createElement(pt.FaPlusSquare,null)):null,this.state.supportedFeatures.includes("update")&&this.props.expertMode?s().createElement(X.Z,{size:"large",disabled:this.state.selected.length!==1,onClick:()=>{const t=JSON.parse(JSON.stringify(this.state.values.find(o=>o.ts===this.state.lastSelected))),a=new Date(t.ts);t.date=new Date(a),t.time=new Date(a),this.setState({edit:t,updateOpened:!0})}},s().createElement(Bs.default,null)):null,this.state.supportedFeatures.includes("delete")&&this.props.expertMode?s().createElement(X.Z,{size:"large",disabled:!this.state.selected.length,onClick:()=>{this.state.suppressMessage&&Date.now()-this.state.suppressMessage<3e5?this.onDelete():this.setState({areYouSure:!0})}},s().createElement(me.default,null)):null)}exportData(){let e=window.document.getElementById("export-file");e||(e=document.createElement("a"),e.setAttribute("id","export-file"),e.style.display="none",document.body.appendChild(e));let t=["timestamp;value;acknowledged;from;"];this.state.values.forEach(a=>!a.i&&!a.e&&t.push([new Date(a.ts).toISOString(),a.val===null||a.val===void 0?"null":a.val.toString(),a.ack?"true":"false",a.from||""].join(";"))),e.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t.join(`
|
|
307
|
+
`))),e.setAttribute("download",ct.default.getObjectName({[this.props.obj._id]:this.props.obj},this.props.obj._id,{language:this.props.lang})+".csv"),e.click(),document.body.removeChild(e)}render(){return this.state.historyInstances?s().createElement(M.Z,{className:this.props.classes.paper},this.state.loading?s().createElement(S.Z,null):s().createElement("div",{className:this.props.classes.noLoadingProgress}),this.renderToolbar(),s().createElement("div",{className:this.props.classes.tableDiv},this.renderTable()),this.renderConfirmDialog(),this.renderEditDialog()):s().createElement(S.Z,null)}}$t.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,obj:l().object,customsInstances:l().array,themeName:l().string,objects:l().object,isFloatComma:l().bool};var Xs=(0,R.default)()((0,G.withStyles)(Qs)($t)),Ae=h(67552),$s=h(56759),qs=h(41544),_s=h(32681),ea=h(92249),ta=h(18308),sa=h(99725),aa=h(55612),oa=h(13351),ia=h(66572),ra=h(27986),na="data:image/png;base64,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",x=h(4819),la=Object.defineProperty,qt=Object.getOwnPropertySymbols,ca=Object.prototype.hasOwnProperty,ha=Object.prototype.propertyIsEnumerable,Tt=(r,e,t)=>e in r?la(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,dt=(r,e)=>{for(var t in e||(e={}))ca.call(e,t)&&Tt(r,t,e[t]);if(qt)for(var t of qt(e))ha.call(e,t)&&Tt(r,t,e[t]);return r},_t=(r,e,t)=>(Tt(r,typeof e!="symbol"?e+"":e,t),t);qs.D([ta.N,sa.N,aa.N,oa.N,ia.N,ea.N,ra.N]);const pa={en:zt.Z,fr:Wt.Z,ru:Mt.Z,de:Yt.Z,es:Vt.Z,br:Ut.Z,nl:Gt.Z,it:Lt.Z,pt:Jt.Z,pl:Ht.Z,"zh-cn":Bt.Z};function da(r){return r<10?"00"+r:r<100?"0"+r:r}function fe(r){return r<10?"0"+r:r}const ma=r=>({paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden",width:"100%"},chart:{width:"100%",overflow:"hidden"},chartWithToolbar:{height:`calc(100% - ${r.mixins.toolbar.minHeight+parseInt(r.spacing(1),10)}px)`},chartWithoutToolbar:{height:"100%"},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:r.palette.primary.main},splitLineButtonIcon:{marginRight:r.spacing(1)},splitLineButton:{float:"right"},grow:{flexGrow:1},toolbarTime:{width:100,marginTop:9,marginLeft:r.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:r.spacing(1),paddingLeft:r.spacing(1),paddingRight:r.spacing(1),paddingTop:r.spacing(.5),paddingBottom:r.spacing(.5),border:"1px dotted #AAAAAA",borderRadius:r.spacing(1),display:"flex"},buttonIcon:{width:24,height:24},echartsButton:{marginRight:r.spacing(1),height:34,width:34},dateInput:{width:140,marginRight:r.spacing(1)},timeInput:{width:80}}),_=80,Te=25;class es extends C.Component{constructor(e){if(super(e),_t(this,"onResize",()=>{this.timerResize&&clearTimeout(this.timerResize),this.timerResize=setTimeout(()=>{this.timerResize=null,this.componentDidUpdate()})}),_t(this,"onChange",(i,n)=>{i===this.props.obj._id&&n&&this.rangeValues&&(!this.rangeValues.length||this.rangeValues[this.rangeValues.length-1].ts<n.ts)&&(!this.state.max||n.ts-this.state.max<12e4)&&(this.chartValues&&this.chartValues.push({val:n.val,ts:n.ts}),this.rangeValues.push({val:n.val,ts:n.ts}),n.ts>=this.chart.min&&n.ts<=this.chart.max+3e5&&this.updateChart())}),this.props.from)this.start=this.props.from;else{const i=new Date;i.setHours(i.getHours()-24*7),this.start=i.getTime()}this.props.end?this.end=this.props.end:this.end=Date.now();let t=(window._localStorage||window.localStorage).getItem("App.relativeRange")||"30",a=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteStart"),10)||0,o=parseInt((window._localStorage||window.localStorage).getItem("App.absoluteEnd"),10)||0;(!a||!o)&&(!t||t==="absolute")&&(t="30"),o&&a&&(t="absolute"),this.state={loaded:!1,historyInstance:this.props.historyInstance||"",historyInstances:null,defaultHistory:"",chartHeight:300,chartWidth:500,relativeRange:t,splitLine:(window._localStorage||window.localStorage).getItem("App.splitLine")==="true",dateFormat:"dd.MM.yyyy",min:a,max:o,maxYLen:0},this.echartsReact=(0,C.createRef)(),this.rangeRef=(0,C.createRef)(),this.readTimeout=null,this.chartValues=null,this.rangeValues=null,this.unit=this.props.obj.common&&this.props.obj.common.unit?" "+this.props.obj.common.unit:"",this.divRef=(0,C.createRef)(),this.chart={},this.onChange=this.onChange.bind(this),this.onResize=this.onResize.bind(this)}componentDidMount(){this.props.socket.subscribeState(this.props.obj._id,this.onChange),window.addEventListener("resize",this.onResize),this.prepareData().then(()=>!this.props.noToolbar&&this.readHistoryRange()).then(()=>this.setRelativeInterval(this.state.relativeRange,!0,()=>this.forceUpdate()))}componentWillUnmount(){this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=null,this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.maxYLenTimeout&&clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange),window.removeEventListener("resize",this.onResize)}prepareData(){let e;return this.props.noToolbar?new Promise(t=>this.setState({dateFormat:this.props.dateFormat.replace(/D/g,"d").replace(/Y/g,"y"),defaultHistory:this.props.defaultHistory,historyInstance:this.props.defaultHistory},()=>t())):this.getHistoryInstances().then(t=>(e=t,this.props.socket.getCompactSystemConfig())).then(t=>this.props.showJumpToEchart?this.props.socket.getAdapterInstances("echarts",!0).then(a=>{const o=!!a.find(c=>c._id.startsWith("system.adapter.echarts.")),i=t&&t.common&&t.common.defaultHistory;let n=(window._localStorage||window.localStorage).getItem("App.historyInstance")||"";(!n||!e.find(c=>c.id===n&&c.alive))&&(n=i),(!n||!e.find(c=>c.id===n&&c.alive))&&(n=e.find(c=>c.alive),n&&(n=n.id)),!n&&e.length&&(n=i),this.setState({dateFormat:(t.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y"),historyInstances:e,defaultHistory:i,historyInstance:n,echartsJump:o})}):Promise.resolve([]))}getHistoryInstances(){const e=[],t=[];return this.props.historyInstance?Promise.resolve(e):(this.props.customsInstances.forEach(a=>{const o=this.props.objects["system.adapter."+a];if(o&&o.common&&o.common.getHistory){let i={id:a,alive:!1};e.push(i),t.push(`system.adapter.${a}.alive`)}}),t.length?this.props.socket.getForeignStates(t).then(a=>(Object.keys(a).forEach(o=>{const i=e.find(n=>o.endsWith(n.id+".alive"));i&&(i.alive=a[o]&&a[o].val)}),e)):Promise.resolve(e))}readHistoryRange(){const e=new Date,t=new Date(2e3,0,1);return this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:t.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then(a=>{var o;a&&((o=a[0])==null?void 0:o.val)===null&&a.shift(),this.rangeValues=a})}readHistory(e,t){const a={instance:this.state.historyInstance,start:e,end:t,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none",returnNewestEntries:!0};return t-e>6e4*24&&!(this.props.obj.common.type==="boolean"||this.props.obj.common.type==="number"&&this.props.obj.common.states)&&(a.aggregate="minmax"),this.props.socket.getHistory(this.props.obj._id,a).then(o=>{let i=[],n=0,c=this.rangeValues,d=null,m=null;for(let f=0;f<o.length;f++){if(c)for(;n<c.length&&c[n].ts<o[f].ts;)i.push(c[n]),n++;!i.length||i[i.length-1].ts<o[f].ts?i.push(o[f]):i[i.length-1].ts===o[f].ts&&i[i.length-1].val!==o[f].ts&&console.error("Strange data!"),(d===null||o[f].val<d)&&(d=o[f].val),(m===null||o[f].val>m)&&(m=o[f].val)}if(c)for(;n<c.length;)i.push(c[n]),console.log(`add range ${new Date(c[n].ts).toISOString()}: ${c[n].val}`),n++;return i.sort((f,p)=>f.ts>p.ts?1:f.ts<p.ts?-1:0),this.chartValues=i,this.minY=d,this.maxY=m,this.minY<10?this.minY=Math.round(this.minY*10)/10:this.minY=Math.ceil(this.minY),this.maxY<10?this.maxY=Math.round(this.maxY*10)/10:this.maxY=Math.ceil(this.maxY),i})}convertData(e){e=e||this.chartValues;const t=[];if(!e.length)return t;for(let a=0;a<e.length;a++){const o={value:[e[a].ts,e[a].val]};e[a].i&&(o.exact=!1),t.push(o)}return this.chart.min||(this.chart.min=e[0].ts,this.chart.max=e[e.length-1].ts),t}getOption(){let e;if(this.minY!==null&&this.minY!==void 0&&(e=(this.minY.toString()+this.unit).length*9+12),this.maxY!==null&&this.maxY!==void 0){const i=(this.maxY.toString()+this.unit).length*9+12;i>e&&(e=i)}if(this.state.maxYLen){const i=this.state.maxYLen*9+12;i>e&&(e=i)}const t={xAxisIndex:0,type:"line",showSymbol:!1,hoverAnimation:!0,animation:!1,data:this.convertData(),lineStyle:{color:"#4dabf5"},areaStyle:{}},a={type:"value",boundaryGap:[0,"100%"],splitLine:{show:this.props.noToolbar||!!this.state.splitLine},splitNumber:Math.round(this.state.chartHeight/50),axisLabel:{formatter:(i,n)=>{let c;return this.props.isFloatComma?c=i.toString().replace(",",".")+this.unit:c=i+this.unit,this.state.maxYLen<c.length&&(this.maxYLenTimeout&&clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=setTimeout(d=>this.setState({maxYLen:d}),200,c.length)),c},showMaxLabel:!0,showMinLabel:!0},axisTick:{alignWithLabel:!0}};if(this.props.obj.common.type==="boolean")t.step="end",a.axisLabel.showMaxLabel=!1,a.axisLabel.formatter=i=>i===1?"TRUE":"FALSE",a.max=1.5,a.interval=1,e=50;else if(this.props.obj.common.type==="number"&&this.props.obj.common.states){t.step="end",a.axisLabel.showMaxLabel=!1,a.axisLabel.formatter=c=>this.props.obj.common.states[c]!==void 0?this.props.obj.common.states[c]:c;const i=Object.keys(this.props.obj.common.states);i.sort(),a.max=parseFloat(i[i.length-1])+.5,a.interval=1;let n="";for(let c=0;c<i.length;c++)typeof this.props.obj.common.states[i[c]]=="string"&&this.props.obj.common.states[i[c]].length>n.length&&(n=this.props.obj.common.states[i[c]]);e=(n.length*9||50)+12}const o=this.chart.withSeconds?Math.round((this.state.chartWidth-Te-_)/100):Math.round((this.state.chartWidth-Te-_)/60);return{backgroundColor:"transparent",title:{text:this.props.noToolbar?"":ct.default.getObjectNameFromObj(this.props.obj,this.props.lang),padding:[10,0,0,e?e+10:_+10]},grid:{left:e||_,top:8,right:this.props.noToolbar?5:Te,bottom:40},tooltip:{trigger:"axis",formatter:i=>{i=i[0];const n=new Date(i.value[0]);let c=i.value[1];return c!==null&&this.props.isFloatComma&&(c=c.toString().replace(".",",")),`${i.exact===!1?"i":""}${n.toLocaleString()}.${da(n.getMilliseconds())}: ${c}${this.unit}`},axisPointer:{animation:!0}},xAxis:{type:"time",splitLine:{show:!1},splitNumber:o,min:this.chart.min,max:this.chart.max,axisTick:{alignWithLabel:!0},axisLabel:{formatter:(i,n)=>{const c=new Date(i);return this.chart.withSeconds?`${fe(c.getHours())}:${fe(c.getMinutes())}:${fe(c.getSeconds())}`:this.chart.withTime?`${fe(c.getHours())}:${fe(c.getMinutes())}
|
|
308
308
|
${fe(c.getDate())}.${fe(c.getMonth()+1)}`:`${fe(c.getDate())}.${fe(c.getMonth()+1)}
|
|
309
|
-
${c.getFullYear()}`}}},yAxis:a,toolbox:{left:"right",feature:this.props.noToolbar?void 0:{saveAsImage:{title:this.props.t("Save as image"),show:!0}}},series:[t]}}static getDerivedStateFromProps(e,t){return null}updateChart(e,t,a,o){e&&(this.start=e),t&&(this.end=t),e=e||this.start,t=t||this.end,this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=setTimeout(()=>{this.readTimeout=null;const i=this.chart.max-this.chart.min;i!==this.chart.diff&&(this.chart.diff=i,this.chart.withTime=this.chart.diff<36e5*24*7,this.chart.withSeconds=this.chart.diff<6e4*30),a?this.readHistory(e,t).then(n=>{this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData(n)}],xAxis:{min:this.chart.min,max:this.chart.max}}),o&&o()}):(this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData()}],xAxis:{min:this.chart.min,max:this.chart.max}}),o&&o())},400)}setNewRange(e){this.chart.diff=this.chart.max-this.chart.min,this.chart.withTime=this.chart.diff<36e5*24*7,this.chart.withSeconds=this.chart.diff<6e4*30,this.state.relativeRange!=="absolute"?(this.setState({relativeRange:"absolute"}),this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null):this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&(this.echartsReact.getEchartsInstance().setOption({xAxis:{min:this.chart.min,max:this.chart.max}}),e&&this.updateChart(this.chart.min,this.chart.max,!0))}shiftTime(){const e=new Date,t=6e4-e.getSeconds()-(1e3-e.getMilliseconds());e.getMilliseconds()&&e.setMilliseconds(1e3),e.getSeconds()&&e.setSeconds(60);const a=e.getTime();let o,i=this.state.relativeRange;if(i==="day")e.setHours(0),e.setMinutes(0),e.setSeconds(0),o=e.getTime();else if(i==="week"){e.setHours(0),e.setMinutes(0),e.setSeconds(0);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else if(i==="2weeks"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(e.getDate()-7);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else i==="month"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),o=e.getTime()):i==="year"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),e.setMonth(0),o=e.getTime()):i==="12months"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setFullYear(e.getFullYear()-1),o=e.getTime()):(i=parseInt(i,10),o=a-i*6e4);this.chart.min=o,this.chart.max=a,this.setState({min:o,max:a},()=>this.updateChart(this.chart.min,this.chart.max,!0)),this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},t||6e4)}setRelativeInterval(e,t,a){if(t||((window._localStorage||window.localStorage).setItem("App.relativeRange",e),this.setState({relativeRange:e})),e==="absolute"){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.updateChart(this.chart.min,this.chart.max,!0,a);return}else(window._localStorage||window.localStorage).removeItem("App.absoluteStart"),(window._localStorage||window.localStorage).removeItem("App.absoluteEnd");const o=new Date;if(!this.timeTimer){const i=6e4-o.getSeconds()-(1e3-o.getMilliseconds());this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},i||6e4)}if(o.getMilliseconds()&&o.setMilliseconds(1e3),o.getSeconds()&&o.setSeconds(60),this.chart.max=o.getTime(),e==="day")o.setHours(0),o.setMinutes(0),o.setSeconds(0),this.chart.min=o.getTime();else if(e==="week"){o.setHours(0),o.setMinutes(0),o.setSeconds(0);const i=o.getDay()||7;i!==1&&o.setHours(-24*(i-1)),this.chart.min=o.getTime()}else if(e==="2weeks"){o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(o.getDate()-7);const i=o.getDay()||7;i!==1&&o.setHours(-24*(i-1)),this.chart.min=o.getTime()}else e==="month"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(1),this.chart.min=o.getTime()):e==="year"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(1),o.setMonth(0),this.chart.min=o.getTime()):e==="12months"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setFullYear(o.getFullYear()-1),this.chart.min=o.getTime()):(e=parseInt(e,10),this.chart.min=this.chart.max-e*6e4);this.setState({min:this.chart.min,max:this.chart.max},()=>this.updateChart(this.chart.min,this.chart.max,!0,a))}installEventHandlers(){if(!this.echartsReact||typeof this.echartsReact.getEchartsInstance!="function")return;const e=this.echartsReact.getEchartsInstance().getZr();e._iobInstalled||(e._iobInstalled=!0,e.on("mousedown",t=>{console.log("mouse down"),this.mouseDown=!0,this.chart.lastX=t.offsetX}),e.on("mouseup",()=>{console.log("mouse up"),this.mouseDown=!1,this.setNewRange(!0)}),e.on("mousewheel",t=>{let a=this.chart.max-this.chart.min;const o=this.state.chartWidth-De-_,n=(t.offsetX-_)/o,c=a,d=t.wheelDelta>0?1.1:.9;a=a*d;const m=c-a;this.chart.max+=m*(1-n),this.chart.min-=m*n,this.setNewRange()}),e.on("mousemove",t=>{if(this.mouseDown){const a=this.chart.lastX-(t.offsetX-_);this.chart.lastX=t.offsetX-_;const o=this.chart.max-this.chart.min,i=this.state.chartWidth-De-_,n=Math.round(a*o/i);this.chart.min+=n,this.chart.max+=n,this.setNewRange()}}),e.on("touchstart",t=>{t.preventDefault(),this.mouseDown=!0;const a=t.touches||t.originalEvent.touches;a&&(this.chart.lastX=a[a.length-1].pageX,a.length>1?this.chart.lastWidth=Math.abs(a[0].pageX-a[1].pageX):this.chart.lastWidth=null)}),e.on("touchend",t=>{t.preventDefault(),this.mouseDown=!1,this.setNewRange(!0)}),e.on("touchmove",t=>{t.preventDefault();const a=t.touches||t.originalEvent.touches;if(!a)return;const o=a[a.length-1].pageX-_;if(this.mouseDown)if(a.length>1){const i=Math.abs(a[0].pageX-a[1].pageX);if(this.chart.lastWidth!==null&&i!==this.chart.lastWidth){let n=this.chart.max-this.chart.min;const c=this.state.chartWidth-De-_,d=i>this.chart.lastWidth?1.1:.9,f=(a[0].pageX>a[1].pageX?a[1].pageX-_+i/2:a[0].pageX-_+i/2)/c,p=n;n=n*d;const j=p-n;this.chart.max+=j*(1-f),this.chart.min-=j*f,this.setNewRange()}this.chart.lastWidth=i}else{const i=this.chart.lastX-o,n=this.chart.max-this.chart.min,c=this.state.chartWidth-De-_,d=Math.round(i*n/c);this.chart.min+=d,this.chart.max+=d,this.setNewRange()}this.chart.lastX=o}))}renderChart(){return this.chartValues?x.createElement($s.Z,{ref:e=>this.echartsReact=e,echarts:_s,option:this.getOption(),notMerge:!0,lazyUpdate:!0,theme:this.props.themeType==="dark"?"dark":"",style:{height:this.state.chartHeight+"px",width:"100%"},opts:{renderer:"svg"},onEvents:{rendered:e=>{this.installEventHandlers()}}}):x.createElement(S.Z,null)}componentDidUpdate(){if(this.divRef.current){const e=this.divRef.current.offsetWidth,t=this.divRef.current.offsetHeight;this.state.chartHeight!==t&&setTimeout(()=>this.setState({chartHeight:t,chartWidth:e}),100)}}setStartDate(e){e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",e),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",this.state.max),this.chart.min=e,this.setState({min:e,relativeRange:"absolute"},()=>this.updateChart(this.chart.min,this.chart.max,!0))}setEndDate(e){e=e.getTime(),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",this.state.min),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.chart.max=e,this.setState({max:e,relativeRange:"absolute"},()=>this.updateChart(this.chart.min,this.chart.max,!0))}openEcharts(){const e=["id="+window.encodeURIComponent(this.props.obj._id),"instance="+window.encodeURIComponent(this.state.historyInstance),"menuOpened=false"];this.state.relativeRange==="absolute"?(e.push("start="+this.chart.min),e.push("end="+this.chart.max)):e.push("range="+this.state.relativeRange),window.open(`${window.location.protocol}//${window.location.host}/adapter/echarts/tab.html#${e.join("&")}`,"echarts")}renderToolbar(){if(this.props.noToolbar)return null;const e=this.props.classes;return x.createElement(Pt.Z,null,!this.props.historyInstance&&x.createElement(Oe.Z,{variant:"standard",className:e.selectHistoryControl},x.createElement(je.Z,null,this.props.t("History instance")),x.createElement(Ie.Z,{variant:"standard",value:this.state.historyInstance,onChange:t=>{(window._localStorage||window.localStorage).setItem("App.historyInstance",t.target.value),this.setState({historyInstance:t.target.value})}},this.state.historyInstances.map(t=>x.createElement(E.Z,{key:t.id,value:t.id,className:(0,V.default)(!t.alive&&e.notAliveInstance)},t.id)))),x.createElement(Oe.Z,{variant:"standard",className:e.selectRelativeTime},x.createElement(je.Z,null,this.props.t("Relative")),x.createElement(Ie.Z,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value)},x.createElement(E.Z,{key:"custom",value:"absolute",className:e.customRange},this.props.t("custom range")),x.createElement(E.Z,{key:"1",value:10},this.props.t("last 10 minutes")),x.createElement(E.Z,{key:"2",value:30},this.props.t("last 30 minutes")),x.createElement(E.Z,{key:"3",value:60},this.props.t("last hour")),x.createElement(E.Z,{key:"4",value:"day"},this.props.t("this day")),x.createElement(E.Z,{key:"5",value:24*60},this.props.t("last 24 hours")),x.createElement(E.Z,{key:"6",value:"week"},this.props.t("this week")),x.createElement(E.Z,{key:"7",value:24*60*7},this.props.t("last week")),x.createElement(E.Z,{key:"8",value:"2weeks"},this.props.t("this 2 weeks")),x.createElement(E.Z,{key:"9",value:24*60*14},this.props.t("last 2 weeks")),x.createElement(E.Z,{key:"10",value:"month"},this.props.t("this month")),x.createElement(E.Z,{key:"11",value:30*24*60},this.props.t("last 30 days")),x.createElement(E.Z,{key:"12",value:"year"},this.props.t("this year")),x.createElement(E.Z,{key:"13",value:"12months"},this.props.t("last 12 months")))),x.createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:pa[this.props.lang]},x.createElement("div",{className:e.toolbarTimeGrid},x.createElement(et.M,{className:e.toolbarDate,disabled:this.state.relativeRange!=="absolute",disableToolbar:!0,variant:"inline",margin:"normal",inputFormat:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.min),onChange:t=>this.setStartDate(t),renderInput:t=>x.createElement(T.Z,dt({className:this.props.classes.dateInput,variant:"standard"},t))}),x.createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.min),onChange:t=>this.setStartDate(t),renderInput:t=>x.createElement(T.Z,dt({className:this.props.classes.timeInput,variant:"standard"},t))})),x.createElement("div",{className:e.toolbarTimeGrid},x.createElement(et.M,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarDate,disableToolbar:!0,inputFormat:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.max),onChange:t=>this.setEndDate(t),renderInput:t=>x.createElement(T.Z,dt({className:this.props.classes.dateInput,variant:"standard"},t))}),x.createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.max),onChange:t=>this.setEndDate(t),renderInput:t=>x.createElement(T.Z,dt({className:this.props.classes.timeInput,variant:"standard"},t))}))),x.createElement("div",{className:e.grow}),this.props.showJumpToEchart&&this.state.echartsJump&&x.createElement(Ae.Z,{className:e.echartsButton,size:"small",onClick:()=>this.openEcharts(),title:this.props.t("Open charts in new window")},x.createElement("img",{src:na,alt:"echarts",className:e.buttonIcon})),x.createElement(Ae.Z,{variant:"extended",size:"small",color:this.state.splitLine?"primary":"inherit","aria-label":"show lines",onClick:()=>{(window._localStorage||window.localStorage).setItem("App.splitLine",this.state.splitLine?"false":"true"),this.setState({splitLine:!this.state.splitLine})},className:e.splitLineButton},x.createElement(pt.FaChartLine,{className:e.splitLineButtonIcon}),this.props.t("Show lines")))}render(){return!this.state.historyInstances&&!this.state.defaultHistory?x.createElement(S.Z,null):x.createElement(M.Z,{className:this.props.classes.paper},this.renderToolbar(),x.createElement("div",{ref:this.divRef,className:(0,V.default)(this.props.classes.chart,this.props.noToolbar?this.props.classes.chartWithoutToolbar:this.props.classes.chartWithToolbar)},this.renderChart()))}}es.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,obj:l().object,customsInstances:l().array,themeType:l().string,objects:l().object,from:l().number,end:l().number,noToolbar:l().bool,defaultHistory:l().string,historyInstance:l().string,showJumpToEchart:l().bool,isFloatComma:l().bool};var ts=(0,R.default)()((0,G.withStyles)(ma)(es)),ss=h(86695);const ua=r=>({dialog:{height:"100%"},paper:{height:"calc(100% - 64px)"},content:{textAlign:"center",overflow:"hidden"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+r.mixins.toolbar.minHeight+"px)"},tabSelected:{color:r.palette.mode==="dark"?r.palette.secondary.contrastText:"#FFFFFF !important"},tabsIndicator:{backgroundColor:r.palette.secondary.main}}),Oo={images:["png","jpg","svg","jpeg"],code:["js","json"],txt:["log","txt","html","css","xml"]};class as extends ss.Z{constructor(e){super(e);let t=parseInt((window._localStorage||window.localStorage).getItem("App.objectCustomTab")||0,10);if(this.chartAvailable=this.isChartAvailable(),this.chartAvailable){const a=pe.Z.getLocation();a.arg==="chart"?t=2:a.arg==="table"&&(t=1)}else t=0;this.state={hasChanges:!1,currentTab:t,confirmDialog:!1,mobile:ss.Z.isMobile(),progressRunning:!1},this.saveFunc=null}isChartAvailable(){let e=this.props.objectIDs.length===1;if(e){const t=this.props.objectIDs[0];this.props.objects[t]&&this.props.objects[t].common&&this.props.objects[t].common.custom&&this.props.objects[t].common.custom?e=Object.keys(this.props.objects[t].common.custom).find(a=>{const o=this.props.objects["system.adapter."+a];return o&&o.common&&o.common.getHistory}):e=!1}return e}renderCharts(){return s().createElement(ts,{id:"chart-tabpanel",isFloatComma:this.props.isFloatComma,showJumpToEchart:!0,t:this.props.t,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,obj:this.props.objects[this.props.objectIDs[0]],customsInstances:this.props.customsInstances,themeType:this.props.themeType,objects:this.props.objects})}renderTable(){return s().createElement(Xs,{id:"table-tabpanel",t:this.props.t,isFloatComma:this.props.isFloatComma,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,obj:this.props.objects[this.props.objectIDs[0]],customsInstances:this.props.customsInstances,themeName:this.props.themeName,objects:this.props.objects})}renderCustomEditor(){return s().createElement(Fs,{id:"custom-settings-tabpanel",registerSaveFunc:e=>this.saveFunc=e,t:this.props.t,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,objectIDs:this.props.objectIDs,customsInstances:this.props.customsInstances,objects:this.props.objects,onProgress:e=>this.setState({progressRunning:e}),reportChangedIds:this.props.reportChangedIds,onChange:(e,t)=>{this.setState({hasChanges:e},()=>{if(t){const a=this.isChartAvailable();a!==this.chartAvailable&&(this.chartAvailable=a,this.forceUpdate())}})},theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType})}renderConfirmDialog(){return this.state.confirmDialog?s().createElement(le.default,{title:P.default.t("You have unsaved changes"),text:P.default.t("Discard?"),ok:P.default.t("Yes"),cancel:P.default.t("Cancel"),onClose:e=>this.setState({confirmDialog:!1},()=>e&&this.props.onClose())}):null}onClose(){this.state.hasChanges?this.setState({confirmDialog:!0}):this.props.onClose()}render(){var e,t;const a=(t=(e=this.props.objects[this.props.objectIDs[0]])==null?void 0:e.common)==null?void 0:t.type;return s().createElement(te.Z,{classes:{scrollPaper:this.props.classes.dialog,paper:this.props.classes.paper},scroll:"paper",open:!0,onClose:()=>this.props.onClose(),fullWidth:!0,maxWidth:"xl","aria-labelledby":"form-dialog-title"},this.renderConfirmDialog(),s().createElement(K.Z,null,this.props.objectIDs.length>1?this.props.t("Edit config for %s states",this.props.objectIDs.length):this.props.t("Edit config: %s",this.props.objectIDs[0])),s().createElement(oe.Z,{className:this.props.classes.content},s().createElement(Se.Z,{position:"static"},s().createElement(He.Z,{value:this.state.currentTab,onChange:(o,i)=>{pe.Z.doNavigate(null,null,null,i===1?"table":i===2?"chart":"config"),this.setState({currentTab:i}),(window._localStorage||window.localStorage).setItem("App.objectCustomTab",i)},classes:{indicator:this.props.classes.tabsIndicator},indicatorColor:"secondary"},s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("Custom settings"),id:"custom-settings-tab","aria-controls":"simple-tabpanel-0",classes:{selected:this.props.classes.tabSelected}}),this.props.objectIDs.length===1&&this.chartAvailable?s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("History data"),id:"history-data-tab","aria-controls":"simple-tabpanel-1",classes:{selected:this.props.classes.tabSelected}}):null,(a==="number"||a==="boolean")&&this.props.objectIDs.length===1&&this.chartAvailable?s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("Chart"),id:"chart-tab","aria-controls":"simple-tabpanel-2",classes:{selected:this.props.classes.tabSelected}}):null)),this.state.currentTab===0?s().createElement("div",{className:this.props.classes.tabPanel},this.renderCustomEditor()):null,this.props.objectIDs.length===1&&this.chartAvailable&&this.state.currentTab===1?s().createElement("div",{className:this.props.classes.tabPanel},this.renderTable()):null,(a==="number"||a==="boolean")&&this.props.objectIDs.length===1&&this.chartAvailable&&this.state.currentTab===2?s().createElement("div",{className:this.props.classes.tabPanel},this.renderCharts()):null),s().createElement(L.Z,null,this.state.currentTab===0&&s().createElement(Z.Z,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>this.saveFunc&&this.saveFunc()},this.getButtonTitle(s().createElement(ie.default,null),this.props.t("Save"))),this.state.currentTab===0&&s().createElement(Z.Z,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>{this.saveFunc?this.saveFunc(o=>!o&&this.onClose()):this.onClose()}},this.getButtonTitle(s().createElement(ie.default,null),this.props.t("Save & close"),s().createElement(J.default,null))),s().createElement(Z.Z,{disabled:this.state.progressRunning,variant:"contained",onClick:()=>this.onClose(),color:"grey"},this.getButtonTitle(s().createElement(J.default,null),this.props.t("Close")))))}}as.propTypes={t:l().func,lang:l().string,expertMode:l().bool,objects:l().object,socket:l().object,theme:l().object,themeName:l().string,themeType:l().string,customsInstances:l().array,objectIDs:l().array,onClose:l().func,reportChangedIds:l().func,isFloatComma:l().bool};var fa=(0,G.withStyles)(ua)(as),ga=h(83732),os=h.n(ga),Io=h(72921),Ao=h(14091),Do=h(15120),No=h(68716),To=h(24317),va=h(54566),ba=h(21233),is=h(95697),ya=h(13423),Nt=h(26021),Ea=h(53736),wa=h(94315),Ca=Object.defineProperty,Sa=Object.defineProperties,xa=Object.getOwnPropertyDescriptors,rs=Object.getOwnPropertySymbols,ja=Object.prototype.hasOwnProperty,Oa=Object.prototype.propertyIsEnumerable,ns=(r,e,t)=>e in r?Ca(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ia=(r,e)=>{for(var t in e||(e={}))ja.call(e,t)&&ns(r,t,e[t]);if(rs)for(var t of rs(e))Oa.call(e,t)&&ns(r,t,e[t]);return r},Aa=(r,e)=>Sa(r,xa(e));const Da=r=>({input:{width:"100%"},textInput:{width:"100%"},formControl:{minWidth:150},quality:{width:"calc(100% - 88px)"},expire:{marginLeft:8,width:80},jsonError:{border:"1px solid red",minHeight:200},jsonNoError:{border:"1px solid #00000000",minHeight:200},wrapperButton:{},readOnly:{backgroundColor:"#b74848"},readOnlyText:{color:"#b74848"},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:12}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:11}}},ackCheckbox:{marginLeft:4},dialog:{minHeight:window.clientHeight-50>500?500:window.clientHeight-50}}),Na=(0,G.withStyles)(r=>({root:{width:28,height:16,padding:0,display:"flex"},switchBase:{padding:2,color:r.palette.grey[500],"&$checked":{transform:"translateX(12px)",color:r.palette.common.white,"& + $track":{opacity:1,backgroundColor:r.palette.primary.main,borderColor:r.palette.primary.main}}},thumb:{width:12,height:12,boxShadow:"none"},track:{border:`1px solid ${r.palette.grey[500]}`,borderRadius:16/2,opacity:1,backgroundColor:r.palette.common.white},checked:{}}))(ba.Z);class ls extends C.Component{constructor(e){super(e);let t=this.props.type||typeof this.props.value;if(this.value=this.props.value,this.propsValue=this.value,this.propsValue===null?this.propsValue="null":this.propsValue===void 0&&(this.propsValue="undefined"),this.props.states)t="states";else if(t==="string"||t==="json"){if(this.value&&typeof this.value=="string"&&(this.value.startsWith("[")&&this.value.endsWith("]")||this.value.startsWith("{")&&this.value.endsWith("}")))try{this.value=JSON.parse(this.value),this.value=JSON.stringify(this.value,null,2),this.propsValue=this.value,t="json"}catch(a){}}else t==="number"&&(this.value=parseFloat(this.propsValue)||0);this.state={type:t,chart:!1,chartEnabled:(window._localStorage||window.localStorage).getItem("App.chartSetValue")!=="false",fullScreen:(window._localStorage||window.localStorage).getItem("App.fullScreen")==="true"},this.ack=!1,this.q=0,this.expire=0,this.inputRef=s().createRef(),this.chartFrom=Date.now()-36e5*2}componentDidMount(){var e,t,a;this.props.defaultHistory&&((t=(e=this.props.object)==null?void 0:e.common)==null?void 0:t.custom)&&((a=this.props.object.common.custom[this.props.defaultHistory])==null?void 0:a.enabled)&&this.props.socket.getState("system.adapter."+this.props.defaultHistory+".alive").then(o=>this.setState({chart:o&&!!o.val})),setTimeout(()=>{if(this.inputRef&&this.inputRef.current){const o=this.inputRef.current,i=o.value||"";o.setSelectionRange(0,i.length)}},200)}onUpdate(e){e&&e.stopPropagation(),e&&e.preventDefault();let t=this.value;if(this.state.type==="states")if(t==="null")t=null;else{let a=this.props.type||typeof this.props.value;t=typeof t=="object"?t.value:t,a==="number"?typeof t=="string"&&(t=parseFloat(t.replace(",","."))||0):a==="boolean"&&(t=t===!0||t==="true"||t==="1"||t==="ON"||t==="on")}else this.state.type==="number"?t==="null"?t=null:typeof t=="string"&&(t=parseFloat(t.replace(",","."))||0):this.state.type==="boolean"&&(t==="null"?t=null:t=t===!0||t==="true"||t==="1"||t==="ON"||t==="on");this.props.onClose({val:t,ack:this.ack,q:this.q,expire:parseInt(this.expire,10)||void 0})}renderChart(){return s().createElement(ts,{t:this.props.t,isFloatComma:this.props.isFloatComma,showJumpToEchart:!1,lang:this.props.lang,socket:this.props.socket,obj:this.props.object,themeType:this.props.themeType,from:this.chartFrom,end:Date.now(),noToolbar:!0,dateFormat:this.props.dateFormat,defaultHistory:this.props.defaultHistory})}checkJsonError(){try{JSON.parse(this.value),this.setState({jsonError:!1})}catch(e){this.setState({jsonError:!0})}}renderJsonEditor(){return s().createElement(os(),{className:this.state.jsonError?this.props.classes.jsonError:this.props.classes.jsonNoError,mode:"json",width:"100%",height:"100%",showPrintMargin:!0,showGutter:!0,highlightActiveLine:!0,theme:this.props.themeType==="dark"?"clouds_midnight":"chrome",defaultValue:(this.propsValue||"").toString(),onChange:e=>{this.value=e,this.checkJsonError()},name:"UNIQUE_ID_OF_DIV1",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:!0,tabSize:2},editorProps:{$blockScrolling:!0}})}renderStates(){if(this.props.states)if(this.props.type==="number"&&this.props.object.common.max!==void 0&&this.props.object.common.min!==void 0){const e=Object.keys(this.props.states).map(t=>({label:this.props.states[t],value:t}));return s().createElement(is.Z,{className:this.props.classes.formControl,disablePortal:!0,defaultValue:this.props.states[this.propsValue]!==void 0?this.props.states[this.propsValue]:this.propsValue,options:e,noOptionsText:"",freeSolo:!0,getOptionLabel:t=>t.label||(t!=null?t.toString():""),onChange:(t,a)=>this.value=a,onInputChange:(t,a)=>this.value=a,onKeyUp:t=>t.keyCode===13&&this.onUpdate(t),renderInput:t=>s().createElement(T.Z,Aa(Ia({},t),{label:this.props.t("Value"),variant:"standard"}))})}else return s().createElement(Oe.Z,{variant:"standard",className:this.props.classes.formControl},s().createElement(je.Z,null,this.props.t("Value")),s().createElement(Ie.Z,{variant:"standard",defaultValue:this.propsValue,onChange:e=>this.value=e.target.value},Object.keys(this.props.states).map((e,t)=>s().createElement(E.Z,{key:t,value:e},this.props.states[e]))));else return null}render(){var e,t;const a=s().createElement(k.Z,{className:ct.default.clsx(this.props.classes.formControl,this.props.expertMode?"":this.props.classes.ackCheckbox),control:s().createElement(N.Z,{defaultChecked:!1,onChange:o=>this.ack=o.target.checked}),label:this.props.t("Acknowledged")});return s().createElement(te.Z,{open:!0,maxWidth:this.state.type==="number"||this.state.type==="boolean"||this.state.type==="states"?this.state.chart&&this.state.chartEnabled?"lg":null:"md",fullWidth:this.state.type==="json"&&this.state.fullScreen||this.state.type!=="number"&&this.state.type!=="boolean"&&this.state.type!=="states"||this.state.chart&&this.state.chartEnabled,fullScreen:this.state.type==="json"&&this.state.fullScreen,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",classes:{root:this.state.type==="json"?this.props.classes.dialog:""}},s().createElement(K.Z,{id:"edit-value-dialog-title"},this.props.t("Write value"),((e=this.props.object.common)==null?void 0:e.write)===!1?s().createElement("span",{className:this.props.classes.readOnlyText},"(",this.props.t("read only"),")"):null,this.state.chart?s().createElement(Ae.Z,{style:{float:"right"},size:"small",color:this.state.chartEnabled?"primary":"default",onClick:()=>{(window._localStorage||window.localStorage).setItem("App.chartSetValue",this.state.chartEnabled?"false":"true"),this.setState({chartEnabled:!this.state.chartEnabled})}},s().createElement(ya.default,null)):null,this.state.type==="json"?s().createElement(X.Z,{style:{float:"right"},onClick:()=>{(window._localStorage||window.localStorage).setItem("App.fullScreen",this.state.fullScreen?"false":"true"),this.setState({fullScreen:!this.state.fullScreen})}},this.state.fullScreen?s().createElement(wa.Z,null):s().createElement(Ea.Z,null)):null),s().createElement(oe.Z,null,s().createElement("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",onSubmit:()=>!1,style:{height:"100%"}},s().createElement(W.ZP,{container:!0,direction:"row",spacing:2,style:{height:"100%"}},s().createElement(W.ZP,{item:!0,xs:this.state.chart&&this.state.chartEnabled?6:12,style:{height:"100%"}},s().createElement(W.ZP,{container:!0,direction:"column",spacing:2,style:{marginTop:0,height:"100%"}},this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(W.ZP,{container:!0,direction:"row",spacing:2,style:{marginTop:0}},this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(Oe.Z,{className:this.props.classes.formControl},s().createElement(je.Z,null,this.props.t("Value type")),s().createElement(Ie.Z,{variant:"standard",value:this.state.type,onChange:o=>{o.target.value==="json"&&(this.value=(this.value||"").toString(),this.checkJsonError()),this.setState({type:o.target.value})}},s().createElement(E.Z,{value:"string"},"String"),s().createElement(E.Z,{value:"number"},"Number"),s().createElement(E.Z,{value:"boolean"},"Boolean"),s().createElement(E.Z,{value:"json"},"JSON"),this.props.states?s().createElement(E.Z,{value:"states"},"States"):null))):null,this.state.type==="json"?s().createElement(W.ZP,{item:!0,flex:1}):null)):null,s().createElement(W.ZP,{item:!0,flex:this.state.type==="json"&&this.state.fullScreen?1:void 0,style:{paddingTop:0}},this.state.type==="boolean"?s().createElement(I.Z,{component:"div"},s().createElement(W.ZP,{component:"label",container:!0,alignItems:"center",spacing:1},s().createElement(W.ZP,{item:!0,style:{marginRight:10}},this.props.t("Value"),":"),s().createElement(W.ZP,{item:!0},"FALSE"),s().createElement(W.ZP,{item:!0},s().createElement(Na,{autoFocus:!0,defaultChecked:!!this.propsValue,onKeyUp:o=>o.keyCode===13&&this.onUpdate(o),onChange:o=>this.value=o.target.checked})),s().createElement(W.ZP,{item:!0},"TRUE"))):this.state.type==="number"?s().createElement(T.Z,{variant:"standard",classes:{root:this.props.classes.textInput},autoFocus:!0,inputRef:this.inputRef,helperText:this.props.t("Press ENTER to write the value, when focused"),label:this.props.t("Value"),defaultValue:parseFloat(this.propsValue)||0,onKeyUp:o=>{o.keyCode===13&&this.onUpdate(o)},onChange:o=>this.value=o.target.value}):this.state.type==="json"?this.renderJsonEditor():this.state.type==="states"?this.renderStates():s().createElement(T.Z,{variant:"standard",classes:{root:this.props.classes.textInput},inputRef:this.inputRef,autoFocus:!0,helperText:this.props.t("Press CTRL+ENTER to write the value, when focused"),label:this.props.t("Value"),fullWidth:!0,multiline:!0,onKeyDown:o=>o.ctrlKey&&o.keyCode===13&&this.onUpdate(o),defaultValue:this.propsValue.toString(),onChange:o=>this.value=o.target.value})),this.props.expertMode?s().createElement(W.ZP,{item:!0},a):null,this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(Oe.Z,{variant:"standard",className:this.props.classes.quality},s().createElement(je.Z,null,this.props.t("Quality")),s().createElement(Ie.Z,{variant:"standard",defaultValue:0,onChange:o=>this.q=parseInt(o.target.value,10)},s().createElement(E.Z,{value:0},"0x00 - good"),s().createElement(E.Z,{value:1},"0x01 - general problem"),s().createElement(E.Z,{value:2},"0x02 - no connection problem"),s().createElement(E.Z,{value:16},"0x10 - substitute value from controller"),s().createElement(E.Z,{value:32},"0x20 - substitute initial value"),s().createElement(E.Z,{value:64},"0x40 - substitute value from device or instance"),s().createElement(E.Z,{value:128},"0x80 - substitute value from sensor"),s().createElement(E.Z,{value:17},"0x11 - general problem by instance"),s().createElement(E.Z,{value:65},"0x41 - general problem by device"),s().createElement(E.Z,{value:129},"0x81 - general problem by sensor"),s().createElement(E.Z,{value:18},"0x12 - instance not connected"),s().createElement(E.Z,{value:66},"0x42 - device not connected"),s().createElement(E.Z,{value:130},"0x82 - sensor not connected"),s().createElement(E.Z,{value:68},"0x44 - device reports error"),s().createElement(E.Z,{value:132},"0x84 - sensor reports error"))),s().createElement(T.Z,{variant:"standard",title:this.props.t("0 - no expiration"),classes:{root:this.props.classes.expire},label:this.props.t("Expire"),type:"number",inputProps:{min:0},helperText:this.props.t("in seconds"),defaultValue:this.expire,onChange:o=>this.expire=o.target.value})):null)),this.state.chart&&this.state.chartEnabled&&this.state.type!=="json"?s().createElement(va.Z,{only:["sm","xs"]},s().createElement(W.ZP,{item:!0,xs:6,style:{minHeight:300}},this.renderChart())):null))),s().createElement(L.Z,{className:this.props.classes.wrapperButton},this.props.expertMode?null:a,this.props.expertMode?null:s().createElement("div",{style:{flexGrow:1}}),s().createElement(Z.Z,{variant:"contained",onClick:o=>this.onUpdate(o),color:"primary",startIcon:s().createElement(Nt.default,null),className:((t=this.props.object.common)==null?void 0:t.write)===!1?this.props.classes.readOnly:""},this.props.t("Set value")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}ls.propTypes={classes:l().object,type:l().string,states:l().object,value:l().any,expertMode:l().bool,onClose:l().func.isRequired,themeType:l().string,socket:l().object,defaultHistory:l().string,dateFormat:l().string,object:l().object,isFloatComma:l().bool,t:l().func,lang:l().string};var Ta=(0,G.withStyles)(Da)(ls),Ne=h(27254),Za=h(17773),cs=h(64143),hs=h(78569),Ra=h(98735),Fa=h(23962),ka=h.n(Fa),F=h(94427),Pa=h(94437),Wa=Object.defineProperty,Ma=Object.defineProperties,za=Object.getOwnPropertyDescriptors,ps=Object.getOwnPropertySymbols,Va=Object.prototype.hasOwnProperty,Ha=Object.prototype.propertyIsEnumerable,ds=(r,e,t)=>e in r?Wa(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ja=(r,e)=>{for(var t in e||(e={}))Va.call(e,t)&&ds(r,t,e[t]);if(ps)for(var t of ps(e))Ha.call(e,t)&&ds(r,t,e[t]);return r},La=(r,e)=>Ma(r,za(e));const Ba=r=>({divWithoutTitle:{width:"100%",height:"100%",border:"2px solid #00000000"},divWithoutTitleAndTab:{height:"calc(100% - 48px)"},error:{border:"2px solid #FF0000"},id:{fontStyle:"italic"},dialog:{height:"calc(100% - 64px)"},aliasIdEdit:{width:400-32},button:{marginTop:20,marginLeft:r.spacing(1)},funcDivEdit:{width:"100%"},funcEditName:{display:"inline-block",width:85},funcEdit:{width:400},funcIcon:{width:16,height:16},marginTop:{marginTop:20},commonTabWrapper:{flexFlow:"wrap",display:"flex"},commonWrapper:{width:500,minWidth:300},flexDrop:{width:"100%",maxWidth:500,margin:"auto",display:"flex"},marginBlock:{marginTop:20},buttonAdd:{minWidth:150},textField:{width:"100%"},flex:{display:"flex","& > div":{marginRight:r.spacing(1)}},close:{width:"20px",height:"20px",opacity:"0.9",cursor:"pointer",position:"relative",top:20,transition:"all 0.6s ease","&:hover":{transform:"rotate(90deg)"},"&:before":{position:"absolute",left:"9px",content:'""',height:"20px",width:"3px",backgroundColor:"#ff4f4f",transform:"rotate(45deg)"},"&:after":{position:"absolute",left:"9px",content:'""',height:"20px",width:"3px",backgroundColor:"#ff4f4f",transform:"rotate(-45deg)"}},color:{width:70},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},tabsPadding:{padding:"0px 24px"},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:10}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:9}}}});class ms extends C.Component{constructor(e){var t,a,o,i;super(e);const n=this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state";let c=(window._localStorage||window.localStorage).getItem((this.props.dialogName||"App")+".editTab")||"object";c==="alias"&&!n&&(c="common"),this.state={text:JSON.stringify(this.props.obj,null,2),error:!1,changed:!1,readError:this.checkFunction((a=(t=this.props.obj.common)==null?void 0:t.alias)==null?void 0:a.read,!1),writeError:this.checkFunction((i=(o=this.props.obj.common)==null?void 0:o.alias)==null?void 0:i.write,!0),tab:c,showCopyDialog:!1},this.isMobile=window.innerWidth<850,this.originalObj=JSON.stringify(this.props.obj,null,2)}checkFunction(e,t){var a,o,i,n,c;if(e){if(e.includes("JSON.parse("))return"";{let d;try{d=JSON.parse(this.state.text)}catch(f){}let m;try{m=new Function("val",e.includes("return")?e:"return "+e)}catch(f){return this.props.t("Cannot parse code!")}if(((a=d==null?void 0:d.common)==null?void 0:a.type)&&((c=(n=this.props.objects[(i=(o=d.common)==null?void 0:o.alias)==null?void 0:i.id])==null?void 0:n.common)==null?void 0:c.type)){const f=t?d.common.type:this.props.objects[d.common.alias.id].common.type,p=t?this.props.objects[d.common.alias.id].common.type:d.common.type;if(f&&p){let j=null;if(f==="boolean"?j=!0:f==="number"?j=1:f==="string"&&(j="string"),j!==null)try{const A=m(j);return A!==null&&typeof A!==p?this.props.t("Type of result is not as expected: %s",p):""}catch(A){return this.props.t("Cannot execute function")+": "+A.toString()}}}return""}}else return""}prepareObject(e){var t,a,o,i;e=e||this.state.text;try{const n=JSON.parse(e);return n._id=this.props.obj._id,(t=n.common)!=null&&t.alias&&(n.common.alias.id||delete n.common.alias.id,(!n.common.alias.read&&n.common.alias.read!==void 0||n.common.alias.read==="val")&&delete n.common.alias.read,(!n.common.alias.write&&n.common.alias.write!==void 0||n.common.alias.write==="val")&&delete n.common.alias.write,!n.common.alias.id&&!n.common.alias.read&&!n.common.alias.write&&delete n.common.alias),((a=n.common)==null?void 0:a.min)!==void 0&&typeof n.common.min!="number"&&(n.common.min=parseFloat(n.common.min)),((o=n.common)==null?void 0:o.max)!==void 0&&typeof n.common.max!="number"&&(n.common.max=parseFloat(n.common.max)),((i=n.common)==null?void 0:i.step)!==void 0&&typeof n.common.step!="number"&&(n.common.step=parseFloat(n.common.step)),n}catch(n){return null}}onChange(e,t){var a,o,i,n;const c=this.prepareObject(e),d={text:e};c?(d.changed=this.originalObj!==JSON.stringify(c,null,2),this.state.error&&(d.error=!1),d.readError=this.checkFunction((o=(a=c.common)==null?void 0:a.alias)==null?void 0:o.read,!1),d.writeError=this.checkFunction((n=(i=c.common)==null?void 0:i.alias)==null?void 0:n.write,!0)):d.error=!0,this.setState(d,()=>t&&t())}onUpdate(){var e,t,a,o;try{const i=JSON.parse(this.state.text);i._id=this.props.obj._id,(e=i.common)!=null&&e.alias&&(i.common.alias.id||delete i.common.alias.id,(!i.common.alias.read&&i.common.alias.read!==void 0||i.common.alias.read==="val")&&delete i.common.alias.read,(!i.common.alias.write&&i.common.alias.write!==void 0||i.common.alias.write==="val")&&delete i.common.alias.write,!i.common.alias.id&&!i.common.alias.read&&!i.common.alias.write&&delete i.common.alias),((t=i.common)==null?void 0:t.min)!==void 0&&typeof i.common.min!="number"&&(i.common.min=parseFloat(i.common.min)),((a=i.common)==null?void 0:a.max)!==void 0&&typeof i.common.max!="number"&&(i.common.max=parseFloat(i.common.max)),((o=i.common)==null?void 0:o.step)!==void 0&&typeof i.common.step!="number"&&(i.common.step=parseFloat(i.common.step)),this.props.onClose(i)}catch(i){console.log.error(`Cannot parse: ${this.state.text}`)}}renderTabs(){return s().createElement(He.Z,{className:this.props.classes.tabsPadding,value:this.state.tab,onChange:(e,t)=>{var a,o,i;if((window._localStorage||window.localStorage).setItem((this.props.dialogName||"App")+".editTab",t),t==="object")try{const n=JSON.parse(this.state.text);let c=!1;((a=n.common)==null?void 0:a.min)!==void 0&&typeof n.common.min!="number"&&(n.common.min=parseFloat(n.common.min),c=!0),((o=n.common)==null?void 0:o.max)!==void 0&&typeof n.common.max!="number"&&(n.common.max=parseFloat(n.common.max),c=!0),((i=n.common)==null?void 0:i.step)!==void 0&&typeof n.common.step!="number"&&(n.common.step=parseFloat(n.common.step),c=!0),c&&this.setState({text:JSON.stringify(n,null,2)})}catch(n){}this.setState({tab:t})}},s().createElement(he.Z,{value:"common",label:this.props.t("Common")}),s().createElement(he.Z,{value:"object",label:this.props.t("Object data")}),this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state"&&s().createElement(he.Z,{value:"alias",label:this.props.t("Alias")}))}renderSelectDialog(){var e,t,a,o,i,n,c,d;if(!this.state.selectId&&!this.state.selectRead&&!this.state.selectWrite)return null;let m="",f;try{f=JSON.parse(this.state.text),this.state.selectId?m=((t=(e=f.common)==null?void 0:e.alias)==null?void 0:t.id)||"":this.state.selectRead?m=((i=(o=(a=f.common)==null?void 0:a.alias)==null?void 0:o.id)==null?void 0:i.read)||"":this.state.selectWrite&&(m=((d=(c=(n=f.common)==null?void 0:n.alias)==null?void 0:c.id)==null?void 0:d.write)||"")}catch(p){console.error("Cannot parse "+this.state.text)}return s().createElement(Ra.default,{key:"selectDialog",imagePrefix:".",dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,socket:this.props.socket,dialogName:"aliasesEdit",title:`${this.props.t("Select for")} ${this.props.obj._id}`,selected:m,statesOnly:!0,onOk:p=>{const j=this.state.selectRead,A=this.state.selectWrite,ne=this.state.selectId;this.setState({selectId:!1,selectRead:!1,selectWrite:!1},()=>{j?this.setAliasItem(f,"id.read",p):A?this.setAliasItem(f,"id.write",p):ne&&this.setAliasItem(f,"id",p)})},onClose:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!1})})}setAliasItem(e,t,a,o){e.common=e.common||{},e.common.alias=e.common.alias||{},t==="id.read"?e.common.alias.id&&typeof e.common.alias.id=="object"?e.common.alias.id.read=a:e.common.alias.id={read:a,write:a}:t==="id.write"?e.common.alias.id&&typeof e.common.alias.id=="object"?e.common.alias.id.write=a:e.common.alias.id={read:a,write:a}:e.common.alias[t]=a,this.onChange(JSON.stringify(e,null,2),o)}setCommonItem(e,t,a){e.common[t]=a,this.onChange(JSON.stringify(e,null,2))}removeCommonItem(e,t){delete e.common[t],this.onChange(JSON.stringify(e,null,2))}buttonAddKey(e,t){const{classes:a}=this.props;return s().createElement("div",{className:a.marginBlock},s().createElement(Z.Z,{className:a.buttonAdd,variant:"contained",color:"secondary",startIcon:s().createElement(Za.default,null),onClick:t},e))}buttonRemoveKey(e,t){const{t:a,classes:o}=this.props;return s().createElement(F.Tooltip,{title:a("Remove attribute %s",e)},s().createElement("div",{className:o.close,onClick:t}))}renderCommonEdit(){try{const e=JSON.parse(this.state.text),t=["boolean","json","string","number","multistate","file","object","mixed"],a=!1,{classes:o,t:i,roleArray:n,obj:c}=this.props,d=c.type==="state",m=c.type==="channel"||c.type==="device"||d;let f;if(typeof e.common.icon!="undefined"&&(f=e.type==="instance"||e.type==="adapter"?`./adapter/${e.common.name}/${e.common.icon}`:e.common.icon,!f.startsWith(".")&&!f.startsWith("/")&&!f.startsWith("data:"))){const p=c._id.split(".");p[0]==="system"?f=`adapter/${p[2]}${f.startsWith("/")?"":"/"}${f}`:f=`adapter/${p[0]}${f.startsWith("/")?"":"/"}${f}`}return s().createElement("div",{className:o.commonTabWrapper},s().createElement("div",{className:o.commonWrapper},typeof e.common.name!="undefined"?s().createElement(T.Z,{variant:"standard",disabled:a,label:i("Name"),className:(0,V.default)(o.marginBlock,o.textField),fullWidth:!0,value:ct.default.getObjectNameFromObj(e,P.default.getLanguage(),null,!1,!0),onChange:p=>this.setCommonItem(e,"name",p.target.value)}):this.buttonAddKey("name",()=>this.setCommonItem(e,"name","")),d?typeof e.common.type!="undefined"?s().createElement("div",{className:o.flex},s().createElement(F.FormControl,{className:o.marginBlock,fullWidth:!0},s().createElement(F.InputLabel,null,i("State type")),s().createElement(F.Select,{variant:"standard",disabled:a,value:e.common.type,onChange:p=>this.setCommonItem(e,"type",p.target.value)},t.map(p=>s().createElement(F.MenuItem,{key:p,value:p},i(p))))),this.buttonRemoveKey("type",()=>this.removeCommonItem(e,"type"))):this.buttonAddKey("type",()=>this.setCommonItem(e,"type","string")):null,s().createElement("div",{className:o.flex},d?typeof e.common.read!="undefined"?s().createElement("div",{className:o.flex},s().createElement(k.Z,{className:o.marginBlock,control:s().createElement(N.Z,{disabled:a,checked:e.common.read,onClick:p=>this.setCommonItem(e,"read",p.target.checked)}),label:i("Readable")}),this.buttonRemoveKey("read",()=>this.removeCommonItem(e,"read"))):this.buttonAddKey("read",()=>this.setCommonItem(e,"read",!0)):null,d?typeof e.common.write!="undefined"?s().createElement("div",{className:o.flex},s().createElement(k.Z,{className:o.marginBlock,control:s().createElement(N.Z,{disabled:a,checked:e.common.write,onClick:p=>this.setCommonItem(e,"write",p.target.checked)}),label:i("Writeable")}),this.buttonRemoveKey("write",()=>this.removeCommonItem(e,"write"))):this.buttonAddKey("write",()=>this.setCommonItem(e,"write",!0)):null),m?typeof e.common.role!="undefined"?s().createElement("div",{className:o.flex},s().createElement(F.Autocomplete,{className:o.marginBlock,fullWidth:!0,disabled:a,value:e.common.role,onChange:(p,j)=>this.setCommonItem(e,"role",j),options:n,renderInput:p=>s().createElement(T.Z,La(Ja({variant:"standard"},p),{label:i("Role")}))}),this.buttonRemoveKey("role",()=>this.removeCommonItem(e,"role"))):this.buttonAddKey("role",()=>this.setCommonItem(e,"role","")):null,typeof e.common.color!="undefined"?s().createElement("div",{className:o.flex},s().createElement(T.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Color"),type:"color",value:e.common.color,onChange:p=>this.setCommonItem(e,"color",p.target.value)}),this.buttonRemoveKey("color",()=>this.removeCommonItem(e,"color"))):this.buttonAddKey("color",()=>this.setCommonItem(e,"color","")),s().createElement("div",{className:o.flex},e.common.type==="number"?typeof e.common.min!="undefined"?s().createElement("div",{className:o.flex},s().createElement(T.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Min"),value:e.common.min,onChange:p=>this.setCommonItem(e,"min",p.target.value)}),this.buttonRemoveKey("min",()=>this.removeCommonItem(e,"min"))):s().createElement("div",{className:o.flex},this.buttonAddKey("min",()=>this.setCommonItem(e,"min",0))):null,e.common.type==="number"?typeof e.common.max!="undefined"?s().createElement("div",{className:o.flex},s().createElement(T.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Max"),value:e.common.max,onChange:p=>this.setCommonItem(e,"max",p.target.value)}),this.buttonRemoveKey("max",()=>this.removeCommonItem(e,"max"))):s().createElement("div",{className:o.flex},this.buttonAddKey("max",()=>this.setCommonItem(e,"max",100))):null,e.common.type==="number"?typeof e.common.step!="undefined"?s().createElement("div",{className:o.flex},s().createElement(T.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Step"),value:e.common.step,onChange:p=>this.setCommonItem(e,"step",p.target.value)}),this.buttonRemoveKey("step",()=>this.removeCommonItem(e,"step"))):s().createElement("div",{className:o.flex},this.buttonAddKey("step",()=>this.setCommonItem(e,"step",1))):null),e.common.type==="number"?typeof e.common.unit!="undefined"?s().createElement("div",{className:o.flex},s().createElement(T.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Unit"),value:e.common.unit,onChange:p=>this.setCommonItem(e,"unit",p.target.value)}),this.buttonRemoveKey("unit",()=>this.removeCommonItem(e,"unit"))):s().createElement("div",{className:o.flexDrop},this.buttonAddKey("unit",()=>this.setCommonItem(e,"unit",""))):null),typeof e.common.icon!="undefined"?s().createElement("div",{className:o.flex,style:{flexGrow:1}},s().createElement(Pa.Z,{disabled:a,maxSize:10*1024,icon:f,removeIconFunc:()=>this.setCommonItem(e,"icon",""),onChange:p=>this.setCommonItem(e,"icon",p),t:i}),this.buttonRemoveKey("icon",()=>this.removeCommonItem(e,"icon"))):s().createElement("div",{className:o.flex},this.buttonAddKey("icon",()=>this.setCommonItem(e,"icon",""))))}catch(e){return s().createElement("div",null,this.props.t("Cannot parse JSON!"))}}renderAliasEdit(){var e,t,a,o,i,n,c,d,m,f,p,j,A,ne,U,ge,Q,Te,Le,Ze,de,Re,O,at,Be,ot,Ue,ut,Ye,ft,gt,vt,bt,yt,it,Et,rt,wt,Ge,Ct;try{const w=JSON.parse(this.state.text),Ke=((t=(e=w.common)==null?void 0:e.alias)==null?void 0:t.read)!==void 0||((o=(a=w.common)==null?void 0:a.alias)==null?void 0:o.write)!==void 0;return s().createElement(W.ZP,{container:!0,direction:"column",className:this.props.classes.marginTop},s().createElement(W.ZP,{item:!0},s().createElement(k.Z,{control:s().createElement(N.Z,{checked:typeof((n=(i=w.common)==null?void 0:i.alias)==null?void 0:n.id)=="object",onChange:()=>{var ee,Ee,Fe,b,$,ae,we;typeof((Ee=(ee=w.common)==null?void 0:ee.alias)==null?void 0:Ee.id)=="object"?this.setAliasItem(w,"id",(($=(b=(Fe=w.common)==null?void 0:Fe.alias)==null?void 0:b.id)==null?void 0:$.read)||""):this.setAliasItem(w,"id.read",((we=(ae=w.common)==null?void 0:ae.alias)==null?void 0:we.id)||"")}}),label:this.props.t("Different IDs for read and write")})),typeof((d=(c=w.common)==null?void 0:c.alias)==null?void 0:d.id)!="object"?s().createElement(W.ZP,{item:!0},s().createElement(T.Z,{variant:"standard",label:this.props.t("Alias state"),value:((f=(m=w.common)==null?void 0:m.alias)==null?void 0:f.id)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(j=(p=w.common)==null?void 0:p.alias)!=null&&j.id?s().createElement(Ne.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!0,selectRead:!1,selectWrite:!1})},"...")):null,typeof((ne=(A=w.common)==null?void 0:A.alias)==null?void 0:ne.id)=="object"?s().createElement(W.ZP,{item:!0},s().createElement(T.Z,{variant:"standard",label:this.props.t("Alias read state"),value:((Q=(ge=(U=w.common)==null?void 0:U.alias)==null?void 0:ge.id)==null?void 0:Q.read)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(Ze=(Le=(Te=w.common)==null?void 0:Te.alias)==null?void 0:Le.id)!=null&&Ze.read?s().createElement(Ne.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id.read","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id.read",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!0,selectWrite:!1})},"...")):null,typeof((Re=(de=w.common)==null?void 0:de.alias)==null?void 0:Re.id)=="object"?s().createElement(W.ZP,{item:!0},s().createElement(T.Z,{variant:"standard",label:this.props.t("Alias write state"),value:((Be=(at=(O=w.common)==null?void 0:O.alias)==null?void 0:at.id)==null?void 0:Be.write)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(ut=(Ue=(ot=w.common)==null?void 0:ot.alias)==null?void 0:Ue.id)!=null&&ut.write?s().createElement(Ne.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id.write","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id.write",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!0})},"...")):null,s().createElement(W.ZP,{item:!0,className:this.props.classes.marginTop},s().createElement(k.Z,{control:s().createElement(N.Z,{checked:((ft=(Ye=w.common)==null?void 0:Ye.alias)==null?void 0:ft.read)!==void 0||((vt=(gt=w.common)==null?void 0:gt.alias)==null?void 0:vt.write)!==void 0,onChange:()=>{Ke?(delete w.common.alias.read,delete w.common.alias.write):(w.common=w.common||{},w.common.alias=w.common.alias||{},w.common.alias.read="val",w.common.alias.write="val"),this.onChange(JSON.stringify(w,null,2))}}),label:this.props.t("Use convert functions")})),Ke?s().createElement(W.ZP,{item:!0},s().createElement(T.Z,{variant:"standard",label:this.props.t("Read converter"),value:((yt=(bt=w.common)==null?void 0:bt.alias)==null?void 0:yt.read)||"val",className:this.props.classes.funcEdit,error:!!this.state.readError,InputProps:{endAdornment:(Et=(it=w.common)==null?void 0:it.alias)!=null&&Et.read?s().createElement(Ne.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"read","")},s().createElement(J.default,null))):null,startAdornment:s().createElement(Ne.Z,{position:"start"},s().createElement(hs.Z,{className:this.props.classes.funcIcon}))},onChange:ee=>this.setAliasItem(w,"read",ee.target.value),helperText:this.state.readError||this.props.t("JS function like")+' "val / 5 + 21"',margin:"normal"})):null,Ke?s().createElement(W.ZP,{item:!0},s().createElement(T.Z,{variant:"standard",label:this.props.t("Write converter"),error:!!this.state.writeError,value:((wt=(rt=w.common)==null?void 0:rt.alias)==null?void 0:wt.write)||"val",helperText:this.state.writeError||this.props.t("JS function like")+' "(val - 21) * 5"',className:this.props.classes.funcEdit,InputProps:{endAdornment:(Ct=(Ge=w.common)==null?void 0:Ge.alias)!=null&&Ct.write?s().createElement(Ne.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"write","")},s().createElement(J.default,null))):null,startAdornment:s().createElement(Ne.Z,{position:"start"},s().createElement(hs.Z,{className:this.props.classes.funcIcon}))},onChange:ee=>this.setAliasItem(w,"write",ee.target.value),margin:"normal"})):null)}catch(w){return s().createElement("div",null,this.props.t("Cannot parse JSON!"))}}onCopy(e){e.stopPropagation(),e.preventDefault(),ka()(this.state.text),window.alert(this.props.t("ra_Copied"))}onClone(e,t,a){const o=JSON.parse(JSON.stringify(this.props.objects[e]));delete o.from,delete o.ts,delete o.user,o._id=t,this.props.objects[o._id]=o,this.props.onNewObject(o)}renderCopyDialog(){return this.state.showCopyDialog?s().createElement(te.Z,{open:!0,maxWidth:"md",fullWidth:!0,onClose:()=>this.setState({showCopyDialog:!1})},s().createElement(K.Z,null,this.props.t("Enter new ID for this object")),s().createElement(oe.Z,null,s().createElement(T.Z,{variant:"standard",autoFocus:!0,fullWidth:!0,label:this.props.t("New object ID"),value:this.state.newId,onKeyDown:e=>{e.keyCode===13&&!this.props.objects[this.state.newId]&&(this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId))},onChange:e=>this.setState({newId:e.target.value})})),s().createElement(L.Z,null,s().createElement(Z.Z,{disabled:!!this.props.objects[this.state.newId],onClick:()=>{this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId)},color:"primary",startIcon:s().createElement(cs.Z,null)},this.props.t("Clone")),s().createElement(Z.Z,{color:"grey",onClick:()=>this.setState({showCopyDialog:""}),startIcon:s().createElement(J.default,null)},this.props.t("Cancel")))):null}render(){const e=this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state";return s().createElement(te.Z,{classes:{paper:this.props.classes.dialog},open:!0,maxWidth:"lg",fullWidth:this.state.type!=="number"&&this.state.type!=="boolean",fullScreen:!1,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description"},s().createElement(K.Z,{id:"edit-value-dialog-title"},this.props.t("Edit object:")," ",s().createElement("span",{className:this.props.classes.id},this.props.obj._id)),this.renderTabs(),this.renderCopyDialog(),s().createElement(oe.Z,null,this.state.tab==="object"?s().createElement("div",{className:(0,V.default)(this.props.classes.divWithoutTitle,e&&this.props.classes.divWithoutTitleAndTab,this.state.error&&this.props.classes.error)},s().createElement(os(),{mode:"json",width:"100%",height:"100%",theme:this.props.themeName==="dark"?"clouds_midnight":"chrome",value:this.state.text,onChange:t=>this.onChange(t),name:"UNIQUE_ID_OF_DIV",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0},editorProps:{$blockScrolling:!0}})):null,this.state.tab==="alias"&&this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state"?this.renderAliasEdit():null,this.state.tab==="common"?this.renderCommonEdit():null,this.renderSelectDialog()),s().createElement(L.Z,{className:this.props.classes.wrapperButton},s().createElement(Z.Z,{color:"grey",onClick:()=>this.setState({showCopyDialog:this.props.obj._id,newId:this.props.obj._id}),disabled:this.state.error||this.state.changed,title:this.props.t("Create a copy of this object")},s().createElement(cs.Z,null)),s().createElement("div",{style:{flexGrow:1}}),this.state.tab==="object"&&s().createElement(Z.Z,{color:"grey",onClick:t=>this.onCopy(t),disabled:this.state.error,title:this.isMobile?this.props.t("Copy into clipboard"):"",startIcon:s().createElement(pt.FaClipboard,null)},this.isMobile?null:this.props.t("Copy into clipboard")),s().createElement(Z.Z,{variant:"contained",disabled:this.state.error||!this.state.changed,onClick:()=>this.onUpdate(),startIcon:s().createElement(Nt.default,null),color:"primary"},this.props.t("Write")),s().createElement(Z.Z,{color:"grey",variant:"contained",onClick:()=>this.props.onClose(),startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}ms.propTypes={classes:l().object,socket:l().object,obj:l().object,expertMode:l().bool,themeName:l().string,onClose:l().func.isRequired,dialogName:l().string,objects:l().object,dateFormat:l().string,isFloatComma:l().bool,onNewObject:l().func,t:l().func};var Ua=(0,G.withStyles)(Ba)(ms),Ya=Object.defineProperty,Ga=Object.defineProperties,Ka=Object.getOwnPropertyDescriptors,us=Object.getOwnPropertySymbols,Qa=Object.prototype.hasOwnProperty,Xa=Object.prototype.propertyIsEnumerable,fs=(r,e,t)=>e in r?Ya(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,$a=(r,e)=>{for(var t in e||(e={}))Qa.call(e,t)&&fs(r,t,e[t]);if(us)for(var t of us(e))Xa.call(e,t)&&fs(r,t,e[t]);return r},qa=(r,e)=>Ga(r,Ka(e));const _a=r=>({input:{marginBottom:r.spacing(2)},inputText:{width:400,height:300,marginBottom:r.spacing(2)},formControl:{marginBottom:r.spacing(2),minWidth:150},quality:{width:"100%"}});class gs extends C.Component{constructor(e){super(e),this.state={role:null,initRole:null,roleInput:null}}componentDidMount(){this.props.socket.getObject(this.props.id).then(e=>{var t;this.object=e;const a=((t=e==null?void 0:e.common)==null?void 0:t.role)||null;this.setState({role:a,initRole:a,roleInput:a})}).catch(e=>console.error(e))}onUpdate(){this.object.common=this.object.common||{},this.object.common.role=this.state.roleInput,this.props.socket.setObject(this.object._id,this.object).then(()=>this.props.onClose(this.object))}render(){return s().createElement(te.Z,{key:"objectBrowserEditRole",open:!0,maxWidth:"sm",fullWidth:!0,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-role-dialog-title","aria-describedby":"edit-role-dialog-description"},s().createElement(K.Z,{id:"edit-role-dialog-title"},this.object?this.props.t("Update role for %s",this.object._id):null),s().createElement(oe.Z,null,s().createElement(is.Z,{freeSolo:!0,options:this.props.roles,style:{width:"100%"},value:this.state.role,onChange:(e,t)=>this.setState({role:t,roleInput:t}),onInputChange:(e,t)=>this.setState({roleInput:t}),renderInput:e=>s().createElement(T.Z,qa($a({},e),{label:this.props.t("Role"),variant:"outlined"}))})),s().createElement(L.Z,null,s().createElement(Z.Z,{disabled:this.state.initRole===this.state.roleInput,variant:"contained",onClick:()=>this.onUpdate(),color:"primary",startIcon:s().createElement(Nt.default,null)},this.props.t("Apply")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}gs.propTypes={classes:l().object,roles:l().array,id:l().string,socket:l().object,onClose:l().func.isRequired,t:l().func};var eo=(0,G.withStyles)(_a)(gs),to=h(4050),ye=h(61984),vs=h(43253),so=Object.defineProperty,ao=Object.defineProperties,oo=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,io=Object.prototype.hasOwnProperty,ro=Object.prototype.propertyIsEnumerable,ys=(r,e,t)=>e in r?so(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Es=(r,e)=>{for(var t in e||(e={}))io.call(e,t)&&ys(r,t,e[t]);if(bs)for(var t of bs(e))ro.call(e,t)&&ys(r,t,e[t]);return r},ws=(r,e)=>ao(r,oo(e));const no=["boolean","string","number","array","json","object","mixed"],lo={boolean:!1,string:"",number:0},ce={state:{name:"Datapoint",value:"state"},channel:{name:"Channel",value:"channel"},device:{name:"Device",value:"device"},folder:{name:"Folder",value:"folder"}};var co=({onClose:r,onApply:e,open:t,selected:a,setObject:o,objects:i,expertMode:n})=>{var c;const d={state:P.default.t("New state"),channel:P.default.t("New channel"),device:P.default.t("New device"),folder:P.default.t("New folder")},m=[],f=(c=i[a])==null?void 0:c.type;let p="";i[a]?f==="channel"?(m.push(ce.state),p="state"):f==="device"?(p="channel",m.push(ce.state),m.push(ce.channel)):f==="state"?p="":(m.push(ce.state),m.push(ce.channel),m.push(ce.device),a.startsWith("0_userdata.")||a.startsWith("alias.0.")||a==="0_userdata"||a==="alias.0"?(m.push(ce.folder),p="folder"):p="state"):(m.push(ce.folder),p="folder",n&&(a.startsWith("mqtt.")||a.startsWith("javascript."))&&(m.push(ce.state),m.push(ce.channel),m.push(ce.device)));const j=(window._localStorage||window.localStorage).getItem("App.lastObjectType");j&&m.find(O=>O.value===j)&&(p=j);const[A,ne]=(0,C.useState)(p),[U,ge]=(0,C.useState)(d[p]),[Q,Te]=(0,C.useState)((window._localStorage||window.localStorage).getItem("App.lastStateType")||"string"),[Le,Ze]=(0,C.useState)(!i[de(d.state)]);function de(O){return a+"."+O.toString().replace(ye.Z.FORBIDDEN_CHARS,"_").replace(/\s/g,"_").replace(/\./g,"_")}const Re=()=>{const O={common:{name:U,desc:P.default.t("Manually created")},type:A};A==="state"?(O.common=ws(Es({},O.common),{role:"state",type:Q,read:!0,write:!0,def:lo[Q]}),O.native={}):A!=="folder"?O.common=ws(Es({},O.common),{role:"",icon:""}):delete O.common.desc,o(`${a}.${U.split(" ").join("_")}`,O).then(()=>e())};return t?s().createElement(vs.Z,{open:!0,fullWidth:!0,maxWidth:"lg",titleButtonApply:"add",applyDisabled:!U||!Le||!m.length,onClose:r,onApply:()=>Re()},s().createElement("div",{style:{display:"flex",flexDirection:"column"}},s().createElement("div",{style:{margin:10,fontSize:20}},s().createElement(to.Z,null),P.default.t("Add new object:"),s().createElement("span",{style:{fontStyle:"italic"}},a,".",U)),s().createElement(F.TextField,{variant:"standard",label:P.default.t("Parent"),style:{margin:"5px 0"},disabled:!0,value:a}),s().createElement(F.FormControl,{variant:"standard",style:{marginTop:10,marginBottom:16}},s().createElement(F.InputLabel,null,P.default.t("Type")),s().createElement(F.Select,{variant:"standard",value:A,onChange:O=>{(window._localStorage||window.localStorage).setItem("App.lastObjectType",O.target.value),U===d[A]&&(ge(d[O.target.value]),Ze(i[de(d[O.target.value])])),ne(O.target.value)}},m.map(O=>s().createElement(F.MenuItem,{key:O.value,value:O.value},P.default.t(O.name))))),A==="state"&&s().createElement(F.FormControl,{style:{marginTop:10,marginBottom:16}},s().createElement(F.InputLabel,{style:{left:-14}},P.default.t("State type")),s().createElement(F.Select,{style:{marginTop:6},variant:"standard",value:Q,onChange:O=>{(window._localStorage||window.localStorage).setItem("App.lastStateType",O.target.value),Te(O.target.value)}},no.map(O=>s().createElement(F.MenuItem,{key:O,value:O},O)))),s().createElement(F.TextField,{variant:"standard",label:P.default.t("Name"),style:{margin:"5px 0"},autoFocus:!0,value:U,onKeyDown:O=>{O.keyCode===13&&(O.preventDefault(),U&&Re())},onChange:O=>{Ze(!i[de(O.target.value)]),ge(O.target.value)}}))):null},mt=h(94475),ho=(r,e,t)=>new Promise((a,o)=>{var i=d=>{try{c(t.next(d))}catch(m){o(m)}},n=d=>{try{c(t.throw(d))}catch(m){o(m)}},c=d=>d.done?a(d.value):Promise.resolve(d.value).then(i,n);c((t=t.apply(r,e)).next())});const po=[{Owner:[{name:"read",valueNum:1024,title:"read owner"},{name:"write",valueNum:512,title:"write owner"}]},{Group:[{name:"read",valueNum:64,title:"read group"},{name:"write",valueNum:32,title:"write group"}]},{Everyone:[{name:"read",valueNum:4,title:"read everyone"},{name:"write",valueNum:2,title:"write everyone"}]}],Cs=(r,e,t)=>(r|=e&t,r&=e|~t&65535,r),Ss=({value:r,disabled:e,setValue:t,t:a,differentValues:o,applyToChildren:i,mask:n,setMask:c})=>{(0,C.useEffect)(()=>{if(i){let m=0;for(let f=0;f<o.length;f++)m|=r^o[f];c(m)}else c(0)},[o,i]);let d=r;return s().createElement("div",{style:{display:"flex",width:"fit-content",margin:20,border:"1px solid",borderLeft:0}},po.map(m=>{const f=Object.keys(m)[0];return s().createElement("div",{style:{width:150,height:150,display:"flex",flexDirection:"column",alignItems:"center",borderLeft:"1px solid"},key:f},s().createElement("div",{style:{height:50,display:"flex",alignItems:"center",fontSize:18,borderBottom:"1px solid silver",width:"100%",justifyContent:"center"}},a(f)),s().createElement("div",{style:{display:"flex",width:"100%"}},m[f].map((p,j)=>{let A=!1;return d-p.valueNum>=0&&(d=d-p.valueNum,A=!0),s().createElement("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",borderRight:j===0?"1px solid":0},key:p.valueNum},s().createElement("div",{style:{height:50,borderBottom:"1px solid",width:"100%",justifyContent:"center",display:"flex",alignItems:"center",color:"silver"}},a(p.name)),s().createElement("div",{style:{height:50,display:"flex"}},s().createElement(F.Checkbox,{disabled:e,checked:A,color:n&p.valueNum?"primary":"secondary",indeterminate:!!(n&p.valueNum),style:n&p.valueNum?{opacity:.5}:null,onChange:ne=>{n&p.valueNum&&(n&=~p.valueNum&65535,c(n));let U=r;ne.target.checked?U|=p.valueNum:U&=~p.valueNum&65535,t(U)}})))})))}))};var mo=({onClose:r,onApply:e,open:t,selected:a,extendObject:o,objects:i,t:n,modalEmptyId:c,themeType:d})=>{const[m,f]=(0,C.useState)(null),[p,j]=(0,C.useState)(null),[A,ne]=(0,C.useState)([]),[U,ge]=(0,C.useState)([]),[Q,Te]=(0,C.useState)(!1),[Le,Ze]=(0,C.useState)(!1),[de,Re]=(0,C.useState)(0),[O,at]=(0,C.useState)(null),[Be,ot]=(0,C.useState)(null),[Ue,ut]=(0,C.useState)(!1),[Ye,ft]=(0,C.useState)(!1),[gt,vt]=(0,C.useState)([]),[bt,yt]=(0,C.useState)([]),[it,Et]=(0,C.useState)(0),[rt,wt]=(0,C.useState)(0),[Ge,Ct]=(0,C.useState)([]),[w,Ke]=(0,C.useState)(!1),[ee,Ee]=(0,C.useState)(!0),Fe=n("different");return(0,C.useEffect)(()=>{var b,$,ae,we;let ke=0,ve=[],Tt=[],Os=a||c,So=Os+".";const Is=Object.keys(i).sort();let Zt=!1,Rt=[],Ft=[];const As=P.default.getLanguage();let Ds=!1,Ns=!1,Qe=null,Xe=null,Pe=null,We=null;const Ts=[];for(let Me=0;Me<Is.length;Me++){const Ce=Is[Me],D=i[Ce];if(D&&(Ce===Os||Ce.startsWith(So))){if(ke++,Ts.push(Ce),!D.acl)continue;Pe===null&&D.acl.object!==void 0&&(Pe=D.acl.object),We===null&&D.acl.state!==void 0&&(We=D.acl.state),Qe===null&&D.acl.owner!==void 0&&(Qe=D.acl.owner),Xe===null&&D.acl.ownerGroup!==void 0&&(Xe=D.acl.ownerGroup),!Ue&&Qe!==D.acl.owner&&D.acl.owner!==void 0&&(Ds=!0),!Ye&&Xe!==D.acl.ownerGroup&&D.acl.ownerGroup!==void 0&&(Ns=!0),D.acl.state!==void 0&&We!==D.acl.state&&!ve.includes(D.acl.state)&&ve.push(D.acl.state),D.acl.object!==void 0&&Pe!==D.acl.object&&!Tt.includes(D.acl.object)&&Tt.push(D.acl.object),D.type==="state"&&(Zt=!0)}Ce.startsWith("system.group.")&&(D==null?void 0:D.type)==="group"?Rt.push({name:ye.Z.getObjectNameFromObj(D,As).replace("system.group.",""),value:Ce,icon:(b=D.common)==null?void 0:b.icon,color:($=D.common)==null?void 0:$.color}):Ce.startsWith("system.user.")&&(D==null?void 0:D.type)==="user"&&Ft.push({name:ye.Z.getObjectNameFromObj(D,As).replace("system.user.",""),value:Ce,icon:(ae=D.common)==null?void 0:ae.icon,color:(we=D.common)==null?void 0:we.color})}Qe=Qe||i["system.config"].common.defaultNewAcl.owner,Xe=Xe||i["system.config"].common.defaultNewAcl.ownerGroup,Pe=Pe||i["system.config"].common.defaultNewAcl.object,at(isNaN(Pe)?i["system.config"].common.defaultNewAcl.object:Pe),Zt&&(We=We||i["system.config"].common.defaultNewAcl.state,ot(isNaN(We)?i["system.config"].common.defaultNewAcl.state:We));const xo=Ft.find(Me=>Me.value===Qe),jo=Rt.find(Me=>Me.value===Xe);f(xo),j(jo),ut(Ds),ft(Ns),ne(Ft),ge(Rt),Zt&&Ze(!0),c&&Te(!0),Re(ke),vt(ve),yt(Tt),Ct(Ts)},[i,a]),(0,C.useEffect)(()=>{Q?(Ye&&(p.value!=="different"&&j({name:Fe,value:"different"}),U.find(b=>b.value==="different")||ge(b=>[{name:Fe,value:"different"},...b])),Ue&&((!m||m.value!=="different")&&f({name:Fe,value:"different"}),A.find(b=>b.value==="different")||ne(b=>[{name:Fe,value:"different"},...b]))):(m&&m.value==="different"&&f(i[a].acl.owner),p&&p.value==="different"&&j(i[a].acl.ownerGroup),ge(b=>b.filter(({value:$})=>$!=="different")),ne(b=>b.filter(({value:$})=>$!=="different")))},[Q,Ue,Ye]),Ge.length?s().createElement(vs.Z,{open:t,titleButtonApply:"apply",overflowHidden:!0,applyDisabled:ee,progress:w,onClose:r,onApply:()=>{Ke(!0),setTimeout(()=>ho(void 0,null,function*(){if(Q){let b=~it&65535,$=~rt&65535;for(let ae=0;ae<Ge.length;ae++){const we=Ge[ae],ke=i[we];let ve=JSON.parse(JSON.stringify(ke.acl||{}));ve.object=Cs(ke.acl.object,O,b),m&&m.value!=="different"&&(ve.owner=m.value),p&&p.value!=="different"&&(ve.ownerGroup=p.value),ke.type==="state"&&(ve.state=Cs(ke.acl.state,Be,$)),yield o(we,{acl:ve})}}else{let b=JSON.parse(JSON.stringify(i[a].acl||{}));b.object=O,b.owner=m?m.value:"system.user.admin",b.ownerGroup=p?p.value:"system.group.administrator",i[a].type==="state"&&(b.state=Be),o(a,{acl:b})}Ke(!1),e()}),200)}},s().createElement("div",{style:{display:"flex",flexDirection:"column"}},s().createElement("div",{style:{margin:10,fontSize:20}},n("Access control list: %s",a||c)),s().createElement("div",{style:{display:"flex"}},s().createElement(F.FormControl,{variant:"standard",fullWidth:!0,style:{marginRight:10}},s().createElement(F.InputLabel,null,n("Owner user")),s().createElement(F.Select,{variant:"standard",disabled:w,value:m?m.value:"",renderValue:b=>s().createElement("span",null,m!=null&&m.icon?s().createElement(mt.default,{src:m.icon,style:{width:16,height:16,marginRight:8}}):null,m?m.name:""),style:(m==null?void 0:m.value)==="different"?{opacity:.5}:{color:(m==null?void 0:m.color)||void 0,backgroundColor:ye.Z.getInvertedColor(m==null?void 0:m.color,d)},onChange:b=>{const $=A.find(ae=>ae.value===b.target.value);f($),Ee(!1)}},A.map(b=>s().createElement(F.MenuItem,{style:b.value==="different"?{opacity:.5}:{color:b.color||void 0,backgroundColor:ye.Z.getInvertedColor(b.color,d)},key:b.value,value:b.value},b.icon?s().createElement(mt.default,{src:b.icon,style:{width:16,height:16,marginRight:8}}):null,b.name)))),s().createElement(F.FormControl,{variant:"standard",fullWidth:!0},s().createElement(F.InputLabel,null,n("Owner group")),s().createElement(F.Select,{variant:"standard",disabled:w,value:p?p.value:"",renderValue:b=>s().createElement("span",null,p!=null&&p.icon?s().createElement(mt.default,{src:p.icon,style:{width:16,height:16,marginRight:8}}):null,p?p.name:""),style:(p==null?void 0:p.value)==="different"?{opacity:.5}:{color:(p==null?void 0:p.color)||void 0,backgroundColor:ye.Z.getInvertedColor(p==null?void 0:p.color,d)},onChange:b=>{const $=U.find(ae=>ae.value===b.target.value);j($),Ee(!1)}},U.map(b=>s().createElement(F.MenuItem,{key:b.value,value:b.value,style:b.value==="different"?{opacity:.5}:{color:b.color||void 0,backgroundColor:ye.Z.getInvertedColor(b.color,d)}},b.icon?s().createElement(mt.default,{src:b.icon,style:{width:16,height:16,marginRight:8}}):null,b.name))))),s().createElement("div",{style:{display:"flex",margin:10,alignItems:"center",fontSize:10,marginLeft:0,color:"silver"}},s().createElement("div",{style:Q?null:{color:"green"}},n("to apply one item")),s().createElement(F.Switch,{disabled:w||!!c||de===1,checked:!!c||Q,onChange:b=>{Te(b.target.checked),Ee(!1)},color:"primary"}),s().createElement("div",{style:Q?{color:"green"}:null},n("to apply with children")," ",c||de>1?`(${de} ${n("object(s)")})`:"")),w&&s().createElement(F.LinearProgress,null),s().createElement("div",{style:{overflowY:"auto"}},s().createElement("div",null,s().createElement("h2",null,n("Object rights")),s().createElement(Ss,{mask:rt,disabled:w,setMask:wt,applyToChildren:Q,differentValues:bt,t:n,setValue:b=>{at(b),Ee(!1)},value:O})),Le&&s().createElement("div",null,s().createElement("h2",null,n("States rights")),s().createElement(Ss,{mask:it,disabled:w,setMask:Et,applyToChildren:Q,differentValues:Q?gt:[],t:n,setValue:b=>{ot(b),Ee(!1)},value:Be}))))):s().createElement(F.LinearProgress,null)},uo=h(37538),fo=h(93919);const go=r=>({dialog:{height:"100%",maxHeight:"100%",maxWidth:"100%"},content:{textAlign:"center"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+r.mixins.toolbar.minHeight+"px)"},error:{color:r.palette.mode==="dark"?"#ff7777":"#c20000"},image:{height:"100%",width:"auto"},text:{fontFamily:"Lucida Console, Courier, monospace",width:"100%"},download:{textDecoration:"none",textTransform:"uppercase",fontSize:14,color:"white",border:"1px solid white",borderRadius:5,padding:"8px 16px",marginRight:r.spacing(1)}}),Fo={images:["png","jpg","svg","jpeg"],code:["js","json"],txt:["log","txt","html","css","xml"]};class xs extends C.Component{constructor(e){super(e);const t=this.props.obj._id.split(".");this.state={error:"",sound:null,image:null,text:null,binary:null,fileName:t[t.length-2]+"."+t[t.length-1]},this.audioRef=s().createRef()}componentDidMount(){this.props.socket.getBinaryState(this.props.obj._id).then(e=>{let t=this.props.obj._id.toLowerCase().split(".").pop();const a=ye.Z.detectMimeType(e);if(a&&(t=a),t==="jpg")this.setState({image:!0,binary:e,mime:"image/jpeg"});else if(t==="svg")this.setState({image:!0,binary:e,mime:"image/svg+xml"});else if(t==="png"||t==="bmp")this.setState({image:!0,binary:e,mime:"image/"+t});else if(t==="mp3")this.setState({audio:!0,binary:e,mime:"audio/mpeg"});else if(t==="ogg")this.setState({audio:!0,binary:e,mime:"audio/ogg"});else if(t==="txt"||t==="log")try{const o=btoa(e);this.setState({text:o,binary:e,mime:"text/plain"})}catch(o){}}).catch(e=>this.setState({error:e}))}render(){return s().createElement(te.Z,{className:this.props.classes.dialog,open:!0,maxWidth:this.state.audio?"sm":"md",onClose:()=>this.props.onClose(),fullWidth:!0,"aria-labelledby":"object-view-dialog-title"},s().createElement(K.Z,{id:"object-view-dialog-title"},this.props.t("View file in state: %s",this.props.obj._id)),s().createElement(oe.Z,{className:this.props.classes.content},this.state.error?s().createElement("div",{className:this.props.classes.error},this.state.error==="State is not binary"?this.props.t("No file stored yet"):this.props.t(this.state.error)):null,this.state.audio?s().createElement("audio",{ref:this.audioRef,src:`data:${this.state.mime};base64,${this.state.binary}`}):null,this.state.audio?s().createElement(Ae.Z,{color:"primary",onClick:()=>this.audioRef.current&&this.audioRef.current.play()},s().createElement(uo.default,null)):null,this.state.image?s().createElement("img",{src:`data:${this.state.mime};base64,${this.state.binary}`,alt:this.props.obj._id,className:this.props.classes.image}):null,this.state.text!==null?s().createElement("pre",{className:this.props.classes.text},this.state.text):null),s().createElement(L.Z,null,s().createElement("a",{className:this.props.classes.download,download:this.state.fileName,href:`data:${this.state.mime};base64,${this.state.binary}`},s().createElement(fo.Z,{style:{paddingRight:8,height:12}}),s().createElement("span",null,this.props.t("Download"))),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),startIcon:s().createElement(J.default,null),color:"grey"},this.props.t("Close"))))}}xs.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,themeType:l().string,obj:l().object,onClose:l().func.isRequired};var vo=(0,R.default)()((0,G.withStyles)(go)(xs)),bo=Object.defineProperty,yo=(r,e,t)=>e in r?bo(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Eo=(r,e,t)=>(yo(r,typeof e!="symbol"?e+"":e,t),t);const wo=r=>({buttonIcon:{marginRight:4},buttonAll:{color:"#FF0000"},id:{fontStyle:"italic"},buttonText:{whiteSpace:"nowrap"}});class js extends C.Component{constructor(e){super(e),Eo(this,"translate",(a,o,i)=>o!==void 0?this.props.t(a,o,i):(this.wordCache[a]||(this.wordCache[a]=this.props.t(a)),this.wordCache[a])),this.dialogName="AdminObjects",this.filters=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.filters`)||"{}";try{this.filters=JSON.parse(this.filters)}catch(a){this.filters={}}let t=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.selected`)||"";this.state={selected:this.props.selected===void 0?t:"",name:"",toast:"",deleteObjectShow:null},this.t=this.translate,this.wordCache={}}onDelete(e){const t=this.state.deleteObjectShow.id;e?(this.props.socket.delObjects(t,!0).then(()=>this.setState({toast:this.t("All deleted")})).catch(a=>window.alert("Cannot delete object: "+a)),this.setState({deleteObjectShow:null})):(this.props.socket.delObject(t,!1).catch(a=>window.alert("Cannot delete object: "+a)),this.setState({deleteObjectShow:null}))}renderToast(){return s().createElement(Ve.Z,{anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!this.state.toast,autoHideDuration:3e3,onClose:()=>this.setState({toast:""}),message:this.state.toast,action:s().createElement(s().Fragment,null,s().createElement(X.Z,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({toast:""})},s().createElement(J.default,{fontSize:"small"})))})}renderDeleteDialog(){return this.state.deleteObjectShow?s().createElement(te.Z,{key:"delete",maxWidth:"md",open:!0,onClose:()=>this.setState({deleteObjectShow:null}),"aria-labelledby":"delete-object-dialog-title","aria-describedby":"delete-object-dialog-description"},s().createElement(K.Z,{id:"delete-object-dialog-title"},this.state.deleteObjectShow.hasChildren?this.t("Delete object(s)"):this.t("Delete object"),": ",s().createElement("span",{className:this.props.classes.id},this.state.deleteObjectShow.id)),s().createElement(oe.Z,null,s().createElement(qe.Z,null,this.t("Are you sure?"))),s().createElement(L.Z,null,this.state.deleteObjectShow.hasChildren?s().createElement(Z.Z,{variant:"contained",color:"grey",classes:{label:this.props.classes.buttonText},onClick:()=>this.onDelete(!0),startIcon:s().createElement(me.default,{className:this.props.classes.buttonAll})},this.t("Delete with children")):null,this.state.deleteObjectShow.exists?s().createElement(Z.Z,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:()=>this.onDelete(!1),color:"primary",startIcon:s().createElement(me.default,null),autoFocus:!0},this.t("Delete one item")):null,s().createElement(Z.Z,{variant:"contained",color:"grey",onClick:()=>this.setState({deleteObjectShow:null}),startIcon:s().createElement(J.default,null)},this.t("ra_Cancel")))):null}render(){return[s().createElement(_e.Z,{key:"browser",dialogName:"admin",objectsWorker:this.props.objectsWorker,prefix:this.props.prefix,defaultFilters:this.filters,statesOnly:this.props.statesOnly,style:{width:"100%",height:"100%"},socket:this.props.socket,selected:this.state.selected,name:this.state.name,expertMode:this.props.expertMode,isFloatComma:this.props.isFloatComma,dateFormat:this.props.dateFormat,t:this.t,lang:this.props.lang,themeName:this.props.themeName,themeType:this.props.themeType,theme:this.props.theme,objectCustomDialog:fa,objectBrowserValue:Ta,objectBrowserEditObject:Ua,objectBrowserEditRole:eo,objectBrowserViewFile:vo,router:pe.Z,enableStateValueEdit:!0,onObjectDelete:(e,t,a)=>this.setState({deleteObjectShow:{id:e,hasChildren:t,exists:a}}),onFilterChanged:e=>{this.filters=e,(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.filters`,JSON.stringify(e))},onSelect:e=>(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.selected`,e[0]||""),objectEditBoolean:!0,objectAddBoolean:!0,objectStatesView:!0,objectImportExport:!0,objectEditOfAccessControl:!0,modalNewObject:e=>s().createElement(co,{objects:e.objects,expertMode:this.props.expertMode,open:e.state.modalNewObj,setObject:(t,a)=>e.setObject(t,a),selected:e.state.selected[0]||e.state.selectedNonObject,onClose:()=>e.setState({modalNewObj:!1}),onApply:()=>e.setState({modalNewObj:!1})}),modalEditOfAccessControl:(e,t)=>s().createElement(mo,{themeType:this.props.themeType,open:e.state.modalEditOfAccess,extendObject:(a,o)=>{e.extendObject(a,o),t.aclTooltip=null},selected:e.state.selected[0],modalEmptyId:e.state.modalEmptyId,objects:e.objects,t:this.t,onClose:()=>e.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null}),onApply:()=>e.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})})}),this.renderDeleteDialog()]}}js.propTypes={t:l().func,lang:l().string,socket:l().object,themeName:l().string,themeType:l().string,theme:l().object,expertMode:l().bool,isFloatComma:l().bool,dateFormat:l().string,objectsWorker:l().object};var Co=(0,R.default)()((0,G.withStyles)(wo)(js))}}]);
|
|
309
|
+
${c.getFullYear()}`}}},yAxis:a,toolbox:{left:"right",feature:this.props.noToolbar?void 0:{saveAsImage:{title:this.props.t("Save as image"),show:!0}}},series:[t]}}static getDerivedStateFromProps(e,t){return null}updateChart(e,t,a,o){e&&(this.start=e),t&&(this.end=t),e=e||this.start,t=t||this.end,this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=setTimeout(()=>{this.readTimeout=null;const i=this.chart.max-this.chart.min;i!==this.chart.diff&&(this.chart.diff=i,this.chart.withTime=this.chart.diff<36e5*24*7,this.chart.withSeconds=this.chart.diff<6e4*30),a?this.readHistory(e,t).then(n=>{this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData(n)}],xAxis:{min:this.chart.min,max:this.chart.max}}),o&&o()}):(this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData()}],xAxis:{min:this.chart.min,max:this.chart.max}}),o&&o())},400)}setNewRange(e){this.chart.diff=this.chart.max-this.chart.min,this.chart.withTime=this.chart.diff<36e5*24*7,this.chart.withSeconds=this.chart.diff<6e4*30,this.state.relativeRange!=="absolute"?(this.setState({relativeRange:"absolute"}),this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null):this.echartsReact&&typeof this.echartsReact.getEchartsInstance=="function"&&(this.echartsReact.getEchartsInstance().setOption({xAxis:{min:this.chart.min,max:this.chart.max}}),e&&this.updateChart(this.chart.min,this.chart.max,!0))}shiftTime(){const e=new Date,t=6e4-e.getSeconds()-(1e3-e.getMilliseconds());e.getMilliseconds()&&e.setMilliseconds(1e3),e.getSeconds()&&e.setSeconds(60);const a=e.getTime();let o,i=this.state.relativeRange;if(i==="day")e.setHours(0),e.setMinutes(0),e.setSeconds(0),o=e.getTime();else if(i==="week"){e.setHours(0),e.setMinutes(0),e.setSeconds(0);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else if(i==="2weeks"){e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(e.getDate()-7);const n=e.getDay()||7;n!==1&&e.setHours(-24*(n-1)),o=e.getTime()}else i==="month"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),o=e.getTime()):i==="year"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setDate(1),e.setMonth(0),o=e.getTime()):i==="12months"?(e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setFullYear(e.getFullYear()-1),o=e.getTime()):(i=parseInt(i,10),o=a-i*6e4);this.chart.min=o,this.chart.max=a,this.setState({min:o,max:a},()=>this.updateChart(this.chart.min,this.chart.max,!0)),this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},t||6e4)}setRelativeInterval(e,t,a){if(t||((window._localStorage||window.localStorage).setItem("App.relativeRange",e),this.setState({relativeRange:e})),e==="absolute"){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.updateChart(this.chart.min,this.chart.max,!0,a);return}else(window._localStorage||window.localStorage).removeItem("App.absoluteStart"),(window._localStorage||window.localStorage).removeItem("App.absoluteEnd");const o=new Date;if(!this.timeTimer){const i=6e4-o.getSeconds()-(1e3-o.getMilliseconds());this.timeTimer=setTimeout(()=>{this.timeTimer=null,this.shiftTime()},i||6e4)}if(o.getMilliseconds()&&o.setMilliseconds(1e3),o.getSeconds()&&o.setSeconds(60),this.chart.max=o.getTime(),e==="day")o.setHours(0),o.setMinutes(0),o.setSeconds(0),this.chart.min=o.getTime();else if(e==="week"){o.setHours(0),o.setMinutes(0),o.setSeconds(0);const i=o.getDay()||7;i!==1&&o.setHours(-24*(i-1)),this.chart.min=o.getTime()}else if(e==="2weeks"){o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(o.getDate()-7);const i=o.getDay()||7;i!==1&&o.setHours(-24*(i-1)),this.chart.min=o.getTime()}else e==="month"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(1),this.chart.min=o.getTime()):e==="year"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setDate(1),o.setMonth(0),this.chart.min=o.getTime()):e==="12months"?(o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setFullYear(o.getFullYear()-1),this.chart.min=o.getTime()):(e=parseInt(e,10),this.chart.min=this.chart.max-e*6e4);this.setState({min:this.chart.min,max:this.chart.max},()=>this.updateChart(this.chart.min,this.chart.max,!0,a))}installEventHandlers(){if(!this.echartsReact||typeof this.echartsReact.getEchartsInstance!="function")return;const e=this.echartsReact.getEchartsInstance().getZr();e._iobInstalled||(e._iobInstalled=!0,e.on("mousedown",t=>{console.log("mouse down"),this.mouseDown=!0,this.chart.lastX=t.offsetX}),e.on("mouseup",()=>{console.log("mouse up"),this.mouseDown=!1,this.setNewRange(!0)}),e.on("mousewheel",t=>{let a=this.chart.max-this.chart.min;const o=this.state.chartWidth-Te-_,n=(t.offsetX-_)/o,c=a,d=t.wheelDelta>0?1.1:.9;a=a*d;const m=c-a;this.chart.max+=m*(1-n),this.chart.min-=m*n,this.setNewRange()}),e.on("mousemove",t=>{if(this.mouseDown){const a=this.chart.lastX-(t.offsetX-_);this.chart.lastX=t.offsetX-_;const o=this.chart.max-this.chart.min,i=this.state.chartWidth-Te-_,n=Math.round(a*o/i);this.chart.min+=n,this.chart.max+=n,this.setNewRange()}}),e.on("touchstart",t=>{t.preventDefault(),this.mouseDown=!0;const a=t.touches||t.originalEvent.touches;a&&(this.chart.lastX=a[a.length-1].pageX,a.length>1?this.chart.lastWidth=Math.abs(a[0].pageX-a[1].pageX):this.chart.lastWidth=null)}),e.on("touchend",t=>{t.preventDefault(),this.mouseDown=!1,this.setNewRange(!0)}),e.on("touchmove",t=>{t.preventDefault();const a=t.touches||t.originalEvent.touches;if(!a)return;const o=a[a.length-1].pageX-_;if(this.mouseDown)if(a.length>1){const i=Math.abs(a[0].pageX-a[1].pageX);if(this.chart.lastWidth!==null&&i!==this.chart.lastWidth){let n=this.chart.max-this.chart.min;const c=this.state.chartWidth-Te-_,d=i>this.chart.lastWidth?1.1:.9,f=(a[0].pageX>a[1].pageX?a[1].pageX-_+i/2:a[0].pageX-_+i/2)/c,p=n;n=n*d;const j=p-n;this.chart.max+=j*(1-f),this.chart.min-=j*f,this.setNewRange()}this.chart.lastWidth=i}else{const i=this.chart.lastX-o,n=this.chart.max-this.chart.min,c=this.state.chartWidth-Te-_,d=Math.round(i*n/c);this.chart.min+=d,this.chart.max+=d,this.setNewRange()}this.chart.lastX=o}))}renderChart(){return this.chartValues?x.createElement($s.Z,{ref:e=>this.echartsReact=e,echarts:_s,option:this.getOption(),notMerge:!0,lazyUpdate:!0,theme:this.props.themeType==="dark"?"dark":"",style:{height:this.state.chartHeight+"px",width:"100%"},opts:{renderer:"svg"},onEvents:{rendered:e=>{this.installEventHandlers()}}}):x.createElement(S.Z,null)}componentDidUpdate(){if(this.divRef.current){const e=this.divRef.current.offsetWidth,t=this.divRef.current.offsetHeight;this.state.chartHeight!==t&&setTimeout(()=>this.setState({chartHeight:t,chartWidth:e}),100)}}setStartDate(e){e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",e),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",this.state.max),this.chart.min=e,this.setState({min:e,relativeRange:"absolute"},()=>this.updateChart(this.chart.min,this.chart.max,!0))}setEndDate(e){e=e.getTime(),(window._localStorage||window.localStorage).setItem("App.relativeRange","absolute"),(window._localStorage||window.localStorage).setItem("App.absoluteStart",this.state.min),(window._localStorage||window.localStorage).setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.chart.max=e,this.setState({max:e,relativeRange:"absolute"},()=>this.updateChart(this.chart.min,this.chart.max,!0))}openEcharts(){const e=["id="+window.encodeURIComponent(this.props.obj._id),"instance="+window.encodeURIComponent(this.state.historyInstance),"menuOpened=false"];this.state.relativeRange==="absolute"?(e.push("start="+this.chart.min),e.push("end="+this.chart.max)):e.push("range="+this.state.relativeRange),window.open(`${window.location.protocol}//${window.location.host}/adapter/echarts/tab.html#${e.join("&")}`,"echarts")}renderToolbar(){if(this.props.noToolbar)return null;const e=this.props.classes;return x.createElement(Pt.Z,null,!this.props.historyInstance&&x.createElement(Oe.Z,{variant:"standard",className:e.selectHistoryControl},x.createElement(je.Z,null,this.props.t("History instance")),x.createElement(Ie.Z,{variant:"standard",value:this.state.historyInstance,onChange:t=>{(window._localStorage||window.localStorage).setItem("App.historyInstance",t.target.value),this.setState({historyInstance:t.target.value})}},this.state.historyInstances.map(t=>x.createElement(E.Z,{key:t.id,value:t.id,className:(0,V.default)(!t.alive&&e.notAliveInstance)},t.id)))),x.createElement(Oe.Z,{variant:"standard",className:e.selectRelativeTime},x.createElement(je.Z,null,this.props.t("Relative")),x.createElement(Ie.Z,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value)},x.createElement(E.Z,{key:"custom",value:"absolute",className:e.customRange},this.props.t("custom range")),x.createElement(E.Z,{key:"1",value:10},this.props.t("last 10 minutes")),x.createElement(E.Z,{key:"2",value:30},this.props.t("last 30 minutes")),x.createElement(E.Z,{key:"3",value:60},this.props.t("last hour")),x.createElement(E.Z,{key:"4",value:"day"},this.props.t("this day")),x.createElement(E.Z,{key:"5",value:24*60},this.props.t("last 24 hours")),x.createElement(E.Z,{key:"6",value:"week"},this.props.t("this week")),x.createElement(E.Z,{key:"7",value:24*60*7},this.props.t("last week")),x.createElement(E.Z,{key:"8",value:"2weeks"},this.props.t("this 2 weeks")),x.createElement(E.Z,{key:"9",value:24*60*14},this.props.t("last 2 weeks")),x.createElement(E.Z,{key:"10",value:"month"},this.props.t("this month")),x.createElement(E.Z,{key:"11",value:30*24*60},this.props.t("last 30 days")),x.createElement(E.Z,{key:"12",value:"year"},this.props.t("this year")),x.createElement(E.Z,{key:"13",value:"12months"},this.props.t("last 12 months")))),x.createElement(Ot._,{dateAdapter:jt.Z,adapterLocale:pa[this.props.lang]},x.createElement("div",{className:e.toolbarTimeGrid},x.createElement(et.M,{className:e.toolbarDate,disabled:this.state.relativeRange!=="absolute",disableToolbar:!0,variant:"inline",margin:"normal",inputFormat:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.min),onChange:t=>this.setStartDate(t),renderInput:t=>x.createElement(N.Z,dt({className:this.props.classes.dateInput,variant:"standard"},t))}),x.createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.min),onChange:t=>this.setStartDate(t),renderInput:t=>x.createElement(N.Z,dt({className:this.props.classes.timeInput,variant:"standard"},t))})),x.createElement("div",{className:e.toolbarTimeGrid},x.createElement(et.M,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarDate,disableToolbar:!0,inputFormat:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.max),onChange:t=>this.setEndDate(t),renderInput:t=>x.createElement(N.Z,dt({className:this.props.classes.dateInput,variant:"standard"},t))}),x.createElement(tt.j,{disabled:this.state.relativeRange!=="absolute",className:e.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.max),onChange:t=>this.setEndDate(t),renderInput:t=>x.createElement(N.Z,dt({className:this.props.classes.timeInput,variant:"standard"},t))}))),x.createElement("div",{className:e.grow}),this.props.showJumpToEchart&&this.state.echartsJump&&x.createElement(Ae.Z,{className:e.echartsButton,size:"small",onClick:()=>this.openEcharts(),title:this.props.t("Open charts in new window")},x.createElement("img",{src:na,alt:"echarts",className:e.buttonIcon})),x.createElement(Ae.Z,{variant:"extended",size:"small",color:this.state.splitLine?"primary":"inherit","aria-label":"show lines",onClick:()=>{(window._localStorage||window.localStorage).setItem("App.splitLine",this.state.splitLine?"false":"true"),this.setState({splitLine:!this.state.splitLine})},className:e.splitLineButton},x.createElement(pt.FaChartLine,{className:e.splitLineButtonIcon}),this.props.t("Show lines")))}render(){return!this.state.historyInstances&&!this.state.defaultHistory?x.createElement(S.Z,null):x.createElement(M.Z,{className:this.props.classes.paper},this.renderToolbar(),x.createElement("div",{ref:this.divRef,className:(0,V.default)(this.props.classes.chart,this.props.noToolbar?this.props.classes.chartWithoutToolbar:this.props.classes.chartWithToolbar)},this.renderChart()))}}es.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,obj:l().object,customsInstances:l().array,themeType:l().string,objects:l().object,from:l().number,end:l().number,noToolbar:l().bool,defaultHistory:l().string,historyInstance:l().string,showJumpToEchart:l().bool,isFloatComma:l().bool};var ts=(0,R.default)()((0,G.withStyles)(ma)(es)),ss=h(86695);const ua=r=>({dialog:{height:"100%"},paper:{height:"calc(100% - 64px)"},content:{textAlign:"center",overflow:"hidden"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+r.mixins.toolbar.minHeight+"px)"},tabSelected:{color:r.palette.mode==="dark"?r.palette.secondary.contrastText:"#FFFFFF !important"},tabsIndicator:{backgroundColor:r.palette.secondary.main}}),Oo={images:["png","jpg","svg","jpeg"],code:["js","json"],txt:["log","txt","html","css","xml"]};class as extends ss.Z{constructor(e){super(e);let t=parseInt((window._localStorage||window.localStorage).getItem("App.objectCustomTab")||0,10);if(this.chartAvailable=this.isChartAvailable(),this.chartAvailable){const a=pe.Z.getLocation();a.arg==="chart"?t=2:a.arg==="table"&&(t=1)}else t=0;this.state={hasChanges:!1,currentTab:t,confirmDialog:!1,mobile:ss.Z.isMobile(),progressRunning:!1},this.saveFunc=null}isChartAvailable(){let e=this.props.objectIDs.length===1;if(e){const t=this.props.objectIDs[0];this.props.objects[t]&&this.props.objects[t].common&&this.props.objects[t].common.custom&&this.props.objects[t].common.custom?e=Object.keys(this.props.objects[t].common.custom).find(a=>{const o=this.props.objects["system.adapter."+a];return o&&o.common&&o.common.getHistory}):e=!1}return e}renderCharts(){return s().createElement(ts,{id:"chart-tabpanel",isFloatComma:this.props.isFloatComma,showJumpToEchart:!0,t:this.props.t,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,obj:this.props.objects[this.props.objectIDs[0]],customsInstances:this.props.customsInstances,themeType:this.props.themeType,objects:this.props.objects})}renderTable(){return s().createElement(Xs,{id:"table-tabpanel",t:this.props.t,isFloatComma:this.props.isFloatComma,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,obj:this.props.objects[this.props.objectIDs[0]],customsInstances:this.props.customsInstances,themeName:this.props.themeName,objects:this.props.objects})}renderCustomEditor(){return s().createElement(Fs,{id:"custom-settings-tabpanel",registerSaveFunc:e=>this.saveFunc=e,t:this.props.t,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,objectIDs:this.props.objectIDs,customsInstances:this.props.customsInstances,objects:this.props.objects,onProgress:e=>this.setState({progressRunning:e}),reportChangedIds:this.props.reportChangedIds,onChange:(e,t)=>{this.setState({hasChanges:e},()=>{if(t){const a=this.isChartAvailable();a!==this.chartAvailable&&(this.chartAvailable=a,this.forceUpdate())}})},theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType})}renderConfirmDialog(){return this.state.confirmDialog?s().createElement(le.default,{title:P.default.t("You have unsaved changes"),text:P.default.t("Discard?"),ok:P.default.t("Yes"),cancel:P.default.t("Cancel"),onClose:e=>this.setState({confirmDialog:!1},()=>e&&this.props.onClose())}):null}onClose(){this.state.hasChanges?this.setState({confirmDialog:!0}):this.props.onClose()}render(){var e,t;const a=(t=(e=this.props.objects[this.props.objectIDs[0]])==null?void 0:e.common)==null?void 0:t.type;return s().createElement(te.Z,{classes:{scrollPaper:this.props.classes.dialog,paper:this.props.classes.paper},scroll:"paper",open:!0,onClose:()=>this.props.onClose(),fullWidth:!0,maxWidth:"xl","aria-labelledby":"form-dialog-title"},this.renderConfirmDialog(),s().createElement(K.Z,null,this.props.objectIDs.length>1?this.props.t("Edit config for %s states",this.props.objectIDs.length):this.props.t("Edit config: %s",this.props.objectIDs[0])),s().createElement(oe.Z,{className:this.props.classes.content},s().createElement(Se.Z,{position:"static"},s().createElement(He.Z,{value:this.state.currentTab,onChange:(o,i)=>{pe.Z.doNavigate(null,null,null,i===1?"table":i===2?"chart":"config"),this.setState({currentTab:i}),(window._localStorage||window.localStorage).setItem("App.objectCustomTab",i)},classes:{indicator:this.props.classes.tabsIndicator},indicatorColor:"secondary"},s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("Custom settings"),id:"custom-settings-tab","aria-controls":"simple-tabpanel-0",classes:{selected:this.props.classes.tabSelected}}),this.props.objectIDs.length===1&&this.chartAvailable?s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("History data"),id:"history-data-tab","aria-controls":"simple-tabpanel-1",classes:{selected:this.props.classes.tabSelected}}):null,(a==="number"||a==="boolean")&&this.props.objectIDs.length===1&&this.chartAvailable?s().createElement(he.Z,{disabled:this.state.progressRunning,label:this.props.t("Chart"),id:"chart-tab","aria-controls":"simple-tabpanel-2",classes:{selected:this.props.classes.tabSelected}}):null)),this.state.currentTab===0?s().createElement("div",{className:this.props.classes.tabPanel},this.renderCustomEditor()):null,this.props.objectIDs.length===1&&this.chartAvailable&&this.state.currentTab===1?s().createElement("div",{className:this.props.classes.tabPanel},this.renderTable()):null,(a==="number"||a==="boolean")&&this.props.objectIDs.length===1&&this.chartAvailable&&this.state.currentTab===2?s().createElement("div",{className:this.props.classes.tabPanel},this.renderCharts()):null),s().createElement(L.Z,null,this.state.currentTab===0&&s().createElement(Z.Z,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>this.saveFunc&&this.saveFunc()},this.getButtonTitle(s().createElement(ie.default,null),this.props.t("Save"))),this.state.currentTab===0&&s().createElement(Z.Z,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>{this.saveFunc?this.saveFunc(o=>!o&&this.onClose()):this.onClose()}},this.getButtonTitle(s().createElement(ie.default,null),this.props.t("Save & close"),s().createElement(J.default,null))),s().createElement(Z.Z,{disabled:this.state.progressRunning,variant:"contained",onClick:()=>this.onClose(),color:"grey"},this.getButtonTitle(s().createElement(J.default,null),this.props.t("Close")))))}}as.propTypes={t:l().func,lang:l().string,expertMode:l().bool,objects:l().object,socket:l().object,theme:l().object,themeName:l().string,themeType:l().string,customsInstances:l().array,objectIDs:l().array,onClose:l().func,reportChangedIds:l().func,isFloatComma:l().bool};var fa=(0,G.withStyles)(ua)(as),ga=h(83732),os=h.n(ga),Io=h(72921),Ao=h(14091),To=h(15120),Do=h(68716),No=h(24317),va=h(54566),ba=h(21233),is=h(95697),ya=h(13423),Dt=h(26021),Ea=h(53736),wa=h(94315),Ca=Object.defineProperty,Sa=Object.defineProperties,xa=Object.getOwnPropertyDescriptors,rs=Object.getOwnPropertySymbols,ja=Object.prototype.hasOwnProperty,Oa=Object.prototype.propertyIsEnumerable,ns=(r,e,t)=>e in r?Ca(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ia=(r,e)=>{for(var t in e||(e={}))ja.call(e,t)&&ns(r,t,e[t]);if(rs)for(var t of rs(e))Oa.call(e,t)&&ns(r,t,e[t]);return r},Aa=(r,e)=>Sa(r,xa(e));const Ta=r=>({input:{width:"100%"},textInput:{width:"100%"},formControl:{minWidth:150},quality:{width:"calc(100% - 88px)"},expire:{marginLeft:8,width:80},jsonError:{border:"1px solid red",minHeight:200},jsonNoError:{border:"1px solid #00000000",minHeight:200},wrapperButton:{},readOnly:{backgroundColor:"#b74848"},readOnlyText:{color:"#b74848"},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:12}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:11}}},ackCheckbox:{marginLeft:4},dialog:{minHeight:window.clientHeight-50>500?500:window.clientHeight-50}}),Da=(0,G.withStyles)(r=>({root:{width:28,height:16,padding:0,display:"flex"},switchBase:{padding:2,color:r.palette.grey[500],"&$checked":{transform:"translateX(12px)",color:r.palette.common.white,"& + $track":{opacity:1,backgroundColor:r.palette.primary.main,borderColor:r.palette.primary.main}}},thumb:{width:12,height:12,boxShadow:"none"},track:{border:`1px solid ${r.palette.grey[500]}`,borderRadius:16/2,opacity:1,backgroundColor:r.palette.common.white},checked:{}}))(ba.Z);class ls extends C.Component{constructor(e){super(e);let t=this.props.type||typeof this.props.value;if(this.value=this.props.value,this.propsValue=this.value,this.propsValue===null?this.propsValue="null":this.propsValue===void 0&&(this.propsValue="undefined"),this.props.states)t="states";else if(t==="string"||t==="json"){if(this.value&&typeof this.value=="string"&&(this.value.startsWith("[")&&this.value.endsWith("]")||this.value.startsWith("{")&&this.value.endsWith("}")))try{this.value=JSON.parse(this.value),this.value=JSON.stringify(this.value,null,2),this.propsValue=this.value,t="json"}catch(a){}}else t==="number"&&(this.value=parseFloat(this.propsValue)||0);this.state={type:t,chart:!1,chartEnabled:(window._localStorage||window.localStorage).getItem("App.chartSetValue")!=="false",fullScreen:(window._localStorage||window.localStorage).getItem("App.fullScreen")==="true"},this.ack=!1,this.q=0,this.expire=0,this.inputRef=s().createRef(),this.chartFrom=Date.now()-36e5*2}componentDidMount(){var e,t,a;this.props.defaultHistory&&((t=(e=this.props.object)==null?void 0:e.common)==null?void 0:t.custom)&&((a=this.props.object.common.custom[this.props.defaultHistory])==null?void 0:a.enabled)&&this.props.socket.getState("system.adapter."+this.props.defaultHistory+".alive").then(o=>this.setState({chart:o&&!!o.val})),setTimeout(()=>{if(this.inputRef&&this.inputRef.current){const o=this.inputRef.current,i=o.value||"";o.setSelectionRange(0,i.length)}},200)}onUpdate(e){e&&e.stopPropagation(),e&&e.preventDefault();let t=this.value;if(this.state.type==="states")if(t==="null")t=null;else{let a=this.props.type||typeof this.props.value;t=typeof t=="object"?t.value:t,a==="number"?typeof t=="string"&&(t=parseFloat(t.replace(",","."))||0):a==="boolean"&&(t=t===!0||t==="true"||t==="1"||t==="ON"||t==="on")}else this.state.type==="number"?t==="null"?t=null:typeof t=="string"&&(t=parseFloat(t.replace(",","."))||0):this.state.type==="boolean"&&(t==="null"?t=null:t=t===!0||t==="true"||t==="1"||t==="ON"||t==="on");this.props.onClose({val:t,ack:this.ack,q:this.q,expire:parseInt(this.expire,10)||void 0})}renderChart(){return s().createElement(ts,{t:this.props.t,isFloatComma:this.props.isFloatComma,showJumpToEchart:!1,lang:this.props.lang,socket:this.props.socket,obj:this.props.object,themeType:this.props.themeType,from:this.chartFrom,end:Date.now(),noToolbar:!0,dateFormat:this.props.dateFormat,defaultHistory:this.props.defaultHistory})}checkJsonError(){try{JSON.parse(this.value),this.setState({jsonError:!1})}catch(e){this.setState({jsonError:!0})}}renderJsonEditor(){return s().createElement(os(),{className:this.state.jsonError?this.props.classes.jsonError:this.props.classes.jsonNoError,mode:"json",width:"100%",height:"100%",showPrintMargin:!0,showGutter:!0,highlightActiveLine:!0,theme:this.props.themeType==="dark"?"clouds_midnight":"chrome",defaultValue:(this.propsValue||"").toString(),onChange:e=>{this.value=e,this.checkJsonError()},name:"UNIQUE_ID_OF_DIV1",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:!0,tabSize:2},editorProps:{$blockScrolling:!0}})}renderStates(){if(this.props.states)if(this.props.type==="number"&&this.props.object.common.max!==void 0&&this.props.object.common.min!==void 0){const e=Object.keys(this.props.states).map(t=>({label:this.props.states[t],value:t}));return s().createElement(is.Z,{className:this.props.classes.formControl,disablePortal:!0,defaultValue:this.props.states[this.propsValue]!==void 0?this.props.states[this.propsValue]:this.propsValue,options:e,noOptionsText:"",freeSolo:!0,getOptionLabel:t=>t.label||(t!=null?t.toString():""),onChange:(t,a)=>this.value=a,onInputChange:(t,a)=>this.value=a,onKeyUp:t=>t.keyCode===13&&this.onUpdate(t),renderInput:t=>s().createElement(N.Z,Aa(Ia({},t),{label:this.props.t("Value"),variant:"standard"}))})}else return s().createElement(Oe.Z,{variant:"standard",className:this.props.classes.formControl},s().createElement(je.Z,null,this.props.t("Value")),s().createElement(Ie.Z,{variant:"standard",defaultValue:this.propsValue,onChange:e=>this.value=e.target.value},Object.keys(this.props.states).map((e,t)=>s().createElement(E.Z,{key:t,value:e},this.props.states[e]))));else return null}render(){var e,t;const a=s().createElement(k.Z,{className:ct.default.clsx(this.props.classes.formControl,this.props.expertMode?"":this.props.classes.ackCheckbox),control:s().createElement(D.Z,{defaultChecked:!1,onChange:o=>this.ack=o.target.checked}),label:this.props.t("Acknowledged")});return s().createElement(te.Z,{open:!0,maxWidth:this.state.type==="number"||this.state.type==="boolean"||this.state.type==="states"?this.state.chart&&this.state.chartEnabled?"lg":null:"md",fullWidth:this.state.type==="json"&&this.state.fullScreen||this.state.type!=="number"&&this.state.type!=="boolean"&&this.state.type!=="states"||this.state.chart&&this.state.chartEnabled,fullScreen:this.state.type==="json"&&this.state.fullScreen,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",classes:{root:this.state.type==="json"?this.props.classes.dialog:""}},s().createElement(K.Z,{id:"edit-value-dialog-title"},this.props.t("Write value"),((e=this.props.object.common)==null?void 0:e.write)===!1?s().createElement("span",{className:this.props.classes.readOnlyText},"(",this.props.t("read only"),")"):null,this.state.chart?s().createElement(Ae.Z,{style:{float:"right"},size:"small",color:this.state.chartEnabled?"primary":"default",onClick:()=>{(window._localStorage||window.localStorage).setItem("App.chartSetValue",this.state.chartEnabled?"false":"true"),this.setState({chartEnabled:!this.state.chartEnabled})}},s().createElement(ya.default,null)):null,this.state.type==="json"?s().createElement(X.Z,{style:{float:"right"},onClick:()=>{(window._localStorage||window.localStorage).setItem("App.fullScreen",this.state.fullScreen?"false":"true"),this.setState({fullScreen:!this.state.fullScreen})}},this.state.fullScreen?s().createElement(wa.Z,null):s().createElement(Ea.Z,null)):null),s().createElement(oe.Z,null,s().createElement("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",onSubmit:()=>!1,style:{height:"100%"}},s().createElement(W.ZP,{container:!0,direction:"row",spacing:2,style:{height:"100%"}},s().createElement(W.ZP,{item:!0,xs:this.state.chart&&this.state.chartEnabled?6:12,style:{height:"100%"}},s().createElement(W.ZP,{container:!0,direction:"column",spacing:2,style:{marginTop:0,height:"100%"}},this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(W.ZP,{container:!0,direction:"row",spacing:2,style:{marginTop:0}},this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(Oe.Z,{className:this.props.classes.formControl},s().createElement(je.Z,null,this.props.t("Value type")),s().createElement(Ie.Z,{variant:"standard",value:this.state.type,onChange:o=>{o.target.value==="json"&&(this.value=(this.value||"").toString(),this.checkJsonError()),this.setState({type:o.target.value})}},s().createElement(E.Z,{value:"string"},"String"),s().createElement(E.Z,{value:"number"},"Number"),s().createElement(E.Z,{value:"boolean"},"Boolean"),s().createElement(E.Z,{value:"json"},"JSON"),this.props.states?s().createElement(E.Z,{value:"states"},"States"):null))):null,this.state.type==="json"?s().createElement(W.ZP,{item:!0,flex:1}):null)):null,s().createElement(W.ZP,{item:!0,flex:this.state.type==="json"&&this.state.fullScreen?1:void 0,style:{paddingTop:0}},this.state.type==="boolean"?s().createElement(I.Z,{component:"div"},s().createElement(W.ZP,{component:"label",container:!0,alignItems:"center",spacing:1},s().createElement(W.ZP,{item:!0,style:{marginRight:10}},this.props.t("Value"),":"),s().createElement(W.ZP,{item:!0},"FALSE"),s().createElement(W.ZP,{item:!0},s().createElement(Da,{autoFocus:!0,defaultChecked:!!this.propsValue,onKeyUp:o=>o.keyCode===13&&this.onUpdate(o),onChange:o=>this.value=o.target.checked})),s().createElement(W.ZP,{item:!0},"TRUE"))):this.state.type==="number"?s().createElement(N.Z,{variant:"standard",classes:{root:this.props.classes.textInput},autoFocus:!0,inputRef:this.inputRef,helperText:this.props.t("Press ENTER to write the value, when focused"),label:this.props.t("Value"),defaultValue:parseFloat(this.propsValue)||0,onKeyUp:o=>{o.keyCode===13&&this.onUpdate(o)},onChange:o=>this.value=o.target.value}):this.state.type==="json"?this.renderJsonEditor():this.state.type==="states"?this.renderStates():s().createElement(N.Z,{variant:"standard",classes:{root:this.props.classes.textInput},inputRef:this.inputRef,autoFocus:!0,helperText:this.props.t("Press CTRL+ENTER to write the value, when focused"),label:this.props.t("Value"),fullWidth:!0,multiline:!0,onKeyDown:o=>o.ctrlKey&&o.keyCode===13&&this.onUpdate(o),defaultValue:this.propsValue.toString(),onChange:o=>this.value=o.target.value})),this.props.expertMode?s().createElement(W.ZP,{item:!0},a):null,this.props.expertMode?s().createElement(W.ZP,{item:!0},s().createElement(Oe.Z,{variant:"standard",className:this.props.classes.quality},s().createElement(je.Z,null,this.props.t("Quality")),s().createElement(Ie.Z,{variant:"standard",defaultValue:0,onChange:o=>this.q=parseInt(o.target.value,10)},s().createElement(E.Z,{value:0},"0x00 - good"),s().createElement(E.Z,{value:1},"0x01 - general problem"),s().createElement(E.Z,{value:2},"0x02 - no connection problem"),s().createElement(E.Z,{value:16},"0x10 - substitute value from controller"),s().createElement(E.Z,{value:32},"0x20 - substitute initial value"),s().createElement(E.Z,{value:64},"0x40 - substitute value from device or instance"),s().createElement(E.Z,{value:128},"0x80 - substitute value from sensor"),s().createElement(E.Z,{value:17},"0x11 - general problem by instance"),s().createElement(E.Z,{value:65},"0x41 - general problem by device"),s().createElement(E.Z,{value:129},"0x81 - general problem by sensor"),s().createElement(E.Z,{value:18},"0x12 - instance not connected"),s().createElement(E.Z,{value:66},"0x42 - device not connected"),s().createElement(E.Z,{value:130},"0x82 - sensor not connected"),s().createElement(E.Z,{value:68},"0x44 - device reports error"),s().createElement(E.Z,{value:132},"0x84 - sensor reports error"))),s().createElement(N.Z,{variant:"standard",title:this.props.t("0 - no expiration"),classes:{root:this.props.classes.expire},label:this.props.t("Expire"),type:"number",inputProps:{min:0},helperText:this.props.t("in seconds"),defaultValue:this.expire,onChange:o=>this.expire=o.target.value})):null)),this.state.chart&&this.state.chartEnabled&&this.state.type!=="json"?s().createElement(va.Z,{only:["sm","xs"]},s().createElement(W.ZP,{item:!0,xs:6,style:{minHeight:300}},this.renderChart())):null))),s().createElement(L.Z,{className:this.props.classes.wrapperButton},this.props.expertMode?null:a,this.props.expertMode?null:s().createElement("div",{style:{flexGrow:1}}),s().createElement(Z.Z,{variant:"contained",onClick:o=>this.onUpdate(o),color:"primary",startIcon:s().createElement(Dt.default,null),className:((t=this.props.object.common)==null?void 0:t.write)===!1?this.props.classes.readOnly:""},this.props.t("Set value")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}ls.propTypes={classes:l().object,type:l().string,states:l().object,value:l().any,expertMode:l().bool,onClose:l().func.isRequired,themeType:l().string,socket:l().object,defaultHistory:l().string,dateFormat:l().string,object:l().object,isFloatComma:l().bool,t:l().func,lang:l().string};var Na=(0,G.withStyles)(Ta)(ls),De=h(27254),Za=h(17773),cs=h(64143),hs=h(78569),Ra=h(98735),Fa=h(23962),ka=h.n(Fa),F=h(94427),Pa=h(94437),Wa=Object.defineProperty,Ma=Object.defineProperties,za=Object.getOwnPropertyDescriptors,ps=Object.getOwnPropertySymbols,Va=Object.prototype.hasOwnProperty,Ha=Object.prototype.propertyIsEnumerable,ds=(r,e,t)=>e in r?Wa(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ja=(r,e)=>{for(var t in e||(e={}))Va.call(e,t)&&ds(r,t,e[t]);if(ps)for(var t of ps(e))Ha.call(e,t)&&ds(r,t,e[t]);return r},La=(r,e)=>Ma(r,za(e));const Ba=r=>({divWithoutTitle:{width:"100%",height:"100%",border:"2px solid #00000000"},divWithoutTitleAndTab:{height:"calc(100% - 48px)"},error:{border:"2px solid #FF0000"},id:{fontStyle:"italic"},dialog:{height:"calc(100% - 64px)"},aliasIdEdit:{width:400-32},button:{marginTop:20,marginLeft:r.spacing(1)},funcDivEdit:{width:"100%"},funcEditName:{display:"inline-block",width:85},funcEdit:{width:400},funcIcon:{width:16,height:16},marginTop:{marginTop:20},commonTabWrapper:{flexFlow:"wrap",display:"flex"},commonWrapper:{width:500,minWidth:300},flexDrop:{width:"100%",maxWidth:500,margin:"auto",display:"flex"},marginBlock:{marginTop:20},buttonAdd:{minWidth:150},textField:{width:"100%"},flex:{display:"flex","& > div":{marginRight:r.spacing(1)}},close:{width:"20px",height:"20px",opacity:"0.9",cursor:"pointer",position:"relative",top:20,transition:"all 0.6s ease","&:hover":{transform:"rotate(90deg)"},"&:before":{position:"absolute",left:"9px",content:'""',height:"20px",width:"3px",backgroundColor:"#ff4f4f",transform:"rotate(45deg)"},"&:after":{position:"absolute",left:"9px",content:'""',height:"20px",width:"3px",backgroundColor:"#ff4f4f",transform:"rotate(-45deg)"}},color:{width:70},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},tabsPadding:{padding:"0px 24px"},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:10}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:9}}}});class ms extends C.Component{constructor(e){var t,a,o,i;super(e);const n=this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state";let c=(window._localStorage||window.localStorage).getItem((this.props.dialogName||"App")+".editTab")||"object";c==="alias"&&!n&&(c="common"),this.state={text:JSON.stringify(this.props.obj,null,2),error:!1,changed:!1,readError:this.checkFunction((a=(t=this.props.obj.common)==null?void 0:t.alias)==null?void 0:a.read,!1),writeError:this.checkFunction((i=(o=this.props.obj.common)==null?void 0:o.alias)==null?void 0:i.write,!0),tab:c,showCopyDialog:!1},this.isMobile=window.innerWidth<850,this.originalObj=JSON.stringify(this.props.obj,null,2)}checkFunction(e,t){var a,o,i,n,c;if(e){if(e.includes("JSON.parse("))return"";{let d;try{d=JSON.parse(this.state.text)}catch(f){}let m;try{m=new Function("val",e.includes("return")?e:"return "+e)}catch(f){return this.props.t("Cannot parse code!")}if(((a=d==null?void 0:d.common)==null?void 0:a.type)&&((c=(n=this.props.objects[(i=(o=d.common)==null?void 0:o.alias)==null?void 0:i.id])==null?void 0:n.common)==null?void 0:c.type)){const f=t?d.common.type:this.props.objects[d.common.alias.id].common.type,p=t?this.props.objects[d.common.alias.id].common.type:d.common.type;if(f&&p){let j=null;if(f==="boolean"?j=!0:f==="number"?j=1:f==="string"&&(j="string"),j!==null)try{const A=m(j);return A!==null&&typeof A!==p?this.props.t("Type of result is not as expected: %s",p):""}catch(A){return this.props.t("Cannot execute function")+": "+A.toString()}}}return""}}else return""}prepareObject(e){var t,a,o,i;e=e||this.state.text;try{const n=JSON.parse(e);return n._id=this.props.obj._id,(t=n.common)!=null&&t.alias&&(n.common.alias.id||delete n.common.alias.id,(!n.common.alias.read&&n.common.alias.read!==void 0||n.common.alias.read==="val")&&delete n.common.alias.read,(!n.common.alias.write&&n.common.alias.write!==void 0||n.common.alias.write==="val")&&delete n.common.alias.write,!n.common.alias.id&&!n.common.alias.read&&!n.common.alias.write&&delete n.common.alias),((a=n.common)==null?void 0:a.min)!==void 0&&typeof n.common.min!="number"&&(n.common.min=parseFloat(n.common.min)),((o=n.common)==null?void 0:o.max)!==void 0&&typeof n.common.max!="number"&&(n.common.max=parseFloat(n.common.max)),((i=n.common)==null?void 0:i.step)!==void 0&&typeof n.common.step!="number"&&(n.common.step=parseFloat(n.common.step)),n}catch(n){return null}}onChange(e,t){var a,o,i,n;const c=this.prepareObject(e),d={text:e};c?(d.changed=this.originalObj!==JSON.stringify(c,null,2),this.state.error&&(d.error=!1),d.readError=this.checkFunction((o=(a=c.common)==null?void 0:a.alias)==null?void 0:o.read,!1),d.writeError=this.checkFunction((n=(i=c.common)==null?void 0:i.alias)==null?void 0:n.write,!0)):d.error=!0,this.setState(d,()=>t&&t())}onUpdate(){var e,t,a,o;try{const i=JSON.parse(this.state.text);i._id=this.props.obj._id,(e=i.common)!=null&&e.alias&&(i.common.alias.id||delete i.common.alias.id,(!i.common.alias.read&&i.common.alias.read!==void 0||i.common.alias.read==="val")&&delete i.common.alias.read,(!i.common.alias.write&&i.common.alias.write!==void 0||i.common.alias.write==="val")&&delete i.common.alias.write,!i.common.alias.id&&!i.common.alias.read&&!i.common.alias.write&&delete i.common.alias),((t=i.common)==null?void 0:t.min)!==void 0&&typeof i.common.min!="number"&&(i.common.min=parseFloat(i.common.min)),((a=i.common)==null?void 0:a.max)!==void 0&&typeof i.common.max!="number"&&(i.common.max=parseFloat(i.common.max)),((o=i.common)==null?void 0:o.step)!==void 0&&typeof i.common.step!="number"&&(i.common.step=parseFloat(i.common.step)),this.props.onClose(i)}catch(i){console.log.error(`Cannot parse: ${this.state.text}`)}}renderTabs(){return s().createElement(He.Z,{className:this.props.classes.tabsPadding,value:this.state.tab,onChange:(e,t)=>{var a,o,i;if((window._localStorage||window.localStorage).setItem((this.props.dialogName||"App")+".editTab",t),t==="object")try{const n=JSON.parse(this.state.text);let c=!1;((a=n.common)==null?void 0:a.min)!==void 0&&typeof n.common.min!="number"&&(n.common.min=parseFloat(n.common.min),c=!0),((o=n.common)==null?void 0:o.max)!==void 0&&typeof n.common.max!="number"&&(n.common.max=parseFloat(n.common.max),c=!0),((i=n.common)==null?void 0:i.step)!==void 0&&typeof n.common.step!="number"&&(n.common.step=parseFloat(n.common.step),c=!0),c&&this.setState({text:JSON.stringify(n,null,2)})}catch(n){}this.setState({tab:t})}},s().createElement(he.Z,{value:"common",label:this.props.t("Common")}),s().createElement(he.Z,{value:"object",label:this.props.t("Object data")}),this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state"&&s().createElement(he.Z,{value:"alias",label:this.props.t("Alias")}))}renderSelectDialog(){var e,t,a,o,i,n,c,d;if(!this.state.selectId&&!this.state.selectRead&&!this.state.selectWrite)return null;let m="",f;try{f=JSON.parse(this.state.text),this.state.selectId?m=((t=(e=f.common)==null?void 0:e.alias)==null?void 0:t.id)||"":this.state.selectRead?m=((i=(o=(a=f.common)==null?void 0:a.alias)==null?void 0:o.id)==null?void 0:i.read)||"":this.state.selectWrite&&(m=((d=(c=(n=f.common)==null?void 0:n.alias)==null?void 0:c.id)==null?void 0:d.write)||"")}catch(p){console.error("Cannot parse "+this.state.text)}return s().createElement(Ra.default,{key:"selectDialog",imagePrefix:".",dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,socket:this.props.socket,dialogName:"aliasesEdit",title:`${this.props.t("Select for")} ${this.props.obj._id}`,selected:m,statesOnly:!0,onOk:p=>{const j=this.state.selectRead,A=this.state.selectWrite,ne=this.state.selectId;this.setState({selectId:!1,selectRead:!1,selectWrite:!1},()=>{j?this.setAliasItem(f,"id.read",p):A?this.setAliasItem(f,"id.write",p):ne&&this.setAliasItem(f,"id",p)})},onClose:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!1})})}setAliasItem(e,t,a,o){e.common=e.common||{},e.common.alias=e.common.alias||{},t==="id.read"?e.common.alias.id&&typeof e.common.alias.id=="object"?e.common.alias.id.read=a:e.common.alias.id={read:a,write:a}:t==="id.write"?e.common.alias.id&&typeof e.common.alias.id=="object"?e.common.alias.id.write=a:e.common.alias.id={read:a,write:a}:e.common.alias[t]=a,this.onChange(JSON.stringify(e,null,2),o)}setCommonItem(e,t,a){e.common[t]=a,this.onChange(JSON.stringify(e,null,2))}removeCommonItem(e,t){delete e.common[t],this.onChange(JSON.stringify(e,null,2))}buttonAddKey(e,t){const{classes:a}=this.props;return s().createElement("div",{className:a.marginBlock},s().createElement(Z.Z,{className:a.buttonAdd,variant:"contained",color:"secondary",startIcon:s().createElement(Za.default,null),onClick:t},e))}buttonRemoveKey(e,t){const{t:a,classes:o}=this.props;return s().createElement(F.Tooltip,{title:a("Remove attribute %s",e)},s().createElement("div",{className:o.close,onClick:t}))}renderCommonEdit(){try{const e=JSON.parse(this.state.text),t=["boolean","json","string","number","multistate","file","object","mixed"],a=!1,{classes:o,t:i,roleArray:n,obj:c}=this.props,d=c.type==="state",m=c.type==="channel"||c.type==="device"||d;let f;if(typeof e.common.icon!="undefined"&&(f=e.type==="instance"||e.type==="adapter"?`./adapter/${e.common.name}/${e.common.icon}`:e.common.icon,!f.startsWith(".")&&!f.startsWith("/")&&!f.startsWith("data:"))){const p=c._id.split(".");p[0]==="system"?f=`adapter/${p[2]}${f.startsWith("/")?"":"/"}${f}`:f=`adapter/${p[0]}${f.startsWith("/")?"":"/"}${f}`}return s().createElement("div",{className:o.commonTabWrapper},s().createElement("div",{className:o.commonWrapper},typeof e.common.name!="undefined"?s().createElement(N.Z,{variant:"standard",disabled:a,label:i("Name"),className:(0,V.default)(o.marginBlock,o.textField),fullWidth:!0,value:ct.default.getObjectNameFromObj(e,P.default.getLanguage(),null,!1,!0),onChange:p=>this.setCommonItem(e,"name",p.target.value)}):this.buttonAddKey("name",()=>this.setCommonItem(e,"name","")),d?typeof e.common.type!="undefined"?s().createElement("div",{className:o.flex},s().createElement(F.FormControl,{className:o.marginBlock,fullWidth:!0},s().createElement(F.InputLabel,null,i("State type")),s().createElement(F.Select,{variant:"standard",disabled:a,value:e.common.type,onChange:p=>this.setCommonItem(e,"type",p.target.value)},t.map(p=>s().createElement(F.MenuItem,{key:p,value:p},i(p))))),this.buttonRemoveKey("type",()=>this.removeCommonItem(e,"type"))):this.buttonAddKey("type",()=>this.setCommonItem(e,"type","string")):null,s().createElement("div",{className:o.flex},d?typeof e.common.read!="undefined"?s().createElement("div",{className:o.flex},s().createElement(k.Z,{className:o.marginBlock,control:s().createElement(D.Z,{disabled:a,checked:e.common.read,onClick:p=>this.setCommonItem(e,"read",p.target.checked)}),label:i("Readable")}),this.buttonRemoveKey("read",()=>this.removeCommonItem(e,"read"))):this.buttonAddKey("read",()=>this.setCommonItem(e,"read",!0)):null,d?typeof e.common.write!="undefined"?s().createElement("div",{className:o.flex},s().createElement(k.Z,{className:o.marginBlock,control:s().createElement(D.Z,{disabled:a,checked:e.common.write,onClick:p=>this.setCommonItem(e,"write",p.target.checked)}),label:i("Writeable")}),this.buttonRemoveKey("write",()=>this.removeCommonItem(e,"write"))):this.buttonAddKey("write",()=>this.setCommonItem(e,"write",!0)):null),m?typeof e.common.role!="undefined"?s().createElement("div",{className:o.flex},s().createElement(F.Autocomplete,{className:o.marginBlock,fullWidth:!0,disabled:a,value:e.common.role,onChange:(p,j)=>this.setCommonItem(e,"role",j),options:n,renderInput:p=>s().createElement(N.Z,La(Ja({variant:"standard"},p),{label:i("Role")}))}),this.buttonRemoveKey("role",()=>this.removeCommonItem(e,"role"))):this.buttonAddKey("role",()=>this.setCommonItem(e,"role","")):null,typeof e.common.color!="undefined"?s().createElement("div",{className:o.flex},s().createElement(N.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Color"),type:"color",value:e.common.color,onChange:p=>this.setCommonItem(e,"color",p.target.value)}),this.buttonRemoveKey("color",()=>this.removeCommonItem(e,"color"))):this.buttonAddKey("color",()=>this.setCommonItem(e,"color","")),s().createElement("div",{className:o.flex},e.common.type==="number"?typeof e.common.min!="undefined"?s().createElement("div",{className:o.flex},s().createElement(N.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Min"),value:e.common.min,onChange:p=>this.setCommonItem(e,"min",p.target.value)}),this.buttonRemoveKey("min",()=>this.removeCommonItem(e,"min"))):s().createElement("div",{className:o.flex},this.buttonAddKey("min",()=>this.setCommonItem(e,"min",0))):null,e.common.type==="number"?typeof e.common.max!="undefined"?s().createElement("div",{className:o.flex},s().createElement(N.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Max"),value:e.common.max,onChange:p=>this.setCommonItem(e,"max",p.target.value)}),this.buttonRemoveKey("max",()=>this.removeCommonItem(e,"max"))):s().createElement("div",{className:o.flex},this.buttonAddKey("max",()=>this.setCommonItem(e,"max",100))):null,e.common.type==="number"?typeof e.common.step!="undefined"?s().createElement("div",{className:o.flex},s().createElement(N.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Step"),value:e.common.step,onChange:p=>this.setCommonItem(e,"step",p.target.value)}),this.buttonRemoveKey("step",()=>this.removeCommonItem(e,"step"))):s().createElement("div",{className:o.flex},this.buttonAddKey("step",()=>this.setCommonItem(e,"step",1))):null),e.common.type==="number"?typeof e.common.unit!="undefined"?s().createElement("div",{className:o.flex},s().createElement(N.Z,{variant:"standard",disabled:a,className:(0,V.default)(o.marginBlock,o.color),label:i("Unit"),value:e.common.unit,onChange:p=>this.setCommonItem(e,"unit",p.target.value)}),this.buttonRemoveKey("unit",()=>this.removeCommonItem(e,"unit"))):s().createElement("div",{className:o.flexDrop},this.buttonAddKey("unit",()=>this.setCommonItem(e,"unit",""))):null),typeof e.common.icon!="undefined"?s().createElement("div",{className:o.flex,style:{flexGrow:1}},s().createElement(Pa.Z,{disabled:a,maxSize:10*1024,icon:f,removeIconFunc:()=>this.setCommonItem(e,"icon",""),onChange:p=>this.setCommonItem(e,"icon",p),t:i}),this.buttonRemoveKey("icon",()=>this.removeCommonItem(e,"icon"))):s().createElement("div",{className:o.flex},this.buttonAddKey("icon",()=>this.setCommonItem(e,"icon",""))))}catch(e){return s().createElement("div",null,this.props.t("Cannot parse JSON!"))}}renderAliasEdit(){var e,t,a,o,i,n,c,d,m,f,p,j,A,ne,U,ge,Q,Ne,Le,Ze,de,Re,O,at,Be,ot,Ue,ut,Ye,ft,gt,vt,bt,yt,it,Et,rt,wt,Ge,Ct;try{const w=JSON.parse(this.state.text),Ke=((t=(e=w.common)==null?void 0:e.alias)==null?void 0:t.read)!==void 0||((o=(a=w.common)==null?void 0:a.alias)==null?void 0:o.write)!==void 0;return s().createElement(W.ZP,{container:!0,direction:"column",className:this.props.classes.marginTop},s().createElement(W.ZP,{item:!0},s().createElement(k.Z,{control:s().createElement(D.Z,{checked:typeof((n=(i=w.common)==null?void 0:i.alias)==null?void 0:n.id)=="object",onChange:()=>{var ee,Ee,Fe,b,$,ae,we;typeof((Ee=(ee=w.common)==null?void 0:ee.alias)==null?void 0:Ee.id)=="object"?this.setAliasItem(w,"id",(($=(b=(Fe=w.common)==null?void 0:Fe.alias)==null?void 0:b.id)==null?void 0:$.read)||""):this.setAliasItem(w,"id.read",((we=(ae=w.common)==null?void 0:ae.alias)==null?void 0:we.id)||"")}}),label:this.props.t("Different IDs for read and write")})),typeof((d=(c=w.common)==null?void 0:c.alias)==null?void 0:d.id)!="object"?s().createElement(W.ZP,{item:!0},s().createElement(N.Z,{variant:"standard",label:this.props.t("Alias state"),value:((f=(m=w.common)==null?void 0:m.alias)==null?void 0:f.id)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(j=(p=w.common)==null?void 0:p.alias)!=null&&j.id?s().createElement(De.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!0,selectRead:!1,selectWrite:!1})},"...")):null,typeof((ne=(A=w.common)==null?void 0:A.alias)==null?void 0:ne.id)=="object"?s().createElement(W.ZP,{item:!0},s().createElement(N.Z,{variant:"standard",label:this.props.t("Alias read state"),value:((Q=(ge=(U=w.common)==null?void 0:U.alias)==null?void 0:ge.id)==null?void 0:Q.read)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(Ze=(Le=(Ne=w.common)==null?void 0:Ne.alias)==null?void 0:Le.id)!=null&&Ze.read?s().createElement(De.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id.read","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id.read",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!0,selectWrite:!1})},"...")):null,typeof((Re=(de=w.common)==null?void 0:de.alias)==null?void 0:Re.id)=="object"?s().createElement(W.ZP,{item:!0},s().createElement(N.Z,{variant:"standard",label:this.props.t("Alias write state"),value:((Be=(at=(O=w.common)==null?void 0:O.alias)==null?void 0:at.id)==null?void 0:Be.write)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(ut=(Ue=(ot=w.common)==null?void 0:ot.alias)==null?void 0:Ue.id)!=null&&ut.write?s().createElement(De.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"id.write","")},s().createElement(J.default,null))):null},onChange:ee=>this.setAliasItem(w,"id.write",ee.target.value),margin:"normal"}),s().createElement(Ae.Z,{className:this.props.classes.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!0})},"...")):null,s().createElement(W.ZP,{item:!0,className:this.props.classes.marginTop},s().createElement(k.Z,{control:s().createElement(D.Z,{checked:((ft=(Ye=w.common)==null?void 0:Ye.alias)==null?void 0:ft.read)!==void 0||((vt=(gt=w.common)==null?void 0:gt.alias)==null?void 0:vt.write)!==void 0,onChange:()=>{Ke?(delete w.common.alias.read,delete w.common.alias.write):(w.common=w.common||{},w.common.alias=w.common.alias||{},w.common.alias.read="val",w.common.alias.write="val"),this.onChange(JSON.stringify(w,null,2))}}),label:this.props.t("Use convert functions")})),Ke?s().createElement(W.ZP,{item:!0},s().createElement(N.Z,{variant:"standard",label:this.props.t("Read converter"),value:((yt=(bt=w.common)==null?void 0:bt.alias)==null?void 0:yt.read)||"val",className:this.props.classes.funcEdit,error:!!this.state.readError,InputProps:{endAdornment:(Et=(it=w.common)==null?void 0:it.alias)!=null&&Et.read?s().createElement(De.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"read","")},s().createElement(J.default,null))):null,startAdornment:s().createElement(De.Z,{position:"start"},s().createElement(hs.Z,{className:this.props.classes.funcIcon}))},onChange:ee=>this.setAliasItem(w,"read",ee.target.value),helperText:this.state.readError||this.props.t("JS function like")+' "val / 5 + 21"',margin:"normal"})):null,Ke?s().createElement(W.ZP,{item:!0},s().createElement(N.Z,{variant:"standard",label:this.props.t("Write converter"),error:!!this.state.writeError,value:((wt=(rt=w.common)==null?void 0:rt.alias)==null?void 0:wt.write)||"val",helperText:this.state.writeError||this.props.t("JS function like")+' "(val - 21) * 5"',className:this.props.classes.funcEdit,InputProps:{endAdornment:(Ct=(Ge=w.common)==null?void 0:Ge.alias)!=null&&Ct.write?s().createElement(De.Z,{position:"end"},s().createElement(X.Z,{size:"large",onClick:()=>this.setAliasItem(w,"write","")},s().createElement(J.default,null))):null,startAdornment:s().createElement(De.Z,{position:"start"},s().createElement(hs.Z,{className:this.props.classes.funcIcon}))},onChange:ee=>this.setAliasItem(w,"write",ee.target.value),margin:"normal"})):null)}catch(w){return s().createElement("div",null,this.props.t("Cannot parse JSON!"))}}onCopy(e){e.stopPropagation(),e.preventDefault(),ka()(this.state.text),window.alert(this.props.t("ra_Copied"))}onClone(e,t,a){const o=JSON.parse(JSON.stringify(this.props.objects[e]));delete o.from,delete o.ts,delete o.user,o._id=t,this.props.objects[o._id]=o,this.props.onNewObject(o)}renderCopyDialog(){return this.state.showCopyDialog?s().createElement(te.Z,{open:!0,maxWidth:"md",fullWidth:!0,onClose:()=>this.setState({showCopyDialog:!1})},s().createElement(K.Z,null,this.props.t("Enter new ID for this object")),s().createElement(oe.Z,null,s().createElement(N.Z,{variant:"standard",autoFocus:!0,fullWidth:!0,label:this.props.t("New object ID"),value:this.state.newId,onKeyDown:e=>{e.keyCode===13&&!this.props.objects[this.state.newId]&&(this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId))},onChange:e=>this.setState({newId:e.target.value})})),s().createElement(L.Z,null,s().createElement(Z.Z,{disabled:!!this.props.objects[this.state.newId],onClick:()=>{this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId)},color:"primary",startIcon:s().createElement(cs.Z,null)},this.props.t("Clone")),s().createElement(Z.Z,{color:"grey",onClick:()=>this.setState({showCopyDialog:""}),startIcon:s().createElement(J.default,null)},this.props.t("Cancel")))):null}render(){const e=this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state";return s().createElement(te.Z,{classes:{paper:this.props.classes.dialog},open:!0,maxWidth:"lg",fullWidth:this.state.type!=="number"&&this.state.type!=="boolean",fullScreen:!1,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description"},s().createElement(K.Z,{id:"edit-value-dialog-title"},this.props.t("Edit object:")," ",s().createElement("span",{className:this.props.classes.id},this.props.obj._id)),this.renderTabs(),this.renderCopyDialog(),s().createElement(oe.Z,null,this.state.tab==="object"?s().createElement("div",{className:(0,V.default)(this.props.classes.divWithoutTitle,e&&this.props.classes.divWithoutTitleAndTab,this.state.error&&this.props.classes.error)},s().createElement(os(),{mode:"json",width:"100%",height:"100%",theme:this.props.themeName==="dark"?"clouds_midnight":"chrome",value:this.state.text,onChange:t=>this.onChange(t),name:"UNIQUE_ID_OF_DIV",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0},editorProps:{$blockScrolling:!0}})):null,this.state.tab==="alias"&&this.props.obj._id.startsWith("alias.0")&&this.props.obj.type==="state"?this.renderAliasEdit():null,this.state.tab==="common"?this.renderCommonEdit():null,this.renderSelectDialog()),s().createElement(L.Z,{className:this.props.classes.wrapperButton},s().createElement(Z.Z,{color:"grey",onClick:()=>this.setState({showCopyDialog:this.props.obj._id,newId:this.props.obj._id}),disabled:this.state.error||this.state.changed,title:this.props.t("Create a copy of this object")},s().createElement(cs.Z,null)),s().createElement("div",{style:{flexGrow:1}}),this.state.tab==="object"&&s().createElement(Z.Z,{color:"grey",onClick:t=>this.onCopy(t),disabled:this.state.error,title:this.isMobile?this.props.t("Copy into clipboard"):"",startIcon:s().createElement(pt.FaClipboard,null)},this.isMobile?null:this.props.t("Copy into clipboard")),s().createElement(Z.Z,{variant:"contained",disabled:this.state.error||!this.state.changed,onClick:()=>this.onUpdate(),startIcon:s().createElement(Dt.default,null),color:"primary"},this.props.t("Write")),s().createElement(Z.Z,{color:"grey",variant:"contained",onClick:()=>this.props.onClose(),startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}ms.propTypes={classes:l().object,socket:l().object,obj:l().object,expertMode:l().bool,themeName:l().string,onClose:l().func.isRequired,dialogName:l().string,objects:l().object,dateFormat:l().string,isFloatComma:l().bool,onNewObject:l().func,t:l().func};var Ua=(0,G.withStyles)(Ba)(ms),Ya=Object.defineProperty,Ga=Object.defineProperties,Ka=Object.getOwnPropertyDescriptors,us=Object.getOwnPropertySymbols,Qa=Object.prototype.hasOwnProperty,Xa=Object.prototype.propertyIsEnumerable,fs=(r,e,t)=>e in r?Ya(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,$a=(r,e)=>{for(var t in e||(e={}))Qa.call(e,t)&&fs(r,t,e[t]);if(us)for(var t of us(e))Xa.call(e,t)&&fs(r,t,e[t]);return r},qa=(r,e)=>Ga(r,Ka(e));const _a=r=>({input:{marginBottom:r.spacing(2)},inputText:{width:400,height:300,marginBottom:r.spacing(2)},formControl:{marginBottom:r.spacing(2),minWidth:150},quality:{width:"100%"}});class gs extends C.Component{constructor(e){super(e),this.state={role:null,initRole:null,roleInput:null}}componentDidMount(){this.props.socket.getObject(this.props.id).then(e=>{var t;this.object=e;const a=((t=e==null?void 0:e.common)==null?void 0:t.role)||null;this.setState({role:a,initRole:a,roleInput:a})}).catch(e=>console.error(e))}onUpdate(){this.object.common=this.object.common||{},this.object.common.role=this.state.roleInput,this.props.socket.setObject(this.object._id,this.object).then(()=>this.props.onClose(this.object))}render(){return s().createElement(te.Z,{key:"objectBrowserEditRole",open:!0,maxWidth:"sm",fullWidth:!0,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-role-dialog-title","aria-describedby":"edit-role-dialog-description"},s().createElement(K.Z,{id:"edit-role-dialog-title"},this.object?this.props.t("Update role for %s",this.object._id):null),s().createElement(oe.Z,null,s().createElement(is.Z,{freeSolo:!0,options:this.props.roles,style:{width:"100%"},value:this.state.role,onChange:(e,t)=>this.setState({role:t,roleInput:t}),onInputChange:(e,t)=>this.setState({roleInput:t}),renderInput:e=>s().createElement(N.Z,qa($a({},e),{label:this.props.t("Role"),variant:"outlined"}))})),s().createElement(L.Z,null,s().createElement(Z.Z,{disabled:this.state.initRole===this.state.roleInput,variant:"contained",onClick:()=>this.onUpdate(),color:"primary",startIcon:s().createElement(Dt.default,null)},this.props.t("Apply")),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:s().createElement(J.default,null)},this.props.t("Cancel"))))}}gs.propTypes={classes:l().object,roles:l().array,id:l().string,socket:l().object,onClose:l().func.isRequired,t:l().func};var eo=(0,G.withStyles)(_a)(gs),to=h(4050),ye=h(61984),vs=h(43253),so=Object.defineProperty,ao=Object.defineProperties,oo=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,io=Object.prototype.hasOwnProperty,ro=Object.prototype.propertyIsEnumerable,ys=(r,e,t)=>e in r?so(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Es=(r,e)=>{for(var t in e||(e={}))io.call(e,t)&&ys(r,t,e[t]);if(bs)for(var t of bs(e))ro.call(e,t)&&ys(r,t,e[t]);return r},ws=(r,e)=>ao(r,oo(e));const no=["boolean","string","number","array","json","object","mixed"],lo={boolean:!1,string:"",number:0},ce={state:{name:"Datapoint",value:"state"},channel:{name:"Channel",value:"channel"},device:{name:"Device",value:"device"},folder:{name:"Folder",value:"folder"}};var co=({onClose:r,onApply:e,open:t,selected:a,setObject:o,objects:i,expertMode:n})=>{var c;const d={state:P.default.t("New state"),channel:P.default.t("New channel"),device:P.default.t("New device"),folder:P.default.t("New folder")},m=[],f=(c=i[a])==null?void 0:c.type;let p="";i[a]?f==="channel"?(m.push(ce.state),p="state"):f==="device"?(p="channel",m.push(ce.state),m.push(ce.channel)):f==="state"?p="":(m.push(ce.state),m.push(ce.channel),m.push(ce.device),a.startsWith("0_userdata.")||a.startsWith("alias.0.")||a==="0_userdata"||a==="alias.0"?(m.push(ce.folder),p="folder"):p="state"):(m.push(ce.folder),p="folder",n&&(a.startsWith("mqtt.")||a.startsWith("javascript."))&&(m.push(ce.state),m.push(ce.channel),m.push(ce.device)));const j=(window._localStorage||window.localStorage).getItem("App.lastObjectType");j&&m.find(O=>O.value===j)&&(p=j);const[A,ne]=(0,C.useState)(p),[U,ge]=(0,C.useState)(d[p]),[Q,Ne]=(0,C.useState)((window._localStorage||window.localStorage).getItem("App.lastStateType")||"string"),[Le,Ze]=(0,C.useState)(!i[de(d.state)]);function de(O){return a+"."+O.toString().replace(ye.Z.FORBIDDEN_CHARS,"_").replace(/\s/g,"_").replace(/\./g,"_")}const Re=()=>{const O={common:{name:U,desc:P.default.t("Manually created")},type:A};A==="state"?(O.common=ws(Es({},O.common),{role:"state",type:Q,read:!0,write:!0,def:lo[Q]}),O.native={}):A!=="folder"?O.common=ws(Es({},O.common),{role:"",icon:""}):delete O.common.desc,o(`${a}.${U.split(" ").join("_")}`,O).then(()=>e())};return t?s().createElement(vs.Z,{open:!0,fullWidth:!0,maxWidth:"lg",titleButtonApply:"add",applyDisabled:!U||!Le||!m.length,onClose:r,onApply:()=>Re()},s().createElement("div",{style:{display:"flex",flexDirection:"column"}},s().createElement("div",{style:{margin:10,fontSize:20}},s().createElement(to.Z,null),P.default.t("Add new object:"),s().createElement("span",{style:{fontStyle:"italic"}},a,".",U)),s().createElement(F.TextField,{variant:"standard",label:P.default.t("Parent"),style:{margin:"5px 0"},disabled:!0,value:a}),s().createElement(F.FormControl,{variant:"standard",style:{marginTop:10,marginBottom:16}},s().createElement(F.InputLabel,null,P.default.t("Type")),s().createElement(F.Select,{variant:"standard",value:A,onChange:O=>{(window._localStorage||window.localStorage).setItem("App.lastObjectType",O.target.value),U===d[A]&&(ge(d[O.target.value]),Ze(i[de(d[O.target.value])])),ne(O.target.value)}},m.map(O=>s().createElement(F.MenuItem,{key:O.value,value:O.value},P.default.t(O.name))))),A==="state"&&s().createElement(F.FormControl,{style:{marginTop:10,marginBottom:16}},s().createElement(F.InputLabel,{style:{left:-14}},P.default.t("State type")),s().createElement(F.Select,{style:{marginTop:6},variant:"standard",value:Q,onChange:O=>{(window._localStorage||window.localStorage).setItem("App.lastStateType",O.target.value),Ne(O.target.value)}},no.map(O=>s().createElement(F.MenuItem,{key:O,value:O},O)))),s().createElement(F.TextField,{variant:"standard",label:P.default.t("Name"),style:{margin:"5px 0"},autoFocus:!0,value:U,onKeyDown:O=>{O.keyCode===13&&(O.preventDefault(),U&&Re())},onChange:O=>{Ze(!i[de(O.target.value)]),ge(O.target.value)}}))):null},mt=h(94475),ho=(r,e,t)=>new Promise((a,o)=>{var i=d=>{try{c(t.next(d))}catch(m){o(m)}},n=d=>{try{c(t.throw(d))}catch(m){o(m)}},c=d=>d.done?a(d.value):Promise.resolve(d.value).then(i,n);c((t=t.apply(r,e)).next())});const po=[{Owner:[{name:"read",valueNum:1024,title:"read owner"},{name:"write",valueNum:512,title:"write owner"}]},{Group:[{name:"read",valueNum:64,title:"read group"},{name:"write",valueNum:32,title:"write group"}]},{Everyone:[{name:"read",valueNum:4,title:"read everyone"},{name:"write",valueNum:2,title:"write everyone"}]}],Cs=(r,e,t)=>(r|=e&t,r&=e|~t&65535,r),Ss=({value:r,disabled:e,setValue:t,t:a,differentValues:o,applyToChildren:i,mask:n,setMask:c})=>{(0,C.useEffect)(()=>{if(i){let m=0;for(let f=0;f<o.length;f++)m|=r^o[f];c(m)}else c(0)},[o,i]);let d=r;return s().createElement("div",{style:{display:"flex",width:"fit-content",margin:20,border:"1px solid",borderLeft:0}},po.map(m=>{const f=Object.keys(m)[0];return s().createElement("div",{style:{width:150,height:150,display:"flex",flexDirection:"column",alignItems:"center",borderLeft:"1px solid"},key:f},s().createElement("div",{style:{height:50,display:"flex",alignItems:"center",fontSize:18,borderBottom:"1px solid silver",width:"100%",justifyContent:"center"}},a(f)),s().createElement("div",{style:{display:"flex",width:"100%"}},m[f].map((p,j)=>{let A=!1;return d-p.valueNum>=0&&(d=d-p.valueNum,A=!0),s().createElement("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",borderRight:j===0?"1px solid":0},key:p.valueNum},s().createElement("div",{style:{height:50,borderBottom:"1px solid",width:"100%",justifyContent:"center",display:"flex",alignItems:"center",color:"silver"}},a(p.name)),s().createElement("div",{style:{height:50,display:"flex"}},s().createElement(F.Checkbox,{disabled:e,checked:A,color:n&p.valueNum?"primary":"secondary",indeterminate:!!(n&p.valueNum),style:n&p.valueNum?{opacity:.5}:null,onChange:ne=>{n&p.valueNum&&(n&=~p.valueNum&65535,c(n));let U=r;ne.target.checked?U|=p.valueNum:U&=~p.valueNum&65535,t(U)}})))})))}))};var mo=({onClose:r,onApply:e,open:t,selected:a,extendObject:o,objects:i,t:n,modalEmptyId:c,themeType:d})=>{const[m,f]=(0,C.useState)(null),[p,j]=(0,C.useState)(null),[A,ne]=(0,C.useState)([]),[U,ge]=(0,C.useState)([]),[Q,Ne]=(0,C.useState)(!1),[Le,Ze]=(0,C.useState)(!1),[de,Re]=(0,C.useState)(0),[O,at]=(0,C.useState)(null),[Be,ot]=(0,C.useState)(null),[Ue,ut]=(0,C.useState)(!1),[Ye,ft]=(0,C.useState)(!1),[gt,vt]=(0,C.useState)([]),[bt,yt]=(0,C.useState)([]),[it,Et]=(0,C.useState)(0),[rt,wt]=(0,C.useState)(0),[Ge,Ct]=(0,C.useState)([]),[w,Ke]=(0,C.useState)(!1),[ee,Ee]=(0,C.useState)(!0),Fe=n("different");return(0,C.useEffect)(()=>{var b,$,ae,we;let ke=0,ve=[],Nt=[],Os=a||c,So=Os+".";const Is=Object.keys(i).sort();let Zt=!1,Rt=[],Ft=[];const As=P.default.getLanguage();let Ts=!1,Ds=!1,Qe=null,Xe=null,Pe=null,We=null;const Ns=[];for(let Me=0;Me<Is.length;Me++){const Ce=Is[Me],T=i[Ce];if(T&&(Ce===Os||Ce.startsWith(So))){if(ke++,Ns.push(Ce),!T.acl)continue;Pe===null&&T.acl.object!==void 0&&(Pe=T.acl.object),We===null&&T.acl.state!==void 0&&(We=T.acl.state),Qe===null&&T.acl.owner!==void 0&&(Qe=T.acl.owner),Xe===null&&T.acl.ownerGroup!==void 0&&(Xe=T.acl.ownerGroup),!Ue&&Qe!==T.acl.owner&&T.acl.owner!==void 0&&(Ts=!0),!Ye&&Xe!==T.acl.ownerGroup&&T.acl.ownerGroup!==void 0&&(Ds=!0),T.acl.state!==void 0&&We!==T.acl.state&&!ve.includes(T.acl.state)&&ve.push(T.acl.state),T.acl.object!==void 0&&Pe!==T.acl.object&&!Nt.includes(T.acl.object)&&Nt.push(T.acl.object),T.type==="state"&&(Zt=!0)}Ce.startsWith("system.group.")&&(T==null?void 0:T.type)==="group"?Rt.push({name:ye.Z.getObjectNameFromObj(T,As).replace("system.group.",""),value:Ce,icon:(b=T.common)==null?void 0:b.icon,color:($=T.common)==null?void 0:$.color}):Ce.startsWith("system.user.")&&(T==null?void 0:T.type)==="user"&&Ft.push({name:ye.Z.getObjectNameFromObj(T,As).replace("system.user.",""),value:Ce,icon:(ae=T.common)==null?void 0:ae.icon,color:(we=T.common)==null?void 0:we.color})}Qe=Qe||i["system.config"].common.defaultNewAcl.owner,Xe=Xe||i["system.config"].common.defaultNewAcl.ownerGroup,Pe=Pe||i["system.config"].common.defaultNewAcl.object,at(isNaN(Pe)?i["system.config"].common.defaultNewAcl.object:Pe),Zt&&(We=We||i["system.config"].common.defaultNewAcl.state,ot(isNaN(We)?i["system.config"].common.defaultNewAcl.state:We));const xo=Ft.find(Me=>Me.value===Qe),jo=Rt.find(Me=>Me.value===Xe);f(xo),j(jo),ut(Ts),ft(Ds),ne(Ft),ge(Rt),Zt&&Ze(!0),c&&Ne(!0),Re(ke),vt(ve),yt(Nt),Ct(Ns)},[i,a]),(0,C.useEffect)(()=>{Q?(Ye&&(p.value!=="different"&&j({name:Fe,value:"different"}),U.find(b=>b.value==="different")||ge(b=>[{name:Fe,value:"different"},...b])),Ue&&((!m||m.value!=="different")&&f({name:Fe,value:"different"}),A.find(b=>b.value==="different")||ne(b=>[{name:Fe,value:"different"},...b]))):(m&&m.value==="different"&&f(i[a].acl.owner),p&&p.value==="different"&&j(i[a].acl.ownerGroup),ge(b=>b.filter(({value:$})=>$!=="different")),ne(b=>b.filter(({value:$})=>$!=="different")))},[Q,Ue,Ye]),Ge.length?s().createElement(vs.Z,{open:t,titleButtonApply:"apply",overflowHidden:!0,applyDisabled:ee,progress:w,onClose:r,onApply:()=>{Ke(!0),setTimeout(()=>ho(void 0,null,function*(){if(Q){let b=~it&65535,$=~rt&65535;for(let ae=0;ae<Ge.length;ae++){const we=Ge[ae],ke=i[we];let ve=JSON.parse(JSON.stringify(ke.acl||{}));ve.object=Cs(ke.acl.object,O,b),m&&m.value!=="different"&&(ve.owner=m.value),p&&p.value!=="different"&&(ve.ownerGroup=p.value),ke.type==="state"&&(ve.state=Cs(ke.acl.state,Be,$)),yield o(we,{acl:ve})}}else{let b=JSON.parse(JSON.stringify(i[a].acl||{}));b.object=O,b.owner=m?m.value:"system.user.admin",b.ownerGroup=p?p.value:"system.group.administrator",i[a].type==="state"&&(b.state=Be),o(a,{acl:b})}Ke(!1),e()}),200)}},s().createElement("div",{style:{display:"flex",flexDirection:"column"}},s().createElement("div",{style:{margin:10,fontSize:20}},n("Access control list: %s",a||c)),s().createElement("div",{style:{display:"flex"}},s().createElement(F.FormControl,{variant:"standard",fullWidth:!0,style:{marginRight:10}},s().createElement(F.InputLabel,null,n("Owner user")),s().createElement(F.Select,{variant:"standard",disabled:w,value:m?m.value:"",renderValue:b=>s().createElement("span",null,m!=null&&m.icon?s().createElement(mt.default,{src:m.icon,style:{width:16,height:16,marginRight:8}}):null,m?m.name:""),style:(m==null?void 0:m.value)==="different"?{opacity:.5}:{color:(m==null?void 0:m.color)||void 0,backgroundColor:ye.Z.getInvertedColor(m==null?void 0:m.color,d)},onChange:b=>{const $=A.find(ae=>ae.value===b.target.value);f($),Ee(!1)}},A.map(b=>s().createElement(F.MenuItem,{style:b.value==="different"?{opacity:.5}:{color:b.color||void 0,backgroundColor:ye.Z.getInvertedColor(b.color,d)},key:b.value,value:b.value},b.icon?s().createElement(mt.default,{src:b.icon,style:{width:16,height:16,marginRight:8}}):null,b.name)))),s().createElement(F.FormControl,{variant:"standard",fullWidth:!0},s().createElement(F.InputLabel,null,n("Owner group")),s().createElement(F.Select,{variant:"standard",disabled:w,value:p?p.value:"",renderValue:b=>s().createElement("span",null,p!=null&&p.icon?s().createElement(mt.default,{src:p.icon,style:{width:16,height:16,marginRight:8}}):null,p?p.name:""),style:(p==null?void 0:p.value)==="different"?{opacity:.5}:{color:(p==null?void 0:p.color)||void 0,backgroundColor:ye.Z.getInvertedColor(p==null?void 0:p.color,d)},onChange:b=>{const $=U.find(ae=>ae.value===b.target.value);j($),Ee(!1)}},U.map(b=>s().createElement(F.MenuItem,{key:b.value,value:b.value,style:b.value==="different"?{opacity:.5}:{color:b.color||void 0,backgroundColor:ye.Z.getInvertedColor(b.color,d)}},b.icon?s().createElement(mt.default,{src:b.icon,style:{width:16,height:16,marginRight:8}}):null,b.name))))),s().createElement("div",{style:{display:"flex",margin:10,alignItems:"center",fontSize:10,marginLeft:0,color:"silver"}},s().createElement("div",{style:Q?null:{color:"green"}},n("to apply one item")),s().createElement(F.Switch,{disabled:w||!!c||de===1,checked:!!c||Q,onChange:b=>{Ne(b.target.checked),Ee(!1)},color:"primary"}),s().createElement("div",{style:Q?{color:"green"}:null},n("to apply with children")," ",c||de>1?`(${de} ${n("object(s)")})`:"")),w&&s().createElement(F.LinearProgress,null),s().createElement("div",{style:{overflowY:"auto"}},s().createElement("div",null,s().createElement("h2",null,n("Object rights")),s().createElement(Ss,{mask:rt,disabled:w,setMask:wt,applyToChildren:Q,differentValues:bt,t:n,setValue:b=>{at(b),Ee(!1)},value:O})),Le&&s().createElement("div",null,s().createElement("h2",null,n("States rights")),s().createElement(Ss,{mask:it,disabled:w,setMask:Et,applyToChildren:Q,differentValues:Q?gt:[],t:n,setValue:b=>{ot(b),Ee(!1)},value:Be}))))):s().createElement(F.LinearProgress,null)},uo=h(37538),fo=h(93919);const go=r=>({dialog:{height:"100%",maxHeight:"100%",maxWidth:"100%"},content:{textAlign:"center"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+r.mixins.toolbar.minHeight+"px)"},error:{color:r.palette.mode==="dark"?"#ff7777":"#c20000"},image:{height:"100%",width:"auto"},text:{fontFamily:"Lucida Console, Courier, monospace",width:"100%"},download:{textDecoration:"none",textTransform:"uppercase",fontSize:14,color:"white",border:"1px solid white",borderRadius:5,padding:"8px 16px",marginRight:r.spacing(1)}}),Fo={images:["png","jpg","svg","jpeg"],code:["js","json"],txt:["log","txt","html","css","xml"]};class xs extends C.Component{constructor(e){super(e);const t=this.props.obj._id.split(".");this.state={error:"",sound:null,image:null,text:null,binary:null,fileName:t[t.length-2]+"."+t[t.length-1]},this.audioRef=s().createRef()}componentDidMount(){this.props.socket.getBinaryState(this.props.obj._id).then(e=>{let t=this.props.obj._id.toLowerCase().split(".").pop();const a=ye.Z.detectMimeType(e);if(a&&(t=a),t==="jpg")this.setState({image:!0,binary:e,mime:"image/jpeg"});else if(t==="svg")this.setState({image:!0,binary:e,mime:"image/svg+xml"});else if(t==="png"||t==="bmp")this.setState({image:!0,binary:e,mime:"image/"+t});else if(t==="mp3")this.setState({audio:!0,binary:e,mime:"audio/mpeg"});else if(t==="ogg")this.setState({audio:!0,binary:e,mime:"audio/ogg"});else if(t==="txt"||t==="log")try{const o=btoa(e);this.setState({text:o,binary:e,mime:"text/plain"})}catch(o){}}).catch(e=>this.setState({error:e}))}render(){return s().createElement(te.Z,{className:this.props.classes.dialog,open:!0,maxWidth:this.state.audio?"sm":"md",onClose:()=>this.props.onClose(),fullWidth:!0,"aria-labelledby":"object-view-dialog-title"},s().createElement(K.Z,{id:"object-view-dialog-title"},this.props.t("View file in state: %s",this.props.obj._id)),s().createElement(oe.Z,{className:this.props.classes.content},this.state.error?s().createElement("div",{className:this.props.classes.error},this.state.error==="State is not binary"?this.props.t("No file stored yet"):this.props.t(this.state.error)):null,this.state.audio?s().createElement("audio",{ref:this.audioRef,src:`data:${this.state.mime};base64,${this.state.binary}`}):null,this.state.audio?s().createElement(Ae.Z,{color:"primary",onClick:()=>this.audioRef.current&&this.audioRef.current.play()},s().createElement(uo.default,null)):null,this.state.image?s().createElement("img",{src:`data:${this.state.mime};base64,${this.state.binary}`,alt:this.props.obj._id,className:this.props.classes.image}):null,this.state.text!==null?s().createElement("pre",{className:this.props.classes.text},this.state.text):null),s().createElement(L.Z,null,s().createElement("a",{className:this.props.classes.download,download:this.state.fileName,href:`data:${this.state.mime};base64,${this.state.binary}`},s().createElement(fo.Z,{style:{paddingRight:8,height:12}}),s().createElement("span",null,this.props.t("Download"))),s().createElement(Z.Z,{variant:"contained",onClick:()=>this.props.onClose(),startIcon:s().createElement(J.default,null),color:"grey"},this.props.t("Close"))))}}xs.propTypes={t:l().func,lang:l().string,expertMode:l().bool,socket:l().object,themeType:l().string,obj:l().object,onClose:l().func.isRequired};var vo=(0,R.default)()((0,G.withStyles)(go)(xs)),bo=Object.defineProperty,yo=(r,e,t)=>e in r?bo(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Eo=(r,e,t)=>(yo(r,typeof e!="symbol"?e+"":e,t),t);const wo=r=>({buttonIcon:{marginRight:4},buttonAll:{color:"#FF0000"},id:{fontStyle:"italic"},buttonText:{whiteSpace:"nowrap"}});class js extends C.Component{constructor(e){super(e),Eo(this,"translate",(a,o,i)=>o!==void 0?this.props.t(a,o,i):(this.wordCache[a]||(this.wordCache[a]=this.props.t(a)),this.wordCache[a])),this.dialogName="AdminObjects",this.filters=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.filters`)||"{}";try{this.filters=JSON.parse(this.filters)}catch(a){this.filters={}}let t=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.selected`)||"";this.state={selected:this.props.selected===void 0?t:"",name:"",toast:"",deleteObjectShow:null},this.t=this.translate,this.wordCache={}}onDelete(e){const t=this.state.deleteObjectShow.id;e?(this.props.socket.delObjects(t,!0).then(()=>this.setState({toast:this.t("All deleted")})).catch(a=>window.alert("Cannot delete object: "+a)),this.setState({deleteObjectShow:null})):(this.props.socket.delObject(t,!1).catch(a=>window.alert("Cannot delete object: "+a)),this.setState({deleteObjectShow:null}))}renderToast(){return s().createElement(Ve.Z,{anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!this.state.toast,autoHideDuration:3e3,onClose:()=>this.setState({toast:""}),message:this.state.toast,action:s().createElement(s().Fragment,null,s().createElement(X.Z,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({toast:""})},s().createElement(J.default,{fontSize:"small"})))})}renderDeleteDialog(){return this.state.deleteObjectShow?s().createElement(te.Z,{key:"delete",maxWidth:"md",open:!0,onClose:()=>this.setState({deleteObjectShow:null}),"aria-labelledby":"delete-object-dialog-title","aria-describedby":"delete-object-dialog-description"},s().createElement(K.Z,{id:"delete-object-dialog-title"},this.state.deleteObjectShow.hasChildren?this.t("Delete object(s)"):this.t("Delete object"),": ",s().createElement("span",{className:this.props.classes.id},this.state.deleteObjectShow.id)),s().createElement(oe.Z,null,s().createElement(qe.Z,null,this.t("Are you sure?"))),s().createElement(L.Z,null,this.state.deleteObjectShow.hasChildren?s().createElement(Z.Z,{variant:"contained",color:"grey",classes:{label:this.props.classes.buttonText},onClick:()=>this.onDelete(!0),startIcon:s().createElement(me.default,{className:this.props.classes.buttonAll})},this.t("Delete with children")):null,this.state.deleteObjectShow.exists?s().createElement(Z.Z,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:()=>this.onDelete(!1),color:"primary",startIcon:s().createElement(me.default,null),autoFocus:!0},this.t("Delete one item")):null,s().createElement(Z.Z,{variant:"contained",color:"grey",onClick:()=>this.setState({deleteObjectShow:null}),startIcon:s().createElement(J.default,null)},this.t("ra_Cancel")))):null}render(){return[s().createElement(_e.Z,{key:"browser",dialogName:"admin",objectsWorker:this.props.objectsWorker,prefix:this.props.prefix,defaultFilters:this.filters,statesOnly:this.props.statesOnly,style:{width:"100%",height:"100%"},socket:this.props.socket,selected:this.state.selected,name:this.state.name,expertMode:this.props.expertMode,isFloatComma:this.props.isFloatComma,dateFormat:this.props.dateFormat,t:this.t,lang:this.props.lang,themeName:this.props.themeName,themeType:this.props.themeType,theme:this.props.theme,objectCustomDialog:fa,objectBrowserValue:Na,objectBrowserEditObject:Ua,objectBrowserEditRole:eo,objectBrowserViewFile:vo,router:pe.Z,enableStateValueEdit:!0,onObjectDelete:(e,t,a)=>this.setState({deleteObjectShow:{id:e,hasChildren:t,exists:a}}),onFilterChanged:e=>{this.filters=e,(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.filters`,JSON.stringify(e))},onSelect:e=>(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.selected`,e[0]||""),objectEditBoolean:!0,objectAddBoolean:!0,objectStatesView:!0,objectImportExport:!0,objectEditOfAccessControl:!0,modalNewObject:e=>s().createElement(co,{objects:e.objects,expertMode:this.props.expertMode,open:e.state.modalNewObj,setObject:(t,a)=>e.setObject(t,a),selected:e.state.selected[0]||e.state.selectedNonObject,onClose:()=>e.setState({modalNewObj:!1}),onApply:()=>e.setState({modalNewObj:!1})}),modalEditOfAccessControl:(e,t)=>s().createElement(mo,{themeType:this.props.themeType,open:e.state.modalEditOfAccess,extendObject:(a,o)=>{e.extendObject(a,o),t.aclTooltip=null},selected:e.state.selected[0],modalEmptyId:e.state.modalEmptyId,objects:e.objects,t:this.t,onClose:()=>e.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null}),onApply:()=>e.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})})}),this.renderDeleteDialog()]}}js.propTypes={t:l().func,lang:l().string,socket:l().object,themeName:l().string,themeType:l().string,theme:l().object,expertMode:l().bool,isFloatComma:l().bool,dateFormat:l().string,objectsWorker:l().object};var Co=(0,R.default)()((0,G.withStyles)(wo)(js))}}]);
|
|
310
310
|
|
|
311
|
-
//# sourceMappingURL=7412.
|
|
311
|
+
//# sourceMappingURL=7412.e4b0556a.chunk.js.map
|