@iobroker/adapter-react-v5 4.13.6 → 4.13.7

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.
@@ -1,509 +1,424 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
6
17
  });
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 _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
- var _react = _interopRequireDefault(require("react"));
16
- var _propTypes = _interopRequireDefault(require("prop-types"));
17
- var _styles = require("@mui/styles");
18
- var _material = require("@mui/material");
19
- var _i18n = _interopRequireDefault(require("../i18n"));
20
- var _cronText = _interopRequireDefault(require("./SimpleCron/cronText"));
21
- 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)); }
22
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
23
- var styles = function styles() {
24
- return {
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const styles_1 = require("@mui/styles");
31
+ const material_1 = require("@mui/material");
32
+ const i18n_1 = __importDefault(require("../i18n"));
33
+ const cronText_1 = __importDefault(require("./SimpleCron/cronText"));
34
+ const styles = {
25
35
  mainDiv: {
26
- width: '100%',
27
- height: '100%'
36
+ width: '100%',
37
+ height: '100%',
28
38
  },
29
39
  periodSelect: {
30
- // margin: '0 10px 60px 10px',
31
- display: 'block',
32
- width: 200
40
+ // margin: '0 10px 60px 10px',
41
+ display: 'block',
42
+ width: 200,
33
43
  },
34
44
  slider: {
35
- marginTop: 20,
36
- display: 'block',
37
- width: '100%'
45
+ marginTop: 20,
46
+ display: 'block',
47
+ width: '100%',
38
48
  },
39
49
  tabContent: {
40
- padding: 20,
41
- height: 'calc(100% - 240px)',
42
- overflow: 'auto'
50
+ padding: 20,
51
+ height: 'calc(100% - 240px)',
52
+ overflow: 'auto',
43
53
  },
44
54
  numberButton: {
45
- padding: 4,
46
- minWidth: 40,
47
- margin: 5
55
+ padding: 4,
56
+ minWidth: 40,
57
+ margin: 5,
48
58
  },
49
59
  numberButtonBreak: {
50
- display: 'block'
60
+ display: 'block',
51
61
  },
52
62
  appBar: {
53
- color: 'white'
54
- }
55
- };
63
+ color: 'white',
64
+ },
56
65
  };
57
- var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
58
- var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
59
-
66
+ const WEEKDAYS = [
67
+ 'Sunday',
68
+ 'Monday',
69
+ 'Tuesday',
70
+ 'Wednesday',
71
+ 'Thursday',
72
+ 'Friday',
73
+ 'Saturday',
74
+ 'Sunday',
75
+ ];
76
+ const MONTHS = [
77
+ 'January',
78
+ 'February',
79
+ 'March',
80
+ 'April',
81
+ 'May',
82
+ 'June',
83
+ 'July',
84
+ 'August',
85
+ 'September',
86
+ 'October',
87
+ 'November',
88
+ 'December',
89
+ ];
60
90
  // 5-7,9-11 => [5,6,7,9,10,11]
