@iobroker/adapter-react-v5 6.1.10 → 7.0.1

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 (207) hide show
  1. package/Components/404.js +13 -13
  2. package/Components/Loader.js +223 -223
  3. package/Components/Loaders/PT.css +108 -108
  4. package/Components/Loaders/PT.js +103 -103
  5. package/Components/Loaders/Vendor.css +13 -13
  6. package/Components/Loaders/Vendor.js +7 -7
  7. package/Components/ObjectBrowser.js +29 -29
  8. package/Components/UploadImage.js +305 -305
  9. package/Components/loader.css +221 -221
  10. package/Components/types.d.ts +82 -82
  11. package/GenericApp.js +49 -49
  12. package/LICENSE +22 -22
  13. package/Prompt.js +7 -7
  14. package/README.md +1004 -1005
  15. package/Theme.js +8 -7
  16. package/assets/devices/Alarm Systems.svg +18 -18
  17. package/assets/devices/Amplifier.svg +21 -21
  18. package/assets/devices/Awnings.svg +4 -4
  19. package/assets/devices/Battery Status.svg +4 -4
  20. package/assets/devices/Ceiling Spotlights.svg +15 -15
  21. package/assets/devices/Chandelier.svg +6 -6
  22. package/assets/devices/Climate.svg +11 -11
  23. package/assets/devices/Coffee Makers.svg +5 -5
  24. package/assets/devices/Cold Water.svg +31 -31
  25. package/assets/devices/Computer.svg +21 -21
  26. package/assets/devices/Consumption.svg +7 -7
  27. package/assets/devices/Curtains.svg +43 -43
  28. package/assets/devices/Dishwashers.svg +11 -11
  29. package/assets/devices/Doors.svg +5 -5
  30. package/assets/devices/Doorstep.svg +35 -35
  31. package/assets/devices/Dryer.svg +13 -13
  32. package/assets/devices/Fan.svg +20 -20
  33. package/assets/devices/Floor Lamps.svg +4 -4
  34. package/assets/devices/Garage Doors.svg +9 -9
  35. package/assets/devices/Gates.svg +32 -32
  36. package/assets/devices/Hairdryer.svg +23 -23
  37. package/assets/devices/Handle.svg +6 -6
  38. package/assets/devices/Hanging Lamps.svg +8 -8
  39. package/assets/devices/Heater.svg +44 -44
  40. package/assets/devices/Hoods.svg +11 -11
  41. package/assets/devices/Hot Water.svg +9 -9
  42. package/assets/devices/Humidity.svg +41 -41
  43. package/assets/devices/Iron.svg +4 -4
  44. package/assets/devices/Irrigation.svg +22 -22
  45. package/assets/devices/Led Strip.svg +30 -30
  46. package/assets/devices/Light.svg +29 -29
  47. package/assets/devices/Lightings.svg +46 -46
  48. package/assets/devices/Lock.svg +19 -19
  49. package/assets/devices/Louvre.svg +6 -6
  50. package/assets/devices/Mowing Machine.svg +8 -8
  51. package/assets/devices/Music.svg +12 -12
  52. package/assets/devices/Outdoor Blinds.svg +6 -6
  53. package/assets/devices/People.svg +19 -19
  54. package/assets/devices/Pool.svg +7 -7
  55. package/assets/devices/Power Consumption.svg +12 -12
  56. package/assets/devices/Printer.svg +9 -9
  57. package/assets/devices/Pump.svg +9 -9
  58. package/assets/devices/Receiver.svg +18 -18
  59. package/assets/devices/Sconces.svg +9 -9
  60. package/assets/devices/Security.svg +34 -34
  61. package/assets/devices/Shading.svg +4 -4
  62. package/assets/devices/Shutters.svg +10 -10
  63. package/assets/devices/SmokeDetector.svg +12 -12
  64. package/assets/devices/Sockets.svg +13 -13
  65. package/assets/devices/Speaker.svg +35 -35
  66. package/assets/devices/Stove.svg +11 -11
  67. package/assets/devices/Table Lamps.svg +11 -11
  68. package/assets/devices/Temperature Sensors.svg +28 -28
  69. package/assets/devices/Tv.svg +7 -7
  70. package/assets/devices/Vacuum Cleaner.svg +15 -15
  71. package/assets/devices/Ventilation.svg +12 -12
  72. package/assets/devices/Washing Machines.svg +15 -15
  73. package/assets/devices/Water Consumption.svg +5 -5
  74. package/assets/devices/Water Heater.svg +8 -8
  75. package/assets/devices/Water.svg +40 -40
  76. package/assets/devices/Weather.svg +28 -28
  77. package/assets/devices/Window.svg +7 -7
  78. package/assets/lamp_ceiling.svg +8 -8
  79. package/assets/lamp_table.svg +7 -7
  80. package/assets/no_icon.svg +9 -9
  81. package/assets/rooms/Anteroom.svg +52 -52
  82. package/assets/rooms/Attic.svg +21 -21
  83. package/assets/rooms/Balcony.svg +12 -12
  84. package/assets/rooms/Barn.svg +5 -5
  85. package/assets/rooms/Basement.svg +4 -4
  86. package/assets/rooms/Bathroom.svg +38 -38
  87. package/assets/rooms/Bedroom.svg +5 -5
  88. package/assets/rooms/Boiler Room.svg +12 -12
  89. package/assets/rooms/Carport.svg +17 -17
  90. package/assets/rooms/Cellar.svg +89 -89
  91. package/assets/rooms/Chamber.svg +9 -9
  92. package/assets/rooms/Corridor.svg +52 -52
  93. package/assets/rooms/Dining Area.svg +37 -37
  94. package/assets/rooms/Dining Room.svg +37 -37
  95. package/assets/rooms/Dining.svg +37 -37
  96. package/assets/rooms/Dressing Room.svg +4 -4
  97. package/assets/rooms/Driveway.svg +14 -14
  98. package/assets/rooms/Entrance.svg +44 -44
  99. package/assets/rooms/Equipment Room.svg +14 -14
  100. package/assets/rooms/Front Yard.svg +64 -64
  101. package/assets/rooms/Gallery.svg +13 -13
  102. package/assets/rooms/Garage.svg +20 -20
  103. package/assets/rooms/Garden.svg +12 -12
  104. package/assets/rooms/Ground Floor.svg +95 -95
  105. package/assets/rooms/Guest Bathroom.svg +32 -32
  106. package/assets/rooms/Guest Room.svg +5 -5
  107. package/assets/rooms/Gym.svg +4 -4
  108. package/assets/rooms/Hall.svg +19 -19
  109. package/assets/rooms/Home Theater.svg +7 -7
  110. package/assets/rooms/Kitchen.svg +17 -17
  111. package/assets/rooms/Laundry Room.svg +11 -11
  112. package/assets/rooms/Living Area.svg +10 -10
  113. package/assets/rooms/Living Room.svg +10 -10
  114. package/assets/rooms/Locker Room.svg +16 -16
  115. package/assets/rooms/Nursery.svg +4 -4
  116. package/assets/rooms/Office.svg +8 -8
  117. package/assets/rooms/Outdoors.svg +7 -7
  118. package/assets/rooms/Playroom.svg +5 -5
  119. package/assets/rooms/Pool.svg +7 -7
  120. package/assets/rooms/Rear Wall.svg +30 -30
  121. package/assets/rooms/Second Floor.svg +95 -95
  122. package/assets/rooms/Shed.svg +16 -16
  123. package/assets/rooms/Sleeping Area.svg +22 -22
  124. package/assets/rooms/Stairway.svg +4 -4
  125. package/assets/rooms/Stairwell.svg +15 -15
  126. package/assets/rooms/Storeroom.svg +4 -4
  127. package/assets/rooms/Summer House.svg +27 -27
  128. package/assets/rooms/Swimming Pool.svg +21 -21
  129. package/assets/rooms/Terrace.svg +6 -6
  130. package/assets/rooms/Toilet.svg +10 -10
  131. package/assets/rooms/Upstairs.svg +5 -5
  132. package/assets/rooms/Wardrobe.svg +60 -60
  133. package/assets/rooms/Washroom.svg +19 -19
  134. package/assets/rooms/Wc.svg +10 -10
  135. package/assets/rooms/Windscreen.svg +60 -60
  136. package/assets/rooms/Workshop.svg +22 -22
  137. package/assets/rooms/Workspace.svg +8 -8
  138. package/craco-module-federation.js +71 -71
  139. package/icons/IconFx.js +1 -1
  140. package/icons/IconLogout.js +1 -1
  141. package/index.css +54 -54
  142. package/modulefederation.admin.config.js +31 -31
  143. package/package.json +4 -4
  144. package/src/AdminConnection.tsx +3 -3
  145. package/src/Components/404.tsx +121 -121
  146. package/src/Components/ColorPicker.tsx +315 -315
  147. package/src/Components/ComplexCron.tsx +507 -507
  148. package/src/Components/CopyToClipboard.tsx +165 -165
  149. package/src/Components/CustomModal.tsx +163 -163
  150. package/src/Components/FileBrowser.tsx +2414 -2414
  151. package/src/Components/FileViewer.tsx +393 -393
  152. package/src/Components/Icon.tsx +210 -210
  153. package/src/Components/IconPicker.tsx +149 -149
  154. package/src/Components/IconSelector.tsx +2202 -2202
  155. package/src/Components/Image.tsx +176 -176
  156. package/src/Components/Loader.tsx +304 -304
  157. package/src/Components/Logo.tsx +166 -166
  158. package/src/Components/MDUtils.tsx +100 -100
  159. package/src/Components/ObjectBrowser.tsx +8032 -8032
  160. package/src/Components/Router.tsx +90 -90
  161. package/src/Components/SaveCloseButtons.tsx +113 -113
  162. package/src/Components/Schedule.tsx +1724 -1724
  163. package/src/Components/SelectWithIcon.tsx +197 -197
  164. package/src/Components/TabContainer.tsx +55 -55
  165. package/src/Components/TabContent.tsx +37 -37
  166. package/src/Components/TabHeader.tsx +19 -19
  167. package/src/Components/TableResize.tsx +259 -259
  168. package/src/Components/TextWithIcon.tsx +148 -148
  169. package/src/Components/ToggleThemeMenu.tsx +34 -34
  170. package/src/Components/TreeTable.tsx +919 -919
  171. package/src/Components/UploadImage.tsx +599 -599
  172. package/src/Components/Utils.tsx +1794 -1794
  173. package/src/Components/loader.css +221 -221
  174. package/src/Components/withWidth.tsx +21 -21
  175. package/src/Connection.tsx +7 -7
  176. package/src/Dialogs/ComplexCron.tsx +129 -129
  177. package/src/Dialogs/Confirm.tsx +162 -162
  178. package/src/Dialogs/Cron.tsx +182 -182
  179. package/src/Dialogs/Error.tsx +72 -72
  180. package/src/Dialogs/Message.tsx +71 -71
  181. package/src/Dialogs/SelectFile.tsx +270 -270
  182. package/src/Dialogs/SelectID.tsx +298 -298
  183. package/src/Dialogs/SimpleCron.tsx +100 -100
  184. package/src/Dialogs/TextInput.tsx +107 -107
  185. package/src/GenericApp.tsx +976 -976
  186. package/src/LegacyConnection.tsx +3589 -3589
  187. package/src/Prompt.tsx +20 -20
  188. package/src/Theme.tsx +479 -479
  189. package/src/icons/IconAdapter.tsx +20 -20
  190. package/src/icons/IconAlias.tsx +20 -20
  191. package/src/icons/IconChannel.tsx +21 -21
  192. package/src/icons/IconClearFilter.tsx +22 -22
  193. package/src/icons/IconClosed.tsx +17 -17
  194. package/src/icons/IconCopy.tsx +16 -16
  195. package/src/icons/IconDevice.tsx +27 -27
  196. package/src/icons/IconDocument.tsx +17 -17
  197. package/src/icons/IconDocumentReadOnly.tsx +18 -18
  198. package/src/icons/IconExpert.tsx +18 -18
  199. package/src/icons/IconFx.tsx +36 -36
  200. package/src/icons/IconInstance.tsx +20 -20
  201. package/src/icons/IconLogout.tsx +30 -30
  202. package/src/icons/IconNoIcon.tsx +19 -19
  203. package/src/icons/IconOpen.tsx +17 -17
  204. package/src/icons/IconProps.tsx +15 -15
  205. package/src/icons/IconState.tsx +17 -17
  206. package/src/index.css +54 -54
  207. package/types.d.ts +134 -134
