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);
});
}
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
getControlsPeriodElements(type) {
const settings = this.state[type];
if (this.state.extended) {
return (<div style="{{paddingLeft:">
<h5 style="{{marginBottom:">{I18n.t('sc_period')}</h5>
{
const settings = JSON.parse(JSON.stringify(this.state[type]));
settings.minutes = parseInt(e.target.value, 10);
if (settings.minutes < 1) settings.minutes = 1;
this.setState({[type]: settings}, () => this.recalcCron());
}}
min={1}
max={60}
type="number"
InputLabelProps={{shrink: true,}}
margin="normal"
/>
</div>
onImport(data) {
this.importFile = data;
if (data) {
this.confirmCallback = this.onImportConfirmed.bind(this);
this.setState({importFile: false, confirm: I18n.t('Existing scripts will be overwritten.')});
} else {
this.setState({importFile: false});
}
}
getControlsPeriodElements(type) {
const settings = this.state[type];
if (this.state.extended) {
return (<div style="{{paddingLeft:">
<h5 style="{{marginBottom:">{I18n.t('sc_period')}</h5>
{
const settings = JSON.parse(JSON.stringify(this.state[type]));
settings.minutes = parseInt(e.target.value, 10);
if (settings.minutes < 1) settings.minutes = 1;
this.setState({[type]: settings}, () => this.recalcCron());
}}
min={1}
max={60}
type="number"
InputLabelProps={{shrink: true,}}
margin="normal"</div>
render() {
if (!this.state.loaded) {
return ();
}
return (
<div>
this.selectTab(e.target.parentNode.dataset.name, index)}>
{this.state.native.amazonAlexa && }
{this.state.native.googleHome && }
{this.state.native.yandexAlisa && }
<div>
{(this.state.selectedTab === 'options' || !this.state.selectedTab) && ( this.setState({errorText: text})}
onLoad={native => this.onLoadConfig(native)}
instance={this.instance}
adapterName={this.adapterName}</div></div>
{
const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
const result = [];
const parsedMonths = JSON.parse(_schedule.period.months);
for (let i = 1; i <= 12; i++) {
if (parsedMonths.indexOf(i) === -1) {
result.push(i);
}
}
result.sort((a, b) => a - b);
_schedule.period.months = JSON.stringify(result);
this.onChange(_schedule);
}}
/>
} label={I18n.t('sch_invert')}
/>)}
<div>
{MONTHS.map((month, i) => ( {
const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
let months;
try {
months = JSON.parse(_schedule.period.months);
} catch (e) {
months = [];
}
if (e.target.checked && months.indexOf(i + 1) === -1) {
months.push(i + 1);
} else if (!e.target.checked && months.indexOf(i + 1) !== -1) {</div>
style={{width: '100%'}}
label={I18n.t('Smart name')}
onKeyDown={e =>
e.keyCode === 13 && this.changeSmartName(e)}
onChange={e => this.editedSmartName = e.target.value}
defaultValue={this.state.editedSmartName}
helperText={I18n.t('You can enter several names divided by comma')}
margin="normal"
/>
<button> this.changeSmartName()} color="primary" autoFocus>{I18n.t('Ok')}</button>
<button> {
this.editedSmartName = null;
this.setState({editId: '', editedSmartName: ''});
}}>{I18n.t('Cancel')}</button>
)
} else {
return null;
}
}
}
this.onChange(_schedule);
}}/>)}
label={I18n.t('sch_periodWeekend')} />),
(<div style="{{verticalAlign:"> {
const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
_schedule.period.dows = '[0,1,2,3,4,5,6]';
if (_schedule.period.days) {
_schedule.period.days = 1;
}
this.onChange(_schedule);
}}/>)
}
label={I18n.t('sch_periodWeekdays')} />
{isSpecific && (schedule.period.days === 1 || schedule.period.weeks) && (
{[1,2,3,4,5,6,0].map(i =>
( {
const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
let dows;
try {
dows = JSON.parse(_schedule.period.dows);
} catch (e) {
dows = [];
}
if (e.target.checked && dows.indexOf(i) === -1) {
dows.push(i);
} else if (!e.target.checked && dows.indexOf(i) !== -1) {
dows.splice(dows.indexOf(i), 1);</div>