61
91
  function convertMinusIntoArray(value, max) {
62
- var result = [];
63
- if (value === '*') {
64
- if (max === 24 || max === 60 || max === 7) {
65
- for (var i = 0; i < max; i++) {
66
- result.push(i);
67
- }
68
- } else {
69
- for (var _i = 1; _i <= max; _i++) {
70
- result.push(_i);
71
- }
72
- }
73
- return result; // array with entries max
74
- }
75
- var parts = (value || '').toString().split(',');
76
- for (var p = 0; p < parts.length; p++) {
77
- if (!parts[p].trim().length) {
78
- continue;
92
+ let result = [];
93
+ if (value === '*') {
94
+ if (max === 24 || max === 60 || max === 7) {
95
+ for (let i = 0; i < max; i++) {
96
+ result.push(i);
97
+ }
98
+ }
99
+ else {
100
+ for (let i = 1; i <= max; i++) {
101
+ result.push(i);
102
+ }
103
+ }
104
+ return result; // array with entries max
79
105
  }
80
- var items = parts[p].trim().split('-');
81
- if (items.length > 1) {
82
- var iMax = parseInt(items[1], 10);
83
- for (var _i2 = parseInt(items[0], 10); _i2 <= iMax; _i2++) {
84
- result.push(_i2);
85
- }
86
- } else {
87
- result.push(parseInt(parts[p], 10));
106
+ const parts = (value || '').toString().split(',');
107
+ for (let p = 0; p < parts.length; p++) {
108
+ if (!parts[p].trim().length) {
109
+ continue;
110
+ }
111
+ const items = parts[p].trim().split('-');
112
+ if (items.length > 1) {
113
+ const iMax = parseInt(items[1], 10);
114
+ for (let i = parseInt(items[0], 10); i <= iMax; i++) {
115
+ result.push(i);
116
+ }
117
+ }
118
+ else {
119
+ result.push(parseInt(parts[p], 10));
120
+ }
88
121
  }
89
- }
90
- result = result.map(function (a) {
91
- return parseInt(a, 10);
92
- });
93
- result.sort();
94
-
95
- // remove double entries
96
- for (var _p = result.length - 1; _p >= 0; _p--) {
97
- if (result[_p] === result[_p + 1]) {
98
- result.splice(_p + 1, 1);
122
+ result.sort();
123
+ // remove double entries
124
+ for (let p = result.length - 1; p >= 0; p--) {
125
+ if (result[p] === result[p + 1]) {
126
+ result.splice(p + 1, 1);
127
+ }
99
128
  }
100
- }
101
- return result;
129
+ return result;
102
130
  }
103
-
104
131
  // [5,6,7,9,10,11] => 5-7,9-11
105
132
  function convertArrayIntoMinus(value, max) {
106
- if ((0, _typeof2["default"])(value) !== 'object') {
107
- value = [value];
108
- }
109
- if (value.length === max) {
110
- return '*';
111
- }
112
- var newParts = [];
113
- if (!value.length) {
114
- return '-';
115
- }
116
- value = value.map(function (a) {
117
- return parseInt(a, 10);
118
- });
119
- value.sort(function (a, b) {
120
- return a - b;
121
- });
122
- var start = value[0];
123
- var end = value[0];
124
- for (var p = 1; p < value.length; p++) {
125
- if (value[p] - 1 !== parseInt(value[p - 1], 10)) {
126
- if (start === end) {
127
- newParts.push(start);
128
- } else if (end - 1 === start) {
129
- newParts.push("".concat(start, ",").concat(end));
130
- } else {
131
- newParts.push("".concat(start, "-").concat(end));
132
- }
133
- start = value[p];
134
- end = value[p];
135
- } else {
136
- end = value[p];
133
+ if (typeof value !== 'object') {
134
+ value = [value];
137
135
  }
138
- }
139
- if (start === end) {
140
- newParts.push(start);
141
- } else if (end - 1 === start) {
142
- newParts.push("".concat(start, ",").concat(end));
143
- } else {
144
- newParts.push("".concat(start, "-").concat(end));
145
- }
146
- return newParts.join(',');
147
- }
148
- var ComplexCron = /*#__PURE__*/function (_React$Component) {
149
- function ComplexCron(props) {
150
- var _this;
151
- (0, _classCallCheck2["default"])(this, ComplexCron);
152
- _this = _callSuper(this, ComplexCron, [props]);
153
- var cron = typeof _this.props.cronExpression === 'string' ? _this.props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
154
- if (cron[0] === '{') {
155
- cron = '';
136
+ if (value.length === max) {
137
+ return '*';
138
+ }
139
+ const newParts = [];
140
+ if (!value.length) {
141
+ return '-';
142
+ }
143
+ value = value.map(a => parseInt(a, 10));
144
+ value.sort((a, b) => a - b);
145
+ let start = value[0];
146
+ let end = value[0];
147
+ for (let p = 1; p < value.length; p++) {
148
+ if (value[p] - 1 !== parseInt(value[p - 1], 10)) {
149
+ if (start === end) {
150
+ newParts.push(start);
151
+ }
152
+ else if (end - 1 === start) {
153
+ newParts.push(`${start},${end}`);
154
+ }
155
+ else {
156
+ newParts.push(`${start}-${end}`);
157
+ }
158
+ start = value[p];
159
+ }
160
+ end = value[p];
156
161
  }
157
- var state = ComplexCron.cron2state(cron || '* * * * *');
158
- _this.state = {
159
- extended: false,
160
- tab: state.seconds !== false ? 1 : 0,
161
- cron: ComplexCron.state2cron(state),
162
- modes: {
163
- seconds: null,
164
- minutes: null,
165
- hours: null,
166
- dates: null,
167
- months: null,
168
- dows: null
169
- }
170
- };
171
- Object.assign(_this.state, state);
172
- if (_this.state.cron !== _this.props.cronExpression) {
173
- setTimeout(function () {
174
- return _this.props.onChange && _this.props.onChange(_this.state.cron);
175
- }, 100);
162
+ if (start === end) {
163
+ newParts.push(start);
176
164
  }
177
- return _this;
178
- }
179
- (0, _inherits2["default"])(ComplexCron, _React$Component);
180
- return (0, _createClass2["default"])(ComplexCron, [{
181
- key: "recalcCron",
182
- value: function recalcCron() {
183
- var _this2 = this;
184
- var cron = ComplexCron.state2cron(this.state);
185
- if (cron !== this.state.cron) {
186
- this.setState({
187
- cron: cron
188
- }, function () {
189
- return _this2.props.onChange && _this2.props.onChange(_this2.state.cron);
190
- });
191
- }
165
+ else if (end - 1 === start) {
166
+ newParts.push(`${start},${end}`);
192
167
  }
193
- }, {
194
- key: "onChange",
195
- value: function onChange(cron) {
196
- if (cron !== this.state.cron) {
197
- this.setState({
198
- cron: cron
199
- });
200
- this.props.onChange && this.props.onChange(cron);
201
- }
168
+ else {
169
+ newParts.push(`${start}-${end}`);
202
170
  }
203
- }, {
204
- key: "onToggle",
205
- value: function onToggle(i, type, max) {
206
- var _this3 = this;
207
- if (i === true) {
208
- this.setState((0, _defineProperty2["default"])({}, type, '*'), function () {
209
- return _this3.recalcCron();
210
- });
211
- } else if (i === false) {
212
- if (max === 60 || max === 24) {
213
- this.setState((0, _defineProperty2["default"])({}, type, '0'), function () {
214
- return _this3.recalcCron();
215
- });
216
- } else {
217
- this.setState((0, _defineProperty2["default"])({}, type, '1'), function () {
218
- return _this3.recalcCron();
219
- });
171
+ return newParts.join(',');
172
+ }
173
+ class ComplexCron extends react_1.Component {
174
+ constructor(props) {
175
+ super(props);
176
+ let cron = typeof this.props.cronExpression === 'string' ?
177
+ this.props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
178
+ if (cron[0] === '{') {
179
+ cron = '';
220
180
  }
221
- } else {
222
- var nums = convertMinusIntoArray(this.state[type], max);
223
- var pos = nums.indexOf(i);
224
- if (pos !== -1) {
225
- nums.splice(pos, 1);
226
- } else {
227
- nums.push(i);
228
- nums.sort();
181
+ const state = ComplexCron.cron2state(cron || '* * * * *');
182
+ this.state = {
183
+ extended: false,
184
+ tab: state.seconds !== false ? 1 : 0,
185
+ cron: ComplexCron.state2cron(state),
186
+ modes: {
187
+ seconds: null,
188
+ minutes: null,
189
+ hours: null,
190
+ dates: null,
191
+ months: null,
192
+ dows: null,
193
+ },
194
+ };
195
+ Object.assign(this.state, state);
196
+ if (this.state.cron !== this.props.cronExpression) {
197
+ setTimeout(() => this.props.onChange && this.props.onChange(this.state.cron), 100);
229
198
  }
230
- this.setState((0, _defineProperty2["default"])({}, type, convertArrayIntoMinus(nums, max)), function () {
231
- return _this3.recalcCron();
232
- });
233
- }
234
199
  }
235
- }, {
236
- key: "getDigitsSelector",
237
- value: function getDigitsSelector(type, max) {
238
- var _this4 = this;
239
- var values = [];
240
- if (max === 7) {
241
- values = [1, 2, 3, 4, 5, 6, 0];
242
- } else if (max === 60 || max === 24) {
243
- for (var i = 0; i < max; i++) {
244
- values.push(i);
200
+ static cron2state(cron) {
201
+ cron = cron.replace(/['"]/g, '').trim();
202
+ const cronParts = cron.split(' ').map(p => p.trim());
203
+ let options;
204
+ if (cronParts.length === 6) {
205
+ options = {
206
+ seconds: cronParts[0] || '*',
207
+ minutes: cronParts[1] || '*',
208
+ hours: cronParts[2] || '*',
209
+ dates: cronParts[3] || '*',
210
+ months: cronParts[4] || '*',
211
+ dows: cronParts[5] || '*',
212
+ };
245
213
  }
246
- } else {
247
- for (var _i3 = 1; _i3 <= max; _i3++) {
248
- values.push(_i3);
214
+ else {
215
+ options = {
216
+ seconds: false,
217
+ minutes: cronParts[0] || '*',
218
+ hours: cronParts[1] || '*',
219
+ dates: cronParts[2] || '*',
220
+ months: cronParts[3] || '*',
221
+ dows: cronParts[4] || '*',
222
+ };
249
223
  }
250
- }
251
- var parts = convertMinusIntoArray(this.state[type], max);
252
- return [/*#__PURE__*/_react["default"].createElement(_material.Button, {
253
- key: "removeall",
254
- variant: "outlined",
255
- className: this.props.classes.numberButton
256
- // style={{paddingBottom: 20}}
257
- ,
258
- color: "primary",
259
- onClick: function onClick() {
260
- return _this4.onToggle(false, type, max);
224
+ return options;
225
+ }
226
+ static state2cron(state) {
227
+ let text = `${state.minutes} ${state.hours} ${state.dates} ${state.months} ${state.dows}`;
228
+ if (state.seconds !== false) {
229
+ text = `${state.seconds} ${text}`;
261
230
  }
262
- }, _i18n["default"].t('ra_Deselect all')), /*#__PURE__*/_react["default"].createElement(_material.Button, {
263
- key: "addall",
264
- variant: "contained"
265
- // style={{paddingBottom: 20}}
266
- ,
267
- className: this.props.classes.numberButton,
268
- color: "secondary",
269
- onClick: function onClick() {
270
- return _this4.onToggle(true, type, max);
231
+ return text;
232
+ }
233
+ recalcCron() {
234
+ const cron = ComplexCron.state2cron(this.state);
235
+ if (cron !== this.state.cron) {
236
+ this.setState({ cron }, () => this.props.onChange && this.props.onChange(this.state.cron));
237
+ }
238
+ }
239
+ onChange(cron) {
240
+ if (cron !== this.state.cron) {
241
+ this.setState({ cron });
242
+ this.props.onChange && this.props.onChange(cron);
271
243
  }
272
- }, _i18n["default"].t('ra_Select all')), /*#__PURE__*/_react["default"].createElement("div", {
273
- key: "all"
274
- }, values.map(function (i) {
275
- return [max === 7 && i === 4 || max === 12 && i === 7 || max === 31 && !((i - 1) % 10) || max === 60 && i && !(i % 10) || max === 24 && i && !(i % 6) ? /*#__PURE__*/_react["default"].createElement("div", {
276
- key: "allInner".concat(i),
277
- style: {
278
- width: '100%'
279
- }
280
- }) : null, /*#__PURE__*/_react["default"].createElement(_material.Button, {
281
- key: "_".concat(i),
282
- variant: parts.indexOf(i) !== -1 ? 'contained' : 'outlined',
283
- className: _this4.props.classes.numberButton,
284
- color: parts.indexOf(i) !== -1 ? 'secondary' : 'primary',
285
- onClick: function onClick() {
286
- return _this4.onToggle(i, type, max);
287
- }
288
- }, max === 7 ? _i18n["default"].t(WEEKDAYS[i]) : max === 12 ? MONTHS[i - 1] : i)];
289
- }))];
290
244
  }
291
- }, {
292
- key: "getPeriodsTab",
293
- value: function getPeriodsTab(type, max) {
294
- var _this5 = this;
295
- var value = this.state[type];
296
- var every = value === '*';
297
- var everyN = value.toString().includes('/');
298
- var select;
299
- if (this.state.modes[type] === null) {
300
- select = every ? 'every' : everyN ? 'everyN' : 'specific';
301
- var modes = JSON.parse(JSON.stringify(this.state.modes));
302
- modes[type] = select;
303
- return setTimeout(function () {
304
- return _this5.setState({
305
- modes: modes
306
- }, function () {
307
- return _this5.recalcCron();
308
- });
309
- }, 100);
310
- }
311
- every = this.state.modes[type] === 'every';
312
- everyN = this.state.modes[type] === 'everyN';
313
- select = this.state.modes[type];
314
- if (everyN) {
315
- value = parseInt(value.replace('*/', ''), 10) || 1;
316
- }
317
- return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_material.Select, {
318
- variant: "standard",
319
- className: this.props.classes.periodSelect,
320
- style: {
321
- verticalAlign: 'bottom'
322
- },
323
- value: select,
324
- onChange: function onChange(e) {
325
- var modes = JSON.parse(JSON.stringify(_this5.state.modes));
326
- modes[type] = e.target.value;
327
- if (e.target.value === 'every') {
328
- _this5.setState((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, type, '*'), "modes", modes), function () {
329
- return _this5.recalcCron();
330
- });
331
- } else if (e.target.value === 'everyN') {
332
- var num = parseInt(_this5.state[type].toString().replace('*/', ''), 10) || 1;
333
- _this5.setState((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, type, "*/".concat(num)), "modes", modes), function () {
334
- return _this5.recalcCron();
335
- });
336
- } else if (e.target.value === 'specific') {
337
- var _num = parseInt(_this5.state[type].split(',')[0], 10) || 0;
338
- console.log(_num);
339
- if (!_num && (type === 'months' || type === 'dates')) {
340
- _num = 1;
245
+ onToggle(i, type, max) {
246
+ if (i === true) {
247
+ this.setCronAttr(type, '*');
248
+ }
249
+ else if (i === false) {
250
+ if (max === 60 || max === 24) {
251
+ this.setCronAttr(type, '0');
252
+ }
253
+ else {
254
+ this.setCronAttr(type, '1');
341
255
  }
342
- _this5.setState((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, type, convertArrayIntoMinus(_num, max)), "modes", modes), function () {
343
- return _this5.recalcCron();
344
- });
345
- }
346
256
  }
347
- }, /*#__PURE__*/_react["default"].createElement(_material.MenuItem, {
348
- key: "every",
349
- value: "every"
350
- }, _i18n["default"].t("sc_every_".concat(type))), /*#__PURE__*/_react["default"].createElement(_material.MenuItem, {
351
- key: "everyN",
352
- value: "everyN"
353
- }, _i18n["default"].t("sc_everyN_".concat(type))), /*#__PURE__*/_react["default"].createElement(_material.MenuItem, {
354
- key: "specific",
355
- value: "specific"
356
- }, _i18n["default"].t("sc_specific_".concat(type)))), everyN && false && /*#__PURE__*/_react["default"].createElement("span", null, value), everyN && /*#__PURE__*/_react["default"].createElement(_material.TextField, {
357
- variant: "standard",
358
- key: "interval",
359
- label: _i18n["default"].t("sc_".concat(type)),
360
- value: value,
361
- min: 1,
362
- max: max,
363
- onChange: function onChange(e) {
364
- _this5.setState((0, _defineProperty2["default"])({}, type, "*/".concat(e.target.value)), function () {
365
- return _this5.recalcCron();
366
- });
367
- },
368
- InputLabelProps: {
369
- shrink: true
370
- },
371
- type: "number",
372
- margin: "normal"
373
- }), !every && !everyN && this.getDigitsSelector(type, max));
257
+ else {
258
+ const nums = convertMinusIntoArray(this.state[type], max);
259
+ const pos = nums.indexOf(i);
260
+ if (pos !== -1) {
261
+ nums.splice(pos, 1);
262
+ }
263
+ else {
264
+ nums.push(i);
265
+ nums.sort();
266
+ }
267
+ this.setCronAttr(type, convertArrayIntoMinus(nums, max));
268
+ }
374
269
  }
375
- }, {
376
- key: "render",
377
- value: function render() {
378
- var _this6 = this;
379
- var tab = this.state.seconds !== false ? this.state.tab : this.state.tab + 1;
380
- return /*#__PURE__*/_react["default"].createElement("div", {
381
- className: this.props.classes.mainDiv
382
- }, /*#__PURE__*/_react["default"].createElement("div", {
383
- style: {
384
- paddingLeft: 8,
385
- width: '100%'
270
+ getDigitsSelector(type, max) {
271
+ let values = [];
272
+ if (max === 7) {
273
+ values = [1, 2, 3, 4, 5, 6, 0];
274
+ }
275
+ else if (max === 60 || max === 24) {
276
+ for (let i = 0; i < max; i++) {
277
+ values.push(i);
278
+ }
386
279
  }
387
- }, /*#__PURE__*/_react["default"].createElement(_material.TextField, {
388
- variant: "standard",
389
- style: {
390
- width: '100%'
391
- },
392
- value: this.state.cron,
393
- disabled: true
394
- })), /*#__PURE__*/_react["default"].createElement("div", {
395
- style: {
396
- paddingLeft: 8,
397
- width: '100%',
398
- height: 60
280
+ else {
281
+ for (let i = 1; i <= max; i++) {
282
+ values.push(i);
283
+ }
284
+ }
285
+ const parts = convertMinusIntoArray(this.state[type], max);
286
+ return [
287
+ react_1.default.createElement(material_1.Button, { key: "removeall", variant: "outlined", className: this.props.classes.numberButton,
288
+ // style={{paddingBottom: 20}}
289
+ color: "primary", onClick: () => this.onToggle(false, type, max) }, i18n_1.default.t('ra_Deselect all')),
290
+ react_1.default.createElement(material_1.Button, { key: "addall", variant: "contained",
291
+ // style={{paddingBottom: 20}}
292
+ className: this.props.classes.numberButton, color: "secondary", onClick: () => this.onToggle(true, type, max) }, i18n_1.default.t('ra_Select all')),
293
+ react_1.default.createElement("div", { key: "all" }, values.map(i => [((max === 7 && i === 4) ||
294
+ (max === 12 && i === 7) ||
295
+ (max === 31 && !((i - 1) % 10)) ||
296
+ (max === 60 && i && !(i % 10)) ||
297
+ (max === 24 && i && !(i % 6))) ?
298
+ react_1.default.createElement("div", { key: `allInner${i}`, style: { width: '100%' } }) : null, react_1.default.createElement(material_1.Button, { key: `_${i}`, variant: parts.indexOf(i) !== -1 ? 'contained' : 'outlined', className: this.props.classes.numberButton, color: parts.indexOf(i) !== -1 ? 'secondary' : 'primary', onClick: () => this.onToggle(i, type, max) }, max === 7 ? i18n_1.default.t(WEEKDAYS[i]) : (max === 12 ? MONTHS[i - 1] : i)),
299
+ ])),
300
+ ];
301
+ }
302
+ getPeriodsTab(type, max) {
303
+ let value = this.state[type];
304
+ let every = value === '*';
305
+ let everyN = value === undefined || value === null ? false : value.toString().includes('/');
306
+ let select;
307
+ if (this.state.modes[type] === null) {
308
+ select = every ? 'every' : (everyN ? 'everyN' : 'specific');
309
+ const modes = JSON.parse(JSON.stringify(this.state.modes));
310
+ modes[type] = select;
311
+ setTimeout(() => this.setState({ modes }, () => this.recalcCron()), 100);
312
+ return null;
399
313
  }
400
- }, ComplexCron.convertCronToText(this.state.cron, this.props.language || 'en')), /*#__PURE__*/_react["default"].createElement(_material.FormControlLabel, {
401
- control: /*#__PURE__*/_react["default"].createElement(_material.Checkbox, {
402
- checked: this.state.seconds,
403
- onChange: function onChange(e) {
404
- return _this6.setState({
405
- seconds: e.target.checked ? '*' : false
406
- }, function () {
407
- return _this6.recalcCron();
408
- });
409
- }
410
- }),
411
- label: _i18n["default"].t('ra_use seconds')
412
- }), /*#__PURE__*/_react["default"].createElement(_material.AppBar, {
413
- position: "static",
414
- classes: {
415
- root: this.props.classes.appBar
416
- },
417
- color: "secondary"
418
- }, /*#__PURE__*/_react["default"].createElement(_material.Tabs, {
419
- value: this.state.tab,
420
- className: this.props.classes.appBar,
421
- color: "secondary",
422
- onChange: function onChange(active, _tab) {
423
- return _this6.setState({
424
- tab: _tab
425
- });
314
+ every = this.state.modes[type] === 'every';
315
+ everyN = this.state.modes[type] === 'everyN';
316
+ select = this.state.modes[type];
317
+ let valueNumber = 1;
318
+ if (everyN && value) {
319
+ valueNumber = parseInt(value.replace('*/', ''), 10) || 1;
426
320
  }
427
- }, this.state.seconds !== false && /*#__PURE__*/_react["default"].createElement(_material.Tab, {
428
- id: "sc_seconds",
429
- label: _i18n["default"].t('sc_seconds')
430
- }), /*#__PURE__*/_react["default"].createElement(_material.Tab, {
431
- id: "minutes",
432
- label: _i18n["default"].t('sc_minutes')
433
- }), /*#__PURE__*/_react["default"].createElement(_material.Tab, {
434
- id: "hours",
435
- label: _i18n["default"].t('sc_hours')
436
- }), /*#__PURE__*/_react["default"].createElement(_material.Tab, {
437
- id: "dates",
438
- label: _i18n["default"].t('sc_dates')
439
- }), /*#__PURE__*/_react["default"].createElement(_material.Tab, {
440
- id: "months",
441
- label: _i18n["default"].t('sc_months')
442
- }), /*#__PURE__*/_react["default"].createElement(_material.Tab, {
443
- id: "dows",
444
- label: _i18n["default"].t('sc_dows')
445
- }))), tab === 0 && /*#__PURE__*/_react["default"].createElement("div", {
446
- className: this.props.classes.tabContent
447
- }, this.getPeriodsTab('seconds', 60)), tab === 1 && /*#__PURE__*/_react["default"].createElement("div", {
448
- className: this.props.classes.tabContent
449
- }, this.getPeriodsTab('minutes', 60)), tab === 2 && /*#__PURE__*/_react["default"].createElement("div", {
450
- className: this.props.classes.tabContent
451
- }, this.getPeriodsTab('hours', 24)), tab === 3 && /*#__PURE__*/_react["default"].createElement("div", {
452
- className: this.props.classes.tabContent
453
- }, this.getPeriodsTab('dates', 31)), tab === 4 && /*#__PURE__*/_react["default"].createElement("div", {
454
- className: this.props.classes.tabContent
455
- }, this.getPeriodsTab('months', 12)), tab === 5 && /*#__PURE__*/_react["default"].createElement("div", {
456
- className: this.props.classes.tabContent
457
- }, this.getPeriodsTab('dows', 7)));
321
+ return react_1.default.createElement("div", null,
322
+ react_1.default.createElement(material_1.Select, { variant: "standard", className: this.props.classes.periodSelect, style: { verticalAlign: 'bottom' }, value: select, onChange: e => {
323
+ const modes = JSON.parse(JSON.stringify(this.state.modes));
324
+ modes[type] = e.target.value;
325
+ if (e.target.value === 'every') {
326
+ this.setCronAttr(type, '*', modes);
327
+ }
328
+ else if (e.target.value === 'everyN') {
329
+ const num = parseInt((this.state[type] || '').toString().replace('*/', ''), 10) || 1;
330
+ this.setCronAttr(type, `*/${num}`, modes);
331
+ }
332
+ else if (e.target.value === 'specific') {
333
+ let num = parseInt((this.state[type] || '').toString().split(',')[0], 10) || 0;
334
+ if (!num && (type === 'months' || type === 'dates')) {
335
+ num = 1;
336
+ }
337
+ this.setCronAttr(type, convertArrayIntoMinus(num, max), modes);
338
+ }
339
+ } },
340
+ react_1.default.createElement(material_1.MenuItem, { key: "every", value: "every" }, i18n_1.default.t(`sc_every_${type}`)),
341
+ react_1.default.createElement(material_1.MenuItem, { key: "everyN", value: "everyN" }, i18n_1.default.t(`sc_everyN_${type}`)),
342
+ react_1.default.createElement(material_1.MenuItem, { key: "specific", value: "specific" }, i18n_1.default.t(`sc_specific_${type}`))),
343
+ everyN && false && react_1.default.createElement("span", null, value),
344
+ everyN && react_1.default.createElement(material_1.TextField, { variant: "standard", key: "interval", label: i18n_1.default.t(`sc_${type}`), value: valueNumber, inputProps: { min: 1, max: max }, onChange: e => {
345
+ // @ts-expect-error is allowed
346
+ this.setState({ [type]: `*/${e.target.value}` }, () => this.recalcCron());
347
+ }, InputLabelProps: { shrink: true }, type: "number", margin: "normal" }),
348
+ !every && !everyN && this.getDigitsSelector(type, max));
458
349
  }
459
- }], [{
460
- key: "cron2state",
461
- value: function cron2state(cron) {
462
- cron = cron.replace(/['"]/g, '').trim();
463
- var cronParts = cron.split(' ').map(function (p) {
464
- return p.trim();
465
- });
466
- var options = {};
467
- if (cronParts.length === 6) {
468
- options.seconds = cronParts[0] || '*';
469
- options.minutes = cronParts[1] || '*';
470
- options.hours = cronParts[2] || '*';
471
- options.dates = cronParts[3] || '*';
472
- options.months = cronParts[4] || '*';
473
- options.dows = cronParts[5] || '*';
474
- } else {
475
- options.seconds = false;
476
- options.minutes = cronParts[0] || '*';
477
- options.hours = cronParts[1] || '*';
478
- options.dates = cronParts[2] || '*';
479
- options.months = cronParts[3] || '*';
480
- options.dows = cronParts[4] || '*';
481
- }
482
- return options;
350
+ static convertCronToText(cron, lang) {
351
+ if (cron.split(' ').includes('-')) {
352
+ return i18n_1.default.t('ra_Invalid CRON');
353
+ }
354
+ return (0, cronText_1.default)(cron, lang);
483
355
  }
484
- }, {
485
- key: "state2cron",
486
- value: function state2cron(state) {
487
- var text = "".concat(state.minutes, " ").concat(state.hours, " ").concat(state.dates, " ").concat(state.months, " ").concat(state.dows);
488
- if (state.seconds !== false) {
489
- text = "".concat(state.seconds, " ").concat(text);
490
- }
491
- return text;
356
+ setCronAttr(attr, value, modes) {
357
+ if (modes) {
358
+ if (attr === 'seconds') {
359
+ this.setState({ seconds: value, modes }, () => this.recalcCron());
360
+ }
361
+ else if (attr === 'minutes') {
362
+ this.setState({ minutes: value, modes }, () => this.recalcCron());
363
+ }
364
+ else if (attr === 'hours') {
365
+ this.setState({ hours: value, modes }, () => this.recalcCron());
366
+ }
367
+ else if (attr === 'dates') {
368
+ this.setState({ hours: value, modes }, () => this.recalcCron());
369
+ }
370
+ else if (attr === 'months') {
371
+ this.setState({ months: value, modes }, () => this.recalcCron());
372
+ }
373
+ else if (attr === 'dows') {
374
+ this.setState({ dows: value, modes }, () => this.recalcCron());
375
+ }
376
+ else {
377
+ this.setState({ modes }, () => this.recalcCron());
378
+ }
379
+ }
380
+ else {
381
+ if (attr === 'seconds') {
382
+ this.setState({ seconds: value }, () => this.recalcCron());
383
+ }
384
+ else if (attr === 'minutes') {
385
+ this.setState({ minutes: value }, () => this.recalcCron());
386
+ }
387
+ else if (attr === 'hours') {
388
+ this.setState({ hours: value }, () => this.recalcCron());
389
+ }
390
+ else if (attr === 'dates') {
391
+ this.setState({ hours: value }, () => this.recalcCron());
392
+ }
393
+ else if (attr === 'months') {
394
+ this.setState({ months: value }, () => this.recalcCron());
395
+ }
396
+ else if (attr === 'dows') {
397
+ this.setState({ dows: value }, () => this.recalcCron());
398
+ }
399
+ }
492
400
  }
493
- }, {
494
- key: "convertCronToText",
495
- value: function convertCronToText(cron, lang) {
496
- if (cron.split(' ').includes('-')) {
497
- return _i18n["default"].t('ra_Invalid CRON');
498
- }
499
- return (0, _cronText["default"])(cron, lang);
401
+ render() {
402
+ const tab = this.state.seconds !== false ? this.state.tab : this.state.tab + 1;
403
+ return react_1.default.createElement("div", { className: this.props.classes.mainDiv },
404
+ react_1.default.createElement("div", { style: { paddingLeft: 8, width: '100%' } },
405
+ react_1.default.createElement(material_1.TextField, { variant: "standard", style: { width: '100%' }, value: this.state.cron, disabled: true })),
406
+ react_1.default.createElement("div", { style: { paddingLeft: 8, width: '100%', height: 60 } }, ComplexCron.convertCronToText(this.state.cron, this.props.language || 'en')),
407
+ react_1.default.createElement(material_1.FormControlLabel, { control: react_1.default.createElement(material_1.Checkbox, { checked: !!this.state.seconds, onChange: e => this.setState({ seconds: e.target.checked ? '*' : false }, () => this.recalcCron()) }), label: i18n_1.default.t('ra_use seconds') }),
408
+ react_1.default.createElement(material_1.AppBar, { position: "static", classes: { root: this.props.classes.appBar }, color: "secondary" },
409
+ react_1.default.createElement(material_1.Tabs, { value: this.state.tab, className: this.props.classes.appBar, color: "secondary", onChange: (active, _tab) => this.setState({ tab: _tab }) },
410
+ this.state.seconds !== false && react_1.default.createElement(material_1.Tab, { id: "sc_seconds", label: i18n_1.default.t('sc_seconds') }),
411
+ react_1.default.createElement(material_1.Tab, { id: "minutes", label: i18n_1.default.t('sc_minutes') }),
412
+ react_1.default.createElement(material_1.Tab, { id: "hours", label: i18n_1.default.t('sc_hours') }),
413
+ react_1.default.createElement(material_1.Tab, { id: "dates", label: i18n_1.default.t('sc_dates') }),
414
+ react_1.default.createElement(material_1.Tab, { id: "months", label: i18n_1.default.t('sc_months') }),
415
+ react_1.default.createElement(material_1.Tab, { id: "dows", label: i18n_1.default.t('sc_dows') }))),
416
+ tab === 0 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('seconds', 60)),
417
+ tab === 1 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('minutes', 60)),
418
+ tab === 2 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('hours', 24)),
419
+ tab === 3 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('dates', 31)),
420
+ tab === 4 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('months', 12)),
421
+ tab === 5 && react_1.default.createElement("div", { className: this.props.classes.tabContent }, this.getPeriodsTab('dows', 7)));
500
422
  }
501
- }]);
502
- }(_react["default"].Component);
503
- ComplexCron.propTypes = {
504
- cronExpression: _propTypes["default"].string,
505
- onChange: _propTypes["default"].func.isRequired,
506
- language: _propTypes["default"].string
507
- };
508
- var _default = exports["default"] = (0, _styles.withStyles)(styles)(ComplexCron);
509
- //# sourceMappingURL=ComplexCron.js.map
423
+ }
424
+ exports.default = (0, styles_1.withStyles)(styles)(ComplexCron);