Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if anything except source was changed
if (JSON.stringify(commonLocal) !== JSON.stringify(this.objects[id].common)) {
this.scripts[id] = JSON.parse(JSON.stringify(this.objects[id].common));
this.scripts[id].source = oldSource;
}
if (oldSource !== this.objects[id].common.source) {
// take new script if it not yet changed
if (!this.state.changed[id]) {
// just use new value
this.scripts[id].source = this.objects[id].common.source;
} else {
if (this.objects[id].from && this.objects[id].from.startsWith('system.adapter.javascript.')) {
this.objects[id].from = 'system.adapter.admin.0';
// show that script was changed from outside
this.setState({toast: I18n.t('Script %s was modified on disk.', id.split('.').pop())});
}
}
} else {
if (this.state.changed[id]) {
newState.changed = newState.changed || JSON.parse(JSON.stringify(this.state.changed));
newState.changed[id] = false;
_changed = true;
}
}
} else {
delete this.scripts[id];
if (this.state.selected === id) {
if (this.state.editing.indexOf(id) !== -1) {
const editing = JSON.parse(JSON.stringify(this.state.editing));
const pos = editing.indexOf(id);
if (pos !== -1) {
onConvert2JS() {
this.showConfirmDialog(I18n.t('It will not be possible to revert this operation.'), result => {
if (result) {
this.scripts[this.state.selected].engineType = 'Javascript/js';
let source = this.scripts[this.state.selected].source;
const lines = source.split('\n');
lines.pop();
this.scripts[this.state.selected].source = lines.join('\n');
const nowSelected = this.state.selected;
const changed = JSON.parse(JSON.stringify(this.state.changed));
changed[this.state.selected] = true;
this.setState({changed, blockly: false, selected: ''}, () => {
this.setChangedInAdmin();
// force update of the editor
setTimeout(() => this.setState({selected: nowSelected}), 100);
});
renderEnum(obj) {
let smartName = Utils.getSmartNameFromObj(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
// convert old format
if (smartName && typeof smartName === 'object') {
smartName = smartName[I18n.getLanguage()] || smartName.en || '';
}
let name = Utils.getObjectNameFromObj(obj);
return (<div style="{{background:">
<span style="{{opacity:">{smartName || null}{smartName ? (<span> ({name})</span>) : name}</span>
<span style="{{opacity:">{obj._id}</span>
</div>);
}
renderEnum(obj) {
let smartName = Utils.getSmartNameFromObj(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
// convert old format
if (smartName && typeof smartName === 'object') {
smartName = smartName[I18n.getLanguage()] || smartName.en || '';
}
let name = Utils.getObjectNameFromObj(obj);
return (<div style="{{background:">
<span style="{{opacity:">{smartName || null}{smartName ? (<span> ({name})</span>) : name}</span>
<span style="{{opacity:">{obj._id}</span>
</div>
}
else
if (schedule.period.years) {
if (schedule.period.years === 1) {
desc.push(I18n.t('sch_desc_everyYear'));
} else {
desc.push(I18n.t('sch_desc_everyNYears', schedule.period.years));
}
desc.push(I18n.t('sch_desc_onDate', schedule.period.yearDate, schedule.period.yearMonth ? I18n.t(MONTHS[schedule.period.yearMonth - 1]) : I18n.t('sch_desc_everyMonth')));
}
// time
if (schedule.time.exactTime) {
if (ASTRO.indexOf(schedule.time.start) !== -1) {
// at sunset
desc.push(I18n.t('sch_desc_atTime', I18n.t('sch_astro_' + schedule.time.start)));
} else {
// at HH:MM
desc.push(I18n.t('sch_desc_atTime', schedule.time.start));
}
} else {
if (schedule.time.mode === PERIODS.minutes) {
if (schedule.time.interval === 1) {
// every minute
desc.push(I18n.t('sch_desc_everyMinute'));
} else {
// every N minutes
desc.push(I18n.t('sch_desc_everyNMinutes', schedule.time.interval));
}
} else {
if (schedule.time.interval === 1) {
// every minute
getToolbox() {
// Interpolate translated messages into toolbox.
let toolboxText = window.document.getElementById('toolbox').outerHTML;
toolboxText = toolboxText.replace(/{(\w+)}/g, (m, p1) => window.MSG[p1]);
let blocks = '';
const lang = I18n.getLanguage();
for (let cb = 0; cb < this.Blockly.CustomBlocks.length; cb++) {
const name = this.Blockly.CustomBlocks[cb];
// add blocks
blocks += '';
for (const _b in this.Blockly[name].blocks) {
if (this.Blockly[name].blocks.hasOwnProperty(_b)) {
blocks += this.Blockly[name].blocks[_b];
}
}
blocks += '';
}
toolboxText = toolboxText.replace('%%CUSTOM_BLOCKS%%', blocks);
return toolboxText;
}
onToggleEnum(id) {
let obj = this.state.funcs.find(e => e._id === id) || this.state.rooms.find(e => e._id === id);
let smartName = Utils.getSmartNameFromObj(obj);
obj = JSON.parse(JSON.stringify(obj));
if (smartName !== false) {
Utils.disableSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
} else {
Utils.removeSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
}
this.addChanged(id);
this.props.socket.setObject(id, obj)
.then(() => {
// update obj
this.updateObjInState(id, obj);
this.informInstance(id);
setTimeout(() => this.removeChanged(id), 500);
onToggleEnum(id) {
let obj = this.state.funcs.find(e => e._id === id) || this.state.rooms.find(e => e._id === id);
let smartName = Utils.getSmartNameFromObj(obj);
obj = JSON.parse(JSON.stringify(obj));
if (smartName !== false) {
Utils.disableSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
} else {
Utils.removeSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
}
this.addChanged(id);
this.props.socket.setObject(id, obj)
.then(() => {
// update obj
this.updateObjInState(id, obj);
this.informInstance(id);
setTimeout(() => this.removeChanged(id), 500);
});
}
onToggleEnum(id) {
let obj = this.state.funcs.find(e => e._id === id) || this.state.rooms.find(e => e._id === id);
let smartName = Utils.getSmartNameFromObj(obj);
obj = JSON.parse(JSON.stringify(obj));
if (smartName !== false) {
Utils.disableSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
} else {
Utils.removeSmartName(obj, this.props.adapterName + '.' + this.props.instance, this.props.native.noCommon);
}
this.addChanged(id);
this.props.socket.setObject(id, obj)
.then(() => {
// update obj
this.updateObjInState(id, obj);
this.informInstance(id);
setTimeout(() => this.removeChanged(id), 500);
});
}
logHorzLayout: window.localStorage ? window.localStorage.getItem('App.logHorzLayout') === 'true' : false,
runningInstances: {},
confirm: '',
importFile: false,
message: '',
searchText: '',
themeType: window.localStorage ? window.localStorage.getItem('App.theme') || 'light' : 'light',
};
// this.logIndex = 0;
this.logSize = window.localStorage ? parseFloat(window.localStorage.getItem('App.logSize')) || 150 : 150;
this.menuSize = window.localStorage ? parseFloat(window.localStorage.getItem('App.menuSize')) || 500 : 500;
this.scripts = {};
this.hosts = [];
this.importFile = null;
this.socket = new Connection({
autoSubscribes: ['script.*', 'system.adapter.javascript.*'],
autoSubscribeLog: true,
onProgress: progress => {
if (progress === PROGRESS.CONNECTING) {
this.setState({connected: false});
} else if (progress === PROGRESS.READY) {
this.setState({connected: true, progress: 100});
} else {
this.setState({connected: true, progress: Math.round(PROGRESS.READY / progress * 100)});
}
},
onReady: (objects, scripts) => {
I18n.setLanguage(this.socket.systemLang);
window.systemLang = this.socket.systemLang;
this.onObjectChange(objects, scripts, true);
},