UNPKG

@iobroker/adapter-react-v5

Version:

React components to develop ioBroker interfaces with react.

85 lines 3.97 kB
import React from 'react'; import { Button, DialogTitle, DialogContent, DialogActions, Dialog } from '@mui/material'; import { Check as IconOk, Cancel as IconCancel, Delete as IconClear } from '@mui/icons-material'; import { ComplexCron } from '../Components/ComplexCron'; import { DialogConfirm } from '../Dialogs/Confirm'; import { I18n } from '../i18n'; // Generate cron expression const styles = { headerID: { fontWeight: 'bold', fontStyle: 'italic', }, radio: { display: 'inline-block', }, dialogPaper: { height: 'calc(100% - 96px)', }, }; export class DialogComplexCron 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 = { showWarning: '', cron, }; } handleCancel() { this.props.onClose(); } handleOk(ignoreCheck) { if (!ignoreCheck) { // Check if the CRON will be executed every second or every minute and warn about it const cron = ComplexCron.cron2state(this.state.cron); if (cron.seconds === '*' || cron.seconds === '*/1') { this.setState({ showWarning: 'everySecond' }); return; } if (cron.minutes === '*' || cron.minutes === '*/1') { this.setState({ showWarning: 'everyMinute' }); return; } } this.props.onOk(this.state.cron); this.props.onClose(); } renderWarningDialog() { if (!this.state.showWarning) { return null; } return (React.createElement(DialogConfirm, { title: I18n.t('ra_Please confirm'), text: I18n.t(this.state.showWarning === 'everySecond' ? 'ra_The schedule will be executed every second. Are you sure?' : 'ra_The schedule will be executed every minute. Are you sure?'), onClose: (ok) => this.setState({ showWarning: '' }, () => { if (ok) { this.handleOk(true); } }) })); } handleClear() { this.props.onOk(false); this.props.onClose(); } render() { return (React.createElement(Dialog, { onClose: () => { }, maxWidth: "md", fullWidth: true, sx: { '& .MuiDialog-paper': styles.dialogPaper }, open: !0, "aria-labelledby": "cron-dialog-title" }, this.renderWarningDialog(), React.createElement(DialogTitle, { id: "cron-dialog-title" }, this.props.title || I18n.t('ra_Define schedule...')), React.createElement(DialogContent, { style: { height: '100%', overflow: 'hidden' } }, React.createElement(ComplexCron, { cronExpression: this.state.cron, onChange: cron => this.setState({ cron }), language: I18n.getLanguage() })), React.createElement(DialogActions, null, !!this.props.clearButton && (React.createElement(Button, { color: "grey", variant: "contained", onClick: () => this.handleClear(), startIcon: React.createElement(IconClear, null) }, this.props.clear || I18n.t('ra_Clear'))), 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, { color: "grey", variant: "contained", onClick: () => this.handleCancel(), startIcon: React.createElement(IconCancel, null) }, this.props.cancel || I18n.t('ra_Cancel'))))); } } //# sourceMappingURL=ComplexCron.js.map