@@ -1,507 +1,507 @@
1
- import React, { Component } from 'react';
2
-
3
- import {
4
- Checkbox,
5
- Button,
6
- MenuItem,
7
- Select,
8
- FormControlLabel,
9
- AppBar,
10
- Tabs,
11
- Tab,
12
- TextField, Box,
13
- } from '@mui/material';
14
-
15
- import I18n from '../i18n';
16
- import convertCronToText from './SimpleCron/cronText';
17
-
18
- const styles: Record<string, React.CSSProperties> = {
19
- mainDiv: {
20
- width: '100%',
21
- height: '100%',
22
- },
23
- periodSelect: {
24
- // margin: '0 10px 60px 10px',
25
- display: 'block',
26
- width: 200,
27
- },
28
- slider: {
29
- marginTop: 20,
30
- display: 'block',
31
- width: '100%',
32
- },
33
- tabContent: {
34
- padding: 20,
35
- height: 'calc(100% - 240px)',
36
- overflow: 'auto',
37
- },
38
- numberButton: {
39
- padding: 4,
40
- minWidth: 40,
41
- margin: 5,
42
- },
43
- numberButtonBreak: {
44
- display: 'block',
45
- },
46
- appBar: {
47
- color: 'white',
48
- },
49
- };
50
-
51
- const WEEKDAYS = [
52
- 'Sunday',
53
- 'Monday',
54
- 'Tuesday',
55
- 'Wednesday',
56
- 'Thursday',
57
- 'Friday',
58
- 'Saturday',
59
- 'Sunday',
60
- ];
61
- const MONTHS = [
62
- 'January',
63
- 'February',
64
- 'March',
65
- 'April',
66
- 'May',
67
- 'June',
68
- 'July',
69
- 'August',
70
- 'September',
71
- 'October',
72
- 'November',
73
- 'December',
74
- ];
75
-
76
- // 5-7,9-11 => [5,6,7,9,10,11]
77
- function convertMinusIntoArray(value: string | false | undefined, max: number): number[] {
78
- const result: number[] = [];
79
-
80
- if (value === '*') {
81
- if (max === 24 || max === 60 || max === 7) {
82
- for (let i = 0; i < max; i++) {
83
- result.push(i);
84
- }
85
- } else {
86
- for (let i = 1; i <= max; i++) {
87
- result.push(i);
88
- }
89
- }
90
- return result; // array with entries max
91
- }
92
-
93
- const parts = (value || '').toString().split(',');
94
-
95
- for (let p = 0; p < parts.length; p++) {
96
- if (!parts[p].trim().length) {
97
- continue;
98
- }
99
- const items = parts[p].trim().split('-');
100
- if (items.length > 1) {
101
- const iMax = parseInt(items[1], 10);
102
- for (let i = parseInt(items[0], 10); i <= iMax; i++) {
103
- result.push(i);
104
- }
105
- } else {
106
- result.push(parseInt(parts[p], 10));
107
- }
108
- }
109
-
110
- result.sort();
111
-
112
- // remove double entries
113
- for (let p = result.length - 1; p >= 0; p--) {
114
- if (result[p] === result[p + 1]) {
115
- result.splice(p + 1, 1);
116
- }
117
- }
118
-
119
- return result;
120
- }
121
-
122
- // [5,6,7,9,10,11] => 5-7,9-11
123
- function convertArrayIntoMinus(value: number | number [], max: number): string {
124
- if (typeof value !== 'object') {
125
- value = [value];
126
- }
127
- if (value.length === max) {
128
- return '*';
129
- }
130
- const newParts = [];
131
- if (!value.length) {
132
- return '-';
133
- }
134
- value = value.map(a => parseInt(a as any as string, 10));
135
-
136
- value.sort((a, b) => a - b);
137
-
138
- let start = value[0];
139
- let end = value[0];
140
- for (let p = 1; p < value.length; p++) {
141
- if (value[p] - 1 !== parseInt(value[p - 1] as any as string, 10)) {
142
- if (start === end) {
143
- newParts.push(start);
144
- } else if (end - 1 === start) {
145
- newParts.push(`${start},${end}`);
146
- } else {
147
- newParts.push(`${start}-${end}`);
148
- }
149
- start = value[p];
150
- }
151
- end = value[p];
152
- }
153
-
154
- if (start === end) {
155
- newParts.push(start);
156
- } else if (end - 1 === start) {
157
- newParts.push(`${start},${end}`);
158
- } else {
159
- newParts.push(`${start}-${end}`);
160
- }
161
-
162
- return newParts.join(',');
163
- }
164
-
165
- type CronNames = 'seconds' | 'minutes' | 'hours' | 'dates' | 'months' | 'dow';
166
-
167
- interface CronProps {
168
- seconds: string | false | null;
169
- minutes: string | null;
170
- hours: string | null;
171
- dates: string | null;
172
- months: string | null;
173
- dow: string | null;
174
- }
175
-
176
- interface ComplexCronProps {
177
- cronExpression: string;
178
- onChange: (cron: string) => void;
179
- language: ioBroker.Languages;
180
- }
181
-
182
- // type CronModes = 'every' | 'everyN' | 'specific';
183
-
184
- interface ComplexCronState {
185
- extended: boolean;
186
- tab: number;
187
- cron: string;
188
- seconds?: string | false;
189
- minutes?: string;
190
- hours?: string;
191
- dates?: string;
192
- months?: string;
193
- dow?: string;
194
- modes: CronProps;
195
- }
196
-
197
- class ComplexCron extends Component<ComplexCronProps, ComplexCronState> {
198
- constructor(props: ComplexCronProps) {
199
- super(props);
200
- let cron = typeof this.props.cronExpression === 'string' ?
201
- this.props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
202
- if (cron[0] === '{') {
203
- cron = '';
204
- }
205
- const state = ComplexCron.cron2state(cron || '* * * * *');
206
-
207
- this.state = {
208
- extended: false,
209
- tab: state.seconds !== false ? 1 : 0,
210
- cron: ComplexCron.state2cron(state),
211
- modes: {
212
- seconds: null,
213
- minutes: null,
214
- hours: null,
215
- dates: null,
216
- months: null,
217
- dow: null,
218
- },
219
- };
220
- Object.assign(this.state, state);
221
- if (this.state.cron !== this.props.cronExpression) {
222
- setTimeout(() => this.props.onChange && this.props.onChange(this.state.cron), 100);
223
- }
224
- }
225
-
226
- static cron2state(cron: string): CronProps {
227
- cron = cron.replace(/['"]/g, '').trim();
228
- const cronParts = cron.split(' ').map(p => p.trim());
229
- let options: CronProps;
230
-
231
- if (cronParts.length === 6) {
232
- options = {
233
- seconds: cronParts[0] || '*',
234
- minutes: cronParts[1] || '*',
235
- hours: cronParts[2] || '*',
236
- dates: cronParts[3] || '*',
237
- months: cronParts[4] || '*',
238
- dow: cronParts[5] || '*',
239
- };
240
- } else {
241
- options = {
242
- seconds: false,
243
- minutes: cronParts[0] || '*',
244
- hours: cronParts[1] || '*',
245
- dates: cronParts[2] || '*',
246
- months: cronParts[3] || '*',
247
- dow: cronParts[4] || '*',
248
- };
249
- }
250
- return options;
251
- }
252
-
253
- static state2cron(state: ComplexCronState | CronProps): string {
254
- let text = `${state.minutes} ${state.hours} ${state.dates} ${state.months} ${state.dow}`;
255
- if (state.seconds !== false) {
256
- text = `${state.seconds} ${text}`;
257
- }
258
- return text;
259
- }
260
-
261
- recalcCron() {
262
- const cron = ComplexCron.state2cron(this.state);
263
- if (cron !== this.state.cron) {
264
- this.setState({ cron }, () =>
265
- this.props.onChange && this.props.onChange(this.state.cron));
266
- }
267
- }
268
-
269
- onToggle(i: boolean | number, type: CronNames, max: number) {
270
- if (i === true) {
271
- this.setCronAttr(type, '*');
272
- } else if (i === false) {
273
- if (max === 60 || max === 24) {
274
- this.setCronAttr(type, '0');
275
- } else {
276
- this.setCronAttr(type, '1');
277
- }
278
- } else {
279
- const nums = convertMinusIntoArray(this.state[type], max);
280
- const pos = nums.indexOf(i);
281
- if (pos !== -1) {
282
- nums.splice(pos, 1);
283
- } else {
284
- nums.push(i);
285
- nums.sort();
286
- }
287
- this.setCronAttr(type, convertArrayIntoMinus(nums, max));
288
- }
289
- }
290
-
291
- getDigitsSelector(type: CronNames, max: number) {
292
- let values = [];
293
- if (max === 7) {
294
- values = [1, 2, 3, 4, 5, 6, 0];
295
- } else if (max === 60 || max === 24) {
296
- for (let i = 0; i < max; i++) {
297
- values.push(i);
298
- }
299
- } else {
300
- for (let i = 1; i <= max; i++) {
301
- values.push(i);
302
- }
303
- }
304
-
305
- const parts = convertMinusIntoArray(this.state[type], max);
306
-
307
- return [
308
- <Button
309
- key="removeall"
310
- variant="outlined"
311
- style={styles.numberButton}
312
- // style={{paddingBottom: 20}}
313
- color="primary"
314
- onClick={() => this.onToggle(false, type, max)}
315
- >
316
- {I18n.t('ra_Deselect all')}
317
- </Button>,
318
- <Button
319
- key="addall"
320
- variant="contained"
321
- // style={{paddingBottom: 20}}
322
- style={styles.numberButton}
323
- color="secondary"
324
- onClick={() => this.onToggle(true, type, max)}
325
- >
326
- {I18n.t('ra_Select all')}
327
- </Button>,
328
- <div key="all">
329
- {values.map(i =>
330
- [((max === 7 && i === 4) ||
331
- (max === 12 && i === 7) ||
332
- (max === 31 && !((i - 1) % 10)) ||
333
- (max === 60 && i && !(i % 10)) ||
334
- (max === 24 && i && !(i % 6))) ?
335
- <div key={`allInner${i}`} style={{ width: '100%' }} /> : null,
336
- <Button
337
- key={`_${i}`}
338
- variant={parts.indexOf(i) !== -1 ? 'contained' : 'outlined'}
339
- style={styles.numberButton}
340
- color={parts.indexOf(i) !== -1 ? 'secondary' : 'primary'}
341
- onClick={() => this.onToggle(i, type, max)}
342
- >
343
- {max === 7 ? I18n.t(WEEKDAYS[i]) : (max === 12 ? MONTHS[i - 1] : i)}
344
- </Button>,
345
- ])}
346
- </div>,
347
- ];
348
- }
349
-
350
- getPeriodsTab(type: CronNames, max: number): React.JSX.Element | null {
351
- const value = this.state[type];
352
- let every = value === '*';
353
- let everyN = value === undefined || value === null ? false : value.toString().includes('/');
354
- let select;
355
- if (this.state.modes[type] === null) {
356
- select = every ? 'every' : (everyN ? 'everyN' : 'specific');
357
- const modes = JSON.parse(JSON.stringify(this.state.modes));
358
- modes[type] = select;
359
- setTimeout(() => this.setState({ modes }, () => this.recalcCron()), 100);
360
- return null;
361
- }
362
-
363
- every = this.state.modes[type] === 'every';
364
- everyN = this.state.modes[type] === 'everyN';
365
- select = this.state.modes[type];
366
-
367
- let valueNumber = 1;
368
- if (everyN && value) {
369
- valueNumber = parseInt(value.replace('*/', ''), 10) || 1;
370
- }
371
-
372
- return <div>
373
- <Select
374
- variant="standard"
375
- style={{ ...styles.periodSelect, verticalAlign: 'bottom' }}
376
- value={select}
377
- onChange={e => {
378
- const modes = JSON.parse(JSON.stringify(this.state.modes));
379
- modes[type] = e.target.value;
380
- if (e.target.value === 'every') {
381
- this.setCronAttr(type, '*', modes);
382
- } else if (e.target.value === 'everyN') {
383
- const num = parseInt((this.state[type] || '').toString().replace('*/', ''), 10) || 1;
384
- this.setCronAttr(type, `*/${num}`, modes);
385
- } else if (e.target.value === 'specific') {
386
- let num = parseInt((this.state[type] || '').toString().split(',')[0], 10) || 0;
387
- if (!num && (type === 'months' || type === 'dates')) {
388
- num = 1;
389
- }
390
- this.setCronAttr(type, convertArrayIntoMinus(num, max), modes);
391
- }
392
- }}
393
- >
394
- <MenuItem key="every" value="every">{I18n.t(`sc_every_${type}`)}</MenuItem>
395
- <MenuItem key="everyN" value="everyN">{I18n.t(`sc_everyN_${type}`)}</MenuItem>
396
- <MenuItem key="specific" value="specific">{I18n.t(`sc_specific_${type}`)}</MenuItem>
397
- </Select>
398
- {everyN && false && <span>{value}</span>}
399
- {everyN && <TextField
400
- variant="standard"
401
- key="interval"
402
- label={I18n.t(`sc_${type}`)}
403
- value={valueNumber}
404
- inputProps={{ min: 1, max }}
405
- onChange={e => {
406
- // @ts-expect-error is allowed
407
- this.setState({ [type]: `*/${e.target.value}` }, () => this.recalcCron());
408
- }}
409
- InputLabelProps={{ shrink: true }}
410
- type="number"
411
- margin="normal"
412
- />}
413
- {!every && !everyN && this.getDigitsSelector(type, max)}
414
- </div>;
415
- }
416
-
417
- static convertCronToText(cron: string, lang: ioBroker.Languages): string {
418
- if (cron.split(' ').includes('-')) {
419
- return I18n.t('ra_Invalid CRON');
420
- }
421
- return convertCronToText(cron, lang);
422
- }
423
-
424
- setCronAttr(attr: CronNames, value: string, modes?: CronProps) {
425
- if (modes) {
426
- if (attr === 'seconds') {
427
- this.setState({ seconds: value, modes }, () =>
428
- this.recalcCron());
429
- } else if (attr === 'minutes') {
430
- this.setState({ minutes: value, modes }, () =>
431
- this.recalcCron());
432
- } else if (attr === 'hours') {
433
- this.setState({ hours: value, modes }, () =>
434
- this.recalcCron());
435
- } else if (attr === 'dates') {
436
- this.setState({ dates: value, modes }, () =>
437
- this.recalcCron());
438
- } else if (attr === 'months') {
439
- this.setState({ months: value, modes }, () =>
440
- this.recalcCron());
441
- } else if (attr === 'dow') {
442
- this.setState({ dow: value, modes }, () =>
443
- this.recalcCron());
444
- } else {
445
- this.setState({ modes }, () =>
446
- this.recalcCron());
447
- }
448
- } else if (attr === 'seconds') {
449
- this.setState({ seconds: value }, () =>
450
- this.recalcCron());
451
- } else if (attr === 'minutes') {
452
- this.setState({ minutes: value }, () =>
453
- this.recalcCron());
454
- } else if (attr === 'hours') {
455
- this.setState({ hours: value }, () =>
456
- this.recalcCron());
457
- } else if (attr === 'dates') {
458
- this.setState({ dates: value }, () =>
459
- this.recalcCron());
460
- } else if (attr === 'months') {
461
- this.setState({ months: value }, () =>
462
- this.recalcCron());
463
- } else if (attr === 'dow') {
464
- this.setState({ dow: value }, () =>
465
- this.recalcCron());
466
- }
467
- }
468
-
469
- render() {
470
- const tab = this.state.seconds !== false ? this.state.tab : this.state.tab + 1;
471
- return <div style={styles.mainDiv}>
472
- <div style={{ paddingLeft: 8, width: '100%' }}><TextField variant="standard" style={{ width: '100%' }} value={this.state.cron} disabled /></div>
473
- <div style={{ paddingLeft: 8, width: '100%', height: 60 }}>{ComplexCron.convertCronToText(this.state.cron, this.props.language || 'en')}</div>
474
- <FormControlLabel
475
- control={<Checkbox
476
- checked={!!this.state.seconds}
477
- onChange={e => this.setState({ seconds: e.target.checked ? '*' : false }, () => this.recalcCron())}
478
- />}
479
- label={I18n.t('ra_use seconds')}
480
- />
481
- <AppBar position="static" sx={{ '&.MuiAppBar-root': styles.appBar }} color="secondary">
482
- <Tabs
483
- value={this.state.tab}
484
- style={styles.appBar}
485
- color="secondary"
486
- onChange={(active, _tab) =>
487
- this.setState({ tab: _tab })}
488
- >
489
- {this.state.seconds !== false && <Tab id="sc_seconds" label={I18n.t('sc_seconds')} />}
490
- <Tab id="minutes" label={I18n.t('sc_minutes')} />
491
- <Tab id="hours" label={I18n.t('sc_hours')} />
492
- <Tab id="dates" label={I18n.t('sc_dates')} />
493
- <Tab id="months" label={I18n.t('sc_months')} />
494
- <Tab id="dow" label={I18n.t('sc_dows')} />
495
- </Tabs>
496
- </AppBar>
497
- {tab === 0 && <div style={styles.tabContent}>{this.getPeriodsTab('seconds', 60)}</div>}
498
- {tab === 1 && <div style={styles.tabContent}>{this.getPeriodsTab('minutes', 60)}</div>}
499
- {tab === 2 && <div style={styles.tabContent}>{this.getPeriodsTab('hours', 24)}</div>}
500
- {tab === 3 && <div style={styles.tabContent}>{this.getPeriodsTab('dates', 31)}</div>}
501
- {tab === 4 && <div style={styles.tabContent}>{this.getPeriodsTab('months', 12)}</div>}
502
- {tab === 5 && <div style={styles.tabContent}>{this.getPeriodsTab('dow', 7)}</div>}
503
- </div>;
504
- }
505
- }
506
-
507
- export default ComplexCron;
1
+ import React, { Component } from 'react';
2
+
3
+ import {
4
+ Checkbox,
5
+ Button,
6
+ MenuItem,
7
+ Select,
8
+ FormControlLabel,
9
+ AppBar,
10
+ Tabs,
11
+ Tab,
12
+ TextField, Box,
13
+ } from '@mui/material';
14
+
15
+ import I18n from '../i18n';
16
+ import convertCronToText from './SimpleCron/cronText';
17
+
18
+ const styles: Record<string, React.CSSProperties> = {
19
+ mainDiv: {
20
+ width: '100%',
21
+ height: '100%',
22
+ },
23
+ periodSelect: {
24
+ // margin: '0 10px 60px 10px',
25
+ display: 'block',
26
+ width: 200,
27
+ },
28
+ slider: {
29
+ marginTop: 20,
30
+ display: 'block',
31
+ width: '100%',
32
+ },
33
+ tabContent: {
34
+ padding: 20,
35
+ height: 'calc(100% - 240px)',
36
+ overflow: 'auto',
37
+ },
38
+ numberButton: {
39
+ padding: 4,
40
+ minWidth: 40,
41
+ margin: 5,
42
+ },
43
+ numberButtonBreak: {
44
+ display: 'block',
45
+ },
46
+ appBar: {
47
+ color: 'white',
48
+ },
49
+ };
50
+
51
+ const WEEKDAYS = [
52
+ 'Sunday',
53
+ 'Monday',
54
+ 'Tuesday',
55
+ 'Wednesday',
56
+ 'Thursday',
57
+ 'Friday',
58
+ 'Saturday',
59
+ 'Sunday',
60
+ ];
61
+ const MONTHS = [
62
+ 'January',
63
+ 'February',
64
+ 'March',
65
+ 'April',
66
+ 'May',
67
+ 'June',
68
+ 'July',
69
+ 'August',
70
+ 'September',
71
+ 'October',
72
+ 'November',
73
+ 'December',
74
+ ];
75
+
76
+ // 5-7,9-11 => [5,6,7,9,10,11]
77
+ function convertMinusIntoArray(value: string | false | undefined, max: number): number[] {
78
+ const result: number[] = [];
79
+
80
+ if (value === '*') {
81
+ if (max === 24 || max === 60 || max === 7) {
82
+ for (let i = 0; i < max; i++) {
83
+ result.push(i);
84
+ }
85
+ } else {
86
+ for (let i = 1; i <= max; i++) {
87
+ result.push(i);
88
+ }
89
+ }
90
+ return result; // array with entries max
91
+ }
92
+
93
+ const parts = (value || '').toString().split(',');
94
+
95
+ for (let p = 0; p < parts.length; p++) {
96
+ if (!parts[p].trim().length) {
97
+ continue;
98
+ }
99
+ const items = parts[p].trim().split('-');
100
+ if (items.length > 1) {
101
+ const iMax = parseInt(items[1], 10);
102
+ for (let i = parseInt(items[0], 10); i <= iMax; i++) {
103
+ result.push(i);
104
+ }
105
+ } else {
106
+ result.push(parseInt(parts[p], 10));
107
+ }
108
+ }
109
+
110
+ result.sort();
111
+
112
+ // remove double entries
113
+ for (let p = result.length - 1; p >= 0; p--) {
114
+ if (result[p] === result[p + 1]) {
115
+ result.splice(p + 1, 1);
116
+ }
117
+ }
118
+
119
+ return result;
120
+ }
121
+
122
+ // [5,6,7,9,10,11] => 5-7,9-11
123
+ function convertArrayIntoMinus(value: number | number [], max: number): string {
124
+ if (typeof value !== 'object') {
125
+ value = [value];
126
+ }
127
+ if (value.length === max) {
128
+ return '*';
129
+ }
130
+ const newParts = [];
131
+ if (!value.length) {
132
+ return '-';
133
+ }
134
+ value = value.map(a => parseInt(a as any as string, 10));
135
+
136
+ value.sort((a, b) => a - b);
137
+
138
+ let start = value[0];
139
+ let end = value[0];
140
+ for (let p = 1; p < value.length; p++) {
141
+ if (value[p] - 1 !== parseInt(value[p - 1] as any as string, 10)) {
142
+ if (start === end) {
143
+ newParts.push(start);
144
+ } else if (end - 1 === start) {
145
+ newParts.push(`${start},${end}`);
146
+ } else {
147
+ newParts.push(`${start}-${end}`);
148
+ }
149
+ start = value[p];
150
+ }
151
+ end = value[p];
152
+ }
153
+
154
+ if (start === end) {
155
+ newParts.push(start);
156
+ } else if (end - 1 === start) {
157
+ newParts.push(`${start},${end}`);
158
+ } else {
159
+ newParts.push(`${start}-${end}`);
160
+ }
161
+
162
+ return newParts.join(',');
163
+ }
164
+
165
+ type CronNames = 'seconds' | 'minutes' | 'hours' | 'dates' | 'months' | 'dow';
166
+
167
+ interface CronProps {
168
+ seconds: string | false | null;
169
+ minutes: string | null;
170
+ hours: string | null;
171
+ dates: string | null;
172
+ months: string | null;
173
+ dow: string | null;
174
+ }
175
+
176
+ interface ComplexCronProps {
177
+ cronExpression: string;
178
+ onChange: (cron: string) => void;
179
+ language: ioBroker.Languages;
180
+ }
181
+
182
+ // type CronModes = 'every' | 'everyN' | 'specific';
183
+
184
+ interface ComplexCronState {
185
+ extended: boolean;
186
+ tab: number;
187
+ cron: string;
188
+ seconds?: string | false;
189
+ minutes?: string;
190
+ hours?: string;
191
+ dates?: string;
192
+ months?: string;
193
+ dow?: string;
194
+ modes: CronProps;
195
+ }
196
+
197
+ class ComplexCron extends Component<ComplexCronProps, ComplexCronState> {
198
+ constructor(props: ComplexCronProps) {
199
+ super(props);
200
+ let cron = typeof this.props.cronExpression === 'string' ?
201
+ this.props.cronExpression.replace(/^["']/, '').replace(/["']\n?$/, '') : '';
202
+ if (cron[0] === '{') {
203
+ cron = '';
204
+ }
205
+ const state = ComplexCron.cron2state(cron || '* * * * *');
206
+
207
+ this.state = {
208
+ extended: false,
209
+ tab: state.seconds !== false ? 1 : 0,
210
+ cron: ComplexCron.state2cron(state),
211
+ modes: {
212
+ seconds: null,
213
+ minutes: null,
214
+ hours: null,
215
+ dates: null,
216
+ months: null,
217
+ dow: null,
218
+ },
219
+ };
220
+ Object.assign(this.state, state);
221
+ if (this.state.cron !== this.props.cronExpression) {
222
+ setTimeout(() => this.props.onChange && this.props.onChange(this.state.cron), 100);
223
+ }
224
+ }
225
+
226
+ static cron2state(cron: string): CronProps {
227
+ cron = cron.replace(/['"]/g, '').trim();
228
+ const cronParts = cron.split(' ').map(p => p.trim());
229
+ let options: CronProps;
230
+
231
+ if (cronParts.length === 6) {
232
+ options = {
233
+ seconds: cronParts[0] || '*',
234
+ minutes: cronParts[1] || '*',
235
+ hours: cronParts[2] || '*',
236
+ dates: cronParts[3] || '*',
237
+ months: cronParts[4] || '*',
238
+ dow: cronParts[5] || '*',
239
+ };
240
+ } else {
241
+ options = {
242
+ seconds: false,
243
+ minutes: cronParts[0] || '*',
244
+ hours: cronParts[1] || '*',
245
+ dates: cronParts[2] || '*',
246
+ months: cronParts[3] || '*',
247
+ dow: cronParts[4] || '*',
248
+ };
249
+ }
250
+ return options;
251
+ }
252
+
253
+ static state2cron(state: ComplexCronState | CronProps): string {
254
+ let text = `${state.minutes} ${state.hours} ${state.dates} ${state.months} ${state.dow}`;
255
+ if (state.seconds !== false) {
256
+ text = `${state.seconds} ${text}`;
257
+ }
258
+ return text;
259
+ }
260
+
261
+ recalcCron() {
262
+ const cron = ComplexCron.state2cron(this.state);
263
+ if (cron !== this.state.cron) {
264
+ this.setState({ cron }, () =>
265
+ this.props.onChange && this.props.onChange(this.state.cron));
266
+ }
267
+ }
268
+
269
+ onToggle(i: boolean | number, type: CronNames, max: number) {
270
+ if (i === true) {
271
+ this.setCronAttr(type, '*');
272
+ } else if (i === false) {
273
+ if (max === 60 || max === 24) {
274
+ this.setCronAttr(type, '0');
275
+ } else {
276
+ this.setCronAttr(type, '1');
277
+ }
278
+ } else {
279
+ const nums = convertMinusIntoArray(this.state[type], max);
280
+ const pos = nums.indexOf(i);
281
+ if (pos !== -1) {
282
+ nums.splice(pos, 1);
283
+ } else {
284
+ nums.push(i);
285
+ nums.sort();
286
+ }
287
+ this.setCronAttr(type, convertArrayIntoMinus(nums, max));
288
+ }
289
+ }
290
+
291
+ getDigitsSelector(type: CronNames, max: number) {
292
+ let values = [];
293
+ if (max === 7) {
294
+ values = [1, 2, 3, 4, 5, 6, 0];
295
+ } else if (max === 60 || max === 24) {
296
+ for (let i = 0; i < max; i++) {
297
+ values.push(i);
298
+ }
299
+ } else {
300
+ for (let i = 1; i <= max; i++) {
301
+ values.push(i);
302
+ }
303
+ }
304
+
305
+ const parts = convertMinusIntoArray(this.state[type], max);
306
+
307
+ return [
308
+ <Button
309
+ key="removeall"
310
+ variant="outlined"
311
+ style={styles.numberButton}
312
+ // style={{paddingBottom: 20}}
313
+ color="primary"
314
+ onClick={() => this.onToggle(false, type, max)}
315
+ >
316
+ {I18n.t('ra_Deselect all')}
317
+ </Button>,
318
+ <Button
319
+ key="addall"
320
+ variant="contained"
321
+ // style={{paddingBottom: 20}}
322
+ style={styles.numberButton}
323
+ color="secondary"
324
+ onClick={() => this.onToggle(true, type, max)}
325
+ >
326
+ {I18n.t('ra_Select all')}
327
+ </Button>,
328
+ <div key="all">
329
+ {values.map(i =>
330
+ [((max === 7 && i === 4) ||
331
+ (max === 12 && i === 7) ||
332
+ (max === 31 && !((i - 1) % 10)) ||
333
+ (max === 60 && i && !(i % 10)) ||
334
+ (max === 24 && i && !(i % 6))) ?
335
+ <div key={`allInner${i}`} style={{ width: '100%' }} /> : null,
336
+ <Button
337
+ key={`_${i}`}
338
+ variant={parts.indexOf(i) !== -1 ? 'contained' : 'outlined'}
339
+ style={styles.numberButton}
340
+ color={parts.indexOf(i) !== -1 ? 'secondary' : 'primary'}
341
+ onClick={() => this.onToggle(i, type, max)}
342
+ >
343
+ {max === 7 ? I18n.t(WEEKDAYS[i]) : (max === 12 ? MONTHS[i - 1] : i)}
344
+ </Button>,
345
+ ])}
346
+ </div>,
347
+ ];
348
+ }
349
+
350
+ getPeriodsTab(type: CronNames, max: number): React.JSX.Element | null {
351
+ const value = this.state[type];
352
+ let every = value === '*';
353
+ let everyN = value === undefined || value === null ? false : value.toString().includes('/');
354
+ let select;
355
+ if (this.state.modes[type] === null) {
356
+ select = every ? 'every' : (everyN ? 'everyN' : 'specific');
357
+ const modes = JSON.parse(JSON.stringify(this.state.modes));
358
+ modes[type] = select;
359
+ setTimeout(() => this.setState({ modes }, () => this.recalcCron()), 100);
360
+ return null;
361
+ }
362
+
363
+ every = this.state.modes[type] === 'every';
364
+ everyN = this.state.modes[type] === 'everyN';
365
+ select = this.state.modes[type];
366
+
367
+ let valueNumber = 1;
368
+ if (everyN && value) {
369
+ valueNumber = parseInt(value.replace('*/', ''), 10) || 1;
370
+ }
371
+
372
+ return <div>
373
+ <Select
374
+ variant="standard"
375
+ style={{ ...styles.periodSelect, verticalAlign: 'bottom' }}
376
+ value={select}
377
+ onChange={e => {
378
+ const modes = JSON.parse(JSON.stringify(this.state.modes));
379
+ modes[type] = e.target.value;
380
+ if (e.target.value === 'every') {
381
+ this.setCronAttr(type, '*', modes);
382
+ } else if (e.target.value === 'everyN') {
383
+ const num = parseInt((this.state[type] || '').toString().replace('*/', ''), 10) || 1;
384
+ this.setCronAttr(type, `*/${num}`, modes);
385
+ } else if (e.target.value === 'specific') {
386
+ let num = parseInt((this.state[type] || '').toString().split(',')[0], 10) || 0;
387
+ if (!num && (type === 'months' || type === 'dates')) {
388
+ num = 1;
389
+ }
390
+ this.setCronAttr(type, convertArrayIntoMinus(num, max), modes);
391
+ }
392
+ }}
393
+ >
394
+ <MenuItem key="every" value="every">{I18n.t(`sc_every_${type}`)}</MenuItem>
395
+ <MenuItem key="everyN" value="everyN">{I18n.t(`sc_everyN_${type}`)}</MenuItem>
396
+ <MenuItem key="specific" value="specific">{I18n.t(`sc_specific_${type}`)}</MenuItem>
397
+ </Select>
398
+ {everyN && false && <span>{value}</span>}
399
+ {everyN && <TextField
400
+ variant="standard"
401
+ key="interval"
402
+ label={I18n.t(`sc_${type}`)}
403
+ value={valueNumber}
404
+ inputProps={{ min: 1, max }}
405
+ onChange={e => {
406
+ // @ts-expect-error is allowed
407
+ this.setState({ [type]: `*/${e.target.value}` }, () => this.recalcCron());
408
+ }}
409
+ InputLabelProps={{ shrink: true }}
410
+ type="number"
411
+ margin="normal"
412
+ />}
413
+ {!every && !everyN && this.getDigitsSelector(type, max)}
414
+ </div>;
415
+ }
416
+
417
+ static convertCronToText(cron: string, lang: ioBroker.Languages): string {
418
+ if (cron.split(' ').includes('-')) {
419
+ return I18n.t('ra_Invalid CRON');
420
+ }
421
+ return convertCronToText(cron, lang);
422
+ }
423
+
424
+ setCronAttr(attr: CronNames, value: string, modes?: CronProps) {
425
+ if (modes) {
426
+ if (attr === 'seconds') {
427
+ this.setState({ seconds: value, modes }, () =>
428
+ this.recalcCron());
429
+ } else if (attr === 'minutes') {
430
+ this.setState({ minutes: value, modes }, () =>
431
+ this.recalcCron());
432
+ } else if (attr === 'hours') {
433
+ this.setState({ hours: value, modes }, () =>
434
+ this.recalcCron());
435
+ } else if (attr === 'dates') {
436
+ this.setState({ dates: value, modes }, () =>
437
+ this.recalcCron());
438
+ } else if (attr === 'months') {
439
+ this.setState({ months: value, modes }, () =>
440
+ this.recalcCron());
441
+ } else if (attr === 'dow') {
442
+ this.setState({ dow: value, modes }, () =>
443
+ this.recalcCron());
444
+ } else {
445
+ this.setState({ modes }, () =>
446
+ this.recalcCron());
447
+ }
448
+ } else if (attr === 'seconds') {
449
+ this.setState({ seconds: value }, () =>
450
+ this.recalcCron());
451
+ } else if (attr === 'minutes') {
452
+ this.setState({ minutes: value }, () =>
453
+ this.recalcCron());
454
+ } else if (attr === 'hours') {
455
+ this.setState({ hours: value }, () =>
456
+ this.recalcCron());
457
+ } else if (attr === 'dates') {
458
+ this.setState({ dates: value }, () =>
459
+ this.recalcCron());
460
+ } else if (attr === 'months') {
461
+ this.setState({ months: value }, () =>
462
+ this.recalcCron());
463
+ } else if (attr === 'dow') {
464
+ this.setState({ dow: value }, () =>
465
+ this.recalcCron());
466
+ }
467
+ }
468
+
469
+ render() {
470
+ const tab = this.state.seconds !== false ? this.state.tab : this.state.tab + 1;
471
+ return <div style={styles.mainDiv}>
472
+ <div style={{ paddingLeft: 8, width: '100%' }}><TextField variant="standard" style={{ width: '100%' }} value={this.state.cron} disabled /></div>
473
+ <div style={{ paddingLeft: 8, width: '100%', height: 60 }}>{ComplexCron.convertCronToText(this.state.cron, this.props.language || 'en')}</div>
474
+ <FormControlLabel
475
+ control={<Checkbox
476
+ checked={!!this.state.seconds}
477
+ onChange={e => this.setState({ seconds: e.target.checked ? '*' : false }, () => this.recalcCron())}
478
+ />}
479
+ label={I18n.t('ra_use seconds')}
480
+ />
481
+ <AppBar position="static" sx={{ '&.MuiAppBar-root': styles.appBar }} color="secondary">
482
+ <Tabs
483
+ value={this.state.tab}
484
+ style={styles.appBar}
485
+ color="secondary"
486
+ onChange={(active, _tab) =>
487
+ this.setState({ tab: _tab })}
488
+ >
489
+ {this.state.seconds !== false && <Tab id="sc_seconds" label={I18n.t('sc_seconds')} />}
490
+ <Tab id="minutes" label={I18n.t('sc_minutes')} />
491
+ <Tab id="hours" label={I18n.t('sc_hours')} />
492
+ <Tab id="dates" label={I18n.t('sc_dates')} />
493
+ <Tab id="months" label={I18n.t('sc_months')} />
494
+ <Tab id="dow" label={I18n.t('sc_dows')} />
495
+ </Tabs>
496
+ </AppBar>
497
+ {tab === 0 && <div style={styles.tabContent}>{this.getPeriodsTab('seconds', 60)}</div>}
498
+ {tab === 1 && <div style={styles.tabContent}>{this.getPeriodsTab('minutes', 60)}</div>}
499
+ {tab === 2 && <div style={styles.tabContent}>{this.getPeriodsTab('hours', 24)}</div>}
500
+ {tab === 3 && <div style={styles.tabContent}>{this.getPeriodsTab('dates', 31)}</div>}
501
+ {tab === 4 && <div style={styles.tabContent}>{this.getPeriodsTab('months', 12)}</div>}
502
+ {tab === 5 && <div style={styles.tabContent}>{this.getPeriodsTab('dow', 7)}</div>}
503
+ </div>;
504
+ }
505
+ }
506
+
507
+ export default ComplexCron;