@iobroker/adapter-react-v5 4.11.3 → 4.11.5

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.
Files changed (39) hide show
  1. package/Components/IconPicker.d.ts +9 -3
  2. package/Components/IconSelector.d.ts +1 -1
  3. package/Components/Loaders/MV.js +1 -1
  4. package/Components/SimpleCron/cron2text.d.ts +4 -6
  5. package/Components/SimpleCron/cron2text.js +463 -481
  6. package/Components/SimpleCron/cronText.d.ts +1 -1
  7. package/Components/SimpleCron/cronText.js +46 -48
  8. package/Components/SimpleCron/index.d.ts +38 -7
  9. package/Components/SimpleCron/index.js +579 -729
  10. package/Components/SimpleCron/jquery.cron.locale.d.ts +28 -1
  11. package/Components/SimpleCron/jquery.cron.locale.js +530 -336
  12. package/Dialogs/ComplexCron.d.ts +13 -12
  13. package/Dialogs/ComplexCron.js +59 -130
  14. package/Dialogs/Cron.d.ts +17 -14
  15. package/Dialogs/Cron.js +92 -183
  16. package/Dialogs/SimpleCron.d.ts +11 -11
  17. package/Dialogs/SimpleCron.js +49 -119
  18. package/GenericApp.d.ts +7 -2
  19. package/GenericApp.js +3 -25
  20. package/README.md +6 -0
  21. package/i18n/de.json +2 -1
  22. package/i18n/en.json +2 -1
  23. package/i18n/es.json +2 -1
  24. package/i18n/fr.json +2 -1
  25. package/i18n/it.json +2 -1
  26. package/i18n/nl.json +2 -1
  27. package/i18n/pl.json +2 -1
  28. package/i18n/pt.json +2 -1
  29. package/i18n/ru.json +2 -1
  30. package/i18n/uk.json +2 -1
  31. package/i18n/zh-cn.json +2 -1
  32. package/package.json +1 -1
  33. package/Components/SimpleCron/cron2text.js.map +0 -1
  34. package/Components/SimpleCron/cronText.js.map +0 -1
  35. package/Components/SimpleCron/index.js.map +0 -1
  36. package/Components/SimpleCron/jquery.cron.locale.js.map +0 -1
  37. package/Dialogs/ComplexCron.js.map +0 -1
  38. package/Dialogs/Cron.js.map +0 -1
  39. package/Dialogs/SimpleCron.js.map +0 -1
@@ -1,773 +1,623 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
- var _react = _interopRequireDefault(require("react"));
15
- var _propTypes = _interopRequireDefault(require("prop-types"));
16
- var _styles = require("@mui/styles");
17
- var _InputLabel = _interopRequireDefault(require("@mui/material/InputLabel"));
18
- var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
19
- var _FormControl = _interopRequireDefault(require("@mui/material/FormControl"));
20
- var _Select = _interopRequireDefault(require("@mui/material/Select"));
21
- var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
22
- var _FormControlLabel = _interopRequireDefault(require("@mui/material/FormControlLabel"));
23
- var _Checkbox = _interopRequireDefault(require("@mui/material/Checkbox"));
24
- var _cronText = _interopRequireDefault(require("./cronText"));
25
- var _i18n = _interopRequireDefault(require("../../i18n"));
26
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
27
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
28
- var styles = function styles() {
29
- return {
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cron2state = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const styles_1 = require("@mui/styles");
9
+ const InputLabel_1 = __importDefault(require("@mui/material/InputLabel"));
10
+ const MenuItem_1 = __importDefault(require("@mui/material/MenuItem"));
11
+ const FormControl_1 = __importDefault(require("@mui/material/FormControl"));
12
+ const Select_1 = __importDefault(require("@mui/material/Select"));
13
+ const TextField_1 = __importDefault(require("@mui/material/TextField"));
14
+ const FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
15
+ const Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
16
+ const cronText_1 = __importDefault(require("./cronText"));
17
+ const i18n_1 = __importDefault(require("../../i18n"));
18
+ const styles = {
30
19
  mainDiv: {
31
- width: '100%',
32
- height: '100%',
33
- overflow: 'auto'
20
+ width: '100%',
21
+ height: '100%',
22
+ overflow: 'auto',
34
23
  },
35
24
  formControl: {
36
- margin: 0,
37
- minWidth: 120
25
+ margin: 0,
26
+ minWidth: 120,
38
27
  },
39
28
  formControlMarginRight: {
40
- marginRight: 5
29
+ marginRight: 5,
41
30
  },
42
31
  formControlPaddingTop: {
43
- paddingTop: 6.2
44
- }
45
- };
32
+ paddingTop: 6.2,
33
+ },
46
34
  };
