iobroker.admin 7.1.1 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -8
- package/adminWww/asset-manifest.json +33 -33
- package/adminWww/index.html +1 -1
- package/adminWww/static/css/3210.f6c8a5fc.chunk.css.map +1 -1
- package/adminWww/static/js/2534.d8fd195b.chunk.js +2 -0
- package/adminWww/static/js/2534.d8fd195b.chunk.js.map +1 -0
- package/adminWww/static/js/2544.047df092.chunk.js +2 -0
- package/adminWww/static/js/2544.047df092.chunk.js.map +1 -0
- package/adminWww/static/js/2816.f7bf6ba0.chunk.js +2 -0
- package/adminWww/static/js/2816.f7bf6ba0.chunk.js.map +1 -0
- package/adminWww/static/js/3210.1be726e7.chunk.js +2 -0
- package/adminWww/static/js/3210.1be726e7.chunk.js.map +1 -0
- package/adminWww/static/js/4112.9b241792.chunk.js +2 -0
- package/adminWww/static/js/4112.9b241792.chunk.js.map +1 -0
- package/adminWww/static/js/4579.014de1f1.chunk.js +2 -0
- package/adminWww/static/js/4579.014de1f1.chunk.js.map +1 -0
- package/adminWww/static/js/{5174.60f22386.chunk.js → 5174.f5aa1074.chunk.js} +2 -2
- package/adminWww/static/js/5174.f5aa1074.chunk.js.map +1 -0
- package/adminWww/static/js/530.cb8dbcf9.chunk.js +2 -0
- package/adminWww/static/js/530.cb8dbcf9.chunk.js.map +1 -0
- package/adminWww/static/js/6552.0a447e18.chunk.js +2 -0
- package/adminWww/static/js/6552.0a447e18.chunk.js.map +1 -0
- package/adminWww/static/js/6938.af058182.chunk.js +2 -0
- package/adminWww/static/js/6938.af058182.chunk.js.map +1 -0
- package/adminWww/static/js/{8038.cacab580.chunk.js → 8038.ae8b7862.chunk.js} +2 -2
- package/adminWww/static/js/8038.ae8b7862.chunk.js.map +1 -0
- package/adminWww/static/js/858.f34ea2c6.chunk.js +2 -0
- package/adminWww/static/js/858.f34ea2c6.chunk.js.map +1 -0
- package/adminWww/static/js/9399.5852b7e7.chunk.js +2 -0
- package/adminWww/static/js/9399.5852b7e7.chunk.js.map +1 -0
- package/adminWww/static/js/9534.2af54084.chunk.js +2 -0
- package/adminWww/static/js/9534.2af54084.chunk.js.map +1 -0
- package/adminWww/static/js/9917.3662a807.chunk.js +2 -0
- package/adminWww/static/js/9917.3662a807.chunk.js.map +1 -0
- package/adminWww/static/js/{main.c1384a82.js → main.423e60b6.js} +2 -2
- package/adminWww/static/js/main.423e60b6.js.map +1 -0
- package/build-backend/lib/passportSocket.js +8 -10
- package/build-backend/lib/translations.js +0 -1
- package/build-backend/lib/web.js +101 -81
- package/build-backend/main.js +173 -184
- package/io-package.json +14 -14
- package/package.json +97 -96
- package/adminWww/static/js/2534.0bc9912f.chunk.js +0 -2
- package/adminWww/static/js/2534.0bc9912f.chunk.js.map +0 -1
- package/adminWww/static/js/2544.4fa1eef5.chunk.js +0 -2
- package/adminWww/static/js/2544.4fa1eef5.chunk.js.map +0 -1
- package/adminWww/static/js/2816.cfab0128.chunk.js +0 -2
- package/adminWww/static/js/2816.cfab0128.chunk.js.map +0 -1
- package/adminWww/static/js/3210.4c1ccdc2.chunk.js +0 -2
- package/adminWww/static/js/3210.4c1ccdc2.chunk.js.map +0 -1
- package/adminWww/static/js/4112.8c6e6dae.chunk.js +0 -2
- package/adminWww/static/js/4112.8c6e6dae.chunk.js.map +0 -1
- package/adminWww/static/js/4579.cd86a1cb.chunk.js +0 -2
- package/adminWww/static/js/4579.cd86a1cb.chunk.js.map +0 -1
- package/adminWww/static/js/5174.60f22386.chunk.js.map +0 -1
- package/adminWww/static/js/530.8eed62a7.chunk.js +0 -2
- package/adminWww/static/js/530.8eed62a7.chunk.js.map +0 -1
- package/adminWww/static/js/6552.29112fa0.chunk.js +0 -2
- package/adminWww/static/js/6552.29112fa0.chunk.js.map +0 -1
- package/adminWww/static/js/6938.f4331126.chunk.js +0 -2
- package/adminWww/static/js/6938.f4331126.chunk.js.map +0 -1
- package/adminWww/static/js/8038.cacab580.chunk.js.map +0 -1
- package/adminWww/static/js/858.3a130f69.chunk.js +0 -2
- package/adminWww/static/js/858.3a130f69.chunk.js.map +0 -1
- package/adminWww/static/js/9399.c959c5de.chunk.js +0 -2
- package/adminWww/static/js/9399.c959c5de.chunk.js.map +0 -1
- package/adminWww/static/js/9534.68ac37f7.chunk.js +0 -2
- package/adminWww/static/js/9534.68ac37f7.chunk.js.map +0 -1
- package/adminWww/static/js/9917.28c0dbc2.chunk.js +0 -2
- package/adminWww/static/js/9917.28c0dbc2.chunk.js.map +0 -1
- package/adminWww/static/js/main.c1384a82.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[9534],{90869:(t,e,s)=>{s.d(e,{A:()=>h});var i=s(29183),o=s(89303),a=s(32075),n=s(26699),l=s(99277);const r={modalDialog:{minWidth:400,maxWidth:800},overflowHidden:{display:"flex",overflow:"hidden"},titleIcon:{marginRight:5},content:{fontSize:16},languageButton:{position:"absolute",right:8,top:8},languageButtonActive:t=>({color:t.palette.primary.main})},h=t=>{let{toggleTranslation:e,noTranslation:s,title:h,fullWidth:d,help:c,maxWidth:p,progress:m,icon:u,disableApplyIfNotChanged:g,applyButton:v,onClose:x,children:b,titleButtonApply:j,titleButtonClose:f,onApply:y,textInput:w,defaultValue:C,overflowHidden:S,disableApply:I,theme:A}=t;const[T,k]=(0,i.useState)(C);(0,i.useEffect)((()=>{k(C)}),[C]);let D=null;u&&(D=u);const F=n.Utils.getStyle(A,r.languageButtonActive);return(0,l.jsxs)(o.Dialog,{open:!0,maxWidth:p||"md",fullWidth:!!d,disableEscapeKeyDown:!1,onClose:x,sx:{"& .MuiPaper-root":r.modalDialog},children:[h&&(0,l.jsxs)(o.DialogTitle,{children:[u?(0,l.jsx)(D,{style:r.titleIcon}):null,h,"en"!==n.I18n.getLanguage()&&e?(0,l.jsx)(o.IconButton,{size:"large",style:{...r.languageButton,...s?F:void 0},onClick:()=>e(),title:n.I18n.t("Disable/Enable translation"),children:(0,l.jsx)(a.Language,{})}):null]}),(0,l.jsxs)(o.DialogContent,{style:{...S?r.overflowHidden:void 0,...r.content,paddingTop:8},children:[w&&(0,l.jsx)(o.TextField,{autoComplete:"off",fullWidth:!0,autoFocus:!0,variant:"standard",size:"medium",multiline:!0,value:T,onChange:t=>k(t.target.value),slotProps:{input:{endAdornment:T?(0,l.jsx)(o.InputAdornment,{position:"end",children:(0,l.jsx)(o.IconButton,{size:"small",onClick:()=>k(""),children:(0,l.jsx)(a.Close,{})})}):null}}}),b,c?(0,l.jsx)("div",{children:c}):null]}),(0,l.jsxs)(o.DialogActions,{children:[(void 0===v||v)&&(0,l.jsx)(o.Button,{startIcon:(0,l.jsx)(a.Check,{}),disabled:I||m||g&&C===T,onClick:()=>y&&y(w?T:""),variant:"contained",color:"primary",children:n.I18n.t(j||"Ok")}),(0,l.jsx)(o.Button,{color:"grey",onClick:x,disabled:m,variant:"contained",startIcon:(0,l.jsx)(a.Close,{}),children:n.I18n.t(f||"Cancel")})]})]})}},29534:(t,e,s)=>{s.r(e),s.d(e,{default:()=>wt});var i=s(29183),o=s.n(i),a=s(89303),n=s(32075),l=s(26699),r=s(858),h=s(58680),d=s.n(h),c=s(4531),p=s(78884),m=s(99277);const u={paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},headingIcon:{marginRight:5,width:32,height:32},titleEnabled:{float:"right",fontSize:16,color:"#7ff57f",textTransform:"uppercase",fontWeight:"bold",paddingLeft:20},scrollDiv:{width:"100%",height:"100%",overflow:"auto"},fullWidth:{width:"100%"},enabledControl:{width:130,display:"inline-block",verticalAlign:"top"},customControls:{width:"calc(100% - 130px)",maxWidth:800,display:"inline-block",verticalAlign:"top",paddingTop:16},accordionOdd:{},accordionEven:{backgroundColor:"rgba(128, 128, 128, 0.1)"},accordionHeaderOdd:{backgroundColor:"rgba(128, 128, 128, 0.2)"},accordionHeaderEven:{backgroundColor:"rgba(128, 128, 128, 0.3)"},accordionHeaderEnabledOdd:{backgroundColor:"rgba(128, 255, 128, 0.2)"},accordionHeaderEnabledEven:{backgroundColor:"rgba(128, 255, 128, 0.2)"},enabledVisible:{display:"inline-block"},enabledInvisible:{display:"none"}};class g extends i.Component{constructor(t){let e;super(t),this.changedIds=void 0,this.scrollDivRef=void 0,this.jsonConfigs=void 0,this.refTemplate=void 0,this.customObj=void 0,this.commonConfig={},this.cb=void 0,this.cachedNewValues=void 0,this.onSave=t=>{this.props.objectIDs.length>10&&!this.state.confirmed?(this.cb=t,this.setState({showConfirmation:!0})):this.saveOneState([...this.props.objectIDs],(()=>{this.cachedNewValues={},this.commonConfig=this.getCommonConfig(),this.setState({confirmed:!1,hasChanges:void 0,newValues:{}},(()=>{this.props.reportChangedIds(this.changedIds),this.props.onChange(!1,!0),t&&setTimeout((()=>t()),100)}))}))};try{e=JSON.parse((window._localStorage||window.localStorage).getItem("App.customsExpanded")||"[]")}catch{e=[]}this.changedIds=[],this.state={loaded:!1,expanded:e,newValues:{},confirmed:!1,showConfirmation:!1,maxOids:0,systemConfig:this.props.systemConfig},this.scrollDivRef=(0,i.createRef)(),this.jsonConfigs={},this.refTemplate={},this.props.customsInstances.map((t=>this.refTemplate[t]=(0,i.createRef)())),this.customObj=this.props.objectIDs.length>1?{common:{custom:{}},native:{}}:p.A.deepClone(this.props.objects[this.props.objectIDs[0]]||null),this.customObj&&this.loadAllCustoms().then((()=>{this.commonConfig=this.getCommonConfig(),this.setState({loaded:!0,newValues:{}})}))}async componentDidMount(){this.state.systemConfig||this.setState({systemConfig:await this.props.socket.getCompactSystemConfig()}),this.props.registerSaveFunc&&this.props.registerSaveFunc(this.onSave)}componentWillUnmount(){this.props.registerSaveFunc&&this.props.registerSaveFunc()}async loadAllCustoms(){const t=[];for(const e of this.props.customsInstances){if("_"===e)continue;const s=e.replace(/\.\d+$/,"").replace("system.adapter.","");void 0===this.jsonConfigs[s]&&(this.jsonConfigs[s]=null,t.push(this.getCustomTemplate(s)))}await Promise.all(t),this.props.customsInstances.forEach((t=>{const e=t.replace(/\.\d+$/,"").replace("system.adapter.","");var s,i;this.jsonConfigs[e]&&(this.jsonConfigs[e].instanceObjs=this.jsonConfigs[e].instanceObjs||{},this.jsonConfigs[e].instanceObjs[t]={_id:t,common:JSON.parse(JSON.stringify(null===(s=this.props.objects[`system.adapter.${t}`])||void 0===s?void 0:s.common)),native:JSON.parse(JSON.stringify(null===(i=this.props.objects[`system.adapter.${t}`])||void 0===i?void 0:i.native)),type:"instance",instanceObjects:[],objects:[]})}))}async getCustomTemplate(t){var e;const s=this.props.objects[`system.adapter.${t}`]?p.A.deepClone(this.props.objects[`system.adapter.${t}`]):null;if(s){if(p.A.fixAdminUI(s),"json"===(null===(e=s.common)||void 0===e?void 0:e.adminUI.custom))try{let e;await this.props.socket.fileExists(`${t}.admin`,"jsonCustom.json5")&&await this.props.socket.readFile(`${t}.admin`,"jsonCustom.json5");const s=await this.props.socket.readFile(`${t}.admin`,"jsonCustom.json");let o;e=void 0!==s.file?s.file:s;try{o=d().parse(e),this.jsonConfigs[t]=this.jsonConfigs[t]||{},this.jsonConfigs[t].json=o}catch(i){console.error(`Cannot parse jsonConfig of ${t}: ${i}`),window.alert(`Cannot parse jsonConfig of ${t}: ${i}`)}return void await c.JsonConfigComponent.loadI18n(this.props.socket,o.i18n,t)}catch(o){console.error(`Cannot load jsonConfig of ${t}: ${o}`),window.alert(`Cannot load jsonConfig of ${t}: ${o}`)}console.error(`Adapter ${t} is not yet supported by this version of admin`),window.alert(`Adapter ${t} is not yet supported by this version of admin`)}else console.error(`Cannot find adapter "${t}"`)}_executeCustom(t,e,s,i,o,a,n){if(n.includes(a))return;n.push(a);let l,r=[];if(t&&"object"===typeof t?(r=t.alsoDependsOn||[],"string"===typeof r&&(r=[r]),l=t.func):l=t,r.forEach((t=>{if(o[t])if(o[t].defaultFunc){const a=this._executeCustom(o[t].defaultFunc,e,s,i,o,t,n);void 0!==a&&(e[t]=a)}else console.error(`[JsonConfigComponent] attribute "${t}" is not required to be includes in "alsoDependsOn" while has static value!`);else console.error(`[JsonConfigComponent] attribute "${t}" does not exist!`)})),l)try{const t=new Function("data","originalData","_system","instanceObj","customObj","_socket",l.includes("return")?l:`return ${l}`);e[a]=t(e||this.props.data,this.props.originalData,this.props.systemConfig,i,s,this.props.socket)}catch(h){console.error(`Cannot execute ${t}: ${h}`),e[a]=o[a]&&void 0!==o[a].default?o[a].default:null}else e[a]=void 0===o[a].default?null:o[a].default;return e[a]}static flattenItems(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t&&Object.keys(t).forEach((s=>{t[s].items?g.flattenItems(t[s].items,e):e[s]=t[s]})),e}getDefaultValues(t,e){const s={enabled:!1},i=t.split(".")[0];if(this.jsonConfigs[i]&&!this.jsonConfigs[i].disabled){const o=g.flattenItems(this.jsonConfigs[i].json.items);if(o){const a=[],n=Object.keys(o).filter((t=>o[t]));n.forEach((t=>{o[t].defaultFunc||void 0===o[t].default||(s[t]=o[t].default)})),n.forEach((n=>{o[n].defaultFunc&&this._executeCustom(o[n].defaultFunc,s,e,this.jsonConfigs[i].instanceObjs[t],o,n,a)}))}}return s}getCommonConfig(){const t=this.props.objectIDs||[],e=this.props.objects,s={};return this.props.customsInstances.forEach((i=>{const o=i.split(".")[0];this.jsonConfigs[o]&&this.jsonConfigs[o].disabled||(s[i]={},t.forEach((t=>{var o;const a=e[t],n=null!==a&&void 0!==a&&null!==(o=a.common)&&void 0!==o&&o.custom&&a.common.custom[i]||null;if(n)Object.keys(n).forEach((t=>{t.startsWith("_")||(void 0===s[i][t]?s[i][t]=n[t]:s[i][t]!==n[t]&&(Array.isArray(s[i][t])||(s[i][t]=[s[i][t]]),s[i][t].includes(n[t])||s[i][t].push(n[t])))}));else{const t=this.getDefaultValues(i,a);t.enabled=!1,Object.keys(t).forEach((e=>{e.startsWith("_")||(void 0===s[i][e]?s[i][e]=t[e]:s[i][e]!==t[e]&&(Array.isArray(s[i][e])||(s[i][e]=[s[i][e]]),s[i][e].includes(t[e])||s[i][e].push(t[e])))}))}})),Object.keys(s[i]).forEach((t=>{Array.isArray(s[i][t])&&s[i][t].sort()})))})),s}isChanged(t){return t=t||this.state.newValues,Object.keys(t).find((e=>null===t[e]||t[e]&&Object.keys(t[e]).find((t=>!t.startsWith("_")))))}combineNewAndOld(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const s={...this.commonConfig[t]||{},...this.state.newValues[t]||{}};return e&&Object.keys(s).forEach((t=>{t.startsWith("_")&&delete s[t]})),null===this.state.newValues[t]&&(s.enabled=!1),s}renderOneCustom(t,e,s,i){var o,l,r;const h=t.split(".")[0],d=`./adapter/${h}/${this.props.objects[`system.adapter.${h}`].common.icon}`,g=void 0===this.state.newValues[t]||this.state.newValues[t]&&void 0===this.state.newValues[t].enabled?null!==this.state.newValues[t]&&this.commonConfig[t].enabled:!(!this.state.newValues[t]||!this.state.newValues[t].enabled),v=Array.isArray(g)&&(!this.state.newValues[t]||void 0===this.state.newValues[t].enabled),x=null===(o=this.jsonConfigs[h])||void 0===o||null===(l=o.json)||void 0===l?void 0:l.disabled,b=this.combineNewAndOld(t);if(x&&!0===this.jsonConfigs[h].json.hidden)return null;if("string"===typeof this.jsonConfigs[h].json.hidden&&this._executeCustom(this.jsonConfigs[h].json.hidden,b,s,e,this.jsonConfigs[h].json.items,"enabled",[]))return null;let j=null;return x&&this.jsonConfigs[h].json.help&&(j="object"===typeof this.jsonConfigs[h].json.help?this.jsonConfigs[h].json.help[this.props.lang]||this.jsonConfigs[h].json.help.en:this.props.t(this.jsonConfigs[h].json.help)),(0,m.jsxs)(a.Accordion,{id:`Accordion_${t}`,style:i%2?u.accordionOdd:u.accordionEven,expanded:this.state.expanded.includes(t),ref:this.refTemplate[t],onChange:()=>{const e=[...this.state.expanded],s=e.indexOf(t);-1===s?e.push(t):e.splice(s,1),(window._localStorage||window.localStorage).setItem("App.customsExpanded",JSON.stringify(e)),-1===s&&(window._localStorage||window.localStorage).setItem("App.customsLastExpanded",t),this.setState({expanded:e})},children:[(0,m.jsxs)(a.AccordionSummary,{expandIcon:(0,m.jsx)(n.ExpandMore,{}),"data-id":t,style:i%2?g?u.accordionHeaderEnabledOdd:u.accordionHeaderOdd:g?u.accordionHeaderEnabledEven:u.accordionHeaderEven,children:[(0,m.jsx)("img",{src:d,style:u.headingIcon,alt:""}),(0,m.jsx)(a.Typography,{style:u.heading,children:this.props.t("Settings %s",t)}),(0,m.jsx)("div",{className:"titleEnabled",style:{...u.titleEnabled,...g?u.enabledVisible:u.enabledInvisible},children:this.props.t("Enabled")})]}),(0,m.jsxs)(a.AccordionDetails,{children:[(0,m.jsx)("div",{style:u.enabledControl,children:(0,m.jsx)(a.FormControlLabel,{style:u.formControl,control:(0,m.jsx)(a.Checkbox,{indeterminate:v,checked:!!g,disabled:!!x,onChange:e=>{this.cachedNewValues=this.cachedNewValues||this.state.newValues;const s=p.A.deepClone(this.cachedNewValues);s[t]=s[t]||{},v||e.target.checked?s[t].enabled=!0:g&&this.commonConfig[t].enabled?s[t]=null:delete s[t],this.cachedNewValues=s,this.setState({newValues:s,hasChanges:this.isChanged(s)},(()=>{this.cachedNewValues=void 0,this.props.onChange&&this.props.onChange(!!this.state.hasChanges)}))}}),label:this.props.t("Enabled")})}),(0,m.jsxs)("div",{style:u.customControls,children:[!x&&(g||v)&&this.state.systemConfig?(0,m.jsx)(c.JsonConfigComponent,{instanceObj:e,customObj:s,custom:!0,adapterName:h,instance:parseInt(null!==(r=null===t||void 0===t?void 0:t.split(".").pop())&&void 0!==r?r:"0",10)||0,socket:this.props.socket,themeName:this.props.themeName,themeType:this.props.themeType,theme:this.props.theme,multiEdit:this.props.objectIDs.length>1,schema:this.jsonConfigs[h].json,data:b,isFloatComma:this.props.systemConfig.common.isFloatComma,dateFormat:this.props.systemConfig.common.dateFormat,onError:t=>this.setState({error:t},(()=>this.props.onError&&this.props.onError(t))),onValueChange:(e,s)=>{var i;this.cachedNewValues=this.cachedNewValues||this.state.newValues,console.log(`${e} => ${s}`);const o=p.A.deepClone(this.cachedNewValues);o[t]=o[t]||{},JSON.stringify(c.ConfigGeneric.getValue(null===(i=this.commonConfig)||void 0===i?void 0:i[t],e))===JSON.stringify(s)?(c.ConfigGeneric.setValue(o[t],e,null),Object.keys(o[t]).length||delete o[t]):c.ConfigGeneric.setValue(o[t],e,s),this.cachedNewValues=o,this.setState({newValues:o,hasChanges:this.isChanged(o)},(()=>{this.cachedNewValues=void 0,this.props.onChange&&this.props.onChange(!!this.state.hasChanges)}))}}):null,j]})]})]},t)}renderErrorMessage(){return!!this.state.error&&(0,m.jsx)(l.Error,{title:this.props.t("Error"),text:this.state.error?"Error":"",onClose:()=>this.setState({error:!1})})}getObject(t,e,s){return t[s]?Promise.resolve(t[s]):this.props.socket.getObject(s).then((i=>(e[s]=p.A.deepClone(i),t[s]=i,i)))}saveOneState(t,e,s,i){if(s=s||{},i=i||{},null!==t&&void 0!==t&&t.length){const o=this.state.maxOids||t.length;null===this.state.maxOids&&this.setState({maxOids:t.length},(()=>this.props.onProgress(!0))),this.setState({progress:Math.round((o-t.length)/o*50)});const a=t.shift();this.getObject(s,i,a).then((o=>{var n;if(!o)return void window.alert(`Invalid object ${a}`);null!==(n=o.common)&&void 0!==n&&n.custom&&Object.keys(o.common.custom).forEach((t=>{o.common.custom[t]&&o.common.custom[t].enabled||(o.common.custom[t]=null)}));const l=Object.keys(this.state.newValues);for(let t=0;t<l.length;t++){const e=l[t],s=this.combineNewAndOld(e,!0);var r,h;if(!1===s.enabled)null!==(r=o.common)&&void 0!==r&&null!==(h=r.custom)&&void 0!==h&&h[e]&&(o.common.custom[e]=null);else if(s.enabled){if(o.common=o.common||{},Array.isArray(s.enabled)&&(!o.common.custom||!o.common.custom[e]||!o.common.custom[e].enabled)){o.common.custom&&o.common.custom[e]&&(o.common.custom[e]=null);continue}if(o.common.custom=o.common.custom||{},!o.common.custom[e]||!o.common.custom[e].enabled){const t=this.getDefaultValues(e,o);o.common.custom[e]=JSON.parse(JSON.stringify(t||{})),Object.keys(o.common.custom[e]).forEach((t=>{t.startsWith("_")&&delete o.common.custom[e][t]}))}const t=this.props.objectIDs.length>1;o.common.custom[e].enabled=!0,Object.keys(s).forEach((i=>{if(!i.startsWith("_")){if(Array.isArray(s[i])&&t)return;o.common.custom[e][i]=s[i]}}))}}setTimeout((()=>this.saveOneState(t,e,s,i)),0)}))}else{const o=Object.keys(s);if(o.length){this.setState({progress:Math.round((this.state.maxOids-o.length)/this.state.maxOids*50)+50});const a=o.shift();if(JSON.stringify(s[a].common)!==JSON.stringify(i[a].common))return this.changedIds.includes(a)||this.changedIds.push(a),void this.props.socket.setObject(a,s[a]).then((async()=>{delete s[a],delete i[a],this.props.objects[a]=await this.props.socket.getObject(a),setTimeout((()=>this.saveOneState(t,e,s,i)),0)}));delete s[a],delete i[a],setTimeout((()=>this.saveOneState(t,e,s,i)),0)}else this.setState({maxOids:0},(()=>this.props.onProgress(!1))),e&&e()}}renderConfirmationDialog(){return this.state.showConfirmation?(0,m.jsx)(l.Confirm,{text:this.props.t("The changes will be applied to %s states. Are you sure?",this.props.objectIDs.length.toString()),ok:this.props.t("Yes"),onClose:t=>{t?this.setState({showConfirmation:!1,confirmed:!0},(()=>{const t=this.cb;this.cb=void 0,this.onSave(t)})):(this.cb=void 0,this.setState({showConfirmation:!1}))}}):null}render(){if(null===this.customObj)return(0,m.jsx)("div",{style:{color:"#F55",fontSize:32},children:this.props.t("Object does not exist!")});if(!this.state.loaded)return(0,m.jsx)(a.LinearProgress,{});let t=0;return(0,m.jsxs)(a.Paper,{style:u.paper,children:[this.state.maxOids>1&&(0,m.jsx)(a.LinearProgress,{color:"secondary",variant:"determinate",value:this.state.progress}),(0,m.jsx)("div",{style:u.scrollDiv,ref:this.scrollDivRef,children:0===this.state.maxOids&&Object.values(this.jsonConfigs).map((e=>e?Object.keys(e.instanceObjs).map((s=>this.renderOneCustom(s,e.instanceObjs[s],this.customObj,t++))):null))}),this.renderErrorMessage(),this.renderConfirmationDialog()]})}}const v=(0,l.withWidth)()(g);var x=s(35141),b=s(46567),j=s(25512),f=s(57669);const y={en:f.enUS,fr:f.fr,ru:f.ru,de:f.de,es:f.es,br:f.ptBR,nl:f.nl,it:f.it,pt:f.pt,pl:f.pl,uk:f.uk,"zh-cn":f.zhCN},w={paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden"},tableDiv:t=>({height:`calc(100% - ${parseInt(t.mixins.toolbar.minHeight,10)+8}px)`,overflow:"hidden",width:"100%"}),container:{height:"100%"},table:t=>({minWidth:960,width:"100%","& td:nth-of-type(5)":{overflow:"hidden",whiteSpace:"nowrap"},"& tr:nth-child(even)":{backgroundColor:"dark"===t.palette.mode?"#383838":"#b2b2b2"}}),row:{userSelect:"none",position:"relative","&:hover":{opacity:.7},"& td":{position:"relative"}},updatedRow:{animation:"updated 1s"},rowInterpolated:{opacity:.5},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:t=>({color:t.palette.primary.main}),rowSelected:t=>({backgroundColor:t.palette.secondary.main,color:t.palette.secondary.contrastText,"& td":{color:t.palette.secondary.contrastText,backgroundColor:t.palette.secondary.main}}),rowFocused:t=>({position:"absolute",pointerEvents:"none",top:0,bottom:0,left:0,right:0,m:"3px",border:`1px dotted ${t.palette.action.active}`}),grow:{flexGrow:1},msInput:{width:50,pt:"10px",ml:"5px","& label":{mt:"15px"}},cellAckTrue:t=>({color:"dark"===t.palette.mode?"#66ff7f":"#04a821"}),cellAckFalse:{color:"#FF6666"},toolbarDate:{width:124,mt:"9px","& fieldset":{display:"none"},"& input":{padding:"8px 0 0 0"},"& .MuiInputAdornment-root":{ml:0,mt:"7px"}},toolbarTime:{width:84,mt:"9px","& fieldset":{display:"none"},"& input":{padding:"8px 0 0 0"},"& .MuiInputAdornment-root":{ml:0,mt:"7px"}},toolbarTimeGrid:{position:"relative",marginLeft:8,paddingLeft:8,paddingRight:8,paddingTop:4,paddingBottom:4,border:"1px dotted #AAAAAA",borderRadius:8,display:"flex"},toolbarTimeLabel:{position:"absolute",padding:8,fontSize:"0.8rem",left:2,top:-9},noLoadingProgress:{width:"100%",height:4},colValue:{},colAck:{},colFrom:{},colLastChange:{},colTs:{}};class C extends i.Component{constructor(t){super(t),this.adminInstance=void 0,this.supportedFeaturesPromises=void 0,this.unit=void 0,this.timeTimer=void 0,this.readSupportedFeaturesTimeout=void 0,this.rangeValues=void 0,this.rangeRef=void 0,this.subscribes=void 0,this.localStorage=void 0,this.onChange=(t,e)=>{if(t===this.props.obj._id&&e&&this.state.values&&(!this.state.values.length||this.state.values[this.state.values.length-1].ts<e.ts)){const t=[...this.state.values,e];this.setState({values:t})}else if(t.startsWith("system.adapter.")&&t.endsWith(".alive")){const s=t.substring(15,t.length-6),i=this.state.historyInstances,o=i.findIndex((t=>t.id===s));if(-1!==o&&i[o].alive!==!(null===e||void 0===e||!e.val)){const t=JSON.parse(JSON.stringify(i));t[o].alive=!(null===e||void 0===e||!e.val),this.setState({historyInstances:t},(()=>{t[o].alive&&this.state.historyInstance===s&&this.readHistoryRange().then((()=>this.readHistory()))}))}}},this.localStorage=window._localStorage||window.localStorage;let e=this.localStorage.getItem("App.relativeRange")||"absolute";const s=parseInt(this.localStorage.getItem("App.absoluteStart"),10)||0,i=parseInt(this.localStorage.getItem("App.absoluteEnd"),10)||0,o=this.localStorage.getItem("App.historySelected")||"",a=parseInt(this.localStorage.getItem("App.historyLastSelected"),10)||null,n=this.localStorage.getItem("App.historyLastSelectedColumn")||null;let l;s&&i||e&&"absolute"!==e||(e="30"),s&&i&&(e="absolute");try{l=JSON.parse(o)}catch{l=[]}this.state={start:s,end:i,values:null,relativeRange:e,selected:l,lastSelected:a,lastSelectedColumn:n,historyInstance:"",updateOpened:!1,insertOpened:!1,historyInstances:null,lcVisible:!0,ackVisible:!0,fromVisible:!0,supportedFeatures:[],ampm:!1,edit:{}},this.adminInstance=parseInt(window.location.search.slice(1),10)||0,this.supportedFeaturesPromises={},this.unit=this.props.obj.common&&this.props.obj.common.unit?` ${this.props.obj.common.unit}`:"",this.timeTimer=void 0,this.subscribes=[],this.prepareData().then((()=>this.readHistoryRange())).then((()=>{"absolute"!==e?this.setRelativeInterval(this.state.relativeRange,!0):this.readHistory()}))}readSupportedFeatures(t){return(t=t||this.state.historyInstance)?(this.supportedFeaturesPromises[t]instanceof Promise||(this.supportedFeaturesPromises[t]=new Promise((e=>{this.readSupportedFeaturesTimeout&&clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=setTimeout((()=>{this.readSupportedFeaturesTimeout=void 0,e([])}),2e3),this.props.socket.sendTo(t,"features",null).then((t=>{this.readSupportedFeaturesTimeout?(clearTimeout(this.readSupportedFeaturesTimeout),this.readSupportedFeaturesTimeout=void 0,e(t&&t.supportedFeatures||[])):this.setState({supportedFeatures:t&&t.supportedFeatures||[]})}))}))),this.supportedFeaturesPromises[t]):Promise.resolve([])}async componentDidMount(){await this.props.socket.subscribeState(this.props.obj._id,this.onChange)}componentWillUnmount(){this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=void 0);for(let t=0;t<this.subscribes.length;t++)this.props.socket.unsubscribeState(this.subscribes[t],this.onChange);this.subscribes=[],this.props.socket.unsubscribeState(this.props.obj._id,this.onChange)}async prepareData(){var t;const e=await this.getHistoryInstances(),s=await this.props.socket.getCompactSystemConfig(),i=null===s||void 0===s||null===(t=s.common)||void 0===t?void 0:t.defaultHistory;let o=this.localStorage.getItem("App.historyInstance")||"";if(o&&e.find((t=>t.id===o&&t.alive))||(o=i),!o||!e.find((t=>t.id===o&&t.alive))){const t=e.find((t=>t.alive));t&&(o=t.id)}!o&&e.length&&(o=i);const a=await this.readSupportedFeatures(o);await new Promise((t=>{this.setState({ampm:(s.common.dateFormat||"").includes("/"),historyInstances:e,historyInstance:o,supportedFeatures:a},(()=>t()))}))}getHistoryInstances(){const t=[],e=[];return this.props.customsInstances.forEach((s=>{const i=this.props.objects[`system.adapter.${s}`];if(i&&i.common&&i.common.getHistory){const i={id:s,alive:!1};t.push(i),e.push(`system.adapter.${s}.alive`)}})),e.length?this.props.socket.getForeignStates(e).then((async s=>{Object.keys(s).forEach((e=>{const i=t.find((t=>e.endsWith(`${t.id}.alive`)));var o;i&&(i.alive=!(null===(o=s[e])||void 0===o||!o.val))})),this.subscribes=e;for(let t=0;t<e.length;t++)await this.props.socket.subscribeState(e[t],this.onChange);return t})):Promise.resolve(t)}readHistory(t,e){var s;return t=t||this.state.start,e=e||this.state.end,this.state.historyInstance&&null!==(s=this.state.historyInstances)&&void 0!==s&&s.find((t=>t.id===this.state.historyInstance&&t.alive))?(this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:t,end:e,from:!0,ack:!0,q:!0,addID:!1,aggregate:"none",returnNewestEntries:!0}).then((t=>{const e=[],s=this.rangeValues;let i=!1,o=!1,a=!1;if(s&&s.length&&(!t||!t.length||s[0].ts<t[0].ts)&&(e.push(s[0]),e.push({ts:s[0].ts+1,e:!0}),console.log(`add ${new Date(s[0].ts).toISOString()}: ${s[0].val}`),o||void 0===s[0].ack||(o=!0),!a&&s[0].from&&(a=!0)),null!==t&&void 0!==t&&t.length)for(let n=0;n<t.length;n++)t[n]&&(!e.length||e[e.length-1].ts<t[n].ts)?(e.push(t[n]),t[n].from&&(t[n].from.startsWith("system.adapter.")?t[n].from=t[n].from.substring(15):t[n].from.startsWith("system.host.")&&(t[n].from=t[n].from.substring(7))),!i&&t[n].lc&&(i=!0),o||void 0===t[n].ack||(o=!0),!a&&t[n].from&&(a=!0),console.log(`add value ${new Date(t[n].ts).toISOString()}: ${t[n].val}`)):e[e.length-1].ts===t[n].ts&&e[e.length-1].val!==t[n].ts&&console.error("Strange data!");else e.push({noDataForPeriod:!0});e.length||e.push({noData:!0}),this.setState({loading:!1,values:e,lcVisible:i,fromVisible:a,ackVisible:o})}))):null}readHistoryRange(){var t;const e=new Date,s=new Date(2e3,0,1);return this.state.historyInstance&&null!==(t=this.state.historyInstances)&&void 0!==t&&t.find((t=>t.id===this.state.historyInstance&&t.alive))?(this.setState({loading:!0}),this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then((t=>{t.length?(null!==t[0].val&&t[0].ts!==s.getTime()||t.shift(),t.forEach((t=>t.i=!0)),this.rangeValues=t,this.setState({loading:!1})):(this.rangeValues=[],this.setState({loading:!1}))}))):Promise.resolve()}onToggleSelect(t,e,s){let i=[...this.state.selected];const o=i.indexOf(e);if(t.shiftKey&&this.state.lastSelected){let t=-1,s=-1;i=[];for(let o=0;o<this.state.values.length&&(this.state.values[o].ts!==e||(t=o,s!==t&&i.push(this.state.values[o].ts),-1===t||-1===s))&&(this.state.values[o].ts!==this.state.lastSelected||(s=o,s!==t&&i.push(this.state.values[o].ts),-1===t||-1===s));o++)-1===t&&-1===s||i.push(this.state.values[o].ts)}else t.ctrlKey?(-1!==o?i.splice(o,1):i.push(e),i.sort()):i=[e];this.localStorage.setItem("App.historyLastSelected",e.toString()),this.localStorage.setItem("App.historyLastSelectedColumn",s),this.localStorage.setItem("App.historySelected",JSON.stringify(i)),this.setState({selected:i,lastSelected:e,lastSelectedColumn:s})}getTableRows(){const t=[];for(let e=this.state.values.length-1;e>=0;e--){const s=this.state.values[e],i=s.ts;if(s.e)t.push((0,m.jsxs)(a.TableRow,{sx:{...w.row,...w.updatedRow,...w.rowInterpolated},hover:!0,children:[(0,m.jsx)(a.TableCell,{}),(0,m.jsx)(a.TableCell,{children:"..."}),this.state.ackVisible?(0,m.jsx)(a.TableCell,{}):null,this.state.fromVisible?(0,m.jsx)(a.TableCell,{}):null,this.state.lcVisible?(0,m.jsx)(a.TableCell,{}):null]},i));else if(s.noData||s.noDataForPeriod)t.push((0,m.jsxs)(a.TableRow,{sx:{...w.row,...w.updatedRow,...w.rowNoData},hover:!0,children:[(0,m.jsx)(a.TableCell,{}),(0,m.jsx)(a.TableCell,{children:s.noData?this.props.t("No data in history"):this.props.t("No data in history for selected period")}),this.state.ackVisible?(0,m.jsx)(a.TableCell,{}):null,this.state.fromVisible?(0,m.jsx)(a.TableCell,{}):null,this.state.lcVisible?(0,m.jsx)(a.TableCell,{}):null]},s.noData?"nodata":""));else{const e=s.i,o=this.state.lastSelected===i;let n=s.val;this.props.isFloatComma&&"number"===this.props.obj.common.type&&n&&(n=n.toString().replace(".",",")),null===n&&(n="null"),void 0===n&&(n="_");const l=this.state.selected.includes(i);t.push((0,m.jsxs)(a.TableRow,{sx:{...w.row,...w.updatedRow,...e?w.rowInterpolated:void 0,...l?w.rowSelected:void 0},children:[(0,m.jsxs)(a.TableCell,{onClick:t=>!e&&this.onToggleSelect(t,i,"ts"),children:[`${C.formatTimestamp(s.ts)}`,o&&"ts"===this.state.lastSelectedColumn?(0,m.jsx)(a.Box,{component:"div",sx:w.rowFocused}):""]}),(0,m.jsxs)(a.TableCell,{onClick:t=>!e&&this.onToggleSelect(t,i,"val"),children:[n+this.unit,o&&"val"===this.state.lastSelectedColumn?(0,m.jsx)(a.Box,{component:"div",sx:w.rowFocused}):""]}),this.state.ackVisible?(0,m.jsxs)(a.TableCell,{onClick:t=>!e&&this.onToggleSelect(t,i,"ack"),sx:s.ack?w.cellAckTrue:w.cellAckFalse,children:[s.ack?"true":"false",o&&"ack"===this.state.lastSelectedColumn?(0,m.jsx)(a.Box,{component:"div",sx:w.rowFocused}):""]}):null,this.state.fromVisible?(0,m.jsxs)(a.TableCell,{onClick:t=>!e&&this.onToggleSelect(t,i,"from"),children:[s.from||"",o&&"from"===this.state.lastSelectedColumn?(0,m.jsx)(a.Box,{component:"div",sx:w.rowFocused}):""]}):null,this.state.lcVisible?(0,m.jsxs)(a.TableCell,{onClick:t=>!e&&this.onToggleSelect(t,i,"lc"),children:[s.lc?`${new Date(s.lc).toLocaleDateString()} ${new Date(s.lc).toLocaleTimeString()}.${(s.ts%1e3).toString().padStart(3,"0")}`:"",o&&"lc"===this.state.lastSelectedColumn?(0,m.jsx)(a.Box,{component:"div",sx:w.rowFocused}):""]}):null]},i.toString()+(s.val||"").toString()))}}return t}shiftTime(){const t=new Date,e=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);const s=t.getTime();let i;const o=this.state.relativeRange;if("day"===o)t.setHours(0),t.setMinutes(0),t.setSeconds(0),i=t.getTime();else if("week"===o){t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0);const e=t.getDay()||7;1!==e&&t.setHours(-24*(e-1)),i=t.getTime()}else if("2weeks"===o){t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(t.getDate()-7);const e=t.getDay()||7;1!==e&&t.setHours(-24*(e-1)),i=t.getTime()}else"month"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(1),i=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(1),t.setMonth(0),i=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setFullYear(t.getFullYear()-1),i=t.getTime()):i=s-6e4*parseInt(o,10);this.setState({start:i,end:s},(()=>this.readHistory())),this.timeTimer=setTimeout((()=>{this.timeTimer=void 0,this.shiftTime()}),e||6e4)}setRelativeInterval(t,e){if(e||(this.localStorage.setItem("App.relativeRange",t.toString()),this.setState({relativeRange:t})),"absolute"===t)return void(this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=void 0));this.localStorage.removeItem("App.absoluteStart"),this.localStorage.removeItem("App.absolute");const s=new Date;if(!this.timeTimer){const t=6e4-s.getSeconds()-(1e3-s.getMilliseconds());this.timeTimer=setTimeout((()=>{this.timeTimer=void 0,this.shiftTime()}),t||6e4)}s.getMilliseconds()&&s.setMilliseconds(1e3),s.getSeconds()&&s.setSeconds(60);const i=s.getTime();let o;if("day"===t)s.setHours(0),s.setMinutes(0),s.setSeconds(0),o=s.getTime();else if("week"===t){s.setHours(0),s.setMinutes(0),s.setSeconds(0);const t=s.getDay()||7;1!==t&&s.setHours(-24*(t-1)),o=s.getTime()}else if("2weeks"===t){s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setDate(s.getDate()-7);const t=s.getDay()||7;1!==t&&s.setHours(-24*(t-1)),o=s.getTime()}else"month"===t?(s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setDate(1),o=s.getTime()):"year"===t?(s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setDate(1),s.setMonth(0),o=s.getTime()):"12months"===t?(s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setFullYear(s.getFullYear()-1),o=s.getTime()):o=i-6e4*(t=Number(t));this.setState({start:o,end:i},(()=>this.readHistory()))}renderTable(){var t;if(!this.state.historyInstance)return(0,m.jsx)("div",{style:{marginTop:20,fontSize:24},children:this.props.t("History instance not selected")});if(null===(t=this.state.historyInstances)||void 0===t||!t.find((t=>t.id===this.state.historyInstance&&t.alive)))return(0,m.jsx)("div",{style:{marginTop:20,fontSize:24},children:this.props.t("History instance not alive")});if(this.state.values){const t=[200,"auto"],e=[190,100];return this.state.ackVisible&&(t.push(50),e.push(50)),this.state.fromVisible&&(t.push(150),e.push(150)),this.state.lcVisible&&(t.push(200),e.push(190)),(0,m.jsx)(a.TableContainer,{style:w.container,children:(0,m.jsxs)(l.TableResize,{stickyHeader:!0,sx:w.table,initialWidths:t,minWidths:e,dblTitle:this.props.t("ra_Double click to reset table layout"),children:[(0,m.jsx)(a.TableHead,{children:(0,m.jsxs)(a.TableRow,{children:[(0,m.jsx)(a.TableCell,{style:w.colTs,children:this.props.t("Timestamp")}),(0,m.jsx)(a.TableCell,{style:w.colValue,children:this.props.t("Value")}),this.state.ackVisible?(0,m.jsx)(a.TableCell,{style:w.colAck,children:this.props.t("Ack")}):null,this.state.fromVisible?(0,m.jsx)(a.TableCell,{style:w.colFrom,children:this.props.t("From")}):null,this.state.lcVisible?(0,m.jsx)(a.TableCell,{style:w.colLastChange,children:this.props.t("lc")}):null]})}),(0,m.jsx)(a.TableBody,{children:this.getTableRows()})]})})}return(0,m.jsx)(a.LinearProgress,{})}renderConfirmDialog(){return(0,m.jsxs)(a.Dialog,{open:!!this.state.areYouSure,onClose:()=>this.setState({areYouSure:!1}),"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[(0,m.jsx)(a.DialogTitle,{id:"alert-dialog-title"}),(0,m.jsxs)(a.DialogContent,{children:[(0,m.jsx)(a.DialogContentText,{id:"alert-dialog-description",children:this.props.t("Are you sure?")}),(0,m.jsx)(a.FormControlLabel,{control:(0,m.jsx)(a.Checkbox,{value:this.state.suppressMessage,onChange:()=>this.setState({suppressMessage:!0})}),label:this.props.t("Suppress for 5 minutes")})]}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.setState({areYouSure:!1,suppressMessage:this.state.suppressMessage&&Date.now()},(()=>this.onDelete())),color:"primary",autoFocus:!0,startIcon:(0,m.jsx)(n.Delete,{}),children:this.props.t("Delete")}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.setState({areYouSure:!1}),color:"secondary",startIcon:(0,m.jsx)(n.Close,{}),children:this.props.t("Cancel")})]})]})}onDelete(){const t=this.state.selected.map((t=>({state:{ts:t},id:this.props.obj._id})));this.props.socket.sendTo(this.state.historyInstance,"delete",t).then((()=>this.readHistory()))}onUpdate(){let t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?"number"!==typeof t&&(t=parseFloat(t.toString().replace(",","."))):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));const e={val:t,ack:this.state.edit.ack,ts:this.state.selected[0],from:`system.adapter.admin.${this.adminInstance}`,q:this.state.edit.q};for(const[s,i]of Object.entries(e))void 0===i&&delete e[s];!this.state.lcVisible&&e.lc&&delete e.lc,this.props.socket.sendTo(this.state.historyInstance,"update",[{id:this.props.obj._id,state:e}]).then((()=>this.readHistory()))}onInsert(){let t=this.state.edit.val;this.props.obj.common&&("number"===this.props.obj.common.type?t=parseFloat(t.toString().replace(",",".")):"boolean"===this.props.obj.common.type&&(t="true"===t||"TRUE"===t||!0===t||"1"===t||1===t));const e=this.state.edit.date;e.setHours(this.state.edit.time.getHours()),e.setMinutes(this.state.edit.time.getMinutes()),e.setSeconds(this.state.edit.time.getSeconds()),e.setMilliseconds(parseInt(this.state.edit.ms,10));const s={ts:e.getTime(),val:t,ack:this.state.edit.ack,from:`system.adapter.admin.${this.adminInstance}`,q:this.state.edit.q||0};!this.state.lcVisible&&s.lc&&delete s.lc;for(const[i,o]of Object.entries(s))void 0===o&&delete s[i];this.props.socket.sendTo(this.state.historyInstance,"insert",[{id:this.props.obj._id,state:s}]).then((()=>this.readHistory()))}updateEdit(t,e){const s=JSON.parse(JSON.stringify(this.state.edit));s.time=new Date(s.time),s.date=new Date(s.date),s[t]=e,this.setState({edit:s})}renderEditDialog(){return(0,m.jsxs)(a.Dialog,{open:this.state.updateOpened||this.state.insertOpened,onClose:()=>this.setState({updateOpened:!1,insertOpened:!1}),"aria-labelledby":"edit-dialog-title","aria-describedby":"edit-dialog-description",children:[(0,m.jsx)(a.DialogTitle,{id:"edit-dialog-title",children:this.state.updateOpened?this.props.t("Update entry"):this.props.t("Insert entry")}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsxs)("form",{noValidate:!0,autoComplete:"off",children:["boolean"===typeof this.state.edit.val?(0,m.jsx)(a.FormControlLabel,{control:(0,m.jsx)(a.Checkbox,{checked:this.state.edit.val,onChange:t=>this.updateEdit("val",t.target.checked)}),label:this.props.t("Value")}):(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Value"),value:this.state.edit.val,onChange:t=>this.updateEdit("val",t.target.value)}),(0,m.jsx)("br",{}),(0,m.jsx)(a.FormControlLabel,{control:(0,m.jsx)(a.Checkbox,{checked:this.state.edit.ack,onChange:t=>this.updateEdit("ack",t.target.checked)}),label:this.props.t("Acknowledged")}),this.state.insertOpened?(0,m.jsx)(b.LocalizationProvider,{dateAdapter:x.h,adapterLocale:y[this.props.lang],children:(0,m.jsxs)("div",{style:w.toolbarTimeGrid,children:[(0,m.jsx)("div",{style:w.toolbarTimeLabel,children:this.props.t("Time")}),(0,m.jsx)(b.DatePicker,{sx:w.toolbarDate,value:this.state.edit.date,onChange:t=>this.updateEdit("date",t)}),(0,m.jsx)(b.TimePicker,{sx:w.toolbarTime,ampm:this.state.ampm,views:["hours","minutes","seconds"],value:this.state.edit.time,onChange:t=>this.updateEdit("time",t)}),(0,m.jsx)(a.TextField,{variant:"standard",sx:w.msInput,helperText:this.props.t("ms"),type:"number",slotProps:{htmlInput:{max:999,min:0}},value:this.state.edit.ms,onChange:t=>this.updateEdit("ms",t.target.value)})]})}):null]})}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{variant:"contained",disabled:""===this.state.edit.val,onClick:()=>{const t=this.state.updateOpened;this.setState({updateOpened:!1,insertOpened:!1},(()=>t?this.onUpdate():this.onInsert()))},color:"primary",autoFocus:!0,children:this.state.updateOpened?this.props.t("Update"):this.props.t("Add")}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.setState({updateOpened:!1,insertOpened:!1}),color:"grey",children:this.props.t("Cancel")})]})]})}setStartDate(t){const e=t.getTime();this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=void 0),this.localStorage.setItem("App.relativeRange","absolute"),this.localStorage.setItem("App.absoluteStart",e.toString()),this.localStorage.setItem("App.absoluteEnd",this.state.end.toString()),this.setState({start:e,relativeRange:"absolute"},(()=>this.readHistory()))}setEndDate(t){const e=t.getTime();this.localStorage.setItem("App.relativeRange","absolute"),this.localStorage.setItem("App.absoluteStart",this.state.start.toString()),this.localStorage.setItem("App.absoluteEnd",e.toString()),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=void 0),this.setState({end:e,relativeRange:"absolute"},(()=>this.readHistory()))}renderToolbar(){var t,e;return(0,m.jsxs)(a.Toolbar,{children:[(0,m.jsxs)(a.FormControl,{variant:"standard",style:w.selectHistoryControl,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("History instance")}),(0,m.jsx)(a.Select,{variant:"standard",value:this.state.historyInstance||"",onChange:t=>{const e=t.target.value;this.localStorage.setItem("App.historyInstance",e),this.readSupportedFeatures(e).then((t=>this.setState({historyInstance:e,supportedFeatures:t},(()=>this.readHistory()))))},children:null===(t=this.state.historyInstances)||void 0===t?void 0:t.map((t=>(0,m.jsx)(a.MenuItem,{value:t.id,style:t.alive?void 0:w.notAliveInstance,children:t.id},t.id)))})]}),(0,m.jsxs)(a.FormControl,{variant:"standard",style:w.selectRelativeTime,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("Relative")}),(0,m.jsxs)(a.Select,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value),children:[(0,m.jsx)(a.MenuItem,{value:"absolute",sx:w.customRange,children:this.props.t("custom range")},"custom"),(0,m.jsx)(a.MenuItem,{value:10,children:this.props.t("last 10 minutes")},"1"),(0,m.jsx)(a.MenuItem,{value:30,children:this.props.t("last 30 minutes")},"2"),(0,m.jsx)(a.MenuItem,{value:60,children:this.props.t("last hour")},"3"),(0,m.jsx)(a.MenuItem,{value:"day",children:this.props.t("this day")},"4"),(0,m.jsx)(a.MenuItem,{value:1440,children:this.props.t("last 24 hours")},"5"),(0,m.jsx)(a.MenuItem,{value:"week",children:this.props.t("this week")},"6"),(0,m.jsx)(a.MenuItem,{value:10080,children:this.props.t("last week")},"7"),(0,m.jsx)(a.MenuItem,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),(0,m.jsx)(a.MenuItem,{value:20160,children:this.props.t("last 2 weeks")},"9"),(0,m.jsx)(a.MenuItem,{value:"month",children:this.props.t("this month")},"10"),(0,m.jsx)(a.MenuItem,{value:43200,children:this.props.t("last 30 days")},"11"),(0,m.jsx)(a.MenuItem,{value:"year",children:this.props.t("this year")},"12"),(0,m.jsx)(a.MenuItem,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),(0,m.jsxs)(b.LocalizationProvider,{dateAdapter:x.h,adapterLocale:y[this.props.lang],children:[(0,m.jsxs)("div",{style:w.toolbarTimeGrid,children:[(0,m.jsx)("div",{style:{...w.toolbarTimeLabel,opacity:"absolute"!==this.state.relativeRange?.5:void 0},children:this.props.t("Start time")}),(0,m.jsx)(b.DatePicker,{sx:w.toolbarDate,disabled:"absolute"!==this.state.relativeRange,value:new Date(this.state.start),onChange:t=>this.setStartDate(t)}),(0,m.jsx)(b.TimePicker,{disabled:"absolute"!==this.state.relativeRange,sx:w.toolbarTime,ampm:this.state.ampm,value:new Date(this.state.start),onChange:t=>this.setStartDate(t)})]}),(0,m.jsxs)("div",{style:w.toolbarTimeGrid,children:[(0,m.jsx)("div",{style:{...w.toolbarTimeLabel,opacity:"absolute"!==this.state.relativeRange?.5:void 0},children:this.props.t("End time")}),(0,m.jsx)(b.DatePicker,{disabled:"absolute"!==this.state.relativeRange,sx:w.toolbarDate,value:new Date(this.state.end),onChange:t=>this.setEndDate(t)}),(0,m.jsx)(b.TimePicker,{disabled:"absolute"!==this.state.relativeRange,sx:w.toolbarTime,ampm:this.state.ampm,value:new Date(this.state.end),onChange:t=>this.setEndDate(t)})]})]}),(0,m.jsx)(a.Box,{component:"div",sx:w.grow}),null!==(e=this.state.values)&&void 0!==e&&e.length?(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.exportData(),title:this.props.t("Save data as csv"),children:(0,m.jsx)(j.WCW,{})}):null,this.state.supportedFeatures.includes("insert")&&this.props.expertMode?(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>{const t=new Date,e={ack:this.state.values[this.state.values.length-1].ack,val:this.state.values[this.state.values.length-1].val,date:new Date(t),ms:0,time:new Date(t),q:0};this.setState({edit:e,insertOpened:!0})},children:(0,m.jsx)(j.Hw0,{})}):null,this.state.supportedFeatures.includes("update")&&this.props.expertMode?(0,m.jsx)(a.IconButton,{size:"large",disabled:1!==this.state.selected.length,onClick:()=>{const t=JSON.parse(JSON.stringify(this.state.values.find((t=>t.ts===this.state.lastSelected)))),e=new Date(t.ts);t.date=new Date(e),t.time=new Date(e),this.setState({edit:t,updateOpened:!0})},children:(0,m.jsx)(n.Edit,{})}):null,this.state.supportedFeatures.includes("delete")&&this.props.expertMode?(0,m.jsx)(a.IconButton,{size:"large",disabled:!this.state.selected.length,onClick:()=>{"number"===typeof this.state.suppressMessage&&Date.now()-this.state.suppressMessage<3e5?this.onDelete():this.setState({areYouSure:!0})},children:(0,m.jsx)(n.Delete,{})}):null]})}exportData(){let t=window.document.getElementById("export-file");t||(t=document.createElement("a"),t.setAttribute("id","export-file"),t.style.display="none",document.body.appendChild(t));const e=["timestamp;value;acknowledged;from;"];this.state.values.forEach((t=>!t.i&&!t.e&&e.push([C.formatTimestamp(t.ts),null===t.val||void 0===t.val?"null":t.val.toString(),t.ack?"true":"false",t.from||""].join(";")))),t.setAttribute("href",`data:text/plain;charset=utf-8,${encodeURIComponent(e.join("\n"))}`),t.setAttribute("download",`${l.Utils.getObjectName({[this.props.obj._id]:this.props.obj},this.props.obj._id,this.props.lang)}.csv`),t.click(),document.body.removeChild(t)}render(){return this.state.historyInstances?(0,m.jsxs)(a.Paper,{style:w.paper,children:[this.state.loading?(0,m.jsx)(a.LinearProgress,{}):(0,m.jsx)("div",{style:w.noLoadingProgress}),this.renderToolbar(),(0,m.jsx)(a.Box,{component:"div",sx:w.tableDiv,children:this.renderTable()}),this.renderConfirmDialog(),this.renderEditDialog()]}):(0,m.jsx)(a.LinearProgress,{})}static formatTimestamp(t){return`${new Date(t).toLocaleDateString()} ${new Date(t).toLocaleTimeString()}.${(t%1e3).toString().padStart(3,"0")}`}}const S=(0,l.withWidth)()(C);var I=s(37821),A=s(78940),T=s(34514),k=s(70073),D=s(31446),F=s(28440),R=s(80935),E=s(59173),O=s(58922),M=s(830);A.Y([D.a,F.a,R.a,E.a,O.a,k.a,M.a]);const N={paper:{height:"100%",maxHeight:"100%",maxWidth:"100%",overflow:"hidden",width:"100%"},chart:{width:"100%",overflow:"hidden"},chartWithToolbar:t=>({height:`calc(100% - ${parseInt(t.mixins.toolbar.minHeight,10)+8}px)`}),chartWithoutToolbar:{height:"100%"},selectHistoryControl:{width:130},selectRelativeTime:{marginLeft:10,width:200},notAliveInstance:{opacity:.5},customRange:t=>({color:t.palette.primary.main}),splitLineButtonIcon:{marginRight:8},grow:{flexGrow:1},toolbarDate:{width:124,mt:"9px","& fieldset":{display:"none"},"& input":{padding:"8px 0 0 0"},"& .MuiInputAdornment-root":{ml:0,mt:"7px"}},toolbarTime:{width:84,mt:"9px","& fieldset":{display:"none"},"& input":{padding:"8px 0 0 0"},"& .MuiInputAdornment-root":{ml:0,mt:"7px"}},toolbarTimeLabel:{position:"absolute",padding:8,fontSize:"0.8rem",left:2,top:-9},toolbarTimeGrid:{position:"relative",marginLeft:8,paddingLeft:8,paddingRight:8,paddingTop:4,paddingBottom:4,border:"1px dotted #AAAAAA",borderRadius:8,display:"flex"},buttonIcon:{width:24,height:24},echartsButton:{marginRight:8,height:34,width:34}},W=80,V=25;class L extends i.Component{constructor(t){if(super(t),this.echartsReact=void 0,this.rangeRef=void 0,this.readTimeout=null,this.chartValues=void 0,this.rangeValues=void 0,this.subscribes=void 0,this.unit=void 0,this.divRef=void 0,this.chart=void 0,this.timerResize=null,this.updateTimer=null,this.minY=void 0,this.maxY=void 0,this.timeTimer=null,this.maxYLenTimeout=null,this.mouseDown=void 0,this.start=void 0,this.end=void 0,this.localStorage=void 0,this.onResize=()=>{this.timerResize&&clearTimeout(this.timerResize),this.timerResize=setTimeout((()=>{this.timerResize=null,this.componentDidUpdate()}))},this.onChange=(t,e)=>{if(t===this.props.obj._id&&e&&this.rangeValues&&(!this.rangeValues.length||this.rangeValues[this.rangeValues.length-1].ts<e.ts))(!this.state.max||e.ts-this.state.max<12e4)&&(this.chartValues&&this.chartValues.push({val:e.val,ts:e.ts}),this.rangeValues.push({val:e.val,ts:e.ts}),e.ts>=this.chart.min&&e.ts<=this.chart.max+3e5&&this.updateChart());else if(t.startsWith("system.adapter.")&&t.endsWith(".alive")&&this.state.historyInstances){const s=t.substring(15,t.length-6),i=this.state.historyInstances,o=i.findIndex((t=>t.id===s));if(-1!==o&&i[o].alive!==!(null===e||void 0===e||!e.val)){const t=JSON.parse(JSON.stringify(i));t[o].alive=!(null===e||void 0===e||!e.val),this.setState({historyInstances:t},(()=>{t[o].alive&&this.state.historyInstance===s&&this.readHistoryRange().then((()=>this.updateChart()))}))}}},this.localStorage=window._localStorage||window.localStorage,this.props.from)this.start=this.props.from;else{const t=new Date;t.setHours(t.getHours()-168),this.start=t.getTime()}this.props.end?this.end=this.props.end:this.end=Date.now();let e=this.localStorage.getItem("App.relativeRange")||"30";const s=parseInt(this.localStorage.getItem("App.absoluteStart"),10)||0,o=parseInt(this.localStorage.getItem("App.absoluteEnd"),10)||0;s&&o||e&&"absolute"!==e||(e="30"),o&&s&&(e="absolute"),this.state={historyInstance:this.props.historyInstance||"",historyInstances:null,defaultHistory:"",chartHeight:300,chartWidth:500,ampm:!1,relativeRange:e,splitLine:"true"===this.localStorage.getItem("App.splitLine"),min:s,max:o,maxYLen:0,stepType:"",echartsJump:!1},this.echartsReact=null,this.rangeRef=(0,i.createRef)(),this.readTimeout=null,this.chartValues=null,this.rangeValues=null,this.subscribes=[],this.unit=this.props.obj.common&&this.props.obj.common.unit?` ${this.props.obj.common.unit}`:"",this.divRef=(0,i.createRef)(),this.chart={}}componentDidMount(){this.props.socket.subscribeState(this.props.obj._id,this.onChange),window.addEventListener("resize",this.onResize),this.prepareData().then((()=>!this.props.noToolbar&&this.readHistoryRange())).then((()=>this.setRelativeInterval(this.state.relativeRange,!0,(()=>this.forceUpdate()))))}componentWillUnmount(){this.readTimeout&&(clearTimeout(this.readTimeout),this.readTimeout=null),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.maxYLenTimeout&&(clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=null),this.timerResize&&(clearTimeout(this.timerResize),this.timerResize=null),this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null),this.echartsReact&&this.echartsReact.getEchartsInstance().dispose();for(let t=0;t<this.subscribes.length;t++)this.props.socket.unsubscribeState(this.subscribes[t],this.onChange);this.subscribes=[],this.props.socket.unsubscribeState(this.props.obj._id,this.onChange),window.removeEventListener("resize",this.onResize)}async prepareData(){var t;if(this.props.noToolbar){const t=this.props.defaultHistory&&await this.props.socket.getState(`system.adapter.${this.props.defaultHistory}.alive`);return this.subscribes.length||(this.subscribes=[`system.adapter.${this.props.defaultHistory}.alive`],await this.props.socket.subscribeState(`system.adapter.${this.props.defaultHistory}.alive`,this.onChange)),void await new Promise((e=>{this.setState({defaultHistory:this.props.defaultHistory,historyInstance:this.props.defaultHistory,historyInstances:[{id:this.props.defaultHistory,alive:!(null===t||void 0===t||!t.val)}]},(()=>e(null)))}))}let e=await this.getHistoryInstances();const s=await this.props.socket.getCompactSystemConfig();let i=[];this.props.showJumpToEchart&&(i=await this.props.socket.getAdapterInstances("echarts",!0));const o=!!i.find((t=>t._id.startsWith("system.adapter.echarts."))),a=s&&s.common&&s.common.defaultHistory;this.props.obj.common.custom&&(e=e.filter((t=>this.props.obj.common.custom[t.id])));let n=this.localStorage.getItem("App.historyInstance")||"";if(n&&e.find((t=>t.id===n&&t.alive))||(n=a),!n||!e.find((t=>t.id===n&&t.alive))){const t=e.find((t=>t.alive));t&&(n=t.id)}!n&&e.length&&(n=a),this.setState({ampm:s.common.dateFormat.includes("/"),historyInstances:e,defaultHistory:a,historyInstance:n,echartsJump:o,stepType:this.props.obj.common.custom&&(null===(t=this.props.obj.common.custom[n])||void 0===t?void 0:t.chartStep)||""})}getHistoryInstances(){if(this.props.historyInstance)return Promise.resolve([]);const t=[],e=[];return this.props.customsInstances.forEach((s=>{var i;const o=this.props.objects[`system.adapter.${s}`];if(null!==o&&void 0!==o&&null!==(i=o.common)&&void 0!==i&&i.getHistory){const i={id:s,alive:!1};t.push(i),e.push(`system.adapter.${s}.alive`)}})),e.length?this.props.socket.getForeignStates(e).then((async s=>{Object.keys(s).forEach((e=>{const i=t.find((t=>e.endsWith(`${t.id}.alive`)));var o;i&&(i.alive=!(null===(o=s[e])||void 0===o||!o.val))})),this.subscribes=e;for(let t=0;t<e.length;t++)await this.props.socket.subscribeState(e[t],this.onChange);return t})):Promise.resolve(t)}readHistoryRange(){var t;const e=new Date,s=new Date(2e3,0,1);return null!==(t=this.state.historyInstances)&&void 0!==t&&t.find((t=>t.id===this.state.historyInstance&&t.alive))?this.props.socket.getHistory(this.props.obj._id,{instance:this.state.historyInstance,start:s.getTime(),end:e.getTime(),limit:1,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none"}).then((t=>{var e;t&&null===(null===(e=t[0])||void 0===e?void 0:e.val)&&t.shift(),this.rangeValues=t})):Promise.resolve()}readHistory(t,e){var s;if(!this.state.historyInstance||null===(s=this.state.historyInstances)||void 0===s||!s.find((t=>t.id===this.state.historyInstance&&t.alive)))return Promise.resolve([]);const i={instance:this.state.historyInstance,start:t,end:e,from:!1,ack:!1,q:!1,addID:!1,aggregate:"none",returnNewestEntries:!0};return e-t>144e4&&!("boolean"===this.props.obj.common.type||"number"===this.props.obj.common.type&&this.props.obj.common.states)&&(i.aggregate="minmax"),this.props.socket.getHistory(this.props.obj._id,i).then((t=>{const e=[];let s=0;const i=this.rangeValues;let o=null,a=null;for(let n=0;n<t.length;n++){if(i)for(;s<i.length&&i[s].ts<t[n].ts;)e.push(i[s]),s++;!e.length||e[e.length-1].ts<t[n].ts?e.push(t[n]):e[e.length-1].ts===t[n].ts&&e[e.length-1].val!==t[n].ts&&console.error("Strange data!"),(null===o||t[n].val<o)&&(o=t[n].val),(null===a||t[n].val>a)&&(a=t[n].val)}if(i)for(;s<i.length;)e.push(i[s]),console.log(`add range ${new Date(i[s].ts).toISOString()}: ${i[s].val}`),s++;return e.sort(((t,e)=>t.ts>e.ts?1:t.ts<e.ts?-1:0)),this.chartValues=e,this.minY=o,this.maxY=a,this.minY<10?this.minY=Math.round(10*this.minY)/10:this.minY=Math.ceil(this.minY),this.maxY<10?this.maxY=Math.round(10*this.maxY)/10:this.maxY=Math.ceil(this.maxY),e}))}convertData(t){const e=[];if(!(t=t||this.chartValues).length)return[];for(let s=0;s<t.length;s++){const i={value:[t[s].ts,t[s].val]};t[s].i&&(i.exact=!1),e.push(i)}return this.chart.min||(this.chart.min=t[0].ts,this.chart.max=t[t.length-1].ts),e}getOption(){let t;if(null!==this.minY&&void 0!==this.minY&&(t=9*(this.minY.toString()+this.unit).length+12),null!==this.maxY&&void 0!==this.maxY){const e=9*(this.maxY.toString()+this.unit).length+12;e>t&&(t=e)}if(this.state.maxYLen){const e=9*this.state.maxYLen+12;e>t&&(t=e)}const e={xAxisIndex:0,type:"line",step:"stepStart"===this.state.stepType?"start":"stepMiddle"===this.state.stepType?"middle":"stepEnd"===this.state.stepType?"end":void 0,showSymbol:!1,hoverAnimation:!0,animation:!1,data:this.convertData(),lineStyle:{color:"#4dabf5"},areaStyle:{}},s={type:"value",boundaryGap:[0,"100%"],splitLine:{show:this.props.noToolbar||!!this.state.splitLine},splitNumber:Math.round(this.state.chartHeight/50),axisLabel:{formatter:t=>{let e;return e=this.props.isFloatComma?t.toString().replace(",",".")+this.unit:t+this.unit,this.state.maxYLen<e.length&&(this.maxYLenTimeout&&clearTimeout(this.maxYLenTimeout),this.maxYLenTimeout=setTimeout((t=>{this.maxYLenTimeout=null,this.setState({maxYLen:t})}),200,e.length)),e},showMaxLabel:!0,showMinLabel:!0},axisTick:{alignWithLabel:!0}};if("boolean"===this.props.obj.common.type)e.step="end",s.axisLabel.showMaxLabel=!1,s.axisLabel.formatter=t=>1===t?"TRUE":"FALSE",s.max=1.5,s.interval=1,t=50;else if("number"===this.props.obj.common.type&&this.props.obj.common.states){e.step="end",s.axisLabel.showMaxLabel=!1;const i=this.props.obj.common.states;s.axisLabel.formatter=t=>void 0!==i[t]?i[t]:t;const o=Object.keys(this.props.obj.common.states);o.sort(),s.max=parseFloat(o[o.length-1])+.5,s.interval=1;let a="";for(let t=0;t<o.length;t++)"string"===typeof i[o[t]]&&i[o[t]].length>a.length&&(a=i[o[t]]);t=(9*a.length||50)+12}const i=this.chart.withSeconds?Math.round((this.state.chartWidth-V-W)/100):Math.round((this.state.chartWidth-V-W)/60);return{backgroundColor:"transparent",title:{text:this.props.noToolbar?"":l.Utils.getObjectNameFromObj(this.props.obj,this.props.lang),padding:[10,0,0,t?t+10:90]},grid:{left:t||W,top:8,right:this.props.noToolbar?5:V,bottom:40},tooltip:{trigger:"axis",formatter:t=>{const e=t[0],s=new Date(e.value[0]);let i=e.value[1];return null!==i&&this.props.isFloatComma&&(i=i.toString().replace(".",",")),`${!1===e.exact?"i":""}${s.toLocaleString()}.${s.getMilliseconds().toString().padStart(3,"0")}: ${i}${this.unit}`},axisPointer:{animation:!0}},xAxis:{type:"time",splitLine:{show:!1},splitNumber:i,min:this.chart.min,max:this.chart.max,axisTick:{alignWithLabel:!0},axisLabel:{formatter:t=>{const e=new Date(t);return this.chart.withSeconds?`${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}`:this.chart.withTime?`${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}\n${e.getDate().toString().padStart(2,"0")}.${(e.getMonth()+1).toString().padStart(2,"0")}`:`${e.getDate().toString().padStart(2,"0")}.${(e.getMonth()+1).toString().padStart(2,"0")}\n${e.getFullYear()}`}}},yAxis:s,toolbox:{left:"right",feature:this.props.noToolbar?void 0:{saveAsImage:{title:this.props.t("Save as image"),show:!0}}},series:[e]}}static getDerivedStateFromProps(t,e){return null}updateChart(t,e,s,i){t&&(this.start=t),e&&(this.end=e),t=t||this.start,e=e||this.end,this.readTimeout&&clearTimeout(this.readTimeout),this.readTimeout=setTimeout((()=>{this.readTimeout=null;const o=this.chart.max-this.chart.min;var a;(o!==this.chart.diff&&(this.chart.diff=o,this.chart.withTime=this.chart.diff<6048e5,this.chart.withSeconds=this.chart.diff<18e5),s)?this.readHistory(t,e).then((t=>{var e;"function"===typeof(null===(e=this.echartsReact)||void 0===e?void 0:e.getEchartsInstance)&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData(t)}],xAxis:{min:this.chart.min,max:this.chart.max}}),i&&i()})):("function"===typeof(null===(a=this.echartsReact)||void 0===a?void 0:a.getEchartsInstance)&&this.echartsReact.getEchartsInstance().setOption({series:[{data:this.convertData()}],xAxis:{min:this.chart.min,max:this.chart.max}}),i&&i())}),400)}setNewRange(t){var 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.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null)):"function"===typeof(null===(e=this.echartsReact)||void 0===e?void 0:e.getEchartsInstance)&&(this.echartsReact.getEchartsInstance().setOption({xAxis:{min:this.chart.min,max:this.chart.max}}),t&&this.updateChart(this.chart.min,this.chart.max,!0))}shiftTime(){const t=new Date,e=6e4-t.getSeconds()-(1e3-t.getMilliseconds());t.getMilliseconds()&&t.setMilliseconds(1e3),t.getSeconds()&&t.setSeconds(60);const s=t.getTime();let i;const o=this.state.relativeRange;if("day"===o)t.setHours(0),t.setMinutes(0),t.setSeconds(0),i=t.getTime();else if("week"===o){t.setHours(0),t.setMinutes(0),t.setSeconds(0);const e=t.getDay()||7;1!==e&&t.setHours(-24*(e-1)),i=t.getTime()}else if("2weeks"===o){t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(t.getDate()-7);const e=t.getDay()||7;1!==e&&t.setHours(-24*(e-1)),i=t.getTime()}else"month"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(1),i=t.getTime()):"year"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setDate(1),t.setMonth(0),i=t.getTime()):"12months"===o?(t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setFullYear(t.getFullYear()-1),i=t.getTime()):i=s-6e4*parseInt(o,10);this.chart.min=i,this.chart.max=s,this.setState({min:i,max:s},(()=>this.updateChart(this.chart.min,this.chart.max,!0))),this.timeTimer=setTimeout((()=>{this.timeTimer=null,this.shiftTime()}),e||6e4)}setRelativeInterval(t,e,s){if(e||(this.localStorage.setItem("App.relativeRange",t),this.setState({relativeRange:t})),"absolute"===t)return this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),void this.updateChart(this.chart.min,this.chart.max,!0,s);this.localStorage.removeItem("App.absoluteStart"),this.localStorage.removeItem("App.absoluteEnd");const i=new Date;if(!this.timeTimer){const t=6e4-i.getSeconds()-(1e3-i.getMilliseconds());this.timeTimer=setTimeout((()=>{this.timeTimer=null,this.shiftTime()}),t||6e4)}if(i.getMilliseconds()&&i.setMilliseconds(1e3),i.getSeconds()&&i.setSeconds(60),this.chart.max=i.getTime(),"day"===t)i.setHours(0),i.setMinutes(0),i.setSeconds(0),this.chart.min=i.getTime();else if("week"===t){i.setHours(0),i.setMinutes(0),i.setSeconds(0);const t=i.getDay()||7;1!==t&&i.setHours(-24*(t-1)),this.chart.min=i.getTime()}else if("2weeks"===t){i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setDate(i.getDate()-7);const t=i.getDay()||7;1!==t&&i.setHours(-24*(t-1)),this.chart.min=i.getTime()}else"month"===t?(i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setDate(1),this.chart.min=i.getTime()):"year"===t?(i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setDate(1),i.setMonth(0),this.chart.min=i.getTime()):"12months"===t?(i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setFullYear(i.getFullYear()-1),this.chart.min=i.getTime()):this.chart.min=this.chart.max-6e4*parseInt(t,10);this.setState({min:this.chart.min,max:this.chart.max},(()=>this.updateChart(this.chart.min,this.chart.max,!0,s)))}installEventHandlers(){if(!this.echartsReact||"function"!==typeof this.echartsReact.getEchartsInstance)return;const t=this.echartsReact.getEchartsInstance().getZr();t._iobInstalled||(t._iobInstalled=!0,t.on("mousedown",(t=>{console.log("mouse down"),this.mouseDown=!0,this.chart.lastX=t.offsetX})),t.on("mouseup",(()=>{console.log("mouse up"),this.mouseDown=!1,this.setNewRange(!0)})),t.on("mousewheel",(t=>{let e=this.chart.max-this.chart.min;const s=this.state.chartWidth-V-W,i=(t.offsetX-W)/s,o=e;e*=t.wheelDelta>0?1.1:.9;const a=o-e;this.chart.max+=a*(1-i),this.chart.min-=a*i,this.setNewRange()})),t.on("mousemove",(t=>{if(this.mouseDown){const e=this.chart.lastX-(t.offsetX-W);this.chart.lastX=t.offsetX-W;const s=this.chart.max-this.chart.min,i=this.state.chartWidth-V-W,o=Math.round(e*s/i);this.chart.min+=o,this.chart.max+=o,this.setNewRange()}})),t.on("touchstart",(t=>{t.preventDefault(),this.mouseDown=!0;const e=t.touches||t.originalEvent.touches;e&&(this.chart.lastX=e[e.length-1].pageX,e.length>1?this.chart.lastWidth=Math.abs(e[0].pageX-e[1].pageX):this.chart.lastWidth=null)})),t.on("touchend",(t=>{t.preventDefault(),this.mouseDown=!1,this.setNewRange(!0)})),t.on("touchmove",(t=>{t.preventDefault();const e=t.touches||t.originalEvent.touches;if(!e)return;const s=e[e.length-1].pageX-W;if(this.mouseDown)if(e.length>1){const t=Math.abs(e[0].pageX-e[1].pageX);if(null!==this.chart.lastWidth&&t!==this.chart.lastWidth){let s=this.chart.max-this.chart.min;const i=this.state.chartWidth-V-W,o=t>this.chart.lastWidth?1.1:.9,a=(e[0].pageX>e[1].pageX?e[1].pageX-W+t/2:e[0].pageX-W+t/2)/i,n=s;s*=o;const l=n-s;this.chart.max+=l*(1-a),this.chart.min-=l*a,this.setNewRange()}this.chart.lastWidth=t}else{const t=this.chart.lastX-s,e=this.chart.max-this.chart.min,i=this.state.chartWidth-V-W,o=Math.round(t*e/i);this.chart.min+=o,this.chart.max+=o,this.setNewRange()}this.chart.lastX=s})))}renderChart(){var t;return this.state.historyInstance?null!==(t=this.state.historyInstances)&&void 0!==t&&t.find((t=>t.id===this.state.historyInstance&&t.alive))?this.chartValues?(0,m.jsx)(I.A,{ref:t=>this.echartsReact=t,echarts:T,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:()=>this.installEventHandlers()}}):(0,m.jsx)(a.LinearProgress,{}):(0,m.jsx)("div",{style:{marginTop:20,fontSize:24,marginLeft:24},children:this.props.t("History instance not alive")}):(0,m.jsx)("div",{style:{marginTop:20,fontSize:24,marginLeft:24},children:this.props.t("History instance not selected")})}componentDidUpdate(){if(this.divRef.current){const t=this.divRef.current.offsetWidth,e=this.divRef.current.offsetHeight;this.state.chartHeight!==e&&(this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout((()=>{this.updateTimer=null,this.setState({chartHeight:e,chartWidth:t})}),100))}}setStartDate(t){const e=t.getTime();this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.localStorage.setItem("App.relativeRange","absolute"),this.localStorage.setItem("App.absoluteStart",e.toString()),this.localStorage.setItem("App.absoluteEnd",this.state.max.toString()),this.chart.min=e,this.setState({min:e,relativeRange:"absolute"},(()=>this.updateChart(this.chart.min,this.chart.max,!0)))}setEndDate(t){const e=t.getTime();this.localStorage.setItem("App.relativeRange","absolute"),this.localStorage.setItem("App.absoluteStart",this.state.min.toString()),this.localStorage.setItem("App.absoluteEnd",e.toString()),this.timeTimer&&(clearTimeout(this.timeTimer),this.timeTimer=null),this.chart.max=e,this.setState({max:e,relativeRange:"absolute"},(()=>this.updateChart(this.chart.min,this.chart.max,!0)))}openEcharts(){const t=[`id=${window.encodeURIComponent(this.props.obj._id)}`,`instance=${window.encodeURIComponent(this.state.historyInstance)}`,"menuOpened=false"];"absolute"===this.state.relativeRange?(t.push(`start=${this.chart.min}`),t.push(`end=${this.chart.max}`)):t.push(`range=${this.state.relativeRange}`),window.open(`${window.location.protocol}//${window.location.host}/adapter/echarts/tab.html#${t.join("&")}`,"echarts")}async onStepChanged(t){const e=await this.props.socket.getObject(this.props.obj._id);e.common.custom&&e.common.custom[this.state.historyInstance]&&e.common.custom[this.state.historyInstance].chartStep!==t&&(e.common.custom[this.state.historyInstance].chartStep=t,await this.props.socket.setObject(e._id,e)),this.setState({stepType:t,showStepMenu:null})}renderToolbar(){return this.props.noToolbar?null:(0,m.jsxs)(a.Toolbar,{children:[!this.props.historyInstance&&(0,m.jsxs)(a.FormControl,{variant:"standard",style:N.selectHistoryControl,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("History instance")}),(0,m.jsx)(a.Select,{variant:"standard",value:this.state.historyInstance,onChange:t=>{this.localStorage.setItem("App.historyInstance",t.target.value),this.setState({historyInstance:t.target.value})},children:this.state.historyInstances.map((t=>(0,m.jsx)(a.MenuItem,{value:t.id,style:t.alive?void 0:N.notAliveInstance,children:t.id},t.id)))})]}),(0,m.jsxs)(a.FormControl,{variant:"standard",style:N.selectRelativeTime,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("Relative")}),(0,m.jsxs)(a.Select,{variant:"standard",ref:this.rangeRef,value:this.state.relativeRange,onChange:t=>this.setRelativeInterval(t.target.value),children:[(0,m.jsx)(a.MenuItem,{value:"absolute",sx:N.customRange,children:this.props.t("custom range")},"custom"),(0,m.jsx)(a.MenuItem,{value:10,children:this.props.t("last 10 minutes")},"1"),(0,m.jsx)(a.MenuItem,{value:30,children:this.props.t("last 30 minutes")},"2"),(0,m.jsx)(a.MenuItem,{value:60,children:this.props.t("last hour")},"3"),(0,m.jsx)(a.MenuItem,{value:"day",children:this.props.t("this day")},"4"),(0,m.jsx)(a.MenuItem,{value:1440,children:this.props.t("last 24 hours")},"5"),(0,m.jsx)(a.MenuItem,{value:"week",children:this.props.t("this week")},"6"),(0,m.jsx)(a.MenuItem,{value:10080,children:this.props.t("last week")},"7"),(0,m.jsx)(a.MenuItem,{value:"2weeks",children:this.props.t("this 2 weeks")},"8"),(0,m.jsx)(a.MenuItem,{value:20160,children:this.props.t("last 2 weeks")},"9"),(0,m.jsx)(a.MenuItem,{value:"month",children:this.props.t("this month")},"10"),(0,m.jsx)(a.MenuItem,{value:43200,children:this.props.t("last 30 days")},"11"),(0,m.jsx)(a.MenuItem,{value:"year",children:this.props.t("this year")},"12"),(0,m.jsx)(a.MenuItem,{value:"12months",children:this.props.t("last 12 months")},"13")]})]}),(0,m.jsxs)(b.LocalizationProvider,{dateAdapter:x.h,adapterLocale:y[this.props.lang],children:[(0,m.jsxs)("div",{style:N.toolbarTimeGrid,children:[(0,m.jsx)("div",{style:{...N.toolbarTimeLabel,opacity:"absolute"!==this.state.relativeRange?.5:void 0},children:this.props.t("Start time")}),(0,m.jsx)(b.DatePicker,{sx:N.toolbarDate,disabled:"absolute"!==this.state.relativeRange,value:new Date(this.state.min),onChange:t=>this.setStartDate(t)}),(0,m.jsx)(b.TimePicker,{disabled:"absolute"!==this.state.relativeRange,sx:N.toolbarTime,ampm:this.state.ampm,value:new Date(this.state.min),onChange:t=>this.setStartDate(t)})]}),(0,m.jsxs)("div",{style:N.toolbarTimeGrid,children:[(0,m.jsx)("div",{style:{...N.toolbarTimeLabel,opacity:"absolute"!==this.state.relativeRange?.5:void 0},children:this.props.t("End time")}),(0,m.jsx)(b.DatePicker,{disabled:"absolute"!==this.state.relativeRange,sx:N.toolbarDate,value:new Date(this.state.max),onChange:t=>this.setEndDate(t)}),(0,m.jsx)(b.TimePicker,{disabled:"absolute"!==this.state.relativeRange,sx:N.toolbarTime,ampm:this.state.ampm,value:new Date(this.state.max),onChange:t=>this.setEndDate(t)})]})]}),(0,m.jsx)("div",{style:N.grow}),(0,m.jsx)(a.Button,{style:{marginRight:10},variant:"outlined",onClick:t=>this.setState({showStepMenu:t.target}),children:this.state.stepType?this.props.t(this.state.stepType):this.props.t("Step type")}),this.state.showStepMenu?(0,m.jsxs)(a.Menu,{open:!0,anchorEl:this.state.showStepMenu,onClose:()=>this.setState({showStepMenu:null}),children:[(0,m.jsx)(a.MenuItem,{selected:""===this.state.stepType,onClick:()=>this.onStepChanged(""),children:this.props.t("None")}),(0,m.jsx)(a.MenuItem,{selected:"stepStart"===this.state.stepType,onClick:()=>this.onStepChanged("stepStart"),children:this.props.t("stepStart")})]}):null,this.props.showJumpToEchart&&this.state.echartsJump&&(0,m.jsx)(a.Fab,{style:N.echartsButton,size:"small",onClick:()=>this.openEcharts(),title:this.props.t("Open charts in new window"),children:(0,m.jsx)("img",{src:"data:image/png;base64,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",alt:"echarts",style:N.buttonIcon})}),(0,m.jsxs)(a.Fab,{variant:"extended",size:"small",color:this.state.splitLine?"primary":"default","aria-label":"show lines",onClick:()=>{this.localStorage.setItem("App.splitLine",this.state.splitLine?"false":"true"),this.setState({splitLine:!this.state.splitLine})},children:[(0,m.jsx)(j.YYR,{style:N.splitLineButtonIcon}),this.props.t("Show lines")]})]})}render(){return this.state.historyInstances||this.state.defaultHistory?(0,m.jsxs)(a.Paper,{style:N.paper,children:[this.renderToolbar(),(0,m.jsx)("div",{ref:this.divRef,style:l.Utils.getStyle(this.props.theme,N.chart,this.props.noToolbar?N.chartWithoutToolbar:N.chartWithToolbar),children:this.renderChart()})]}):(0,m.jsx)(a.LinearProgress,{})}}const H=(0,l.withWidth)()(L);var B=s(25424);const J={dialog:{height:"100%"},paper:{height:"calc(100% - 64px)"},content:{textAlign:"center",overflow:"hidden"},tabPanel:t=>({width:"100%",overflow:"hidden",height:`calc(100% - ${t.mixins.toolbar.minHeight}px)`}),tabSelected:t=>({color:"dark"===t.palette.mode?t.palette.secondary.contrastText:"#FFFFFF !important"}),tabsIndicator:t=>({backgroundColor:t.palette.secondary.main})};class P extends B.A{constructor(t){super(t),this.chartAvailable=void 0,this.saveFunc=null;let e=parseInt((window._localStorage||window.localStorage).getItem("App.objectCustomTab")||"0",10);if(this.chartAvailable=this.isChartAvailable(),this.chartAvailable){const t=l.Router.getLocation();"chart"===t.arg?e=2:"table"===t.arg&&(e=1)}else e=0;this.state={hasChanges:!1,currentTab:e,confirmDialog:!1,mobile:B.A.isMobile(),progressRunning:!1,showWarning:this.props.allVisibleObjects}}isChartAvailable(){let t=1===this.props.objectIDs.length;if(t){var e,s;const i=this.props.objectIDs[0];t=!(null===(e=this.props.objects[i])||void 0===e||null===(s=e.common)||void 0===s||!s.custom)&&!!Object.keys(this.props.objects[i].common.custom).find((t=>{const e=this.props.objects[`system.adapter.${t}`];return e&&e.common&&e.common.getHistory}))}return t}renderCharts(){return(0,m.jsx)(H,{id:"custom-tabpanel-chart",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,theme:this.props.theme,objects:this.props.objects})}renderTable(){return(0,m.jsx)(S,{id:"custom-tabpanel-history",t:this.props.t,isFloatComma:this.props.isFloatComma,lang:this.props.lang,expertMode:this.props.expertMode,socket:this.props.socket,obj:this.props.objects[this.props.objectIDs[0]],customsInstances:this.props.customsInstances,themeName:this.props.themeName,objects:this.props.objects})}renderCustomEditor(){return(0,m.jsx)(v,{id:"custom-tabpanel-settings",registerSaveFunc:t=>this.saveFunc=t,t:this.props.t,allVisibleObjects:this.props.allVisibleObjects,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:t=>this.setState({progressRunning:t}),reportChangedIds:this.props.reportChangedIds,onChange:(t,e)=>{this.setState({hasChanges:t},(()=>{if(e){const t=this.isChartAvailable();t!==this.chartAvailable&&(this.chartAvailable=t,this.forceUpdate())}}))},theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType,systemConfig:this.props.systemConfig})}renderConfirmDialog(){return this.state.confirmDialog?(0,m.jsx)(l.Confirm,{title:l.I18n.t("You have unsaved changes"),text:l.I18n.t("Discard?"),ok:l.I18n.t("Yes"),cancel:l.I18n.t("Cancel"),onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this.props.onClose()))}):null}onClose(){this.state.hasChanges?this.setState({confirmDialog:!0}):this.props.onClose()}renderWarningDialog(){return this.state.showWarning?(0,m.jsx)(l.Confirm,{text:(0,m.jsx)("div",{style:{color:"#F00"},children:this.props.t("Your are intend to edit ALL objects. Are you sure?")}),ok:this.props.t("Yes"),onClose:t=>{this.setState({showWarning:!1}),t||this.onClose()}}):null}render(){var t,e;const s=null===(t=this.props.objects[this.props.objectIDs[0]])||void 0===t||null===(e=t.common)||void 0===e?void 0:e.type;return(0,m.jsxs)(a.Dialog,{sx:{"&.MuiDialog-scrollPaper":J.dialog,"& .MuiDialog-paper":J.paper},scroll:"paper",open:!0,onClose:()=>this.props.onClose(),fullWidth:!0,maxWidth:"xl","aria-labelledby":"form-dialog-title",children:[this.renderConfirmDialog(),this.renderWarningDialog(),(0,m.jsx)(a.DialogTitle,{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])}),(0,m.jsxs)(a.DialogContent,{style:J.content,children:[(0,m.jsx)(a.AppBar,{position:"static",children:(0,m.jsxs)(a.Tabs,{value:this.state.currentTab,onChange:(t,e)=>{l.Router.doNavigate(null,null,null,1===e?"table":2===e?"chart":"config"),this.setState({currentTab:e}),(window._localStorage||window.localStorage).setItem("App.objectCustomTab",e)},sx:{"& .MuiTabs-indicator":J.tabsIndicator},indicatorColor:"secondary",children:[(0,m.jsx)(a.Tab,{disabled:this.state.progressRunning,label:this.props.t("Custom settings"),id:"custom-settings-tab","aria-controls":"custom-tabpanel-settings",sx:{"&.Mui-selected":J.tabSelected}}),1===this.props.objectIDs.length&&this.chartAvailable?(0,m.jsx)(a.Tab,{disabled:this.state.progressRunning,label:this.props.t("History data"),id:"history-data-tab","aria-controls":"custom-tabpanel-history",sx:{"&.Mui-selected":J.tabSelected}}):null,"number"!==s&&"boolean"!==s||1!==this.props.objectIDs.length||!this.chartAvailable?null:(0,m.jsx)(a.Tab,{disabled:this.state.progressRunning,label:this.props.t("Chart"),id:"chart-tab","aria-controls":"custom-tabpanel-chart",sx:{"&.Mui-selected":J.tabSelected}})]})}),0===this.state.currentTab?(0,m.jsx)(a.Box,{component:"div",sx:J.tabPanel,children:this.renderCustomEditor()}):null,1===this.props.objectIDs.length&&this.chartAvailable&&1===this.state.currentTab?(0,m.jsx)(a.Box,{component:"div",sx:J.tabPanel,children:this.renderTable()}):null,"number"!==s&&"boolean"!==s||1!==this.props.objectIDs.length||!this.chartAvailable||2!==this.state.currentTab?null:(0,m.jsx)(a.Box,{component:"div",sx:J.tabPanel,children:this.renderCharts()})]}),(0,m.jsxs)(a.DialogActions,{children:[0===this.state.currentTab&&(0,m.jsx)(a.Button,{id:"object-custom-dialog-save",variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>this.saveFunc&&this.saveFunc(),children:this.getButtonTitle((0,m.jsx)(n.Save,{}),this.props.t("Save"))}),0===this.state.currentTab&&(0,m.jsx)(a.Button,{id:"object-custom-dialog-save-close",variant:"contained",color:"primary",disabled:!this.state.hasChanges||this.state.progressRunning,onClick:()=>{this.saveFunc?this.saveFunc((t=>!t&&this.onClose())):this.onClose()},children:this.getButtonTitle((0,m.jsx)(n.Save,{}),this.props.t("Save & close"),(0,m.jsx)(n.Close,{}))}),(0,m.jsx)(a.Button,{id:"object-custom-dialog-close",disabled:this.state.progressRunning,variant:"contained",onClick:()=>this.onClose(),color:"grey",children:this.getButtonTitle((0,m.jsx)(n.Close,{}),this.props.t("Close"))})]})]})}}const z=P;var U=s(40866);const Y={formControl:{minWidth:100},quality:{width:"calc(100% - 88px)"},expire:{ml:1,width:80},readOnly:{backgroundColor:"#b74848"},readOnlyText:{color:"#b74848",marginLeft:8},wrapperButton:{"@media screen and (max-width: 465px)":{"& *":{fontSize:12}},"@media screen and (max-width: 380px)":{"& *":{fontSize:11}}},ackCheckbox:{marginLeft:4},dialog:{minHeight:window.clientHeight-50>500?500:window.clientHeight-50},tooltip:{pointerEvents:"none"}};class G extends i.Component{constructor(t){super(t),this.propsValue=void 0,this.chartFrom=void 0,this.ack=void 0,this.inputRef=o().createRef(),this.q=void 0,this.expire=void 0;let e=this.props.type;e||(e=typeof this.props.value);let s=this.props.value;if(this.propsValue=s,null===this.propsValue?this.propsValue="null":void 0===this.propsValue&&(this.propsValue="undefined"),this.props.states)e="states";else if("string"===e||"json"===e){if(s&&"string"===typeof s&&(s.startsWith("[")&&s.endsWith("]")||s.startsWith("{")&&s.endsWith("}")))try{s=JSON.parse(s),s=JSON.stringify(s,null,2),this.propsValue=s,e="json"}catch{}}else"number"===e&&(s=parseFloat(this.propsValue)||0);this.state={type:e,chart:!1,chartEnabled:"false"!==(window._localStorage||window.localStorage).getItem("App.chartSetValue"),fullScreen:"true"===(window._localStorage||window.localStorage).getItem("App.fullScreen"),targetValue:s,valid:!0,jsonError:!1},this.ack=!1,this.q=0,this.expire=0,this.inputRef=o().createRef(),this.chartFrom=Date.now()-72e5}componentDidMount(){var t,e,s;this.props.defaultHistory&&null!==(t=this.props.object)&&void 0!==t&&null!==(e=t.common)&&void 0!==e&&e.custom&&null!==(s=this.props.object.common.custom[this.props.defaultHistory])&&void 0!==s&&s.enabled&&this.props.socket.getState(`system.adapter.${this.props.defaultHistory}.alive`).then((t=>this.setState({chart:!(null===t||void 0===t||!t.val)}))),setTimeout((()=>{var t;if(null!==(t=this.inputRef)&&void 0!==t&&t.current){const t=this.inputRef.current,e=t.value||"",s=t.type;"number"===t.type&&(t.type="text"),t.setSelectionRange(0,e.length),"number"===s&&(t.type=s)}}),200)}onUpdate(t){t&&(t.stopPropagation(),t.preventDefault());let e=this.state.targetValue;if("states"===this.state.type)if("null"===e)e=null;else{const t=this.props.type||typeof this.state.targetValue;e="object"===typeof e?e.value:e,"number"===t?"string"===typeof e&&(e=parseFloat(e.replace(",","."))||0):"boolean"===t&&(e=!0===e||"true"===e||"1"===e||"ON"===e||"on"===e)}else"number"===this.state.type?"null"===e?e=null:"string"===typeof e&&(e=parseFloat(e.replace(",","."))||0):"boolean"===this.state.type&&(e="null"===e?null:!0===e||"true"===e||"1"===e||"ON"===e||"on"===e);this.props.onClose({val:e,ack:this.ack,q:this.q,expire:parseInt(this.expire,10)||void 0})}static isNumberValid(t){const{common:e,value:s}=t;if(""===s)return!1;const i=Number(s);return!("number"===typeof e.min&&i<e.min)&&!("number"===typeof e.max&&i>e.max)}renderTimePicker(){return(0,m.jsxs)(b.LocalizationProvider,{adapterLocale:y[this.props.lang],dateAdapter:x.h,children:[(0,m.jsx)(b.DatePicker,{value:Number(this.state.targetValue),onChange:t=>{t&&this.setState({targetValue:Math.round(t.getTime())})}}),(0,m.jsx)(b.TimePicker,{value:Number(this.state.targetValue),views:["hours","minutes","seconds"],onChange:t=>{t&&this.setState({targetValue:Math.round(t.getTime())})}})]})}renderChart(){return(0,m.jsx)(H,{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,theme:this.props.theme,from:this.chartFrom,end:Date.now(),noToolbar:!0,dateFormat:this.props.dateFormat,defaultHistory:this.props.defaultHistory})}static checkJsonError(t){try{return JSON.parse(t),!1}catch{return!0}}renderJsonEditor(){return(0,m.jsx)(U.A,{error:this.state.jsonError,editValueMode:!0,themeType:this.props.themeType,defaultValue:(this.propsValue||"").toString(),onChange:t=>this.setState({targetValue:t,jsonError:G.checkJsonError(t)})})}renderStates(){if(!this.props.states)return null;if("number"===this.props.type&&void 0!==this.props.object.common.max&&void 0!==this.props.object.common.min){const t=Object.keys(this.props.states).map((t=>({label:this.props.states[t],value:t})));return(0,m.jsx)(a.Autocomplete,{style:Y.formControl,disablePortal:!0,defaultValue:void 0!==this.props.states[this.propsValue]?this.props.states[this.propsValue]:this.propsValue,options:t,noOptionsText:"",freeSolo:!0,getOptionLabel:t=>(null===t||void 0===t?void 0:t.label)||(void 0!==t&&null!==t?t.toString():""),onChange:(t,e)=>this.setState({targetValue:e}),onInputChange:(t,e)=>this.setState({targetValue:e}),onKeyUp:t=>"Enter"===t.key&&this.onUpdate(t),renderInput:t=>(0,m.jsx)(a.TextField,{...t,label:this.props.t("Value"),variant:"standard"})})}return(0,m.jsxs)(a.FormControl,{variant:"standard",style:Y.formControl,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("Value")}),(0,m.jsx)(a.Select,{variant:"standard",defaultValue:this.propsValue,onChange:t=>this.setState({targetValue:t.target.value}),children:Object.keys(this.props.states).map(((t,e)=>(0,m.jsx)(a.MenuItem,{value:t,children:this.props.states[t]},e)))})]})}render(){var t,e,s;const i=(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[(0,m.jsx)(a.FormControlLabel,{style:{...Y.formControl,...this.props.expertMode?void 0:Y.ackCheckbox},control:(0,m.jsx)(a.Checkbox,{defaultChecked:!1,onChange:t=>this.ack=t.target.checked}),label:this.props.t("Acknowledged")}),(0,m.jsx)(a.Tooltip,{title:this.props.t("Acknowledged explanation"),slotProps:{popper:{sx:Y.tooltip}},children:(0,m.jsx)(n.Info,{color:"primary"})})]});return(0,m.jsxs)(a.Dialog,{open:!0,maxWidth:"number"===this.state.type||"boolean"===this.state.type||"states"===this.state.type?this.state.chart&&this.state.chartEnabled?"lg":void 0:"md",fullWidth:"json"===this.state.type&&this.state.fullScreen||"number"!==this.state.type&&"boolean"!==this.state.type&&"states"!==this.state.type||this.state.chart&&this.state.chartEnabled,fullScreen:"json"===this.state.type&&this.state.fullScreen,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",sx:{"&. MuiDialog-paper":"json"===this.state.type?Y.dialog:void 0},children:[(0,m.jsxs)(a.DialogTitle,{id:"edit-value-dialog-title",children:[this.props.t("Write value"),!1===(null===(t=this.props.object.common)||void 0===t?void 0:t.write)?(0,m.jsxs)("span",{style:Y.readOnlyText,children:["(",this.props.t("read only"),")"]}):null,this.state.chart?(0,m.jsx)(a.Fab,{style:{float:"right"},size:"small",color:this.state.chartEnabled?"primary":"default",onClick:()=>{(window._localStorage||window.localStorage).setItem("App.chartSetValue",this.state.chartEnabled?"false":"true"),this.setState({chartEnabled:!this.state.chartEnabled})},children:(0,m.jsx)(n.ShowChart,{})}):null,"json"===this.state.type?(0,m.jsx)(a.IconButton,{style:{float:"right"},onClick:()=>{(window._localStorage||window.localStorage).setItem("App.fullScreen",this.state.fullScreen?"false":"true"),this.setState({fullScreen:!this.state.fullScreen})},children:this.state.fullScreen?(0,m.jsx)(n.FullscreenExit,{}):(0,m.jsx)(n.Fullscreen,{})}):null]}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsx)("form",{noValidate:!0,autoComplete:"off",onSubmit:()=>!1,style:{...Y.dialogForm,height:"100%"},children:(0,m.jsxs)(a.Grid2,{container:!0,direction:"row",spacing:2,style:{height:"100%"},children:[(0,m.jsx)(a.Grid2,{size:{xs:this.state.chart&&this.state.chartEnabled?6:12},style:{height:"100%"},children:(0,m.jsxs)(a.Grid2,{container:!0,direction:"column",spacing:2,style:{marginTop:0,height:"100%"},children:[this.props.expertMode?(0,m.jsx)(a.Grid2,{children:(0,m.jsxs)(a.Grid2,{container:!0,direction:"row",spacing:2,style:{marginTop:0},children:[this.props.expertMode?(0,m.jsx)(a.Grid2,{children:(0,m.jsxs)(a.FormControl,{style:Y.formControl,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("Value type")}),(0,m.jsxs)(a.Select,{variant:"standard",value:this.state.type,onChange:t=>{this.setState({type:t.target.value,valid:"number"!==t.target.value||G.isNumberValid({value:this.state.targetValue,common:this.props.object.common}),jsonError:!1},(()=>{"json"===this.state.type&&this.setState({targetValue:(this.state.targetValue||"").toString(),jsonError:G.checkJsonError((this.state.targetValue||"").toString())})}))},children:[(0,m.jsx)(a.MenuItem,{value:"string",children:"String"}),(0,m.jsx)(a.MenuItem,{value:"number",children:"Number"}),(0,m.jsx)(a.MenuItem,{value:"boolean",children:"Boolean"}),(0,m.jsx)(a.MenuItem,{value:"json",children:"JSON"}),this.props.states?(0,m.jsx)(a.MenuItem,{value:"states",children:"States"}):null]})]})}):null,"json"===this.state.type?(0,m.jsx)(a.Grid2,{flex:1}):null]})}):null,(0,m.jsx)(a.Grid2,{flex:"json"===this.state.type&&this.state.fullScreen?1:void 0,style:{paddingTop:0},children:"boolean"===this.state.type?(0,m.jsx)(a.Typography,{component:"div",style:this.props.expertMode?{marginTop:20,width:"100%",backgroundColor:"dark"===this.props.themeType?"#595959":"#dadada",borderRadius:5,padding:5}:void 0,children:(0,m.jsxs)(a.Grid2,{component:"label",container:!0,alignItems:"center",spacing:1,children:[(0,m.jsxs)(a.Grid2,{style:{marginRight:10},children:[this.props.t("Value"),":"]}),(0,m.jsx)(a.Grid2,{children:"FALSE"}),(0,m.jsx)(a.Grid2,{children:(0,m.jsx)(a.Switch,{autoFocus:!0,defaultChecked:"null"!==this.propsValue&&"undefined"!==this.propsValue&&!!this.propsValue,onKeyUp:t=>"Enter"===t.key&&this.onUpdate(t),onChange:t=>this.setState({targetValue:t.target.checked})})}),(0,m.jsx)(a.Grid2,{children:"TRUE"})]})}):"number"===this.state.type?(0,m.jsx)(a.TextField,{variant:"standard",fullWidth:!0,autoFocus:!0,error:!this.state.valid,type:"number",inputProps:{step:this.props.object.common.step,min:this.props.object.common.min,max:this.props.object.common.max},inputRef:this.inputRef,helperText:this.props.t("Press ENTER to write the value, when focused"),value:this.state.targetValue.toString(),label:this.props.t("Value")+(void 0!==this.props.object.common.min||"%"===this.props.object.common.unit?`, ${this.props.t("min:")} ${void 0!==this.props.object.common.min?this.props.object.common.min:0}`:"")+(void 0!==this.props.object.common.max||"%"===this.props.object.common.unit?`, ${this.props.t("max:")} ${void 0!==this.props.object.common.max?this.props.object.common.max:100}`:""),onKeyUp:t=>"Enter"===t.key&&this.state.valid&&this.onUpdate(t),onChange:t=>{this.setState({targetValue:t.target.value,valid:G.isNumberValid({value:t.target.value,common:this.props.object.common})})}}):"json"===this.state.type?this.renderJsonEditor():"states"===this.state.type?this.renderStates():(0,m.jsx)(a.TextField,{variant:"standard",fullWidth:!0,inputRef:this.inputRef,autoFocus:!0,helperText:this.props.t("Press CTRL+ENTER to write the value, when focused"),label:this.props.t("Value"),multiline:!0,onKeyDown:t=>t.ctrlKey&&"Enter"===t.key&&this.onUpdate(t),defaultValue:this.propsValue.toString(),onChange:t=>this.setState({targetValue:t.target.value})})}),("date"===this.props.role||null!==(e=this.props.role)&&void 0!==e&&e.startsWith("date."))&&"number"===this.state.type?(0,m.jsx)(a.Grid2,{style:{display:"flex",gap:"5px"},size:{xs:6},children:this.renderTimePicker()}):null,this.props.expertMode?(0,m.jsx)(a.Grid2,{children:i}):null,this.props.expertMode?(0,m.jsxs)(a.Grid2,{children:[(0,m.jsxs)(a.FormControl,{variant:"standard",style:Y.quality,children:[(0,m.jsx)(a.InputLabel,{children:this.props.t("Quality")}),(0,m.jsxs)(a.Select,{variant:"standard",defaultValue:0,onChange:t=>this.q=Number(t.target.value),children:[(0,m.jsx)(a.MenuItem,{value:0,children:"0x00 - good"}),(0,m.jsx)(a.MenuItem,{value:1,children:"0x01 - general problem"}),(0,m.jsx)(a.MenuItem,{value:2,children:"0x02 - no connection problem"}),(0,m.jsx)(a.MenuItem,{value:16,children:"0x10 - substitute value from controller"}),(0,m.jsx)(a.MenuItem,{value:32,children:"0x20 - substitute initial value"}),(0,m.jsx)(a.MenuItem,{value:64,children:"0x40 - substitute value from device or instance"}),(0,m.jsx)(a.MenuItem,{value:128,children:"0x80 - substitute value from sensor"}),(0,m.jsx)(a.MenuItem,{value:17,children:"0x11 - general problem by instance"}),(0,m.jsx)(a.MenuItem,{value:65,children:"0x41 - general problem by device"}),(0,m.jsx)(a.MenuItem,{value:129,children:"0x81 - general problem by sensor"}),(0,m.jsx)(a.MenuItem,{value:18,children:"0x12 - instance not connected"}),(0,m.jsx)(a.MenuItem,{value:66,children:"0x42 - device not connected"}),(0,m.jsx)(a.MenuItem,{value:130,children:"0x82 - sensor not connected"}),(0,m.jsx)(a.MenuItem,{value:68,children:"0x44 - device reports error"}),(0,m.jsx)(a.MenuItem,{value:132,children:"0x84 - sensor reports error"})]})]}),(0,m.jsx)(a.TextField,{variant:"standard",title:this.props.t("0 - no expiration"),sx:{"&.MuiTextField-root":Y.expire},label:this.props.t("Expire"),type:"number",inputProps:{min:0},helperText:this.props.t("in seconds"),defaultValue:this.expire,onChange:t=>this.expire=Number(t.target.value)})]}):null]})}),this.state.chart&&this.state.chartEnabled&&"json"!==this.state.type?(0,m.jsx)(a.Grid2,{size:{xs:6},style:{minHeight:300},sx:{display:{sm:"none",md:"inline-block"}},children:this.renderChart()}):null]})})}),(0,m.jsxs)(a.DialogActions,{sx:Y.wrapperButton,children:[this.props.expertMode?null:i,this.props.expertMode?null:(0,m.jsx)("div",{style:{flexGrow:1}}),(0,m.jsx)(a.Button,{variant:"contained",disabled:!this.state.valid,onClick:t=>this.onUpdate(t),color:"primary",startIcon:"xs"!==this.props.width?(0,m.jsx)(n.Check,{}):void 0,style:!1===(null===(s=this.props.object.common)||void 0===s?void 0:s.write)?Y.readOnly:void 0,children:"xs"!==this.props.width?this.props.t("Set value"):(0,m.jsx)(n.Check,{fontSize:"large"})}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:"xs"!==this.props.width?(0,m.jsx)(n.Close,{}):void 0,children:"xs"!==this.props.width?this.props.t("Cancel"):(0,m.jsx)(n.Close,{fontSize:"large"})})]})]})}}const K=G,$={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:8},funcDivEdit:{width:"100%"},funcEditName:{display:"inline-block",width:85},funcEdit:{width:400},funcIcon:{width:16,height:16},marginTop:{marginTop:20},commonTabWrapper:{flexFlow:"wrap",display:"flex"},commonWrapper:{width:500,minWidth:300},flexDrop:{width:"100%",maxWidth:500,margin:"auto",display:"flex"},marginBlock:{marginTop:20},buttonAdd:{minWidth:150},textField:{width:"100%"},flex:{display:"flex","& > div":{mr:"8px"}},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"},wrapperButton:{"@media screen and (max-width: 465px)":{"& *":{fontSize:10}},"@media screen and (max-width: 380px)":{"& *":{fontSize:9}}},commonDeleteTip:{color:"#fa4a4a"},typeNameEng:{marginLeft:8,opacity:.7,fontStyle:"italic",fontSize:"smaller"},tooltip:{pointerEvents:"none"}},Q=["button","button.close.blind","button.fastforward","button.forward","button.long","button.mode","button.mode.auto","button.mode.silent","button.next","button.open.blind","button.open.door","button.pause","button.stop","button.stop.tilt","button.volume.up","chart","date","date.end","date.forecast.1","date.start","date.sunrise","date.sunset","dayofweek","html","indicator","indicator.alarm","indicator.alarm.fire","indicator.alarm.flood","indicator.alarm.health","indicator.alarm.secure","indicator.connected","indicator.maintenance","indicator.maintenance.alarm","indicator.maintenance.lowbat","indicator.maintenance.waste","indicator.reachable","info.address","info.display","info.firmware","info.hardware","info.ip","info.mac","info.name","info.port","info.serial","info.standby","info.status","json","level","level.bass","level.blind","level.color.blue","level.color.hue","level.color.luminance","level.color.red","level.color.saturation","level.curtain","level.mode.airconditioner","level.mode.cleanup","level.mode.fan","level.mode.swing","level.mode.thermostat","level.mode.work","level.temperature","level.tilt","level.timer","level.treble","level.valve","level.volume","level.volume.group","list","location","media.add","media.bitrate","media.broadcastDate","media.browser","media.clear","media.content","media.cover","media.cover.big","media.cover.small","media.date","media.duration","media.duration.text","media.elapsed","media.elapsed.text","media.episode","media.genre","media.input","media.jump","media.link","media.mode.repeat","media.mode.shuffle","media.mute","media.mute.group","media.playid","media.playlist","media.season","media.seek","media.state","media.titel","media.track","media.tts","media.url","media.url.announcement","medien.artist","sensor.alarm","sensor.alarm.fire","sensor.alarm.flood","sensor.alarm.power","sensor.alarm.secure","sensor.door","sensor.light","sensor.lock","sensor.motion","sensor.noise","sensor.rain","sensor.window","state","switch","switch.enable","switch.gate","switch.gate","switch.light","switch.lock.door","switch.lock.window","switch.mode","switch.mode.auto","switch.mode.boost","switch.mode.color","switch.mode.manual","switch.mode.moonlight","switch.mode.party","switch.mode.silent","switch.power","switch.power.zone","text","text.phone","text.url","url","url.audio","url.blank","url.cam","url.same","value","value.battery","value.blind","value.blood.sugar","value.brightness","value.clouds","value.current","value.curtain","value.default","value.direction","value.direction.max.wind","value.direction.min.wind","value.direction.wind","value.direction.wind.forecast.0","value.direction.wind.forecast.1","value.distance","value.fill","value.gate","value.gps","value.gps.accuracy","value.gps.elevation","value.gps.latitude","value.gps.longitude","value.gps.radius","value.health.bmi","value.health.bpm","value.health.calories","value.health.fat","value.health.steps","value.health.weight","value.humidity","value.humidity","value.humidity.max","value.humidity.min","value.interval","value.lock","value.min","value.position","value.power","value.power.consumption","value.power.production","value.power.reactive","value.precipitation","value.precipitation.chance","value.precipitation.day.forecast.0","value.precipitation.forecast.0","value.precipitation.hour","value.precipitation.night.forecast.0","value.precipitation.today","value.precipitation.type","value.prepitation.forecast.0","value.prepitation.forecast.1","value.prepitation.forecast.1","value.pressure","value.pressure.forecast.0","value.pressure.forecast.1","value.radiation","value.rain","value.rain.hour","value.rain.today","value.severity","value.snow","value.snow.hour","value.snow.today","value.snowline","value.speed","value.speed.max.wind","value.speed.min.wind","value.speed.wind","value.speed.wind.forecast.0","value.speed.wind.gust","value.state","value.sun.azimuth","value.sun.elevation","value.temperature","value.temperature","value.temperature.dewpoint","value.temperature.feelslike","value.temperature.max","value.temperature.max.forecast.0","value.temperature.min","value.temperature.min.forecast.0","value.temperature.min.forecast.1","value.temperature.windchill","value.tilt","value.time","value.uv","value.valve","value.voltage","value.warning","value.waste","value.water","waether.title","weather.chart.url","weather.chart.url.forecast","weather.direction.wind","weather.direction.wind.forecast.0","weather.html","weather.icon","weather.icon.forecast.1","weather.icon.name","weather.icon.wind","weather.json","weather.state","weather.state.forecast.0","weather.state.forecast.1","weather.title.forecast.0","weather.title.short","weather.type"];class q extends i.Component{constructor(t){super(t),this.originalObj=void 0,this.onObjectUpdated=(t,e)=>{this.originalObj!==JSON.stringify(e,null,2)&&(this.originalObj=JSON.stringify(e,null,2),this.state.changed?this.forceUpdate():this.setState({text:this.originalObj}))};const e=this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type;let s=(window._localStorage||window.localStorage).getItem(`${this.props.dialogName||"App"}.editTab`)||"object";"alias"!==s||e||(s="common"),this.props.aliasTab&&e&&(s="alias");const i=this.props.obj,o=i.common&&"type"in i.common&&"alias"in i.common?i.common.alias.read:void 0,a=i.common&&"type"in i.common&&"alias"in i.common?i.common.alias.write:void 0;this.state={text:JSON.stringify(this.props.obj,null,2),error:!1,changed:!1,readError:this.checkFunction(o,!1),writeError:this.checkFunction(a,!0),tab:s,showCopyDialog:"",showCommonDeleteMessage:!1,selectId:!1,selectRead:!1,selectWrite:!1,newId:""},this.originalObj=JSON.stringify(this.props.obj,null,2)}componentDidMount(){this.props.socket.subscribeObject(this.props.obj._id,this.onObjectUpdated)}componentWillUnmount(){this.props.socket.unsubscribeObject(this.props.obj._id,this.onObjectUpdated)}checkFunction(t,e){var s,i,o,a,n;if(!t)return"";if(t.includes("JSON.parse("))return"";let l,r;try{l=JSON.parse(this.state.text)}catch{}try{r=new Function("val",t.includes("return")?t:`return ${t}`)}catch{return this.props.t("Cannot parse code!")}if(null!==(s=l)&&void 0!==s&&null!==(i=s.common)&&void 0!==i&&i.type&&null!==(o=this.props.objects[null===(n=l.common.alias)||void 0===n?void 0:n.id])&&void 0!==o&&null!==(a=o.common)&&void 0!==a&&a.type){const t=e?l.common.type:this.props.objects[l.common.alias.id].common.type,s=e?this.props.objects[l.common.alias.id].common.type:l.common.type;if(t&&s){let e=null;if("boolean"===t?e=!0:"number"===t?e=1:"string"!==t&&"mixed"!==t||(e="string"),null!==e)try{const t=r(e);return"mixed"===s?"":null!==t&&typeof t!==s?this.props.t("Type of result is not as expected: %s",s):""}catch(h){return`${this.props.t("Cannot execute function")}: ${h.toString()}`}}}return""}prepareObject(t){t=t||this.state.text;try{var e,s,i,o;const a=JSON.parse(t);return a._id=this.props.obj._id,null!==(e=a.common)&&void 0!==e&&e.alias&&(a.common.alias.id||delete a.common.alias.id,(!a.common.alias.read&&void 0!==a.common.alias.read||"val"===a.common.alias.read)&&delete a.common.alias.read,(!a.common.alias.write&&void 0!==a.common.alias.write||"val"===a.common.alias.write)&&delete a.common.alias.write,a.common.alias.id||a.common.alias.read||a.common.alias.write||delete a.common.alias),void 0!==(null===(s=a.common)||void 0===s?void 0:s.min)&&"number"!==typeof a.common.min&&(a.common.min=parseFloat(a.common.min)),void 0!==(null===(i=a.common)||void 0===i?void 0:i.max)&&"number"!==typeof a.common.max&&(a.common.max=parseFloat(a.common.max)),void 0!==(null===(o=a.common)||void 0===o?void 0:o.step)&&"number"!==typeof a.common.step&&(a.common.step=parseFloat(a.common.step)),a}catch{return null}}onChange(t,e){const s=this.prepareObject(t),i={text:t};if(s){var o,a,n,l;i.changed=this.originalObj!==JSON.stringify(s,null,2),i.showCommonDeleteMessage=!1;const t=JSON.parse(this.originalObj);s.common&&Object.keys(t.common||{}).forEach((t=>{void 0===s.common[t]&&(i.showCommonDeleteMessage=!0)})),i.error=!1,i.readError=this.checkFunction(null===(o=s.common)||void 0===o||null===(a=o.alias)||void 0===a?void 0:a.read,!1),i.writeError=this.checkFunction(null===(n=s.common)||void 0===n||null===(l=n.alias)||void 0===l?void 0:l.write,!0)}else i.showCommonDeleteMessage=!1,i.error=!0;this.setState(i,(()=>e&&e()))}onUpdate(){try{var t,e,s,i;const o=JSON.parse(this.state.text);o._id=this.props.obj._id,null!==(t=o.common)&&void 0!==t&&t.alias&&(o.common.alias.id||delete o.common.alias.id,(!o.common.alias.read&&void 0!==o.common.alias.read||"val"===o.common.alias.read)&&delete o.common.alias.read,(!o.common.alias.write&&void 0!==o.common.alias.write||"val"===o.common.alias.write)&&delete o.common.alias.write,o.common.alias.id||o.common.alias.read||o.common.alias.write||delete o.common.alias),void 0!==(null===(e=o.common)||void 0===e?void 0:e.min)&&"number"!==typeof o.common.min&&(o.common.min=parseFloat(o.common.min)),void 0!==(null===(s=o.common)||void 0===s?void 0:s.max)&&"number"!==typeof o.common.max&&(o.common.max=parseFloat(o.common.max)),void 0!==(null===(i=o.common)||void 0===i?void 0:i.step)&&"number"!==typeof o.common.step&&(o.common.step=parseFloat(o.common.step)),this.props.onClose(o)}catch{console.error(`Cannot parse: ${this.state.text}`)}}renderTabs(){return(0,m.jsxs)(a.Tabs,{style:$.tabsPadding,value:this.state.tab,onChange:(t,e)=>{if((window._localStorage||window.localStorage).setItem(`${this.props.dialogName||"App"}.editTab`,e),"object"===e)try{var s,i,o;const t=JSON.parse(this.state.text);let e=!1;void 0!==(null===(s=t.common)||void 0===s?void 0:s.min)&&"number"!==typeof t.common.min&&(t.common.min=parseFloat(t.common.min),e=!0),void 0!==(null===(i=t.common)||void 0===i?void 0:i.max)&&"number"!==typeof t.common.max&&(t.common.max=parseFloat(t.common.max),e=!0),void 0!==(null===(o=t.common)||void 0===o?void 0:o.step)&&"number"!==typeof t.common.step&&(t.common.step=parseFloat(t.common.step),e=!0),e&&this.setState({text:JSON.stringify(t,null,2)})}catch{}this.setState({tab:e})},children:[(0,m.jsx)(a.Tab,{value:"common",label:this.props.t("Common")}),(0,m.jsx)(a.Tab,{value:"object",label:this.props.t("Object data")}),this.props.obj._id.startsWith("alias.0")&&"state"===this.props.obj.type&&(0,m.jsx)(a.Tab,{value:"alias",label:this.props.t("Alias")})]})}renderSelectDialog(){if(!this.state.selectId&&!this.state.selectRead&&!this.state.selectWrite)return null;let t,e="";try{var s,i;t=JSON.parse(this.state.text);const n=t.common&&"type"in t.common&&"alias"in t.common?null===(s=t.common.alias)||void 0===s?void 0:s.read:"",l=t.common&&"type"in t.common&&"alias"in t.common?null===(i=t.common.alias)||void 0===i?void 0:i.write:"";var o,a;if(this.state.selectId)e=(null===(o=t.common)||void 0===o||null===(a=o.alias)||void 0===a?void 0:a.id)||"";else this.state.selectRead?e=null!==n&&void 0!==n?n:"":this.state.selectWrite&&(e=null!==l&&void 0!==l?l:"")}catch{console.error(`Cannot parse ${this.state.text}`)}return(0,m.jsx)(l.SelectID,{imagePrefix:".",dateFormat:this.props.dateFormat,theme:this.props.theme,isFloatComma:this.props.isFloatComma,socket:this.props.socket,dialogName:"aliasesEdit",title:`${this.props.t("Select for")} ${this.props.obj._id}`,selected:e,onOk:e=>{const s=this.state.selectRead,i=this.state.selectWrite,o=this.state.selectId,a=e;this.setState({selectId:!1,selectRead:!1,selectWrite:!1},(()=>{s?this.setAliasItem(t,"id.read",a):i?this.setAliasItem(t,"id.write",a):o&&this.setAliasItem(t,"id",a)}))},onClose:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!1})},"selectDialog")}setAliasItem(t,e,s,i){t.common=t.common||{};const o=t.common.alias||{};"id.read"===e?o.id&&"object"===typeof o.id?o.id.read=s:o.id={read:s,write:s}:"id.write"===e?o.id&&"object"===typeof o.id?o.id.write=s:o.id={read:s,write:s}:o[e]=s,t.common.alias=o,this.onChange(JSON.stringify(t,null,2),i)}setCommonItem(t,e,s){t.common[e]=s,this.onChange(JSON.stringify(t,null,2))}removeCommonItem(t,e){delete t.common[e],this.onChange(JSON.stringify(t,null,2))}static buttonAddKey(t,e){return(0,m.jsx)("div",{style:$.marginBlock,children:(0,m.jsx)(a.Button,{style:$.buttonAdd,variant:"contained",color:"secondary",startIcon:(0,m.jsx)(n.Add,{}),onClick:e,children:t})})}buttonRemoveKey(t,e){const{t:s}=this.props;return(0,m.jsx)(a.Tooltip,{title:s("Remove attribute %s",t),slotProps:{popper:{sx:$.tooltip}},children:(0,m.jsx)(a.Box,{component:"div",sx:$.close,onClick:e})})}renderCommonEdit(){try{const t=JSON.parse(this.state.text),e=["number","string","boolean","array","object","mixed"],s=!1,{t:i,roleArray:o,obj:n}=this.props,r="state"===n.type,h="channel"===n.type||"device"===n.type||r,d=[...Q];let c;if(o.forEach((t=>!d.includes(t)&&d.push(t))),d.sort(),t.common.icon&&(c="instance"===t.type||"adapter"===t.type?`./adapter/${t.common.name}/${t.common.icon}`:t.common.icon,!c.startsWith(".")&&!c.startsWith("/")&&!c.startsWith("data:"))){const t=n._id.split(".");c="system"===t[0]?`adapter/${t[2]}${c.startsWith("/")?"":"/"}${c}`:`adapter/${t[0]}${c.startsWith("/")?"":"/"}${c}`}return(0,m.jsxs)(a.Box,{style:$.commonTabWrapper,onKeyDown:t=>{"Enter"===t.key&&(t.preventDefault(),t.stopPropagation(),this.onUpdate())},children:[(0,m.jsxs)(a.Box,{style:{...$.commonWrapper,width:"xs"===this.props.width?"100%":void 0,minWidth:"xs"===this.props.width?"100%":void 0,gap:"xs"===this.props.width?"10px":void 0,display:"xs"===this.props.width?"flex":void 0,flexDirection:"xs"===this.props.width?"column":void 0},children:["undefined"!==typeof t.common.name?(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,label:i("Name"),style:{...$.marginBlock,...$.textField},fullWidth:!0,value:l.Utils.getObjectNameFromObj(t,l.I18n.getLanguage(),{},!1,!0),onChange:e=>this.setCommonItem(t,"name",e.target.value)}):q.buttonAddKey("name",(()=>this.setCommonItem(t,"name",""))),r?"undefined"!==typeof t.common.type?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsxs)(a.FormControl,{style:$.marginBlock,fullWidth:!0,children:[(0,m.jsx)(a.InputLabel,{style:{transform:"scale(0.75)"},children:i("State type")}),(0,m.jsx)(a.Select,{variant:"standard",disabled:s,value:t.common.type,onChange:e=>this.setCommonItem(t,"type",e.target.value),children:e.map((t=>(0,m.jsxs)(a.MenuItem,{value:t,children:[i(t),(0,m.jsxs)("span",{style:$.typeNameEng,children:["(",t,")"]})]},t)))})]}),this.buttonRemoveKey("type",(()=>this.removeCommonItem(t,"type")))]}):q.buttonAddKey("type",(()=>this.setCommonItem(t,"type","string"))):null,(0,m.jsxs)(a.Box,{component:"div",sx:{...$.flex,flexWrap:"xs"===this.props.width?"wrap":void 0},children:[r?"undefined"!==typeof t.common.read?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.FormControlLabel,{style:$.marginBlock,control:(0,m.jsx)(a.Checkbox,{disabled:s,checked:t.common.read,onClick:e=>this.setCommonItem(t,"read",e.target.checked)}),label:i("Readable")}),this.buttonRemoveKey("read",(()=>this.removeCommonItem(t,"read")))]}):q.buttonAddKey("read",(()=>this.setCommonItem(t,"read",!0))):null,r?"undefined"!==typeof t.common.write?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.FormControlLabel,{style:$.marginBlock,control:(0,m.jsx)(a.Checkbox,{disabled:s,checked:t.common.write,onClick:e=>this.setCommonItem(t,"write",e.target.checked)}),label:i("Writeable")}),this.buttonRemoveKey("write",(()=>this.removeCommonItem(t,"write")))]}):q.buttonAddKey("write",(()=>this.setCommonItem(t,"write",!0))):null]}),h?"undefined"!==typeof t.common.role?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.Autocomplete,{style:$.marginBlock,fullWidth:!0,disabled:s,value:t.common.role,onChange:(e,s)=>this.setCommonItem(t,"role",s),options:o,renderInput:t=>(0,m.jsx)(a.TextField,{variant:"standard",...t,label:i("Role")})}),this.buttonRemoveKey("role",(()=>this.removeCommonItem(t,"role")))]}):q.buttonAddKey("role",(()=>this.setCommonItem(t,"role",""))):null,"undefined"!==typeof t.common.color?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,style:{...$.marginBlock,...$.color},label:i("Color"),type:"color",value:t.common.color,onChange:e=>this.setCommonItem(t,"color",e.target.value)}),this.buttonRemoveKey("color",(()=>this.removeCommonItem(t,"color")))]}):q.buttonAddKey("color",(()=>this.setCommonItem(t,"color",""))),(0,m.jsxs)(a.Box,{component:"div",sx:{...$.flex,flexWrap:"xs"===this.props.width?"wrap":void 0,gap:"xs"===this.props.width?"10px":void 0},children:["number"===t.common.type?"undefined"!==typeof t.common.min?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,className:{...$.marginBlock,...$.color},label:i("Min"),value:t.common.min,onChange:e=>this.setCommonItem(t,"min",e.target.value)}),this.buttonRemoveKey("min",(()=>this.removeCommonItem(t,"min")))]}):(0,m.jsx)(a.Box,{component:"div",sx:$.flex,children:q.buttonAddKey("min",(()=>this.setCommonItem(t,"min",0)))}):null,"number"===t.common.type?"undefined"!==typeof t.common.max?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,className:{...$.marginBlock,...$.color},label:i("Max"),value:t.common.max,onChange:e=>this.setCommonItem(t,"max",e.target.value)}),this.buttonRemoveKey("max",(()=>this.removeCommonItem(t,"max")))]}):(0,m.jsx)(a.Box,{component:"div",sx:$.flex,children:q.buttonAddKey("max",(()=>this.setCommonItem(t,"max",100)))}):null,"number"===t.common.type?"undefined"!==typeof t.common.step?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,className:{...$.marginBlock,...$.color},label:i("Step"),value:t.common.step,onChange:e=>this.setCommonItem(t,"step",e.target.value)}),this.buttonRemoveKey("step",(()=>this.removeCommonItem(t,"step")))]}):(0,m.jsx)(a.Box,{component:"div",sx:$.flex,children:q.buttonAddKey("step",(()=>this.setCommonItem(t,"step",1)))}):null]}),"number"===t.common.type?"undefined"!==typeof t.common.unit?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,children:[(0,m.jsx)(a.TextField,{variant:"standard",disabled:s,className:{...$.marginBlock,...$.color},label:i("Unit"),value:t.common.unit,onChange:e=>this.setCommonItem(t,"unit",e.target.value)}),this.buttonRemoveKey("unit",(()=>this.removeCommonItem(t,"unit")))]}):(0,m.jsx)("div",{style:$.flexDrop,children:q.buttonAddKey("unit",(()=>this.setCommonItem(t,"unit","")))}):null]}),"undefined"!==typeof t.common.icon?(0,m.jsxs)(a.Box,{component:"div",sx:$.flex,style:{flexGrow:1,minWidth:158},children:[(0,m.jsx)(l.UploadImage,{disabled:s,maxSize:10240,icon:c,removeIconFunc:()=>this.setCommonItem(t,"icon",""),onChange:e=>this.setCommonItem(t,"icon",e)}),this.buttonRemoveKey("icon",(()=>this.removeCommonItem(t,"icon")))]}):(0,m.jsx)(a.Box,{component:"div",sx:$.flex,children:q.buttonAddKey("icon",(()=>this.setCommonItem(t,"icon","")))})]})}catch{return(0,m.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}renderAliasEdit(){try{var t,e,s,i,o,r,h,d,c,p,u,g,v,x,b,j,f,y,w,C,S,I,A,T,k,D,F,R,E,O,M,N,W,V,L,H,B,J,P,z;const U=JSON.parse(this.state.text),Y=void 0!==(null===(t=U.common)||void 0===t||null===(e=t.alias)||void 0===e?void 0:e.read)||void 0!==(null===(s=U.common)||void 0===s||null===(i=s.alias)||void 0===i?void 0:i.write);return(0,m.jsxs)(a.Grid2,{container:!0,direction:"column",style:$.marginTop,children:[(0,m.jsx)(a.Grid2,{children:(0,m.jsx)(a.FormControlLabel,{control:(0,m.jsx)(a.Checkbox,{checked:"object"===typeof(null===(o=U.common)||void 0===o||null===(r=o.alias)||void 0===r?void 0:r.id),onChange:()=>{var t,e,s,i,o,a,n;"object"===typeof(null===(t=U.common)||void 0===t||null===(e=t.alias)||void 0===e?void 0:e.id)?this.setAliasItem(U,"id",(null===(s=U.common)||void 0===s||null===(i=s.alias)||void 0===i||null===(o=i.id)||void 0===o?void 0:o.read)||""):this.setAliasItem(U,"id.read",(null===(a=U.common)||void 0===a||null===(n=a.alias)||void 0===n?void 0:n.id)||"")}}),label:this.props.t("Different IDs for read and write")})}),"object"!==typeof(null===(h=U.common)||void 0===h||null===(d=h.alias)||void 0===d?void 0:d.id)?(0,m.jsxs)(a.Grid2,{children:[(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Alias state"),value:(null===(c=U.common)||void 0===c||null===(p=c.alias)||void 0===p?void 0:p.id)||"",style:$.aliasIdEdit,slotProps:{input:{endAdornment:null!==(u=U.common)&&void 0!==u&&null!==(g=u.alias)&&void 0!==g&&g.id?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.setAliasItem(U,"id",""),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setAliasItem(U,"id",t.target.value),margin:"normal"}),(0,m.jsx)(a.Fab,{style:$.button,size:"small",onClick:()=>this.setState({selectId:!0,selectRead:!1,selectWrite:!1}),children:"..."})]}):null,"object"===typeof(null===(v=U.common)||void 0===v||null===(x=v.alias)||void 0===x?void 0:x.id)?(0,m.jsxs)(a.Grid2,{children:[(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Alias read state"),value:(null===(b=U.common)||void 0===b||null===(j=b.alias)||void 0===j||null===(f=j.id)||void 0===f?void 0:f.read)||"",style:$.aliasIdEdit,slotProps:{input:{endAdornment:null!==(y=U.common)&&void 0!==y&&null!==(w=y.alias)&&void 0!==w&&null!==(C=w.id)&&void 0!==C&&C.read?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.setAliasItem(U,"id.read",""),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setAliasItem(U,"id.read",t.target.value),margin:"normal"}),(0,m.jsx)(a.Fab,{style:$.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!0,selectWrite:!1}),children:"..."})]}):null,"object"===typeof(null===(S=U.common)||void 0===S||null===(I=S.alias)||void 0===I?void 0:I.id)?(0,m.jsxs)(a.Grid2,{children:[(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Alias write state"),value:(null===(A=U.common)||void 0===A||null===(T=A.alias)||void 0===T||null===(k=T.id)||void 0===k?void 0:k.write)||"",style:$.aliasIdEdit,slotProps:{input:{endAdornment:null!==(D=U.common)&&void 0!==D&&null!==(F=D.alias)&&void 0!==F&&null!==(R=F.id)&&void 0!==R&&R.write?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.setAliasItem(U,"id.write",""),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setAliasItem(U,"id.write",t.target.value),margin:"normal"}),(0,m.jsx)(a.Fab,{style:$.button,size:"small",onClick:()=>this.setState({selectId:!1,selectRead:!1,selectWrite:!0}),children:"..."})]}):null,(0,m.jsx)(a.Grid2,{style:$.marginTop,children:(0,m.jsx)(a.FormControlLabel,{control:(0,m.jsx)(a.Checkbox,{checked:void 0!==(null===(E=U.common)||void 0===E||null===(O=E.alias)||void 0===O?void 0:O.read)||void 0!==(null===(M=U.common)||void 0===M||null===(N=M.alias)||void 0===N?void 0:N.write),onChange:()=>{Y?(delete U.common.alias.read,delete U.common.alias.write):(U.common=U.common||{},U.common.alias=U.common.alias||{},U.common.alias.read="val",U.common.alias.write="val"),this.onChange(JSON.stringify(U,null,2))}}),label:this.props.t("Use convert functions")})}),Y?(0,m.jsx)(a.Grid2,{children:(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Read converter"),value:(null===(W=U.common)||void 0===W||null===(V=W.alias)||void 0===V?void 0:V.read)||"val",style:$.funcEdit,error:!!this.state.readError,slotProps:{input:{endAdornment:null!==(L=U.common)&&void 0!==L&&null!==(H=L.alias)&&void 0!==H&&H.read?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.setAliasItem(U,"read",""),children:(0,m.jsx)(n.Close,{})})}):null,startAdornment:(0,m.jsx)(a.InputAdornment,{position:"start",children:(0,m.jsx)(l.IconFx,{style:$.funcIcon})})}},onChange:t=>this.setAliasItem(U,"read",t.target.value),helperText:this.state.readError||`${this.props.t("JS function like")} "val / 5 + 21"`,margin:"normal"})}):null,Y?(0,m.jsx)(a.Grid2,{children:(0,m.jsx)(a.TextField,{variant:"standard",label:this.props.t("Write converter"),error:!!this.state.writeError,value:(null===(B=U.common)||void 0===B||null===(J=B.alias)||void 0===J?void 0:J.write)||"val",helperText:this.state.writeError||`${this.props.t("JS function like")} "(val - 21) * 5"`,style:$.funcEdit,slotProps:{input:{endAdornment:null!==(P=U.common)&&void 0!==P&&null!==(z=P.alias)&&void 0!==z&&z.write?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"large",onClick:()=>this.setAliasItem(U,"write",""),children:(0,m.jsx)(n.Close,{})})}):null,startAdornment:(0,m.jsx)(a.InputAdornment,{position:"start",children:(0,m.jsx)(l.IconFx,{style:$.funcIcon})})}},onChange:t=>this.setAliasItem(U,"write",t.target.value),margin:"normal"})}):null]})}catch{return(0,m.jsx)("div",{children:this.props.t("Cannot parse JSON!")})}}onCopy(t){l.Utils.copyToClipboard(this.state.text,t),window.alert(this.props.t("ra_Copied"))}onClone(t,e){const s=JSON.parse(JSON.stringify(this.props.objects[t]));delete s.from,delete s.ts,delete s.user,s._id=e,this.props.objects[s._id]=s,this.props.onNewObject(s)}renderCopyDialog(){return this.state.showCopyDialog?(0,m.jsxs)(a.Dialog,{open:!0,maxWidth:"md",fullWidth:!0,onClose:()=>this.setState({showCopyDialog:""}),children:[(0,m.jsx)(a.DialogTitle,{children:this.props.t("Enter new ID for this object")}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsx)(a.TextField,{variant:"standard",autoFocus:!0,fullWidth:!0,label:this.props.t("New object ID"),value:this.state.newId,onKeyDown:t=>{"Enter"!==t.key||this.props.objects[this.state.newId]||(this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId))},onChange:t=>this.setState({newId:t.target.value})})}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{disabled:!!this.props.objects[this.state.newId],onClick:()=>{this.setState({showCopyDialog:""}),this.onClone(this.state.showCopyDialog,this.state.newId)},color:"primary",startIcon:(0,m.jsx)(n.FileCopy,{}),children:this.props.t("Clone")}),(0,m.jsx)(a.Button,{color:"grey",onClick:()=>this.setState({showCopyDialog:""}),startIcon:(0,m.jsx)(n.Close,{}),children:this.props.t("Cancel")})]})]}):null}render(){const t=this.props.obj,e=t._id.startsWith("alias.0")&&"state"===t.type,s="state"!==t.type||"number"!==t.common.type&&"boolean"!==t.common.type;return(0,m.jsxs)(a.Dialog,{sx:{"& .MuiPaper-root":$.dialog},open:!0,maxWidth:"lg",fullWidth:s,fullScreen:!1,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-value-dialog-title","aria-describedby":"edit-value-dialog-description",children:[(0,m.jsxs)(a.DialogTitle,{id:"edit-value-dialog-title",style:{width:"calc(100% - 32px)",overflow:"hidden",textOverflow:"ellipsis"},children:[this.props.t("Edit object:")," ",(0,m.jsx)(a.Box,{component:"span",style:$.id,sx:{fontSize:{xs:10}},children:this.props.obj._id})]}),this.renderTabs(),this.renderCopyDialog(),(0,m.jsxs)(a.DialogContent,{sx:{p:"xs"===this.props.width&&"object"===this.state.tab?"6px":void 0},children:["object"===this.state.tab?(0,m.jsxs)("div",{style:{...$.divWithoutTitle,...e?$.divWithoutTitleAndTab:void 0,...this.state.error?$.error:void 0},onKeyDown:t=>{t.ctrlKey&&"Enter"===t.key&&(t.preventDefault(),t.stopPropagation(),this.onUpdate())},children:[(0,m.jsx)(U.A,{value:this.state.text,onChange:t=>this.onChange(t),name:"UNIQUE_ID_OF_DIV",themeType:this.props.themeType}),this.state.showCommonDeleteMessage?(0,m.jsx)("div",{style:$.commonDeleteTip,children:l.I18n.t("common_delete_tip")}):null]}):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()]}),(0,m.jsxs)(a.DialogActions,{sx:$.wrapperButton,children:[(0,m.jsx)(a.Button,{color:"grey",onClick:()=>this.setState({showCopyDialog:this.props.obj._id,newId:this.props.obj._id}),disabled:this.state.error||this.state.changed,title:this.props.t("Create a copy of this object"),children:(0,m.jsx)(n.FileCopy,{fontSize:"xs"===this.props.width?"large":void 0})}),(0,m.jsx)("div",{style:{flexGrow:1}}),"object"===this.state.tab&&(0,m.jsx)(a.Button,{color:"grey",onClick:t=>this.onCopy(t),disabled:this.state.error,title:"xs"===this.props.width?this.props.t("Copy into clipboard"):"",startIcon:"xs"===this.props.width?void 0:(0,m.jsx)(j.Y4c,{}),children:"xs"===this.props.width?(0,m.jsx)(j.Y4c,{fontSize:32}):this.props.t("Copy into clipboard")}),(0,m.jsx)(a.Button,{variant:"contained",disabled:this.state.error||!this.state.changed,onClick:()=>this.onUpdate(),startIcon:"xs"===this.props.width?void 0:(0,m.jsx)(n.Check,{}),color:"primary",children:"xs"===this.props.width?(0,m.jsx)(n.Check,{fontSize:"large"}):this.props.t("Write")}),(0,m.jsx)(a.Button,{color:"grey",variant:"contained",onClick:()=>this.props.onClose(),startIcon:"xs"===this.props.width?void 0:(0,m.jsx)(n.Close,{}),children:"xs"===this.props.width?(0,m.jsx)(n.Close,{fontSize:"large"}):this.props.t("Cancel")})]})]})}}const Z=q;class X extends i.Component{constructor(t){super(t),this.object=null,this.state={role:null,initRole:null,roleInput:null}}componentDidMount(){this.props.socket.getObject(this.props.id).then((t=>{var e;this.object=t;const s=(null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.role)||null;this.setState({role:s,initRole:s,roleInput:s})})).catch((t=>console.error(t)))}onUpdate(){this.object.common=this.object.common||{},this.object.common.role=this.state.roleInput,this.props.socket.setObject(this.object._id,this.object).then((()=>this.props.onClose(this.object)))}render(){return(0,m.jsxs)(a.Dialog,{open:!0,maxWidth:"sm",fullWidth:!0,onClose:()=>this.props.onClose(),"aria-labelledby":"edit-role-dialog-title","aria-describedby":"edit-role-dialog-description",children:[(0,m.jsx)(a.DialogTitle,{id:"edit-role-dialog-title",children:this.object?this.props.t("Update role for %s",this.object._id):null}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsx)(a.Autocomplete,{freeSolo:!0,options:this.props.roles,style:{width:"100%"},value:this.state.role,onChange:(t,e)=>this.setState({role:e,roleInput:e}),onInputChange:(t,e)=>this.setState({roleInput:e}),renderInput:t=>(0,m.jsx)(a.TextField,{variant:"standard",...t,label:this.props.t("Role")})})}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{disabled:this.state.initRole===this.state.roleInput,variant:"contained",onClick:()=>this.onUpdate(),color:"primary",startIcon:(0,m.jsx)(n.Check,{}),children:this.props.t("Apply")}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.props.onClose(),color:"grey",startIcon:(0,m.jsx)(n.Close,{}),children:this.props.t("Cancel")})]})]},"objectBrowserEditRole")}}const _=X,tt=["array","boolean","file","json","mixed","number","object","string"],et={boolean:!1,string:"",number:0},st={name:"State",value:"state"},it={name:"Channel",value:"channel"},ot={name:"Device",value:"device"},at={name:"Folder",value:"folder"},nt=t=>{var e;let{onClose:s,onApply:o,selected:r,setObject:h,objects:d,expertMode:c,initialType:p,initialStateType:u}=t;const g={state:l.I18n.t("New state"),channel:l.I18n.t("New channel"),device:l.I18n.t("New device"),folder:l.I18n.t("New folder")},v=[],x=null===(e=d[r])||void 0===e?void 0:e.type;d[r]?"channel"===x?(v.push(st),p=p||"state"):"device"===x?(p=p||"channel",v.push(st),v.push(it)):"state"===x?p=p||"":(v.push(st),v.push(it),v.push(ot),r.startsWith("0_userdata.")||r.startsWith("alias.0.")||"0_userdata"===r||"alias.0"===r?(v.push(at),p=p||"folder"):p=p||"state"):(v.push(at),p=p||"folder",c&&(r.startsWith("mqtt.")||r.startsWith("javascript."))&&(v.push(st),v.push(it),v.push(ot)));const b=(window._localStorage||window.localStorage).getItem("App.lastObjectType");function j(t){return`${r}.${t.toString().replace(l.Utils.FORBIDDEN_CHARS,"_").replace(/\s/g,"_").replace(/\./g,"_")}`}b&&v.find((t=>t.value===b))&&(p=b);const[f,y]=(0,i.useState)(p),[w,C]=(0,i.useState)(g[p]),[S,I]=(0,i.useState)(u||(window._localStorage||window.localStorage).getItem("App.lastStateType")||"string"),[A,T]=(0,i.useState)(!d[j(g.state)]),k=()=>{const t={common:{name:w,desc:l.I18n.t("Manually created")},type:f};"state"===f?(t.common={...t.common,role:"state",type:S,read:!0,write:!0,def:et[S]},t.native={}):"folder"!==f?t.common={...t.common,role:"",icon:""}:delete t.common.desc,h(`${r}.${w.split(" ").join("_")}`,t).then((()=>o()))},D=l.I18n.getLanguage();return(0,m.jsxs)(a.Dialog,{open:!0,fullWidth:!0,maxWidth:"md",disableEscapeKeyDown:!1,onClose:s,children:[(0,m.jsx)(a.DialogTitle,{children:(0,m.jsxs)("div",{style:{margin:10,fontSize:20,display:"flex",alignItems:"center",gap:8},children:[(0,m.jsx)(n.AddBox,{}),l.I18n.t("Add new object:"),(0,m.jsxs)("span",{style:{fontStyle:"italic"},children:[r,".",w]})]})}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[(0,m.jsx)(a.TextField,{variant:"standard",label:l.I18n.t("Parent"),style:{margin:"5px 0"},disabled:!0,value:r}),(0,m.jsxs)(a.FormControl,{variant:"standard",style:{marginTop:10,marginBottom:16},children:[(0,m.jsx)(a.InputLabel,{children:l.I18n.t("Type")}),(0,m.jsx)(a.Select,{variant:"standard",value:f,onChange:t=>{(window._localStorage||window.localStorage).setItem("App.lastObjectType",t.target.value),w===g[f]&&(C(g[t.target.value]),T(!!d[j(g[t.target.value])])),y(t.target.value)},children:v.map((t=>(0,m.jsxs)(a.MenuItem,{value:t.value,children:[l.I18n.t(t.name),"en"!==D&&(0,m.jsxs)("span",{style:{fontSize:"smaller",opacity:.6,marginLeft:4},children:["(",t.value,")"]})]},t.value)))})]}),"state"===f&&(0,m.jsxs)(a.FormControl,{style:{marginTop:10,marginBottom:16},children:[(0,m.jsx)(a.InputLabel,{style:{left:-14},children:l.I18n.t("State type")}),(0,m.jsx)(a.Select,{style:{marginTop:6},variant:"standard",value:S,onChange:t=>{(window._localStorage||window.localStorage).setItem("App.lastStateType",t.target.value),I(t.target.value)},children:tt.map((t=>(0,m.jsxs)(a.MenuItem,{value:t,children:[l.I18n.t(t),"en"!==D&&l.I18n.t(t)!==t&&(0,m.jsxs)("span",{style:{fontSize:"smaller",opacity:.6,marginLeft:4},children:["(",t,")"]})]},t)))})]}),(0,m.jsx)(a.TextField,{variant:"standard",label:l.I18n.t("Name"),style:{margin:"5px 0"},autoFocus:!0,value:w,onKeyDown:t=>{"Enter"===t.key&&(t.preventDefault(),w&&k())},slotProps:{input:{endAdornment:w?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>C(""),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>{T(!d[j(t.target.value)]),C(t.target.value)}})]})}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{id:"add-new-object-dialog-add",startIcon:(0,m.jsx)(n.Check,{}),disabled:!w||!f||!A||"state"===f&&!S,onClick:()=>k(),variant:"contained",color:"primary",children:l.I18n.t("add")}),(0,m.jsx)(a.Button,{id:"add-new-object-dialog-cancel",color:"grey",onClick:s,variant:"contained",startIcon:(0,m.jsx)(n.Close,{}),children:l.I18n.t("ra_Cancel")})]})]})};var lt=s(90869);const rt=[{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"}]}];function ht(t,e,s){return t|=e&s,t&=e|65535&~s}const dt=t=>{let{value:e,setValue:s,t:o,differentValues:n,applyToChildren:l,mask:r,setMask:h,disabled:d}=t;(0,i.useEffect)((()=>{if(l){let t=0;for(let s=0;s<n.length;s++)t|=e^n[s];h(t)}else h(0)}),[n,l,h,e]);let c=e;return(0,m.jsx)("div",{style:{display:"flex",width:"fit-content",margin:20,border:"1px solid",borderLeft:0},children:rt.map((t=>{const i=Object.keys(t)[0];return(0,m.jsxs)("div",{style:{width:150,height:150,display:"flex",flexDirection:"column",alignItems:"center",borderLeft:"1px solid"},children:[(0,m.jsx)("div",{style:{height:50,display:"flex",alignItems:"center",fontSize:18,borderBottom:"1px solid silver",width:"100%",justifyContent:"center"},children:o(i)}),(0,m.jsx)("div",{style:{display:"flex",width:"100%"},children:t[i].map(((t,i)=>{let n=!1;c-t.valueNum>=0&&(c-=t.valueNum,n=!0);const l=r&t.valueNum;return(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",borderRight:0===i?"1px solid":0},children:[(0,m.jsx)("div",{style:{height:50,borderBottom:"1px solid",width:"100%",justifyContent:"center",display:"flex",alignItems:"center",color:"silver"},children:o(t.name)}),(0,m.jsx)("div",{style:{height:50,display:"flex"},children:(0,m.jsx)(a.Checkbox,{disabled:d,checked:n,color:l?"primary":"secondary",indeterminate:!!l,style:l?{opacity:.5}:void 0,onChange:i=>{l&&(r&=65535&~t.valueNum,h(r));let o=e;i.target.checked?o|=t.valueNum:o&=65535&~t.valueNum,s(o)}})})]},t.valueNum)}))})]},i)}))})},ct=t=>{let{onClose:e,onApply:s,selected:o,extendObject:n,objects:r,t:h,modalEmptyId:d,themeType:c,theme:p}=t;const[u,g]=(0,i.useState)(null),[v,x]=(0,i.useState)(null),[b,j]=(0,i.useState)([]),[f,y]=(0,i.useState)([]),[w,C]=(0,i.useState)(!1),[S,I]=(0,i.useState)(!1),[A,T]=(0,i.useState)(0),[k,D]=(0,i.useState)(null),[F,R]=(0,i.useState)(null),[E,O]=(0,i.useState)(!1),[M,N]=(0,i.useState)(!1),[W,V]=(0,i.useState)([]),[L,H]=(0,i.useState)([]),[B,J]=(0,i.useState)(0),[P,z]=(0,i.useState)(0),[U,Y]=(0,i.useState)([]),[G,K]=(0,i.useState)(!1),[$,Q]=(0,i.useState)(!0),q=h("different");return(0,i.useEffect)((()=>{let t=0;const e=[],s=[],i=o||d,a=`${i}.`,n=Object.keys(r).sort();let h=!1;const c=[],p=[],m=l.I18n.getLanguage();let u=!1,v=!1,b=null,f=null,w=null,S=null;const A=[];for(let o=0;o<n.length;o++){const d=n[o],g=r[d];if(g&&(d===i||d.startsWith(a))){if(t++,A.push(d),!g.acl)continue;null===w&&void 0!==g.acl.object&&(w=g.acl.object),null===S&&void 0!==g.acl.state&&(S=g.acl.state),null===b&&void 0!==g.acl.owner&&(b=g.acl.owner),null===f&&void 0!==g.acl.ownerGroup&&(f=g.acl.ownerGroup),E||b===g.acl.owner||void 0===g.acl.owner||(u=!0),M||f===g.acl.ownerGroup||void 0===g.acl.ownerGroup||(v=!0),void 0===g.acl.state||S===g.acl.state||e.includes(g.acl.state)||e.push(g.acl.state),void 0===g.acl.object||w===g.acl.object||s.includes(g.acl.object)||s.push(g.acl.object),"state"===g.type&&(h=!0)}var k,F;if(d.startsWith("system.group.")&&"group"===(null===g||void 0===g?void 0:g.type))c.push({name:l.Utils.getObjectNameFromObj(g,m).replace("system.group.",""),value:d,icon:null===(k=g.common)||void 0===k?void 0:k.icon,color:null===(F=g.common)||void 0===F?void 0:F.color});else if(d.startsWith("system.user.")&&"user"===(null===g||void 0===g?void 0:g.type)){var W,L;p.push({name:l.Utils.getObjectNameFromObj(g,m).replace("system.user.",""),value:d,icon:null===(W=g.common)||void 0===W?void 0:W.icon,color:null===(L=g.common)||void 0===L?void 0:L.color})}}b=b||r["system.config"].common.defaultNewAcl.owner,f=f||r["system.config"].common.defaultNewAcl.ownerGroup,w=w||r["system.config"].common.defaultNewAcl.object,D(Number.isNaN(w)?r["system.config"].common.defaultNewAcl.object:w),h&&(S=S||r["system.config"].common.defaultNewAcl.state,R(Number.isNaN(S)?r["system.config"].common.defaultNewAcl.state:S));const B=p.find((t=>t.value===b)),J=c.find((t=>t.value===f));g(B),x(J),O(u),N(v),j(p),y(c),h&&I(!0),d&&C(!0),T(t),V(e),H(s),Y(A)}),[r,o,M,E,d]),(0,i.useEffect)((()=>{w?(M&&("different"!==v.value&&x({name:q,value:"different"}),f.find((t=>"different"===t.value))||y((t=>[{name:q,value:"different"},...t]))),E&&(u&&"different"===u.value||g({name:q,value:"different"}),b.find((t=>"different"===t.value))||j((t=>[{name:q,value:"different"},...t])))):(u&&"different"===u.value&&g(r[o].acl.owner),v&&"different"===v.value&&x(r[o].acl.ownerGroup),y((t=>t.filter((t=>{let{value:e}=t;return"different"!==e})))),j((t=>t.filter((t=>{let{value:e}=t;return"different"!==e})))))}),[b,w,E,M,r,o,v,u,q,f]),U.length?(0,m.jsx)(lt.A,{theme:p,titleButtonApply:"apply",overflowHidden:!0,disableApply:$,progress:G,onClose:e,onApply:()=>{K(!0),setTimeout((()=>{if(w){const t=65535&~B,e=65535&~P;for(let s=0;s<U.length;s++){const i=U[s],o=r[i],a=l.Utils.clone(o.acl||{});a.object=ht(o.acl.object,k,t),u&&"different"!==u.value&&(a.owner=u.value),v&&"different"!==v.value&&(a.ownerGroup=v.value),"state"===o.type&&(a.state=ht(o.acl.state,F,e)),n(i,{acl:a})}}else{const t=l.Utils.clone(r[o].acl||{});t.object=k,t.owner=u?u.value:"system.user.admin",t.ownerGroup=v?v.value:"system.group.administrator","state"===r[o].type&&(t.state=F),n(o,{acl:t})}K(!1),s()}),200)},children:(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[(0,m.jsx)("div",{style:{margin:10,fontSize:20},children:h("Access control list: %s",o||d)}),(0,m.jsxs)("div",{style:{display:"flex"},children:[(0,m.jsxs)(a.FormControl,{variant:"standard",fullWidth:!0,style:{marginRight:10},children:[(0,m.jsx)(a.InputLabel,{children:h("Owner user")}),(0,m.jsx)(a.Select,{variant:"standard",disabled:G,value:u?u.value:"",renderValue:()=>(0,m.jsxs)("span",{children:[null!==u&&void 0!==u&&u.icon?(0,m.jsx)(l.Icon,{src:u.icon,style:{width:16,height:16,marginRight:8}}):null,u?u.name:""]}),style:"different"===(null===u||void 0===u?void 0:u.value)?{opacity:.5}:{color:(null===u||void 0===u?void 0:u.color)||void 0,backgroundColor:l.Utils.getInvertedColor(null===u||void 0===u?void 0:u.color,c)},onChange:t=>{const e=b.find((e=>e.value===t.target.value));g(e),Q(!1)},children:b.map((t=>(0,m.jsxs)(a.MenuItem,{style:"different"===t.value?{opacity:.5}:{color:t.color||void 0,backgroundColor:l.Utils.getInvertedColor(t.color,c)},value:t.value,children:[t.icon?(0,m.jsx)(l.Icon,{src:t.icon,style:{width:16,height:16,marginRight:8}}):null,t.name]},t.value)))})]}),(0,m.jsxs)(a.FormControl,{variant:"standard",fullWidth:!0,children:[(0,m.jsx)(a.InputLabel,{children:h("Owner group")}),(0,m.jsx)(a.Select,{variant:"standard",disabled:G,value:v?v.value:"",renderValue:()=>(0,m.jsxs)("span",{children:[null!==v&&void 0!==v&&v.icon?(0,m.jsx)(l.Icon,{src:v.icon,style:{width:16,height:16,marginRight:8}}):null,v?v.name:""]}),style:"different"===(null===v||void 0===v?void 0:v.value)?{opacity:.5}:{color:(null===v||void 0===v?void 0:v.color)||void 0,backgroundColor:l.Utils.getInvertedColor(null===v||void 0===v?void 0:v.color,c)},onChange:t=>{const e=f.find((e=>e.value===t.target.value));x(e),Q(!1)},children:f.map((t=>(0,m.jsxs)(a.MenuItem,{value:t.value,style:"different"===t.value?{opacity:.5}:{color:t.color||void 0,backgroundColor:l.Utils.getInvertedColor(t.color,c)},children:[t.icon?(0,m.jsx)(l.Icon,{src:t.icon,style:{width:16,height:16,marginRight:8}}):null,t.name]},t.value)))})]})]}),(0,m.jsxs)("div",{style:{display:"flex",margin:10,alignItems:"center",fontSize:10,marginLeft:0,color:"silver"},children:[(0,m.jsx)("div",{style:w?null:{color:"green"},children:h("to apply one item")}),(0,m.jsx)(a.Switch,{disabled:G||!!d||1===A,checked:!!d||w,onChange:t=>{C(t.target.checked),Q(!1)},color:"primary"}),(0,m.jsxs)("div",{style:w?{color:"green"}:null,children:[h("to apply with children")," ",d||A>1?`(${A} ${h("object(s)")})`:""]})]}),G&&(0,m.jsx)(a.LinearProgress,{}),(0,m.jsxs)("div",{style:{overflowY:"auto"},children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("h2",{children:h("Object rights")}),(0,m.jsx)(dt,{mask:P,disabled:G,setMask:z,applyToChildren:w,differentValues:L,t:h,setValue:t=>{D(t),Q(!1)},value:k})]}),S&&(0,m.jsxs)("div",{children:[(0,m.jsx)("h2",{children:h("States rights")}),(0,m.jsx)(dt,{mask:B,disabled:G,setMask:J,applyToChildren:w,differentValues:w?W:[],t:h,setValue:t=>{R(t),Q(!1)},value:F})]})]})]})}):(0,m.jsx)(a.LinearProgress,{})},pt={dialog:{height:"100%",maxHeight:"100%",maxWidth:"100%"},content:{textAlign:"center"},error:t=>({color:"dark"===t.palette.mode?"#ff7777":"#c20000"}),image:{height:"100%",width:"auto"},text:{fontFamily:"Lucida Console, Courier, monospace",width:"100%"},download:{textDecoration:"none",textTransform:"uppercase",fontSize:14,color:"white",border:"1px solid white",borderRadius:5,padding:"8px 16px",marginRight:8}};class mt extends i.Component{constructor(t){super(t),this.audioRef=void 0;const e=this.props.obj._id.split(".");this.state={error:"",image:null,text:null,binary:null,fileName:`${e[e.length-2]}.${e[e.length-1]}`},this.audioRef=o().createRef()}componentDidMount(){this.props.socket.getBinaryState(this.props.obj._id).then((t=>{let e=this.props.obj._id.toLowerCase().split(".").pop();const s=l.Utils.detectMimeType(t);if(s&&(e=s),"jpg"===e)this.setState({image:!0,binary:t,mime:"image/jpeg"});else if("svg"===e)this.setState({image:!0,binary:t,mime:"image/svg+xml"});else if("png"===e||"bmp"===e)this.setState({image:!0,binary:t,mime:`image/${e}`});else if("mp3"===e)this.setState({audio:!0,binary:t,mime:"audio/mpeg"});else if("ogg"===e)this.setState({audio:!0,binary:t,mime:"audio/ogg"});else if("txt"===e||"log"===e)try{const e=btoa(t);this.setState({text:e,binary:t,mime:"text/plain"})}catch{}})).catch((t=>this.setState({error:t})))}render(){return(0,m.jsxs)(a.Dialog,{style:pt.dialog,open:!0,maxWidth:this.state.audio?"sm":"md",onClose:()=>this.props.onClose(),fullWidth:!0,"aria-labelledby":"object-view-dialog-title",children:[(0,m.jsx)(a.DialogTitle,{id:"object-view-dialog-title",children:this.props.t("View file in state: %s",this.props.obj._id)}),(0,m.jsxs)(a.DialogContent,{style:pt.content,children:[this.state.error?(0,m.jsx)(a.Box,{component:"div",sx:pt.error,children:"State is not binary"===this.state.error?this.props.t("No file stored yet"):this.props.t(this.state.error)}):null,this.state.audio?(0,m.jsx)("audio",{ref:this.audioRef,src:`data:${this.state.mime};base64,${this.state.binary}`}):null,this.state.audio?(0,m.jsx)(a.Fab,{color:"primary",onClick:()=>this.audioRef.current&&this.audioRef.current.play(),children:(0,m.jsx)(n.PlayArrow,{})}):null,this.state.image?(0,m.jsx)("img",{src:`data:${this.state.mime};base64,${this.state.binary}`,alt:this.props.obj._id,style:pt.image}):null,null!==this.state.text?(0,m.jsx)("pre",{style:pt.text,children:this.state.text}):null]}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsxs)("a",{style:pt.download,download:this.state.fileName,href:`data:${this.state.mime};base64,${this.state.binary}`,children:[(0,m.jsx)(n.GetApp,{style:{paddingRight:8,height:12}}),(0,m.jsx)("span",{children:this.props.t("Download")})]}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.props.onClose(),startIcon:(0,m.jsx)(n.Close,{}),color:"grey",children:this.props.t("Close")})]})]})}}const ut=(0,l.withWidth)()(mt),gt={funcIcon:{width:16,height:16},formControlLabel:{marginBottom:16},color:{width:70},typeNameEng:{marginLeft:8,opacity:.7,fontStyle:"italic",fontSize:"smaller"},usedInAlias:{},addNewAlias:t=>({backgroundColor:t.palette.primary.main})},vt=["array","boolean","file","json","mixed","number","object","string"];class xt extends i.Component{constructor(t){super(t),this.aliasIDs=void 0;const e=[],s=this.props.obj._id;this.aliasIDs=Object.keys(this.props.objects).filter((t=>t.startsWith("alias.0")));for(let o=0;o<this.aliasIDs.length;o++){var i;const t=null===(i=this.props.objects[this.aliasIDs[o]].common)||void 0===i?void 0:i.alias;(null===t||void 0===t?void 0:t.id)!==s&&("object"!==typeof(null===t||void 0===t?void 0:t.id)||t.id.read!==s&&t.id.write!==s)||e.push(this.aliasIDs[o])}this.state={usedInAliases:e,showAddNewAlias:!e.length,newAliasId:this.props.obj._id,newAliasName:xt.getText(this.props.obj.common.name||this.props.obj._id),newAliasRead:this.props.obj.common.read,newAliasWrite:this.props.obj.common.write,newAliasUnit:this.props.obj.common.unit,newAliasDesc:xt.getText(this.props.obj.common.desc),newAliasType:this.props.obj.common.type,newAliasUseFormula:!1,newAliasReadFormula:"val",newAliasWriteFormula:"val",newAliasColor:this.props.obj.common.color,newAliasIcon:this.props.obj.common.icon}}static getText(t){return t?"object"===typeof t?t[l.I18n.getLanguage()]||t.en||"":t.toString():""}renderAddNewAlias(){return this.state.showAddNewAlias?(0,m.jsxs)(a.Dialog,{open:!0,onClose:()=>this.setState({showAddNewAlias:!1}),children:[(0,m.jsx)(a.DialogTitle,{children:l.I18n.t("Create new alias: %s",`alias.0.${this.state.newAliasId}`)}),(0,m.jsxs)(a.DialogContent,{children:[(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasId,slotProps:{input:{endAdornment:this.state.newAliasId?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasId:""}),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setState({newAliasId:t.target.value}),label:l.I18n.t("Alias ID"),helperText:`alias.0.${this.state.newAliasId}`,fullWidth:!0}),(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasName,slotProps:{input:{endAdornment:this.state.newAliasName?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasName:""}),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setState({newAliasName:t.target.value}),label:l.I18n.t("Alias name"),fullWidth:!0}),(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasDesc,slotProps:{input:{endAdornment:this.state.newAliasDesc?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasDesc:""}),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setState({newAliasDesc:t.target.value}),label:l.I18n.t("Alias description"),fullWidth:!0}),(0,m.jsxs)(a.FormControl,{style:gt.formControlLabel,fullWidth:!0,children:[(0,m.jsx)(a.InputLabel,{children:l.I18n.t("State type")}),(0,m.jsx)(a.Select,{variant:"standard",value:this.state.newAliasType,onChange:t=>this.setState({newAliasType:t.target.value}),children:vt.map((t=>(0,m.jsxs)(a.MenuItem,{value:t,children:[l.I18n.t(t),(0,m.jsxs)("span",{style:gt.typeNameEng,children:["(",t,")"]})]},t)))})]}),(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasUnit,slotProps:{input:{endAdornment:this.state.newAliasUnit?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasUnit:""}),children:(0,m.jsx)(n.Close,{})})}):null}},onChange:t=>this.setState({newAliasUnit:t.target.value}),label:l.I18n.t("Alias units"),fullWidth:!0}),(0,m.jsx)(a.TextField,{variant:"standard",style:{...gt.formControlLabel,...gt.color},label:l.I18n.t("Color"),type:"color",value:this.state.newAliasColor,onChange:t=>this.setState({newAliasColor:t.target.value})}),(0,m.jsx)(a.FormControlLabel,{style:{...gt.formControlLabel,marginLeft:16},control:(0,m.jsx)(a.Checkbox,{indeterminate:void 0===this.state.newAliasRead||null===this.state.newAliasRead,checked:this.state.newAliasRead,onChange:t=>{const e={newAliasRead:t.target.checked};!1===e.newAliasRead&&!1===this.state.newAliasWrite&&(e.newAliasWrite=!0),this.setState(e)}}),label:l.I18n.t("Alias read")}),(0,m.jsx)(a.FormControlLabel,{style:gt.formControlLabel,control:(0,m.jsx)(a.Checkbox,{indeterminate:void 0===this.state.newAliasWrite||null===this.state.newAliasWrite,checked:this.state.newAliasWrite,onChange:t=>{const e={newAliasWrite:t.target.checked};!1===e.newAliasRead&&!1===this.state.newAliasWrite&&(e.newAliasRead=!0),this.setState(e)}}),label:l.I18n.t("Alias write")}),(0,m.jsx)(a.FormControlLabel,{style:gt.formControlLabel,control:(0,m.jsx)(a.Checkbox,{checked:this.state.newAliasUseFormula,onChange:t=>this.setState({newAliasUseFormula:t.target.checked})}),label:l.I18n.t("Use convert functions")}),this.state.newAliasUseFormula&&this.state.newAliasRead?(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasReadFormula,onChange:t=>this.setState({newAliasReadFormula:t.target.value}),label:l.I18n.t("Read formula"),helperText:`${l.I18n.t("JS function like")} "val / 5 + 21"`,slotProps:{input:{endAdornment:this.state.newAliasReadFormula&&"val"!==this.state.newAliasReadFormula?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasReadFormula:"val"}),children:(0,m.jsx)(n.Close,{})})}):null,startAdornment:(0,m.jsx)(a.InputAdornment,{position:"start",children:(0,m.jsx)(l.IconFx,{style:gt.funcIcon})})}},fullWidth:!0}):null,this.state.newAliasUseFormula&&this.state.newAliasWrite?(0,m.jsx)(a.TextField,{style:gt.formControlLabel,variant:"standard",value:this.state.newAliasWriteFormula,onChange:t=>this.setState({newAliasWriteFormula:t.target.value}),label:l.I18n.t("Write formula"),slotProps:{input:{endAdornment:this.state.newAliasWriteFormula&&"val"!==this.state.newAliasWriteFormula?(0,m.jsx)(a.InputAdornment,{position:"end",children:(0,m.jsx)(a.IconButton,{size:"small",onClick:()=>this.setState({newAliasWriteFormula:"val"}),children:(0,m.jsx)(n.Close,{})})}):null,startAdornment:(0,m.jsx)(a.InputAdornment,{position:"start",children:(0,m.jsx)(l.IconFx,{style:gt.funcIcon})})}},helperText:`${l.I18n.t("JS function like")} "val / 5 + 21"`,fullWidth:!0}):null]}),(0,m.jsxs)(a.DialogActions,{children:[(0,m.jsx)(a.Button,{variant:"contained",disabled:!this.state.newAliasId||!!this.props.objects[`alias.0.${this.state.newAliasId}`],onClick:async()=>{const t={_id:`alias.0.${this.state.newAliasId}`,type:"state",common:{name:this.state.newAliasName,type:this.props.obj.common.type,alias:{id:this.props.obj._id}},native:{}};this.state.newAliasDesc&&(t.common.desc=this.state.newAliasDesc),this.state.newAliasType&&(t.common.type=this.state.newAliasType),this.state.newAliasUnit&&(t.common.unit=this.state.newAliasUnit),void 0!==this.state.newAliasRead&&null!==this.state.newAliasRead&&(t.common.read=this.state.newAliasRead),void 0!==this.state.newAliasWrite&&null!==this.state.newAliasWrite&&(t.common.write=this.state.newAliasWrite),this.state.newAliasColor&&(t.common.color=this.state.newAliasColor),this.state.newAliasIcon&&(t.common.icon=this.state.newAliasIcon),this.state.newAliasUseFormula&&(!1!==t.common.read&&this.state.newAliasReadFormula&&"val"!==this.state.newAliasReadFormula&&(t.common.alias.read=this.state.newAliasReadFormula),!1!==t.common.write&&this.state.newAliasWriteFormula&&"val"!==this.state.newAliasWriteFormula&&(t.common.alias.write=this.state.newAliasWriteFormula)),await this.props.socket.setObject(t._id,t),this.setState({showAddNewAlias:!1}),this.props.onRedirect(t._id,2e3),this.props.onClose()},startIcon:(0,m.jsx)(n.AddLink,{}),color:"primary",children:this.props.t("Create")}),(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.setState({showAddNewAlias:!1}),startIcon:(0,m.jsx)(n.Close,{}),color:"grey",children:this.props.t("Close")})]})]}):null}render(){return(0,m.jsxs)(a.Dialog,{open:!0,maxWidth:"sm",onClose:()=>this.props.onClose(),fullWidth:!0,"aria-labelledby":"object-alias-dialog-title",children:[this.renderAddNewAlias(),(0,m.jsx)(a.DialogTitle,{id:"object-alias-dialog-title",children:this.state.usedInAliases.length?l.I18n.t("This object is used in aliases"):l.I18n.t("This object does not used in any aliases yet")}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsxs)(a.MenuList,{style:{maxWidth:400},children:[this.state.usedInAliases.map((t=>(0,m.jsxs)(a.MenuItem,{style:gt.usedInAlias,onClick:()=>this.props.onRedirect(t),children:[(0,m.jsx)(a.ListItemIcon,{children:(0,m.jsx)(n.Link,{fontSize:"small"})}),(0,m.jsx)(a.ListItemText,{children:t})]},t))),(0,m.jsxs)(a.MenuItem,{onClick:()=>this.setState({showAddNewAlias:!0}),sx:gt.addNewAlias,children:[(0,m.jsx)(a.ListItemIcon,{children:(0,m.jsx)(n.AddLink,{fontSize:"small"})}),(0,m.jsx)(a.ListItemText,{children:l.I18n.t("Create alias from this ID")})]})]})}),(0,m.jsx)(a.DialogActions,{children:(0,m.jsx)(a.Button,{variant:"contained",onClick:()=>this.props.onClose(),startIcon:(0,m.jsx)(n.Close,{}),color:"grey",children:this.props.t("Close")})})]},"editAlias")}}const bt=(0,l.withWidth)()(xt),jt=n.Delete,ft={buttonIcon:{marginRight:4},buttonAll:{color:"#FF0000"},id:{fontStyle:"italic"},buttonText:{whiteSpace:"nowrap"}};class yt extends i.Component{constructor(t){super(t),this.dialogName=void 0,this.filters=void 0,this.t=void 0,this.wordCache=void 0,this.translate=(t,e,s)=>void 0!==e?this.props.t(t,e,s):(this.wordCache[t]||(this.wordCache[t]=this.props.t(t)),this.wordCache[t]),this.dialogName="AdminObjects";const e=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.filters`)||"{}";try{this.filters=JSON.parse(e)}catch{this.filters={}}const s=(window._localStorage||window.localStorage).getItem(`${this.dialogName||"App"}.selected`)||"";this.state={selected:s,name:"",toast:"",deleteObjectShow:null},this.t=this.translate,this.wordCache={}}onDelete(t){const e=this.state.deleteObjectShow.id;t?(this.props.socket.delObjects(e,!0).then((()=>this.setState({toast:this.t("All deleted")}))).catch((t=>window.alert(`Cannot delete object: ${t}`))),this.setState({deleteObjectShow:null})):(this.props.socket.delObject(e,!1).catch((t=>window.alert(`Cannot delete object: ${t}`))),this.setState({deleteObjectShow:null}))}renderToast(){return(0,m.jsx)(a.Snackbar,{anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!this.state.toast,autoHideDuration:3e3,onClose:()=>this.setState({toast:""}),message:this.state.toast,action:(0,m.jsx)(a.IconButton,{size:"small","aria-label":"close",color:"inherit",onClick:()=>this.setState({toast:""}),children:(0,m.jsx)(n.Cancel,{fontSize:"small"})})},"toast")}renderDeleteDialog(){return this.state.deleteObjectShow?(0,m.jsxs)(a.Dialog,{maxWidth:"md",open:!0,onClose:()=>this.setState({deleteObjectShow:null}),"aria-labelledby":"delete-object-dialog-title","aria-describedby":"delete-object-dialog-description",children:[(0,m.jsxs)(a.DialogTitle,{id:"delete-object-dialog-title",children:[this.state.deleteObjectShow.hasChildren?this.t("Delete object(s)"):this.t("Delete object"),":"," ",(0,m.jsx)("span",{style:ft.id,children:this.state.deleteObjectShow.id})]}),(0,m.jsx)(a.DialogContent,{children:(0,m.jsx)(a.DialogContentText,{children:this.t("Are you sure?")})}),(0,m.jsxs)(a.DialogActions,{children:[this.state.deleteObjectShow.hasChildren?(0,m.jsx)(a.Button,{variant:"contained",color:"grey",sx:{"& .MuiButton-text":ft.buttonText},onClick:()=>this.onDelete(!0),startIcon:(0,m.jsx)(jt,{style:ft.buttonAll}),children:this.t("Delete with children",this.state.deleteObjectShow.childrenCount)}):null,this.state.deleteObjectShow.exists?(0,m.jsx)(a.Button,{variant:"contained",sx:{"& .MuiButton-text":ft.buttonText},onClick:()=>this.onDelete(!1),color:"primary",startIcon:(0,m.jsx)(n.Delete,{}),autoFocus:!0,children:this.t("Delete one item")}):null,(0,m.jsx)(a.Button,{variant:"contained",color:"grey",onClick:()=>this.setState({deleteObjectShow:null}),startIcon:(0,m.jsx)(n.Cancel,{}),children:this.t("ra_Cancel")})]})]},"delete"):null}render(){return[this.renderToast(),(0,m.jsx)(r.Ay,{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:z,objectBrowserValue:K,objectBrowserEditObject:Z,objectBrowserEditRole:_,objectBrowserViewFile:ut,objectBrowserAliasEditor:bt,router:l.Router,enableStateValueEdit:!0,onObjectDelete:(t,e,s,i)=>this.setState({deleteObjectShow:{id:t,hasChildren:e,exists:s,childrenCount:i}}),onFilterChanged:t=>{this.filters=t,(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.filters`,JSON.stringify(t))},onSelect:t=>{Array.isArray(t)?(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.selected`,t[0]||""):(window._localStorage||window.localStorage).setItem(`${this.dialogName||"App"}.selected`,t||"")},objectEditBoolean:!0,objectAddBoolean:!0,objectStatesView:!0,objectImportExport:!0,objectEditOfAccessControl:!0,modalNewObject:t=>(0,m.jsx)(nt,{objects:t.objects,expertMode:this.props.expertMode,setObject:(t,e)=>this.props.socket.setObject(t,e).catch((t=>window.alert(t))),selected:t.state.modalNewObj.id,initialType:t.state.modalNewObj.initialType,initialStateType:t.state.modalNewObj.initialStateType,onClose:()=>t.setState({modalNewObj:null}),onApply:()=>t.setState({modalNewObj:null})}),modalEditOfAccessControl:(t,e)=>(0,m.jsx)(ct,{theme:this.props.theme,themeType:this.props.themeType,extendObject:(t,s)=>{this.props.socket.extendObject(t,s).catch((t=>window.alert(t))),e.aclTooltip=null},selected:t.state.selected[0],modalEmptyId:e.obj?"":e.id,objects:t.objects,t:this.t,onClose:()=>t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null}),onApply:()=>t.setState({modalEditOfAccess:!1,modalEditOfAccessObjData:null})})},"browser"),this.renderDeleteDialog()]}}const wt=(0,l.withWidth)()(yt)}}]);
|
|
2
|
+
//# sourceMappingURL=9534.2af54084.chunk.js.map
|