iobroker.admin 5.2.0 → 5.2.1

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.
@@ -1,2 +1,2 @@
1
- (this["webpackJsonpsrc-rx"]=this["webpackJsonpsrc-rx"]||[]).push([[15],{1666:function(e,t,s){"use strict";var a=s(17),n=s(12),o=s(13),i=s(14),r=s(15),l=s(0),c=s(8),u=s(526),d=s(9),h=s.n(d),p=s(4),m=s.n(p),b=s(691),j=s(651),f=s(16),g=s(542),v=s(3),O=function(e){Object(i.a)(s,e);var t=Object(r.a)(s);function s(e){var a;Object(n.a)(this,s),a=t.call(this,e);var o=window.localStorage.getItem((a.props.dialogName||"App")+"."+a.props.adapterName)||Object.keys(a.props.schema.items)[0];return Object.keys(a.props.schema.items).includes(o)||(o=Object.keys(a.props.schema.items)[0]),a.state={tab:o},a}return Object(o.a)(s,[{key:"render",value:function(){var e=this,t=this.props.schema.items;return Object(v.jsxs)("div",{className:this.props.classes.tabs,children:[Object(v.jsx)(b.a,{value:this.state.tab,onChange:function(t,s){window.localStorage.setItem((e.props.dialogName||"App")+"."+e.props.adapterName,s),e.setState({tab:s})},children:Object.keys(t).map((function(s){var a=e.execute(t[s].disabled,!1);return Object(v.jsx)(j.a,{wrapped:!0,disabled:a,value:s,label:e.getText(t[s].label)},s)}))}),Object(v.jsx)(g.a,{isParentTab:!0,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,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:t[this.state.tab]},this.state.tab)]})}}]),s}(f.a);O.propTypes={socket:m.a.object.isRequired,themeType:m.a.string,themeName:m.a.string,style:m.a.object,className:m.a.string,data:m.a.object.isRequired,originalData:m.a.object,schema:m.a.object,onError:m.a.func,onChange:m.a.func,customs:m.a.object,adapterName:m.a.string,instance:m.a.number,commandRunning:m.a.bool,onCommandRunning:m.a.func,dateFormat:m.a.string,isFloatComma:m.a.bool,multiEdit:m.a.bool,customObj:m.a.object,instanceObj:m.a.object,custom:m.a.bool,registerOnForceUpdate:m.a.func.isRequired,forceUpdate:m.a.func.isRequired,systemConfig:m.a.object,alive:m.a.bool,common:m.a.object};var x=Object(c.a)((function(e){return{tabs:{height:"100%",width:"100%"},panel:{height:"calc(100% - 48px)",width:"100%",display:"block"}}}))(O);h.a.extendTranslations=h.a.extendTranslations||function(e,t){try{t?(h.a.translations[t]||console.warn("Used unknown language: ".concat(t)),h.a.translations[t]=h.a.translations[t]||{},Object.keys(e).forEach((function(s){h.a.translations[t][s]?h.a.translations[t][s]!==e[s]&&console.warn('Translation for word "'.concat(s,'" in "').concat(t,'" was ignored: existing = "').concat(h.a.translations[t][s],'", new = ').concat(e[s])):h.a.translations[t][s]=e[s]}))):Object.keys(e).forEach((function(t){Object.keys(e[t]).forEach((function(s){h.a.translations[s]||console.warn("Used unknown language: ".concat(s)),h.a.translations[s][t]?h.a.translations[s][t]!==e[t][s]&&console.warn('Translation for word "'.concat(t,'" in "').concat(s,'" was ignored: existing = "').concat(h.a.translations[s][t],'", new = ').concat(e[t][s])):h.a.translations[s][t]=e[t][s]}))}))}catch(s){console.error("Cannot apply translations: ".concat(s))}};var y=function(e){Object(i.a)(s,e);var t=Object(r.a)(s);function s(e){var a;return Object(n.a)(this,s),(a=t.call(this,e)).onCommandRunning=function(e){return a.setState({commandRunning:e})},a.onAlive=function(e,t){((null===t||void 0===t?void 0:t.val)||!1)!==a.state.alive&&a.setState({alive:(null===t||void 0===t?void 0:t.val)||!1})},a.onChange=function(e,t,s){if(a.props.onValueChange)a.props.onValueChange(e,t),s&&s();else{var n={data:e},o={};Object.keys(e).forEach((function(t){return!t.startsWith("_")&&(o[t]=e[t])})),n.changed=JSON.stringify(o)!==a.state.originalData,a.setState({state:n},(function(){a.props.onChange(o,n.changed),s&&s()}))}},a.onError=function(e,t){var s=JSON.parse(JSON.stringify(a.state.errors));t?s[e]=t:delete s[e],JSON.stringify(s)!==JSON.parse(JSON.stringify(a.state.errors))&&a.setState({errors:s},(function(){return a.props.onError(!!Object.keys(a.state.errors).length)}))},a.forceUpdate=function(e,t){Array.isArray(e)?e.forEach((function(e){return a.forceUpdateHandlers[e]&&a.forceUpdateHandlers[e](t)})):a.forceUpdateHandlers[e]&&a.forceUpdateHandlers[e](t)},a.registerOnForceUpdate=function(e,t){t?a.forceUpdateHandlers[e]=t:a.forceUpdateHandlers[e]&&delete a.forceUpdateHandlers[e]},a.state={originalData:JSON.stringify(a.props.data),changed:!1,errors:{},updateData:a.props.updateData,systemConfig:null,alive:!1,commandRunning:!1},a.forceUpdateHandlers={},a.schema=JSON.parse(JSON.stringify(a.props.schema)),a.buildDependencies(a.schema),a.readData(),a}return Object(o.a)(s,[{key:"readSettings",value:function(){var e=this;return(this.props.custom||this.props.common)&&this.props.data?Promise.resolve():this.props.socket.getObject("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance)).then((function(t){return e.setState({common:t.common,data:e.props.data||t.native})}))}},{key:"readData",value:function(){var e=this;this.readSettings().then((function(){return e.props.socket.getCompactSystemConfig()})).then((function(t){return e.props.socket.getState("system.adapter.".concat(e.props.adapterName,".").concat(e.props.instance,".alive")).then((function(s){e.props.custom?e.setState({systemConfig:t.common,alive:!(!s||!s.val)}):e.setState({systemConfig:t.common,alive:!(!s||!s.val)},(function(){return e.props.socket.subscribeState("system.adapter.".concat(e.props.adapterName,".").concat(e.props.instance,".alive"),e.onAlive)}))}))}))}},{key:"flatten",value:function(e,t){var s=this;return t=t||{},e.items&&Object.keys(e.items).forEach((function(a){t[a]=e.items[a],s.flatten(e.items[a],t)})),t}},{key:"buildDependencies",value:function(e){var t=this.flatten(e);Object.keys(t).forEach((function(e){var s,n,o,i,r,l,c,u,d,h;(null===(s=t[e].confirm)||void 0===s?void 0:s.alsoDependsOn)&&(null===(l=t[e].confirm)||void 0===l||l.alsoDependsOn.forEach((function(s){if(t[s]){t[s].confirmDependsOn=t[s].confirmDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});n.confirm&&(n.confirm.cancel="Undo"),t[s].confirmDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(n=t[e].onChange)||void 0===n?void 0:n.alsoDependsOn)&&(null===(c=t[e].onChange)||void 0===c||c.alsoDependsOn.forEach((function(s){if(t[s]){t[s].onChangeDependsOn=t[s].onChangeDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].onChangeDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(o=t[e].hidden)||void 0===o?void 0:o.alsoDependsOn)&&(null===(u=t[e].hidden)||void 0===u||u.alsoDependsOn.forEach((function(s){if(t[s]){t[s].hiddenDependsOn=t[s].hiddenDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].hiddenDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(i=t[e].label)||void 0===i?void 0:i.alsoDependsOn)&&(null===(d=t[e].label)||void 0===d||d.alsoDependsOn.forEach((function(s){if(t[s]){t[s].labelDependsOn=t[s].labelDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].labelDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(r=t[e].help)||void 0===r?void 0:r.alsoDependsOn)&&(null===(h=t[e].help)||void 0===h||h.alsoDependsOn.forEach((function(s){if(t[s]){t[s].helpDependsOn=t[s].helpDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].helpDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})))}))}},{key:"renderItem",value:function(e){var t=this;return"tabs"===e.type?Object(v.jsx)(x,{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:e,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,forceUpdate:this.forceUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:function(e,s){return t.onError(e,s)}}):"panel"!==e.type&&e.type?void 0:Object(v.jsx)(g.a,{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:e,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,forceUpdate:this.forceUpdate,registerOnForceUpdate:this.registerOnForceUpdate,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,onChange:this.onChange,onError:function(e,s){return t.onError(e,s)}})}},{key:"render",value:function(){return this.state.systemConfig?Object(v.jsx)("div",{className:this.props.classes.root,children:this.renderItem(this.schema)}):Object(v.jsx)(u.a,{})}}],[{key:"getDerivedStateFromProps",value:function(e,t){return JSON.stringify(e.updateData)!==JSON.stringify(t.updateData)?{updateData:e.updateData,originalData:JSON.stringify(e.data)}:null}},{key:"loadI18n",value:function(e,t,s){if(!0===t||t&&"string"===typeof t){var a=h.a.getLanguage(),n="string"===typeof t?t:"i18n";return e.fileExists(s+".admin","".concat(n,"/").concat(a,".json")).then((function(t){return t?"".concat(n,"/").concat(a,".json"):e.fileExists(s+".admin","".concat(n,"/").concat(a,"/translations.json")).then((function(e){return e?"".concat(n,"/").concat(a,"/translations.json"):""}))})).then((function(t){return t?e.readFile(s+".admin",t).then((function(e){void 0!==e.file&&(e=e.file);try{e=JSON.parse(e),h.a.extendTranslations(e,a)}catch(n){console.error('Cannot parse language file "'.concat(s,".admin/").concat(t,": ").concat(n))}})):(console.warn("Cannot find i18n for ".concat(s," / ").concat(t)),Promise.resolve())}))}return t&&"object"===typeof t?(h.a.extendTranslations(t),Promise.resolve()):Promise.resolve()}}]),s}(l.Component);t.a=Object(c.a)((function(e){return{root:{width:"100%",height:"100%"}}}))(y)},2041:function(e,t,s){"use strict";s.r(t);var a=s(12),n=s(13),o=s(14),i=s(15),r=s(326),l=s(0),c=s.n(l),u=s(8),d=s(211),h=s(232),p=s(213),m=s(212),b=s(499),j=s(96),f=s(185),g=s(647),v=s(47),O=s.n(v),x=s(189),y=s.n(x),w=s(1674),C=s(4),S=s.n(C),k=s(648),I=s(691),D=s(651),T=s(82),N=s.n(T),A=s(139),E=s.n(A),R=s(9),F=s.n(R),H=s(1574),M=s.n(H),V=s(29),W=s.n(V),J=s(50),L=s(85),Y=s(6),U=s(526),_=s(1487),P=s(1488),B=s(1489),z=s(75),q=s(159),X=s(623),G=s(692),K=s(244),$=s.n(K),Q=s(569),Z=s.n(Q),ee=s(1666),te=s(86),se=s(3),ae=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).onSave=function(e){if(n.props.objectIDs.length>10&&!n.state.confirmed)return n.cb=e,n.setState({showConfirmation:!0});n.saveOneState(Object(L.a)(n.props.objectIDs),(function(){n.changedItems=[],n.newValues={},n.commonConfig=n.getCommonConfig(),n.setState({confirmed:!1,hasChanges:!1,newValues:{}},(function(){n.props.reportChangedIds(n.changedIds),n.props.onChange(!1,!0),e&&setTimeout((function(){return e()}),100)}))}))};var o=window.localStorage.getItem("App.customsExpanded")||"[]";try{o=JSON.parse(o)}catch(i){o=[]}return n.changedIds=[],n.state={loaded:!1,hasChanges:!1,expanded:o,newValues:{},progress:null,maxOids:null,confirmed:!1,showConfirmation:!1},n.scrollDone=!1,n.lastExpanded=window.localStorage.getItem("App.customsLastExpanded")||"",n.scrollDivRef=Object(l.createRef)(),n.changedItems=[],n.jsonConfigs={},n.controls={},n.refTemplate={},n.props.customsInstances.map((function(e){return n.refTemplate[e]=Object(l.createRef)()})),n.customObj=n.props.objectIDs.length>1?{custom:{},native:{}}:JSON.parse(JSON.stringify(n.props.objects[n.props.objectIDs[0]]||null)),n.customObj&&(n.loadAllPromises=n.loadAllCustoms().then((function(){n.commonConfig=n.getCommonConfig(),n.setState({loaded:!0,newValues:{}})}))),n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){this.props.registerSaveFunc&&this.props.registerSaveFunc(this.onSave)}},{key:"componentWillUnmount",value:function(){this.props.registerSaveFunc&&this.props.registerSaveFunc(null)}},{key:"loadAllCustoms",value:function(){var e=this,t=[];return this.props.customsInstances.forEach((function(s){var a=s.replace(/\.\d+$/,"").replace("system.adapter.","");void 0===e.jsonConfigs[a]&&(e.jsonConfigs[a]=!1,t.push(e.getCustomTemplate(a)))})),Promise.all(t).then((function(){e.props.customsInstances.forEach((function(t){var s,a,n=t.replace(/\.\d+$/,"").replace("system.adapter.","");e.jsonConfigs[n]&&(e.jsonConfigs[n].instanceObjs=e.jsonConfigs[n].instanceObjs||{},e.jsonConfigs[n].instanceObjs[t]={common:JSON.parse(JSON.stringify(null===(s=e.props.objects["system.adapter."+t])||void 0===s?void 0:s.common)),native:JSON.parse(JSON.stringify(null===(a=e.props.objects["system.adapter."+t])||void 0===a?void 0:a.native))})}))}))}},{key:"showError",value:function(e){this.setState({error:e})}},{key:"getCustomTemplate",value:function(e){var t,s=this,a=this.props.objects["system.adapter."+e]?JSON.parse(JSON.stringify(this.props.objects["system.adapter."+e])):null;return a?(te.a.fixAdminUI(a),"json"===(null===(t=a.common)||void 0===t?void 0:t.adminUI.custom)?this.props.socket.readFile(e+".admin","jsonCustom.json").then((function(t){void 0!==t.file&&(t=t.file);try{t=JSON.parse(t),s.jsonConfigs[e]=s.jsonConfigs[e]||{},s.jsonConfigs[e].json=t}catch(a){console.error("Cannot parse jsonConfig of ".concat(e,": ").concat(a)),window.alert("Cannot parse jsonConfig of ".concat(e,": ").concat(a))}return ee.a.loadI18n(s.props.socket,t.i18n,e)})).catch((function(t){console.error("Cannot load jsonConfig of ".concat(e,": ").concat(t)),window.alert("Cannot load jsonConfig of ".concat(e,": ").concat(t))})):(console.error("Adapter ".concat(e," is not yet supported by this version of admin")),window.alert("Adapter ".concat(e," is not yet supported by this version of admin")),Promise.resolve(null))):(console.error('Cannot find adapter "'.concat(a,'"')),Promise.resolve(null))}},{key:"_executeCustom",value:function(e,t,s,a,n,o,i){var r=this;if(!i.includes(o)){i.push(o);var l=[];if(e&&"object"===typeof e&&("string"===typeof(l=e.alsoDependsOn||[])&&(l=[l]),e=e.func),l.forEach((function(e){if(!n[e])return console.error('[JsonConfigComponent] attribute "'.concat(e,'" does not exist!'));if(!n[e].defaultFunc)return console.error('[JsonConfigComponent] attribute "'.concat(e,'" is not required to be includes in "alsoDependsOn" while has static value!'));var o=r._executeCustom(n[e].defaultFunc,t,s,a,n,e,i);void 0!==o&&(t[e]=o)})),e)try{var c=new Function("data","originalData","_system","instanceObj","customObj","_socket",e.includes("return")?e:"return "+e)(t||this.props.data,this.props.originalData,this.props.systemConfig,a,s,this.props.socket);t[o]=c}catch(u){console.error("Cannot execute ".concat(e,": ").concat(u)),t[o]=n[o]&&void 0!==n[o].default?n[o].default:null}else t[o]=void 0===n[o].default?null:n[o].default}}},{key:"getDefaultValues",value:function(e,t){var a=this,n={enabled:!1},o=e.split(".")[0];if(this.jsonConfigs[o]&&!this.jsonConfigs[o].disabled){var i=s.flattenItems(this.jsonConfigs[o].json.items);if(i){var r=[],l=Object.keys(i).filter((function(e){return i[e]}));l.forEach((function(e){i[e].defaultFunc||void 0===i[e].default||(n[e]=i[e].default)})),l.forEach(function(){var s=Object(J.a)(W.a.mark((function s(l){return W.a.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:i[l].defaultFunc&&a._executeCustom(i[l].defaultFunc,n,t,a.jsonConfigs[o].instanceObjs[e],i,l,r);case 1:case"end":return s.stop()}}),s)})));return function(e){return s.apply(this,arguments)}}())}}return n}},{key:"getCommonConfig",value:function(){var e=this,t=this.props.objectIDs||[],s=this.props.objects,a={};return this.props.customsInstances.forEach((function(n){var o=n.split(".")[0];e.jsonConfigs[o]&&e.jsonConfigs[o].disabled||(a[n]={},t.forEach((function(t){var o,i=s[t],r=(null===i||void 0===i||null===(o=i.common)||void 0===o?void 0:o.custom)&&i.common.custom[n]||null;if(r)Object.keys(r).forEach((function(e){void 0===a[n][e]?a[n][e]=r[e]:a[n][e]!==r[e]&&(Array.isArray(a[n][e])||(a[n][e]=[a[n][e]]),!a[n][e].includes(r[e])&&a[n][e].push(r[e]))}));else{var l=e.getDefaultValues(n,i);l.enabled=!1,Object.keys(l).forEach((function(e){void 0===a[n][e]?a[n][e]=l[e]:a[n][e]!==l[e]&&(Array.isArray(a[n][e])||(a[n][e]=[a[n][e]]),!a[n][e].includes(l[e])&&a[n][e].push(l[e]))}))}})),Object.keys(a[n]).forEach((function(e){Array.isArray(a[n][e])&&a[n][e].sort()})))})),a}},{key:"isChanged",value:function(e){return e=e||this.state.newValues,Object.keys(e).find((function(t){return null===e[t]||e[t]&&Object.keys(e[t]).find((function(e){return!e.startsWith("_")}))}))}},{key:"combineNewAndOld",value:function(e,t){var s=Object.assign({},this.commonConfig[e]||{},this.state.newValues[e]||{});return t&&Object.keys(s).forEach((function(e){e.startsWith("_")&&delete s[e]})),null===this.state.newValues[e]&&(s.enabled=!1),s}},{key:"renderOneCustom",value:function(e,t,s,a){var n,o=this,i=e.split(".")[0],r="".concat(".","/adapter/").concat(i,"/").concat(this.props.objects["system.adapter."+i].common.icon),l=void 0===this.state.newValues[e]||this.state.newValues[e]&&void 0===this.state.newValues[e].enabled?null!==this.state.newValues[e]&&this.commonConfig[e].enabled:!(!this.state.newValues[e]||!this.state.newValues[e].enabled),c=Array.isArray(l)&&(!this.state.newValues[e]||void 0===this.state.newValues[e].enabled),u=this.jsonConfigs[i]&&(null===(n=this.jsonConfigs[i].json)||void 0===n?void 0:n.disabled),d=this.combineNewAndOld(e);return u&&!0===this.jsonConfigs[i].json.hidden||"string"===typeof this.jsonConfigs[i].json.hidden&&this._executeCustom(this.jsonConfigs[i].json.hidden,d,s,t,this.jsonConfigs[i].json.items,"enabled",[])?null:Object(se.jsxs)(_.a,{id:"Accordion_"+e,className:a%2?this.props.classes.accordionOdd:this.props.classes.accordionEven,expanded:this.state.expanded.includes(e),ref:this.refTemplate[e],onChange:function(){var t=Object(L.a)(o.state.expanded),s=t.indexOf(e);-1===s?t.push(e):t.splice(s,1),window.localStorage.setItem("App.customsExpanded",JSON.stringify(t)),-1===s&&window.localStorage.setItem("App.customsLastExpanded",e),o.setState({expanded:t})},children:[Object(se.jsxs)(P.a,{expandIcon:Object(se.jsx)($.a,{}),"data-id":e,className:a%2?l?this.props.classes.accordionHeaderEnabledOdd:this.props.classes.accordionHeaderOdd:l?this.props.classes.accordionHeaderEnabledEven:this.props.classes.accordionHeaderEven,children:[Object(se.jsx)("img",{src:r,className:this.props.classes.headingIcon,alt:""}),Object(se.jsx)(z.a,{className:this.props.classes.heading,children:this.props.t("Settings %s",e)}),Object(se.jsx)("div",{className:Object(Y.default)(this.props.classes.titleEnabled,"titleEnabled",l?this.props.classes.enabledVisible:this.props.classes.enabledInvisible),children:this.props.t("Enabled")})]}),Object(se.jsxs)(B.a,{children:[Object(se.jsx)("div",{className:this.props.classes.enabledControl,children:Object(se.jsx)(X.a,{className:this.props.classes.formControl,control:Object(se.jsx)(G.a,{indeterminate:c,checked:!!l,disabled:u,onChange:function(t){var s=JSON.parse(JSON.stringify(o.state.newValues));s[e]=s[e]||{},c||t.target.checked?s[e].enabled=!0:l?s[e]=null:delete s[e],o.setState({newValues:s,hasChanges:o.isChanged(s)},(function(){return o.props.onChange&&o.props.onChange(o.state.hasChanges)}))}}),label:this.props.t("Enabled")})}),Object(se.jsxs)("div",{className:this.props.classes.customControls,children:[u||!l&&!c?null:Object(se.jsx)(ee.a,{instanceObj:t,customObj:s,custom:!0,className:"",adapterName:i,instance:parseInt(e.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:d,onError:function(e){return o.setState({error:e},(function(){return o.props.onError&&o.props.onError(e)}))},onValueChange:function(t,s){console.log(t+" => "+s);var a=JSON.parse(JSON.stringify(o.state.newValues));a[e]=a[e]||{},o.commonConfig[e][t]===s?(delete a[e][t],Object.keys(a[e]).length||delete a[e]):a[e][t]=s,o.setState({newValues:a,hasChanges:o.isChanged(a)},(function(){return o.props.onChange&&o.props.onChange(o.state.hasChanges)}))}}),u&&this.jsonConfigs[i].json.help?"object"===typeof this.jsonConfigs[i].json.help?this.jsonConfigs[i].json.help[this.props.lang]||this.jsonConfigs[i].json.help.en:this.props.t(this.jsonConfigs[i].json.help):null]})]})]},e)}},{key:"isAllOk",value:function(){return!0}},{key:"renderErrorMessage",value:function(){var e=this;return!!this.state.error&&Object(se.jsx)(Z.a,{title:this.props.t("Error"),text:this.state.error,onClose:function(){return e.setState({error:""})}})}},{key:"getObject",value:function(e,t,s){return e[s]?Promise.resolve(e[s]):this.props.socket.getObject(s).then((function(a){return t[s]=JSON.parse(JSON.stringify(a)),e[s]=a,a}))}},{key:"saveOneState",value:function(e,t,s,a){var n=this;if(s=s||{},a=a||{},e&&e.length){var o=this.state.maxOids||e.length;null===this.state.maxOids&&this.setState({maxOids:e.length},(function(){return n.props.onProgress(!0)})),this.setState({progress:Math.round((o-e.length)/o*50)});var i=e.shift();this.getObject(s,a,i).then((function(o){if(!o)return window.alert("Invalid object ".concat(i));o.common&&o.common.custom&&Object.keys(o.common.custom).forEach((function(e){o.common.custom[e]&&o.common.custom[e].enabled||(o.common.custom[e]=null)}));for(var r=Object.keys(n.state.newValues),l=function(e){var t=r[e],s=n.combineNewAndOld(t,!0);if(!1===s.enabled)o.common&&o.common.custom&&o.common.custom[t]&&(o.common.custom[t]=null);else if(s.enabled){if(o.common=o.common||{},Array.isArray(s.enabled)&&(!o.common.custom||!o.common.custom[t]||!o.common.custom[t].enabled))return o.common.custom&&o.common.custom[t]&&(o.common.custom[t]=null),"continue";if(o.common.custom=o.common.custom||{},!o.common.custom[t]||!o.common.custom[t].enabled){var a=n.getDefaultValues(t,o);o.common.custom[t]=JSON.parse(JSON.stringify(a||{}))}o.common.custom[t].enabled=!0,Object.keys(s).forEach((function(e){Array.isArray(s[e])||(o.common.custom[t][e]=s[e])}))}},c=0;c<r.length;c++)l(c);setTimeout((function(){return n.saveOneState(e,t,s,a)}),0)}))}else{var r=Object.keys(s);if(r.length){this.setState({progress:Math.round((this.state.maxOids-r.length)/this.state.maxOids*50)+50});var l=r.shift();return JSON.stringify(s[l].common)!==JSON.stringify(a[l].common)?(!this.changedIds.includes(l)&&this.changedIds.push(l),this.props.socket.setObject(l,s[l]).then((function(){return delete s[l],delete a[l],n.props.socket.getObject(l).then((function(o){n.props.objects[l]=o,setTimeout((function(){return n.saveOneState(e,t,s,a)}),0)}))}))):(delete s[l],delete a[l],setTimeout((function(){return n.saveOneState(e,t,s,a)}),0))}this.setState({maxOids:null},(function(){return n.props.onProgress(!1)})),t&&t()}}},{key:"renderConfirmationDialog",value:function(){var e=this;return!!this.state.showConfirmation&&Object(se.jsx)(E.a,{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:function(t){t?e.setState({showConfirmation:!1,confirmed:!0},(function(){var t=e.cb;e.cb=null,e.onSave(t)})):(e.cb=null,e.setState({showConfirmation:!1}))}})}},{key:"render",value:function(){var e=this;if(null===this.customObj)return Object(se.jsx)("div",{style:{color:"#F55",fontSize:32},children:this.props.t("Object does not exist!")});if(!this.state.loaded)return Object(se.jsx)(U.a,{});var t=0;return Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.state.maxOids>1&&Object(se.jsx)(U.a,{color:"secondary",variant:"determinate",value:this.state.progress}),Object(se.jsx)("div",{className:this.props.classes.scrollDiv,ref:this.scrollDivRef,children:null===this.state.maxOids&&Object.keys(this.jsonConfigs).map((function(s){return e.jsonConfigs[s]?Object.keys(e.jsonConfigs[s].instanceObjs).map((function(a){return e.renderOneCustom(a,e.jsonConfigs[s].instanceObjs[a],e.customObj,t++)})):null}))}),this.renderErrorMessage(),this.renderConfirmationDialog()]})}}],[{key:"flattenItems",value:function(e,t){return t=t||{},e&&Object.keys(e).forEach((function(a){e[a].items?s.flattenItems(e[a].items,t):t[a]=e[a]})),t}}]),s}(l.Component);ae.AsyncFunction=Object.getPrototypeOf(Object(J.a)(W.a.mark((function e(){return W.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})))).constructor;var ne=Object(r.a)()(Object(u.a)((function(e){return{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"},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"}}}))(ae)),oe=s(55),ie=s(99),re=s(1511),le=s(1526),ce=s(506),ue=s(339),de=s(505),he=s(511),pe=s(773),me=s(88),be=s(1492),je=s(1493),fe=s(1491),ge=s(1490),ve=s(283),Oe=s(1494),xe=s(1501),ye=s(571),we=s(1844),Ce=s(1845),Se=s(381),ke=s(1847),Ie=s(1852),De=s(1851),Te=s(1850),Ne=s(1853),Ae=s(1848),Ee=s(1846),Re=s(1849),Fe=s(57),He=s.n(Fe),Me=s(434),Ve=s.n(Me),We=s(191),Je={en:Se.a,fr:we.a,ru:Ce.a,de:Ee.a,es:ke.a,br:Ae.a,nl:Re.a,it:Te.a,pt:De.a,pl:Ie.a,"zh-cn":Ne.a};function Le(e){return e<10?"00"+e:e<100?"0"+e:e}function Ye(e){return e<10?"0"+e:e}var Ue=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).onChange=function(e,t){if(e===n.props.obj._id&&t&&n.state.values&&(!n.state.values.length||n.state.values[n.state.values.length-1].ts<t.ts)){var s=[].concat(Object(L.a)(n.state.values),[t]);n.setState({values:s})}};var o=window.localStorage.getItem("App.relativeRange")||"absolute",i=parseInt(window.localStorage.getItem("App.absoluteStart"),10)||0,r=parseInt(window.localStorage.getItem("App.absoluteEnd"),10)||0,l=window.localStorage.getItem("App.historySelected")||"",c=parseInt(window.localStorage.getItem("App.historyLastSelected"),10)||null,u=window.localStorage.getItem("App.historyLastSelectedColumn")||null;i&&r||o&&"absolute"!==o||(o="30"),i&&r&&(o="absolute");try{l=JSON.parse(l)}catch(d){l=[]}return n.state={loaded:!1,min:null,max:null,start:i,end:r,values:null,relativeRange:o,selected:l,lastSelected:c,lastSelectedColumn:u,historyInstance:"",updateOpened:!1,insertOpened:!1,historyInstances:null,defaultHistory:"",lcVisible:!0,qVisible:!0,ackVisible:!0,fromVisible:!0,supportedFeatures:[],dateFormat:"dd.MM.yyyy",edit:{}},n.adminInstance=parseInt(window.location.search.slice(1),10)||0,n.supportedFeaturesPromises={},n.unit=n.props.obj.common&&n.props.obj.common.unit?" "+n.props.obj.common.unit:"",n.timeTimer=null,n.prepareData().then((function(){return n.readHistoryRange()})).then((function(){"absolute"!==o?n.setRelativeInterval(n.state.relativeRange,!0):n.readHistory()})),n}return Object(n.a)(s,[{key:"readSupportedFeatures",value:function(e){var t=this;return(e=e||this.state.historyInstance)?(this.supportedFeaturesPromises[e]||(this.supportedFeaturesPromises[e]=new Promise((function(s){t.readSupportedFeaturesTimeout&&clearTimeout(t.readSupportedFeaturesTimeout),t.readSupportedFeaturesTimeout=setTimeout((function(){t.readSupportedFeaturesTimeout=null,s([])}),2e3),t.props.socket.sendTo(e,"features",null).then((function(e){t.readSupportedFeaturesTimeout?(t.readSupportedFeaturesTimeout&&clearTimeout(t.readSupportedFeaturesTimeout),t.readSupportedFeaturesTimeout=null,s(e&&e.supportedFeatures||[])):t.setState({supportedFeatures:e&&e.supportedFeatures||[]})}))}))),this.supportedFeaturesPromises[e]):Promise.resolve([])}},{key:"componentDidMount",value:function(){this.props.socket.subscribeState(this.props.obj._id,this.onChange)}},{key:"componentWillUnmount",value:function(){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange)}},{key:"prepareData",value:function(){var e,t=this;return this.getHistoryInstances().then((function(s){return e=s,t.props.socket.getCompactSystemConfig()})).then((function(s){var a=s&&s.common&&s.common.defaultHistory,n=window.localStorage.getItem("App.historyInstance")||"";return n&&e.find((function(e){return e.id===n&&e.alive}))||(n=a),n&&e.find((function(e){return e.id===n&&e.alive}))||(n=e.find((function(e){return e.alive})))&&(n=n.id),!n&&e.length&&(n=a),t.readSupportedFeatures(n).then((function(o){return new Promise((function(i){t.setState({historyInstances:e,defaultHistory:a,historyInstance:n,supportedFeatures:o,dateFormat:(s.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y")},(function(){return i()}))}))}))}))}},{key:"getHistoryInstances",value:function(){var e=this,t=[],s=[];return this.props.customsInstances.forEach((function(a){var n=e.props.objects["system.adapter."+a];if(n&&n.common&&n.common.getHistory){var o={id:a,alive:!1};t.push(o),s.push("system.adapter.".concat(a,".alive"))}})),s.length?this.props.socket.getForeignStates(s).then((function(e){return Object.keys(e).forEach((function(s){var a=t.find((function(e){return s.endsWith(e.id+".alive")}));a&&(a.alive=e[s]&&e[s].val)})),t})):Promise.resolve(t)}},{key:"readHistory",value:function(e,t){var s=this;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"}).then((function(e){var t=[],a=s.rangeValues,n=!1,o=!1,i=!1,r=!1,l=!1;if(a&&a.length&&(!e||!e.length||a[0].ts<e[0].ts)&&(t.push(a[0]),t.push({ts:a[0].ts+1,e:!0}),console.log("add ".concat(new Date(a[0].ts).toISOString(),": ").concat(a[0].val)),o||void 0===a[0].q||(o=!0),i||void 0===a[0].ack||(i=!0),!r&&a[0].from&&(r=!0),!l&&a[0].c&&(l=!0)),e&&e.length)for(var c=0;c<e.length;c++)e[c]&&(!t.length||t[t.length-1].ts<e[c].ts)?(t.push(e[c]),e[c].from&&(e[c].from.startsWith("system.adapter.")?e[c].from=e[c].from.substring(15):e[c].from.startsWith("system.host.")&&(e[c].from=e[c].from.substring(7))),!n&&e[c].lc&&(n=!0),o||void 0===e[c].q||(o=!0),i||void 0===e[c].ack||(i=!0),!r&&e[c].from&&(r=!0),!l&&e[c].c&&(l=!0),console.log("add value ".concat(new Date(e[c].ts).toISOString(),": ").concat(e[c].val))):t[t.length-1].ts===e[c].ts&&t[t.length-1].val!==e[c].ts&&console.error("Strange data!");else t.push({noDataForPeriod:!0});t.length||t.push({noData:!0}),s.setState({loading:!1,values:t,lcVisible:n,fromVisible:r,qVisible:o,ackVisible:i,cVisible:l})}))):null}},{key:"readHistoryRange",value:function(){var e=this,t=new Date,s=new Date(2e3,0,1);return this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:t.getTime(),step:2592e6,from:!1,ack:!1,q:!1,addID:!1,aggregate:"minmax"}).then((function(t){t.length?(null!==t[0].val&&t[0].ts!==s.getTime()||t.shift(),t.forEach((function(e){return e.i=!0})),e.rangeValues=t,e.setState({min:t[0].ts,max:t[t.length-1].ts,loading:!1})):(e.rangeValues=[],e.setState({loading:!1}))}))}},{key:"onToggleSelect",value:function(e,t,s){var a=Object(L.a)(this.state.selected),n=a.indexOf(t);if(e.shiftKey&&this.state.lastSelected){var o=-1,i=-1;a=[];for(var r=0;r<this.state.values.length&&(this.state.values[r].ts!==t||(i!==(o=r)&&a.push(this.state.values[r].ts),-1===o||-1===i))&&(this.state.values[r].ts!==this.state.lastSelected||((i=r)!==o&&a.push(this.state.values[r].ts),-1===o||-1===i));r++)-1===o&&-1===i||a.push(this.state.values[r].ts)}else e.ctrlKey?(-1!==n?a.splice(n,1):a.push(t),a.sort()):a=[t];window.localStorage.setItem("App.historyLastSelected",t.toString()),window.localStorage.setItem("App.historyLastSelectedColumn",s),window.localStorage.setItem("App.historySelected",JSON.stringify(a)),this.setState({selected:a,lastSelected:t,lastSelectedColumn:s})}},{key:"getTableRows",value:function(e){for(var t=this,s=[],a=function(a){var n=t.state.values[a],o=n.ts;if(n.e)s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,e.rowInterpolated),hover:!0,children:[Object(se.jsx)(ge.a,{}),Object(se.jsx)(ge.a,{children:"..."}),t.state.ackVisible?Object(se.jsx)(ge.a,{}):null,t.state.fromVisible?Object(se.jsx)(ge.a,{}):null,t.state.lcVisible?Object(se.jsx)(ge.a,{}):null]},o));else if(n.noData||n.noDataForPeriod)s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,e.rowNoData),hover:!0,children:[Object(se.jsx)(ge.a,{}),Object(se.jsx)(ge.a,{children:n.noData?t.props.t("No data in history"):t.props.t("No data in history for selected period")}),t.state.ackVisible?Object(se.jsx)(ge.a,{}):null,t.state.fromVisible?Object(se.jsx)(ge.a,{}):null,t.state.lcVisible?Object(se.jsx)(ge.a,{}):null]},n.noData?"nodata":""));else{var i=n.i,r=t.state.lastSelected===o,l=n.val;t.props.isFloatComma&&"number"===t.props.obj.common.type&&l&&(l=l.toString().replace(".",",")),null===l&&(l="null"),void 0===l&&(l="_"),s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,i&&e.rowInterpolated,t.state.selected.includes(o)&&e.rowSelected),children:[Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"ts")},children:["".concat(new Date(n.ts).toLocaleDateString()," ").concat(new Date(n.ts).toLocaleTimeString(),".").concat(Le(n.ts%1e3)),r&&"ts"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}),Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"val")},children:[l+t.unit,r&&"val"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}),t.state.ackVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"ack")},className:n.ack?e.cellAckTrue:e.cellAckFalse,children:[n.ack?"true":"false",r&&"ack"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null,t.state.fromVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"from")},children:[n.from||"",r&&"from"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null,t.state.lcVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"lc")},children:[n.lc?"".concat(new Date(n.lc).toLocaleDateString()," ").concat(new Date(n.lc).toLocaleTimeString(),".").concat(Le(n.ts%1e3)):"",r&&"lc"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null]},o+(n.val||"")))}},n=this.state.values.length-1;n>=0;n--)a(n);return s}},{key:"shiftTime",value:function(){var e=this,t=new Date,s=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);var a,n=t.getTime(),o=this.state.relativeRange;"day"===o?(t.setHours(0),t.setMinutes(0),a=t.getTime()):"week"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-1):t.setDate(t.getDate()-6)):"2weeks"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-8):t.setDate(t.getDate()-13)):"month"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),a=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),t.setMonth(0),a=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),a=t.getTime()):a=n-6e4*(o=parseInt(o,10)),this.setState({start:a,end:n},(function(){return e.readHistory()})),this.timeTimer=setTimeout((function(){e.timeTimer=null,e.shiftTime()}),s||6e4)}},{key:"setRelativeInterval",value:function(e,t){var s=this;if(t||(window.localStorage.setItem("App.relativeRange",e),this.setState({relativeRange:e})),"absolute"===e)return this.timeTimer&&clearTimeout(this.timeTimer),void(this.timeTimer=null);window.localStorage.removeItem("App.absoluteStart"),window.localStorage.removeItem("App.absolute");var a=new Date;if(!this.timeTimer){var n=6e4-a.getSeconds()-(1e3-a.getMilliseconds());this.timeTimer=setTimeout((function(){s.timeTimer=null,s.shiftTime()}),n||6e4)}a.getMilliseconds()&&a.setMilliseconds(1e3),a.getSeconds()&&a.setSeconds(60);var o,i=a.getTime();"day"===e?(a.setHours(0),a.setMinutes(0),o=a.getTime()):"week"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),a.getDay()?a.setDate(a.getDate()-a.getDay()-1):a.setDate(a.getDate()-6)):"2weeks"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),a.getDay()?a.setDate(a.getDate()-a.getDay()-8):a.setDate(a.getDate()-13)):"month"===e?(a.setHours(0),a.setMinutes(0),a.setDate(1),o=a.getTime()):"year"===e?(a.setHours(0),a.setMinutes(0),a.setDate(1),a.setMonth(0),o=a.getTime()):"12months"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),o=a.getTime()):o=i-6e4*(e=parseInt(e,10)),this.setState({start:o,end:i},(function(){return s.readHistory()}))}},{key:"renderTable",value:function(){if(this.state.values){var e=this.props.classes;return Object(se.jsx)(xe.a,{className:e.container,children:Object(se.jsxs)(be.a,{stickyHeader:!0,size:"small",className:e.table,children:[Object(se.jsx)(je.a,{children:Object(se.jsxs)(fe.a,{children:[Object(se.jsx)(ge.a,{className:e.colTs,children:this.props.t("Timestamp")}),Object(se.jsx)(ge.a,{className:e.colValue,children:this.props.t("Value")}),this.state.ackVisible?Object(se.jsx)(ge.a,{className:e.colAck,children:this.props.t("Ack")}):null,this.state.fromVisible?Object(se.jsx)(ge.a,{className:e.colFrom,children:this.props.t("From")}):null,this.state.lcVisible?Object(se.jsx)(ge.a,{className:e.colLastChange,children:this.props.t("Last change")}):null]})}),Object(se.jsx)(Oe.a,{children:this.getTableRows(e)})]})})}return Object(se.jsx)(U.a,{})}},{key:"renderConfirmDialog",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!!this.state.areYouSure,onClose:function(){return e.setState({areYouSure:!1})},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[Object(se.jsx)(h.a,{id:"alert-dialog-title"}),Object(se.jsxs)(p.a,{children:[Object(se.jsx)(b.a,{id:"alert-dialog-description",children:this.props.t("Are you sure?")}),Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{value:this.state.suppressMessage,onChange:function(){return e.setState({suppressMessage:!0})}}),label:this.props.t("Suppress for 5 minutes")})]}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({areYouSure:!1,suppressMessage:e.state.suppressMessage&&Date.now()},(function(){return e.onDelete()}))},color:"primary",autoFocus:!0,startIcon:Object(se.jsx)(y.a,{}),children:this.props.t("Delete")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({areYouSure:!1})},color:"secondary",startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}},{key:"onDelete",value:function(){var e=this,t=this.state.selected.map((function(t){return{state:{ts:t},id:e.props.obj._id}}));this.props.socket.sendTo(this.state.historyInstance,"delete",t).then((function(){return e.readHistory()}))}},{key:"onUpdate",value:function(){var e=this,t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?"number"!==typeof t&&(t=parseFloat(t.replace(",","."))):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));var s={val:t,ack:this.state.edit.ack,ts:this.state.selected[0],from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q};Object.keys(s).forEach((function(e){void 0===s[e]&&delete s[e]})),!this.state.lcVisible&&s.lc&&delete s.lc,this.props.socket.sendTo(this.state.historyInstance,"update",[{id:this.props.obj._id,state:s}]).then((function(){return e.readHistory()}))}},{key:"onInsert",value:function(){var e=this,t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?t=parseFloat(t.replace(",",".")):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));var s=this.state.edit.date;s.setHours(this.state.edit.time.getHours()),s.setMinutes(this.state.edit.time.getMinutes()),s.setSeconds(this.state.edit.time.getSeconds()),s.setMilliseconds(parseInt(this.state.edit.ms,10));var a={ts:s.getTime(),val:t,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((function(e){void 0===a[e]&&delete a[e]})),this.props.socket.sendTo(this.state.historyInstance,"insert",[{id:this.props.obj._id,state:a}]).then((function(){return e.readHistory()}))}},{key:"formatTime",value:function(e){var t=new Date(e);return"".concat(Ye(t.getHours()),":").concat(Ye(t.getMinutes()),":").concat(Ye(t.getSeconds()),".").concat(Le(t.getMilliseconds()))}},{key:"formatDate",value:function(e){var t=new Date(e);return"".concat(Ye(t.getDate()),".").concat(Ye(t.getMonth()+1),".").concat(t.getFullYear())}},{key:"updateEdit",value:function(e,t){var s=JSON.parse(JSON.stringify(this.state.edit));s.time=new Date(s.time),s.date=new Date(s.date),s[e]=t,this.setState({edit:s})}},{key:"renderEditDialog",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:this.state.updateOpened||this.state.insertOpened,onClose:function(){return e.setState({updateOpened:!1,insertOpened:!1})},"aria-labelledby":"edit-dialog-title","aria-describedby":"edit-dialog-description",children:[Object(se.jsx)(h.a,{id:"edit-dialog-title",children:this.state.updateOpened?this.props.t("Update entry"):this.props.t("Insert entry")}),Object(se.jsx)(p.a,{children:Object(se.jsxs)("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",children:["boolean"===typeof this.state.edit.val?Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:this.state.edit.val,onChange:function(t){return e.updateEdit("val",t.target.checked)}}),label:this.props.t("Value")}):Object(se.jsx)(ve.a,{label:this.props.t("Value"),value:this.state.edit.val,onChange:function(t){return e.updateEdit("val",t.target.value)}}),Object(se.jsx)("br",{}),Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:this.state.edit.ack,onChange:function(t){return e.updateEdit("ack",t.target.checked)}}),label:this.props.t("Acknowledged")}),this.state.insertOpened?Object(se.jsx)(ie.a,{utils:ye.a,locale:Je[this.props.lang],children:Object(se.jsxs)(me.a,{container:!0,justify:"space-around",children:[Object(se.jsx)(re.a,{className:this.props.classes.editorDatePicker,margin:"normal",label:this.props.t("Date"),format:this.state.dateFormat,value:this.state.edit.date,onChange:function(t){return e.updateEdit("date",t)}}),Object(se.jsx)(le.a,{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:function(t){return e.updateEdit("time",t)}}),Object(se.jsx)(ve.a,{classes:{root:this.props.classes.msInput},label:this.props.t("ms"),type:"number",inputProps:{max:999,min:0},value:this.state.edit.ms,onChange:function(t){return e.updateEdit("ms",t.target.value)}})]})}):null]})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){var t=e.state.updateOpened;e.setState({updateOpened:!1,insertOpened:!1},(function(){return t?e.onUpdate():e.onInsert()}))},color:"primary",autoFocus:!0,children:this.state.updateOpened?this.props.t("Update"):this.props.t("Add")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({updateOpened:!1,insertOpened:!1})},children:this.props.t("Cancel")})]})]})}},{key:"setStartDate",value:function(e){var t=this;e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",e),window.localStorage.setItem("App.absoluteEnd",this.state.end),this.setState({start:e,relativeRange:"absolute"},(function(){return t.readHistory()}))}},{key:"setEndDate",value:function(e){var t=this;e=e.getTime(),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",this.state.start),window.localStorage.setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.setState({end:e,relativeRange:"absolute"},(function(){return t.readHistory()}))}},{key:"renderToolbar",value:function(){var e=this,t=this.props.classes;return Object(se.jsxs)(pe.a,{children:[Object(se.jsxs)(de.a,{className:t.selectHistoryControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("History instance")}),Object(se.jsx)(he.a,{value:this.state.historyInstance,onChange:function(t){var s=t.target.value;window.localStorage.setItem("App.historyInstance",s),e.readSupportedFeatures(s).then((function(t){return e.setState({historyInstance:s,supportedFeatures:t},(function(){return e.readHistory()}))}))},children:this.state.historyInstances.map((function(e){return Object(se.jsx)(ue.a,{value:e.id,className:Object(Y.default)(!e.alive&&t.notAliveInstance),children:e.id},e.id)}))})]}),Object(se.jsxs)(de.a,{className:t.selectRelativeTime,children:[Object(se.jsx)(ce.a,{children:this.props.t("Relative")}),Object(se.jsxs)(he.a,{ref:this.rangeRef,value:this.state.relativeRange,onChange:function(t){return e.setRelativeInterval(t.target.value)},children:[Object(se.jsx)(ue.a,{value:"absolute",className:t.customRange,children:this.props.t("custom range")},"custom"),Object(se.jsx)(ue.a,{value:10,children:this.props.t("last 10 minutes")},"1"),Object(se.jsx)(ue.a,{value:30,children:this.props.t("last 30 minutes")},"2"),Object(se.jsx)(ue.a,{value:60,children:this.props.t("last hour")},"3"),Object(se.jsx)(ue.a,{value:"day",children:this.props.t("this day")},"4"),Object(se.jsx)(ue.a,{value:1440,children:this.props.t("last 24 hours")},"5"),Object(se.jsx)(ue.a,{value:"week",children:this.props.t("this week")},"6"),Object(se.jsx)(ue.a,{value:10080,children:this.props.t("last week")},"7"),Object(se.jsx)(ue.a,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),Object(se.jsx)(ue.a,{value:20160,children:this.props.t("last 2 weeks")},"9"),Object(se.jsx)(ue.a,{value:"month",children:this.props.t("this month")},"10"),Object(se.jsx)(ue.a,{value:43200,children:this.props.t("last 30 days")},"11"),Object(se.jsx)(ue.a,{value:"year",children:this.props.t("this year")},"12"),Object(se.jsx)(ue.a,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),Object(se.jsxs)(ie.a,{utils:ye.a,locale:Je[this.props.lang],children:[Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{className:t.toolbarDate,disabled:"absolute"!==this.state.relativeRange,disableToolbar:!0,variant:"inline",margin:"normal",format:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.start),onChange:function(t){return e.setStartDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.start),onChange:function(t){return e.setStartDate(t)}})]}),Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarDate,disableToolbar:!0,format:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.end),onChange:function(t){return e.setEndDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.end),onChange:function(t){return e.setEndDate(t)}})]})]}),Object(se.jsx)("div",{className:t.grow}),this.state.values&&this.state.values.length?Object(se.jsx)(f.a,{onClick:function(){return e.exportData()},title:this.props.t("Save data as csv"),children:Object(se.jsx)(We.FaDownload,{})}):null,this.state.supportedFeatures.includes("insert")&&this.props.expertMode?Object(se.jsx)(f.a,{onClick:function(){var t=new Date,s={ack:e.state.values[e.state.values.length-1].ack,val:e.state.values[e.state.values.length-1].val,ts:t,date:new Date(t),ms:0,time:new Date(t),q:0};e.setState({edit:s,insertOpened:!0})},children:Object(se.jsx)(We.FaPlusSquare,{})}):null,this.state.supportedFeatures.includes("update")&&this.props.expertMode?Object(se.jsx)(f.a,{disabled:1!==this.state.selected.length,onClick:function(){var t=JSON.parse(JSON.stringify(e.state.values.find((function(t){return t.ts===e.state.lastSelected})))),s=new Date(t.ts);t.date=new Date(s),t.time=new Date(s),e.setState({edit:t,updateOpened:!0})},children:Object(se.jsx)(Ve.a,{})}):null,this.state.supportedFeatures.includes("delete")&&this.props.expertMode?Object(se.jsx)(f.a,{disabled:!this.state.selected.length,onClick:function(){e.state.suppressMessage&&Date.now()-e.state.suppressMessage<3e5?e.onDelete():e.setState({areYouSure:!0})},children:Object(se.jsx)(y.a,{})}):null]})}},{key:"exportData",value:function(){var e=window.document.getElementById("export-file");e||((e=document.createElement("a")).setAttribute("id","export-file"),e.style.display="none",document.body.appendChild(e));var t=["timestamp;value;acknowledged;from;"];this.state.values.forEach((function(e){return!e.i&&!e.e&&t.push([new Date(e.ts).toISOString(),null===e.val||void 0===e.val?"null":e.val.toString(),e.ack?"true":"false",e.from||""].join(";"))})),e.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t.join("\n"))),e.setAttribute("download",He.a.getObjectName(Object(oe.a)({},this.props.obj._id,this.props.obj),this.props.obj._id,{language:this.props.lang})+".csv"),e.click(),document.body.removeChild(e)}},{key:"render",value:function(){return this.state.historyInstances?Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.state.loading?Object(se.jsx)(U.a,{}):Object(se.jsx)("div",{className:this.props.classes.noLoadingProgress}),this.renderToolbar(),Object(se.jsx)("div",{className:this.props.classes.tableDiv,children:this.renderTable()}),this.renderConfirmDialog(),this.renderEditDialog()]}):Object(se.jsx)(U.a,{})}}]),s}(l.Component),_e=Object(r.a)()(Object(u.a)((function(e){return{paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},tableDiv:{height:"calc(100% - ".concat(e.mixins.toolbar.minHeight+e.spacing(1),"px)"),overflow:"hidden",width:"100%"},container:{height:"100%"},table:{tableLayout:"fixed",minWidth:960,"& td:nth-of-type(5)":{overflow:"hidden",whiteSpace:"nowrap"}},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:e.palette.primary.main},rowSelected:{background:e.palette.secondary.main},rowFocused:{position:"absolute",pointerEvents:"none",top:0,bottom:0,left:0,right:0,margin:3,border:"1px dotted "+e.palette.action.active},grow:{flexGrow:1},editorTimePicker:{marginLeft:e.spacing(1),width:120},editorDatePicker:{marginLeft:e.spacing(1),width:150},msInput:{width:50,paddingTop:16,marginLeft:5,"& label":{marginTop:15}},cellAckTrue:{color:"#66ff7f"},cellAckFalse:{color:"#FF6666"},toolbarTime:{width:100,marginTop:9,marginLeft:e.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:e.spacing(1),paddingLeft:e.spacing(1),paddingRight:e.spacing(1),border:"1px dotted #AAAAAA",borderRadius:e.spacing(1)},noLoadingProgress:{width:"100%",height:4},colValue:{},colAck:{width:50},colFrom:{width:150},colLastChange:{width:200},colTs:{width:200}}}))(Ue)),Pe=s(614),Be=s(649),ze=s(1877),qe=s.n(ze),Xe=s(1567),Ge=s(2030),Ke=s(2038),$e=s(2045),Qe=s(2037),Ze=s(2036),et=s(2047),tt=s(2039),st=s(2042),at=s(1677);Xe.a([$e.a,Qe.a,Ze.a,et.a,tt.a,Ke.a,st.a]);var nt={en:Se.a,fr:we.a,ru:Ce.a,de:Ee.a,es:ke.a,br:Ae.a,nl:Re.a,it:Te.a,pt:De.a,pl:Ie.a,"zh-cn":Ne.a};function ot(e){return e<10?"0"+e:e}var it=80,rt=25,lt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n,o;Object(a.a)(this,s),(n=t.call(this,e)).onResize=function(){n.timerResize&&clearTimeout(n.timerResize),n.timerResize=setTimeout((function(){n.timerResize=null,n.componentDidUpdate()}))},n.onChange=function(e,t){e===n.props.obj._id&&t&&n.rangeValues&&(!n.rangeValues.length||n.rangeValues[n.rangeValues.length-1].ts<t.ts)&&(n.chartValues&&n.chartValues.push({val:t.val,ts:t.ts}),n.rangeValues.push({val:t.val,ts:t.ts}),t.ts>=n.chart.min&&t.ts<=n.chart.max+3e5&&n.updateChart())},n.props.from?n.start=n.props.from:((o=new Date(n.props.from)).setHours(o.getHours()-168),n.start=o.getTime()),n.props.end?n.end=n.props.end:n.end=Date.now();var i=window.localStorage.getItem("App.relativeRange")||"30",r=parseInt(window.localStorage.getItem("App.absoluteStart"),10)||0,c=parseInt(window.localStorage.getItem("App.absoluteEnd"),10)||0;return r&&c||i&&"absolute"!==i||(i="30"),c&&r&&(i="absolute"),n.state={loaded:!1,historyInstance:n.props.historyInstance||"",historyInstances:null,defaultHistory:"",chartHeight:300,chartWidth:500,relativeRange:i,splitLine:"true"===window.localStorage.getItem("App.splitLine"),dateFormat:"dd.MM.yyyy",min:r,max:c,maxYLen:0},n.echartsReact=Object(l.createRef)(),n.rangeRef=Object(l.createRef)(),n.readTimeout=null,n.chartValues=null,n.rangeValues=null,n.unit=n.props.obj.common&&n.props.obj.common.unit?" "+n.props.obj.common.unit:"",n.divRef=Object(l.createRef)(),n.chart={},n.onChange=n.onChange.bind(Object(Pe.a)(n)),n.onResize=n.onResize.bind(Object(Pe.a)(n)),n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e=this;this.props.socket.subscribeState(this.props.obj._id,this.onChange),window.addEventListener("resize",this.onResize),this.prepareData().then((function(){return!e.props.noToolbar&&e.readHistoryRange()})).then((function(){return e.setRelativeInterval(e.state.relativeRange,!0,(function(){return e.forceUpdate()}))}))}},{key:"componentWillUnmount",value:function(){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)}},{key:"prepareData",value:function(){var e,t=this;return this.props.noToolbar?new Promise((function(e){return t.setState({dateFormat:t.props.dateFormat.replace(/D/g,"d").replace(/Y/g,"y"),defaultHistory:t.props.defaultHistory,historyInstance:t.props.defaultHistory},(function(){return e()}))})):this.getHistoryInstances().then((function(s){return e=s,t.props.socket.getCompactSystemConfig()})).then((function(s){return t.props.showJumpToEchart?t.props.socket.getAdapterInstances("echarts").then((function(a){var n=!!a.find((function(e){return e._id.startsWith("system.adapter.echarts.")})),o=s&&s.common&&s.common.defaultHistory,i=window.localStorage.getItem("App.historyInstance")||"";i&&e.find((function(e){return e.id===i&&e.alive}))||(i=o),i&&e.find((function(e){return e.id===i&&e.alive}))||(i=e.find((function(e){return e.alive})))&&(i=i.id),!i&&e.length&&(i=o),t.setState({dateFormat:(s.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y"),historyInstances:e,defaultHistory:o,historyInstance:i,echartsJump:n})})):Promise.resolve([])}))}},{key:"getHistoryInstances",value:function(){var e=this,t=[],s=[];return this.props.historyInstance?Promise.resolve(t):(this.props.customsInstances.forEach((function(a){var n=e.props.objects["system.adapter."+a];if(n&&n.common&&n.common.getHistory){var o={id:a,alive:!1};t.push(o),s.push("system.adapter.".concat(a,".alive"))}})),s.length?this.props.socket.getForeignStates(s).then((function(e){return Object.keys(e).forEach((function(s){var a=t.find((function(e){return s.endsWith(e.id+".alive")}));a&&(a.alive=e[s]&&e[s].val)})),t})):Promise.resolve(t))}},{key:"readHistoryRange",value:function(){var e=this,t=new Date,s=new Date(2e3,0,1);return this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:t.getTime(),step:36e5,from:!1,ack:!1,q:!1,addID:!1,aggregate:"minmax"}).then((function(t){var s;t&&null===(null===(s=t[0])||void 0===s?void 0:s.val)&&t.shift(),e.rangeValues=t}))}},{key:"readHistory",value:function(e,t){var s=this,a={instance:this.state.historyInstance,start:e,end:t,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"};return t-e>144e4&&!("boolean"===this.props.obj.common.type||"number"===this.props.obj.common.type&&this.props.obj.common.states)&&(a.aggregate="minmax"),this.props.socket.getHistory(this.props.obj._id,a).then((function(e){for(var t=[],a=0,n=s.rangeValues,o=null,i=null,r=0;r<e.length;r++){if(n)for(;a<n.length&&n[a].ts<e[r].ts;)t.push(n[a]),a++;!t.length||t[t.length-1].ts<e[r].ts?t.push(e[r]):t[t.length-1].ts===e[r].ts&&t[t.length-1].val!==e[r].ts&&console.error("Strange data!"),(null===o||e[r].val<o)&&(o=e[r].val),(null===i||e[r].val>i)&&(i=e[r].val)}if(n)for(;a<n.length;)t.push(n[a]),console.log("add range ".concat(new Date(n[a].ts).toISOString(),": ").concat(n[a].val)),a++;return t.sort((function(e,t){return e.ts>t.ts?1:e.ts<t.ts?-1:0})),s.chartValues=t,s.minY=o,s.maxY=i,s.minY<10?s.minY=Math.round(10*s.minY)/10:s.minY=Math.ceil(s.minY),s.maxY<10?s.maxY=Math.round(10*s.maxY)/10:s.maxY=Math.ceil(s.maxY),t}))}},{key:"convertData",value:function(e){var t=[];if(!(e=e||this.chartValues).length)return t;for(var s=0;s<e.length;s++)t.push({value:[e[s].ts,e[s].val]});return this.chart.min||(this.chart.min=e[0].ts,this.chart.max=e[e.length-1].ts),t}},{key:"getOption",value:function(){var e,t=this;if(null!==this.minY&&void 0!==this.minY&&(e=9*(this.minY.toString()+this.unit).length+12),null!==this.maxY&&void 0!==this.maxY){var s=9*(this.maxY.toString()+this.unit).length+12;s>e&&(e=s)}if(this.state.maxYLen){var a=9*this.state.maxYLen+12;a>e&&(e=a)}var n={xAxisIndex:0,type:"line",showSymbol:!1,hoverAnimation:!0,animation:!1,data:this.convertData(),lineStyle:{color:"#4dabf5"},areaStyle:{}},o={type:"value",boundaryGap:[0,"100%"],splitLine:{show:this.props.noToolbar||!!this.state.splitLine},splitNumber:Math.round(this.state.chartHeight/50),axisLabel:{formatter:function(e,s){var a;return a=t.props.isFloatComma?e.toString().replace(",",".")+t.unit:e+t.unit,t.state.maxYLen<a.length&&(t.maxYLenTimeout&&clearTimeout(t.maxYLenTimeout),t.maxYLenTimeout=setTimeout((function(e){return t.setState({maxYLen:e})}),200,a.length)),a},showMaxLabel:!0,showMinLabel:!0},axisTick:{alignWithLabel:!0}};if("boolean"===this.props.obj.common.type)n.step="end",o.axisLabel.showMaxLabel=!1,o.axisLabel.formatter=function(e){return 1===e?"TRUE":"FALSE"},o.max=1.5,o.interval=1,e=50;else if("number"===this.props.obj.common.type&&this.props.obj.common.states){n.step="end",o.axisLabel.showMaxLabel=!1,o.axisLabel.formatter=function(e){return void 0!==t.props.obj.common.states[e]?t.props.obj.common.states[e]:e};var i=Object.keys(this.props.obj.common.states);i.sort(),o.max=parseFloat(i[i.length-1])+.5,o.interval=1;for(var r="",l=0;l<i.length;l++)"string"===typeof this.props.obj.common.states[i[l]]&&this.props.obj.common.states[i[l]].length>r.length&&(r=this.props.obj.common.states[i[l]]);e=(9*r.length||50)+12}return{backgroundColor:"transparent",title:{text:this.props.noToolbar?"":He.a.getObjectNameFromObj(this.props.obj,this.props.lang),padding:[10,0,0,e?e+10:90]},grid:{left:e||it,top:8,right:this.props.noToolbar?5:rt,bottom:40},tooltip:{trigger:"axis",formatter:function(e){e=e[0];var s,a=new Date(e.value[0]),n=e.value[1];return null!==n&&t.props.isFloatComma&&(n=n.toString().replace(".",",")),"".concat(a.toLocaleString(),".").concat((s=a.getMilliseconds(),s<10?"00"+s:s<100?"0"+s:s),": ").concat(n).concat(t.unit)},axisPointer:{animation:!0}},xAxis:{type:"time",splitLine:{show:!1},splitNumber:this.chart.withSeconds?Math.round((this.state.chartWidth-rt-it)/70):Math.round((this.state.chartWidth-rt-it)/50),min:this.chart.min,max:this.chart.max,axisTick:{alignWithLabel:!0},axisLabel:{formatter:function(e,s){var a=new Date(e);return t.chart.withSeconds?ot(a.getHours())+":"+ot(a.getMinutes())+":"+ot(a.getSeconds()):t.chart.withTime?ot(a.getHours())+":"+ot(a.getMinutes())+"\n"+ot(a.getDate())+"."+ot(a.getMonth()+1):ot(a.getDate())+"."+ot(a.getMonth()+1)+"\n"+a.getFullYear()}}},yAxis:o,toolbox:{left:"right",feature:this.props.noToolbar?void 0:{saveAsImage:{title:this.props.t("Save as image"),show:!0}}},series:[n]}}},{key:"updateChart",value:function(e,t,s,a){var n=this;e&&(this.start=e),t&&(this.end=t),e=e||this.start,t=t||this.end,this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=setTimeout((function(){n.readTimeout=null;var o=n.chart.max-n.chart.min;o!==n.chart.diff&&(n.chart.diff=o,n.chart.withTime=n.chart.diff<6048e5,n.chart.withSeconds=n.chart.diff<18e5),s?n.readHistory(e,t).then((function(e){n.echartsReact&&"function"===typeof n.echartsReact.getEchartsInstance&&n.echartsReact.getEchartsInstance().setOption({series:[{data:n.convertData(e)}],xAxis:{min:n.chart.min,max:n.chart.max}}),a&&a()})):(n.echartsReact&&"function"===typeof n.echartsReact.getEchartsInstance&&n.echartsReact.getEchartsInstance().setOption({series:[{data:n.convertData()}],xAxis:{min:n.chart.min,max:n.chart.max}}),a&&a())}),400)}},{key:"setNewRange",value:function(e){this.chart.diff=this.chart.max-this.chart.min,this.chart.withTime=this.chart.diff<6048e5,this.chart.withSeconds=this.chart.diff<18e5,"absolute"!==this.state.relativeRange?this.setState({relativeRange:"absolute"}):this.echartsReact&&"function"===typeof this.echartsReact.getEchartsInstance&&(this.echartsReact.getEchartsInstance().setOption({xAxis:{min:this.chart.min,max:this.chart.max}}),e&&this.updateChart(this.chart.min,this.chart.max,!0))}},{key:"shiftTime",value:function(){var e=this,t=new Date,s=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);var a,n=t.getTime(),o=this.state.relativeRange;"day"===o?(t.setHours(0),t.setMinutes(0),a=t.getTime()):"week"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-1):t.setDate(t.getDate()-6),this.chart.min=t.getTime()):"2weeks"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-8):t.setDate(t.getDate()-13),this.chart.min=t.getTime()):"month"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),a=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),t.setMonth(0),a=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),a=t.getTime()):a=n-6e4*(o=parseInt(o,10)),this.chart.min=a,this.chart.max=n,this.setState({min:a,max:n},(function(){return e.updateChart(e.chart.min,e.chart.max,!0)})),this.timeTimer=setTimeout((function(){e.timeTimer=null,e.shiftTime()}),s||6e4)}},{key:"setRelativeInterval",value:function(e,t,s){var a=this;if(t||(window.localStorage.setItem("App.relativeRange",e),this.setState({relativeRange:e})),"absolute"===e)return this.timeTimer&&clearTimeout(this.timeTimer),void(this.timeTimer=null);window.localStorage.removeItem("App.absoluteStart"),window.localStorage.removeItem("App.absoluteEnd");var n=new Date;if(!this.timeTimer){var o=6e4-n.getSeconds()-(1e3-n.getMilliseconds());this.timeTimer=setTimeout((function(){a.timeTimer=null,a.shiftTime()}),o||6e4)}n.getMilliseconds()&&n.setMilliseconds(1e3),n.getSeconds()&&n.setSeconds(60),this.chart.max=n.getTime(),"day"===e?(n.setHours(0),n.setMinutes(0),this.chart.min=n.getTime()):"week"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),n.getDay()?n.setDate(n.getDate()-n.getDay()-1):n.setDate(n.getDate()-6),this.chart.min=n.getTime()):"2weeks"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),n.getDay()?n.setDate(n.getDate()-n.getDay()-8):n.setDate(n.getDate()-13),this.chart.min=n.getTime()):"month"===e?(n.setHours(0),n.setMinutes(0),n.setDate(1),this.chart.min=n.getTime()):"year"===e?(n.setHours(0),n.setMinutes(0),n.setDate(1),n.setMonth(0),this.chart.min=n.getTime()):"12months"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),this.chart.min=n.getTime()):(e=parseInt(e,10),this.chart.min=this.chart.max-6e4*e),this.setState({min:this.chart.min,max:this.chart.max},(function(){return a.updateChart(a.chart.min,a.chart.max,!0,s)}))}},{key:"installEventHandlers",value:function(){var e=this;if(this.echartsReact&&"function"===typeof this.echartsReact.getEchartsInstance){var t=this.echartsReact.getEchartsInstance().getZr();t._iobInstalled||(t._iobInstalled=!0,t.on("mousedown",(function(t){console.log("mouse down"),e.mouseDown=!0,e.chart.lastX=t.offsetX})),t.on("mouseup",(function(){console.log("mouse up"),e.mouseDown=!1,e.setNewRange(!0)})),t.on("mousewheel",(function(t){var s=e.chart.max-e.chart.min,a=e.state.chartWidth-rt-it,n=(t.offsetX-it)/a,o=s-(s*=t.wheelDelta>0?1.1:.9);e.chart.max+=o*(1-n),e.chart.min-=o*n,e.setNewRange()})),t.on("mousemove",(function(t){if(e.mouseDown){var s=e.chart.lastX-(t.offsetX-it);e.chart.lastX=t.offsetX-it;var a=e.chart.max-e.chart.min,n=e.state.chartWidth-rt-it,o=Math.round(s*a/n);e.chart.min+=o,e.chart.max+=o,e.setNewRange()}})),t.on("touchstart",(function(t){t.preventDefault(),e.mouseDown=!0;var s=t.touches||t.originalEvent.touches;s&&(e.chart.lastX=s[s.length-1].pageX,s.length>1?e.chart.lastWidth=Math.abs(s[0].pageX-s[1].pageX):e.chart.lastWidth=null)})),t.on("touchend",(function(t){t.preventDefault(),e.mouseDown=!1,e.setNewRange(!0)})),t.on("touchmove",(function(t){t.preventDefault();var s=t.touches||t.originalEvent.touches;if(s){var a=s[s.length-1].pageX-it;if(e.mouseDown)if(s.length>1){var n=Math.abs(s[0].pageX-s[1].pageX);if(null!==e.chart.lastWidth&&n!==e.chart.lastWidth){var o=e.chart.max-e.chart.min,i=e.state.chartWidth-rt-it,r=n>e.chart.lastWidth?1.1:.9,l=(s[0].pageX>s[1].pageX?s[1].pageX-it+n/2:s[0].pageX-it+n/2)/i,c=o-(o*=r);e.chart.max+=c*(1-l),e.chart.min-=c*l,e.setNewRange()}e.chart.lastWidth=n}else{var u=e.chart.lastX-a,d=e.chart.max-e.chart.min,h=e.state.chartWidth-rt-it,p=Math.round(u*d/h);e.chart.min+=p,e.chart.max+=p,e.setNewRange()}e.chart.lastX=a}})))}}},{key:"renderChart",value:function(){var e=this;return this.chartValues?Object(se.jsx)(qe.a,{ref:function(t){return e.echartsReact=t},echarts:Ge,option:this.getOption(),notMerge:!0,lazyUpdate:!0,theme:"dark"===this.props.themeType?"dark":"",style:{height:this.state.chartHeight+"px",width:"100%"},opts:{renderer:"svg"},onEvents:{rendered:function(t){e.installEventHandlers()}}}):Object(se.jsx)(U.a,{})}},{key:"componentDidUpdate",value:function(){var e=this;if(this.divRef.current){var t=this.divRef.current.offsetWidth,s=this.divRef.current.offsetHeight;this.state.chartHeight!==s&&setTimeout((function(){return e.setState({chartHeight:s,chartWidth:t})}),100)}}},{key:"setStartDate",value:function(e){var t=this;e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",e),window.localStorage.setItem("App.absoluteEnd",this.state.max),this.chart.min=e,this.setState({min:e,relativeRange:"absolute"},(function(){return t.updateChart(t.chart.min,t.chart.max,!0)}))}},{key:"setEndDate",value:function(e){var t=this;e=e.getTime(),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",this.state.min),window.localStorage.setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.chart.max=e,this.setState({max:e,relativeRange:"absolute"},(function(){return t.updateChart(t.chart.min,t.chart.max,!0)}))}},{key:"openEcharts",value:function(){var e=["id="+window.encodeURIComponent(this.props.obj._id),"instance="+window.encodeURIComponent(this.state.historyInstance),"menuOpened=false"];"absolute"===this.state.relativeRange?(e.push("start="+this.chart.min),e.push("end="+this.chart.max)):e.push("range="+this.state.relativeRange),window.open("".concat(window.location.protocol,"//").concat(window.location.host,"/adapter/echarts/tab.html#").concat(e.join("&")),"echarts")}},{key:"renderToolbar",value:function(){var e=this;if(this.props.noToolbar)return null;var t=this.props.classes;return Object(se.jsxs)(pe.a,{children:[!this.props.historyInstance&&Object(se.jsxs)(de.a,{className:t.selectHistoryControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("History instance")}),Object(se.jsx)(he.a,{value:this.state.historyInstance,onChange:function(t){window.localStorage.setItem("App.historyInstance",t.target.value),e.setState({historyInstance:t.target.value})},children:this.state.historyInstances.map((function(e){return Object(se.jsx)(ue.a,{value:e.id,className:Object(Y.default)(!e.alive&&t.notAliveInstance),children:e.id},e.id)}))})]}),Object(se.jsxs)(de.a,{className:t.selectRelativeTime,children:[Object(se.jsx)(ce.a,{children:this.props.t("Relative")}),Object(se.jsxs)(he.a,{ref:this.rangeRef,value:this.state.relativeRange,onChange:function(t){return e.setRelativeInterval(t.target.value)},children:[Object(se.jsx)(ue.a,{value:"absolute",className:t.customRange,children:this.props.t("custom range")},"custom"),Object(se.jsx)(ue.a,{value:10,children:this.props.t("last 10 minutes")},"1"),Object(se.jsx)(ue.a,{value:30,children:this.props.t("last 30 minutes")},"2"),Object(se.jsx)(ue.a,{value:60,children:this.props.t("last hour")},"3"),Object(se.jsx)(ue.a,{value:"day",children:this.props.t("this day")},"4"),Object(se.jsx)(ue.a,{value:1440,children:this.props.t("last 24 hours")},"5"),Object(se.jsx)(ue.a,{value:"week",children:this.props.t("this week")},"6"),Object(se.jsx)(ue.a,{value:10080,children:this.props.t("last week")},"7"),Object(se.jsx)(ue.a,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),Object(se.jsx)(ue.a,{value:20160,children:this.props.t("last 2 weeks")},"9"),Object(se.jsx)(ue.a,{value:"month",children:this.props.t("this month")},"10"),Object(se.jsx)(ue.a,{value:43200,children:this.props.t("last 30 days")},"11"),Object(se.jsx)(ue.a,{value:"year",children:this.props.t("this year")},"12"),Object(se.jsx)(ue.a,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),Object(se.jsxs)(ie.a,{utils:ye.a,locale:nt[this.props.lang],children:[Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{className:t.toolbarDate,disabled:"absolute"!==this.state.relativeRange,disableToolbar:!0,variant:"inline",margin:"normal",format:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.min),onChange:function(t){return e.setStartDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.min),onChange:function(t){return e.setStartDate(t)}})]}),Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarDate,disableToolbar:!0,format:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.max),onChange:function(t){return e.setEndDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.max),onChange:function(t){return e.setEndDate(t)}})]})]}),Object(se.jsx)("div",{className:t.grow}),this.props.showJumpToEchart&&this.state.echartsJump&&Object(se.jsx)(Be.a,{className:t.echartsButton,size:"small",onClick:function(){return e.openEcharts()},title:this.props.t("Open charts in new window"),children:Object(se.jsx)("img",{src:at.default,alt:"echarts",className:t.buttonIcon})}),Object(se.jsxs)(Be.a,{variant:"extended",size:"small",color:this.state.splitLine?"primary":"inherit","aria-label":"show lines",onClick:function(){window.localStorage.setItem("App.splitLine",e.state.splitLine?"false":"true"),e.setState({splitLine:!e.state.splitLine})},className:t.splitLineButton,children:[Object(se.jsx)(We.FaChartLine,{className:t.splitLineButtonIcon}),this.props.t("Show lines")]})]})}},{key:"render",value:function(){return this.state.historyInstances||this.state.defaultHistory?Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.renderToolbar(),Object(se.jsx)("div",{ref:this.divRef,className:Object(Y.default)(this.props.classes.chart,this.props.noToolbar?this.props.classes.chartWithoutToolbar:this.props.classes.chartWithToolbar),children:this.renderChart()})]}):Object(se.jsx)(U.a,{})}}],[{key:"getDerivedStateFromProps",value:function(e,t){return null}}]),s}(l.Component),ct=Object(r.a)()(Object(u.a)((function(e){return{paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden",width:"100%"},chart:{width:"100%",overflow:"hidden"},chartWithToolbar:{height:"calc(100% - ".concat(e.mixins.toolbar.minHeight+e.spacing(1),"px)")},chartWithoutToolbar:{height:"100%"},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:e.palette.primary.main},splitLineButtonIcon:{marginRight:e.spacing(1)},splitLineButton:{float:"right"},grow:{flexGrow:1},toolbarTime:{width:100,marginTop:9,marginLeft:e.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:e.spacing(1),paddingLeft:e.spacing(1),paddingRight:e.spacing(1),border:"1px dotted #AAAAAA",borderRadius:e.spacing(1)},buttonIcon:{width:24,height:24},echartsButton:{marginRight:e.spacing(1),height:34,width:34}}}))(lt)),ut=s(385),dt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),n=t.call(this,e);var o=parseInt(window.localStorage.getItem("App.objectCustomTab")||0,10);if(n.chartAvailable=n.isChartAvailable(),n.chartAvailable){var i=N.a.getLocation();"chart"===i.arg?o=2:"table"===i.arg&&(o=1)}else o=0;return n.state={hasChanges:!1,currentTab:o,confirmDialog:!1,mobile:ut.b.isMobile(),progressRunning:!1},n.saveFunc=null,n}return Object(n.a)(s,[{key:"isChartAvailable",value:function(){var e=this,t=1===this.props.objectIDs.length;if(t){var s=this.props.objectIDs[0];t=!!(this.props.objects[s]&&this.props.objects[s].common&&this.props.objects[s].common.custom&&this.props.objects[s].common.custom)&&Object.keys(this.props.objects[s].common.custom).find((function(t){var s=e.props.objects["system.adapter."+t];return s&&s.common&&s.common.getHistory}))}return t}},{key:"renderCharts",value:function(){return Object(se.jsx)(ct,{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})}},{key:"renderTable",value:function(){return Object(se.jsx)(_e,{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})}},{key:"renderCustomEditor",value:function(){var e=this;return Object(se.jsx)(ne,{id:"custom-settings-tabpanel",registerSaveFunc:function(t){return e.saveFunc=t},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:function(t){return e.setState({progressRunning:t})},reportChangedIds:this.props.reportChangedIds,onChange:function(t,s){e.setState({hasChanges:t},(function(){if(s){var t=e.isChartAvailable();t!==e.chartAvailable&&(e.chartAvailable=t,e.forceUpdate())}}))},theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType})}},{key:"renderConfirmDialog",value:function(){var e=this;return this.state.confirmDialog?Object(se.jsx)(E.a,{title:F.a.t("You have unsaved changes"),text:F.a.t("Discard?"),ok:F.a.t("Yes"),cancel:F.a.t("Cancel"),onClose:function(t){return e.setState({confirmDialog:!1},(function(){return t&&e.props.onClose()}))}}):null}},{key:"onClose",value:function(){this.state.hasChanges?this.setState({confirmDialog:!0}):this.props.onClose()}},{key:"render",value:function(){var e,t,s=this,a=null===(e=this.props.objects[this.props.objectIDs[0]])||void 0===e||null===(t=e.common)||void 0===t?void 0:t.type;return Object(se.jsxs)(d.a,{classes:{scrollPaper:this.props.classes.dialog,paper:this.props.classes.paper},scroll:"paper",open:!0,onClose:function(){return s.props.onClose()},fullWidth:!0,maxWidth:"xl","aria-labelledby":"form-dialog-title",children:[this.renderConfirmDialog(),Object(se.jsx)(h.a,{children: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])}),Object(se.jsxs)(p.a,{className:this.props.classes.content,children:[Object(se.jsx)(k.a,{position:"static",children:Object(se.jsxs)(I.a,{value:this.state.currentTab,onChange:function(e,t){N.a.doNavigate(null,null,null,1===t?"table":2===t?"chart":"config"),s.setState({currentTab:t}),window.localStorage.setItem("App.objectCustomTab",t)},children:[Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("Custom settings"),id:"custom-settings-tab","aria-controls":"simple-tabpanel-0"}),1===this.props.objectIDs.length&&this.chartAvailable?Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("History data"),id:"history-data-tab","aria-controls":"simple-tabpanel-1"}):null,"number"!==a&&"boolean"!==a||1!==this.props.objectIDs.length||!this.chartAvailable?null:Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("Chart"),id:"chart-tab","aria-controls":"simple-tabpanel-2"})]})}),0===this.state.currentTab?Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderCustomEditor()}):null,1===this.props.objectIDs.length&&this.chartAvailable&&1===this.state.currentTab?Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderTable()}):null,"number"!==a&&"boolean"!==a||1!==this.props.objectIDs.length||!this.chartAvailable||2!==this.state.currentTab?null:Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderCharts()})]}),Object(se.jsxs)(m.a,{children:[0===this.state.currentTab&&Object(se.jsx)(j.a,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:function(){return s.saveFunc&&s.saveFunc()},children:this.getButtonTitle(Object(se.jsx)(M.a,{}),this.props.t("Save"))}),0===this.state.currentTab&&Object(se.jsx)(j.a,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:function(){s.saveFunc?s.saveFunc((function(e){return!e&&s.onClose()})):s.onClose()},children:this.getButtonTitle(Object(se.jsx)(M.a,{}),this.props.t("Save & close"),Object(se.jsx)(O.a,{}))}),Object(se.jsx)(j.a,{disabled:this.state.progressRunning,variant:"contained",onClick:function(){return s.onClose()},children:this.getButtonTitle(Object(se.jsx)(O.a,{}),this.props.t("Close"))})]})]})}}]),s}(ut.b);dt.propTypes={t:S.a.func,lang:S.a.string,expertMode:S.a.bool,objects:S.a.object,socket:S.a.object,theme:S.a.object,themeName:S.a.string,themeType:S.a.string,customsInstances:S.a.array,objectIDs:S.a.array,onClose:S.a.func,reportChangedIds:S.a.func,isFloatComma:S.a.bool};var ht=Object(u.a)((function(e){return{dialog:{height:"100%"},paper:{height:"calc(100% - 64px)"},content:{textAlign:"center",overflow:"hidden"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+e.mixins.toolbar.minHeight+"px)"}}}))(dt),pt=s(354),mt=s.n(pt),bt=(s(534),s(535),s(536),s(537),s(538),s(1524)),jt=s(502),ft=s(767),gt=s.n(ft),vt=s(53),Ot=s.n(vt),xt=Object(u.a)((function(e){return{root:{width:28,height:16,padding:0,display:"flex"},switchBase:{padding:2,color:e.palette.grey[500],"&$checked":{transform:"translateX(12px)",color:e.palette.common.white,"& + $track":{opacity:1,backgroundColor:e.palette.primary.main,borderColor:e.palette.primary.main}}},thumb:{width:12,height:12,boxShadow:"none"},track:{border:"1px solid ".concat(e.palette.grey[500]),borderRadius:8,opacity:1,backgroundColor:e.palette.common.white},checked:{}}}))(jt.a),yt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s);var o=(n=t.call(this,e)).props.type||typeof n.props.value;if(n.value=n.props.value,n.propsValue=n.value,null===n.propsValue?n.propsValue="null":void 0===n.propsValue&&(n.propsValue="undefined"),n.props.states)o="states";else if(("string"===o||"json"===o)&&n.value&&"string"===typeof n.value&&(n.value.startsWith("[")&&n.value.endsWith("]")||n.value.startsWith("{")&&n.value.endsWith("}")))try{n.value=JSON.parse(n.value),n.value=JSON.stringify(n.value,null,2),n.propsValue=n.value,o="json"}catch(i){}return n.state={type:o,chart:!1,chartEnabled:"false"!==window.localStorage.getItem("App.chartSetValue")},n.ack=!1,n.q=0,n.expire=0,n.inputRef=c.a.createRef(),n.chartFrom=Date.now()-72e5,n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e,t,s,a=this;this.props.defaultHistory&&(null===(e=this.props.object)||void 0===e||null===(t=e.common)||void 0===t?void 0:t.custom)&&(null===(s=this.props.object.common.custom[this.props.defaultHistory])||void 0===s?void 0:s.enabled)&&this.props.socket.getState("system.adapter."+this.props.defaultHistory+".alive").then((function(e){return a.setState({chart:e&&!!e.val})})),setTimeout((function(){if(a.inputRef&&a.inputRef.current){var e=a.inputRef.current,t=e.value||"";e.setSelectionRange(0,t.length)}}),200)}},{key:"onUpdate",value:function(){if("states"===this.state.type){var e=this.props.type||typeof this.props.value;"number"===e?"string"===typeof this.value&&(this.value=parseFloat(this.value.replace(",","."))||0):"boolean"===e&&(this.value=!0===this.value||"true"===this.value||"1"===this.value||"ON"===this.value||"on"===this.value)}else"number"===this.state.type?"string"===typeof this.value&&(this.value=parseFloat(this.value.replace(",","."))||0):"boolean"===this.state.type&&(this.value=!0===this.value||"true"===this.value||"1"===this.value||"ON"===this.value||"on"===this.value);this.props.onClose({val:this.value,ack:this.ack,q:this.q,expire:parseInt(this.expire,10)||void 0})}},{key:"renderChart",value:function(){return Object(se.jsx)(ct,{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})}},{key:"checkJsonError",value:function(){try{JSON.parse(this.value),this.setState({jsonError:!1})}catch(e){this.setState({jsonError:!0})}}},{key:"renderJsonEditor",value:function(){var e=this;return Object(se.jsx)(mt.a,{className:this.state.jsonError?this.props.classes.jsonError:this.props.classes.jsonNoError,mode:"json",width:"100%",height:"200px",showPrintMargin:!0,showGutter:!0,highlightActiveLine:!0,theme:"dark"===this.props.themeType?"clouds_midnight":"chrome",defaultValue:(this.propsValue||"").toString(),onChange:function(t){e.value=t,e.checkJsonError()},name:"UNIQUE_ID_OF_DIV1",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:!0,tabSize:2},editorProps:{$blockScrolling:!0}})}},{key:"renderStates",value:function(){var e=this;return this.props.states?Object(se.jsxs)(de.a,{className:this.props.classes.formControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("Value")}),Object(se.jsx)(he.a,{defaultValue:this.propsValue,onChange:function(t){return e.value=t.target.value},children:Object.keys(this.props.states).map((function(t,s){return Object(se.jsx)(ue.a,{value:t,children:e.props.states[t]},s)}))})]}):null}},{key:"render",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!0,maxWidth:"number"===this.state.type||"boolean"===this.state.type||"states"===this.state.type?this.state.chart&&this.state.chartEnabled?"lg":null:"md",fullWidth:"number"!==this.state.type&&"boolean"!==this.state.type&&"states"!==this.state.type||this.state.chart&&this.state.chartEnabled,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",children:[Object(se.jsxs)(h.a,{id:"edit-value-dialog-title",children:[this.props.t("Write value"),this.state.chart?Object(se.jsx)(Be.a,{style:{float:"right"},size:"small",color:this.state.chartEnabled?"primary":"default",onClick:function(){window.localStorage.setItem("App.chartSetValue",e.state.chartEnabled?"false":"true"),e.setState({chartEnabled:!e.state.chartEnabled})},children:Object(se.jsx)(gt.a,{})}):null]}),Object(se.jsx)(p.a,{children:Object(se.jsx)("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",children:Object(se.jsxs)(me.a,{container:!0,direction:"row",spacing:2,children:[Object(se.jsx)(me.a,{item:!0,xs:this.state.chart&&this.state.chartEnabled?6:12,children:Object(se.jsxs)(me.a,{container:!0,direction:"column",spacing:2,children:[this.props.expertMode?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsxs)(de.a,{className:this.props.classes.formControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("Value type")}),Object(se.jsxs)(he.a,{value:this.state.type,onChange:function(t){"json"===t.target.value&&(e.value=(e.value||"").toString(),e.checkJsonError()),e.setState({type:t.target.value})},children:[Object(se.jsx)(ue.a,{value:"string",children:"String"}),Object(se.jsx)(ue.a,{value:"number",children:"Number"}),Object(se.jsx)(ue.a,{value:"boolean",children:"Boolean"}),Object(se.jsx)(ue.a,{value:"json",children:"JSON"}),this.props.states?Object(se.jsx)(ue.a,{value:"states",children:"States"}):null]})]})}):null,Object(se.jsx)(me.a,{item:!0,children:"boolean"===this.state.type?Object(se.jsx)(z.a,{component:"div",children:Object(se.jsxs)(me.a,{component:"label",container:!0,alignItems:"center",spacing:1,children:[Object(se.jsxs)(me.a,{item:!0,style:{marginRight:10},children:[this.props.t("Value"),":"]}),Object(se.jsx)(me.a,{item:!0,children:"FALSE"}),Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(xt,{autoFocus:!0,defaultChecked:!!this.propsValue,onKeyUp:function(t){return 13===t.keyCode&&e.onUpdate()},onChange:function(t){return e.value=t.target.checked}})}),Object(se.jsx)(me.a,{item:!0,children:"TRUE"})]})}):"number"===this.state.type?Object(se.jsx)(ve.a,{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:function(t){return 13===t.keyCode&&e.onUpdate()},onChange:function(t){return e.value=t.target.value}}):"json"===this.state.type?this.renderJsonEditor():"states"===this.state.type?this.renderStates():Object(se.jsx)(ve.a,{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,onKeyUp:function(t){return t.ctrlKey&&13===t.keyCode&&e.onUpdate()},defaultValue:this.propsValue.toString(),onChange:function(t){return e.value=t.target.value}})}),Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(X.a,{className:this.props.classes.formControl,control:Object(se.jsx)(G.a,{defaultChecked:!1,onChange:function(t){return e.ack=t.target.checked}}),label:this.props.t("Acknowledged")})}),this.props.expertMode?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsxs)(de.a,{className:this.props.classes.quality,children:[Object(se.jsx)(ce.a,{children:this.props.t("Quality")}),Object(se.jsxs)(he.a,{defaultValue:0,onChange:function(t){return e.q=parseInt(t.target.value,10)},children:[Object(se.jsx)(ue.a,{value:0,children:"0x00 - good"}),Object(se.jsx)(ue.a,{value:1,children:"0x01 - general problem"}),Object(se.jsx)(ue.a,{value:2,children:"0x02 - no connection problem"}),Object(se.jsx)(ue.a,{value:16,children:"0x10 - substitute value from controller"}),Object(se.jsx)(ue.a,{value:32,children:"0x20 - substitute initial value"}),Object(se.jsx)(ue.a,{value:64,children:"0x40 - substitute value from device or instance"}),Object(se.jsx)(ue.a,{value:128,children:"0x80 - substitute value from sensor"}),Object(se.jsx)(ue.a,{value:17,children:"0x11 - general problem by instance"}),Object(se.jsx)(ue.a,{value:65,children:"0x41 - general problem by device"}),Object(se.jsx)(ue.a,{value:129,children:"0x81 - general problem by sensor"}),Object(se.jsx)(ue.a,{value:18,children:"0x12 - instance not connected"}),Object(se.jsx)(ue.a,{value:66,children:"0x42 - device not connected"}),Object(se.jsx)(ue.a,{value:130,children:"0x82 - sensor not connected"}),Object(se.jsx)(ue.a,{value:68,children:"0x44 - device reports error"}),Object(se.jsx)(ue.a,{value:132,children:"0x84 - sensor reports error"})]})]}),Object(se.jsx)(ve.a,{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:function(t){return e.expire=t.target.value}})]}):null]})}),this.state.chart&&this.state.chartEnabled?Object(se.jsx)(bt.a,{only:["sm","xs"],children:Object(se.jsx)(me.a,{item:!0,xs:6,style:{minHeight:300},children:this.renderChart()})}):null]})})}),Object(se.jsxs)(m.a,{className:this.props.classes.wrapperButton,children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.onUpdate()},color:"primary",startIcon:Object(se.jsx)(Ot.a,{}),children:this.props.t("Set value")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}}]),s}(l.Component),wt=Object(u.a)((function(e){return{input:{width:"100%"},textInput:{width:"100%"},formControl:{minWidth:150},quality:{width:"calc(100% - 88px)"},expire:{marginLeft:8,width:80},jsonError:{border:"1px solid red"},jsonNoError:{border:"1px solid #00000000"},wrapperButton:{},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:12}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:11}}}}}))(yt),Ct=s(17),St=s(1463),kt=s(145),It=s.n(kt),Dt=s(563),Tt=s.n(Dt),Nt=s(1888),At=s.n(Nt),Et=s(689),Rt=s.n(Et),Ft=s(219),Ht=s.n(Ft),Mt=s(282),Vt=s(1522),Wt=s(548),Jt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n,o,i,r,l;return Object(a.a)(this,s),(l=t.call(this,e)).state={text:JSON.stringify(l.props.obj,null,2),error:!1,changed:!1,readError:l.checkFunction(null===(n=l.props.obj.common)||void 0===n||null===(o=n.alias)||void 0===o?void 0:o.read,!1),writeError:l.checkFunction(null===(i=l.props.obj.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.write,!0),tab:window.localStorage.getItem((l.props.dialogName||"App")+".editTab")||"object",showCopyDialog:!1},l.isMobile=window.innerWidth<850,l.originalObj=JSON.stringify(l.props.obj,null,2),l}return Object(n.a)(s,[{key:"checkFunction",value:function(e,t){if(e){var s,a,n,o,i,r,l,c;try{l=JSON.parse(this.state.text)}catch(m){}try{c=new Function("val",e.includes("return")?e:"return "+e)}catch(m){return this.props.t("Cannot parse code!")}if((null===(s=l)||void 0===s||null===(a=s.common)||void 0===a?void 0:a.type)&&(null===(n=this.props.objects[null===(i=l.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.id])||void 0===n||null===(o=n.common)||void 0===o?void 0:o.type)){var u=t?l.common.type:this.props.objects[l.common.alias.id].common.type,d=t?this.props.objects[l.common.alias.id].common.type:l.common.type;if(u&&d){var h=null;if("boolean"===u?h=!0:"number"===u?h=1:"string"===u&&(h="string"),null!==h)try{var p=c(h);return null!==p&&typeof p!==d?this.props.t("Type of result is not as expected: %s",d):""}catch(m){return this.props.t("Cannot execute function")+": "+m.toString()}}}return""}return""}},{key:"prepareObject",value:function(e){e=e||this.state.text;try{var t,s=JSON.parse(e);return s._id=this.props.obj._id,(null===(t=s.common)||void 0===t?void 0:t.alias)&&(s.common.alias.id||delete s.common.alias.id,(!s.common.alias.read&&void 0!==s.common.alias.read||"val"===s.common.alias.read)&&delete s.common.alias.read,(!s.common.alias.write&&void 0!==s.common.alias.write||"val"===s.common.alias.write)&&delete s.common.alias.write,s.common.alias.id||s.common.alias.read||s.common.alias.write||delete s.common.alias),s}catch(a){return null}}},{key:"onChange",value:function(e,t){var s,a,n,o,i={text:e},r=this.prepareObject(e);r?(i.changed=this.originalObj!==JSON.stringify(r,null,2),this.state.error&&(i.error=!1),i.readError=this.checkFunction(null===(s=r.common)||void 0===s||null===(a=s.alias)||void 0===a?void 0:a.read,!1),i.writeError=this.checkFunction(null===(n=r.common)||void 0===n||null===(o=n.alias)||void 0===o?void 0:o.write,!0)):i.error=!0;this.setState(i,(function(){return t&&t()}))}},{key:"onUpdate",value:function(){var e,t=JSON.parse(this.state.text);t._id=this.props.obj._id,(null===(e=t.common)||void 0===e?void 0:e.alias)&&(t.common.alias.id||delete t.common.alias.id,(!t.common.alias.read&&void 0!==t.common.alias.read||"val"===t.common.alias.read)&&delete t.common.alias.read,(!t.common.alias.write&&void 0!==t.common.alias.write||"val"===t.common.alias.write)&&delete t.common.alias.write,t.common.alias.id||t.common.alias.read||t.common.alias.write||delete t.common.alias),this.props.onClose(t)}},{key:"renderTabs",value:function(){var e=this;return Object(se.jsxs)(I.a,{className:this.props.classes.tabsPadding,value:this.state.tab,onChange:function(t,s){window.localStorage.setItem((e.props.dialogName||"App")+".editTab",s),e.setState({tab:s})},children:[Object(se.jsx)(D.a,{value:"common",label:this.props.t("Common")}),Object(se.jsx)(D.a,{value:"object",label:this.props.t("Object data")}),this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type&&Object(se.jsx)(D.a,{value:"alias",label:this.props.t("Alias")})]})}},{key:"renderSelectDialog",value:function(){var e=this;if(!this.state.selectId&&!this.state.selectRead&&!this.state.selectWrite)return null;var t,s,a,n=JSON.parse(this.state.text);if(this.state.selectId)t=(null===(s=n.common)||void 0===s||null===(a=s.alias)||void 0===a?void 0:a.id)||"";else if(this.state.selectRead){var o,i,r;t=(null===(o=n.common)||void 0===o||null===(i=o.alias)||void 0===i||null===(r=i.id)||void 0===r?void 0:r.read)||""}else if(this.state.selectWrite){var l,c,u;t=(null===(l=n.common)||void 0===l||null===(c=l.alias)||void 0===c||null===(u=c.id)||void 0===u?void 0:u.write)||""}return Object(se.jsx)(Rt.a,{imagePrefix:".",dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,socket:this.props.socket,dialogName:"aliasesEdit",title:"".concat(this.props.t("Select for")," ").concat(this.props.obj._id),selected:t,statesOnly:!0,onOk:function(t){var s=e.state.selectRead,a=e.state.selectWrite,o=e.state.selectId;e.setState({selectId:!1,selectRead:!1,selectWrite:!1},(function(){s?e.setAliasItem(n,"id.read",t):a?e.setAliasItem(n,"id.write",t):o&&e.setAliasItem(n,"id",t)}))},onClose:function(){return e.setState({selectId:!1,selectRead:!1,selectWrite:!1})}},"selectDialog")}},{key:"setAliasItem",value:function(e,t,s,a){e.common=e.common||{},e.common.alias=e.common.alias||{},"id.read"===t?e.common.alias.id&&"object"===typeof e.common.alias.id?e.common.alias.id.read=s:e.common.alias.id={read:s,write:s}:"id.write"===t?e.common.alias.id&&"object"===typeof e.common.alias.id?e.common.alias.id.write=s:e.common.alias.id={read:s,write:s}:e.common.alias[t]=s,this.onChange(JSON.stringify(e,null,2),a)}},{key:"setCommonItem",value:function(e,t,s){e.common[t]=s,this.onChange(JSON.stringify(e,null,2))}},{key:"removeCommonItem",value:function(e,t){delete e.common[t],this.onChange(JSON.stringify(e,null,2))}},{key:"buttonAddKey",value:function(e,t){var s=this.props,a=s.t,n=s.classes;return Object(se.jsx)("div",{className:n.marginBlock,children:Object(se.jsx)(j.a,{className:n.buttonAdd,variant:"contained",color:"secondary",startIcon:Object(se.jsx)(It.a,{}),onClick:t,children:a("add %s",e)})})}},{key:"buttonRemoveKey",value:function(e,t){var s=this.props,a=s.t,n=s.classes;return Object(se.jsx)(Mt.a,{title:a("Remove %s",e),children:Object(se.jsx)("div",{className:n.close,onClick:t})})}},{key:"renderCommonEdit",value:function(){var e=this;try{var t=JSON.parse(this.state.text),s=!1,a=this.props,n=a.classes,o=a.t,i=a.roleArray,r=a.obj,l="state"===r.type,c="channel"===r.type||"device"===r.type||l;return Object(se.jsxs)("div",{className:n.commonTabWrapper,children:[Object(se.jsxs)("div",{className:n.commonWrapper,children:["undefined"!==typeof t.common.name?Object(se.jsx)(ve.a,{disabled:s,label:o("Name"),className:Object(Y.default)(n.marginBlock,n.textField),fullWidth:!0,value:He.a.getObjectNameFromObj(t,F.a.getLanguage()),onChange:function(s){return e.setCommonItem(t,"name",s.target.value)}}):this.buttonAddKey("name",(function(){return e.setCommonItem(t,"name","")})),l?"undefined"!==typeof t.common.type?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsxs)(de.a,{className:n.marginBlock,fullWidth:!0,children:[Object(se.jsx)(ce.a,{children:o("State type")}),Object(se.jsx)(he.a,{disabled:s,value:t.common.type,onChange:function(s){return e.setCommonItem(t,"type",s.target.value)},children:["boolean","json","string","number","multistate","file","object","mixed"].map((function(e){return Object(se.jsx)(ue.a,{value:e,children:o(e)},e)}))})]}),this.buttonRemoveKey("type",(function(){return e.removeCommonItem(t,"type")}))]}):this.buttonAddKey("type",(function(){return e.setCommonItem(t,"type","string")})):null,c?"undefined"!==typeof t.common.role?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsx)(Vt.a,{className:n.marginBlock,fullWidth:!0,disabled:s,value:t.common.role,getOptionSelected:function(e,t){return e.name===t.name},onChange:function(s,a){return e.setCommonItem(t,"role",a)},options:i,renderInput:function(e){return Object(se.jsx)(ve.a,Object(Ct.a)(Object(Ct.a)({},e),{},{label:o("Role")}))}}),this.buttonRemoveKey("role",(function(){return e.removeCommonItem(t,"role")}))]}):this.buttonAddKey("role",(function(){return e.setCommonItem(t,"role","")})):null,"undefined"!==typeof t.common.color?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsx)(ve.a,{disabled:s,className:Object(Y.default)(n.marginBlock,n.color),label:o("Color"),type:"color",value:t.common.color,onChange:function(s){return e.setCommonItem(t,"color",s.target.value)}}),this.buttonRemoveKey("color",(function(){return e.removeCommonItem(t,"color")}))]}):this.buttonAddKey("color",(function(){return e.setCommonItem(t,"color","")}))]}),"undefined"!==typeof t.common.icon?Object(se.jsxs)("div",{className:n.flexDrop,children:[Object(se.jsx)(Wt.a,{disabled:s,maxSize:10240,icon:t.common.icon,removeIconFunc:function(){return e.setCommonItem(t,"icon","")},onChange:function(s){return e.setCommonItem(t,"icon",s)},t:o}),this.buttonRemoveKey("icon",(function(){return e.removeCommonItem(t,"icon")}))]}):Object(se.jsx)("div",{className:n.flexDrop,children:this.buttonAddKey("icon",(function(){return e.setCommonItem(t,"icon","")}))})]})}catch(u){return Object(se.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}},{key:"renderAliasEdit",value:function(){var e=this;try{var t,s,a,n,o,i,r,l,c,u,d,h,p,m,b,j,g,v,x,y,w,C,S,k,I,D,T,N,A,E,R,F,H,M,V,W,J=JSON.parse(this.state.text),L=void 0!==(null===(t=J.common)||void 0===t||null===(s=t.alias)||void 0===s?void 0:s.read);return Object(se.jsxs)(me.a,{container:!0,direction:"column",className:this.props.classes.marginTop,children:[Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:"object"===typeof(null===(a=J.common)||void 0===a||null===(n=a.alias)||void 0===n?void 0:n.id),onChange:function(){var t,s,a,n,o,i,r;"object"===typeof(null===(t=J.common)||void 0===t||null===(s=t.alias)||void 0===s?void 0:s.id)?e.setAliasItem(J,"id",(null===(a=J.common)||void 0===a||null===(n=a.alias)||void 0===n||null===(o=n.id)||void 0===o?void 0:o.read)||""):e.setAliasItem(J,"id.read",(null===(i=J.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.id)||"")}}),label:this.props.t("Different IDs for read and write")})}),"object"!==typeof(null===(o=J.common)||void 0===o||null===(i=o.alias)||void 0===i?void 0:i.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias state"),value:(null===(r=J.common)||void 0===r||null===(l=r.alias)||void 0===l?void 0:l.id)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(c=J.common)||void 0===c||null===(u=c.alias)||void 0===u?void 0:u.id)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!0,selectRead:!1,selectWrite:!1})},children:"..."})]}):null,"object"===typeof(null===(d=J.common)||void 0===d||null===(h=d.alias)||void 0===h?void 0:h.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias read state"),value:(null===(p=J.common)||void 0===p||null===(m=p.alias)||void 0===m||null===(b=m.id)||void 0===b?void 0:b.read)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(j=J.common)||void 0===j||null===(g=j.alias)||void 0===g||null===(v=g.id)||void 0===v?void 0:v.read)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id.read","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id.read",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!1,selectRead:!0,selectWrite:!1})},children:"..."})]}):null,"object"===typeof(null===(x=J.common)||void 0===x||null===(y=x.alias)||void 0===y?void 0:y.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias write state"),value:(null===(w=J.common)||void 0===w||null===(C=w.alias)||void 0===C||null===(S=C.id)||void 0===S?void 0:S.write)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(k=J.common)||void 0===k||null===(I=k.alias)||void 0===I||null===(D=I.id)||void 0===D?void 0:D.write)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id.write","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id.write",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!1,selectRead:!1,selectWrite:!0})},children:"..."})]}):null,Object(se.jsx)(me.a,{item:!0,className:this.props.classes.marginTop,children:Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:void 0!==(null===(T=J.common)||void 0===T||null===(N=T.alias)||void 0===N?void 0:N.read),onChange:function(){L?(delete J.common.alias.read,delete J.common.alias.write):(J.common=J.common||{},J.common.alias=J.common.alias||{},J.common.alias.read="val",J.common.alias.write="val"),e.onChange(JSON.stringify(J,null,2))}}),label:this.props.t("Use convert functions")})}),L?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(ve.a,{label:this.props.t("Read converter"),value:(null===(A=J.common)||void 0===A||null===(E=A.alias)||void 0===E?void 0:E.read)||"",className:this.props.classes.funcEdit,error:!!this.state.readError,InputProps:{endAdornment:(null===(R=J.common)||void 0===R||null===(F=R.alias)||void 0===F?void 0:F.read)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"read","")},children:Object(se.jsx)(O.a,{})})}):null,startAdornment:Object(se.jsx)(St.a,{position:"start",children:Object(se.jsx)(At.a,{className:this.props.classes.funcIcon})})},onChange:function(t){return e.setAliasItem(J,"read",t.target.value)},helperText:this.state.readError||this.props.t("JS function like")+' "val / 5 + 21"',margin:"normal"})}):null,L?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(ve.a,{label:this.props.t("Write converter"),error:!!this.state.writeError,value:(null===(H=J.common)||void 0===H||null===(M=H.alias)||void 0===M?void 0:M.write)||"",helperText:this.state.writeError||this.props.t("JS function like")+' "(val - 21) * 5"',className:this.props.classes.funcEdit,InputProps:{endAdornment:(null===(V=J.common)||void 0===V||null===(W=V.alias)||void 0===W?void 0:W.write)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"write","")},children:Object(se.jsx)(O.a,{})})}):null,startAdornment:Object(se.jsx)(St.a,{position:"start",children:Object(se.jsx)(At.a,{className:this.props.classes.funcIcon})})},onChange:function(t){return e.setAliasItem(J,"write",t.target.value)},margin:"normal"})}):null]})}catch(Y){return Object(se.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}},{key:"onCopy",value:function(e){e.stopPropagation(),e.preventDefault(),Ht()(this.state.text),window.alert(this.props.t("ra_Copied"))}},{key:"onClone",value:function(e,t,s){var a=JSON.parse(JSON.stringify(this.props.objects[e]));delete a.from,delete a.ts,delete a.user,a._id=t,this.props.objects[a._id]=a,this.props.onNewObject(a)}},{key:"renderCopyDialog",value:function(){var e=this;return this.state.showCopyDialog?Object(se.jsxs)(d.a,{open:!0,maxWidth:"md",fullWidth:!0,onClose:function(){return e.setState({showCopyDialog:!1})},children:[Object(se.jsx)(h.a,{children:this.props.t("Enter new ID for this object")}),Object(se.jsx)(p.a,{children:Object(se.jsx)(ve.a,{autoFocus:!0,fullWidth:!0,label:this.props.t("New object ID"),value:this.state.newId,onKeyDown:function(t){13!==t.keyCode||e.props.objects[e.state.newId]||(e.setState({showCopyDialog:""}),e.onClone(e.state.showCopyDialog,e.state.newId))},onChange:function(t){return e.setState({newId:t.target.value})}})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{disabled:!!this.props.objects[this.state.newId],onClick:function(){e.setState({showCopyDialog:""}),e.onClone(e.state.showCopyDialog,e.state.newId)},color:"primary",startIcon:Object(se.jsx)(Tt.a,{}),children:this.props.t("Clone")}),Object(se.jsx)(j.a,{onClick:function(){return e.setState({showCopyDialog:""})},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]}):null}},{key:"render",value:function(){var e=this,t=this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type;return Object(se.jsxs)(d.a,{classes:{paper:this.props.classes.dialog},open:!0,maxWidth:"lg",fullWidth:"number"!==this.state.type&&"boolean"!==this.state.type,fullScreen:!1,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",children:[Object(se.jsxs)(h.a,{id:"edit-value-dialog-title",children:[this.props.t("Edit object:")," ",Object(se.jsx)("span",{className:this.props.classes.id,children:this.props.obj._id})]}),this.renderTabs(),this.renderCopyDialog(),Object(se.jsxs)(p.a,{children:["object"===this.state.tab?Object(se.jsx)("div",{className:Object(Y.default)(this.props.classes.divWithoutTitle,t&&this.props.classes.divWithoutTitleAndTab,this.state.error&&this.props.classes.error),children:Object(se.jsx)(mt.a,{mode:"json",width:"100%",height:"100%",theme:"dark"===this.props.themeName?"clouds_midnight":"chrome",value:this.state.text,onChange:function(t){return e.onChange(t)},name:"UNIQUE_ID_OF_DIV",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0},editorProps:{$blockScrolling:!0}})}):null,"alias"===this.state.tab&&this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type?this.renderAliasEdit():null,"common"===this.state.tab?this.renderCommonEdit():null,this.renderSelectDialog()]}),Object(se.jsxs)(m.a,{className:this.props.classes.wrapperButton,children:[Object(se.jsx)(j.a,{onClick:function(){return e.setState({showCopyDialog:e.props.obj._id,newId:e.props.obj._id})},disabled:this.state.error||this.state.changed,title:this.props.t("Create a copy of this object"),children:Object(se.jsx)(Tt.a,{})}),Object(se.jsx)("div",{style:{flexGrow:1}}),"object"===this.state.tab&&Object(se.jsx)(j.a,{onClick:function(t){return e.onCopy(t)},disabled:this.state.error,title:this.isMobile?this.props.t("Copy into clipboard"):"",startIcon:Object(se.jsx)(We.FaClipboard,{}),children:this.isMobile?null:this.props.t("Copy into clipboard")}),Object(se.jsx)(j.a,{variant:"contained",disabled:this.state.error||!this.state.changed,onClick:function(){return e.onUpdate()},startIcon:Object(se.jsx)(Ot.a,{}),color:"primary",children:this.props.t("Write")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}}]),s}(l.Component),Lt=Object(u.a)((function(e){return{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:368},button:{marginTop:20,marginLeft:e.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"},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}}}}}))(Jt),Yt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).state={role:null,initRole:null,roleInput:null},n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e=this;this.props.socket.getObject(this.props.id).then((function(t){var s;e.object=t;var a=(null===t||void 0===t||null===(s=t.common)||void 0===s?void 0:s.role)||null;e.setState({role:a,initRole:a,roleInput:a})})).catch((function(e){return console.error(e)}))}},{key:"onUpdate",value:function(){var e=this;this.object.common=this.object.common||{},this.object.common.role=this.state.roleInput,this.props.socket.setObject(this.object._id,this.object).then((function(){return e.props.onClose(e.object)}))}},{key:"render",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!0,maxWidth:"sm",fullWidth:!0,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-role-dialog-title","aria-describedby":"edit-role-dialog-description",children:[Object(se.jsx)(h.a,{id:"edit-role-dialog-title",children:this.object?this.props.t("Update role for %s",this.object._id):null}),Object(se.jsx)(p.a,{children:Object(se.jsx)(Vt.a,{freeSolo:!0,options:this.props.roles,style:{width:"100%"},value:this.state.role,onChange:function(t,s){return e.setState({role:s,roleInput:s})},onInputChange:function(t,s){return e.setState({roleInput:s})},renderInput:function(t){return Object(se.jsx)(ve.a,Object(Ct.a)(Object(Ct.a)({},t),{},{label:e.props.t("Role"),variant:"outlined"}))}})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{disabled:this.state.initRole===this.state.roleInput,variant:"contained",onClick:function(){return e.onUpdate()},color:"primary",startIcon:Object(se.jsx)(Ot.a,{}),children:this.props.t("Apply")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},color:"default",startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]},"objectBrowserEditRole")}}]),s}(l.Component),Ut=Object(u.a)((function(e){return{input:{marginBottom:e.spacing(2)},inputText:{width:400,height:300,marginBottom:e.spacing(2)},formControl:{marginBottom:e.spacing(2),minWidth:150},quality:{width:"100%"}}}))(Yt),_t=s(28),Pt=s(1889),Bt=s.n(Pt),zt=s(166),qt=s(349),Xt=["boolean","string","number","array","json","object","mixed"],Gt={boolean:!1,string:"",number:0},Kt={name:"Datapoint",value:"state"},$t={name:"Channel",value:"channel"},Qt={name:"Device",value:"device"},Zt={name:"Folder",value:"folder"},es=function(e){var t,s=e.onClose,a=e.onApply,n=e.open,o=e.selected,i=e.setObject,r=e.objects,c={state:F.a.t("New state"),channel:F.a.t("New channel"),device:F.a.t("New device"),folder:F.a.t("New folder")},u=[],d=null===(t=r[o])||void 0===t?void 0:t.type,h="";r[o]?"channel"===d?(u.push(Kt),h="state"):"device"===d?(h="channel",u.push(Kt),u.push($t)):"state"===d?h="":(u.push(Kt),u.push($t),u.push(Qt),o.startsWith("0_userdata.")||o.startsWith("alias.0.")||"0_userdata"===o||"alias.0"===o?(u.push(Zt),h="folder"):h="state"):(u.push(Zt),h="folder");var p=Object(l.useState)(c[h]),m=Object(_t.a)(p,2),b=m[0],j=m[1],f=Object(l.useState)(h),g=Object(_t.a)(f,2),v=g[0],O=g[1],x=Object(l.useState)("string"),y=Object(_t.a)(x,2),w=y[0],C=y[1],S=Object(l.useState)(!r[T(c.state)]),k=Object(_t.a)(S,2),I=k[0],D=k[1];function T(e){return e.toString().replace(zt.a.FORBIDDEN_CHARS,"_").replace(/\s/g,"_").replace(/\./g,"_")}var N=function(){var e={common:{name:b,desc:F.a.t("Manually created")},type:v};"state"===v?e.common=Object(Ct.a)(Object(Ct.a)({},e.common),{},{role:"state",type:w,read:!0,write:!0,def:Gt[w]}):"folder"!==v?e.common=Object(Ct.a)(Object(Ct.a)({},e.common),{},{role:"",icon:""}):delete e.common.desc,i("".concat(o,".").concat(b.split(" ").join("_")),e).then((function(){return a()}))};return Object(se.jsx)(qt.a,{open:n,fullWidth:!0,maxWidth:"lg",titleButtonApply:"add",applyDisabled:!b||!I||!u.length,onClose:s,onApply:function(){return N()},children:Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[Object(se.jsxs)("div",{style:{margin:10,fontSize:20},children:[Object(se.jsx)(Bt.a,{})," ",F.a.t("Add new object:")," ",Object(se.jsxs)("span",{style:{fontStyle:"italic"},children:[o,".",b]})]}),Object(se.jsx)(ve.a,{label:F.a.t("Parent"),style:{margin:"5px 0"},disabled:!0,value:o}),Object(se.jsxs)(de.a,{style:{marginTop:10,marginBottom:10},children:[Object(se.jsx)(ce.a,{children:F.a.t("Type")}),Object(se.jsx)(he.a,{value:v,onChange:function(e){b===c[v]&&(j(c[e.target.value]),D(r[T(c[e.target.value])])),O(e.target.value)},children:u.map((function(e){return Object(se.jsx)(ue.a,{value:e.value,children:F.a.t(e.name)},e.value)}))})]})," ","state"===v&&Object(se.jsxs)(de.a,{children:[Object(se.jsx)(ce.a,{children:F.a.t("State type")}),Object(se.jsx)(he.a,{value:w,onChange:function(e){return C(e.target.value)},children:Xt.map((function(e){return Object(se.jsx)(ue.a,{value:e,children:e},e)}))})]}),Object(se.jsx)(ve.a,{label:F.a.t("Name"),style:{margin:"5px 0"},autoFocus:!0,value:b,onKeyDown:function(e){13===e.keyCode&&(e.preventDefault(),b&&N())},onChange:function(e){D(!r[T(e.target.value)]),j(e.target.value)}})]})})},ts=s(81),ss=s.n(ts),as=[{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"}]}],ns=function(e,t,s){return e|=t&s,e&=t|65535&~s},os=function(e){var t=e.value,s=e.disabled,a=e.setValue,n=e.t,o=e.differentValues,i=e.applyToChildren,r=e.mask,c=e.setMask;Object(l.useEffect)((function(){if(i){for(var e=0,s=0;s<o.length;s++)e|=t^o[s];c(e)}else c(0)}),[o,i]);var u=t;return Object(se.jsx)("div",{style:{display:"flex",width:"fit-content",margin:20,border:"1px solid",borderLeft:0},children:as.map((function(e){var o=Object.keys(e)[0];return Object(se.jsxs)("div",{style:{width:150,height:150,display:"flex",flexDirection:"column",alignItems:"center",borderLeft:"1px solid"},children:[Object(se.jsx)("div",{style:{height:50,display:"flex",alignItems:"center",fontSize:18,borderBottom:"1px solid silver",width:"100%",justifyContent:"center"},children:n(o)}),Object(se.jsx)("div",{style:{display:"flex",width:"100%"},children:e[o].map((function(e,o){var i=!1;return u-e.valueNum>=0&&(u-=e.valueNum,i=!0),Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",borderRight:0===o?"1px solid":0},children:[Object(se.jsx)("div",{style:{height:50,borderBottom:"1px solid",width:"100%",justifyContent:"center",display:"flex",alignItems:"center",color:"silver"},children:n(e.name)}),Object(se.jsx)("div",{style:{height:50,display:"flex"},children:Object(se.jsx)(G.a,{disabled:s,checked:i,color:r&e.valueNum?"primary":"secondary",indeterminate:!!(r&e.valueNum),style:r&e.valueNum?{opacity:.5}:null,onChange:function(s){r&e.valueNum&&(r&=65535&~e.valueNum,c(r));var n=t;s.target.checked?n|=e.valueNum:n&=65535&~e.valueNum,a(n)}})})]},e.valueNum)}))})]},o)}))})},is=function(e){var t=e.onClose,s=e.onApply,a=e.open,n=e.selected,o=e.extendObject,i=e.objects,r=e.t,c=e.modalEmptyId,u=e.themeType,d=Object(l.useState)(null),h=Object(_t.a)(d,2),p=h[0],m=h[1],b=Object(l.useState)(null),j=Object(_t.a)(b,2),f=j[0],g=j[1],v=Object(l.useState)([]),O=Object(_t.a)(v,2),x=O[0],y=O[1],w=Object(l.useState)([]),C=Object(_t.a)(w,2),S=C[0],k=C[1],I=Object(l.useState)(!1),D=Object(_t.a)(I,2),T=D[0],N=D[1],A=Object(l.useState)(!1),E=Object(_t.a)(A,2),R=E[0],H=E[1],M=Object(l.useState)(0),V=Object(_t.a)(M,2),Y=V[0],_=V[1],P=Object(l.useState)(null),B=Object(_t.a)(P,2),z=B[0],q=B[1],X=Object(l.useState)(null),G=Object(_t.a)(X,2),K=G[0],$=G[1],Q=Object(l.useState)(!1),Z=Object(_t.a)(Q,2),ee=Z[0],te=Z[1],ae=Object(l.useState)(!1),ne=Object(_t.a)(ae,2),oe=ne[0],ie=ne[1],re=Object(l.useState)([]),le=Object(_t.a)(re,2),pe=le[0],me=le[1],be=Object(l.useState)([]),je=Object(_t.a)(be,2),fe=je[0],ge=je[1],ve=Object(l.useState)(0),Oe=Object(_t.a)(ve,2),xe=Oe[0],ye=Oe[1],we=Object(l.useState)(0),Ce=Object(_t.a)(we,2),Se=Ce[0],ke=Ce[1],Ie=Object(l.useState)([]),De=Object(_t.a)(Ie,2),Te=De[0],Ne=De[1],Ae=Object(l.useState)(!1),Ee=Object(_t.a)(Ae,2),Re=Ee[0],Fe=Ee[1],He=Object(l.useState)(!0),Me=Object(_t.a)(He,2),Ve=Me[0],We=Me[1],Je=r("different");return Object(l.useEffect)((function(){for(var e=0,t=[],s=[],a=n||c,o=a+".",r=Object.keys(i).sort(),l=!1,u=[],d=[],h=F.a.getLanguage(),p=!1,b=!1,j=null,f=null,v=null,O=null,x=[],w=0;w<r.length;w++){var C,S,I=r[w],D=i[I];if(D&&(I===a||I.startsWith(o))){if(e++,x.push(I),!D.acl)continue;null===v&&void 0!==D.acl.object&&(v=D.acl.object),null===O&&void 0!==D.acl.state&&(O=D.acl.state),null===j&&void 0!==D.acl.owner&&(j=D.acl.owner),null===f&&void 0!==D.acl.ownerGroup&&(f=D.acl.ownerGroup),ee||j===D.acl.owner||void 0===D.acl.owner||(p=!0),oe||f===D.acl.ownerGroup||void 0===D.acl.ownerGroup||(b=!0),void 0===D.acl.state||O===D.acl.state||t.includes(D.acl.state)||t.push(D.acl.state),void 0===D.acl.object||v===D.acl.object||s.includes(D.acl.object)||s.push(D.acl.object),"state"===D.type&&(l=!0)}if(I.startsWith("system.group.")&&"group"===(null===D||void 0===D?void 0:D.type))u.push({name:zt.a.getObjectNameFromObj(D,h).replace("system.group.",""),value:I,icon:null===(C=D.common)||void 0===C?void 0:C.icon,color:null===(S=D.common)||void 0===S?void 0:S.color});else if(I.startsWith("system.user.")&&"user"===(null===D||void 0===D?void 0:D.type)){var T,A;d.push({name:zt.a.getObjectNameFromObj(D,h).replace("system.user.",""),value:I,icon:null===(T=D.common)||void 0===T?void 0:T.icon,color:null===(A=D.common)||void 0===A?void 0:A.color})}}j=j||i["system.config"].common.defaultNewAcl.owner,f=f||i["system.config"].common.defaultNewAcl.ownerGroup,v=v||i["system.config"].common.defaultNewAcl.object,q(isNaN(v)?i["system.config"].common.defaultNewAcl.object:v),l&&(O=O||i["system.config"].common.defaultNewAcl.state,$(isNaN(O)?i["system.config"].common.defaultNewAcl.state:O));var E=d.find((function(e){return e.value===j})),R=u.find((function(e){return e.value===f}));m(E),g(R),te(p),ie(b),y(d),k(u),l&&H(!0),c&&N(!0),_(e),me(t),ge(s),Ne(x)}),[i,n]),Object(l.useEffect)((function(){T?(oe&&("different"!==f.value&&g({name:Je,value:"different"}),S.find((function(e){return"different"===e.value}))||k((function(e){return[{name:Je,value:"different"}].concat(Object(L.a)(e))}))),ee&&("different"!==p.value&&m({name:Je,value:"different"}),x.find((function(e){return"different"===e.value}))||y((function(e){return[{name:Je,value:"different"}].concat(Object(L.a)(e))})))):(p&&"different"===p.value&&m(i[n].acl.owner),f&&"different"===f.value&&g(i[n].acl.ownerGroup),k((function(e){return e.filter((function(e){return"different"!==e.value}))})),y((function(e){return e.filter((function(e){return"different"!==e.value}))})))}),[T,ee,oe]),Te.length?Object(se.jsx)(qt.a,{open:a,titleButtonApply:"apply",overflowHidden:!0,applyDisabled:Ve,progress:Re,onClose:t,onApply:function(){Fe(!0),setTimeout(Object(J.a)(W.a.mark((function e(){var t,a,r,l,c,u,d;return W.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(T){e.next=9;break}(t=JSON.parse(JSON.stringify(i[n].acl||{}))).object=z,t.owner=p.value,t.ownerGroup=f.value,"state"===i[n].type&&(t.state=K),o(n,{acl:t}),e.next=25;break;case 9:a=65535&~xe,r=65535&~Se,l=0;case 12:if(!(l<Te.length)){e.next=25;break}return c=Te[l],u=i[c],(d=JSON.parse(JSON.stringify(u.acl||{}))).object=ns(u.acl.object,z,a),"different"!==p.value&&(d.owner=p.value),"different"!==f.value&&(d.ownerGroup=f.value),"state"===u.type&&(d.state=ns(u.acl.state,K,r)),e.next=22,o(c,{acl:d});case 22:l++,e.next=12;break;case 25:Fe(!1),s();case 27:case"end":return e.stop()}}),e)}))),200)},children:Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[Object(se.jsx)("div",{style:{margin:10,fontSize:20},children:r("Access control list: %s",n||c)}),Object(se.jsxs)("div",{style:{display:"flex"},children:[Object(se.jsxs)(de.a,{fullWidth:!0,style:{marginRight:10},children:[Object(se.jsx)(ce.a,{children:r("Owner user")}),Object(se.jsx)(he.a,{disabled:Re,value:p.value,renderValue:function(e){return Object(se.jsxs)("span",{children:[p.icon?Object(se.jsx)(ss.a,{src:p.icon,style:{width:16,height:16,marginRight:8}}):null,p.name]})},style:"different"===p.value?{opacity:.5}:{color:p.color||void 0,backgroundColor:zt.a.getInvertedColor(p.color,u)},onChange:function(e){var t=x.find((function(t){return t.value===e.target.value}));m(t),We(!1)},children:x.map((function(e){return Object(se.jsxs)(ue.a,{style:"different"===e.value?{opacity:.5}:{color:e.color||void 0,backgroundColor:zt.a.getInvertedColor(e.color,u)},value:e.value,children:[e.icon?Object(se.jsx)(ss.a,{src:e.icon,style:{width:16,height:16,marginRight:8}}):null,e.name]},e.value)}))})]}),Object(se.jsxs)(de.a,{fullWidth:!0,children:[Object(se.jsx)(ce.a,{children:r("Owner group")}),Object(se.jsx)(he.a,{disabled:Re,value:f.value,renderValue:function(e){return Object(se.jsxs)("span",{children:[f.icon?Object(se.jsx)(ss.a,{src:f.icon,style:{width:16,height:16,marginRight:8}}):null,f.name]})},style:"different"===f.value?{opacity:.5}:{color:f.color||void 0,backgroundColor:zt.a.getInvertedColor(f.color,u)},onChange:function(e){var t=S.find((function(t){return t.value===e.target.value}));g(t),We(!1)},children:S.map((function(e){return Object(se.jsxs)(ue.a,{value:e.value,style:"different"===e.value?{opacity:.5}:{color:e.color||void 0,backgroundColor:zt.a.getInvertedColor(e.color,u)},children:[e.icon?Object(se.jsx)(ss.a,{src:e.icon,style:{width:16,height:16,marginRight:8}}):null,e.name]},e.value)}))})]})]}),Object(se.jsxs)("div",{style:{display:"flex",margin:10,alignItems:"center",fontSize:10,marginLeft:0,color:"silver"},children:[Object(se.jsx)("div",{style:T?null:{color:"green"},children:r("to apply one item")}),Object(se.jsx)(jt.a,{disabled:Re||!!c||1===Y,checked:!!c||T,onChange:function(e){N(e.target.checked),We(!1)},color:"primary"}),Object(se.jsxs)("div",{style:T?{color:"green"}:null,children:[r("to apply with children")," ",c||Y>1?"(".concat(Y," ").concat(r("object(s)"),")"):""]})]}),Re&&Object(se.jsx)(U.a,{}),Object(se.jsxs)("div",{style:{overflowY:"auto"},children:[Object(se.jsxs)("div",{children:[Object(se.jsx)("h2",{children:r("Object rights")}),Object(se.jsx)(os,{mask:Se,disabled:Re,setMask:ke,applyToChildren:T,differentValues:fe,t:r,setValue:function(e){q(e),We(!1)},value:z})]}),R&&Object(se.jsxs)("div",{children:[Object(se.jsx)("h2",{children:r("States rights")}),Object(se.jsx)(os,{mask:xe,disabled:Re,setMask:ye,applyToChildren:T,differentValues:T?pe:[],t:r,setValue:function(e){$(e),We(!1)},value:K})]})]})]})}):Object(se.jsx)(U.a,{})},rs=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).translate=function(e,t,s){return void 0!==t?n.props.t(e,t,s):(n.wordCache[e]||(n.wordCache[e]=n.props.t(e)),n.wordCache[e])},n.dialogName="AdminObjects",n.filters=window.localStorage.getItem("".concat(n.dialogName||"App",".filters"))||"{}";try{n.filters=JSON.parse(n.filters)}catch(i){n.filters={}}var o=window.localStorage.getItem("".concat(n.dialogName||"App",".selected"))||"";return n.state={selected:void 0===n.props.selected?o:"",name:"",toast:"",deleteObjectShow:null},n.t=n.translate,n.wordCache={},n}return Object(n.a)(s,[{key:"onDelete",value:function(e){var t=this,s=this.state.deleteObjectShow.id;e?(this.props.socket.delObjects(s,!0).then((function(){return t.setState({toast:t.t("All deleted")})})).catch((function(e){return window.alert("Cannot delete object: "+e)})),this.setState({deleteObjectShow:null})):(this.props.socket.delObject(s,!1).catch((function(e){return window.alert("Cannot delete object: "+e)})),this.setState({deleteObjectShow:null}))}},{key:"renderToast",value:function(){var e=this;return Object(se.jsx)(g.a,{anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!this.state.toast,autoHideDuration:3e3,onClose:function(){return e.setState({toast:""})},message:this.state.toast,action:Object(se.jsx)(c.a.Fragment,{children:Object(se.jsx)(f.a,{size:"small","aria-label":"close",color:"inherit",onClick:function(){return e.setState({toast:""})},children:Object(se.jsx)(O.a,{fontSize:"small"})})})})}},{key:"renderDeleteDialog",value:function(){var e=this;return this.state.deleteObjectShow?Object(se.jsxs)(d.a,{maxWidth:"md",open:!0,onClose:function(){return e.setState({deleteObjectShow:null})},"aria-labelledby":"delete-object-dialog-title","aria-describedby":"delete-object-dialog-description",children:[Object(se.jsxs)(h.a,{id:"delete-object-dialog-title",children:[this.state.deleteObjectShow.hasChildren?this.t("Delete object(s)"):this.t("Delete object"),": ",Object(se.jsx)("span",{className:this.props.classes.id,children:this.state.deleteObjectShow.id})]}),Object(se.jsx)(p.a,{children:Object(se.jsx)(b.a,{children:this.t("Are you sure?")})}),Object(se.jsxs)(m.a,{children:[this.state.deleteObjectShow.hasChildren?Object(se.jsx)(j.a,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:function(){return e.onDelete(!0)},startIcon:Object(se.jsx)(y.a,{className:this.props.classes.buttonAll}),children:this.t("Delete with children")}):null,this.state.deleteObjectShow.exists?Object(se.jsx)(j.a,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:function(){return e.onDelete(!1)},color:"primary",startIcon:Object(se.jsx)(y.a,{}),autoFocus:!0,children:this.t("Delete one item")}):null,Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({deleteObjectShow:null})},startIcon:Object(se.jsx)(O.a,{}),children:this.t("ra_Cancel")})]})]},"delete"):null}},{key:"render",value:function(){var e=this;return[Object(se.jsx)(w.a,{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:ht,objectBrowserValue:wt,objectBrowserEditObject:Lt,objectBrowserEditRole:Ut,router:N.a,enableStateValueEdit:!0,onObjectDelete:function(t,s,a){return e.setState({deleteObjectShow:{id:t,hasChildren:s,exists:a}})},onFilterChanged:function(t){e.filters=t,window.localStorage.setItem("".concat(e.dialogName||"App",".filters"),JSON.stringify(t))},onSelect:function(t){return window.localStorage.setItem("".concat(e.dialogName||"App",".selected"),t[0]||"")},objectEditBoolean:!0,objectAddBoolean:!0,objectStatesView:!0,objectImportExport:!0,objectEditOfAccessControl:!0,modalNewObject:function(e){return Object(se.jsx)(es,{objects:e.objects,open:e.state.modalNewObj,setObject:function(t,s){return e.setObject(t,s)},selected:e.state.selected[0]||e.state.selectedNonObject,onClose:function(){return e.setState({modalNewObj:!1})},onApply:function(){return e.setState({modalNewObj:!1})}})},modalEditOfAccessControl:function(t,s){return Object(se.jsx)(is,{themeType:e.props.themeType,open:t.state.modalEditOfAccess,extendObject:function(e,a){t.extendObject(e,a),s.aclTooltip=null},selected:t.state.selected[0],modalEmptyId:t.state.modalEmptyId,objects:t.objects,t:e.t,onClose:function(){return t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})},onApply:function(){return t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})}})}},"browser"),this.renderDeleteDialog()]}}]),s}(l.Component),ls=Object(r.a)()(Object(u.a)((function(e){return{buttonIcon:{marginRight:4},buttonAll:{color:"#FF0000"},id:{fontStyle:"italic"},buttonText:{whiteSpace:"nowrap"}}}))(rs));t.default=ls}}]);
2
- //# sourceMappingURL=15.06f26e48.chunk.js.map
1
+ (this["webpackJsonpsrc-rx"]=this["webpackJsonpsrc-rx"]||[]).push([[15],{1666:function(e,t,s){"use strict";var a=s(17),n=s(12),o=s(13),i=s(14),r=s(15),l=s(0),c=s(8),u=s(526),d=s(9),h=s.n(d),p=s(4),m=s.n(p),b=s(691),j=s(651),f=s(16),g=s(542),v=s(3),O=function(e){Object(i.a)(s,e);var t=Object(r.a)(s);function s(e){var a;Object(n.a)(this,s),a=t.call(this,e);var o=window.localStorage.getItem((a.props.dialogName||"App")+"."+a.props.adapterName)||Object.keys(a.props.schema.items)[0];return Object.keys(a.props.schema.items).includes(o)||(o=Object.keys(a.props.schema.items)[0]),a.state={tab:o},a}return Object(o.a)(s,[{key:"render",value:function(){var e=this,t=this.props.schema.items;return Object(v.jsxs)("div",{className:this.props.classes.tabs,children:[Object(v.jsx)(b.a,{value:this.state.tab,onChange:function(t,s){window.localStorage.setItem((e.props.dialogName||"App")+"."+e.props.adapterName,s),e.setState({tab:s})},children:Object.keys(t).map((function(s){var a=e.execute(t[s].disabled,!1);return Object(v.jsx)(j.a,{wrapped:!0,disabled:a,value:s,label:e.getText(t[s].label)},s)}))}),Object(v.jsx)(g.a,{isParentTab:!0,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,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:t[this.state.tab]},this.state.tab)]})}}]),s}(f.a);O.propTypes={socket:m.a.object.isRequired,themeType:m.a.string,themeName:m.a.string,style:m.a.object,className:m.a.string,data:m.a.object.isRequired,originalData:m.a.object,schema:m.a.object,onError:m.a.func,onChange:m.a.func,customs:m.a.object,adapterName:m.a.string,instance:m.a.number,commandRunning:m.a.bool,onCommandRunning:m.a.func,dateFormat:m.a.string,isFloatComma:m.a.bool,multiEdit:m.a.bool,customObj:m.a.object,instanceObj:m.a.object,custom:m.a.bool,registerOnForceUpdate:m.a.func.isRequired,forceUpdate:m.a.func.isRequired,systemConfig:m.a.object,alive:m.a.bool,common:m.a.object};var x=Object(c.a)((function(e){return{tabs:{height:"100%",width:"100%"},panel:{height:"calc(100% - 48px)",width:"100%",display:"block"}}}))(O);h.a.extendTranslations=h.a.extendTranslations||function(e,t){try{t?(h.a.translations[t]||console.warn("Used unknown language: ".concat(t)),h.a.translations[t]=h.a.translations[t]||{},Object.keys(e).forEach((function(s){h.a.translations[t][s]?h.a.translations[t][s]!==e[s]&&console.warn('Translation for word "'.concat(s,'" in "').concat(t,'" was ignored: existing = "').concat(h.a.translations[t][s],'", new = ').concat(e[s])):h.a.translations[t][s]=e[s]}))):Object.keys(e).forEach((function(t){Object.keys(e[t]).forEach((function(s){h.a.translations[s]||console.warn("Used unknown language: ".concat(s)),h.a.translations[s][t]?h.a.translations[s][t]!==e[t][s]&&console.warn('Translation for word "'.concat(t,'" in "').concat(s,'" was ignored: existing = "').concat(h.a.translations[s][t],'", new = ').concat(e[t][s])):h.a.translations[s][t]=e[t][s]}))}))}catch(s){console.error("Cannot apply translations: ".concat(s))}};var y=function(e){Object(i.a)(s,e);var t=Object(r.a)(s);function s(e){var a;return Object(n.a)(this,s),(a=t.call(this,e)).onCommandRunning=function(e){return a.setState({commandRunning:e})},a.onAlive=function(e,t){((null===t||void 0===t?void 0:t.val)||!1)!==a.state.alive&&a.setState({alive:(null===t||void 0===t?void 0:t.val)||!1})},a.onChange=function(e,t,s){if(a.props.onValueChange)a.props.onValueChange(e,t),s&&s();else{var n={data:e},o={};Object.keys(e).forEach((function(t){return!t.startsWith("_")&&(o[t]=e[t])})),n.changed=JSON.stringify(o)!==a.state.originalData,a.setState({state:n},(function(){a.props.onChange(o,n.changed),s&&s()}))}},a.onError=function(e,t){var s=JSON.parse(JSON.stringify(a.state.errors));t?s[e]=t:delete s[e],JSON.stringify(s)!==JSON.parse(JSON.stringify(a.state.errors))&&a.setState({errors:s},(function(){return a.props.onError(!!Object.keys(a.state.errors).length)}))},a.forceUpdate=function(e,t){Array.isArray(e)?e.forEach((function(e){return a.forceUpdateHandlers[e]&&a.forceUpdateHandlers[e](t)})):a.forceUpdateHandlers[e]&&a.forceUpdateHandlers[e](t)},a.registerOnForceUpdate=function(e,t){t?a.forceUpdateHandlers[e]=t:a.forceUpdateHandlers[e]&&delete a.forceUpdateHandlers[e]},a.state={originalData:JSON.stringify(a.props.data),changed:!1,errors:{},updateData:a.props.updateData,systemConfig:null,alive:!1,commandRunning:!1},a.forceUpdateHandlers={},a.schema=JSON.parse(JSON.stringify(a.props.schema)),a.buildDependencies(a.schema),a.readData(),a}return Object(o.a)(s,[{key:"readSettings",value:function(){var e=this;return(this.props.custom||this.props.common)&&this.props.data?Promise.resolve():this.props.socket.getObject("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance)).then((function(t){return e.setState({common:t.common,data:e.props.data||t.native})}))}},{key:"readData",value:function(){var e=this;this.readSettings().then((function(){return e.props.socket.getCompactSystemConfig()})).then((function(t){return e.props.socket.getState("system.adapter.".concat(e.props.adapterName,".").concat(e.props.instance,".alive")).then((function(s){e.props.custom?e.setState({systemConfig:t.common,alive:!(!s||!s.val)}):e.setState({systemConfig:t.common,alive:!(!s||!s.val)},(function(){return e.props.socket.subscribeState("system.adapter.".concat(e.props.adapterName,".").concat(e.props.instance,".alive"),e.onAlive)}))}))}))}},{key:"flatten",value:function(e,t){var s=this;return t=t||{},e.items&&Object.keys(e.items).forEach((function(a){t[a]=e.items[a],s.flatten(e.items[a],t)})),t}},{key:"buildDependencies",value:function(e){var t=this.flatten(e);Object.keys(t).forEach((function(e){var s,n,o,i,r,l,c,u,d,h;(null===(s=t[e].confirm)||void 0===s?void 0:s.alsoDependsOn)&&(null===(l=t[e].confirm)||void 0===l||l.alsoDependsOn.forEach((function(s){if(t[s]){t[s].confirmDependsOn=t[s].confirmDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});n.confirm&&(n.confirm.cancel="Undo"),t[s].confirmDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(n=t[e].onChange)||void 0===n?void 0:n.alsoDependsOn)&&(null===(c=t[e].onChange)||void 0===c||c.alsoDependsOn.forEach((function(s){if(t[s]){t[s].onChangeDependsOn=t[s].onChangeDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].onChangeDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(o=t[e].hidden)||void 0===o?void 0:o.alsoDependsOn)&&(null===(u=t[e].hidden)||void 0===u||u.alsoDependsOn.forEach((function(s){if(t[s]){t[s].hiddenDependsOn=t[s].hiddenDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].hiddenDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(i=t[e].label)||void 0===i?void 0:i.alsoDependsOn)&&(null===(d=t[e].label)||void 0===d||d.alsoDependsOn.forEach((function(s){if(t[s]){t[s].labelDependsOn=t[s].labelDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].labelDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));(null===(r=t[e].help)||void 0===r?void 0:r.alsoDependsOn)&&(null===(h=t[e].help)||void 0===h||h.alsoDependsOn.forEach((function(s){if(t[s]){t[s].helpDependsOn=t[s].helpDependsOn||[];var n=Object(a.a)(Object(a.a)({},t[e]),{},{attr:e});t[s].helpDependsOn.push(n)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})))}))}},{key:"renderItem",value:function(e){var t=this;return"tabs"===e.type?Object(v.jsx)(x,{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:e,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,forceUpdate:this.forceUpdate,registerOnForceUpdate:this.registerOnForceUpdate,onChange:this.onChange,onError:function(e,s){return t.onError(e,s)}}):"panel"!==e.type&&e.type?void 0:Object(v.jsx)(g.a,{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:e,systemConfig:this.state.systemConfig,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,forceUpdate:this.forceUpdate,registerOnForceUpdate:this.registerOnForceUpdate,custom:this.props.custom,customObj:this.props.customObj,instanceObj:this.props.instanceObj,onChange:this.onChange,onError:function(e,s){return t.onError(e,s)}})}},{key:"render",value:function(){return this.state.systemConfig?Object(v.jsx)("div",{className:this.props.classes.root,children:this.renderItem(this.schema)}):Object(v.jsx)(u.a,{})}}],[{key:"getDerivedStateFromProps",value:function(e,t){return JSON.stringify(e.updateData)!==JSON.stringify(t.updateData)?{updateData:e.updateData,originalData:JSON.stringify(e.data)}:null}},{key:"loadI18n",value:function(e,t,s){if(!0===t||t&&"string"===typeof t){var a=h.a.getLanguage(),n="string"===typeof t?t:"i18n";return e.fileExists(s+".admin","".concat(n,"/").concat(a,".json")).then((function(t){return t?"".concat(n,"/").concat(a,".json"):e.fileExists(s+".admin","".concat(n,"/").concat(a,"/translations.json")).then((function(e){return e?"".concat(n,"/").concat(a,"/translations.json"):""}))})).then((function(t){return t?e.readFile(s+".admin",t).then((function(e){void 0!==e.file&&(e=e.file);try{e=JSON.parse(e),h.a.extendTranslations(e,a)}catch(n){console.error('Cannot parse language file "'.concat(s,".admin/").concat(t,": ").concat(n))}})):(console.warn("Cannot find i18n for ".concat(s," / ").concat(t)),Promise.resolve())}))}return t&&"object"===typeof t?(h.a.extendTranslations(t),Promise.resolve()):Promise.resolve()}}]),s}(l.Component);t.a=Object(c.a)((function(e){return{root:{width:"100%",height:"100%"}}}))(y)},2041:function(e,t,s){"use strict";s.r(t);var a=s(12),n=s(13),o=s(14),i=s(15),r=s(326),l=s(0),c=s.n(l),u=s(8),d=s(211),h=s(232),p=s(213),m=s(212),b=s(499),j=s(96),f=s(185),g=s(647),v=s(47),O=s.n(v),x=s(189),y=s.n(x),w=s(1674),C=s(4),S=s.n(C),k=s(648),I=s(691),D=s(651),T=s(82),N=s.n(T),A=s(139),E=s.n(A),R=s(9),F=s.n(R),H=s(1574),M=s.n(H),V=s(29),W=s.n(V),J=s(50),L=s(85),Y=s(6),U=s(526),_=s(1487),P=s(1488),B=s(1489),z=s(75),q=s(159),X=s(623),G=s(692),K=s(244),$=s.n(K),Q=s(569),Z=s.n(Q),ee=s(1666),te=s(86),se=s(3),ae=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).onSave=function(e){if(n.props.objectIDs.length>10&&!n.state.confirmed)return n.cb=e,n.setState({showConfirmation:!0});n.saveOneState(Object(L.a)(n.props.objectIDs),(function(){n.changedItems=[],n.newValues={},n.commonConfig=n.getCommonConfig(),n.setState({confirmed:!1,hasChanges:!1,newValues:{}},(function(){n.props.reportChangedIds(n.changedIds),n.props.onChange(!1,!0),e&&setTimeout((function(){return e()}),100)}))}))};var o=window.localStorage.getItem("App.customsExpanded")||"[]";try{o=JSON.parse(o)}catch(i){o=[]}return n.changedIds=[],n.state={loaded:!1,hasChanges:!1,expanded:o,newValues:{},progress:null,maxOids:null,confirmed:!1,showConfirmation:!1},n.scrollDone=!1,n.lastExpanded=window.localStorage.getItem("App.customsLastExpanded")||"",n.scrollDivRef=Object(l.createRef)(),n.changedItems=[],n.jsonConfigs={},n.controls={},n.refTemplate={},n.props.customsInstances.map((function(e){return n.refTemplate[e]=Object(l.createRef)()})),n.customObj=n.props.objectIDs.length>1?{custom:{},native:{}}:JSON.parse(JSON.stringify(n.props.objects[n.props.objectIDs[0]]||null)),n.customObj&&(n.loadAllPromises=n.loadAllCustoms().then((function(){n.commonConfig=n.getCommonConfig(),n.setState({loaded:!0,newValues:{}})}))),n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){this.props.registerSaveFunc&&this.props.registerSaveFunc(this.onSave)}},{key:"componentWillUnmount",value:function(){this.props.registerSaveFunc&&this.props.registerSaveFunc(null)}},{key:"loadAllCustoms",value:function(){var e=this,t=[];return this.props.customsInstances.forEach((function(s){var a=s.replace(/\.\d+$/,"").replace("system.adapter.","");void 0===e.jsonConfigs[a]&&(e.jsonConfigs[a]=!1,t.push(e.getCustomTemplate(a)))})),Promise.all(t).then((function(){e.props.customsInstances.forEach((function(t){var s,a,n=t.replace(/\.\d+$/,"").replace("system.adapter.","");e.jsonConfigs[n]&&(e.jsonConfigs[n].instanceObjs=e.jsonConfigs[n].instanceObjs||{},e.jsonConfigs[n].instanceObjs[t]={common:JSON.parse(JSON.stringify(null===(s=e.props.objects["system.adapter."+t])||void 0===s?void 0:s.common)),native:JSON.parse(JSON.stringify(null===(a=e.props.objects["system.adapter."+t])||void 0===a?void 0:a.native))})}))}))}},{key:"showError",value:function(e){this.setState({error:e})}},{key:"getCustomTemplate",value:function(e){var t,s=this,a=this.props.objects["system.adapter."+e]?JSON.parse(JSON.stringify(this.props.objects["system.adapter."+e])):null;return a?(te.a.fixAdminUI(a),"json"===(null===(t=a.common)||void 0===t?void 0:t.adminUI.custom)?this.props.socket.readFile(e+".admin","jsonCustom.json").then((function(t){void 0!==t.file&&(t=t.file);try{t=JSON.parse(t),s.jsonConfigs[e]=s.jsonConfigs[e]||{},s.jsonConfigs[e].json=t}catch(a){console.error("Cannot parse jsonConfig of ".concat(e,": ").concat(a)),window.alert("Cannot parse jsonConfig of ".concat(e,": ").concat(a))}return ee.a.loadI18n(s.props.socket,t.i18n,e)})).catch((function(t){console.error("Cannot load jsonConfig of ".concat(e,": ").concat(t)),window.alert("Cannot load jsonConfig of ".concat(e,": ").concat(t))})):(console.error("Adapter ".concat(e," is not yet supported by this version of admin")),window.alert("Adapter ".concat(e," is not yet supported by this version of admin")),Promise.resolve(null))):(console.error('Cannot find adapter "'.concat(a,'"')),Promise.resolve(null))}},{key:"_executeCustom",value:function(e,t,s,a,n,o,i){var r=this;if(!i.includes(o)){i.push(o);var l=[];if(e&&"object"===typeof e&&("string"===typeof(l=e.alsoDependsOn||[])&&(l=[l]),e=e.func),l.forEach((function(e){if(!n[e])return console.error('[JsonConfigComponent] attribute "'.concat(e,'" does not exist!'));if(!n[e].defaultFunc)return console.error('[JsonConfigComponent] attribute "'.concat(e,'" is not required to be includes in "alsoDependsOn" while has static value!'));var o=r._executeCustom(n[e].defaultFunc,t,s,a,n,e,i);void 0!==o&&(t[e]=o)})),e)try{var c=new Function("data","originalData","_system","instanceObj","customObj","_socket",e.includes("return")?e:"return "+e)(t||this.props.data,this.props.originalData,this.props.systemConfig,a,s,this.props.socket);t[o]=c}catch(u){console.error("Cannot execute ".concat(e,": ").concat(u)),t[o]=n[o]&&void 0!==n[o].default?n[o].default:null}else t[o]=void 0===n[o].default?null:n[o].default}}},{key:"getDefaultValues",value:function(e,t){var a=this,n={enabled:!1},o=e.split(".")[0];if(this.jsonConfigs[o]&&!this.jsonConfigs[o].disabled){var i=s.flattenItems(this.jsonConfigs[o].json.items);if(i){var r=[],l=Object.keys(i).filter((function(e){return i[e]}));l.forEach((function(e){i[e].defaultFunc||void 0===i[e].default||(n[e]=i[e].default)})),l.forEach(function(){var s=Object(J.a)(W.a.mark((function s(l){return W.a.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:i[l].defaultFunc&&a._executeCustom(i[l].defaultFunc,n,t,a.jsonConfigs[o].instanceObjs[e],i,l,r);case 1:case"end":return s.stop()}}),s)})));return function(e){return s.apply(this,arguments)}}())}}return n}},{key:"getCommonConfig",value:function(){var e=this,t=this.props.objectIDs||[],s=this.props.objects,a={};return this.props.customsInstances.forEach((function(n){var o=n.split(".")[0];e.jsonConfigs[o]&&e.jsonConfigs[o].disabled||(a[n]={},t.forEach((function(t){var o,i=s[t],r=(null===i||void 0===i||null===(o=i.common)||void 0===o?void 0:o.custom)&&i.common.custom[n]||null;if(r)Object.keys(r).forEach((function(e){void 0===a[n][e]?a[n][e]=r[e]:a[n][e]!==r[e]&&(Array.isArray(a[n][e])||(a[n][e]=[a[n][e]]),!a[n][e].includes(r[e])&&a[n][e].push(r[e]))}));else{var l=e.getDefaultValues(n,i);l.enabled=!1,Object.keys(l).forEach((function(e){void 0===a[n][e]?a[n][e]=l[e]:a[n][e]!==l[e]&&(Array.isArray(a[n][e])||(a[n][e]=[a[n][e]]),!a[n][e].includes(l[e])&&a[n][e].push(l[e]))}))}})),Object.keys(a[n]).forEach((function(e){Array.isArray(a[n][e])&&a[n][e].sort()})))})),a}},{key:"isChanged",value:function(e){return e=e||this.state.newValues,Object.keys(e).find((function(t){return null===e[t]||e[t]&&Object.keys(e[t]).find((function(e){return!e.startsWith("_")}))}))}},{key:"combineNewAndOld",value:function(e,t){var s=Object.assign({},this.commonConfig[e]||{},this.state.newValues[e]||{});return t&&Object.keys(s).forEach((function(e){e.startsWith("_")&&delete s[e]})),null===this.state.newValues[e]&&(s.enabled=!1),s}},{key:"renderOneCustom",value:function(e,t,s,a){var n,o=this,i=e.split(".")[0],r="".concat(".","/adapter/").concat(i,"/").concat(this.props.objects["system.adapter."+i].common.icon),l=void 0===this.state.newValues[e]||this.state.newValues[e]&&void 0===this.state.newValues[e].enabled?null!==this.state.newValues[e]&&this.commonConfig[e].enabled:!(!this.state.newValues[e]||!this.state.newValues[e].enabled),c=Array.isArray(l)&&(!this.state.newValues[e]||void 0===this.state.newValues[e].enabled),u=this.jsonConfigs[i]&&(null===(n=this.jsonConfigs[i].json)||void 0===n?void 0:n.disabled),d=this.combineNewAndOld(e);return u&&!0===this.jsonConfigs[i].json.hidden||"string"===typeof this.jsonConfigs[i].json.hidden&&this._executeCustom(this.jsonConfigs[i].json.hidden,d,s,t,this.jsonConfigs[i].json.items,"enabled",[])?null:Object(se.jsxs)(_.a,{id:"Accordion_"+e,className:a%2?this.props.classes.accordionOdd:this.props.classes.accordionEven,expanded:this.state.expanded.includes(e),ref:this.refTemplate[e],onChange:function(){var t=Object(L.a)(o.state.expanded),s=t.indexOf(e);-1===s?t.push(e):t.splice(s,1),window.localStorage.setItem("App.customsExpanded",JSON.stringify(t)),-1===s&&window.localStorage.setItem("App.customsLastExpanded",e),o.setState({expanded:t})},children:[Object(se.jsxs)(P.a,{expandIcon:Object(se.jsx)($.a,{}),"data-id":e,className:a%2?l?this.props.classes.accordionHeaderEnabledOdd:this.props.classes.accordionHeaderOdd:l?this.props.classes.accordionHeaderEnabledEven:this.props.classes.accordionHeaderEven,children:[Object(se.jsx)("img",{src:r,className:this.props.classes.headingIcon,alt:""}),Object(se.jsx)(z.a,{className:this.props.classes.heading,children:this.props.t("Settings %s",e)}),Object(se.jsx)("div",{className:Object(Y.default)(this.props.classes.titleEnabled,"titleEnabled",l?this.props.classes.enabledVisible:this.props.classes.enabledInvisible),children:this.props.t("Enabled")})]}),Object(se.jsxs)(B.a,{children:[Object(se.jsx)("div",{className:this.props.classes.enabledControl,children:Object(se.jsx)(X.a,{className:this.props.classes.formControl,control:Object(se.jsx)(G.a,{indeterminate:c,checked:!!l,disabled:u,onChange:function(t){var s=JSON.parse(JSON.stringify(o.state.newValues));s[e]=s[e]||{},c||t.target.checked?s[e].enabled=!0:l?s[e]=null:delete s[e],o.setState({newValues:s,hasChanges:o.isChanged(s)},(function(){return o.props.onChange&&o.props.onChange(o.state.hasChanges)}))}}),label:this.props.t("Enabled")})}),Object(se.jsxs)("div",{className:this.props.classes.customControls,children:[u||!l&&!c?null:Object(se.jsx)(ee.a,{instanceObj:t,customObj:s,custom:!0,className:"",adapterName:i,instance:parseInt(e.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:d,onError:function(e){return o.setState({error:e},(function(){return o.props.onError&&o.props.onError(e)}))},onValueChange:function(t,s){console.log(t+" => "+s);var a=JSON.parse(JSON.stringify(o.state.newValues));a[e]=a[e]||{},o.commonConfig[e][t]===s?(delete a[e][t],Object.keys(a[e]).length||delete a[e]):a[e][t]=s,o.setState({newValues:a,hasChanges:o.isChanged(a)},(function(){return o.props.onChange&&o.props.onChange(o.state.hasChanges)}))}}),u&&this.jsonConfigs[i].json.help?"object"===typeof this.jsonConfigs[i].json.help?this.jsonConfigs[i].json.help[this.props.lang]||this.jsonConfigs[i].json.help.en:this.props.t(this.jsonConfigs[i].json.help):null]})]})]},e)}},{key:"isAllOk",value:function(){return!0}},{key:"renderErrorMessage",value:function(){var e=this;return!!this.state.error&&Object(se.jsx)(Z.a,{title:this.props.t("Error"),text:this.state.error,onClose:function(){return e.setState({error:""})}})}},{key:"getObject",value:function(e,t,s){return e[s]?Promise.resolve(e[s]):this.props.socket.getObject(s).then((function(a){return t[s]=JSON.parse(JSON.stringify(a)),e[s]=a,a}))}},{key:"saveOneState",value:function(e,t,s,a){var n=this;if(s=s||{},a=a||{},e&&e.length){var o=this.state.maxOids||e.length;null===this.state.maxOids&&this.setState({maxOids:e.length},(function(){return n.props.onProgress(!0)})),this.setState({progress:Math.round((o-e.length)/o*50)});var i=e.shift();this.getObject(s,a,i).then((function(o){if(!o)return window.alert("Invalid object ".concat(i));o.common&&o.common.custom&&Object.keys(o.common.custom).forEach((function(e){o.common.custom[e]&&o.common.custom[e].enabled||(o.common.custom[e]=null)}));for(var r=Object.keys(n.state.newValues),l=function(e){var t=r[e],s=n.combineNewAndOld(t,!0);if(!1===s.enabled)o.common&&o.common.custom&&o.common.custom[t]&&(o.common.custom[t]=null);else if(s.enabled){if(o.common=o.common||{},Array.isArray(s.enabled)&&(!o.common.custom||!o.common.custom[t]||!o.common.custom[t].enabled))return o.common.custom&&o.common.custom[t]&&(o.common.custom[t]=null),"continue";if(o.common.custom=o.common.custom||{},!o.common.custom[t]||!o.common.custom[t].enabled){var a=n.getDefaultValues(t,o);o.common.custom[t]=JSON.parse(JSON.stringify(a||{}))}o.common.custom[t].enabled=!0,Object.keys(s).forEach((function(e){Array.isArray(s[e])||(o.common.custom[t][e]=s[e])}))}},c=0;c<r.length;c++)l(c);setTimeout((function(){return n.saveOneState(e,t,s,a)}),0)}))}else{var r=Object.keys(s);if(r.length){this.setState({progress:Math.round((this.state.maxOids-r.length)/this.state.maxOids*50)+50});var l=r.shift();return JSON.stringify(s[l].common)!==JSON.stringify(a[l].common)?(!this.changedIds.includes(l)&&this.changedIds.push(l),this.props.socket.setObject(l,s[l]).then((function(){return delete s[l],delete a[l],n.props.socket.getObject(l).then((function(o){n.props.objects[l]=o,setTimeout((function(){return n.saveOneState(e,t,s,a)}),0)}))}))):(delete s[l],delete a[l],setTimeout((function(){return n.saveOneState(e,t,s,a)}),0))}this.setState({maxOids:null},(function(){return n.props.onProgress(!1)})),t&&t()}}},{key:"renderConfirmationDialog",value:function(){var e=this;return!!this.state.showConfirmation&&Object(se.jsx)(E.a,{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:function(t){t?e.setState({showConfirmation:!1,confirmed:!0},(function(){var t=e.cb;e.cb=null,e.onSave(t)})):(e.cb=null,e.setState({showConfirmation:!1}))}})}},{key:"render",value:function(){var e=this;if(null===this.customObj)return Object(se.jsx)("div",{style:{color:"#F55",fontSize:32},children:this.props.t("Object does not exist!")});if(!this.state.loaded)return Object(se.jsx)(U.a,{});var t=0;return Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.state.maxOids>1&&Object(se.jsx)(U.a,{color:"secondary",variant:"determinate",value:this.state.progress}),Object(se.jsx)("div",{className:this.props.classes.scrollDiv,ref:this.scrollDivRef,children:null===this.state.maxOids&&Object.keys(this.jsonConfigs).map((function(s){return e.jsonConfigs[s]?Object.keys(e.jsonConfigs[s].instanceObjs).map((function(a){return e.renderOneCustom(a,e.jsonConfigs[s].instanceObjs[a],e.customObj,t++)})):null}))}),this.renderErrorMessage(),this.renderConfirmationDialog()]})}}],[{key:"flattenItems",value:function(e,t){return t=t||{},e&&Object.keys(e).forEach((function(a){e[a].items?s.flattenItems(e[a].items,t):t[a]=e[a]})),t}}]),s}(l.Component);ae.AsyncFunction=Object.getPrototypeOf(Object(J.a)(W.a.mark((function e(){return W.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})))).constructor;var ne=Object(r.a)()(Object(u.a)((function(e){return{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"},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"}}}))(ae)),oe=s(55),ie=s(99),re=s(1511),le=s(1526),ce=s(506),ue=s(339),de=s(505),he=s(511),pe=s(773),me=s(88),be=s(1492),je=s(1493),fe=s(1491),ge=s(1490),ve=s(283),Oe=s(1494),xe=s(1501),ye=s(571),we=s(1844),Ce=s(1845),Se=s(381),ke=s(1847),Ie=s(1852),De=s(1851),Te=s(1850),Ne=s(1853),Ae=s(1848),Ee=s(1846),Re=s(1849),Fe=s(57),He=s.n(Fe),Me=s(434),Ve=s.n(Me),We=s(191),Je={en:Se.a,fr:we.a,ru:Ce.a,de:Ee.a,es:ke.a,br:Ae.a,nl:Re.a,it:Te.a,pt:De.a,pl:Ie.a,"zh-cn":Ne.a};function Le(e){return e<10?"00"+e:e<100?"0"+e:e}function Ye(e){return e<10?"0"+e:e}var Ue=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).onChange=function(e,t){if(e===n.props.obj._id&&t&&n.state.values&&(!n.state.values.length||n.state.values[n.state.values.length-1].ts<t.ts)){var s=[].concat(Object(L.a)(n.state.values),[t]);n.setState({values:s})}};var o=window.localStorage.getItem("App.relativeRange")||"absolute",i=parseInt(window.localStorage.getItem("App.absoluteStart"),10)||0,r=parseInt(window.localStorage.getItem("App.absoluteEnd"),10)||0,l=window.localStorage.getItem("App.historySelected")||"",c=parseInt(window.localStorage.getItem("App.historyLastSelected"),10)||null,u=window.localStorage.getItem("App.historyLastSelectedColumn")||null;i&&r||o&&"absolute"!==o||(o="30"),i&&r&&(o="absolute");try{l=JSON.parse(l)}catch(d){l=[]}return n.state={loaded:!1,min:null,max:null,start:i,end:r,values:null,relativeRange:o,selected:l,lastSelected:c,lastSelectedColumn:u,historyInstance:"",updateOpened:!1,insertOpened:!1,historyInstances:null,defaultHistory:"",lcVisible:!0,qVisible:!0,ackVisible:!0,fromVisible:!0,supportedFeatures:[],dateFormat:"dd.MM.yyyy",edit:{}},n.adminInstance=parseInt(window.location.search.slice(1),10)||0,n.supportedFeaturesPromises={},n.unit=n.props.obj.common&&n.props.obj.common.unit?" "+n.props.obj.common.unit:"",n.timeTimer=null,n.prepareData().then((function(){return n.readHistoryRange()})).then((function(){"absolute"!==o?n.setRelativeInterval(n.state.relativeRange,!0):n.readHistory()})),n}return Object(n.a)(s,[{key:"readSupportedFeatures",value:function(e){var t=this;return(e=e||this.state.historyInstance)?(this.supportedFeaturesPromises[e]||(this.supportedFeaturesPromises[e]=new Promise((function(s){t.readSupportedFeaturesTimeout&&clearTimeout(t.readSupportedFeaturesTimeout),t.readSupportedFeaturesTimeout=setTimeout((function(){t.readSupportedFeaturesTimeout=null,s([])}),2e3),t.props.socket.sendTo(e,"features",null).then((function(e){t.readSupportedFeaturesTimeout?(t.readSupportedFeaturesTimeout&&clearTimeout(t.readSupportedFeaturesTimeout),t.readSupportedFeaturesTimeout=null,s(e&&e.supportedFeatures||[])):t.setState({supportedFeatures:e&&e.supportedFeatures||[]})}))}))),this.supportedFeaturesPromises[e]):Promise.resolve([])}},{key:"componentDidMount",value:function(){this.props.socket.subscribeState(this.props.obj._id,this.onChange)}},{key:"componentWillUnmount",value:function(){this.timeTimer&&clearTimeout(this.timeTimer),this.timeTimer=null,this.props.socket.unsubscribeState(this.props.obj._id,this.onChange)}},{key:"prepareData",value:function(){var e,t=this;return this.getHistoryInstances().then((function(s){return e=s,t.props.socket.getCompactSystemConfig()})).then((function(s){var a=s&&s.common&&s.common.defaultHistory,n=window.localStorage.getItem("App.historyInstance")||"";return n&&e.find((function(e){return e.id===n&&e.alive}))||(n=a),n&&e.find((function(e){return e.id===n&&e.alive}))||(n=e.find((function(e){return e.alive})))&&(n=n.id),!n&&e.length&&(n=a),t.readSupportedFeatures(n).then((function(o){return new Promise((function(i){t.setState({historyInstances:e,defaultHistory:a,historyInstance:n,supportedFeatures:o,dateFormat:(s.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y")},(function(){return i()}))}))}))}))}},{key:"getHistoryInstances",value:function(){var e=this,t=[],s=[];return this.props.customsInstances.forEach((function(a){var n=e.props.objects["system.adapter."+a];if(n&&n.common&&n.common.getHistory){var o={id:a,alive:!1};t.push(o),s.push("system.adapter.".concat(a,".alive"))}})),s.length?this.props.socket.getForeignStates(s).then((function(e){return Object.keys(e).forEach((function(s){var a=t.find((function(e){return s.endsWith(e.id+".alive")}));a&&(a.alive=e[s]&&e[s].val)})),t})):Promise.resolve(t)}},{key:"readHistory",value:function(e,t){var s=this;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"}).then((function(e){var t=[],a=s.rangeValues,n=!1,o=!1,i=!1,r=!1,l=!1;if(a&&a.length&&(!e||!e.length||a[0].ts<e[0].ts)&&(t.push(a[0]),t.push({ts:a[0].ts+1,e:!0}),console.log("add ".concat(new Date(a[0].ts).toISOString(),": ").concat(a[0].val)),o||void 0===a[0].q||(o=!0),i||void 0===a[0].ack||(i=!0),!r&&a[0].from&&(r=!0),!l&&a[0].c&&(l=!0)),e&&e.length)for(var c=0;c<e.length;c++)e[c]&&(!t.length||t[t.length-1].ts<e[c].ts)?(t.push(e[c]),e[c].from&&(e[c].from.startsWith("system.adapter.")?e[c].from=e[c].from.substring(15):e[c].from.startsWith("system.host.")&&(e[c].from=e[c].from.substring(7))),!n&&e[c].lc&&(n=!0),o||void 0===e[c].q||(o=!0),i||void 0===e[c].ack||(i=!0),!r&&e[c].from&&(r=!0),!l&&e[c].c&&(l=!0),console.log("add value ".concat(new Date(e[c].ts).toISOString(),": ").concat(e[c].val))):t[t.length-1].ts===e[c].ts&&t[t.length-1].val!==e[c].ts&&console.error("Strange data!");else t.push({noDataForPeriod:!0});t.length||t.push({noData:!0}),s.setState({loading:!1,values:t,lcVisible:n,fromVisible:r,qVisible:o,ackVisible:i,cVisible:l})}))):null}},{key:"readHistoryRange",value:function(){var e=this,t=new Date,s=new Date(2e3,0,1);return this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:t.getTime(),step:2592e6,from:!1,ack:!1,q:!1,addID:!1,aggregate:"minmax"}).then((function(t){t.length?(null!==t[0].val&&t[0].ts!==s.getTime()||t.shift(),t.forEach((function(e){return e.i=!0})),e.rangeValues=t,e.setState({min:t[0].ts,max:t[t.length-1].ts,loading:!1})):(e.rangeValues=[],e.setState({loading:!1}))}))}},{key:"onToggleSelect",value:function(e,t,s){var a=Object(L.a)(this.state.selected),n=a.indexOf(t);if(e.shiftKey&&this.state.lastSelected){var o=-1,i=-1;a=[];for(var r=0;r<this.state.values.length&&(this.state.values[r].ts!==t||(i!==(o=r)&&a.push(this.state.values[r].ts),-1===o||-1===i))&&(this.state.values[r].ts!==this.state.lastSelected||((i=r)!==o&&a.push(this.state.values[r].ts),-1===o||-1===i));r++)-1===o&&-1===i||a.push(this.state.values[r].ts)}else e.ctrlKey?(-1!==n?a.splice(n,1):a.push(t),a.sort()):a=[t];window.localStorage.setItem("App.historyLastSelected",t.toString()),window.localStorage.setItem("App.historyLastSelectedColumn",s),window.localStorage.setItem("App.historySelected",JSON.stringify(a)),this.setState({selected:a,lastSelected:t,lastSelectedColumn:s})}},{key:"getTableRows",value:function(e){for(var t=this,s=[],a=function(a){var n=t.state.values[a],o=n.ts;if(n.e)s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,e.rowInterpolated),hover:!0,children:[Object(se.jsx)(ge.a,{}),Object(se.jsx)(ge.a,{children:"..."}),t.state.ackVisible?Object(se.jsx)(ge.a,{}):null,t.state.fromVisible?Object(se.jsx)(ge.a,{}):null,t.state.lcVisible?Object(se.jsx)(ge.a,{}):null]},o));else if(n.noData||n.noDataForPeriod)s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,e.rowNoData),hover:!0,children:[Object(se.jsx)(ge.a,{}),Object(se.jsx)(ge.a,{children:n.noData?t.props.t("No data in history"):t.props.t("No data in history for selected period")}),t.state.ackVisible?Object(se.jsx)(ge.a,{}):null,t.state.fromVisible?Object(se.jsx)(ge.a,{}):null,t.state.lcVisible?Object(se.jsx)(ge.a,{}):null]},n.noData?"nodata":""));else{var i=n.i,r=t.state.lastSelected===o,l=n.val;t.props.isFloatComma&&"number"===t.props.obj.common.type&&l&&(l=l.toString().replace(".",",")),null===l&&(l="null"),void 0===l&&(l="_"),s.push(Object(se.jsxs)(fe.a,{className:Object(Y.default)(e.row,e.updatedRow,i&&e.rowInterpolated,t.state.selected.includes(o)&&e.rowSelected),children:[Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"ts")},children:["".concat(new Date(n.ts).toLocaleDateString()," ").concat(new Date(n.ts).toLocaleTimeString(),".").concat(Le(n.ts%1e3)),r&&"ts"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}),Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"val")},children:[l+t.unit,r&&"val"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}),t.state.ackVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"ack")},className:n.ack?e.cellAckTrue:e.cellAckFalse,children:[n.ack?"true":"false",r&&"ack"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null,t.state.fromVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"from")},children:[n.from||"",r&&"from"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null,t.state.lcVisible?Object(se.jsxs)(ge.a,{onClick:function(e){return!i&&t.onToggleSelect(e,o,"lc")},children:[n.lc?"".concat(new Date(n.lc).toLocaleDateString()," ").concat(new Date(n.lc).toLocaleTimeString(),".").concat(Le(n.ts%1e3)):"",r&&"lc"===t.state.lastSelectedColumn?Object(se.jsx)("div",{className:e.rowFocused}):""]}):null]},o+(n.val||"")))}},n=this.state.values.length-1;n>=0;n--)a(n);return s}},{key:"shiftTime",value:function(){var e=this,t=new Date,s=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);var a,n=t.getTime(),o=this.state.relativeRange;"day"===o?(t.setHours(0),t.setMinutes(0),a=t.getTime()):"week"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-1):t.setDate(t.getDate()-6)):"2weeks"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-8):t.setDate(t.getDate()-13)):"month"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),a=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),t.setMonth(0),a=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),a=t.getTime()):a=n-6e4*(o=parseInt(o,10)),this.setState({start:a,end:n},(function(){return e.readHistory()})),this.timeTimer=setTimeout((function(){e.timeTimer=null,e.shiftTime()}),s||6e4)}},{key:"setRelativeInterval",value:function(e,t){var s=this;if(t||(window.localStorage.setItem("App.relativeRange",e),this.setState({relativeRange:e})),"absolute"===e)return this.timeTimer&&clearTimeout(this.timeTimer),void(this.timeTimer=null);window.localStorage.removeItem("App.absoluteStart"),window.localStorage.removeItem("App.absolute");var a=new Date;if(!this.timeTimer){var n=6e4-a.getSeconds()-(1e3-a.getMilliseconds());this.timeTimer=setTimeout((function(){s.timeTimer=null,s.shiftTime()}),n||6e4)}a.getMilliseconds()&&a.setMilliseconds(1e3),a.getSeconds()&&a.setSeconds(60);var o,i=a.getTime();"day"===e?(a.setHours(0),a.setMinutes(0),o=a.getTime()):"week"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),a.getDay()?a.setDate(a.getDate()-a.getDay()-1):a.setDate(a.getDate()-6)):"2weeks"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),a.getDay()?a.setDate(a.getDate()-a.getDay()-8):a.setDate(a.getDate()-13)):"month"===e?(a.setHours(0),a.setMinutes(0),a.setDate(1),o=a.getTime()):"year"===e?(a.setHours(0),a.setMinutes(0),a.setDate(1),a.setMonth(0),o=a.getTime()):"12months"===e?(a.setHours(0),a.setMinutes(0),a.setFullYear(a.getFullYear()-1),o=a.getTime()):o=i-6e4*(e=parseInt(e,10)),this.setState({start:o,end:i},(function(){return s.readHistory()}))}},{key:"renderTable",value:function(){if(this.state.values){var e=this.props.classes;return Object(se.jsx)(xe.a,{className:e.container,children:Object(se.jsxs)(be.a,{stickyHeader:!0,size:"small",className:e.table,children:[Object(se.jsx)(je.a,{children:Object(se.jsxs)(fe.a,{children:[Object(se.jsx)(ge.a,{className:e.colTs,children:this.props.t("Timestamp")}),Object(se.jsx)(ge.a,{className:e.colValue,children:this.props.t("Value")}),this.state.ackVisible?Object(se.jsx)(ge.a,{className:e.colAck,children:this.props.t("Ack")}):null,this.state.fromVisible?Object(se.jsx)(ge.a,{className:e.colFrom,children:this.props.t("From")}):null,this.state.lcVisible?Object(se.jsx)(ge.a,{className:e.colLastChange,children:this.props.t("Last change")}):null]})}),Object(se.jsx)(Oe.a,{children:this.getTableRows(e)})]})})}return Object(se.jsx)(U.a,{})}},{key:"renderConfirmDialog",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!!this.state.areYouSure,onClose:function(){return e.setState({areYouSure:!1})},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[Object(se.jsx)(h.a,{id:"alert-dialog-title"}),Object(se.jsxs)(p.a,{children:[Object(se.jsx)(b.a,{id:"alert-dialog-description",children:this.props.t("Are you sure?")}),Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{value:this.state.suppressMessage,onChange:function(){return e.setState({suppressMessage:!0})}}),label:this.props.t("Suppress for 5 minutes")})]}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({areYouSure:!1,suppressMessage:e.state.suppressMessage&&Date.now()},(function(){return e.onDelete()}))},color:"primary",autoFocus:!0,startIcon:Object(se.jsx)(y.a,{}),children:this.props.t("Delete")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({areYouSure:!1})},color:"secondary",startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}},{key:"onDelete",value:function(){var e=this,t=this.state.selected.map((function(t){return{state:{ts:t},id:e.props.obj._id}}));this.props.socket.sendTo(this.state.historyInstance,"delete",t).then((function(){return e.readHistory()}))}},{key:"onUpdate",value:function(){var e=this,t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?"number"!==typeof t&&(t=parseFloat(t.replace(",","."))):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));var s={val:t,ack:this.state.edit.ack,ts:this.state.selected[0],from:"system.adapter.admin."+this.adminInstance,q:this.state.edit.q};Object.keys(s).forEach((function(e){void 0===s[e]&&delete s[e]})),!this.state.lcVisible&&s.lc&&delete s.lc,this.props.socket.sendTo(this.state.historyInstance,"update",[{id:this.props.obj._id,state:s}]).then((function(){return e.readHistory()}))}},{key:"onInsert",value:function(){var e=this,t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?t=parseFloat(t.replace(",",".")):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));var s=this.state.edit.date;s.setHours(this.state.edit.time.getHours()),s.setMinutes(this.state.edit.time.getMinutes()),s.setSeconds(this.state.edit.time.getSeconds()),s.setMilliseconds(parseInt(this.state.edit.ms,10));var a={ts:s.getTime(),val:t,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((function(e){void 0===a[e]&&delete a[e]})),this.props.socket.sendTo(this.state.historyInstance,"insert",[{id:this.props.obj._id,state:a}]).then((function(){return e.readHistory()}))}},{key:"formatTime",value:function(e){var t=new Date(e);return"".concat(Ye(t.getHours()),":").concat(Ye(t.getMinutes()),":").concat(Ye(t.getSeconds()),".").concat(Le(t.getMilliseconds()))}},{key:"formatDate",value:function(e){var t=new Date(e);return"".concat(Ye(t.getDate()),".").concat(Ye(t.getMonth()+1),".").concat(t.getFullYear())}},{key:"updateEdit",value:function(e,t){var s=JSON.parse(JSON.stringify(this.state.edit));s.time=new Date(s.time),s.date=new Date(s.date),s[e]=t,this.setState({edit:s})}},{key:"renderEditDialog",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:this.state.updateOpened||this.state.insertOpened,onClose:function(){return e.setState({updateOpened:!1,insertOpened:!1})},"aria-labelledby":"edit-dialog-title","aria-describedby":"edit-dialog-description",children:[Object(se.jsx)(h.a,{id:"edit-dialog-title",children:this.state.updateOpened?this.props.t("Update entry"):this.props.t("Insert entry")}),Object(se.jsx)(p.a,{children:Object(se.jsxs)("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",children:["boolean"===typeof this.state.edit.val?Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:this.state.edit.val,onChange:function(t){return e.updateEdit("val",t.target.checked)}}),label:this.props.t("Value")}):Object(se.jsx)(ve.a,{label:this.props.t("Value"),value:this.state.edit.val,onChange:function(t){return e.updateEdit("val",t.target.value)}}),Object(se.jsx)("br",{}),Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:this.state.edit.ack,onChange:function(t){return e.updateEdit("ack",t.target.checked)}}),label:this.props.t("Acknowledged")}),this.state.insertOpened?Object(se.jsx)(ie.a,{utils:ye.a,locale:Je[this.props.lang],children:Object(se.jsxs)(me.a,{container:!0,justify:"space-around",children:[Object(se.jsx)(re.a,{className:this.props.classes.editorDatePicker,margin:"normal",label:this.props.t("Date"),format:this.state.dateFormat,value:this.state.edit.date,onChange:function(t){return e.updateEdit("date",t)}}),Object(se.jsx)(le.a,{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:function(t){return e.updateEdit("time",t)}}),Object(se.jsx)(ve.a,{classes:{root:this.props.classes.msInput},label:this.props.t("ms"),type:"number",inputProps:{max:999,min:0},value:this.state.edit.ms,onChange:function(t){return e.updateEdit("ms",t.target.value)}})]})}):null]})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){var t=e.state.updateOpened;e.setState({updateOpened:!1,insertOpened:!1},(function(){return t?e.onUpdate():e.onInsert()}))},color:"primary",autoFocus:!0,children:this.state.updateOpened?this.props.t("Update"):this.props.t("Add")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({updateOpened:!1,insertOpened:!1})},children:this.props.t("Cancel")})]})]})}},{key:"setStartDate",value:function(e){var t=this;e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",e),window.localStorage.setItem("App.absoluteEnd",this.state.end),this.setState({start:e,relativeRange:"absolute"},(function(){return t.readHistory()}))}},{key:"setEndDate",value:function(e){var t=this;e=e.getTime(),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",this.state.start),window.localStorage.setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.setState({end:e,relativeRange:"absolute"},(function(){return t.readHistory()}))}},{key:"renderToolbar",value:function(){var e=this,t=this.props.classes;return Object(se.jsxs)(pe.a,{children:[Object(se.jsxs)(de.a,{className:t.selectHistoryControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("History instance")}),Object(se.jsx)(he.a,{value:this.state.historyInstance,onChange:function(t){var s=t.target.value;window.localStorage.setItem("App.historyInstance",s),e.readSupportedFeatures(s).then((function(t){return e.setState({historyInstance:s,supportedFeatures:t},(function(){return e.readHistory()}))}))},children:this.state.historyInstances.map((function(e){return Object(se.jsx)(ue.a,{value:e.id,className:Object(Y.default)(!e.alive&&t.notAliveInstance),children:e.id},e.id)}))})]}),Object(se.jsxs)(de.a,{className:t.selectRelativeTime,children:[Object(se.jsx)(ce.a,{children:this.props.t("Relative")}),Object(se.jsxs)(he.a,{ref:this.rangeRef,value:this.state.relativeRange,onChange:function(t){return e.setRelativeInterval(t.target.value)},children:[Object(se.jsx)(ue.a,{value:"absolute",className:t.customRange,children:this.props.t("custom range")},"custom"),Object(se.jsx)(ue.a,{value:10,children:this.props.t("last 10 minutes")},"1"),Object(se.jsx)(ue.a,{value:30,children:this.props.t("last 30 minutes")},"2"),Object(se.jsx)(ue.a,{value:60,children:this.props.t("last hour")},"3"),Object(se.jsx)(ue.a,{value:"day",children:this.props.t("this day")},"4"),Object(se.jsx)(ue.a,{value:1440,children:this.props.t("last 24 hours")},"5"),Object(se.jsx)(ue.a,{value:"week",children:this.props.t("this week")},"6"),Object(se.jsx)(ue.a,{value:10080,children:this.props.t("last week")},"7"),Object(se.jsx)(ue.a,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),Object(se.jsx)(ue.a,{value:20160,children:this.props.t("last 2 weeks")},"9"),Object(se.jsx)(ue.a,{value:"month",children:this.props.t("this month")},"10"),Object(se.jsx)(ue.a,{value:43200,children:this.props.t("last 30 days")},"11"),Object(se.jsx)(ue.a,{value:"year",children:this.props.t("this year")},"12"),Object(se.jsx)(ue.a,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),Object(se.jsxs)(ie.a,{utils:ye.a,locale:Je[this.props.lang],children:[Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{className:t.toolbarDate,disabled:"absolute"!==this.state.relativeRange,disableToolbar:!0,variant:"inline",margin:"normal",format:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.start),onChange:function(t){return e.setStartDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.start),onChange:function(t){return e.setStartDate(t)}})]}),Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarDate,disableToolbar:!0,format:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.end),onChange:function(t){return e.setEndDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.end),onChange:function(t){return e.setEndDate(t)}})]})]}),Object(se.jsx)("div",{className:t.grow}),this.state.values&&this.state.values.length?Object(se.jsx)(f.a,{onClick:function(){return e.exportData()},title:this.props.t("Save data as csv"),children:Object(se.jsx)(We.FaDownload,{})}):null,this.state.supportedFeatures.includes("insert")&&this.props.expertMode?Object(se.jsx)(f.a,{onClick:function(){var t=new Date,s={ack:e.state.values[e.state.values.length-1].ack,val:e.state.values[e.state.values.length-1].val,ts:t,date:new Date(t),ms:0,time:new Date(t),q:0};e.setState({edit:s,insertOpened:!0})},children:Object(se.jsx)(We.FaPlusSquare,{})}):null,this.state.supportedFeatures.includes("update")&&this.props.expertMode?Object(se.jsx)(f.a,{disabled:1!==this.state.selected.length,onClick:function(){var t=JSON.parse(JSON.stringify(e.state.values.find((function(t){return t.ts===e.state.lastSelected})))),s=new Date(t.ts);t.date=new Date(s),t.time=new Date(s),e.setState({edit:t,updateOpened:!0})},children:Object(se.jsx)(Ve.a,{})}):null,this.state.supportedFeatures.includes("delete")&&this.props.expertMode?Object(se.jsx)(f.a,{disabled:!this.state.selected.length,onClick:function(){e.state.suppressMessage&&Date.now()-e.state.suppressMessage<3e5?e.onDelete():e.setState({areYouSure:!0})},children:Object(se.jsx)(y.a,{})}):null]})}},{key:"exportData",value:function(){var e=window.document.getElementById("export-file");e||((e=document.createElement("a")).setAttribute("id","export-file"),e.style.display="none",document.body.appendChild(e));var t=["timestamp;value;acknowledged;from;"];this.state.values.forEach((function(e){return!e.i&&!e.e&&t.push([new Date(e.ts).toISOString(),null===e.val||void 0===e.val?"null":e.val.toString(),e.ack?"true":"false",e.from||""].join(";"))})),e.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t.join("\n"))),e.setAttribute("download",He.a.getObjectName(Object(oe.a)({},this.props.obj._id,this.props.obj),this.props.obj._id,{language:this.props.lang})+".csv"),e.click(),document.body.removeChild(e)}},{key:"render",value:function(){return this.state.historyInstances?Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.state.loading?Object(se.jsx)(U.a,{}):Object(se.jsx)("div",{className:this.props.classes.noLoadingProgress}),this.renderToolbar(),Object(se.jsx)("div",{className:this.props.classes.tableDiv,children:this.renderTable()}),this.renderConfirmDialog(),this.renderEditDialog()]}):Object(se.jsx)(U.a,{})}}]),s}(l.Component),_e=Object(r.a)()(Object(u.a)((function(e){return{paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},tableDiv:{height:"calc(100% - ".concat(e.mixins.toolbar.minHeight+e.spacing(1),"px)"),overflow:"hidden",width:"100%"},container:{height:"100%"},table:{tableLayout:"fixed",minWidth:960,"& td:nth-of-type(5)":{overflow:"hidden",whiteSpace:"nowrap"}},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:e.palette.primary.main},rowSelected:{background:e.palette.secondary.main},rowFocused:{position:"absolute",pointerEvents:"none",top:0,bottom:0,left:0,right:0,margin:3,border:"1px dotted "+e.palette.action.active},grow:{flexGrow:1},editorTimePicker:{marginLeft:e.spacing(1),width:120},editorDatePicker:{marginLeft:e.spacing(1),width:150},msInput:{width:50,paddingTop:16,marginLeft:5,"& label":{marginTop:15}},cellAckTrue:{color:"#66ff7f"},cellAckFalse:{color:"#FF6666"},toolbarTime:{width:100,marginTop:9,marginLeft:e.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:e.spacing(1),paddingLeft:e.spacing(1),paddingRight:e.spacing(1),border:"1px dotted #AAAAAA",borderRadius:e.spacing(1)},noLoadingProgress:{width:"100%",height:4},colValue:{},colAck:{width:50},colFrom:{width:150},colLastChange:{width:200},colTs:{width:200}}}))(Ue)),Pe=s(614),Be=s(649),ze=s(1877),qe=s.n(ze),Xe=s(1567),Ge=s(2030),Ke=s(2038),$e=s(2045),Qe=s(2037),Ze=s(2036),et=s(2047),tt=s(2039),st=s(2042),at=s(1677);Xe.a([$e.a,Qe.a,Ze.a,et.a,tt.a,Ke.a,st.a]);var nt={en:Se.a,fr:we.a,ru:Ce.a,de:Ee.a,es:ke.a,br:Ae.a,nl:Re.a,it:Te.a,pt:De.a,pl:Ie.a,"zh-cn":Ne.a};function ot(e){return e<10?"0"+e:e}var it=80,rt=25,lt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n,o;Object(a.a)(this,s),(n=t.call(this,e)).onResize=function(){n.timerResize&&clearTimeout(n.timerResize),n.timerResize=setTimeout((function(){n.timerResize=null,n.componentDidUpdate()}))},n.onChange=function(e,t){e===n.props.obj._id&&t&&n.rangeValues&&(!n.rangeValues.length||n.rangeValues[n.rangeValues.length-1].ts<t.ts)&&(n.chartValues&&n.chartValues.push({val:t.val,ts:t.ts}),n.rangeValues.push({val:t.val,ts:t.ts}),t.ts>=n.chart.min&&t.ts<=n.chart.max+3e5&&n.updateChart())},n.props.from?n.start=n.props.from:((o=new Date(n.props.from)).setHours(o.getHours()-168),n.start=o.getTime()),n.props.end?n.end=n.props.end:n.end=Date.now();var i=window.localStorage.getItem("App.relativeRange")||"30",r=parseInt(window.localStorage.getItem("App.absoluteStart"),10)||0,c=parseInt(window.localStorage.getItem("App.absoluteEnd"),10)||0;return r&&c||i&&"absolute"!==i||(i="30"),c&&r&&(i="absolute"),n.state={loaded:!1,historyInstance:n.props.historyInstance||"",historyInstances:null,defaultHistory:"",chartHeight:300,chartWidth:500,relativeRange:i,splitLine:"true"===window.localStorage.getItem("App.splitLine"),dateFormat:"dd.MM.yyyy",min:r,max:c,maxYLen:0},n.echartsReact=Object(l.createRef)(),n.rangeRef=Object(l.createRef)(),n.readTimeout=null,n.chartValues=null,n.rangeValues=null,n.unit=n.props.obj.common&&n.props.obj.common.unit?" "+n.props.obj.common.unit:"",n.divRef=Object(l.createRef)(),n.chart={},n.onChange=n.onChange.bind(Object(Pe.a)(n)),n.onResize=n.onResize.bind(Object(Pe.a)(n)),n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e=this;this.props.socket.subscribeState(this.props.obj._id,this.onChange),window.addEventListener("resize",this.onResize),this.prepareData().then((function(){return!e.props.noToolbar&&e.readHistoryRange()})).then((function(){return e.setRelativeInterval(e.state.relativeRange,!0,(function(){return e.forceUpdate()}))}))}},{key:"componentWillUnmount",value:function(){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)}},{key:"prepareData",value:function(){var e,t=this;return this.props.noToolbar?new Promise((function(e){return t.setState({dateFormat:t.props.dateFormat.replace(/D/g,"d").replace(/Y/g,"y"),defaultHistory:t.props.defaultHistory,historyInstance:t.props.defaultHistory},(function(){return e()}))})):this.getHistoryInstances().then((function(s){return e=s,t.props.socket.getCompactSystemConfig()})).then((function(s){return t.props.showJumpToEchart?t.props.socket.getAdapterInstances("echarts").then((function(a){var n=!!a.find((function(e){return e._id.startsWith("system.adapter.echarts.")})),o=s&&s.common&&s.common.defaultHistory,i=window.localStorage.getItem("App.historyInstance")||"";i&&e.find((function(e){return e.id===i&&e.alive}))||(i=o),i&&e.find((function(e){return e.id===i&&e.alive}))||(i=e.find((function(e){return e.alive})))&&(i=i.id),!i&&e.length&&(i=o),t.setState({dateFormat:(s.common.dateFormat||"dd.MM.yyyy").replace(/D/g,"d").replace(/Y/g,"y"),historyInstances:e,defaultHistory:o,historyInstance:i,echartsJump:n})})):Promise.resolve([])}))}},{key:"getHistoryInstances",value:function(){var e=this,t=[],s=[];return this.props.historyInstance?Promise.resolve(t):(this.props.customsInstances.forEach((function(a){var n=e.props.objects["system.adapter."+a];if(n&&n.common&&n.common.getHistory){var o={id:a,alive:!1};t.push(o),s.push("system.adapter.".concat(a,".alive"))}})),s.length?this.props.socket.getForeignStates(s).then((function(e){return Object.keys(e).forEach((function(s){var a=t.find((function(e){return s.endsWith(e.id+".alive")}));a&&(a.alive=e[s]&&e[s].val)})),t})):Promise.resolve(t))}},{key:"readHistoryRange",value:function(){var e=this,t=new Date,s=new Date(2e3,0,1);return this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:t.getTime(),step:36e5,from:!1,ack:!1,q:!1,addID:!1,aggregate:"minmax"}).then((function(t){var s;t&&null===(null===(s=t[0])||void 0===s?void 0:s.val)&&t.shift(),e.rangeValues=t}))}},{key:"readHistory",value:function(e,t){var s=this,a={instance:this.state.historyInstance,start:e,end:t,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"};return t-e>144e4&&!("boolean"===this.props.obj.common.type||"number"===this.props.obj.common.type&&this.props.obj.common.states)&&(a.aggregate="minmax"),this.props.socket.getHistory(this.props.obj._id,a).then((function(e){for(var t=[],a=0,n=s.rangeValues,o=null,i=null,r=0;r<e.length;r++){if(n)for(;a<n.length&&n[a].ts<e[r].ts;)t.push(n[a]),a++;!t.length||t[t.length-1].ts<e[r].ts?t.push(e[r]):t[t.length-1].ts===e[r].ts&&t[t.length-1].val!==e[r].ts&&console.error("Strange data!"),(null===o||e[r].val<o)&&(o=e[r].val),(null===i||e[r].val>i)&&(i=e[r].val)}if(n)for(;a<n.length;)t.push(n[a]),console.log("add range ".concat(new Date(n[a].ts).toISOString(),": ").concat(n[a].val)),a++;return t.sort((function(e,t){return e.ts>t.ts?1:e.ts<t.ts?-1:0})),s.chartValues=t,s.minY=o,s.maxY=i,s.minY<10?s.minY=Math.round(10*s.minY)/10:s.minY=Math.ceil(s.minY),s.maxY<10?s.maxY=Math.round(10*s.maxY)/10:s.maxY=Math.ceil(s.maxY),t}))}},{key:"convertData",value:function(e){var t=[];if(!(e=e||this.chartValues).length)return t;for(var s=0;s<e.length;s++)t.push({value:[e[s].ts,e[s].val]});return this.chart.min||(this.chart.min=e[0].ts,this.chart.max=e[e.length-1].ts),t}},{key:"getOption",value:function(){var e,t=this;if(null!==this.minY&&void 0!==this.minY&&(e=9*(this.minY.toString()+this.unit).length+12),null!==this.maxY&&void 0!==this.maxY){var s=9*(this.maxY.toString()+this.unit).length+12;s>e&&(e=s)}if(this.state.maxYLen){var a=9*this.state.maxYLen+12;a>e&&(e=a)}var n={xAxisIndex:0,type:"line",showSymbol:!1,hoverAnimation:!0,animation:!1,data:this.convertData(),lineStyle:{color:"#4dabf5"},areaStyle:{}},o={type:"value",boundaryGap:[0,"100%"],splitLine:{show:this.props.noToolbar||!!this.state.splitLine},splitNumber:Math.round(this.state.chartHeight/50),axisLabel:{formatter:function(e,s){var a;return a=t.props.isFloatComma?e.toString().replace(",",".")+t.unit:e+t.unit,t.state.maxYLen<a.length&&(t.maxYLenTimeout&&clearTimeout(t.maxYLenTimeout),t.maxYLenTimeout=setTimeout((function(e){return t.setState({maxYLen:e})}),200,a.length)),a},showMaxLabel:!0,showMinLabel:!0},axisTick:{alignWithLabel:!0}};if("boolean"===this.props.obj.common.type)n.step="end",o.axisLabel.showMaxLabel=!1,o.axisLabel.formatter=function(e){return 1===e?"TRUE":"FALSE"},o.max=1.5,o.interval=1,e=50;else if("number"===this.props.obj.common.type&&this.props.obj.common.states){n.step="end",o.axisLabel.showMaxLabel=!1,o.axisLabel.formatter=function(e){return void 0!==t.props.obj.common.states[e]?t.props.obj.common.states[e]:e};var i=Object.keys(this.props.obj.common.states);i.sort(),o.max=parseFloat(i[i.length-1])+.5,o.interval=1;for(var r="",l=0;l<i.length;l++)"string"===typeof this.props.obj.common.states[i[l]]&&this.props.obj.common.states[i[l]].length>r.length&&(r=this.props.obj.common.states[i[l]]);e=(9*r.length||50)+12}return{backgroundColor:"transparent",title:{text:this.props.noToolbar?"":He.a.getObjectNameFromObj(this.props.obj,this.props.lang),padding:[10,0,0,e?e+10:90]},grid:{left:e||it,top:8,right:this.props.noToolbar?5:rt,bottom:40},tooltip:{trigger:"axis",formatter:function(e){e=e[0];var s,a=new Date(e.value[0]),n=e.value[1];return null!==n&&t.props.isFloatComma&&(n=n.toString().replace(".",",")),"".concat(a.toLocaleString(),".").concat((s=a.getMilliseconds(),s<10?"00"+s:s<100?"0"+s:s),": ").concat(n).concat(t.unit)},axisPointer:{animation:!0}},xAxis:{type:"time",splitLine:{show:!1},splitNumber:this.chart.withSeconds?Math.round((this.state.chartWidth-rt-it)/70):Math.round((this.state.chartWidth-rt-it)/50),min:this.chart.min,max:this.chart.max,axisTick:{alignWithLabel:!0},axisLabel:{formatter:function(e,s){var a=new Date(e);return t.chart.withSeconds?ot(a.getHours())+":"+ot(a.getMinutes())+":"+ot(a.getSeconds()):t.chart.withTime?ot(a.getHours())+":"+ot(a.getMinutes())+"\n"+ot(a.getDate())+"."+ot(a.getMonth()+1):ot(a.getDate())+"."+ot(a.getMonth()+1)+"\n"+a.getFullYear()}}},yAxis:o,toolbox:{left:"right",feature:this.props.noToolbar?void 0:{saveAsImage:{title:this.props.t("Save as image"),show:!0}}},series:[n]}}},{key:"updateChart",value:function(e,t,s,a){var n=this;e&&(this.start=e),t&&(this.end=t),e=e||this.start,t=t||this.end,this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=setTimeout((function(){n.readTimeout=null;var o=n.chart.max-n.chart.min;o!==n.chart.diff&&(n.chart.diff=o,n.chart.withTime=n.chart.diff<6048e5,n.chart.withSeconds=n.chart.diff<18e5),s?n.readHistory(e,t).then((function(e){n.echartsReact&&"function"===typeof n.echartsReact.getEchartsInstance&&n.echartsReact.getEchartsInstance().setOption({series:[{data:n.convertData(e)}],xAxis:{min:n.chart.min,max:n.chart.max}}),a&&a()})):(n.echartsReact&&"function"===typeof n.echartsReact.getEchartsInstance&&n.echartsReact.getEchartsInstance().setOption({series:[{data:n.convertData()}],xAxis:{min:n.chart.min,max:n.chart.max}}),a&&a())}),400)}},{key:"setNewRange",value:function(e){this.chart.diff=this.chart.max-this.chart.min,this.chart.withTime=this.chart.diff<6048e5,this.chart.withSeconds=this.chart.diff<18e5,"absolute"!==this.state.relativeRange?this.setState({relativeRange:"absolute"}):this.echartsReact&&"function"===typeof this.echartsReact.getEchartsInstance&&(this.echartsReact.getEchartsInstance().setOption({xAxis:{min:this.chart.min,max:this.chart.max}}),e&&this.updateChart(this.chart.min,this.chart.max,!0))}},{key:"shiftTime",value:function(){var e=this,t=new Date,s=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);var a,n=t.getTime(),o=this.state.relativeRange;"day"===o?(t.setHours(0),t.setMinutes(0),a=t.getTime()):"week"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-1):t.setDate(t.getDate()-6),this.chart.min=t.getTime()):"2weeks"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),t.getDay()?t.setDate(t.getDate()-t.getDay()-8):t.setDate(t.getDate()-13),this.chart.min=t.getTime()):"month"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),a=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setDate(1),t.setMonth(0),a=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setFullYear(t.getFullYear()-1),a=t.getTime()):a=n-6e4*(o=parseInt(o,10)),this.chart.min=a,this.chart.max=n,this.setState({min:a,max:n},(function(){return e.updateChart(e.chart.min,e.chart.max,!0)})),this.timeTimer=setTimeout((function(){e.timeTimer=null,e.shiftTime()}),s||6e4)}},{key:"setRelativeInterval",value:function(e,t,s){var a=this;if(t||(window.localStorage.setItem("App.relativeRange",e),this.setState({relativeRange:e})),"absolute"===e)return this.timeTimer&&clearTimeout(this.timeTimer),void(this.timeTimer=null);window.localStorage.removeItem("App.absoluteStart"),window.localStorage.removeItem("App.absoluteEnd");var n=new Date;if(!this.timeTimer){var o=6e4-n.getSeconds()-(1e3-n.getMilliseconds());this.timeTimer=setTimeout((function(){a.timeTimer=null,a.shiftTime()}),o||6e4)}n.getMilliseconds()&&n.setMilliseconds(1e3),n.getSeconds()&&n.setSeconds(60),this.chart.max=n.getTime(),"day"===e?(n.setHours(0),n.setMinutes(0),this.chart.min=n.getTime()):"week"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),n.getDay()?n.setDate(n.getDate()-n.getDay()-1):n.setDate(n.getDate()-6),this.chart.min=n.getTime()):"2weeks"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),n.getDay()?n.setDate(n.getDate()-n.getDay()-8):n.setDate(n.getDate()-13),this.chart.min=n.getTime()):"month"===e?(n.setHours(0),n.setMinutes(0),n.setDate(1),this.chart.min=n.getTime()):"year"===e?(n.setHours(0),n.setMinutes(0),n.setDate(1),n.setMonth(0),this.chart.min=n.getTime()):"12months"===e?(n.setHours(0),n.setMinutes(0),n.setFullYear(n.getFullYear()-1),this.chart.min=n.getTime()):(e=parseInt(e,10),this.chart.min=this.chart.max-6e4*e),this.setState({min:this.chart.min,max:this.chart.max},(function(){return a.updateChart(a.chart.min,a.chart.max,!0,s)}))}},{key:"installEventHandlers",value:function(){var e=this;if(this.echartsReact&&"function"===typeof this.echartsReact.getEchartsInstance){var t=this.echartsReact.getEchartsInstance().getZr();t._iobInstalled||(t._iobInstalled=!0,t.on("mousedown",(function(t){console.log("mouse down"),e.mouseDown=!0,e.chart.lastX=t.offsetX})),t.on("mouseup",(function(){console.log("mouse up"),e.mouseDown=!1,e.setNewRange(!0)})),t.on("mousewheel",(function(t){var s=e.chart.max-e.chart.min,a=e.state.chartWidth-rt-it,n=(t.offsetX-it)/a,o=s-(s*=t.wheelDelta>0?1.1:.9);e.chart.max+=o*(1-n),e.chart.min-=o*n,e.setNewRange()})),t.on("mousemove",(function(t){if(e.mouseDown){var s=e.chart.lastX-(t.offsetX-it);e.chart.lastX=t.offsetX-it;var a=e.chart.max-e.chart.min,n=e.state.chartWidth-rt-it,o=Math.round(s*a/n);e.chart.min+=o,e.chart.max+=o,e.setNewRange()}})),t.on("touchstart",(function(t){t.preventDefault(),e.mouseDown=!0;var s=t.touches||t.originalEvent.touches;s&&(e.chart.lastX=s[s.length-1].pageX,s.length>1?e.chart.lastWidth=Math.abs(s[0].pageX-s[1].pageX):e.chart.lastWidth=null)})),t.on("touchend",(function(t){t.preventDefault(),e.mouseDown=!1,e.setNewRange(!0)})),t.on("touchmove",(function(t){t.preventDefault();var s=t.touches||t.originalEvent.touches;if(s){var a=s[s.length-1].pageX-it;if(e.mouseDown)if(s.length>1){var n=Math.abs(s[0].pageX-s[1].pageX);if(null!==e.chart.lastWidth&&n!==e.chart.lastWidth){var o=e.chart.max-e.chart.min,i=e.state.chartWidth-rt-it,r=n>e.chart.lastWidth?1.1:.9,l=(s[0].pageX>s[1].pageX?s[1].pageX-it+n/2:s[0].pageX-it+n/2)/i,c=o-(o*=r);e.chart.max+=c*(1-l),e.chart.min-=c*l,e.setNewRange()}e.chart.lastWidth=n}else{var u=e.chart.lastX-a,d=e.chart.max-e.chart.min,h=e.state.chartWidth-rt-it,p=Math.round(u*d/h);e.chart.min+=p,e.chart.max+=p,e.setNewRange()}e.chart.lastX=a}})))}}},{key:"renderChart",value:function(){var e=this;return this.chartValues?Object(se.jsx)(qe.a,{ref:function(t){return e.echartsReact=t},echarts:Ge,option:this.getOption(),notMerge:!0,lazyUpdate:!0,theme:"dark"===this.props.themeType?"dark":"",style:{height:this.state.chartHeight+"px",width:"100%"},opts:{renderer:"svg"},onEvents:{rendered:function(t){e.installEventHandlers()}}}):Object(se.jsx)(U.a,{})}},{key:"componentDidUpdate",value:function(){var e=this;if(this.divRef.current){var t=this.divRef.current.offsetWidth,s=this.divRef.current.offsetHeight;this.state.chartHeight!==s&&setTimeout((function(){return e.setState({chartHeight:s,chartWidth:t})}),100)}}},{key:"setStartDate",value:function(e){var t=this;e=e.getTime(),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",e),window.localStorage.setItem("App.absoluteEnd",this.state.max),this.chart.min=e,this.setState({min:e,relativeRange:"absolute"},(function(){return t.updateChart(t.chart.min,t.chart.max,!0)}))}},{key:"setEndDate",value:function(e){var t=this;e=e.getTime(),window.localStorage.setItem("App.relativeRange","absolute"),window.localStorage.setItem("App.absoluteStart",this.state.min),window.localStorage.setItem("App.absoluteEnd",e),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.chart.max=e,this.setState({max:e,relativeRange:"absolute"},(function(){return t.updateChart(t.chart.min,t.chart.max,!0)}))}},{key:"openEcharts",value:function(){var e=["id="+window.encodeURIComponent(this.props.obj._id),"instance="+window.encodeURIComponent(this.state.historyInstance),"menuOpened=false"];"absolute"===this.state.relativeRange?(e.push("start="+this.chart.min),e.push("end="+this.chart.max)):e.push("range="+this.state.relativeRange),window.open("".concat(window.location.protocol,"//").concat(window.location.host,"/adapter/echarts/tab.html#").concat(e.join("&")),"echarts")}},{key:"renderToolbar",value:function(){var e=this;if(this.props.noToolbar)return null;var t=this.props.classes;return Object(se.jsxs)(pe.a,{children:[!this.props.historyInstance&&Object(se.jsxs)(de.a,{className:t.selectHistoryControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("History instance")}),Object(se.jsx)(he.a,{value:this.state.historyInstance,onChange:function(t){window.localStorage.setItem("App.historyInstance",t.target.value),e.setState({historyInstance:t.target.value})},children:this.state.historyInstances.map((function(e){return Object(se.jsx)(ue.a,{value:e.id,className:Object(Y.default)(!e.alive&&t.notAliveInstance),children:e.id},e.id)}))})]}),Object(se.jsxs)(de.a,{className:t.selectRelativeTime,children:[Object(se.jsx)(ce.a,{children:this.props.t("Relative")}),Object(se.jsxs)(he.a,{ref:this.rangeRef,value:this.state.relativeRange,onChange:function(t){return e.setRelativeInterval(t.target.value)},children:[Object(se.jsx)(ue.a,{value:"absolute",className:t.customRange,children:this.props.t("custom range")},"custom"),Object(se.jsx)(ue.a,{value:10,children:this.props.t("last 10 minutes")},"1"),Object(se.jsx)(ue.a,{value:30,children:this.props.t("last 30 minutes")},"2"),Object(se.jsx)(ue.a,{value:60,children:this.props.t("last hour")},"3"),Object(se.jsx)(ue.a,{value:"day",children:this.props.t("this day")},"4"),Object(se.jsx)(ue.a,{value:1440,children:this.props.t("last 24 hours")},"5"),Object(se.jsx)(ue.a,{value:"week",children:this.props.t("this week")},"6"),Object(se.jsx)(ue.a,{value:10080,children:this.props.t("last week")},"7"),Object(se.jsx)(ue.a,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),Object(se.jsx)(ue.a,{value:20160,children:this.props.t("last 2 weeks")},"9"),Object(se.jsx)(ue.a,{value:"month",children:this.props.t("this month")},"10"),Object(se.jsx)(ue.a,{value:43200,children:this.props.t("last 30 days")},"11"),Object(se.jsx)(ue.a,{value:"year",children:this.props.t("this year")},"12"),Object(se.jsx)(ue.a,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),Object(se.jsxs)(ie.a,{utils:ye.a,locale:nt[this.props.lang],children:[Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{className:t.toolbarDate,disabled:"absolute"!==this.state.relativeRange,disableToolbar:!0,variant:"inline",margin:"normal",format:this.state.dateFormat,label:this.props.t("Start date"),value:new Date(this.state.min),onChange:function(t){return e.setStartDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("Start time"),value:new Date(this.state.min),onChange:function(t){return e.setStartDate(t)}})]}),Object(se.jsxs)("div",{className:t.toolbarTimeGrid,children:[Object(se.jsx)(re.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarDate,disableToolbar:!0,format:this.state.dateFormat,variant:"inline",margin:"normal",label:this.props.t("End date"),value:new Date(this.state.max),onChange:function(t){return e.setEndDate(t)}}),Object(se.jsx)(le.a,{disabled:"absolute"!==this.state.relativeRange,className:t.toolbarTime,margin:"normal",ampm:!1,label:this.props.t("End time"),value:new Date(this.state.max),onChange:function(t){return e.setEndDate(t)}})]})]}),Object(se.jsx)("div",{className:t.grow}),this.props.showJumpToEchart&&this.state.echartsJump&&Object(se.jsx)(Be.a,{className:t.echartsButton,size:"small",onClick:function(){return e.openEcharts()},title:this.props.t("Open charts in new window"),children:Object(se.jsx)("img",{src:at.default,alt:"echarts",className:t.buttonIcon})}),Object(se.jsxs)(Be.a,{variant:"extended",size:"small",color:this.state.splitLine?"primary":"inherit","aria-label":"show lines",onClick:function(){window.localStorage.setItem("App.splitLine",e.state.splitLine?"false":"true"),e.setState({splitLine:!e.state.splitLine})},className:t.splitLineButton,children:[Object(se.jsx)(We.FaChartLine,{className:t.splitLineButtonIcon}),this.props.t("Show lines")]})]})}},{key:"render",value:function(){return this.state.historyInstances||this.state.defaultHistory?Object(se.jsxs)(q.a,{className:this.props.classes.paper,children:[this.renderToolbar(),Object(se.jsx)("div",{ref:this.divRef,className:Object(Y.default)(this.props.classes.chart,this.props.noToolbar?this.props.classes.chartWithoutToolbar:this.props.classes.chartWithToolbar),children:this.renderChart()})]}):Object(se.jsx)(U.a,{})}}],[{key:"getDerivedStateFromProps",value:function(e,t){return null}}]),s}(l.Component),ct=Object(r.a)()(Object(u.a)((function(e){return{paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden",width:"100%"},chart:{width:"100%",overflow:"hidden"},chartWithToolbar:{height:"calc(100% - ".concat(e.mixins.toolbar.minHeight+e.spacing(1),"px)")},chartWithoutToolbar:{height:"100%"},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:{color:e.palette.primary.main},splitLineButtonIcon:{marginRight:e.spacing(1)},splitLineButton:{float:"right"},grow:{flexGrow:1},toolbarTime:{width:100,marginTop:9,marginLeft:e.spacing(1)},toolbarDate:{width:160,marginTop:9},toolbarTimeGrid:{marginLeft:e.spacing(1),paddingLeft:e.spacing(1),paddingRight:e.spacing(1),border:"1px dotted #AAAAAA",borderRadius:e.spacing(1)},buttonIcon:{width:24,height:24},echartsButton:{marginRight:e.spacing(1),height:34,width:34}}}))(lt)),ut=s(385),dt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),n=t.call(this,e);var o=parseInt(window.localStorage.getItem("App.objectCustomTab")||0,10);if(n.chartAvailable=n.isChartAvailable(),n.chartAvailable){var i=N.a.getLocation();"chart"===i.arg?o=2:"table"===i.arg&&(o=1)}else o=0;return n.state={hasChanges:!1,currentTab:o,confirmDialog:!1,mobile:ut.b.isMobile(),progressRunning:!1},n.saveFunc=null,n}return Object(n.a)(s,[{key:"isChartAvailable",value:function(){var e=this,t=1===this.props.objectIDs.length;if(t){var s=this.props.objectIDs[0];t=!!(this.props.objects[s]&&this.props.objects[s].common&&this.props.objects[s].common.custom&&this.props.objects[s].common.custom)&&Object.keys(this.props.objects[s].common.custom).find((function(t){var s=e.props.objects["system.adapter."+t];return s&&s.common&&s.common.getHistory}))}return t}},{key:"renderCharts",value:function(){return Object(se.jsx)(ct,{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})}},{key:"renderTable",value:function(){return Object(se.jsx)(_e,{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})}},{key:"renderCustomEditor",value:function(){var e=this;return Object(se.jsx)(ne,{id:"custom-settings-tabpanel",registerSaveFunc:function(t){return e.saveFunc=t},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:function(t){return e.setState({progressRunning:t})},reportChangedIds:this.props.reportChangedIds,onChange:function(t,s){e.setState({hasChanges:t},(function(){if(s){var t=e.isChartAvailable();t!==e.chartAvailable&&(e.chartAvailable=t,e.forceUpdate())}}))},theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType})}},{key:"renderConfirmDialog",value:function(){var e=this;return this.state.confirmDialog?Object(se.jsx)(E.a,{title:F.a.t("You have unsaved changes"),text:F.a.t("Discard?"),ok:F.a.t("Yes"),cancel:F.a.t("Cancel"),onClose:function(t){return e.setState({confirmDialog:!1},(function(){return t&&e.props.onClose()}))}}):null}},{key:"onClose",value:function(){this.state.hasChanges?this.setState({confirmDialog:!0}):this.props.onClose()}},{key:"render",value:function(){var e,t,s=this,a=null===(e=this.props.objects[this.props.objectIDs[0]])||void 0===e||null===(t=e.common)||void 0===t?void 0:t.type;return Object(se.jsxs)(d.a,{classes:{scrollPaper:this.props.classes.dialog,paper:this.props.classes.paper},scroll:"paper",open:!0,onClose:function(){return s.props.onClose()},fullWidth:!0,maxWidth:"xl","aria-labelledby":"form-dialog-title",children:[this.renderConfirmDialog(),Object(se.jsx)(h.a,{children: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])}),Object(se.jsxs)(p.a,{className:this.props.classes.content,children:[Object(se.jsx)(k.a,{position:"static",children:Object(se.jsxs)(I.a,{value:this.state.currentTab,onChange:function(e,t){N.a.doNavigate(null,null,null,1===t?"table":2===t?"chart":"config"),s.setState({currentTab:t}),window.localStorage.setItem("App.objectCustomTab",t)},children:[Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("Custom settings"),id:"custom-settings-tab","aria-controls":"simple-tabpanel-0"}),1===this.props.objectIDs.length&&this.chartAvailable?Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("History data"),id:"history-data-tab","aria-controls":"simple-tabpanel-1"}):null,"number"!==a&&"boolean"!==a||1!==this.props.objectIDs.length||!this.chartAvailable?null:Object(se.jsx)(D.a,{disabled:this.state.progressRunning,label:this.props.t("Chart"),id:"chart-tab","aria-controls":"simple-tabpanel-2"})]})}),0===this.state.currentTab?Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderCustomEditor()}):null,1===this.props.objectIDs.length&&this.chartAvailable&&1===this.state.currentTab?Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderTable()}):null,"number"!==a&&"boolean"!==a||1!==this.props.objectIDs.length||!this.chartAvailable||2!==this.state.currentTab?null:Object(se.jsx)("div",{className:this.props.classes.tabPanel,children:this.renderCharts()})]}),Object(se.jsxs)(m.a,{children:[0===this.state.currentTab&&Object(se.jsx)(j.a,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:function(){return s.saveFunc&&s.saveFunc()},children:this.getButtonTitle(Object(se.jsx)(M.a,{}),this.props.t("Save"))}),0===this.state.currentTab&&Object(se.jsx)(j.a,{variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:function(){s.saveFunc?s.saveFunc((function(e){return!e&&s.onClose()})):s.onClose()},children:this.getButtonTitle(Object(se.jsx)(M.a,{}),this.props.t("Save & close"),Object(se.jsx)(O.a,{}))}),Object(se.jsx)(j.a,{disabled:this.state.progressRunning,variant:"contained",onClick:function(){return s.onClose()},children:this.getButtonTitle(Object(se.jsx)(O.a,{}),this.props.t("Close"))})]})]})}}]),s}(ut.b);dt.propTypes={t:S.a.func,lang:S.a.string,expertMode:S.a.bool,objects:S.a.object,socket:S.a.object,theme:S.a.object,themeName:S.a.string,themeType:S.a.string,customsInstances:S.a.array,objectIDs:S.a.array,onClose:S.a.func,reportChangedIds:S.a.func,isFloatComma:S.a.bool};var ht=Object(u.a)((function(e){return{dialog:{height:"100%"},paper:{height:"calc(100% - 64px)"},content:{textAlign:"center",overflow:"hidden"},tabPanel:{width:"100%",overflow:"hidden",height:"calc(100% - "+e.mixins.toolbar.minHeight+"px)"}}}))(dt),pt=s(354),mt=s.n(pt),bt=(s(534),s(535),s(536),s(537),s(538),s(1524)),jt=s(502),ft=s(767),gt=s.n(ft),vt=s(53),Ot=s.n(vt),xt=Object(u.a)((function(e){return{root:{width:28,height:16,padding:0,display:"flex"},switchBase:{padding:2,color:e.palette.grey[500],"&$checked":{transform:"translateX(12px)",color:e.palette.common.white,"& + $track":{opacity:1,backgroundColor:e.palette.primary.main,borderColor:e.palette.primary.main}}},thumb:{width:12,height:12,boxShadow:"none"},track:{border:"1px solid ".concat(e.palette.grey[500]),borderRadius:8,opacity:1,backgroundColor:e.palette.common.white},checked:{}}}))(jt.a),yt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s);var o=(n=t.call(this,e)).props.type||typeof n.props.value;if(n.value=n.props.value,n.propsValue=n.value,null===n.propsValue?n.propsValue="null":void 0===n.propsValue&&(n.propsValue="undefined"),n.props.states)o="states";else if(("string"===o||"json"===o)&&n.value&&"string"===typeof n.value&&(n.value.startsWith("[")&&n.value.endsWith("]")||n.value.startsWith("{")&&n.value.endsWith("}")))try{n.value=JSON.parse(n.value),n.value=JSON.stringify(n.value,null,2),n.propsValue=n.value,o="json"}catch(i){}return n.state={type:o,chart:!1,chartEnabled:"false"!==window.localStorage.getItem("App.chartSetValue")},n.ack=!1,n.q=0,n.expire=0,n.inputRef=c.a.createRef(),n.chartFrom=Date.now()-72e5,n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e,t,s,a=this;this.props.defaultHistory&&(null===(e=this.props.object)||void 0===e||null===(t=e.common)||void 0===t?void 0:t.custom)&&(null===(s=this.props.object.common.custom[this.props.defaultHistory])||void 0===s?void 0:s.enabled)&&this.props.socket.getState("system.adapter."+this.props.defaultHistory+".alive").then((function(e){return a.setState({chart:e&&!!e.val})})),setTimeout((function(){if(a.inputRef&&a.inputRef.current){var e=a.inputRef.current,t=e.value||"";e.setSelectionRange(0,t.length)}}),200)}},{key:"onUpdate",value:function(){if("states"===this.state.type){var e=this.props.type||typeof this.props.value;"number"===e?"string"===typeof this.value&&(this.value=parseFloat(this.value.replace(",","."))||0):"boolean"===e&&(this.value=!0===this.value||"true"===this.value||"1"===this.value||"ON"===this.value||"on"===this.value)}else"number"===this.state.type?"string"===typeof this.value&&(this.value=parseFloat(this.value.replace(",","."))||0):"boolean"===this.state.type&&(this.value=!0===this.value||"true"===this.value||"1"===this.value||"ON"===this.value||"on"===this.value);this.props.onClose({val:this.value,ack:this.ack,q:this.q,expire:parseInt(this.expire,10)||void 0})}},{key:"renderChart",value:function(){return Object(se.jsx)(ct,{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})}},{key:"checkJsonError",value:function(){try{JSON.parse(this.value),this.setState({jsonError:!1})}catch(e){this.setState({jsonError:!0})}}},{key:"renderJsonEditor",value:function(){var e=this;return Object(se.jsx)(mt.a,{className:this.state.jsonError?this.props.classes.jsonError:this.props.classes.jsonNoError,mode:"json",width:"100%",height:"200px",showPrintMargin:!0,showGutter:!0,highlightActiveLine:!0,theme:"dark"===this.props.themeType?"clouds_midnight":"chrome",defaultValue:(this.propsValue||"").toString(),onChange:function(t){e.value=t,e.checkJsonError()},name:"UNIQUE_ID_OF_DIV1",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:!0,tabSize:2},editorProps:{$blockScrolling:!0}})}},{key:"renderStates",value:function(){var e=this;return this.props.states?Object(se.jsxs)(de.a,{className:this.props.classes.formControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("Value")}),Object(se.jsx)(he.a,{defaultValue:this.propsValue,onChange:function(t){return e.value=t.target.value},children:Object.keys(this.props.states).map((function(t,s){return Object(se.jsx)(ue.a,{value:t,children:e.props.states[t]},s)}))})]}):null}},{key:"render",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!0,maxWidth:"number"===this.state.type||"boolean"===this.state.type||"states"===this.state.type?this.state.chart&&this.state.chartEnabled?"lg":null:"md",fullWidth:"number"!==this.state.type&&"boolean"!==this.state.type&&"states"!==this.state.type||this.state.chart&&this.state.chartEnabled,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",children:[Object(se.jsxs)(h.a,{id:"edit-value-dialog-title",children:[this.props.t("Write value"),this.state.chart?Object(se.jsx)(Be.a,{style:{float:"right"},size:"small",color:this.state.chartEnabled?"primary":"default",onClick:function(){window.localStorage.setItem("App.chartSetValue",e.state.chartEnabled?"false":"true"),e.setState({chartEnabled:!e.state.chartEnabled})},children:Object(se.jsx)(gt.a,{})}):null]}),Object(se.jsx)(p.a,{children:Object(se.jsx)("form",{className:this.props.classes.dialogForm,noValidate:!0,autoComplete:"off",children:Object(se.jsxs)(me.a,{container:!0,direction:"row",spacing:2,children:[Object(se.jsx)(me.a,{item:!0,xs:this.state.chart&&this.state.chartEnabled?6:12,children:Object(se.jsxs)(me.a,{container:!0,direction:"column",spacing:2,children:[this.props.expertMode?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsxs)(de.a,{className:this.props.classes.formControl,children:[Object(se.jsx)(ce.a,{children:this.props.t("Value type")}),Object(se.jsxs)(he.a,{value:this.state.type,onChange:function(t){"json"===t.target.value&&(e.value=(e.value||"").toString(),e.checkJsonError()),e.setState({type:t.target.value})},children:[Object(se.jsx)(ue.a,{value:"string",children:"String"}),Object(se.jsx)(ue.a,{value:"number",children:"Number"}),Object(se.jsx)(ue.a,{value:"boolean",children:"Boolean"}),Object(se.jsx)(ue.a,{value:"json",children:"JSON"}),this.props.states?Object(se.jsx)(ue.a,{value:"states",children:"States"}):null]})]})}):null,Object(se.jsx)(me.a,{item:!0,children:"boolean"===this.state.type?Object(se.jsx)(z.a,{component:"div",children:Object(se.jsxs)(me.a,{component:"label",container:!0,alignItems:"center",spacing:1,children:[Object(se.jsxs)(me.a,{item:!0,style:{marginRight:10},children:[this.props.t("Value"),":"]}),Object(se.jsx)(me.a,{item:!0,children:"FALSE"}),Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(xt,{autoFocus:!0,defaultChecked:!!this.propsValue,onKeyUp:function(t){return 13===t.keyCode&&e.onUpdate()},onChange:function(t){return e.value=t.target.checked}})}),Object(se.jsx)(me.a,{item:!0,children:"TRUE"})]})}):"number"===this.state.type?Object(se.jsx)(ve.a,{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:function(t){return 13===t.keyCode&&e.onUpdate()},onChange:function(t){return e.value=t.target.value}}):"json"===this.state.type?this.renderJsonEditor():"states"===this.state.type?this.renderStates():Object(se.jsx)(ve.a,{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,onKeyUp:function(t){return t.ctrlKey&&13===t.keyCode&&e.onUpdate()},defaultValue:this.propsValue.toString(),onChange:function(t){return e.value=t.target.value}})}),Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(X.a,{className:this.props.classes.formControl,control:Object(se.jsx)(G.a,{defaultChecked:!1,onChange:function(t){return e.ack=t.target.checked}}),label:this.props.t("Acknowledged")})}),this.props.expertMode?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsxs)(de.a,{className:this.props.classes.quality,children:[Object(se.jsx)(ce.a,{children:this.props.t("Quality")}),Object(se.jsxs)(he.a,{defaultValue:0,onChange:function(t){return e.q=parseInt(t.target.value,10)},children:[Object(se.jsx)(ue.a,{value:0,children:"0x00 - good"}),Object(se.jsx)(ue.a,{value:1,children:"0x01 - general problem"}),Object(se.jsx)(ue.a,{value:2,children:"0x02 - no connection problem"}),Object(se.jsx)(ue.a,{value:16,children:"0x10 - substitute value from controller"}),Object(se.jsx)(ue.a,{value:32,children:"0x20 - substitute initial value"}),Object(se.jsx)(ue.a,{value:64,children:"0x40 - substitute value from device or instance"}),Object(se.jsx)(ue.a,{value:128,children:"0x80 - substitute value from sensor"}),Object(se.jsx)(ue.a,{value:17,children:"0x11 - general problem by instance"}),Object(se.jsx)(ue.a,{value:65,children:"0x41 - general problem by device"}),Object(se.jsx)(ue.a,{value:129,children:"0x81 - general problem by sensor"}),Object(se.jsx)(ue.a,{value:18,children:"0x12 - instance not connected"}),Object(se.jsx)(ue.a,{value:66,children:"0x42 - device not connected"}),Object(se.jsx)(ue.a,{value:130,children:"0x82 - sensor not connected"}),Object(se.jsx)(ue.a,{value:68,children:"0x44 - device reports error"}),Object(se.jsx)(ue.a,{value:132,children:"0x84 - sensor reports error"})]})]}),Object(se.jsx)(ve.a,{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:function(t){return e.expire=t.target.value}})]}):null]})}),this.state.chart&&this.state.chartEnabled?Object(se.jsx)(bt.a,{only:["sm","xs"],children:Object(se.jsx)(me.a,{item:!0,xs:6,style:{minHeight:300},children:this.renderChart()})}):null]})})}),Object(se.jsxs)(m.a,{className:this.props.classes.wrapperButton,children:[Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.onUpdate()},color:"primary",startIcon:Object(se.jsx)(Ot.a,{}),children:this.props.t("Set value")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}}]),s}(l.Component),wt=Object(u.a)((function(e){return{input:{width:"100%"},textInput:{width:"100%"},formControl:{minWidth:150},quality:{width:"calc(100% - 88px)"},expire:{marginLeft:8,width:80},jsonError:{border:"1px solid red"},jsonNoError:{border:"1px solid #00000000"},wrapperButton:{},"@media screen and (max-width: 465px)":{wrapperButton:{"& *":{fontSize:12}}},"@media screen and (max-width: 380px)":{wrapperButton:{"& *":{fontSize:11}}}}}))(yt),Ct=s(17),St=s(1463),kt=s(145),It=s.n(kt),Dt=s(563),Tt=s.n(Dt),Nt=s(1888),At=s.n(Nt),Et=s(689),Rt=s.n(Et),Ft=s(219),Ht=s.n(Ft),Mt=s(282),Vt=s(1522),Wt=s(548),Jt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n,o,i,r,l;return Object(a.a)(this,s),(l=t.call(this,e)).state={text:JSON.stringify(l.props.obj,null,2),error:!1,changed:!1,readError:l.checkFunction(null===(n=l.props.obj.common)||void 0===n||null===(o=n.alias)||void 0===o?void 0:o.read,!1),writeError:l.checkFunction(null===(i=l.props.obj.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.write,!0),tab:window.localStorage.getItem((l.props.dialogName||"App")+".editTab")||"object",showCopyDialog:!1},l.isMobile=window.innerWidth<850,l.originalObj=JSON.stringify(l.props.obj,null,2),l}return Object(n.a)(s,[{key:"checkFunction",value:function(e,t){if(e){var s,a,n,o,i,r,l,c;try{l=JSON.parse(this.state.text)}catch(m){}try{c=new Function("val",e.includes("return")?e:"return "+e)}catch(m){return this.props.t("Cannot parse code!")}if((null===(s=l)||void 0===s||null===(a=s.common)||void 0===a?void 0:a.type)&&(null===(n=this.props.objects[null===(i=l.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.id])||void 0===n||null===(o=n.common)||void 0===o?void 0:o.type)){var u=t?l.common.type:this.props.objects[l.common.alias.id].common.type,d=t?this.props.objects[l.common.alias.id].common.type:l.common.type;if(u&&d){var h=null;if("boolean"===u?h=!0:"number"===u?h=1:"string"===u&&(h="string"),null!==h)try{var p=c(h);return null!==p&&typeof p!==d?this.props.t("Type of result is not as expected: %s",d):""}catch(m){return this.props.t("Cannot execute function")+": "+m.toString()}}}return""}return""}},{key:"prepareObject",value:function(e){e=e||this.state.text;try{var t,s=JSON.parse(e);return s._id=this.props.obj._id,(null===(t=s.common)||void 0===t?void 0:t.alias)&&(s.common.alias.id||delete s.common.alias.id,(!s.common.alias.read&&void 0!==s.common.alias.read||"val"===s.common.alias.read)&&delete s.common.alias.read,(!s.common.alias.write&&void 0!==s.common.alias.write||"val"===s.common.alias.write)&&delete s.common.alias.write,s.common.alias.id||s.common.alias.read||s.common.alias.write||delete s.common.alias),s}catch(a){return null}}},{key:"onChange",value:function(e,t){var s,a,n,o,i={text:e},r=this.prepareObject(e);r?(i.changed=this.originalObj!==JSON.stringify(r,null,2),this.state.error&&(i.error=!1),i.readError=this.checkFunction(null===(s=r.common)||void 0===s||null===(a=s.alias)||void 0===a?void 0:a.read,!1),i.writeError=this.checkFunction(null===(n=r.common)||void 0===n||null===(o=n.alias)||void 0===o?void 0:o.write,!0)):i.error=!0;this.setState(i,(function(){return t&&t()}))}},{key:"onUpdate",value:function(){var e,t=JSON.parse(this.state.text);t._id=this.props.obj._id,(null===(e=t.common)||void 0===e?void 0:e.alias)&&(t.common.alias.id||delete t.common.alias.id,(!t.common.alias.read&&void 0!==t.common.alias.read||"val"===t.common.alias.read)&&delete t.common.alias.read,(!t.common.alias.write&&void 0!==t.common.alias.write||"val"===t.common.alias.write)&&delete t.common.alias.write,t.common.alias.id||t.common.alias.read||t.common.alias.write||delete t.common.alias),this.props.onClose(t)}},{key:"renderTabs",value:function(){var e=this;return Object(se.jsxs)(I.a,{className:this.props.classes.tabsPadding,value:this.state.tab,onChange:function(t,s){window.localStorage.setItem((e.props.dialogName||"App")+".editTab",s),e.setState({tab:s})},children:[Object(se.jsx)(D.a,{value:"common",label:this.props.t("Common")}),Object(se.jsx)(D.a,{value:"object",label:this.props.t("Object data")}),this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type&&Object(se.jsx)(D.a,{value:"alias",label:this.props.t("Alias")})]})}},{key:"renderSelectDialog",value:function(){var e=this;if(!this.state.selectId&&!this.state.selectRead&&!this.state.selectWrite)return null;var t,s,a,n=JSON.parse(this.state.text);if(this.state.selectId)t=(null===(s=n.common)||void 0===s||null===(a=s.alias)||void 0===a?void 0:a.id)||"";else if(this.state.selectRead){var o,i,r;t=(null===(o=n.common)||void 0===o||null===(i=o.alias)||void 0===i||null===(r=i.id)||void 0===r?void 0:r.read)||""}else if(this.state.selectWrite){var l,c,u;t=(null===(l=n.common)||void 0===l||null===(c=l.alias)||void 0===c||null===(u=c.id)||void 0===u?void 0:u.write)||""}return Object(se.jsx)(Rt.a,{imagePrefix:".",dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,socket:this.props.socket,dialogName:"aliasesEdit",title:"".concat(this.props.t("Select for")," ").concat(this.props.obj._id),selected:t,statesOnly:!0,onOk:function(t){var s=e.state.selectRead,a=e.state.selectWrite,o=e.state.selectId;e.setState({selectId:!1,selectRead:!1,selectWrite:!1},(function(){s?e.setAliasItem(n,"id.read",t):a?e.setAliasItem(n,"id.write",t):o&&e.setAliasItem(n,"id",t)}))},onClose:function(){return e.setState({selectId:!1,selectRead:!1,selectWrite:!1})}},"selectDialog")}},{key:"setAliasItem",value:function(e,t,s,a){e.common=e.common||{},e.common.alias=e.common.alias||{},"id.read"===t?e.common.alias.id&&"object"===typeof e.common.alias.id?e.common.alias.id.read=s:e.common.alias.id={read:s,write:s}:"id.write"===t?e.common.alias.id&&"object"===typeof e.common.alias.id?e.common.alias.id.write=s:e.common.alias.id={read:s,write:s}:e.common.alias[t]=s,this.onChange(JSON.stringify(e,null,2),a)}},{key:"setCommonItem",value:function(e,t,s){e.common[t]=s,this.onChange(JSON.stringify(e,null,2))}},{key:"removeCommonItem",value:function(e,t){delete e.common[t],this.onChange(JSON.stringify(e,null,2))}},{key:"buttonAddKey",value:function(e,t){var s=this.props,a=s.t,n=s.classes;return Object(se.jsx)("div",{className:n.marginBlock,children:Object(se.jsx)(j.a,{className:n.buttonAdd,variant:"contained",color:"secondary",startIcon:Object(se.jsx)(It.a,{}),onClick:t,children:a("add %s",e)})})}},{key:"buttonRemoveKey",value:function(e,t){var s=this.props,a=s.t,n=s.classes;return Object(se.jsx)(Mt.a,{title:a("Remove %s",e),children:Object(se.jsx)("div",{className:n.close,onClick:t})})}},{key:"renderCommonEdit",value:function(){var e=this;try{var t=JSON.parse(this.state.text),s=!1,a=this.props,n=a.classes,o=a.t,i=a.roleArray,r=a.obj,l="state"===r.type,c="channel"===r.type||"device"===r.type||l;return Object(se.jsxs)("div",{className:n.commonTabWrapper,children:[Object(se.jsxs)("div",{className:n.commonWrapper,children:["undefined"!==typeof t.common.name?Object(se.jsx)(ve.a,{disabled:s,label:o("Name"),className:Object(Y.default)(n.marginBlock,n.textField),fullWidth:!0,value:He.a.getObjectNameFromObj(t,F.a.getLanguage()),onChange:function(s){return e.setCommonItem(t,"name",s.target.value)}}):this.buttonAddKey("name",(function(){return e.setCommonItem(t,"name","")})),l?"undefined"!==typeof t.common.type?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsxs)(de.a,{className:n.marginBlock,fullWidth:!0,children:[Object(se.jsx)(ce.a,{children:o("State type")}),Object(se.jsx)(he.a,{disabled:s,value:t.common.type,onChange:function(s){return e.setCommonItem(t,"type",s.target.value)},children:["boolean","json","string","number","multistate","file","object","mixed"].map((function(e){return Object(se.jsx)(ue.a,{value:e,children:o(e)},e)}))})]}),this.buttonRemoveKey("type",(function(){return e.removeCommonItem(t,"type")}))]}):this.buttonAddKey("type",(function(){return e.setCommonItem(t,"type","string")})):null,c?"undefined"!==typeof t.common.role?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsx)(Vt.a,{className:n.marginBlock,fullWidth:!0,disabled:s,value:t.common.role,getOptionSelected:function(e,t){return e.name===t.name},onChange:function(s,a){return e.setCommonItem(t,"role",a)},options:i,renderInput:function(e){return Object(se.jsx)(ve.a,Object(Ct.a)(Object(Ct.a)({},e),{},{label:o("Role")}))}}),this.buttonRemoveKey("role",(function(){return e.removeCommonItem(t,"role")}))]}):this.buttonAddKey("role",(function(){return e.setCommonItem(t,"role","")})):null,"undefined"!==typeof t.common.color?Object(se.jsxs)("div",{className:n.flex,children:[Object(se.jsx)(ve.a,{disabled:s,className:Object(Y.default)(n.marginBlock,n.color),label:o("Color"),type:"color",value:t.common.color,onChange:function(s){return e.setCommonItem(t,"color",s.target.value)}}),this.buttonRemoveKey("color",(function(){return e.removeCommonItem(t,"color")}))]}):this.buttonAddKey("color",(function(){return e.setCommonItem(t,"color","")}))]}),"undefined"!==typeof t.common.icon?Object(se.jsxs)("div",{className:n.flexDrop,children:[Object(se.jsx)(Wt.a,{disabled:s,maxSize:10240,icon:t.common.icon,removeIconFunc:function(){return e.setCommonItem(t,"icon","")},onChange:function(s){return e.setCommonItem(t,"icon",s)},t:o}),this.buttonRemoveKey("icon",(function(){return e.removeCommonItem(t,"icon")}))]}):Object(se.jsx)("div",{className:n.flexDrop,children:this.buttonAddKey("icon",(function(){return e.setCommonItem(t,"icon","")}))})]})}catch(u){return Object(se.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}},{key:"renderAliasEdit",value:function(){var e=this;try{var t,s,a,n,o,i,r,l,c,u,d,h,p,m,b,j,g,v,x,y,w,C,S,k,I,D,T,N,A,E,R,F,H,M,V,W,J=JSON.parse(this.state.text),L=void 0!==(null===(t=J.common)||void 0===t||null===(s=t.alias)||void 0===s?void 0:s.read);return Object(se.jsxs)(me.a,{container:!0,direction:"column",className:this.props.classes.marginTop,children:[Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:"object"===typeof(null===(a=J.common)||void 0===a||null===(n=a.alias)||void 0===n?void 0:n.id),onChange:function(){var t,s,a,n,o,i,r;"object"===typeof(null===(t=J.common)||void 0===t||null===(s=t.alias)||void 0===s?void 0:s.id)?e.setAliasItem(J,"id",(null===(a=J.common)||void 0===a||null===(n=a.alias)||void 0===n||null===(o=n.id)||void 0===o?void 0:o.read)||""):e.setAliasItem(J,"id.read",(null===(i=J.common)||void 0===i||null===(r=i.alias)||void 0===r?void 0:r.id)||"")}}),label:this.props.t("Different IDs for read and write")})}),"object"!==typeof(null===(o=J.common)||void 0===o||null===(i=o.alias)||void 0===i?void 0:i.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias state"),value:(null===(r=J.common)||void 0===r||null===(l=r.alias)||void 0===l?void 0:l.id)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(c=J.common)||void 0===c||null===(u=c.alias)||void 0===u?void 0:u.id)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!0,selectRead:!1,selectWrite:!1})},children:"..."})]}):null,"object"===typeof(null===(d=J.common)||void 0===d||null===(h=d.alias)||void 0===h?void 0:h.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias read state"),value:(null===(p=J.common)||void 0===p||null===(m=p.alias)||void 0===m||null===(b=m.id)||void 0===b?void 0:b.read)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(j=J.common)||void 0===j||null===(g=j.alias)||void 0===g||null===(v=g.id)||void 0===v?void 0:v.read)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id.read","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id.read",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!1,selectRead:!0,selectWrite:!1})},children:"..."})]}):null,"object"===typeof(null===(x=J.common)||void 0===x||null===(y=x.alias)||void 0===y?void 0:y.id)?Object(se.jsxs)(me.a,{item:!0,children:[Object(se.jsx)(ve.a,{label:this.props.t("Alias write state"),value:(null===(w=J.common)||void 0===w||null===(C=w.alias)||void 0===C||null===(S=C.id)||void 0===S?void 0:S.write)||"",className:this.props.classes.aliasIdEdit,InputProps:{endAdornment:(null===(k=J.common)||void 0===k||null===(I=k.alias)||void 0===I||null===(D=I.id)||void 0===D?void 0:D.write)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"id.write","")},children:Object(se.jsx)(O.a,{})})}):null},onChange:function(t){return e.setAliasItem(J,"id.write",t.target.value)},margin:"normal"}),Object(se.jsx)(Be.a,{className:this.props.classes.button,size:"small",onClick:function(){return e.setState({selectId:!1,selectRead:!1,selectWrite:!0})},children:"..."})]}):null,Object(se.jsx)(me.a,{item:!0,className:this.props.classes.marginTop,children:Object(se.jsx)(X.a,{control:Object(se.jsx)(G.a,{checked:void 0!==(null===(T=J.common)||void 0===T||null===(N=T.alias)||void 0===N?void 0:N.read),onChange:function(){L?(delete J.common.alias.read,delete J.common.alias.write):(J.common=J.common||{},J.common.alias=J.common.alias||{},J.common.alias.read="val",J.common.alias.write="val"),e.onChange(JSON.stringify(J,null,2))}}),label:this.props.t("Use convert functions")})}),L?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(ve.a,{label:this.props.t("Read converter"),value:(null===(A=J.common)||void 0===A||null===(E=A.alias)||void 0===E?void 0:E.read)||"",className:this.props.classes.funcEdit,error:!!this.state.readError,InputProps:{endAdornment:(null===(R=J.common)||void 0===R||null===(F=R.alias)||void 0===F?void 0:F.read)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"read","")},children:Object(se.jsx)(O.a,{})})}):null,startAdornment:Object(se.jsx)(St.a,{position:"start",children:Object(se.jsx)(At.a,{className:this.props.classes.funcIcon})})},onChange:function(t){return e.setAliasItem(J,"read",t.target.value)},helperText:this.state.readError||this.props.t("JS function like")+' "val / 5 + 21"',margin:"normal"})}):null,L?Object(se.jsx)(me.a,{item:!0,children:Object(se.jsx)(ve.a,{label:this.props.t("Write converter"),error:!!this.state.writeError,value:(null===(H=J.common)||void 0===H||null===(M=H.alias)||void 0===M?void 0:M.write)||"",helperText:this.state.writeError||this.props.t("JS function like")+' "(val - 21) * 5"',className:this.props.classes.funcEdit,InputProps:{endAdornment:(null===(V=J.common)||void 0===V||null===(W=V.alias)||void 0===W?void 0:W.write)?Object(se.jsx)(St.a,{position:"end",children:Object(se.jsx)(f.a,{onClick:function(){return e.setAliasItem(J,"write","")},children:Object(se.jsx)(O.a,{})})}):null,startAdornment:Object(se.jsx)(St.a,{position:"start",children:Object(se.jsx)(At.a,{className:this.props.classes.funcIcon})})},onChange:function(t){return e.setAliasItem(J,"write",t.target.value)},margin:"normal"})}):null]})}catch(Y){return Object(se.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}},{key:"onCopy",value:function(e){e.stopPropagation(),e.preventDefault(),Ht()(this.state.text),window.alert(this.props.t("ra_Copied"))}},{key:"onClone",value:function(e,t,s){var a=JSON.parse(JSON.stringify(this.props.objects[e]));delete a.from,delete a.ts,delete a.user,a._id=t,this.props.objects[a._id]=a,this.props.onNewObject(a)}},{key:"renderCopyDialog",value:function(){var e=this;return this.state.showCopyDialog?Object(se.jsxs)(d.a,{open:!0,maxWidth:"md",fullWidth:!0,onClose:function(){return e.setState({showCopyDialog:!1})},children:[Object(se.jsx)(h.a,{children:this.props.t("Enter new ID for this object")}),Object(se.jsx)(p.a,{children:Object(se.jsx)(ve.a,{autoFocus:!0,fullWidth:!0,label:this.props.t("New object ID"),value:this.state.newId,onKeyDown:function(t){13!==t.keyCode||e.props.objects[e.state.newId]||(e.setState({showCopyDialog:""}),e.onClone(e.state.showCopyDialog,e.state.newId))},onChange:function(t){return e.setState({newId:t.target.value})}})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{disabled:!!this.props.objects[this.state.newId],onClick:function(){e.setState({showCopyDialog:""}),e.onClone(e.state.showCopyDialog,e.state.newId)},color:"primary",startIcon:Object(se.jsx)(Tt.a,{}),children:this.props.t("Clone")}),Object(se.jsx)(j.a,{onClick:function(){return e.setState({showCopyDialog:""})},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]}):null}},{key:"render",value:function(){var e=this,t=this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type;return Object(se.jsxs)(d.a,{classes:{paper:this.props.classes.dialog},open:!0,maxWidth:"lg",fullWidth:"number"!==this.state.type&&"boolean"!==this.state.type,fullScreen:!1,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",children:[Object(se.jsxs)(h.a,{id:"edit-value-dialog-title",children:[this.props.t("Edit object:")," ",Object(se.jsx)("span",{className:this.props.classes.id,children:this.props.obj._id})]}),this.renderTabs(),this.renderCopyDialog(),Object(se.jsxs)(p.a,{children:["object"===this.state.tab?Object(se.jsx)("div",{className:Object(Y.default)(this.props.classes.divWithoutTitle,t&&this.props.classes.divWithoutTitleAndTab,this.state.error&&this.props.classes.error),children:Object(se.jsx)(mt.a,{mode:"json",width:"100%",height:"100%",theme:"dark"===this.props.themeName?"clouds_midnight":"chrome",value:this.state.text,onChange:function(t){return e.onChange(t)},name:"UNIQUE_ID_OF_DIV",fontSize:14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0},editorProps:{$blockScrolling:!0}})}):null,"alias"===this.state.tab&&this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type?this.renderAliasEdit():null,"common"===this.state.tab?this.renderCommonEdit():null,this.renderSelectDialog()]}),Object(se.jsxs)(m.a,{className:this.props.classes.wrapperButton,children:[Object(se.jsx)(j.a,{onClick:function(){return e.setState({showCopyDialog:e.props.obj._id,newId:e.props.obj._id})},disabled:this.state.error||this.state.changed,title:this.props.t("Create a copy of this object"),children:Object(se.jsx)(Tt.a,{})}),Object(se.jsx)("div",{style:{flexGrow:1}}),"object"===this.state.tab&&Object(se.jsx)(j.a,{onClick:function(t){return e.onCopy(t)},disabled:this.state.error,title:this.isMobile?this.props.t("Copy into clipboard"):"",startIcon:Object(se.jsx)(We.FaClipboard,{}),children:this.isMobile?null:this.props.t("Copy into clipboard")}),Object(se.jsx)(j.a,{variant:"contained",disabled:this.state.error||!this.state.changed,onClick:function(){return e.onUpdate()},startIcon:Object(se.jsx)(Ot.a,{}),color:"primary",children:this.props.t("Write")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]})}}]),s}(l.Component),Lt=Object(u.a)((function(e){return{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:368},button:{marginTop:20,marginLeft:e.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"},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}}}}}))(Jt),Yt=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).state={role:null,initRole:null,roleInput:null},n}return Object(n.a)(s,[{key:"componentDidMount",value:function(){var e=this;this.props.socket.getObject(this.props.id).then((function(t){var s;e.object=t;var a=(null===t||void 0===t||null===(s=t.common)||void 0===s?void 0:s.role)||null;e.setState({role:a,initRole:a,roleInput:a})})).catch((function(e){return console.error(e)}))}},{key:"onUpdate",value:function(){var e=this;this.object.common=this.object.common||{},this.object.common.role=this.state.roleInput,this.props.socket.setObject(this.object._id,this.object).then((function(){return e.props.onClose(e.object)}))}},{key:"render",value:function(){var e=this;return Object(se.jsxs)(d.a,{open:!0,maxWidth:"sm",fullWidth:!0,onClose:function(){return e.props.onClose()},"aria-labelledby":"edit-role-dialog-title","aria-describedby":"edit-role-dialog-description",children:[Object(se.jsx)(h.a,{id:"edit-role-dialog-title",children:this.object?this.props.t("Update role for %s",this.object._id):null}),Object(se.jsx)(p.a,{children:Object(se.jsx)(Vt.a,{freeSolo:!0,options:this.props.roles,style:{width:"100%"},value:this.state.role,onChange:function(t,s){return e.setState({role:s,roleInput:s})},onInputChange:function(t,s){return e.setState({roleInput:s})},renderInput:function(t){return Object(se.jsx)(ve.a,Object(Ct.a)(Object(Ct.a)({},t),{},{label:e.props.t("Role"),variant:"outlined"}))}})}),Object(se.jsxs)(m.a,{children:[Object(se.jsx)(j.a,{disabled:this.state.initRole===this.state.roleInput,variant:"contained",onClick:function(){return e.onUpdate()},color:"primary",startIcon:Object(se.jsx)(Ot.a,{}),children:this.props.t("Apply")}),Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.props.onClose()},color:"default",startIcon:Object(se.jsx)(O.a,{}),children:this.props.t("Cancel")})]})]},"objectBrowserEditRole")}}]),s}(l.Component),Ut=Object(u.a)((function(e){return{input:{marginBottom:e.spacing(2)},inputText:{width:400,height:300,marginBottom:e.spacing(2)},formControl:{marginBottom:e.spacing(2),minWidth:150},quality:{width:"100%"}}}))(Yt),_t=s(28),Pt=s(1889),Bt=s.n(Pt),zt=s(166),qt=s(349),Xt=["boolean","string","number","array","json","object","mixed"],Gt={boolean:!1,string:"",number:0},Kt={name:"Datapoint",value:"state"},$t={name:"Channel",value:"channel"},Qt={name:"Device",value:"device"},Zt={name:"Folder",value:"folder"},es=function(e){var t,s=e.onClose,a=e.onApply,n=e.open,o=e.selected,i=e.setObject,r=e.objects,c=e.expertMode,u={state:F.a.t("New state"),channel:F.a.t("New channel"),device:F.a.t("New device"),folder:F.a.t("New folder")},d=[],h=null===(t=r[o])||void 0===t?void 0:t.type,p="";r[o]?"channel"===h?(d.push(Kt),p="state"):"device"===h?(p="channel",d.push(Kt),d.push($t)):"state"===h?p="":(d.push(Kt),d.push($t),d.push(Qt),o.startsWith("0_userdata.")||o.startsWith("alias.0.")||"0_userdata"===o||"alias.0"===o?(d.push(Zt),p="folder"):p="state"):(d.push(Zt),p="folder",c&&(o.startsWith("mqtt.")||o.startsWith("javascript."))&&(d.push(Kt),d.push($t),d.push(Qt)));var m=Object(l.useState)(u[p]),b=Object(_t.a)(m,2),j=b[0],f=b[1],g=Object(l.useState)(p),v=Object(_t.a)(g,2),O=v[0],x=v[1],y=Object(l.useState)("string"),w=Object(_t.a)(y,2),C=w[0],S=w[1],k=Object(l.useState)(!r[N(u.state)]),I=Object(_t.a)(k,2),D=I[0],T=I[1];function N(e){return e.toString().replace(zt.a.FORBIDDEN_CHARS,"_").replace(/\s/g,"_").replace(/\./g,"_")}var A=function(){var e={common:{name:j,desc:F.a.t("Manually created")},type:O};"state"===O?e.common=Object(Ct.a)(Object(Ct.a)({},e.common),{},{role:"state",type:C,read:!0,write:!0,def:Gt[C]}):"folder"!==O?e.common=Object(Ct.a)(Object(Ct.a)({},e.common),{},{role:"",icon:""}):delete e.common.desc,i("".concat(o,".").concat(j.split(" ").join("_")),e).then((function(){return a()}))};return Object(se.jsx)(qt.a,{open:n,fullWidth:!0,maxWidth:"lg",titleButtonApply:"add",applyDisabled:!j||!D||!d.length,onClose:s,onApply:function(){return A()},children:Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[Object(se.jsxs)("div",{style:{margin:10,fontSize:20},children:[Object(se.jsx)(Bt.a,{})," ",F.a.t("Add new object:")," ",Object(se.jsxs)("span",{style:{fontStyle:"italic"},children:[o,".",j]})]}),Object(se.jsx)(ve.a,{label:F.a.t("Parent"),style:{margin:"5px 0"},disabled:!0,value:o}),Object(se.jsxs)(de.a,{style:{marginTop:10,marginBottom:10},children:[Object(se.jsx)(ce.a,{children:F.a.t("Type")}),Object(se.jsx)(he.a,{value:O,onChange:function(e){j===u[O]&&(f(u[e.target.value]),T(r[N(u[e.target.value])])),x(e.target.value)},children:d.map((function(e){return Object(se.jsx)(ue.a,{value:e.value,children:F.a.t(e.name)},e.value)}))})]})," ","state"===O&&Object(se.jsxs)(de.a,{children:[Object(se.jsx)(ce.a,{children:F.a.t("State type")}),Object(se.jsx)(he.a,{value:C,onChange:function(e){return S(e.target.value)},children:Xt.map((function(e){return Object(se.jsx)(ue.a,{value:e,children:e},e)}))})]}),Object(se.jsx)(ve.a,{label:F.a.t("Name"),style:{margin:"5px 0"},autoFocus:!0,value:j,onKeyDown:function(e){13===e.keyCode&&(e.preventDefault(),j&&A())},onChange:function(e){T(!r[N(e.target.value)]),f(e.target.value)}})]})})},ts=s(81),ss=s.n(ts),as=[{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"}]}],ns=function(e,t,s){return e|=t&s,e&=t|65535&~s},os=function(e){var t=e.value,s=e.disabled,a=e.setValue,n=e.t,o=e.differentValues,i=e.applyToChildren,r=e.mask,c=e.setMask;Object(l.useEffect)((function(){if(i){for(var e=0,s=0;s<o.length;s++)e|=t^o[s];c(e)}else c(0)}),[o,i]);var u=t;return Object(se.jsx)("div",{style:{display:"flex",width:"fit-content",margin:20,border:"1px solid",borderLeft:0},children:as.map((function(e){var o=Object.keys(e)[0];return Object(se.jsxs)("div",{style:{width:150,height:150,display:"flex",flexDirection:"column",alignItems:"center",borderLeft:"1px solid"},children:[Object(se.jsx)("div",{style:{height:50,display:"flex",alignItems:"center",fontSize:18,borderBottom:"1px solid silver",width:"100%",justifyContent:"center"},children:n(o)}),Object(se.jsx)("div",{style:{display:"flex",width:"100%"},children:e[o].map((function(e,o){var i=!1;return u-e.valueNum>=0&&(u-=e.valueNum,i=!0),Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",borderRight:0===o?"1px solid":0},children:[Object(se.jsx)("div",{style:{height:50,borderBottom:"1px solid",width:"100%",justifyContent:"center",display:"flex",alignItems:"center",color:"silver"},children:n(e.name)}),Object(se.jsx)("div",{style:{height:50,display:"flex"},children:Object(se.jsx)(G.a,{disabled:s,checked:i,color:r&e.valueNum?"primary":"secondary",indeterminate:!!(r&e.valueNum),style:r&e.valueNum?{opacity:.5}:null,onChange:function(s){r&e.valueNum&&(r&=65535&~e.valueNum,c(r));var n=t;s.target.checked?n|=e.valueNum:n&=65535&~e.valueNum,a(n)}})})]},e.valueNum)}))})]},o)}))})},is=function(e){var t=e.onClose,s=e.onApply,a=e.open,n=e.selected,o=e.extendObject,i=e.objects,r=e.t,c=e.modalEmptyId,u=e.themeType,d=Object(l.useState)(null),h=Object(_t.a)(d,2),p=h[0],m=h[1],b=Object(l.useState)(null),j=Object(_t.a)(b,2),f=j[0],g=j[1],v=Object(l.useState)([]),O=Object(_t.a)(v,2),x=O[0],y=O[1],w=Object(l.useState)([]),C=Object(_t.a)(w,2),S=C[0],k=C[1],I=Object(l.useState)(!1),D=Object(_t.a)(I,2),T=D[0],N=D[1],A=Object(l.useState)(!1),E=Object(_t.a)(A,2),R=E[0],H=E[1],M=Object(l.useState)(0),V=Object(_t.a)(M,2),Y=V[0],_=V[1],P=Object(l.useState)(null),B=Object(_t.a)(P,2),z=B[0],q=B[1],X=Object(l.useState)(null),G=Object(_t.a)(X,2),K=G[0],$=G[1],Q=Object(l.useState)(!1),Z=Object(_t.a)(Q,2),ee=Z[0],te=Z[1],ae=Object(l.useState)(!1),ne=Object(_t.a)(ae,2),oe=ne[0],ie=ne[1],re=Object(l.useState)([]),le=Object(_t.a)(re,2),pe=le[0],me=le[1],be=Object(l.useState)([]),je=Object(_t.a)(be,2),fe=je[0],ge=je[1],ve=Object(l.useState)(0),Oe=Object(_t.a)(ve,2),xe=Oe[0],ye=Oe[1],we=Object(l.useState)(0),Ce=Object(_t.a)(we,2),Se=Ce[0],ke=Ce[1],Ie=Object(l.useState)([]),De=Object(_t.a)(Ie,2),Te=De[0],Ne=De[1],Ae=Object(l.useState)(!1),Ee=Object(_t.a)(Ae,2),Re=Ee[0],Fe=Ee[1],He=Object(l.useState)(!0),Me=Object(_t.a)(He,2),Ve=Me[0],We=Me[1],Je=r("different");return Object(l.useEffect)((function(){for(var e=0,t=[],s=[],a=n||c,o=a+".",r=Object.keys(i).sort(),l=!1,u=[],d=[],h=F.a.getLanguage(),p=!1,b=!1,j=null,f=null,v=null,O=null,x=[],w=0;w<r.length;w++){var C,S,I=r[w],D=i[I];if(D&&(I===a||I.startsWith(o))){if(e++,x.push(I),!D.acl)continue;null===v&&void 0!==D.acl.object&&(v=D.acl.object),null===O&&void 0!==D.acl.state&&(O=D.acl.state),null===j&&void 0!==D.acl.owner&&(j=D.acl.owner),null===f&&void 0!==D.acl.ownerGroup&&(f=D.acl.ownerGroup),ee||j===D.acl.owner||void 0===D.acl.owner||(p=!0),oe||f===D.acl.ownerGroup||void 0===D.acl.ownerGroup||(b=!0),void 0===D.acl.state||O===D.acl.state||t.includes(D.acl.state)||t.push(D.acl.state),void 0===D.acl.object||v===D.acl.object||s.includes(D.acl.object)||s.push(D.acl.object),"state"===D.type&&(l=!0)}if(I.startsWith("system.group.")&&"group"===(null===D||void 0===D?void 0:D.type))u.push({name:zt.a.getObjectNameFromObj(D,h).replace("system.group.",""),value:I,icon:null===(C=D.common)||void 0===C?void 0:C.icon,color:null===(S=D.common)||void 0===S?void 0:S.color});else if(I.startsWith("system.user.")&&"user"===(null===D||void 0===D?void 0:D.type)){var T,A;d.push({name:zt.a.getObjectNameFromObj(D,h).replace("system.user.",""),value:I,icon:null===(T=D.common)||void 0===T?void 0:T.icon,color:null===(A=D.common)||void 0===A?void 0:A.color})}}j=j||i["system.config"].common.defaultNewAcl.owner,f=f||i["system.config"].common.defaultNewAcl.ownerGroup,v=v||i["system.config"].common.defaultNewAcl.object,q(isNaN(v)?i["system.config"].common.defaultNewAcl.object:v),l&&(O=O||i["system.config"].common.defaultNewAcl.state,$(isNaN(O)?i["system.config"].common.defaultNewAcl.state:O));var E=d.find((function(e){return e.value===j})),R=u.find((function(e){return e.value===f}));m(E),g(R),te(p),ie(b),y(d),k(u),l&&H(!0),c&&N(!0),_(e),me(t),ge(s),Ne(x)}),[i,n]),Object(l.useEffect)((function(){T?(oe&&("different"!==f.value&&g({name:Je,value:"different"}),S.find((function(e){return"different"===e.value}))||k((function(e){return[{name:Je,value:"different"}].concat(Object(L.a)(e))}))),ee&&("different"!==p.value&&m({name:Je,value:"different"}),x.find((function(e){return"different"===e.value}))||y((function(e){return[{name:Je,value:"different"}].concat(Object(L.a)(e))})))):(p&&"different"===p.value&&m(i[n].acl.owner),f&&"different"===f.value&&g(i[n].acl.ownerGroup),k((function(e){return e.filter((function(e){return"different"!==e.value}))})),y((function(e){return e.filter((function(e){return"different"!==e.value}))})))}),[T,ee,oe]),Te.length?Object(se.jsx)(qt.a,{open:a,titleButtonApply:"apply",overflowHidden:!0,applyDisabled:Ve,progress:Re,onClose:t,onApply:function(){Fe(!0),setTimeout(Object(J.a)(W.a.mark((function e(){var t,a,r,l,c,u,d;return W.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(T){e.next=9;break}(t=JSON.parse(JSON.stringify(i[n].acl||{}))).object=z,t.owner=p.value,t.ownerGroup=f.value,"state"===i[n].type&&(t.state=K),o(n,{acl:t}),e.next=25;break;case 9:a=65535&~xe,r=65535&~Se,l=0;case 12:if(!(l<Te.length)){e.next=25;break}return c=Te[l],u=i[c],(d=JSON.parse(JSON.stringify(u.acl||{}))).object=ns(u.acl.object,z,a),"different"!==p.value&&(d.owner=p.value),"different"!==f.value&&(d.ownerGroup=f.value),"state"===u.type&&(d.state=ns(u.acl.state,K,r)),e.next=22,o(c,{acl:d});case 22:l++,e.next=12;break;case 25:Fe(!1),s();case 27:case"end":return e.stop()}}),e)}))),200)},children:Object(se.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[Object(se.jsx)("div",{style:{margin:10,fontSize:20},children:r("Access control list: %s",n||c)}),Object(se.jsxs)("div",{style:{display:"flex"},children:[Object(se.jsxs)(de.a,{fullWidth:!0,style:{marginRight:10},children:[Object(se.jsx)(ce.a,{children:r("Owner user")}),Object(se.jsx)(he.a,{disabled:Re,value:p.value,renderValue:function(e){return Object(se.jsxs)("span",{children:[p.icon?Object(se.jsx)(ss.a,{src:p.icon,style:{width:16,height:16,marginRight:8}}):null,p.name]})},style:"different"===p.value?{opacity:.5}:{color:p.color||void 0,backgroundColor:zt.a.getInvertedColor(p.color,u)},onChange:function(e){var t=x.find((function(t){return t.value===e.target.value}));m(t),We(!1)},children:x.map((function(e){return Object(se.jsxs)(ue.a,{style:"different"===e.value?{opacity:.5}:{color:e.color||void 0,backgroundColor:zt.a.getInvertedColor(e.color,u)},value:e.value,children:[e.icon?Object(se.jsx)(ss.a,{src:e.icon,style:{width:16,height:16,marginRight:8}}):null,e.name]},e.value)}))})]}),Object(se.jsxs)(de.a,{fullWidth:!0,children:[Object(se.jsx)(ce.a,{children:r("Owner group")}),Object(se.jsx)(he.a,{disabled:Re,value:f.value,renderValue:function(e){return Object(se.jsxs)("span",{children:[f.icon?Object(se.jsx)(ss.a,{src:f.icon,style:{width:16,height:16,marginRight:8}}):null,f.name]})},style:"different"===f.value?{opacity:.5}:{color:f.color||void 0,backgroundColor:zt.a.getInvertedColor(f.color,u)},onChange:function(e){var t=S.find((function(t){return t.value===e.target.value}));g(t),We(!1)},children:S.map((function(e){return Object(se.jsxs)(ue.a,{value:e.value,style:"different"===e.value?{opacity:.5}:{color:e.color||void 0,backgroundColor:zt.a.getInvertedColor(e.color,u)},children:[e.icon?Object(se.jsx)(ss.a,{src:e.icon,style:{width:16,height:16,marginRight:8}}):null,e.name]},e.value)}))})]})]}),Object(se.jsxs)("div",{style:{display:"flex",margin:10,alignItems:"center",fontSize:10,marginLeft:0,color:"silver"},children:[Object(se.jsx)("div",{style:T?null:{color:"green"},children:r("to apply one item")}),Object(se.jsx)(jt.a,{disabled:Re||!!c||1===Y,checked:!!c||T,onChange:function(e){N(e.target.checked),We(!1)},color:"primary"}),Object(se.jsxs)("div",{style:T?{color:"green"}:null,children:[r("to apply with children")," ",c||Y>1?"(".concat(Y," ").concat(r("object(s)"),")"):""]})]}),Re&&Object(se.jsx)(U.a,{}),Object(se.jsxs)("div",{style:{overflowY:"auto"},children:[Object(se.jsxs)("div",{children:[Object(se.jsx)("h2",{children:r("Object rights")}),Object(se.jsx)(os,{mask:Se,disabled:Re,setMask:ke,applyToChildren:T,differentValues:fe,t:r,setValue:function(e){q(e),We(!1)},value:z})]}),R&&Object(se.jsxs)("div",{children:[Object(se.jsx)("h2",{children:r("States rights")}),Object(se.jsx)(os,{mask:xe,disabled:Re,setMask:ye,applyToChildren:T,differentValues:T?pe:[],t:r,setValue:function(e){$(e),We(!1)},value:K})]})]})]})}):Object(se.jsx)(U.a,{})},rs=function(e){Object(o.a)(s,e);var t=Object(i.a)(s);function s(e){var n;Object(a.a)(this,s),(n=t.call(this,e)).translate=function(e,t,s){return void 0!==t?n.props.t(e,t,s):(n.wordCache[e]||(n.wordCache[e]=n.props.t(e)),n.wordCache[e])},n.dialogName="AdminObjects",n.filters=window.localStorage.getItem("".concat(n.dialogName||"App",".filters"))||"{}";try{n.filters=JSON.parse(n.filters)}catch(i){n.filters={}}var o=window.localStorage.getItem("".concat(n.dialogName||"App",".selected"))||"";return n.state={selected:void 0===n.props.selected?o:"",name:"",toast:"",deleteObjectShow:null},n.t=n.translate,n.wordCache={},n}return Object(n.a)(s,[{key:"onDelete",value:function(e){var t=this,s=this.state.deleteObjectShow.id;e?(this.props.socket.delObjects(s,!0).then((function(){return t.setState({toast:t.t("All deleted")})})).catch((function(e){return window.alert("Cannot delete object: "+e)})),this.setState({deleteObjectShow:null})):(this.props.socket.delObject(s,!1).catch((function(e){return window.alert("Cannot delete object: "+e)})),this.setState({deleteObjectShow:null}))}},{key:"renderToast",value:function(){var e=this;return Object(se.jsx)(g.a,{anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!this.state.toast,autoHideDuration:3e3,onClose:function(){return e.setState({toast:""})},message:this.state.toast,action:Object(se.jsx)(c.a.Fragment,{children:Object(se.jsx)(f.a,{size:"small","aria-label":"close",color:"inherit",onClick:function(){return e.setState({toast:""})},children:Object(se.jsx)(O.a,{fontSize:"small"})})})})}},{key:"renderDeleteDialog",value:function(){var e=this;return this.state.deleteObjectShow?Object(se.jsxs)(d.a,{maxWidth:"md",open:!0,onClose:function(){return e.setState({deleteObjectShow:null})},"aria-labelledby":"delete-object-dialog-title","aria-describedby":"delete-object-dialog-description",children:[Object(se.jsxs)(h.a,{id:"delete-object-dialog-title",children:[this.state.deleteObjectShow.hasChildren?this.t("Delete object(s)"):this.t("Delete object"),": ",Object(se.jsx)("span",{className:this.props.classes.id,children:this.state.deleteObjectShow.id})]}),Object(se.jsx)(p.a,{children:Object(se.jsx)(b.a,{children:this.t("Are you sure?")})}),Object(se.jsxs)(m.a,{children:[this.state.deleteObjectShow.hasChildren?Object(se.jsx)(j.a,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:function(){return e.onDelete(!0)},startIcon:Object(se.jsx)(y.a,{className:this.props.classes.buttonAll}),children:this.t("Delete with children")}):null,this.state.deleteObjectShow.exists?Object(se.jsx)(j.a,{variant:"contained",classes:{label:this.props.classes.buttonText},onClick:function(){return e.onDelete(!1)},color:"primary",startIcon:Object(se.jsx)(y.a,{}),autoFocus:!0,children:this.t("Delete one item")}):null,Object(se.jsx)(j.a,{variant:"contained",onClick:function(){return e.setState({deleteObjectShow:null})},startIcon:Object(se.jsx)(O.a,{}),children:this.t("ra_Cancel")})]})]},"delete"):null}},{key:"render",value:function(){var e=this;return[Object(se.jsx)(w.a,{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:ht,objectBrowserValue:wt,objectBrowserEditObject:Lt,objectBrowserEditRole:Ut,router:N.a,enableStateValueEdit:!0,onObjectDelete:function(t,s,a){return e.setState({deleteObjectShow:{id:t,hasChildren:s,exists:a}})},onFilterChanged:function(t){e.filters=t,window.localStorage.setItem("".concat(e.dialogName||"App",".filters"),JSON.stringify(t))},onSelect:function(t){return window.localStorage.setItem("".concat(e.dialogName||"App",".selected"),t[0]||"")},objectEditBoolean:!0,objectAddBoolean:!0,objectStatesView:!0,objectImportExport:!0,objectEditOfAccessControl:!0,modalNewObject:function(t){return Object(se.jsx)(es,{objects:t.objects,expertMode:e.props.expertMode,open:t.state.modalNewObj,setObject:function(e,s){return t.setObject(e,s)},selected:t.state.selected[0]||t.state.selectedNonObject,onClose:function(){return t.setState({modalNewObj:!1})},onApply:function(){return t.setState({modalNewObj:!1})}})},modalEditOfAccessControl:function(t,s){return Object(se.jsx)(is,{themeType:e.props.themeType,open:t.state.modalEditOfAccess,extendObject:function(e,a){t.extendObject(e,a),s.aclTooltip=null},selected:t.state.selected[0],modalEmptyId:t.state.modalEmptyId,objects:t.objects,t:e.t,onClose:function(){return t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})},onApply:function(){return t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null,modalEmptyId:null})}})}},"browser"),this.renderDeleteDialog()]}}]),s}(l.Component),ls=Object(r.a)()(Object(u.a)((function(e){return{buttonIcon:{marginRight:4},buttonAll:{color:"#FF0000"},id:{fontStyle:"italic"},buttonText:{whiteSpace:"nowrap"}}}))(rs));t.default=ls}}]);
2
+ //# sourceMappingURL=15.1e46a4bb.chunk.js.map