47
- var PERIODIC = {
48
- once: 'once',
49
- interval: 'interval',
50
- intervalBetween: 'intervalBetween',
51
- specific: 'specific'
35
+ const PERIODIC = {
36
+ once: 'once',
37
+ interval: 'interval',
38
+ intervalBetween: 'intervalBetween',
39
+ specific: 'specific',
52
40
  };
53
- var PERIODIC_TYPES = {
54
- seconds: 'seconds',
55
- minutes: 'minutes'
56
- // hours: 'hours',
41
+ const PERIODIC_TYPES = {
42
+ seconds: 'seconds',
43
+ minutes: 'minutes',
44
+ // hours: 'hours',
57
45
  };
58
- var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
46
+ const WEEKDAYS = [
47
+ 'Sunday',
48
+ 'Monday',
49
+ 'Tuesday',
50
+ 'Wednesday',
51
+ 'Thursday',
52
+ 'Friday',
53
+ 'Saturday',
54
+ 'Sunday',
55
+ ];
59
56
  function padding(num) {
60
- if (num < 10) {
61
- return "0".concat(num);
62
- }
63
- return "".concat(num);
64
- }
65
- var DEFAULT_STATE = {
66
- mode: PERIODIC.interval,
67
- interval: {
68
- period: 1,
69
- unit: PERIODIC_TYPES.minutes
70
- }
71
- };
72
- var SimpleCron = /*#__PURE__*/function (_React$Component) {
73
- (0, _inherits2["default"])(SimpleCron, _React$Component);
74
- function SimpleCron(props) {
75
- var _this;
76
- (0, _classCallCheck2["default"])(this, SimpleCron);
77
- _this = _callSuper(this, SimpleCron, [props]);
78
- var cron = typeof _this.props.cronExpression === 'string' ? _this.props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
79
- if (cron[0] === '{') {
80
- cron = '';
57
+ if (num < 10) {
58
+ return `0${num}`;
81
59
  }
82
- var state = SimpleCron.cron2state(cron || '* * * * *') || DEFAULT_STATE;
83
- _this.state = {
84
- extended: false,
85
- cron: SimpleCron.state2cron(state),
86
- mode: 'interval',
87
- once: {
88
- time: '00:00',
89
- date: ''
90
- },
91
- interval: {
92
- period: 1,
93
- unit: PERIODIC_TYPES.minutes
94
- },
95
- intervalBetween: {
60
+ return `${num}`;
61
+ }
62
+ const DEFAULT_STATE = {
63
+ mode: 'interval',
64
+ interval: {
96
65
  period: 1,
97
66
  unit: PERIODIC_TYPES.minutes,
98
- timeFrom: 0,
99
- timeTo: 24,
100
- weekdays: [0, 1, 2, 3, 4, 5, 6]
101
- },
102
- specific: {
103
- time: '00:00',
104
- weekdays: [0, 1, 2, 3, 4, 5, 6]
105
- }
106
- };
107
- Object.assign(_this.state, state);
108
- if (_this.state.cron !== _this.props.cronExpression) {
109
- setTimeout(function () {
110
- return _this.props.onChange && _this.props.onChange(_this.state.cron);
111
- }, 100);
67
+ },
68
+ };
69
+ function cron2state(cron) {
70
+ cron = cron.replace(/['"]/g, '').trim();
71
+ const cronParts = cron.split(' ');
72
+ let options;
73
+ let state = null;
74
+ if (cronParts.length === 6) {
75
+ options = {
76
+ seconds: cronParts[0] || '*',
77
+ minutes: cronParts[1] || '*',
78
+ hours: cronParts[2] || '*',
79
+ date: cronParts[3] || '*',
80
+ months: cronParts[4] || '*',
81
+ dow: cronParts[5] || '*',
82
+ };
112
83
  }
113
- return _this;
114
- }
115
- (0, _createClass2["default"])(SimpleCron, [{
116
- key: "recalcCron",
117
- value: function recalcCron() {
118
- this.onChange(SimpleCron.state2cron(this.state));
84
+ else {
85
+ options = {
86
+ seconds: null,
87
+ minutes: cronParts[0] || '*',
88
+ hours: cronParts[1] || '*',
89
+ date: cronParts[2] || '*',
90
+ months: cronParts[3] || '*',
91
+ dow: cronParts[4] || '*',
92
+ };
119
93
  }
120
- }, {
121
- key: "getControlsWeekdaysElements",
122
- value: function getControlsWeekdaysElements(type) {
123
- var _this2 = this;
124
- var settings = this.state[type];
125
- return /*#__PURE__*/_react["default"].createElement("div", {
126
- key: "weekdays",
127
- style: {
128
- paddingLeft: 8,
129
- width: '100%',
130
- maxWidth: 600
131
- }
132
- }, /*#__PURE__*/_react["default"].createElement("h5", null, _i18n["default"].t('ra_On weekdays')), [1, 2, 3, 4, 5, 6, 0].map(function (day) {
133
- return /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], {
134
- key: WEEKDAYS[day],
135
- control: /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
136
- checked: settings.weekdays.indexOf(day) !== -1,
137
- onChange: function onChange(e) {
138
- var _settings = JSON.parse(JSON.stringify(_this2.state[type]));
139
- var pos = _settings.weekdays.indexOf(day);
140
- e.target.checked && pos === -1 && _settings.weekdays.push(day);
141
- !e.target.checked && pos !== -1 && _settings.weekdays.splice(pos, 1);
142
- _settings.weekdays.sort();
143
- _this2.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
144
- return _this2.recalcCron();
145
- });
94
+ // * * * * *
95
+ if (options.seconds === null &&
96
+ options.minutes === '*' &&
97
+ options.hours === '*' &&
98
+ options.date === '*' &&
99
+ options.months === '*') {
100
+ state = {
101
+ mode: 'interval',
102
+ interval: {
103
+ period: 1,
104
+ unit: PERIODIC_TYPES.minutes,
146
105
  },
147
- value: day.toString()
148
- }),
149
- label: _i18n["default"].t(WEEKDAYS[day])
150
- });
151
- }));
152
- }
153
- }, {
154
- key: "getControlsPeriodElements",
155
- value: function getControlsPeriodElements(type) {
156
- var _this3 = this;
157
- var settings = this.state[type];
158
- if (this.state.extended) {
159
- return /*#__PURE__*/_react["default"].createElement("div", {
160
- key: "period",
161
- style: {
162
- paddingLeft: 8,
163
- display: 'inline-block'
164
- }
165
- }, /*#__PURE__*/_react["default"].createElement("h5", {
166
- style: {
167
- marginBottom: 5
168
- }
169
- }, _i18n["default"].t('sc_period')), /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
170
- variant: "standard",
171
- style: {
172
- marginTop: 0,
173
- marginBottom: 0,
174
- verticalAlign: 'bottom'
175
- },
176
- key: "value",
177
- label: _i18n["default"].t('sc_minutes'),
178
- value: settings.minutes,
179
- onChange: function onChange(e) {
180
- var _settings = JSON.parse(JSON.stringify(_this3.state[type]));
181
- _settings.minutes = parseInt(e.target.value, 10);
182
- if (_settings.minutes < 1) {
183
- _settings.minutes = 1;
184
- }
185
- _this3.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
186
- return _this3.recalcCron();
187
- });
188
- },
189
- min: 1,
190
- max: 60,
191
- type: "number",
192
- InputLabelProps: {
193
- shrink: true
194
- },
195
- margin: "normal"
196
- }), /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
197
- variant: "standard",
198
- style: {
199
- marginTop: 0,
200
- marginBottom: 0,
201
- verticalAlign: 'bottom'
202
- },
203
- key: "value",
204
- label: _i18n["default"].t('sc_hours'),
205
- value: settings.hours,
206
- onChange: function onChange(e) {
207
- var _settings = JSON.parse(JSON.stringify(_this3.state[type]));
208
- _settings.hours = parseInt(e.target.value, 10);
209
- if (_settings.hours < 1) {
210
- _settings.hours = 1;
211
- }
212
- _this3.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
213
- return _this3.recalcCron();
214
- });
215
- },
216
- min: 1,
217
- max: 24,
218
- type: "number",
219
- InputLabelProps: {
220
- shrink: true
221
- },
222
- margin: "normal"
223
- }));
224
- }
225
- return /*#__PURE__*/_react["default"].createElement("div", {
226
- key: "period",
227
- style: {
228
- paddingLeft: 8,
229
- display: 'inline-block'
230
- }
231
- }, /*#__PURE__*/_react["default"].createElement("h5", {
232
- style: {
233
- marginBottom: 5
234
- }
235
- }, _i18n["default"].t('sc_period')), /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
236
- variant: "standard",
237
- style: {
238
- marginTop: 0,
239
- marginBottom: 0,
240
- verticalAlign: 'bottom'
241
- },
242
- key: "value",
243
- label: _i18n["default"].t('sc_every'),
244
- value: settings.period,
245
- onChange: function onChange(e) {
246
- var _settings = JSON.parse(JSON.stringify(_this3.state[type]));
247
- _settings.period = parseInt(e.target.value, 10);
248
- if (_settings.period < 1) {
249
- _settings.period = 1;
250
- }
251
- _this3.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
252
- return _this3.recalcCron();
253
- });
254
- },
255
- min: 1,
256
- max: 60,
257
- type: "number",
258
- InputLabelProps: {
259
- shrink: true
260
- },
261
- margin: "normal"
262
- }), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
263
- variant: "standard",
264
- style: {
265
- verticalAlign: 'bottom'
266
- },
267
- value: settings.unit,
268
- onChange: function onChange(e) {
269
- var _settings = JSON.parse(JSON.stringify(_this3.state[type]));
270
- _settings.unit = e.target.value;
271
- _this3.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
272
- return _this3.recalcCron();
273
- });
274
- }
275
- }, Object.keys(PERIODIC_TYPES).map(function (mode) {
276
- return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
277
- key: PERIODIC_TYPES[mode],
278
- value: PERIODIC_TYPES[mode]
279
- }, _i18n["default"].t("sc_".concat(PERIODIC_TYPES[mode])));
280
- })));
281
- }
282
- }, {
283
- key: "getControlsTime",
284
- value: function getControlsTime(type) {
285
- var _this4 = this;
286
- var settings = this.state[type];
287
- return /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
288
- variant: "standard",
289
- className: this.props.classes.formControl,
290
- classes: {
291
- root: this.props.classes.formControlMarginRight
292
- }
293
- }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
294
- variant: "standard",
295
- key: "at",
296
- label: _i18n["default"].t('sc_time'),
297
- value: settings.time,
298
- type: "time",
299
- onChange: function onChange(e) {
300
- var _settings = JSON.parse(JSON.stringify(_this4.state[type]));
301
- _settings.time = e.target.value;
302
- _this4.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
303
- return _this4.recalcCron();
304
- });
305
- },
306
- InputLabelProps: {
307
- shrink: true
308
- },
309
- margin: "normal"
310
- }));
311
- }
312
- }, {
313
- key: "getControlsDate",
314
- value: function getControlsDate(type) {
315
- var _this5 = this;
316
- var settings = this.state[type];
317
- if (!settings.date) {
318
- var d = new Date();
319
- settings.date = "".concat(d.getDate(), ".").concat(padding(d.getMonth() + 1));
320
- }
321
-
322
- // <InputLabel htmlFor="formatted-text-mask-input">{I18n.t('sc_at')}</InputLabel>
323
- return /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
324
- variant: "standard",
325
- className: this.props.classes.formControl
326
- }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
327
- variant: "standard",
328
- key: "date",
329
- label: _i18n["default"].t('sc_date'),
330
- value: settings.date,
331
- type: "text",
332
- inputProps: {
333
- className: this.props.classes.formControlPaddingTop
334
- },
335
- onChange: function onChange(e) {
336
- var _settings = JSON.parse(JSON.stringify(_this5.state[type]));
337
- _settings.date = e.target.value;
338
- _this5.setState((0, _defineProperty2["default"])({}, type, _settings), function () {
339
- return _this5.recalcCron();
340
- });
341
- },
342
- InputLabelProps: {
343
- shrink: true
344
- },
345
- margin: "normal"
346
- }));
347
- }
348
- }, {
349
- key: "getOnceElements",
350
- value: function getOnceElements() {
351
- return /*#__PURE__*/_react["default"].createElement("div", {
352
- style: {
353
- marginLeft: 8
354
- }
355
- }, this.getControlsTime('once'), this.getControlsDate('once'));
356
- }
357
- }, {
358
- key: "getIntervalElements",
359
- value: function getIntervalElements() {
360
- return this.getControlsPeriodElements('interval');
361
- }
362
- }, {
363
- key: "getIntervalBetweenElements",
364
- value: function getIntervalBetweenElements() {
365
- var _this6 = this;
366
- var settings = this.state.intervalBetween;
367
- return [this.getControlsPeriodElements('intervalBetween'), /*#__PURE__*/_react["default"].createElement("div", {
368
- key: "between",
369
- style: {
370
- paddingLeft: 8,
371
- display: 'inline-block',
372
- verticalAlign: 'top'
373
- }
374
- }, /*#__PURE__*/_react["default"].createElement("h5", {
375
- style: {
376
- marginBottom: 5
377
- }
378
- }, _i18n["default"].t('sc_hours')), /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
379
- variant: "standard",
380
- className: this.props.classes.formControl
381
- }, /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], {
382
- shrink: true,
383
- htmlFor: "age-label-placeholder"
384
- }, _i18n["default"].t('sc_from')), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
385
- variant: "standard",
386
- style: {
387
- width: 100
388
- },
389
- value: settings.timeFrom,
390
- onChange: function onChange(e) {
391
- var _settings = JSON.parse(JSON.stringify(_this6.state.intervalBetween));
392
- _settings.timeFrom = parseInt(e.target.value, 10);
393
- _this6.setState({
394
- intervalBetween: _settings
395
- }, function () {
396
- return _this6.recalcCron();
397
- });
398
- }
399
- }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23].map(function (hour) {
400
- return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
401
- key: "B_".concat(hour),
402
- value: hour
403
- }, "".concat(padding(hour), ":00"));
404
- }))), /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
405
- variant: "standard",
406
- className: this.props.classes.formControl
407
- }, /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], {
408
- shrink: true,
409
- htmlFor: "age-label-placeholder"
410
- }, _i18n["default"].t('sc_to')), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
411
- variant: "standard",
412
- style: {
413
- width: 100
414
- },
415
- value: settings.timeTo,
416
- onChange: function onChange(e) {
417
- var _settings = JSON.parse(JSON.stringify(_this6.state.intervalBetween));
418
- _settings.timeTo = parseInt(e.target.value, 10);
419
- _this6.setState({
420
- intervalBetween: _settings
421
- }, function () {
422
- return _this6.recalcCron();
423
- });
424
- }
425
- }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24].map(function (hour) {
426
- return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
427
- key: "A_".concat(hour),
428
- value: hour
429
- }, "".concat(padding(hour), ":00"));
430
- })))), this.getControlsWeekdaysElements('intervalBetween')];
431
- }
432
- }, {
433
- key: "getSpecificTimeElements",
434
- value: function getSpecificTimeElements() {
435
- return [/*#__PURE__*/_react["default"].createElement("div", {
436
- key: "time",
437
- style: {
438
- marginLeft: 8
439
- }
440
- }, this.getControlsTime('specific')), this.getControlsWeekdaysElements('specific')];
441
- }
442
- }, {
443
- key: "onModeChange",
444
- value: function onModeChange(mode) {
445
- var _this7 = this;
446
- if (mode !== this.state.mode) {
447
- this.setState({
448
- mode: mode
449
- }, function () {
450
- return _this7.recalcCron();
451
- });
452
- }
453
- }
454
- }, {
455
- key: "onChange",
456
- value: function onChange(cron) {
457
- if (cron !== this.state.cron) {
458
- this.setState({
459
- cron: cron
460
- });
461
- this.props.onChange && this.props.onChange(cron);
462
- }
463
- }
464
- }, {
465
- key: "render",
466
- value: function render() {
467
- var _this8 = this;
468
- return /*#__PURE__*/_react["default"].createElement("div", {
469
- className: this.props.classes.mainDiv
470
- }, /*#__PURE__*/_react["default"].createElement("div", {
471
- style: {
472
- paddingLeft: 8,
473
- width: '100%'
474
- }
475
- }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
476
- style: {
477
- width: '100%'
478
- },
479
- value: this.state.cron,
480
- disabled: true
481
- })), /*#__PURE__*/_react["default"].createElement("div", {
482
- style: {
483
- paddingLeft: 8,
484
- width: '100%',
485
- height: 60
486
- }
487
- }, (0, _cronText["default"])(this.state.cron, this.props.language || 'en')), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
488
- variant: "standard",
489
- style: {
490
- marginLeft: 8,
491
- marginTop: 8
492
- },
493
- className: this.props.classes.formControl
494
- }, /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], null, _i18n["default"].t('ra_Repeat')), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
495
- variant: "standard",
496
- value: this.state.mode,
497
- onChange: function onChange(e) {
498
- return _this8.onModeChange(e.target.value);
499
- },
500
- inputProps: {
501
- name: 'mode',
502
- id: 'mode'
503
- }
504
- }, Object.keys(PERIODIC).map(function (mode) {
505
- return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
506
- key: PERIODIC[mode],
507
- value: PERIODIC[mode]
508
- }, _i18n["default"].t("sc_".concat(PERIODIC[mode])));
509
- })))), this.state.mode === PERIODIC.once && this.getOnceElements(), this.state.mode === PERIODIC.interval && this.getIntervalElements(), this.state.mode === PERIODIC.intervalBetween && this.getIntervalBetweenElements(), this.state.mode === PERIODIC.specific && this.getSpecificTimeElements());
510
- }
511
- }], [{
512
- key: "periodArray2text",
513
- value: function periodArray2text(list, max) {
514
- max = max || 7;
515
- if (list.length === max) {
516
- return '*';
517
- }
518
- var text = [];
519
- var start = null;
520
- var end = null;
521
- for (var i = 0; i < list.length; i++) {
522
- if (start === null) {
523
- start = list[i];
524
- end = list[i];
525
- } else if (list[i - 1] + 1 === list[i]) {
526
- end = list[i];
527
- } else {
528
- if (start !== end) {
529
- text.push("".concat(start, "-").concat(end));
530
- } else {
531
- text.push(start);
532
- }
533
- start = list[i];
534
- end = list[i];
535
- }
536
- }
537
- if (start !== end) {
538
- text.push("".concat(start, "-").concat(end));
539
- } else {
540
- text.push(start);
541
- }
542
- return text.join(',');
543
- }
544
- }, {
545
- key: "text2weekdays",
546
- value: function text2weekdays(text) {
547
- if (text === '*') {
548
- return [0, 1, 2, 3, 4, 5, 6];
549
- }
550
- var parts = text.split(',');
551
- var list = [];
552
- parts.forEach(function (part) {
553
- var _parts = part.split('-');
554
- if (_parts.length === 2) {
555
- var start = parseInt(_parts[0], 10);
556
- var end = parseInt(_parts[1], 10);
557
- for (var day = start; day <= end; day++) {
558
- if (!list.includes(day === 7 ? 0 : day)) {
559
- list.push(day === 7 ? 0 : day);
560
- }
561
- }
562
- } else {
563
- if (part === '7') {
564
- part = 0;
565
- }
566
- part = parseInt(part, 10);
567
- if (!list.includes(part)) {
568
- list.push(part);
569
- }
570
- }
571
- });
572
- list.sort();
573
- return list;
574
- }
575
- }, {
576
- key: "cron2state",
577
- value: function cron2state(cron) {
578
- cron = cron.replace(/['"]/g, '').trim();
579
- var cronParts = cron.split(' ');
580
- var options = {};
581
- var state = {
582
- mode: ''
583
- };
584
- if (cronParts.length === 6) {
585
- options.seconds = cronParts[0] || '*';
586
- options.minutes = cronParts[1] || '*';
587
- options.hours = cronParts[2] || '*';
588
- options.date = cronParts[3] || '*';
589
- options.months = cronParts[4] || '*';
590
- options.dow = cronParts[5] || '*';
591
- } else {
592
- options.seconds = null;
593
- options.minutes = cronParts[0] || '*';
594
- options.hours = cronParts[1] || '*';
595
- options.date = cronParts[2] || '*';
596
- options.months = cronParts[3] || '*';
597
- options.dow = cronParts[4] || '*';
598
- }
599
-
600
- // * * * * *
601
- if (options.seconds === null && options.minutes === '*' && options.hours === '*' && options.date === '*' && options.months === '*') {
602
- state.mode = PERIODIC.interval;
603
- state.interval = {
604
- period: 1,
605
- unit: PERIODIC_TYPES.minutes
606
106
  };
607
- } // * * * * * *
608
- if (options.seconds === '*' && options.minutes === '*' && options.hours === '*' && options.date === '*' && options.months === '*') {
609
- state.mode = PERIODIC.interval;
610
- state.interval = {
611
- period: 1,
612
- unit: PERIODIC_TYPES.seconds
107
+ } // * * * * * *
108
+ if (options.seconds === '*' &&
109
+ options.minutes === '*' &&
110
+ options.hours === '*' &&
111
+ options.date === '*' &&
112
+ options.months === '*') {
113
+ state = {
114
+ mode: 'interval',
115
+ interval: {
116
+ period: 1,
117
+ unit: PERIODIC_TYPES.seconds,
118
+ },
613
119
  };
614
- } else if (options.seconds === null && options.minutes.includes('/') && options.hours === '*' && options.date === '*' && options.months === '*') {
120
+ }
121
+ else if (options.seconds === null &&
122
+ options.minutes.includes('/') &&
123
+ options.hours === '*' &&
124
+ options.date === '*' &&
125
+ options.months === '*') {
615
126
  // */n * * * *
616
- state.mode = PERIODIC.interval;
617
- state.interval = {
618
- period: parseInt(options.minutes.split('/')[1], 10),
619
- unit: PERIODIC_TYPES.minutes
127
+ state = {
128
+ mode: 'interval',
129
+ interval: {
130
+ period: parseInt(options.minutes.split('/')[1], 10),
131
+ unit: PERIODIC_TYPES.minutes,
132
+ },
620
133
  };
621
- } else if (options.seconds !== null && options.seconds.includes('/') && options.minutes === '*' && options.hours === '*' && options.date === '*' && options.months === '*') {
134
+ }
135
+ else if (options.seconds !== null &&
136
+ options.seconds.includes('/') &&
137
+ options.minutes === '*' &&
138
+ options.hours === '*' &&
139
+ options.date === '*' &&
140
+ options.months === '*') {
622
141
  // */n * * * * *
623
- state.mode = PERIODIC.interval;
624
- state.interval = {
625
- period: parseInt(options.seconds.split('/')[1], 10),
626
- unit: PERIODIC_TYPES.seconds
142
+ state = {
143
+ mode: 'interval',
144
+ interval: {
145
+ period: parseInt(options.seconds.split('/')[1], 10),
146
+ unit: PERIODIC_TYPES.seconds,
147
+ },
627
148
  };
628
- } else if (options.seconds !== null && options.seconds.includes('/') && options.minutes === '*' && options.hours.includes('-') && options.date === '*' && options.months === '*') {
149
+ }
150
+ else if (options.seconds !== null &&
151
+ options.seconds.includes('/') &&
152
+ options.minutes === '*' &&
153
+ options.hours.includes('-') &&
154
+ options.date === '*' &&
155
+ options.months === '*') {
629
156
  // */n * 1-24 * * 1-7 or */n * 1-24 * * *
630
- state.mode = PERIODIC.intervalBetween;
631
- state.intervalBetween = {
632
- period: parseInt(options.seconds.split('/')[1], 10),
633
- unit: PERIODIC_TYPES.seconds,
634
- timeFrom: parseInt(options.hours.split('-')[0], 10),
635
- timeTo: parseInt(options.hours.split('-')[1], 10),
636
- weekdays: SimpleCron.text2weekdays(options.dow)
157
+ state = {
158
+ mode: 'intervalBetween',
159
+ intervalBetween: {
160
+ period: parseInt(options.seconds.split('/')[1], 10),
161
+ unit: PERIODIC_TYPES.seconds,
162
+ timeFrom: parseInt(options.hours.split('-')[0], 10),
163
+ timeTo: parseInt(options.hours.split('-')[1], 10),
164
+ weekdays: SimpleCron.text2weekdays(options.dow),
165
+ },
637
166
  };
638
- } else if (options.seconds === null && options.minutes.includes('/') && options.hours.includes('-') && options.date === '*' && options.months === '*') {
167
+ }
168
+ else if (options.seconds === null &&
169
+ options.minutes.includes('/') &&
170
+ options.hours.includes('-') &&
171
+ options.date === '*' &&
172
+ options.months === '*') {
639
173
  // */n 1-24 * * 1-7 or */n 1-24 * * *
640
- state.mode = PERIODIC.intervalBetween;
641
- state.intervalBetween = {
642
- period: parseInt(options.minutes.split('/')[1], 10),
643
- unit: PERIODIC_TYPES.minutes,
644
- timeFrom: parseInt(options.hours.split('-')[0], 10),
645
- timeTo: parseInt(options.hours.split('-')[1], 10),
646
- weekdays: SimpleCron.text2weekdays(options.dow)
174
+ state = {
175
+ mode: 'intervalBetween',
176
+ intervalBetween: {
177
+ period: parseInt(options.minutes.split('/')[1], 10),
178
+ unit: PERIODIC_TYPES.minutes,
179
+ timeFrom: parseInt(options.hours.split('-')[0], 10),
180
+ timeTo: parseInt(options.hours.split('-')[1], 10),
181
+ weekdays: SimpleCron.text2weekdays(options.dow),
182
+ },
647
183
  };
648
- } else if (options.seconds === null && parseInt(options.minutes, 10).toString() === options.minutes && parseInt(options.hours, 10).toString() === options.hours && options.date === '*' && options.months === '*') {
184
+ }
185
+ else if (options.seconds === null &&
186
+ parseInt(options.minutes, 10).toString() === options.minutes &&
187
+ parseInt(options.hours, 10).toString() === options.hours &&
188
+ options.date === '*' &&
189
+ options.months === '*') {
649
190
  // m h * * 1-7 or m h * * *
650
- state.mode = PERIODIC.specific;
651
- state.specific = {
652
- time: "".concat(padding(parseInt(options.hours, 10)), ":").concat(padding(parseInt(options.minutes, 10))),
653
- weekdays: SimpleCron.text2weekdays(options.dow)
191
+ state = {
192
+ mode: 'specific',
193
+ specific: {
194
+ time: `${padding(parseInt(options.hours, 10))}:${padding(parseInt(options.minutes, 10))}`,
195
+ weekdays: SimpleCron.text2weekdays(options.dow),
196
+ },
654
197
  };
655
- } else if (options.seconds === null && parseInt(options.minutes, 10).toString() === options.minutes && parseInt(options.hours, 10).toString() === options.hours && parseInt(options.date, 10).toString() === options.date && parseInt(options.months, 10).toString() === options.months && options.dow === '*') {
198
+ }
199
+ else if (options.seconds === null &&
200
+ parseInt(options.minutes, 10).toString() === options.minutes &&
201
+ parseInt(options.hours, 10).toString() === options.hours &&
202
+ parseInt(options.date, 10).toString() === options.date &&
203
+ parseInt(options.months, 10).toString() === options.months &&
204
+ options.dow === '*') {
656
205
  // m h d M *
657
- state.mode = PERIODIC.once;
658
- state.once = {
659
- time: "".concat(padding(parseInt(options.hours, 10)), ":").concat(padding(parseInt(options.minutes, 10))),
660
- date: "".concat(padding(parseInt(options.date, 10)), ".").concat(padding(parseInt(options.months, 10))),
661
- // ignored
662
- weekdays: SimpleCron.text2weekdays(options.dow)
206
+ state = {
207
+ mode: 'once',
208
+ once: {
209
+ time: `${padding(parseInt(options.hours, 10))}:${padding(parseInt(options.minutes, 10))}`,
210
+ date: `${padding(parseInt(options.date, 10))}.${padding(parseInt(options.months, 10))}`,
211
+ },
663
212
  };
664
- }
665
- if (state.mode) {
666
- return state;
667
- }
668
- return null;
669
213
  }
670
- }, {
671
- key: "state2cron",
672
- value: function state2cron(state) {
673
- var cron = '* * * * *';
674
- if (state.mode === PERIODIC.interval) {
675
- var settings = state.interval || {};
676
- if (settings.period > 60) {
677
- settings.period = 60;
214
+ return state;
215
+ }
216
+ exports.cron2state = cron2state;
217
+ class SimpleCron extends react_1.default.Component {
218
+ constructor(props) {
219
+ super(props);
220
+ let cron = typeof props.cronExpression === 'string' ? props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
221
+ if (cron[0] === '{') {
222
+ cron = '';
678
223
  }
679
- if (settings.period < 1) {
680
- settings.period = 1;
224
+ const state = cron2state(cron || '* * * * *') || DEFAULT_STATE;
225
+ this.state = {
226
+ extended: false,
227
+ cron: SimpleCron.state2cron(state),
228
+ mode: 'interval',
229
+ once: {
230
+ time: '00:00',
231
+ date: '',
232
+ },
233
+ interval: {
234
+ period: 1,
235
+ unit: PERIODIC_TYPES.minutes,
236
+ },
237
+ intervalBetween: {
238
+ period: 1,
239
+ unit: PERIODIC_TYPES.minutes,
240
+ timeFrom: 0,
241
+ timeTo: 24,
242
+ weekdays: [0, 1, 2, 3, 4, 5, 6],
243
+ },
244
+ specific: {
245
+ time: '00:00',
246
+ weekdays: [0, 1, 2, 3, 4, 5, 6],
247
+ },
248
+ };
249
+ Object.assign(this.state, state);
250
+ if (this.state.cron !== props.cronExpression) {
251
+ setTimeout(() => props.onChange && props.onChange(this.state.cron), 100);
681
252
  }
682
- if (settings.minutes > 60) {
683
- settings.minutes = 60;
253
+ }
254
+ static periodArray2text(list, max = 7) {
255
+ max = max || 7;
256
+ if (list.length === max) {
257
+ return '*';
684
258
  }
685
- if (settings.minutes < 1) {
686
- settings.minutes = 1;
259
+ const text = [];
260
+ let start = null;
261
+ let end = null;
262
+ for (let i = 0; i < list.length; i++) {
263
+ if (start === null) {
264
+ start = list[i];
265
+ end = list[i];
266
+ }
267
+ else if (list[i - 1] + 1 === list[i]) {
268
+ end = list[i];
269
+ }
270
+ else {
271
+ if (start !== end) {
272
+ text.push(`${start}-${end}`);
273
+ }
274
+ else {
275
+ text.push(start);
276
+ }
277
+ start = list[i];
278
+ end = list[i];
279
+ }
687
280
  }
688
- if (settings.hours > 24) {
689
- settings.hours = 24;
281
+ if (start !== end) {
282
+ text.push(`${start}-${end}`);
690
283
  }
691
- if (settings.hours < 1) {
692
- settings.hours = 1;
284
+ else {
285
+ text.push(start);
693
286
  }
694
- if (state.extended) {
695
- cron = "".concat(settings.minutes > 1 ? "*/".concat(settings.minutes) : '*', " ").concat(settings.hours > 1 ? "*/".concat(settings.hours) : '*', " * * *");
696
- } else {
697
- switch (settings.unit) {
698
- case PERIODIC_TYPES.seconds:
699
- cron = "".concat(settings.period > 1 ? "*/".concat(settings.period) : '*', " * * * * *");
700
- break;
701
- case PERIODIC_TYPES.minutes:
702
- cron = "".concat(settings.period > 1 ? "*/".concat(settings.period) : '*', " * * * *");
703
- break;
704
- default:
705
- break;
706
- }
287
+ return text.join(',');
288
+ }
289
+ static text2weekdays(text) {
290
+ if (text === '*') {
291
+ return [0, 1, 2, 3, 4, 5, 6];
707
292
  }
708
- } else if (state.mode === PERIODIC.intervalBetween) {
709
- var _settings2 = state.intervalBetween || {};
710
- var hours;
711
- _settings2.timeFrom = _settings2.timeFrom || 0;
712
- _settings2.timeTo = _settings2.timeTo === undefined ? 24 : _settings2.timeTo;
713
- if (_settings2.timeFrom === 0 && _settings2.timeTo === 24) {
714
- hours = '*';
715
- } else {
716
- hours = _settings2.timeFrom !== _settings2.timeTo ? "".concat(_settings2.timeFrom, "-").concat(_settings2.timeTo) : '*';
293
+ const parts = text.split(',');
294
+ const list = [];
295
+ parts.forEach(part => {
296
+ const _parts = part.split('-');
297
+ if (_parts.length === 2) {
298
+ const start = parseInt(_parts[0], 10);
299
+ const end = parseInt(_parts[1], 10);
300
+ for (let day = start; day <= end; day++) {
301
+ if (!list.includes(day === 7 ? 0 : day)) {
302
+ list.push(day === 7 ? 0 : day);
303
+ }
304
+ }
305
+ }
306
+ else {
307
+ if (part === '7') {
308
+ part = '0';
309
+ }
310
+ const numPart = parseInt(part, 10);
311
+ if (!list.includes(numPart)) {
312
+ list.push(numPart);
313
+ }
314
+ }
315
+ });
316
+ list.sort();
317
+ return list;
318
+ }
319
+ static state2cron(state) {
320
+ let cron = '* * * * *';
321
+ if (state.mode === 'interval') {
322
+ const settings = state.interval || {
323
+ period: 1,
324
+ unit: PERIODIC_TYPES.minutes,
325
+ };
326
+ if (settings.period !== undefined && settings.period > 60) {
327
+ settings.period = 60;
328
+ }
329
+ if (settings.period !== undefined && settings.period < 1) {
330
+ settings.period = 1;
331
+ }
332
+ if (settings.minutes !== undefined && settings.minutes !== null && settings.minutes > 60) {
333
+ settings.minutes = 60;
334
+ }
335
+ if (settings.minutes !== undefined && settings.minutes !== null && settings.minutes < 1) {
336
+ settings.minutes = 1;
337
+ }
338
+ if (settings.hours !== undefined && settings.hours !== null && settings.hours > 24) {
339
+ settings.hours = 24;
340
+ }
341
+ if (settings.hours !== undefined && settings.hours !== null && settings.hours < 1) {
342
+ settings.hours = 1;
343
+ }
344
+ if (state.extended) {
345
+ cron = `${settings.minutes !== undefined && settings.minutes !== null && settings.minutes > 1 ? `*/${settings.minutes}` : '*'} ${settings.hours !== undefined && settings.hours !== null && settings.hours > 1 ? `*/${settings.hours}` : '*'} * * *`;
346
+ }
347
+ else {
348
+ switch (settings.unit) {
349
+ case PERIODIC_TYPES.seconds:
350
+ cron = `${settings.period > 1 ? `*/${settings.period}` : '*'} * * * * *`;
351
+ break;
352
+ case PERIODIC_TYPES.minutes:
353
+ cron = `${settings.period > 1 ? `*/${settings.period}` : '*'} * * * *`;
354
+ break;
355
+ default:
356
+ break;
357
+ }
358
+ }
717
359
  }
718
- if (_settings2.period > 60) _settings2.period = 60;
719
- if (_settings2.period < 1) _settings2.period = 1;
720
- _settings2.unit = _settings2.unit || PERIODIC_TYPES.minutes;
721
- switch (_settings2.unit) {
722
- case PERIODIC_TYPES.seconds:
723
- cron = "".concat(_settings2.period > 1 ? "*/".concat(_settings2.period) : '*', " * ").concat(hours, " * * ").concat(this.periodArray2text(_settings2.weekdays));
724
- break;
725
- case PERIODIC_TYPES.minutes:
726
- cron = "".concat(_settings2.period > 1 ? "*/".concat(_settings2.period) : '*', " ").concat(hours, " * * ").concat(this.periodArray2text(_settings2.weekdays));
727
- break;
728
- default:
729
- break;
360
+ else if (state.mode === 'intervalBetween') {
361
+ const settings = state.intervalBetween || {
362
+ period: 1,
363
+ unit: PERIODIC_TYPES.minutes,
364
+ timeFrom: 0,
365
+ timeTo: 24,
366
+ weekdays: [0, 1, 2, 3, 4, 5, 6],
367
+ };
368
+ let hours;
369
+ settings.timeFrom = settings.timeFrom || 0;
370
+ settings.timeTo = settings.timeTo === undefined ? 24 : settings.timeTo;
371
+ if (settings.timeFrom === 0 && settings.timeTo === 24) {
372
+ hours = '*';
373
+ }
374
+ else {
375
+ hours = settings.timeFrom !== settings.timeTo ? `${settings.timeFrom}-${settings.timeTo}` : '*';
376
+ }
377
+ if (settings.period > 60)
378
+ settings.period = 60;
379
+ if (settings.period < 1)
380
+ settings.period = 1;
381
+ settings.unit = settings.unit || PERIODIC_TYPES.minutes;
382
+ switch (settings.unit) {
383
+ case PERIODIC_TYPES.seconds:
384
+ cron = `${settings.period > 1 ? `*/${settings.period}` : '*'} * ${hours} * * ${this.periodArray2text(settings.weekdays)}`;
385
+ break;
386
+ case PERIODIC_TYPES.minutes:
387
+ cron = `${settings.period > 1 ? `*/${settings.period}` : '*'} ${hours} * * ${this.periodArray2text(settings.weekdays)}`;
388
+ break;
389
+ default:
390
+ break;
391
+ }
730
392
  }
731
- } else if (state.mode === PERIODIC.specific) {
732
- var _settings3 = state.specific || {};
733
- var parts = (_settings3.time || '00:00').split(':');
734
- var minutes = parseInt(parts[1], 10) || 0;
735
- if (minutes > 59) minutes = 59;
736
- if (minutes < 0) minutes = 0;
737
- var _hours = parseInt(parts[0], 10) || 0;
738
- if (_hours > 23) _hours = 59;
739
- if (_hours < 0) _hours = 0;
740
- cron = "".concat(minutes, " ").concat(_hours, " * * ").concat(this.periodArray2text(_settings3.weekdays || []));
741
- } else if (state.mode === PERIODIC.once) {
742
- var _settings4 = state.once || {};
743
- if (!_settings4.date) {
744
- _settings4.date = "".concat(new Date().getDate(), ".").concat(padding(new Date().getMonth() + 1));
393
+ else if (state.mode === 'specific') {
394
+ const settings = state.specific || {
395
+ time: '00:00',
396
+ weekdays: [0, 1, 2, 3, 4, 5, 6],
397
+ };
398
+ const parts = (settings.time || '00:00').split(':');
399
+ let minutes = parseInt(parts[1], 10) || 0;
400
+ if (minutes > 59)
401
+ minutes = 59;
402
+ if (minutes < 0)
403
+ minutes = 0;
404
+ let hours = parseInt(parts[0], 10) || 0;
405
+ if (hours > 23)
406
+ hours = 59;
407
+ if (hours < 0)
408
+ hours = 0;
409
+ cron = `${minutes} ${hours} * * ${this.periodArray2text(settings.weekdays || [])}`;
745
410
  }
746
- var _parts2 = (_settings4.time || '00:00').split(':');
747
- var partsDate = _settings4.date.split('.');
748
- var _minutes = parseInt(_parts2[1], 10) || 0;
749
- if (_minutes > 59) _minutes = 59;
750
- if (_minutes < 0) _minutes = 0;
751
- var _hours2 = parseInt(_parts2[0], 10) || 0;
752
- if (_hours2 > 23) _hours2 = 59;
753
- if (_hours2 < 0) _hours2 = 0;
754
- var date = parseInt(partsDate[0], 10) || 1;
755
- if (date > 31) date = 31;
756
- if (date < 1) _hours2 = 1;
757
- var month = parseInt(partsDate[1], 10) || 1;
758
- if (month > 12) month = 12;
759
- if (month < 1) month = 1;
760
- cron = "".concat(_minutes, " ").concat(_hours2, " ").concat(date, " ").concat(month, " *");
761
- }
762
- return cron;
411
+ else if (state.mode === 'once') {
412
+ const settings = state.once || {
413
+ time: '00:00',
414
+ date: '',
415
+ };
416
+ if (!settings.date) {
417
+ settings.date = `${new Date().getDate()}.${padding(new Date().getMonth() + 1)}`;
418
+ }
419
+ const parts = (settings.time || '00:00').split(':');
420
+ const partsDate = settings.date.split('.');
421
+ let minutes = parseInt(parts[1], 10) || 0;
422
+ if (minutes > 59)
423
+ minutes = 59;
424
+ if (minutes < 0)
425
+ minutes = 0;
426
+ let hours = parseInt(parts[0], 10) || 0;
427
+ if (hours > 23)
428
+ hours = 59;
429
+ if (hours < 0)
430
+ hours = 0;
431
+ let date = parseInt(partsDate[0], 10) || 1;
432
+ if (date > 31)
433
+ date = 31;
434
+ if (date < 1)
435
+ hours = 1;
436
+ let month = parseInt(partsDate[1], 10) || 1;
437
+ if (month > 12)
438
+ month = 12;
439
+ if (month < 1)
440
+ month = 1;
441
+ cron = `${minutes} ${hours} ${date} ${month} *`;
442
+ }
443
+ return cron;
763
444
  }
764
- }]);
765
- return SimpleCron;
766
- }(_react["default"].Component);
767
- SimpleCron.propTypes = {
768
- cronExpression: _propTypes["default"].string,
769
- onChange: _propTypes["default"].func,
770
- language: _propTypes["default"].string
771
- };
772
- var _default = exports["default"] = (0, _styles.withStyles)(styles)(SimpleCron);
773
- //# sourceMappingURL=index.js.map
445
+ recalcCron() {
446
+ this.onChange(SimpleCron.state2cron(this.state));
447
+ }
448
+ getControlsWeekdaysElements(type) {
449
+ const settings = type === 'intervalBetween' ? this.state.intervalBetween : this.state.specific;
450
+ return react_1.default.createElement("div", { key: "weekdays", style: { paddingLeft: 8, width: '100%', maxWidth: 600 } },
451
+ react_1.default.createElement("h5", null, i18n_1.default.t('ra_On weekdays')),
452
+ [1, 2, 3, 4, 5, 6, 0].map(day => (react_1.default.createElement(FormControlLabel_1.default, { key: WEEKDAYS[day], control: react_1.default.createElement(Checkbox_1.default, { checked: settings.weekdays.includes(day), onChange: e => {
453
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
454
+ const pos = _settings.weekdays.indexOf(day);
455
+ e.target.checked && pos === -1 && _settings.weekdays.push(day);
456
+ !e.target.checked && pos !== -1 && _settings.weekdays.splice(pos, 1);
457
+ _settings.weekdays.sort();
458
+ if (type === 'intervalBetween') {
459
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
460
+ }
461
+ else {
462
+ this.setState({ specific: _settings }, () => this.recalcCron());
463
+ }
464
+ }, value: day.toString() }), label: i18n_1.default.t(WEEKDAYS[day]) }))));
465
+ }
466
+ getControlsPeriodElements(type) {
467
+ const settings = type === 'interval' ? this.state.interval : this.state.intervalBetween;
468
+ if (this.state.extended) {
469
+ return react_1.default.createElement("div", { key: "period", style: { paddingLeft: 8, display: 'inline-block' } },
470
+ react_1.default.createElement("h5", { style: { marginBottom: 5 } }, i18n_1.default.t('sc_period')),
471
+ react_1.default.createElement(TextField_1.default, { variant: "standard", style: { marginTop: 0, marginBottom: 0, verticalAlign: 'bottom' }, key: "value", label: i18n_1.default.t('sc_minutes'), value: settings.minutes, onChange: e => {
472
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
473
+ _settings.minutes = parseInt(e.target.value, 10);
474
+ if (_settings.minutes < 1) {
475
+ _settings.minutes = 1;
476
+ }
477
+ if (type === 'interval') {
478
+ this.setState({ interval: _settings }, () => this.recalcCron());
479
+ }
480
+ else {
481
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
482
+ }
483
+ }, InputProps: { inputProps: { min: 1, max: 60 } }, type: "number", InputLabelProps: { shrink: true }, margin: "normal" }),
484
+ react_1.default.createElement(TextField_1.default, { variant: "standard", style: { marginTop: 0, marginBottom: 0, verticalAlign: 'bottom' }, key: "value", label: i18n_1.default.t('sc_hours'), value: settings.hours, onChange: e => {
485
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
486
+ _settings.hours = parseInt(e.target.value, 10);
487
+ if (_settings.hours < 1) {
488
+ _settings.hours = 1;
489
+ }
490
+ if (type === 'interval') {
491
+ this.setState({ interval: _settings }, () => this.recalcCron());
492
+ }
493
+ else {
494
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
495
+ }
496
+ }, InputProps: { inputProps: { min: 1, max: 24 } }, type: "number", InputLabelProps: { shrink: true }, margin: "normal" }));
497
+ }
498
+ return react_1.default.createElement("div", { key: "period", style: { paddingLeft: 8, display: 'inline-block' } },
499
+ react_1.default.createElement("h5", { style: { marginBottom: 5 } }, i18n_1.default.t('sc_period')),
500
+ react_1.default.createElement(TextField_1.default, { variant: "standard", style: { marginTop: 0, marginBottom: 0, verticalAlign: 'bottom' }, key: "value", label: i18n_1.default.t('sc_every'), value: settings.period, onChange: e => {
501
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
502
+ _settings.period = parseInt(e.target.value, 10);
503
+ if (_settings.period < 1) {
504
+ _settings.period = 1;
505
+ }
506
+ if (type === 'interval') {
507
+ this.setState({ interval: _settings }, () => this.recalcCron());
508
+ }
509
+ else {
510
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
511
+ }
512
+ }, InputProps: { inputProps: { min: 1, max: 60 } }, type: "number", InputLabelProps: { shrink: true }, margin: "normal" }),
513
+ react_1.default.createElement(Select_1.default, { variant: "standard", style: { verticalAlign: 'bottom' }, value: settings.unit, onChange: e => {
514
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
515
+ _settings.unit = e.target.value;
516
+ if (type === 'interval') {
517
+ this.setState({ interval: _settings }, () => this.recalcCron());
518
+ }
519
+ else {
520
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
521
+ }
522
+ } },
523
+ react_1.default.createElement(MenuItem_1.default, { value: "seconds" }, i18n_1.default.t('sc_seconds')),
524
+ ")",
525
+ react_1.default.createElement(MenuItem_1.default, { value: "minutes" }, i18n_1.default.t('sc_minutes')),
526
+ ")"));
527
+ }
528
+ getControlsTime(type) {
529
+ const settings = type === 'once' ? this.state.once : this.state.specific;
530
+ return react_1.default.createElement(FormControl_1.default, { variant: "standard", className: this.props.classes.formControl, classes: { root: this.props.classes.formControlMarginRight } },
531
+ react_1.default.createElement(TextField_1.default, { variant: "standard", key: "at", label: i18n_1.default.t('sc_time'), value: settings.time, type: "time", onChange: e => {
532
+ const _settings = JSON.parse(JSON.stringify(this.state[type]));
533
+ _settings.time = e.target.value;
534
+ if (type === 'once') {
535
+ this.setState({ once: _settings }, () => this.recalcCron());
536
+ }
537
+ else {
538
+ this.setState({ specific: _settings }, () => this.recalcCron());
539
+ }
540
+ }, InputLabelProps: { shrink: true }, margin: "normal" }));
541
+ }
542
+ getControlsDate() {
543
+ const settings = this.state.once;
544
+ if (!settings.date) {
545
+ const d = new Date();
546
+ settings.date = `${d.getDate()}.${padding(d.getMonth() + 1)}`;
547
+ }
548
+ // <InputLabel htmlFor="formatted-text-mask-input">{I18n.t('sc_at')}</InputLabel>
549
+ return react_1.default.createElement(FormControl_1.default, { variant: "standard", className: this.props.classes.formControl },
550
+ react_1.default.createElement(TextField_1.default, { variant: "standard", key: "date", label: i18n_1.default.t('sc_date'), value: settings.date, type: "text", inputProps: { className: this.props.classes.formControlPaddingTop }, onChange: e => {
551
+ const _settings = JSON.parse(JSON.stringify(this.state.once));
552
+ _settings.date = e.target.value;
553
+ this.setState({ once: _settings }, () => this.recalcCron());
554
+ }, InputLabelProps: { shrink: true }, margin: "normal" }));
555
+ }
556
+ getOnceElements() {
557
+ return react_1.default.createElement("div", { style: { marginLeft: 8 } },
558
+ this.getControlsTime('once'),
559
+ this.getControlsDate());
560
+ }
561
+ getIntervalElements() {
562
+ return this.getControlsPeriodElements('interval');
563
+ }
564
+ getIntervalBetweenElements() {
565
+ const settings = this.state.intervalBetween;
566
+ return [
567
+ this.getControlsPeriodElements('intervalBetween'),
568
+ react_1.default.createElement("div", { key: "between", style: { paddingLeft: 8, display: 'inline-block', verticalAlign: 'top' } },
569
+ react_1.default.createElement("h5", { style: { marginBottom: 5 } }, i18n_1.default.t('sc_hours')),
570
+ react_1.default.createElement(FormControl_1.default, { variant: "standard", className: this.props.classes.formControl },
571
+ react_1.default.createElement(InputLabel_1.default, { shrink: true, htmlFor: "age-label-placeholder" }, i18n_1.default.t('sc_from')),
572
+ react_1.default.createElement(Select_1.default, { variant: "standard", style: { width: 100 }, value: settings.timeFrom, onChange: e => {
573
+ const _settings = JSON.parse(JSON.stringify(this.state.intervalBetween));
574
+ _settings.timeFrom = parseInt(e.target.value, 10);
575
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
576
+ } }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23].map(hour => react_1.default.createElement(MenuItem_1.default, { key: `B_${hour}`, value: hour }, `${padding(hour)}:00`)))),
577
+ react_1.default.createElement(FormControl_1.default, { variant: "standard", className: this.props.classes.formControl },
578
+ react_1.default.createElement(InputLabel_1.default, { shrink: true, htmlFor: "age-label-placeholder" }, i18n_1.default.t('sc_to')),
579
+ react_1.default.createElement(Select_1.default, { variant: "standard", style: { width: 100 }, value: settings.timeTo, onChange: e => {
580
+ const _settings = JSON.parse(JSON.stringify(this.state.intervalBetween));
581
+ _settings.timeTo = parseInt(e.target.value, 10);
582
+ this.setState({ intervalBetween: _settings }, () => this.recalcCron());
583
+ } }, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24].map(hour => (react_1.default.createElement(MenuItem_1.default, { key: `A_${hour}`, value: hour }, `${padding(hour)}:00`)))))),
584
+ this.getControlsWeekdaysElements('intervalBetween'),
585
+ ];
586
+ }
587
+ getSpecificTimeElements() {
588
+ return [
589
+ react_1.default.createElement("div", { key: "time", style: { marginLeft: 8 } }, this.getControlsTime('specific')),
590
+ this.getControlsWeekdaysElements('specific'),
591
+ ];
592
+ }
593
+ onModeChange(mode) {
594
+ if (mode !== this.state.mode) {
595
+ this.setState({ mode }, () => this.recalcCron());
596
+ }
597
+ }
598
+ onChange(cron) {
599
+ if (cron !== this.state.cron) {
600
+ this.setState({ cron });
601
+ this.props.onChange && this.props.onChange(cron);
602
+ }
603
+ }
604
+ render() {
605
+ return react_1.default.createElement("div", { className: this.props.classes.mainDiv },
606
+ react_1.default.createElement("div", { style: { paddingLeft: 8, width: '100%' } },
607
+ react_1.default.createElement(TextField_1.default, { style: { width: '100%' }, value: this.state.cron, disabled: true })),
608
+ react_1.default.createElement("div", { style: { paddingLeft: 8, width: '100%', height: 60 } }, (0, cronText_1.default)(this.state.cron, this.props.language || 'en')),
609
+ react_1.default.createElement("div", null,
610
+ react_1.default.createElement(FormControl_1.default, { variant: "standard", style: { marginLeft: 8, marginTop: 8 }, className: this.props.classes.formControl },
611
+ react_1.default.createElement(InputLabel_1.default, null, i18n_1.default.t('ra_Repeat')),
612
+ react_1.default.createElement(Select_1.default, { variant: "standard", value: this.state.mode, onChange: e => this.onModeChange(e.target.value), inputProps: { name: 'mode', id: 'mode' } },
613
+ react_1.default.createElement(MenuItem_1.default, { value: "once" }, i18n_1.default.t('sc_once')),
614
+ react_1.default.createElement(MenuItem_1.default, { value: "interval" }, i18n_1.default.t('sc_interval')),
615
+ react_1.default.createElement(MenuItem_1.default, { value: "intervalBetween" }, i18n_1.default.t('sc_intervalBetween')),
616
+ react_1.default.createElement(MenuItem_1.default, { value: "specific" }, i18n_1.default.t('sc_specific'))))),
617
+ this.state.mode === PERIODIC.once && this.getOnceElements(),
618
+ this.state.mode === 'interval' && this.getIntervalElements(),
619
+ this.state.mode === 'intervalBetween' && this.getIntervalBetweenElements(),
620
+ this.state.mode === 'specific' && this.getSpecificTimeElements());
621
+ }
622
+ }
623
+ exports.default = (0, styles_1.withStyles)(styles)(SimpleCron);