@iobroker/adapter-react-v5
Version:
React components to develop ioBroker interfaces with react.
72 lines • 4.79 kB
JavaScript
import React from 'react';
import { Button, DialogTitle, DialogContent, DialogActions, Dialog, Radio } from '@mui/material';
import { Check as IconOk, Cancel as IconCancel } from '@mui/icons-material';
import { ComplexCron } from '../Components/ComplexCron';
import { SimpleCron, cron2state } from '../Components/SimpleCron';
import { Schedule } from '../Components/Schedule';
import { I18n } from '../i18n';
// Generate cron expression
const styles = {
dialogPaper: {
height: 'calc(100% - 96px)',
},
};
export class DialogCron extends React.Component {
constructor(props) {
super(props);
let cron;
if (this.props.cron && typeof this.props.cron === 'string' && this.props.cron.replace(/^["']/, '')[0] !== '{') {
cron = this.props.cron.replace(/['"]/g, '').trim();
}
else {
cron = this.props.cron || '{}';
if (typeof cron === 'string') {
cron = cron.replace(/^["']/, '').replace(/["']\n?$/, '');
}
}
this.state = {
cron,
mode: this.props.simple
? 'simple'
: this.props.complex
? 'complex'
: (typeof cron === 'object' || cron[0] === '{') && !this.props.noWizard
? 'wizard'
: cron2state(this.props.cron || '* * * * *')
? 'simple'
: 'complex',
};
}
handleCancel() {
this.props.onClose();
}
handleOk() {
this.props.onOk(this.state.cron);
this.props.onClose();
}
setMode(mode) {
this.setState({ mode });
}
render() {
return (React.createElement(Dialog, { onClose: () => { }, maxWidth: "md", fullWidth: true, sx: { '& .MuiDialog-paper': styles.dialogPaper }, open: !0, "aria-labelledby": "cron-dialog-title" },
React.createElement(DialogTitle, { id: "cron-dialog-title" }, this.props.title || I18n.t('ra_Define schedule...')),
React.createElement(DialogContent, { style: { height: '100%', overflow: 'hidden' } },
(this.props.simple && this.props.complex) || (!this.props.simple && !this.props.complex) ? (React.createElement("div", null,
!this.props.simple && !this.props.complex && !this.props.noWizard && (React.createElement(React.Fragment, null,
React.createElement(Radio, { key: "wizard", checked: this.state.mode === 'wizard', onChange: () => this.setMode('wizard') }),
React.createElement("label", { onClick: () => this.setMode('wizard'), style: this.state.mode !== 'wizard' ? { color: 'lightgrey' } : {} }, I18n.t('sc_wizard')))),
((!this.props.simple && !this.props.complex) || this.props.simple) && (React.createElement(React.Fragment, null,
React.createElement(Radio, { key: "simple", checked: this.state.mode === 'simple', onChange: () => this.setMode('simple') }),
React.createElement("label", { onClick: () => this.setMode('simple'), style: this.state.mode !== 'simple' ? { color: 'lightgrey' } : {} }, I18n.t('sc_simple')))),
((!this.props.simple && !this.props.complex) || this.props.complex) && (React.createElement(React.Fragment, null,
React.createElement(Radio, { key: "complex", checked: this.state.mode === 'complex', onChange: () => this.setMode('complex') }),
React.createElement("label", { onClick: () => this.setMode('complex'), style: this.state.mode !== 'complex' ? { color: 'lightgrey' } : {} }, I18n.t('sc_cron')))))) : null,
this.state.mode === 'simple' && (React.createElement(SimpleCron, { cronExpression: this.state.cron, onChange: cron => this.setState({ cron }), language: I18n.getLanguage() })),
this.state.mode === 'wizard' && (React.createElement(Schedule, { theme: this.props.theme, schedule: this.state.cron, onChange: (cron) => this.setState({ cron }) })),
this.state.mode === 'complex' && (React.createElement(ComplexCron, { cronExpression: this.state.cron, onChange: cron => this.setState({ cron }), language: I18n.getLanguage() }))),
React.createElement(DialogActions, null,
React.createElement(Button, { variant: "contained", onClick: () => this.handleOk(), color: "primary", startIcon: React.createElement(IconOk, null) }, this.props.ok || I18n.t('ra_Ok')),
React.createElement(Button, { variant: "contained", onClick: () => this.handleCancel(), color: "grey", startIcon: React.createElement(IconCancel, null) }, this.props.cancel || I18n.t('ra_Cancel')))));
}
}
//# sourceMappingURL=Cron.js.map