@iobroker/adapter-react-v5 7.2.3 → 7.2.6

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 (375) hide show
  1. package/README.md +3 -3
  2. package/build/AdminConnection.d.ts +1 -0
  3. package/build/AdminConnection.js +2 -0
  4. package/build/AdminConnection.js.map +1 -0
  5. package/{src/Components/404.tsx → build/Components/404.js} +14 -39
  6. package/build/Components/404.js.map +1 -0
  7. package/{Components → build/Components}/ColorPicker.d.ts +2 -2
  8. package/{Components → build/Components}/ColorPicker.js +50 -65
  9. package/build/Components/ColorPicker.js.map +1 -0
  10. package/{Components → build/Components}/ComplexCron.d.ts +2 -2
  11. package/{Components → build/Components}/ComplexCron.js +43 -71
  12. package/build/Components/ComplexCron.js.map +1 -0
  13. package/{Components → build/Components}/CopyToClipboard.d.ts +1 -2
  14. package/{src/Components/CopyToClipboard.tsx → build/Components/CopyToClipboard.js} +20 -38
  15. package/build/Components/CopyToClipboard.js.map +1 -0
  16. package/{Components → build/Components}/CustomModal.d.ts +3 -3
  17. package/build/Components/CustomModal.js +60 -0
  18. package/build/Components/CustomModal.js.map +1 -0
  19. package/{Components → build/Components}/FileBrowser.d.ts +21 -21
  20. package/{Components → build/Components}/FileBrowser.js +253 -248
  21. package/build/Components/FileBrowser.js.map +1 -0
  22. package/build/Components/FileViewer.d.ts +48 -0
  23. package/build/Components/FileViewer.js +277 -0
  24. package/build/Components/FileViewer.js.map +1 -0
  25. package/{Components → build/Components}/Icon.d.ts +1 -1
  26. package/build/Components/Icon.js +140 -0
  27. package/build/Components/Icon.js.map +1 -0
  28. package/{Components → build/Components}/IconPicker.d.ts +2 -2
  29. package/build/Components/IconPicker.js +73 -0
  30. package/build/Components/IconPicker.js.map +1 -0
  31. package/{Components → build/Components}/IconSelector.d.ts +3 -3
  32. package/{Components → build/Components}/IconSelector.js +29 -57
  33. package/build/Components/IconSelector.js.map +1 -0
  34. package/{Components → build/Components}/Image.d.ts +2 -2
  35. package/{Components → build/Components}/Image.js +16 -22
  36. package/build/Components/Image.js.map +1 -0
  37. package/{Components → build/Components}/Loader.d.ts +2 -2
  38. package/{Components → build/Components}/Loader.js +15 -40
  39. package/build/Components/Loader.js.map +1 -0
  40. package/{Components → build/Components}/Loaders/MV.d.ts +2 -2
  41. package/build/Components/Loaders/MV.js +61 -0
  42. package/build/Components/Loaders/MV.js.map +1 -0
  43. package/{Components → build/Components}/Loaders/PT.d.ts +2 -2
  44. package/{Components → build/Components}/Loaders/PT.js +10 -35
  45. package/build/Components/Loaders/PT.js.map +1 -0
  46. package/{Components → build/Components}/Loaders/Vendor.d.ts +2 -2
  47. package/build/Components/Loaders/Vendor.js +52 -0
  48. package/build/Components/Loaders/Vendor.js.map +1 -0
  49. package/{Components → build/Components}/Logo.d.ts +2 -2
  50. package/build/Components/Logo.js +108 -0
  51. package/build/Components/Logo.js.map +1 -0
  52. package/{Components → build/Components}/MDUtils.d.ts +1 -2
  53. package/{Components → build/Components}/MDUtils.js +4 -9
  54. package/build/Components/MDUtils.js.map +1 -0
  55. package/{Components → build/Components}/ObjectBrowser.d.ts +7 -4
  56. package/{Components → build/Components}/ObjectBrowser.js +1183 -1133
  57. package/build/Components/ObjectBrowser.js.map +1 -0
  58. package/{Components → build/Components}/Router.d.ts +1 -2
  59. package/{Components → build/Components}/Router.js +6 -7
  60. package/build/Components/Router.js.map +1 -0
  61. package/{Components → build/Components}/SaveCloseButtons.d.ts +2 -2
  62. package/build/Components/SaveCloseButtons.js +65 -0
  63. package/build/Components/SaveCloseButtons.js.map +1 -0
  64. package/{Components → build/Components}/Schedule.d.ts +3 -3
  65. package/{Components → build/Components}/Schedule.js +246 -261
  66. package/build/Components/Schedule.js.map +1 -0
  67. package/{Components → build/Components}/SelectWithIcon.d.ts +2 -2
  68. package/build/Components/SelectWithIcon.js +135 -0
  69. package/build/Components/SelectWithIcon.js.map +1 -0
  70. package/build/Components/SimpleCron/cronText.js +15 -0
  71. package/build/Components/SimpleCron/cronText.js.map +1 -0
  72. package/{Components → build/Components}/SimpleCron/index.d.ts +2 -2
  73. package/{Components → build/Components}/SimpleCron/index.js +55 -56
  74. package/build/Components/SimpleCron/index.js.map +1 -0
  75. package/{Components → build/Components}/TabContainer.d.ts +2 -2
  76. package/build/Components/TabContainer.js +23 -0
  77. package/build/Components/TabContainer.js.map +1 -0
  78. package/{Components → build/Components}/TabContent.d.ts +3 -2
  79. package/build/Components/TabContent.js +20 -0
  80. package/build/Components/TabContent.js.map +1 -0
  81. package/build/Components/TabHeader.d.ts +6 -0
  82. package/build/Components/TabHeader.js +6 -0
  83. package/build/Components/TabHeader.js.map +1 -0
  84. package/{Components → build/Components}/TableResize.d.ts +2 -2
  85. package/{src/Components/TableResize.tsx → build/Components/TableResize.js} +64 -134
  86. package/build/Components/TableResize.js.map +1 -0
  87. package/{Components → build/Components}/TextWithIcon.d.ts +2 -2
  88. package/{src/Components/TextWithIcon.tsx → build/Components/TextWithIcon.js} +30 -75
  89. package/build/Components/TextWithIcon.js.map +1 -0
  90. package/{Components → build/Components}/ToggleThemeMenu.d.ts +1 -1
  91. package/build/Components/ToggleThemeMenu.js +13 -0
  92. package/build/Components/ToggleThemeMenu.js.map +1 -0
  93. package/{Components → build/Components}/TreeTable.d.ts +3 -3
  94. package/{Components → build/Components}/TreeTable.js +87 -99
  95. package/build/Components/TreeTable.js.map +1 -0
  96. package/{Components → build/Components}/UploadImage.d.ts +2 -2
  97. package/{Components → build/Components}/UploadImage.js +46 -69
  98. package/build/Components/UploadImage.js.map +1 -0
  99. package/{Components → build/Components}/Utils.d.ts +2 -2
  100. package/{Components → build/Components}/Utils.js +47 -60
  101. package/build/Components/Utils.js.map +1 -0
  102. package/build/Components/withWidth.d.ts +2 -0
  103. package/build/Components/withWidth.js +22 -0
  104. package/build/Components/withWidth.js.map +1 -0
  105. package/build/Connection.d.ts +1 -0
  106. package/build/Connection.js +2 -0
  107. package/build/Connection.js.map +1 -0
  108. package/{Dialogs → build/Dialogs}/ComplexCron.d.ts +2 -2
  109. package/build/Dialogs/ComplexCron.js +85 -0
  110. package/build/Dialogs/ComplexCron.js.map +1 -0
  111. package/{Dialogs → build/Dialogs}/Confirm.d.ts +2 -2
  112. package/build/Dialogs/Confirm.js +83 -0
  113. package/build/Dialogs/Confirm.js.map +1 -0
  114. package/{Dialogs → build/Dialogs}/Cron.d.ts +2 -2
  115. package/build/Dialogs/Cron.js +72 -0
  116. package/build/Dialogs/Cron.js.map +1 -0
  117. package/{Dialogs → build/Dialogs}/Error.d.ts +2 -2
  118. package/build/Dialogs/Error.js +27 -0
  119. package/build/Dialogs/Error.js.map +1 -0
  120. package/{Dialogs → build/Dialogs}/Message.d.ts +2 -2
  121. package/build/Dialogs/Message.js +29 -0
  122. package/build/Dialogs/Message.js.map +1 -0
  123. package/{Dialogs → build/Dialogs}/SelectFile.d.ts +2 -2
  124. package/build/Dialogs/SelectFile.js +116 -0
  125. package/build/Dialogs/SelectFile.js.map +1 -0
  126. package/{Dialogs → build/Dialogs}/SelectID.d.ts +3 -3
  127. package/{Dialogs → build/Dialogs}/SelectID.js +28 -53
  128. package/build/Dialogs/SelectID.js.map +1 -0
  129. package/{Dialogs → build/Dialogs}/SimpleCron.d.ts +2 -2
  130. package/build/Dialogs/SimpleCron.js +46 -0
  131. package/build/Dialogs/SimpleCron.js.map +1 -0
  132. package/build/Dialogs/TextInput.d.ts +2 -0
  133. package/build/Dialogs/TextInput.js +31 -0
  134. package/build/Dialogs/TextInput.js.map +1 -0
  135. package/{GenericApp.d.ts → build/GenericApp.d.ts} +2 -3
  136. package/{GenericApp.js → build/GenericApp.js} +162 -176
  137. package/build/GenericApp.js.map +1 -0
  138. package/{LegacyConnection.d.ts → build/LegacyConnection.d.ts} +69 -4
  139. package/{LegacyConnection.js → build/LegacyConnection.js} +106 -99
  140. package/build/LegacyConnection.js.map +1 -0
  141. package/{Prompt.d.ts → build/Prompt.d.ts} +1 -1
  142. package/{Prompt.js → build/Prompt.js} +3 -4
  143. package/build/Prompt.js.map +1 -0
  144. package/build/Theme.d.ts +5 -0
  145. package/{Theme.js → build/Theme.js} +37 -32
  146. package/build/Theme.js.map +1 -0
  147. package/build/assets/devices/parseNames.d.ts +0 -0
  148. package/build/assets/devices/parseNames.js +35 -0
  149. package/build/assets/devices/parseNames.js.map +1 -0
  150. package/build/assets/rooms/parseNames.d.ts +0 -0
  151. package/build/assets/rooms/parseNames.js +35 -0
  152. package/build/assets/rooms/parseNames.js.map +1 -0
  153. package/build/dictionary.d.ts +1 -0
  154. package/build/dictionary.js +25 -0
  155. package/build/dictionary.js.map +1 -0
  156. package/build/i18n/de.json +449 -0
  157. package/build/i18n/en.json +449 -0
  158. package/build/i18n/es.json +449 -0
  159. package/build/i18n/fr.json +449 -0
  160. package/build/i18n/it.json +449 -0
  161. package/build/i18n/nl.json +449 -0
  162. package/build/i18n/pl.json +449 -0
  163. package/build/i18n/pt.json +449 -0
  164. package/build/i18n/ru.json +449 -0
  165. package/build/i18n/uk.json +449 -0
  166. package/build/i18n/zh-cn.json +449 -0
  167. package/{i18n.d.ts → build/i18n.d.ts} +2 -2
  168. package/{i18n.js → build/i18n.js} +9 -11
  169. package/build/i18n.js.map +1 -0
  170. package/build/icons/IconAdapter.d.ts +3 -0
  171. package/build/icons/IconAdapter.js +6 -0
  172. package/build/icons/IconAdapter.js.map +1 -0
  173. package/build/icons/IconAlias.d.ts +3 -0
  174. package/build/icons/IconAlias.js +6 -0
  175. package/build/icons/IconAlias.js.map +1 -0
  176. package/build/icons/IconChannel.d.ts +3 -0
  177. package/build/icons/IconChannel.js +9 -0
  178. package/build/icons/IconChannel.js.map +1 -0
  179. package/build/icons/IconClearFilter.d.ts +3 -0
  180. package/build/icons/IconClearFilter.js +7 -0
  181. package/build/icons/IconClearFilter.js.map +1 -0
  182. package/build/icons/IconClosed.d.ts +3 -0
  183. package/build/icons/IconClosed.js +6 -0
  184. package/build/icons/IconClosed.js.map +1 -0
  185. package/build/icons/IconCopy.d.ts +3 -0
  186. package/build/icons/IconCopy.js +5 -0
  187. package/build/icons/IconCopy.js.map +1 -0
  188. package/build/icons/IconDevice.d.ts +3 -0
  189. package/build/icons/IconDevice.js +15 -0
  190. package/build/icons/IconDevice.js.map +1 -0
  191. package/build/icons/IconDocument.d.ts +3 -0
  192. package/build/icons/IconDocument.js +6 -0
  193. package/build/icons/IconDocument.js.map +1 -0
  194. package/build/icons/IconDocumentReadOnly.d.ts +3 -0
  195. package/build/icons/IconDocumentReadOnly.js +7 -0
  196. package/build/icons/IconDocumentReadOnly.js.map +1 -0
  197. package/build/icons/IconExpert.d.ts +3 -0
  198. package/build/icons/IconExpert.js +6 -0
  199. package/build/icons/IconExpert.js.map +1 -0
  200. package/build/icons/IconFx.d.ts +3 -0
  201. package/build/icons/IconFx.js +5 -0
  202. package/build/icons/IconFx.js.map +1 -0
  203. package/build/icons/IconInstance.d.ts +3 -0
  204. package/build/icons/IconInstance.js +6 -0
  205. package/build/icons/IconInstance.js.map +1 -0
  206. package/build/icons/IconLogout.d.ts +3 -0
  207. package/build/icons/IconLogout.js +6 -0
  208. package/build/icons/IconLogout.js.map +1 -0
  209. package/build/icons/IconNoIcon.d.ts +3 -0
  210. package/build/icons/IconNoIcon.js +5 -0
  211. package/build/icons/IconNoIcon.js.map +1 -0
  212. package/build/icons/IconOpen.d.ts +3 -0
  213. package/build/icons/IconOpen.js +6 -0
  214. package/build/icons/IconOpen.js.map +1 -0
  215. package/{icons → build/icons}/IconProps.d.ts +1 -1
  216. package/build/icons/IconProps.js +2 -0
  217. package/build/icons/IconProps.js.map +1 -0
  218. package/build/icons/IconState.d.ts +3 -0
  219. package/build/icons/IconState.js +6 -0
  220. package/build/icons/IconState.js.map +1 -0
  221. package/build/index.d.ts +67 -0
  222. package/build/index.js +67 -0
  223. package/build/index.js.map +1 -0
  224. package/{types.d.ts → build/types.d.ts} +1 -1
  225. package/package.json +84 -47
  226. package/AdminConnection.d.ts +0 -2
  227. package/AdminConnection.js +0 -4
  228. package/Components/404.js +0 -101
  229. package/Components/CopyToClipboard.js +0 -163
  230. package/Components/CustomModal.js +0 -88
  231. package/Components/FileViewer.d.ts +0 -10
  232. package/Components/FileViewer.js +0 -305
  233. package/Components/Icon.js +0 -148
  234. package/Components/IconPicker.js +0 -98
  235. package/Components/Loaders/MV.js +0 -66
  236. package/Components/Loaders/Vendor.js +0 -77
  237. package/Components/Logo.js +0 -117
  238. package/Components/SaveCloseButtons.js +0 -69
  239. package/Components/SelectWithIcon.js +0 -168
  240. package/Components/SimpleCron/cronText.js +0 -19
  241. package/Components/TabContainer.js +0 -25
  242. package/Components/TabContent.js +0 -21
  243. package/Components/TabHeader.d.ts +0 -6
  244. package/Components/TabHeader.js +0 -11
  245. package/Components/TableResize.js +0 -226
  246. package/Components/TextWithIcon.js +0 -119
  247. package/Components/ToggleThemeMenu.js +0 -18
  248. package/Components/withWidth.d.ts +0 -3
  249. package/Components/withWidth.js +0 -27
  250. package/Connection.d.ts +0 -3
  251. package/Connection.js +0 -8
  252. package/Dialogs/ComplexCron.js +0 -90
  253. package/Dialogs/Confirm.js +0 -111
  254. package/Dialogs/Cron.js +0 -100
  255. package/Dialogs/Error.js +0 -55
  256. package/Dialogs/Message.js +0 -57
  257. package/Dialogs/SelectFile.js +0 -119
  258. package/Dialogs/SimpleCron.js +0 -51
  259. package/Dialogs/TextInput.d.ts +0 -3
  260. package/Dialogs/TextInput.js +0 -35
  261. package/Theme.d.ts +0 -6
  262. package/i18n/de.json +0 -449
  263. package/i18n/en.json +0 -449
  264. package/i18n/es.json +0 -449
  265. package/i18n/fr.json +0 -449
  266. package/i18n/it.json +0 -449
  267. package/i18n/nl.json +0 -449
  268. package/i18n/pl.json +0 -449
  269. package/i18n/pt.json +0 -449
  270. package/i18n/ru.json +0 -449
  271. package/i18n/uk.json +0 -449
  272. package/i18n/zh-cn.json +0 -449
  273. package/icons/IconAdapter.d.ts +0 -4
  274. package/icons/IconAdapter.js +0 -10
  275. package/icons/IconAlias.d.ts +0 -4
  276. package/icons/IconAlias.js +0 -10
  277. package/icons/IconChannel.d.ts +0 -4
  278. package/icons/IconChannel.js +0 -13
  279. package/icons/IconClearFilter.d.ts +0 -4
  280. package/icons/IconClearFilter.js +0 -11
  281. package/icons/IconClosed.d.ts +0 -4
  282. package/icons/IconClosed.js +0 -10
  283. package/icons/IconCopy.d.ts +0 -4
  284. package/icons/IconCopy.js +0 -9
  285. package/icons/IconDevice.d.ts +0 -4
  286. package/icons/IconDevice.js +0 -19
  287. package/icons/IconDocument.d.ts +0 -4
  288. package/icons/IconDocument.js +0 -10
  289. package/icons/IconDocumentReadOnly.d.ts +0 -4
  290. package/icons/IconDocumentReadOnly.js +0 -11
  291. package/icons/IconExpert.d.ts +0 -4
  292. package/icons/IconExpert.js +0 -10
  293. package/icons/IconFx.d.ts +0 -4
  294. package/icons/IconFx.js +0 -9
  295. package/icons/IconInstance.d.ts +0 -4
  296. package/icons/IconInstance.js +0 -10
  297. package/icons/IconLogout.d.ts +0 -4
  298. package/icons/IconLogout.js +0 -10
  299. package/icons/IconNoIcon.d.ts +0 -4
  300. package/icons/IconNoIcon.js +0 -9
  301. package/icons/IconOpen.d.ts +0 -4
  302. package/icons/IconOpen.js +0 -10
  303. package/icons/IconProps.js +0 -2
  304. package/icons/IconState.d.ts +0 -4
  305. package/icons/IconState.js +0 -10
  306. package/index.d.ts +0 -128
  307. package/index.js +0 -215
  308. package/src/AdminConnection.tsx +0 -3
  309. package/src/Components/ColorPicker.tsx +0 -343
  310. package/src/Components/ComplexCron.tsx +0 -561
  311. package/src/Components/CustomModal.tsx +0 -170
  312. package/src/Components/FileBrowser.tsx +0 -2550
  313. package/src/Components/FileViewer.tsx +0 -412
  314. package/src/Components/Icon.tsx +0 -238
  315. package/src/Components/IconPicker.tsx +0 -165
  316. package/src/Components/IconSelector.tsx +0 -2220
  317. package/src/Components/Image.tsx +0 -193
  318. package/src/Components/Loader.tsx +0 -328
  319. package/src/Components/Logo.tsx +0 -176
  320. package/src/Components/MDUtils.tsx +0 -104
  321. package/src/Components/ObjectBrowser.tsx +0 -8935
  322. package/src/Components/Router.tsx +0 -90
  323. package/src/Components/SaveCloseButtons.tsx +0 -117
  324. package/src/Components/Schedule.tsx +0 -1995
  325. package/src/Components/SelectWithIcon.tsx +0 -239
  326. package/src/Components/TabContainer.tsx +0 -57
  327. package/src/Components/TabContent.tsx +0 -38
  328. package/src/Components/TabHeader.tsx +0 -20
  329. package/src/Components/ToggleThemeMenu.tsx +0 -52
  330. package/src/Components/TreeTable.tsx +0 -1002
  331. package/src/Components/UploadImage.tsx +0 -643
  332. package/src/Components/Utils.tsx +0 -1802
  333. package/src/Components/loader.css +0 -231
  334. package/src/Components/withWidth.tsx +0 -32
  335. package/src/Connection.tsx +0 -5
  336. package/src/Dialogs/ComplexCron.tsx +0 -163
  337. package/src/Dialogs/Confirm.tsx +0 -185
  338. package/src/Dialogs/Cron.tsx +0 -192
  339. package/src/Dialogs/Error.tsx +0 -67
  340. package/src/Dialogs/Message.tsx +0 -73
  341. package/src/Dialogs/SelectFile.tsx +0 -280
  342. package/src/Dialogs/SelectID.tsx +0 -310
  343. package/src/Dialogs/SimpleCron.tsx +0 -101
  344. package/src/Dialogs/TextInput.tsx +0 -99
  345. package/src/GenericApp.tsx +0 -1076
  346. package/src/LegacyConnection.tsx +0 -3720
  347. package/src/Prompt.tsx +0 -22
  348. package/src/Theme.tsx +0 -472
  349. package/src/icons/IconAdapter.tsx +0 -22
  350. package/src/icons/IconAlias.tsx +0 -22
  351. package/src/icons/IconChannel.tsx +0 -60
  352. package/src/icons/IconClearFilter.tsx +0 -24
  353. package/src/icons/IconClosed.tsx +0 -22
  354. package/src/icons/IconCopy.tsx +0 -21
  355. package/src/icons/IconDevice.tsx +0 -126
  356. package/src/icons/IconDocument.tsx +0 -22
  357. package/src/icons/IconDocumentReadOnly.tsx +0 -27
  358. package/src/icons/IconExpert.tsx +0 -26
  359. package/src/icons/IconFx.tsx +0 -38
  360. package/src/icons/IconInstance.tsx +0 -22
  361. package/src/icons/IconLogout.tsx +0 -32
  362. package/src/icons/IconNoIcon.tsx +0 -21
  363. package/src/icons/IconOpen.tsx +0 -22
  364. package/src/icons/IconProps.tsx +0 -16
  365. package/src/icons/IconState.tsx +0 -38
  366. package/src/index.css +0 -56
  367. /package/{Components → build/Components}/404.d.ts +0 -0
  368. /package/{Components → build/Components}/SimpleCron/cronText.d.ts +0 -0
  369. /package/{assets → build/assets}/devices.json +0 -0
  370. /package/{assets → build/assets}/lamp_ceiling.svg +0 -0
  371. /package/{assets → build/assets}/lamp_table.svg +0 -0
  372. /package/{assets → build/assets}/no_icon.svg +0 -0
  373. /package/{assets → build/assets}/rooms.json +0 -0
  374. /package/{index.css → build/index.css} +0 -0
  375. /package/{tasks.js → tasksExample.js} +0 -0
@@ -1,1995 +0,0 @@
1
- import React, { Component, type JSX } from 'react';
2
-
3
- import {
4
- Input,
5
- Radio,
6
- FormControlLabel,
7
- FormGroup,
8
- Checkbox,
9
- MenuItem,
10
- Select,
11
- TextField,
12
- Box,
13
- type Theme
14
- } from '@mui/material';
15
-
16
- import I18n from '../i18n';
17
- import type { IobTheme } from '../types';
18
- import Utils from './Utils';
19
-
20
- const styles: Record<string, any> = {
21
- hr: {
22
- border: 0,
23
- borderTop: '1px solid gray',
24
- },
25
- scrollWindow: {
26
- width: '100%',
27
- overflow: 'auto',
28
- height: 'calc(100% - 22px)',
29
- },
30
- rowDiv: {
31
- width: '100%',
32
- },
33
- modeDiv: {
34
- width: 200,
35
- display: 'inline-block',
36
- verticalAlign: 'top',
37
- },
38
- settingsDiv: {
39
- display: 'inline-block',
40
- verticalAlign: 'top',
41
- },
42
- inputTime: {
43
- width: 90,
44
- marginTop: 0,
45
- marginLeft: 5,
46
- },
47
- inputDate: {
48
- width: 140,
49
- marginTop: 0,
50
- marginLeft: 5,
51
- },
52
- inputEvery: {
53
- width: 40,
54
- marginLeft: 5,
55
- marginRight: 5,
56
- },
57
- inputRadio: {
58
- padding: '4px 12px',
59
- verticalAlign: 'top',
60
- },
61
- inputGroup: {
62
- maxWidth: 400,
63
- display: 'inline-block',
64
- },
65
- inputGroupElement: {
66
- width: 120,
67
- },
68
- inputDateDay: {
69
- width: 60,
70
- },
71
- inputDateDayCheck: {
72
- padding: 4,
73
- },
74
- inputSmallCheck: {
75
- padding: 0,
76
- },
77
- rowOnce: {},
78
- rowDays: (theme: IobTheme) => ({
79
- background: theme.palette.mode !== 'dark' ? '#ddeaff' : '#4b5057',
80
- }),
81
- rowDows: (theme: IobTheme) => ({
82
- background: theme.palette.mode !== 'dark' ? '#DDFFDD' : '#52646c',
83
- }),
84
- rowDates: (theme: IobTheme) => ({
85
- background: theme.palette.mode !== 'dark' ? '#DDDDFF' : '#747a86',
86
- }),
87
- rowWeeks: (theme: IobTheme) => ({
88
- background: theme.palette.mode !== 'dark' ? '#DDDDFF' : '#717680',
89
- }),
90
- rowMonths: (theme: IobTheme) => ({
91
- background: theme.palette.mode !== 'dark' ? '#DDFFFF' : '#1f5557',
92
- }),
93
- rowMonthsDates: (theme: IobTheme) => ({
94
- background: theme.palette.mode !== 'dark' ? '#EEFFFF' : '#3c5737',
95
- maxWidth: 600,
96
- }),
97
- rowYears: (theme: IobTheme) => ({
98
- background: theme.palette.mode !== 'dark' ? '#fbffdd' : '#574b33',
99
- }),
100
- rowDaysDows: (theme: IobTheme) => ({
101
- background: theme.palette.mode !== 'dark' ? '#EEEAFF' : '#573544',
102
- pl: '10px',
103
- pb: '10px',
104
- }),
105
- rowDowsDows: (theme: IobTheme) => ({
106
- background: theme.palette.mode !== 'dark' ? '#EEFFEE' : '#3d4c54',
107
- pl: '10px',
108
- pb: '10px',
109
- }),
110
- };
111
-
112
- const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
113
- const MONTHS = [
114
- 'January',
115
- 'February',
116
- 'March',
117
- 'April',
118
- 'May',
119
- 'June',
120
- 'July',
121
- 'August',
122
- 'September',
123
- 'October',
124
- 'November',
125
- 'December',
126
- ];
127
- const PERIODS = {
128
- minutes: 'minutes',
129
- hours: 'hours',
130
- };
131
- const ASTRO = [
132
- 'sunrise',
133
- 'sunriseEnd',
134
- 'goldenHourEnd',
135
- 'solarNoon',
136
- 'goldenHour',
137
- 'sunsetStart',
138
- 'sunset',
139
- 'dusk',
140
- 'nauticalDusk',
141
- 'night',
142
- 'nightEnd',
143
- 'nauticalDawn',
144
- 'dawn',
145
- 'nadir',
146
- ];
147
-
148
- function padding(num: number): string {
149
- if (num < 10) {
150
- return `0${num}`;
151
- }
152
- return `${num}`;
153
- }
154
-
155
- interface ScheduleConfig {
156
- time: {
157
- exactTime: boolean;
158
- start: string;
159
- end: string;
160
- mode: string;
161
- interval: number;
162
- };
163
- period: {
164
- once: string;
165
- days: number;
166
- dows: string;
167
- dates: string;
168
- weeks: number;
169
- months: string | number;
170
- years: number;
171
- yearMonth: number;
172
- yearDate: number;
173
- };
174
- valid: {
175
- from: string;
176
- to?: string;
177
- };
178
- }
179
-
180
- // interface TextTimeProps {
181
- // inputRef: React.RefObject<HTMLInputElement>;
182
- // placeholder?: string;
183
- // }
184
-
185
- // function TextTime(props: TextTimeProps) {
186
- // const { inputRef, ...other } = props;
187
- //
188
- // return <MaskedInput
189
- // {...other}
190
- // ref={inputRef}
191
- // mask={[/[0-2]/, /[0-9]/, ':', /[0-5]/, /[0-9]/]}
192
- // placeholderChar={props.placeholder || '00:00'}
193
- // showMask
194
- // />;
195
- // }
196
-
197
- // function TextDate(props: TextTimeProps) {
198
- // const { inputRef, ...other } = props;
199
- //
200
- // return <MaskedInput
201
- // {...other}
202
- // ref={inputRef}
203
- // mask={[/[0-3]/, /[0-9]/, '.', /[0-1]/, /[0-9]/, '.', '2', '0', /[0-9]/, /[0-9]/]}
204
- // placeholderChar={props.placeholder || '01.01.2020'}
205
- // showMask
206
- // />;
207
- // }
208
-
209
- const DEFAULT: ScheduleConfig = {
210
- time: {
211
- exactTime: false,
212
-
213
- start: '00:00',
214
- end: '23:59',
215
-
216
- mode: 'hours',
217
- interval: 1,
218
- },
219
- period: {
220
- once: '',
221
- days: 1,
222
- dows: '',
223
- dates: '',
224
- weeks: 0,
225
- months: '',
226
-
227
- years: 0,
228
- yearMonth: 0,
229
- yearDate: 0,
230
- },
231
- valid: {
232
- from: '',
233
- to: '',
234
- },
235
- };
236
-
237
- function string2USdate(date: string): string {
238
- const parts = date.split('.');
239
- if (parts.length === 3) {
240
- return `${parts[2]}-${parts[1]}-${parts[0]}`;
241
- }
242
- return '';
243
- }
244
-
245
- interface ScheduleProps {
246
- schedule: string | ScheduleConfig;
247
- onChange: (schedule: string, desc?: string) => void;
248
- theme: IobTheme;
249
- }
250
-
251
- interface ScheduleState {
252
- schedule: ScheduleConfig;
253
- desc: string;
254
- }
255
-
256
- class Schedule extends Component<ScheduleProps, ScheduleState> {
257
- private readonly refFrom: React.RefObject<HTMLInputElement>;
258
-
259
- private readonly refTo: React.RefObject<HTMLInputElement>;
260
-
261
- private readonly refOnce: React.RefObject<HTMLInputElement>;
262
-
263
- private timerOnce: ReturnType<typeof setTimeout> | null = null;
264
-
265
- private timerFrom: ReturnType<typeof setTimeout> | null = null;
266
-
267
- private timerTo: ReturnType<typeof setTimeout> | null = null;
268
-
269
- constructor(props: ScheduleProps) {
270
- super(props);
271
- let schedule: ScheduleConfig | undefined;
272
- if (this.props.schedule && typeof this.props.schedule === 'string' && this.props.schedule[0] === '{') {
273
- try {
274
- schedule = JSON.parse(this.props.schedule);
275
- } catch {
276
- // ignore
277
- }
278
- } else if (typeof this.props.schedule === 'object') {
279
- schedule = this.props.schedule;
280
- }
281
-
282
- if (!schedule || !Object.keys(schedule).length) {
283
- setTimeout(() => this.onChange(this.state.schedule, true), 200);
284
- schedule = DEFAULT;
285
- }
286
- schedule = { ...DEFAULT, ...schedule };
287
- schedule.valid.from = schedule.valid.from || Schedule.now2string();
288
-
289
- this.refFrom = React.createRef();
290
- this.refTo = React.createRef();
291
- this.refOnce = React.createRef();
292
-
293
- this.state = {
294
- schedule,
295
- desc: Schedule.state2text(schedule),
296
- };
297
-
298
- if (JSON.stringify(schedule) !== this.props.schedule) {
299
- setTimeout(() => this.props.onChange && this.props.onChange(JSON.stringify(schedule)), 100);
300
- }
301
- }
302
-
303
- onChange(schedule: ScheduleConfig, force?: boolean): void {
304
- const isDiff = JSON.stringify(schedule) !== JSON.stringify(this.state.schedule);
305
- if (force || isDiff) {
306
- isDiff && this.setState({ schedule, desc: Schedule.state2text(schedule) });
307
- const copy = JSON.parse(JSON.stringify(schedule));
308
- if (copy.period.once) {
309
- const once = copy.period.once;
310
- delete copy.period;
311
- copy.period = { once };
312
- delete copy.valid;
313
- } else if (copy.period.days) {
314
- const days = copy.period.days;
315
- const daysOfWeek = copy.period.dows;
316
- delete copy.period;
317
- copy.period = { days };
318
- if (daysOfWeek && daysOfWeek !== '[]') {
319
- copy.period.dows = daysOfWeek;
320
- }
321
- } else if (copy.period.weeks) {
322
- const weeks = copy.period.weeks;
323
- const daysOfWeek = copy.period.dows;
324
- delete copy.period;
325
- copy.period = { weeks };
326
- if (daysOfWeek && daysOfWeek !== '[]') {
327
- copy.period.dows = daysOfWeek;
328
- }
329
- } else if (copy.period.months) {
330
- const months = copy.period.months;
331
- const dates = copy.period.dates;
332
- delete copy.period;
333
- copy.period = { months };
334
- if (dates && dates !== '[]') {
335
- copy.period.dates = dates;
336
- }
337
- } else if (copy.period.years) {
338
- const years = copy.period.years;
339
- const yearMonth = copy.period.yearMonth;
340
- const yearDate = copy.period.yearDate;
341
- delete copy.period;
342
- copy.period = { years, yearDate };
343
- if (yearMonth) {
344
- copy.period.yearMonth = yearMonth;
345
- }
346
- }
347
-
348
- if (copy.time.exactTime) {
349
- delete copy.time.end;
350
- delete copy.time.mode;
351
- delete copy.time.interval;
352
- } else {
353
- delete copy.time.exactTime;
354
- }
355
- if (copy.valid) {
356
- if (!copy.valid.to) {
357
- delete copy.valid.to;
358
- }
359
- if (
360
- copy.period.days === 1 ||
361
- copy.period.weeks === 1 ||
362
- copy.period.months === 1 ||
363
- copy.period.years === 1
364
- ) {
365
- const from = Schedule.string2date(copy.valid.from);
366
- const today = new Date();
367
- today.setHours(0);
368
- today.setMinutes(0);
369
- today.setSeconds(0);
370
- today.setMilliseconds(0);
371
- if (from <= today) {
372
- delete copy.valid.from;
373
- }
374
- }
375
- if (!copy.valid.from && !copy.valid.to) {
376
- delete copy.valid;
377
- }
378
- }
379
-
380
- this.props.onChange && this.props.onChange(JSON.stringify(copy), Schedule.state2text(schedule));
381
- }
382
- }
383
-
384
- static state2text(schedule: string | ScheduleConfig): string {
385
- if (typeof schedule === 'string') {
386
- try {
387
- schedule = JSON.parse(schedule) as ScheduleConfig;
388
- } catch {
389
- return '';
390
- }
391
- }
392
-
393
- const desc = [];
394
- const validFrom = Schedule.string2date(schedule.valid.from);
395
- if (schedule.period.once) {
396
- // once
397
- const once = Schedule.string2date(schedule.period.once);
398
- const now = new Date();
399
- now.setMilliseconds(0);
400
- now.setSeconds(0);
401
- now.setMinutes(0);
402
- now.setHours(0);
403
-
404
- //
405
- if (once < now) {
406
- // will be not executed anymore, because start is in the past
407
- return I18n.t('sch_desc_onceInPast');
408
- }
409
- // only once
410
- desc.push(I18n.t('sch_desc_once_on', schedule.period.once));
411
- } else if (schedule.period.days) {
412
- if (schedule.period.days === 1) {
413
- if (schedule.period.dows) {
414
- const daysOfWeek = JSON.parse(schedule.period.dows);
415
- if (daysOfWeek.length === 2 && daysOfWeek[0] === 0 && daysOfWeek[1] === 6) {
416
- // on weekends
417
- desc.push(I18n.t('sch_desc_onWeekends'));
418
- } else if (
419
- daysOfWeek.length === 5 &&
420
- daysOfWeek[0] === 1 &&
421
- daysOfWeek[1] === 2 &&
422
- daysOfWeek[2] === 3 &&
423
- daysOfWeek[3] === 4 &&
424
- daysOfWeek[4] === 5
425
- ) {
426
- // on workdays
427
- desc.push(I18n.t('sch_desc_onWorkdays'));
428
- } else {
429
- const tDows = daysOfWeek.map((day: number) => I18n.t(WEEKDAYS[day]));
430
- if (tDows.length === 1) {
431
- // on Monday
432
- desc.push(I18n.t('sch_desc_onWeekday', tDows[0]));
433
- } else if (tDows.length === 7) {
434
- // on every day
435
- desc.push(I18n.t('sch_desc_everyDay'));
436
- } else {
437
- const last = tDows.pop();
438
- // on Monday and Sunday
439
- desc.push(I18n.t('sch_desc_onWeekdays', tDows.join(', '), last));
440
- }
441
- }
442
- } else {
443
- desc.push(I18n.t('sch_desc_everyDay'));
444
- }
445
- } else {
446
- desc.push(I18n.t('sch_desc_everyNDay', schedule.period.days.toString()));
447
- }
448
- } else if (schedule.period.weeks) {
449
- if (schedule.period.weeks === 1) {
450
- desc.push(I18n.t('sch_desc_everyWeek'));
451
- } else {
452
- desc.push(I18n.t('sch_desc_everyNWeeks', schedule.period.weeks.toString()));
453
- }
454
-
455
- if (schedule.period.dows) {
456
- const daysOfWeek = JSON.parse(schedule.period.dows);
457
- if (daysOfWeek.length === 2 && daysOfWeek[0] === 0 && daysOfWeek[1] === 6) {
458
- // on weekends
459
- desc.push(I18n.t('sch_desc_onWeekends'));
460
- } else if (
461
- daysOfWeek.length === 5 &&
462
- daysOfWeek[0] === 1 &&
463
- daysOfWeek[1] === 2 &&
464
- daysOfWeek[2] === 3 &&
465
- daysOfWeek[3] === 4 &&
466
- daysOfWeek[4] === 5
467
- ) {
468
- // on workdays
469
- desc.push(I18n.t('sch_desc_onWorkdays'));
470
- } else {
471
- const tDows = daysOfWeek.map((day: number) => I18n.t(WEEKDAYS[day]));
472
- if (tDows.length === 1) {
473
- // on Monday
474
- desc.push(I18n.t('sch_desc_onWeekday', tDows[0]));
475
- } else if (tDows.length === 7) {
476
- // on every day
477
- desc.push(I18n.t('sch_desc_everyDay'));
478
- } else {
479
- const last = tDows.pop();
480
- // on Monday and Sunday
481
- desc.push(I18n.t('sch_desc_onWeekdays', tDows.join(', '), last));
482
- }
483
- }
484
- } else {
485
- return I18n.t('sch_desc_never');
486
- }
487
- } else if (schedule.period.months) {
488
- if (schedule.period.dates) {
489
- const dates = JSON.parse(schedule.period.dates);
490
- if (dates.length === 1) {
491
- // in 1 of month
492
- desc.push(I18n.t('sch_desc_onDate', dates[0]));
493
- } else if (dates.length === 31) {
494
- desc.push(I18n.t('sch_desc_onEveryDate'));
495
- } else if (!dates.length) {
496
- return I18n.t('sch_desc_never');
497
- } else {
498
- const last = dates.pop();
499
- // in 1 and 4 of month
500
- desc.push(I18n.t('sch_desc_onDates', dates.join(', '), last));
501
- }
502
- } else {
503
- desc.push(I18n.t('sch_desc_onEveryDate'));
504
- }
505
-
506
- if (schedule.period.months === 1) {
507
- desc.push(I18n.t('sch_desc_everyMonth'));
508
- } else if (typeof schedule.period.months === 'number') {
509
- desc.push(I18n.t('sch_desc_everyNMonths', schedule.period.months.toString()));
510
- } else {
511
- const months = JSON.parse(schedule.period.months);
512
- const tMonths = months.map((month: number) => I18n.t(MONTHS[month - 1]));
513
- if (!tMonths.length) {
514
- // in January
515
- return I18n.t('sch_desc_never');
516
- }
517
- if (tMonths.length === 1) {
518
- // in January
519
- desc.push(I18n.t('sch_desc_onMonth', tMonths[0]));
520
- } else if (tMonths.length === 12) {
521
- // every month
522
- desc.push(I18n.t('sch_desc_everyMonth'));
523
- } else {
524
- const last = tMonths.pop();
525
- // in January and May
526
- desc.push(I18n.t('sch_desc_onMonths', tMonths.join(', '), last));
527
- }
528
- }
529
- } else if (schedule.period.years) {
530
- if (schedule.period.years === 1) {
531
- desc.push(I18n.t('sch_desc_everyYear'));
532
- } else {
533
- desc.push(I18n.t('sch_desc_everyNYears', schedule.period.years.toString()));
534
- }
535
- desc.push(
536
- I18n.t(
537
- 'sch_desc_onDate',
538
- schedule.period.yearDate.toString(),
539
- schedule.period.yearMonth
540
- ? I18n.t(MONTHS[schedule.period.yearMonth - 1])
541
- : I18n.t('sch_desc_everyMonth'),
542
- ),
543
- );
544
- }
545
-
546
- // time
547
- if (schedule.time.exactTime) {
548
- if (ASTRO.includes(schedule.time.start)) {
549
- // at sunset
550
- desc.push(I18n.t('sch_desc_atTime', I18n.t(`sch_astro_${schedule.time.start}`)));
551
- } else {
552
- // at HH:MM
553
- desc.push(I18n.t('sch_desc_atTime', schedule.time.start));
554
- }
555
- } else {
556
- if (schedule.time.mode === PERIODS.minutes) {
557
- if (schedule.time.interval === 1) {
558
- // every minute
559
- desc.push(I18n.t('sch_desc_everyMinute'));
560
- } else {
561
- // every N minutes
562
- desc.push(I18n.t('sch_desc_everyNMinutes', schedule.time.interval.toString()));
563
- }
564
- } else if (schedule.time.interval === 1) {
565
- // every minute
566
- desc.push(I18n.t('sch_desc_everyHour'));
567
- } else {
568
- // every N minutes
569
- desc.push(I18n.t('sch_desc_everyNHours', schedule.time.interval.toString()));
570
- }
571
-
572
- const start =
573
- ASTRO.indexOf(schedule.time.start) !== -1
574
- ? I18n.t(`sch_astro_${schedule.time.start}`)
575
- : schedule.time.start;
576
- const end =
577
- ASTRO.indexOf(schedule.time.end) !== -1 ? I18n.t(`sch_astro_${schedule.time.end}`) : schedule.time.end;
578
- if (start !== '00:00' || (end !== '24:00' && end !== '23:59')) {
579
- // from HH:mm to HH:mm
580
- desc.push(I18n.t('sch_desc_intervalFromTo', start, end));
581
- }
582
- }
583
-
584
- if (!schedule.period.once) {
585
- // valid
586
- if (validFrom.getTime() > Date.now() && schedule.valid.to) {
587
- // from XXX to XXXX
588
- desc.push(I18n.t('sch_desc_validFromTo', schedule.valid.from, schedule.valid.to));
589
- } else if (validFrom.getTime() > Date.now()) {
590
- // from XXXX
591
- desc.push(I18n.t('sch_desc_validFrom', schedule.valid.from));
592
- } else if (schedule.valid.to) {
593
- // till XXXX
594
- desc.push(I18n.t('sch_desc_validTo', schedule.valid.to));
595
- }
596
- }
597
- return desc.join(' ');
598
- }
599
-
600
- getTimePeriodElements(): JSX.Element {
601
- const schedule = this.state.schedule;
602
- let wholeDay = false;
603
- let day = false;
604
- let night = false;
605
- let fromTo = true;
606
- if (schedule.time.start === '00:00' && schedule.time.end === '24:00') {
607
- wholeDay = true;
608
- fromTo = false;
609
- } else if (schedule.time.start === 'sunrise') {
610
- day = true;
611
- fromTo = false;
612
- } else if (schedule.time.start === 'sunset') {
613
- night = true;
614
- fromTo = false;
615
- }
616
-
617
- return (
618
- <div
619
- key="timePeriod"
620
- style={styles.rowDiv}
621
- >
622
- <div style={styles.modeDiv}>
623
- <FormControlLabel
624
- control={
625
- <Radio
626
- style={styles.inputRadio}
627
- checked={!schedule.time.exactTime}
628
- onClick={() => {
629
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
630
- _schedule.time.exactTime = false;
631
- this.onChange(_schedule);
632
- }}
633
- />
634
- }
635
- label={I18n.t('sch_intervalTime')}
636
- />
637
- </div>
638
- <div style={styles.settingsDiv}>
639
- <div style={styles.settingsDiv}>
640
- {!schedule.time.exactTime && (
641
- <div>
642
- <div>
643
- <FormControlLabel
644
- control={
645
- <Radio
646
- style={styles.inputRadio}
647
- checked={!!fromTo}
648
- onClick={() => {
649
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
650
- _schedule.time.start = '00:00';
651
- _schedule.time.end = '23:59';
652
- this.onChange(_schedule);
653
- }}
654
- />
655
- }
656
- label={!fromTo ? I18n.t('sch_fromTo') : ''}
657
- />
658
- {fromTo && [
659
- <TextField
660
- variant="standard"
661
- style={{ ...styles.inputTime, marginRight: 10 }}
662
- key="exactTimeFrom"
663
- type="time"
664
- sx={(theme: Theme) => ({
665
- '& input[type="time"]::-webkit-calendar-picker-indicator': {
666
- filter: theme.palette.mode === 'dark' ? 'invert(80%)' : undefined,
667
- },
668
- })}
669
- value={this.state.schedule.time.start}
670
- // InputProps={{inputComponent: TextTime}}
671
- onChange={e => {
672
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
673
- _schedule.time.start = e.target.value;
674
- this.onChange(_schedule);
675
- }}
676
- slotProps={{
677
- inputLabel: { shrink: true },
678
- }}
679
- label={I18n.t('sch_from')}
680
- margin="normal"
681
- />,
682
- <TextField
683
- variant="standard"
684
- style={styles.inputTime}
685
- key="exactTimeTo"
686
- type="time"
687
- sx={(theme: Theme) => ({
688
- '& input[type="time"]::-webkit-calendar-picker-indicator': {
689
- filter: theme.palette.mode === 'dark' ? 'invert(80%)' : undefined,
690
- },
691
- })}
692
- value={this.state.schedule.time.end}
693
- // InputProps={{inputComponent: TextTime}}
694
- onChange={e => {
695
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
696
- _schedule.time.end = e.target.value;
697
- this.onChange(_schedule);
698
- }}
699
- slotProps={{
700
- inputLabel: { shrink: true },
701
- }}
702
- label={I18n.t('sch_to')}
703
- margin="normal"
704
- />,
705
- ]}
706
- </div>
707
- </div>
708
- )}
709
-
710
- {!schedule.time.exactTime && (
711
- <div>
712
- <FormControlLabel
713
- control={
714
- <Radio
715
- style={styles.inputRadio}
716
- checked={!!wholeDay}
717
- onClick={() => {
718
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
719
- _schedule.time.start = '00:00';
720
- _schedule.time.end = '24:00';
721
- this.onChange(_schedule);
722
- }}
723
- />
724
- }
725
- label={I18n.t('sch_wholeDay')}
726
- />
727
- </div>
728
- )}
729
-
730
- {!schedule.time.exactTime && (
731
- <div>
732
- <FormControlLabel
733
- control={
734
- <Radio
735
- style={styles.inputRadio}
736
- checked={!!day}
737
- onClick={() => {
738
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
739
- _schedule.time.start = 'sunrise';
740
- _schedule.time.end = 'sunset';
741
- this.onChange(_schedule);
742
- }}
743
- />
744
- }
745
- label={I18n.t('sch_astroDay')}
746
- />
747
- </div>
748
- )}
749
-
750
- {!schedule.time.exactTime && (
751
- <div>
752
- <FormControlLabel
753
- control={
754
- <Radio
755
- style={styles.inputRadio}
756
- checked={!!night}
757
- onClick={() => {
758
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
759
- _schedule.time.start = 'sunset';
760
- _schedule.time.end = 'sunrise';
761
- this.onChange(_schedule);
762
- }}
763
- />
764
- }
765
- label={I18n.t('sch_astroNight')}
766
- />
767
- </div>
768
- )}
769
- </div>
770
- {!schedule.time.exactTime && this.getPeriodSettingsMinutes()}
771
- </div>
772
- </div>
773
- );
774
- }
775
-
776
- getTimeExactElements(): JSX.Element {
777
- const isAstro = ASTRO.includes(this.state.schedule.time.start);
778
-
779
- return (
780
- <div
781
- key="timeExact"
782
- style={styles.rowDiv}
783
- >
784
- <div style={styles.modeDiv}>
785
- <FormControlLabel
786
- control={
787
- <Radio
788
- style={styles.inputRadio}
789
- checked={!!this.state.schedule.time.exactTime}
790
- onClick={() => {
791
- const schedule = JSON.parse(JSON.stringify(this.state.schedule));
792
- schedule.time.exactTime = true;
793
- this.onChange(schedule);
794
- }}
795
- />
796
- }
797
- label={I18n.t('sch_exactTime')}
798
- />
799
- </div>
800
- {this.state.schedule.time.exactTime && (
801
- <Select
802
- variant="standard"
803
- value={isAstro ? this.state.schedule.time.start : '00:00'}
804
- onChange={e => {
805
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
806
- _schedule.time.start = e.target.value;
807
- this.onChange(_schedule);
808
- }}
809
- >
810
- <MenuItem
811
- key="specific"
812
- value="00:00"
813
- >
814
- {I18n.t('sch_specificTime')}
815
- </MenuItem>
816
- {ASTRO.map(event => (
817
- <MenuItem
818
- key={event}
819
- value={event}
820
- >
821
- {I18n.t(`sch_astro_${event}`)}
822
- </MenuItem>
823
- ))}
824
- </Select>
825
- )}
826
- {this.state.schedule.time.exactTime && !isAstro && (
827
- <div style={styles.settingsDiv}>
828
- <TextField
829
- variant="standard"
830
- style={styles.inputTime}
831
- key="exactTimeValue"
832
- value={this.state.schedule.time.start}
833
- type="time"
834
- sx={(theme: Theme) => ({
835
- '& input[type="time"]::-webkit-calendar-picker-indicator': {
836
- filter: theme.palette.mode === 'dark' ? 'invert(80%)' : undefined,
837
- },
838
- })}
839
- onChange={e => {
840
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
841
- _schedule.time.start = e.target.value;
842
- this.onChange(_schedule);
843
- }}
844
- slotProps={{
845
- inputLabel: { shrink: true },
846
- }}
847
- margin="normal"
848
- />
849
- </div>
850
- )}
851
- </div>
852
- );
853
- }
854
-
855
- static getDivider(): JSX.Element {
856
- return <hr style={styles.hr} />;
857
- }
858
-
859
- getPeriodModes(): JSX.Element[] {
860
- const schedule = this.state.schedule;
861
- const isOnce =
862
- !schedule.period.dows &&
863
- !schedule.period.months &&
864
- !schedule.period.dates &&
865
- !schedule.period.years &&
866
- !schedule.period.days &&
867
- !schedule.period.weeks;
868
- if (isOnce && !schedule.period.once) {
869
- schedule.period.once = Schedule.now2string(true);
870
- }
871
-
872
- return [
873
- // ----- once ---
874
- <div
875
- key="once"
876
- style={{ ...styles.rowDiv, ...styles.rowOnce }}
877
- >
878
- <div style={styles.modeDiv}>
879
- <FormControlLabel
880
- control={
881
- <Radio
882
- style={styles.inputRadio}
883
- checked={!!isOnce}
884
- onClick={() => {
885
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
886
- _schedule.period.once = _schedule.period.once || Schedule.now2string(true);
887
- _schedule.period.dows = '';
888
- _schedule.period.months = '';
889
- _schedule.period.dates = '';
890
- _schedule.period.years = 0;
891
- _schedule.period.yearDate = 0;
892
- _schedule.period.yearMonth = 0;
893
- _schedule.period.weeks = 0;
894
- _schedule.period.days = 0;
895
- this.onChange(_schedule);
896
- }}
897
- />
898
- }
899
- label={I18n.t('sch_periodOnce')}
900
- />
901
- </div>
902
- {isOnce && (
903
- <div style={styles.settingsDiv}>
904
- <TextField
905
- variant="standard"
906
- style={styles.inputDate}
907
- type="date"
908
- ref={this.refOnce}
909
- key="exactDateAt"
910
- defaultValue={string2USdate(schedule.period.once)}
911
- // InputProps={{inputComponent: TextTime}}
912
- onChange={e => {
913
- this.timerOnce && clearTimeout(this.timerOnce);
914
- this.timerOnce = null;
915
-
916
- if (this.refOnce.current) {
917
- this.refOnce.current.style.background = '#ff000030';
918
- }
919
- this.timerOnce = setTimeout(
920
- value => {
921
- this.timerOnce = null;
922
- if (this.refOnce.current) {
923
- this.refOnce.current.style.background = '';
924
- }
925
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
926
- const date = Schedule.string2date(value);
927
- if (date.toString() !== 'Invalid Date') {
928
- _schedule.period.once = `${padding(date.getDate())}.${padding(date.getMonth() + 1)}.${date.getFullYear()}`;
929
- this.onChange(_schedule);
930
- }
931
- },
932
- 1500,
933
- e.target.value,
934
- );
935
- }}
936
- slotProps={{
937
- inputLabel: { shrink: true },
938
- }}
939
- label={I18n.t('sch_at')}
940
- margin="normal"
941
- />
942
- </div>
943
- )}
944
- </div>,
945
-
946
- // ----- days ---
947
- <Box
948
- component="div"
949
- key="days"
950
- sx={Utils.getStyle(this.props.theme, styles.rowDiv, styles.rowDays)}
951
- >
952
- <div style={styles.modeDiv}>
953
- <FormControlLabel
954
- control={
955
- <Radio
956
- style={styles.inputRadio}
957
- checked={!!schedule.period.days}
958
- onClick={() => {
959
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
960
- _schedule.period.days = 1;
961
- _schedule.period.dows = '';
962
- _schedule.period.months = '';
963
- _schedule.period.dates = '';
964
- _schedule.period.years = 0;
965
- _schedule.period.yearDate = 0;
966
- _schedule.period.yearMonth = 0;
967
- _schedule.period.weeks = 0;
968
- _schedule.period.once = '';
969
- this.onChange(_schedule);
970
- }}
971
- />
972
- }
973
- label={I18n.t('sch_periodDaily')}
974
- />
975
- </div>
976
- <div style={styles.settingsDiv}>
977
- {this.getPeriodSettingsDaily()}
978
- {schedule.period.days ? this.getPeriodSettingsWeekdays() : null}
979
- </div>
980
- </Box>,
981
-
982
- // ----- days of weeks ---
983
- /*
984
- !schedule.period.days && (
985
- <div key="dows" style={styles.rowDiv + ' ' + styles.rowDows}>
986
- <div style={styles.modeDiv}>
987
- <FormControlLabel control={<Radio style={styles.inputRadio} checked={!!schedule.period.dows} onClick={() => {
988
- const schedule = JSON.parse(JSON.stringify(this.state.schedule));
989
- schedule.period.dows = schedule.period.dows ? '' : '[0,1,2,3,4,5,6]';
990
- this.onChange(schedule);
991
- }}/>}
992
- label={I18n.t('sch_periodWeekdays')} />
993
- </div>
994
- <div style={styles.settingsDiv}>
995
- {this.getPeriodSettingsWeekdays()}
996
- </div>
997
- </div>,
998
- */
999
- // ----- weeks ---
1000
- <Box
1001
- component="div"
1002
- key="weeks"
1003
- sx={Utils.getStyle(this.props.theme, styles.rowDiv, styles.rowDows)}
1004
- >
1005
- <div style={styles.modeDiv}>
1006
- <FormControlLabel
1007
- control={
1008
- <Radio
1009
- style={styles.inputRadio}
1010
- checked={!!schedule.period.weeks}
1011
- onClick={() => {
1012
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1013
- _schedule.period.weeks = schedule.period.weeks ? 0 : 1;
1014
- _schedule.period.dows = schedule.period.dows || '[0]';
1015
- _schedule.period.months = '';
1016
- _schedule.period.dates = '';
1017
- _schedule.period.years = 0;
1018
- _schedule.period.yearDate = 0;
1019
- _schedule.period.yearMonth = 0;
1020
- _schedule.period.days = 0;
1021
- _schedule.period.once = '';
1022
- this.onChange(_schedule);
1023
- }}
1024
- />
1025
- }
1026
- label={I18n.t('sch_periodWeekly')}
1027
- />
1028
- </div>
1029
- <Box
1030
- component="div"
1031
- style={styles.settingsDiv}
1032
- >
1033
- <div style={styles.settingsDiv}>{this.getPeriodSettingsWeekly()}</div>
1034
- <Box
1035
- component="div"
1036
- sx={Utils.getStyle(this.props.theme, styles.settingsDiv, styles.rowDowsDows)}
1037
- >
1038
- {this.state.schedule.period.weeks ? this.getPeriodSettingsWeekdays() : null}
1039
- </Box>
1040
- </Box>
1041
- </Box>,
1042
-
1043
- // ----- months ---
1044
- <Box
1045
- component="div"
1046
- key="months"
1047
- sx={Utils.getStyle(this.props.theme, styles.rowDiv, styles.rowMonths)}
1048
- >
1049
- <div style={styles.modeDiv}>
1050
- <FormControlLabel
1051
- control={
1052
- <Radio
1053
- style={styles.inputRadio}
1054
- checked={!!schedule.period.months}
1055
- onClick={() => {
1056
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1057
- _schedule.period.months = 1;
1058
- _schedule.period.dows = '';
1059
- _schedule.period.dates = '';
1060
- _schedule.period.years = 0;
1061
- _schedule.period.yearDate = 0;
1062
- _schedule.period.yearMonth = 0;
1063
- _schedule.period.weeks = 0;
1064
- _schedule.period.days = 0;
1065
- _schedule.period.once = '';
1066
- this.onChange(_schedule);
1067
- }}
1068
- />
1069
- }
1070
- label={I18n.t('sch_periodMonthly')}
1071
- />
1072
- </div>
1073
- <div style={styles.settingsDiv}>
1074
- {this.getPeriodSettingsMonthly()}
1075
- {schedule.period.months ? (
1076
- <Box>
1077
- <Box
1078
- component="div"
1079
- sx={Utils.getStyle(this.props.theme, styles.settingsDiv, styles.rowMonthsDates)}
1080
- >
1081
- <FormControlLabel
1082
- control={
1083
- <Checkbox
1084
- style={styles.inputRadio}
1085
- checked={!!schedule.period.dates}
1086
- onClick={() => {
1087
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1088
- _schedule.period.months = _schedule.period.months || 1;
1089
- const dates = [];
1090
- for (let i = 1; i <= 31; i++) {
1091
- dates.push(i);
1092
- }
1093
- _schedule.period.dates =
1094
- _schedule.period.dates || JSON.stringify(dates);
1095
- _schedule.period.dows = '';
1096
- _schedule.period.years = 0;
1097
- _schedule.period.yearDate = 0;
1098
- _schedule.period.yearMonth = 0;
1099
- _schedule.period.weeks = 0;
1100
- _schedule.period.days = 0;
1101
- _schedule.period.once = '';
1102
-
1103
- this.onChange(_schedule);
1104
- }}
1105
- />
1106
- }
1107
- label={I18n.t('sch_periodDates')}
1108
- />
1109
- </Box>
1110
- <Box
1111
- component="div"
1112
- sx={Utils.getStyle(this.props.theme, styles.settingsDiv, styles.rowMonthsDates)}
1113
- >
1114
- {this.getPeriodSettingsDates()}
1115
- </Box>
1116
- </Box>
1117
- ) : null}
1118
- </div>
1119
- </Box>,
1120
-
1121
- // ----- years ---
1122
- <Box
1123
- component="div"
1124
- key="years"
1125
- sx={Utils.getStyle(this.props.theme, styles.rowDiv, styles.rowYears)}
1126
- >
1127
- <div style={styles.modeDiv}>
1128
- <FormControlLabel
1129
- control={
1130
- <Radio
1131
- style={styles.inputRadio}
1132
- checked={!!schedule.period.years}
1133
- onClick={() => {
1134
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1135
- _schedule.period.years = 1;
1136
- _schedule.period.yearDate = 1;
1137
- _schedule.period.yearMonth = 1;
1138
- _schedule.period.dows = '';
1139
- _schedule.period.months = 0;
1140
- _schedule.period.dates = '';
1141
- _schedule.period.weeks = 0;
1142
- _schedule.period.days = 0;
1143
- _schedule.period.once = '';
1144
- this.onChange(_schedule);
1145
- }}
1146
- />
1147
- }
1148
- label={I18n.t('sch_periodYearly')}
1149
- />
1150
- </div>
1151
- <div style={styles.settingsDiv}>
1152
- <div style={styles.settingsDiv}>{this.getPeriodSettingsYearly()}</div>
1153
- {!!schedule.period.years && (
1154
- <div style={styles.settingsDiv}>
1155
- <span>{I18n.t('sch_on')}</span>
1156
- <Input
1157
- key="input"
1158
- value={this.state.schedule.period.yearDate}
1159
- style={styles.inputEvery}
1160
- type="number"
1161
- inputProps={{ min: 1, max: 31 }}
1162
- onChange={e => {
1163
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1164
- _schedule.period.yearDate = parseInt(e.target.value, 10);
1165
- if (_schedule.period.yearDate < 1) {
1166
- _schedule.period.yearDate = 31;
1167
- }
1168
- if (_schedule.period.yearDate > 31) {
1169
- _schedule.period.yearDate = 1;
1170
- }
1171
- this.onChange(_schedule);
1172
- }}
1173
- />
1174
- <Select
1175
- variant="standard"
1176
- value={schedule.period.yearMonth}
1177
- onChange={e => {
1178
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1179
- _schedule.period.yearMonth = e.target.value;
1180
- this.onChange(_schedule);
1181
- }}
1182
- >
1183
- <MenuItem
1184
- key="every"
1185
- value={0}
1186
- >
1187
- {I18n.t('sch_yearEveryMonth')}
1188
- </MenuItem>
1189
- {MONTHS.map((month, i) => (
1190
- <MenuItem
1191
- key={month}
1192
- value={i + 1}
1193
- >
1194
- {I18n.t(month)}
1195
- </MenuItem>
1196
- ))}
1197
- </Select>
1198
- </div>
1199
- )}
1200
- </div>
1201
- </Box>,
1202
- ];
1203
- }
1204
-
1205
- getPeriodSettingsMinutes(): JSX.Element {
1206
- return (
1207
- <div style={{ display: 'inline-block' }}>
1208
- <label>{I18n.t('sch_every')}</label>
1209
- <Input
1210
- value={this.state.schedule.time.interval}
1211
- style={{ ...styles.inputEvery, verticalAlign: 'bottom' }}
1212
- type="number"
1213
- inputProps={{ min: 1 }}
1214
- onChange={e => {
1215
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1216
- _schedule.time.interval = parseInt(e.target.value, 10);
1217
- this.onChange(_schedule);
1218
- }}
1219
- />
1220
- <Select
1221
- variant="standard"
1222
- value={this.state.schedule.time.mode}
1223
- onChange={e => {
1224
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1225
- _schedule.time.mode = e.target.value;
1226
- this.onChange(_schedule);
1227
- }}
1228
- >
1229
- <MenuItem value={PERIODS.minutes}>{I18n.t('sch_periodMinutes')}</MenuItem>
1230
- <MenuItem value={PERIODS.hours}>{I18n.t('sch_periodHours')}</MenuItem>
1231
- </Select>
1232
- </div>
1233
- );
1234
- }
1235
-
1236
- getPeriodSettingsWeekdays(): JSX.Element[] {
1237
- // || this.state.schedule.period.dows === '[1, 2, 3, 4, 5]' || this.state.schedule.period.dows === '[0, 6]'
1238
- const schedule = this.state.schedule;
1239
- const isSpecific =
1240
- schedule.period.dows && schedule.period.dows !== '[1, 2, 3, 4, 5]' && schedule.period.dows !== '[0, 6]';
1241
- return [
1242
- <div key="workdays">
1243
- <FormControlLabel
1244
- control={
1245
- <Radio
1246
- style={styles.inputRadio}
1247
- checked={schedule.period.dows === '[1, 2, 3, 4, 5]'}
1248
- onClick={() => {
1249
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1250
- _schedule.period.dows = '[1, 2, 3, 4, 5]';
1251
- if (_schedule.period.days) {
1252
- _schedule.period.days = 1;
1253
- }
1254
- this.onChange(_schedule);
1255
- }}
1256
- />
1257
- }
1258
- label={I18n.t('sch_periodWorkdays')}
1259
- />
1260
- </div>,
1261
-
1262
- <div key="weekend">
1263
- <FormControlLabel
1264
- control={
1265
- <Radio
1266
- style={styles.inputRadio}
1267
- checked={schedule.period.dows === '[0, 6]'}
1268
- onClick={() => {
1269
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1270
- _schedule.period.dows = '[0, 6]';
1271
- if (_schedule.period.days) {
1272
- _schedule.period.days = 1;
1273
- }
1274
- this.onChange(_schedule);
1275
- }}
1276
- />
1277
- }
1278
- label={I18n.t('sch_periodWeekend')}
1279
- />
1280
- </div>,
1281
-
1282
- <div
1283
- key="specific"
1284
- style={{ verticalAlign: 'top' }}
1285
- >
1286
- <FormControlLabel
1287
- style={{ verticalAlign: 'top' }}
1288
- control={
1289
- <Radio
1290
- style={styles.inputRadio}
1291
- checked={!!isSpecific}
1292
- onClick={() => {
1293
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1294
- _schedule.period.dows = '[0, 1, 2, 3, 4, 5, 6]';
1295
- if (_schedule.period.days) {
1296
- _schedule.period.days = 1;
1297
- }
1298
- this.onChange(_schedule);
1299
- }}
1300
- />
1301
- }
1302
- label={I18n.t('sch_periodWeekdays')}
1303
- />
1304
- {isSpecific && (schedule.period.days === 1 || schedule.period.weeks) && (
1305
- <FormGroup
1306
- row
1307
- style={{ ...styles.inputGroup, width: 150 }}
1308
- >
1309
- {[1, 2, 3, 4, 5, 6, 0].map(i => (
1310
- <FormControlLabel
1311
- key={`specific_${i}`}
1312
- style={styles.inputGroupElement}
1313
- control={
1314
- <Checkbox
1315
- style={styles.inputSmallCheck}
1316
- checked={schedule.period.dows.includes(i.toString())}
1317
- onChange={e => {
1318
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1319
- let daysOfWeek: number[];
1320
- try {
1321
- daysOfWeek = JSON.parse(_schedule.period.dows);
1322
- } catch {
1323
- daysOfWeek = [];
1324
- }
1325
- if (e.target.checked && !daysOfWeek.includes(i)) {
1326
- daysOfWeek.push(i);
1327
- } else if (!e.target.checked && daysOfWeek.includes(i)) {
1328
- daysOfWeek.splice(daysOfWeek.indexOf(i), 1);
1329
- }
1330
- daysOfWeek.sort((a: number, b: number) => a - b);
1331
- _schedule.period.dows = JSON.stringify(daysOfWeek);
1332
- if (_schedule.period.days) {
1333
- _schedule.period.days = 1;
1334
- }
1335
- this.onChange(_schedule);
1336
- }}
1337
- />
1338
- }
1339
- label={I18n.t(WEEKDAYS[i])}
1340
- />
1341
- ))}
1342
- </FormGroup>
1343
- )}
1344
- </div>,
1345
- ];
1346
- }
1347
-
1348
- getPeriodSettingsDaily(): JSX.Element[] | null {
1349
- if (!this.state.schedule.period.days) {
1350
- return null;
1351
- }
1352
- const schedule = this.state.schedule;
1353
- return [
1354
- <div key="every_day">
1355
- <FormControlLabel
1356
- control={
1357
- <Radio
1358
- style={styles.inputRadio}
1359
- checked={schedule.period.days === 1 && !schedule.period.dows}
1360
- onClick={() => {
1361
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1362
- _schedule.period.days = 1;
1363
- _schedule.period.dows = '';
1364
- this.onChange(_schedule);
1365
- }}
1366
- />
1367
- }
1368
- label={I18n.t('sch_periodEveryDay')}
1369
- />
1370
- </div>,
1371
- <div key="everyN_day">
1372
- <FormControlLabel
1373
- control={
1374
- <Radio
1375
- style={styles.inputRadio}
1376
- checked={schedule.period.days > 1}
1377
- onClick={() => {
1378
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1379
- _schedule.period.days = 2;
1380
- _schedule.period.dows = '';
1381
- this.onChange(_schedule);
1382
- }}
1383
- />
1384
- }
1385
- label={I18n.t('sch_periodEvery')}
1386
- />
1387
- {schedule.period.days > 1 && [
1388
- <Input
1389
- key="input"
1390
- value={this.state.schedule.period.days}
1391
- style={styles.inputEvery}
1392
- type="number"
1393
- inputProps={{ min: 2 }}
1394
- onChange={e => {
1395
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1396
- _schedule.period.days = parseInt(e.target.value, 10);
1397
- _schedule.period.dows = '';
1398
- this.onChange(_schedule);
1399
- }}
1400
- />,
1401
- <span
1402
- key="span"
1403
- style={{ paddingRight: 10 }}
1404
- >
1405
- {I18n.t('sch_periodDay')}
1406
- </span>,
1407
- ]}
1408
- </div>,
1409
- ];
1410
- }
1411
-
1412
- getPeriodSettingsWeekly(): JSX.Element[] | null {
1413
- if (!this.state.schedule.period.weeks) {
1414
- return null;
1415
- }
1416
- const schedule = this.state.schedule;
1417
- return [
1418
- <div
1419
- key="radios"
1420
- style={{ display: 'inline-block', verticalAlign: 'top' }}
1421
- >
1422
- <div>
1423
- <FormControlLabel
1424
- control={
1425
- <Radio
1426
- style={styles.inputRadio}
1427
- checked={schedule.period.weeks === 1}
1428
- onClick={() => {
1429
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1430
- _schedule.period.weeks = 1;
1431
- this.onChange(_schedule);
1432
- }}
1433
- />
1434
- }
1435
- label={I18n.t('sch_periodEveryWeek')}
1436
- />
1437
- </div>
1438
- <div>
1439
- <FormControlLabel
1440
- control={
1441
- <Radio
1442
- style={styles.inputRadio}
1443
- checked={schedule.period.weeks > 1}
1444
- onClick={() => {
1445
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1446
- _schedule.period.weeks = 2;
1447
- this.onChange(_schedule);
1448
- }}
1449
- />
1450
- }
1451
- label={I18n.t('sch_periodEvery')}
1452
- />
1453
- {schedule.period.weeks > 1 && [
1454
- <Input
1455
- key="input"
1456
- value={this.state.schedule.period.weeks}
1457
- style={styles.inputEvery}
1458
- type="number"
1459
- inputProps={{ min: 2 }}
1460
- onChange={e => {
1461
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1462
- _schedule.period.weeks = parseInt(e.target.value, 10);
1463
- this.onChange(_schedule);
1464
- }}
1465
- />,
1466
- <span key="text">{I18n.t('sch_periodWeek')}</span>,
1467
- ]}
1468
- </div>
1469
- </div>,
1470
- ];
1471
- }
1472
-
1473
- getPeriodSettingsDates(): JSX.Element | null {
1474
- if (!this.state.schedule.period.dates) {
1475
- return null;
1476
- }
1477
- const schedule = this.state.schedule;
1478
-
1479
- const dates = [];
1480
- for (let i = 1; i <= 31; i++) {
1481
- dates.push(i);
1482
- }
1483
-
1484
- const parsedDates = JSON.parse(schedule.period.dates);
1485
-
1486
- return (
1487
- <FormGroup
1488
- row
1489
- style={{ ...styles.inputGroup, maxWidth: 620 }}
1490
- >
1491
- <FormControlLabel
1492
- style={styles.inputDateDay}
1493
- control={
1494
- <Checkbox
1495
- style={styles.inputDateDayCheck}
1496
- checked={parsedDates.length === 31}
1497
- onChange={() => {
1498
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1499
- const _dates = [];
1500
- for (let i = 1; i <= 31; i++) {
1501
- _dates.push(i);
1502
- }
1503
- _schedule.period.dates = JSON.stringify(_dates);
1504
- this.onChange(_schedule);
1505
- }}
1506
- />
1507
- }
1508
- label={I18n.t('sch_all')}
1509
- />
1510
- <FormControlLabel
1511
- style={styles.inputDateDay}
1512
- control={
1513
- <Checkbox
1514
- style={styles.inputDateDayCheck}
1515
- checked={!parsedDates.length}
1516
- onChange={() => {
1517
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1518
- _schedule.period.dates = '[]';
1519
- this.onChange(_schedule);
1520
- }}
1521
- />
1522
- }
1523
- label={I18n.t('sch_no_one')}
1524
- />
1525
- {parsedDates.length !== 31 && !!parsedDates.length && (
1526
- <FormControlLabel
1527
- style={styles.inputDateDay}
1528
- control={
1529
- <Checkbox
1530
- style={styles.inputDateDayCheck}
1531
- checked={false}
1532
- onChange={() => {
1533
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1534
- const result = [];
1535
- const _parsedDates = JSON.parse(_schedule.period.dates);
1536
- for (let i = 1; i <= 31; i++) {
1537
- if (!_parsedDates.includes(i)) {
1538
- result.push(i);
1539
- }
1540
- }
1541
- result.sort((a, b) => a - b);
1542
- _schedule.period.dates = JSON.stringify(result);
1543
- this.onChange(_schedule);
1544
- }}
1545
- />
1546
- }
1547
- label={I18n.t('sch_invert')}
1548
- />
1549
- )}
1550
- <div />
1551
- {dates.map(i => (
1552
- <FormControlLabel
1553
- key={`date_${i}`}
1554
- style={
1555
- !i
1556
- ? {
1557
- ...styles.inputDateDay,
1558
- opacity: 0,
1559
- cursor: 'default',
1560
- userSelect: 'none',
1561
- pointerEvents: 'none',
1562
- }
1563
- : styles.inputDateDay
1564
- }
1565
- control={
1566
- <Checkbox
1567
- style={styles.inputDateDayCheck}
1568
- checked={JSON.parse(schedule.period.dates).includes(i)}
1569
- onChange={e => {
1570
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1571
- let _dates;
1572
- try {
1573
- _dates = JSON.parse(_schedule.period.dates);
1574
- } catch {
1575
- _dates = [];
1576
- }
1577
- if (e.target.checked && !_dates.includes(i)) {
1578
- _dates.push(i);
1579
- } else if (!e.target.checked && _dates.includes(i)) {
1580
- _dates.splice(_dates.indexOf(i), 1);
1581
- }
1582
- _dates.sort((a: number, b: number) => a - b);
1583
- _schedule.period.dates = JSON.stringify(_dates);
1584
- this.onChange(_schedule);
1585
- }}
1586
- />
1587
- }
1588
- label={
1589
- i < 10
1590
- ? [
1591
- <span
1592
- key="0"
1593
- style={{ opacity: 0 }}
1594
- >
1595
- 0
1596
- </span>,
1597
- <span key="num">{i}</span>,
1598
- ]
1599
- : i
1600
- }
1601
- />
1602
- ))}
1603
- </FormGroup>
1604
- );
1605
- }
1606
-
1607
- getPeriodSettingsMonthly(): JSX.Element[] | null {
1608
- if (!this.state.schedule.period.months) {
1609
- return null;
1610
- }
1611
- const schedule = this.state.schedule;
1612
- const parsedMonths = typeof schedule.period.months === 'string' ? JSON.parse(schedule.period.months) : [];
1613
-
1614
- return [
1615
- <div key="every">
1616
- <FormControlLabel
1617
- control={
1618
- <Radio
1619
- style={styles.inputRadio}
1620
- checked={typeof schedule.period.months === 'number' && schedule.period.months === 1}
1621
- onClick={() => {
1622
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1623
- _schedule.period.months = 1;
1624
- this.onChange(schedule);
1625
- }}
1626
- />
1627
- }
1628
- label={I18n.t('sch_periodEveryMonth')}
1629
- />
1630
- </div>,
1631
- <div key="everyN">
1632
- <FormControlLabel
1633
- control={
1634
- <Radio
1635
- style={styles.inputRadio}
1636
- checked={typeof schedule.period.months === 'number' && schedule.period.months > 1}
1637
- onClick={() => {
1638
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1639
- _schedule.period.months = 2;
1640
- this.onChange(_schedule);
1641
- }}
1642
- />
1643
- }
1644
- label={I18n.t('sch_periodEvery')}
1645
- />
1646
- {typeof schedule.period.months === 'number' &&
1647
- schedule.period.months > 1 && [
1648
- <Input
1649
- key="input"
1650
- value={schedule.period.months}
1651
- style={styles.inputEvery}
1652
- type="number"
1653
- inputProps={{ min: 2 }}
1654
- onChange={e => {
1655
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1656
- _schedule.period.months = parseInt(e.target.value, 10);
1657
- if (_schedule.period.months < 1) {
1658
- _schedule.period.months = 1;
1659
- }
1660
- this.onChange(_schedule);
1661
- }}
1662
- />,
1663
- <span key="text">{I18n.t('sch_periodMonth')}</span>,
1664
- ]}
1665
- </div>,
1666
- <div
1667
- key="specific"
1668
- style={{ verticalAlign: 'top' }}
1669
- >
1670
- <FormControlLabel
1671
- style={{ verticalAlign: 'top' }}
1672
- control={
1673
- <Radio
1674
- style={styles.inputRadio}
1675
- checked={typeof schedule.period.months === 'string'}
1676
- onClick={() => {
1677
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1678
- _schedule.period.months = '[1,2,3,4,5,6,7,8,9,10,11,12]';
1679
- this.onChange(_schedule);
1680
- }}
1681
- />
1682
- }
1683
- label={I18n.t('sch_periodSpecificMonths')}
1684
- />
1685
- {typeof schedule.period.months === 'string' && (
1686
- <FormGroup
1687
- row
1688
- style={styles.inputGroup}
1689
- >
1690
- <FormControlLabel
1691
- style={styles.inputDateDay}
1692
- control={
1693
- <Checkbox
1694
- style={styles.inputDateDayCheck}
1695
- checked={parsedMonths.length === 12}
1696
- onChange={() => {
1697
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1698
- const months = [];
1699
- for (let i = 1; i <= 12; i++) {
1700
- months.push(i);
1701
- }
1702
- _schedule.period.months = JSON.stringify(months);
1703
- this.onChange(_schedule);
1704
- }}
1705
- />
1706
- }
1707
- label={I18n.t('sch_all')}
1708
- />
1709
- <FormControlLabel
1710
- style={styles.inputDateDay}
1711
- control={
1712
- <Checkbox
1713
- style={styles.inputDateDayCheck}
1714
- checked={!parsedMonths.length}
1715
- onChange={() => {
1716
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1717
- _schedule.period.months = '[]';
1718
- this.onChange(_schedule);
1719
- }}
1720
- />
1721
- }
1722
- label={I18n.t('sch_no_one')}
1723
- />
1724
- {parsedMonths.length !== 12 && !!parsedMonths.length && (
1725
- <FormControlLabel
1726
- style={styles.inputDateDay}
1727
- control={
1728
- <Checkbox
1729
- style={styles.inputDateDayCheck}
1730
- checked={false}
1731
- onChange={() => {
1732
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1733
- const result = [];
1734
- const _parsedMonths = JSON.parse(_schedule.period.months);
1735
- for (let i = 1; i <= 12; i++) {
1736
- if (!_parsedMonths.includes(i)) {
1737
- result.push(i);
1738
- }
1739
- }
1740
- result.sort((a, b) => a - b);
1741
- _schedule.period.months = JSON.stringify(result);
1742
- this.onChange(_schedule);
1743
- }}
1744
- />
1745
- }
1746
- label={I18n.t('sch_invert')}
1747
- />
1748
- )}
1749
- <div />
1750
- {MONTHS.map((month, i) => (
1751
- <FormControlLabel
1752
- key={`month_${i}`}
1753
- style={styles.inputGroupElement}
1754
- control={
1755
- <Checkbox
1756
- style={styles.inputSmallCheck}
1757
- checked={
1758
- typeof schedule.period.months === 'string'
1759
- ? JSON.parse(schedule.period.months).includes(i + 1)
1760
- : schedule.period.months === i
1761
- }
1762
- onChange={e => {
1763
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1764
- let months;
1765
- try {
1766
- months = JSON.parse(_schedule.period.months);
1767
- } catch {
1768
- months = [];
1769
- }
1770
- if (e.target.checked && !months.includes(i + 1)) {
1771
- months.push(i + 1);
1772
- } else if (!e.target.checked && months.includes(i + 1)) {
1773
- months.splice(months.indexOf(i + 1), 1);
1774
- }
1775
- months.sort((a: number, b: number) => a - b);
1776
- _schedule.period.months = JSON.stringify(months);
1777
- this.onChange(_schedule);
1778
- }}
1779
- />
1780
- }
1781
- label={I18n.t(month)}
1782
- />
1783
- ))}
1784
- </FormGroup>
1785
- )}
1786
- </div>,
1787
- ];
1788
- }
1789
-
1790
- getPeriodSettingsYearly(): JSX.Element[] | null {
1791
- if (!this.state.schedule.period.years) {
1792
- return null;
1793
- }
1794
- const schedule = this.state.schedule;
1795
- return [
1796
- <div key="year">
1797
- <FormControlLabel
1798
- control={
1799
- <Radio
1800
- style={styles.inputRadio}
1801
- checked={schedule.period.years === 1}
1802
- onClick={() => {
1803
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1804
- _schedule.period.years = 1;
1805
- this.onChange(_schedule);
1806
- }}
1807
- />
1808
- }
1809
- label={I18n.t('sch_periodEveryYear')}
1810
- />
1811
- </div>,
1812
- <div key="every">
1813
- <FormControlLabel
1814
- control={
1815
- <Radio
1816
- style={styles.inputRadio}
1817
- checked={schedule.period.years > 1}
1818
- onClick={() => {
1819
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1820
- _schedule.period.years = 2;
1821
- this.onChange(_schedule);
1822
- }}
1823
- />
1824
- }
1825
- label={I18n.t('sch_periodEvery')}
1826
- />
1827
- {schedule.period.years > 1 && [
1828
- <Input
1829
- key="input"
1830
- value={this.state.schedule.period.years}
1831
- style={styles.inputEvery}
1832
- type="number"
1833
- inputProps={{ min: 2 }}
1834
- onChange={e => {
1835
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1836
- _schedule.period.years = parseInt(e.target.value, 10);
1837
- if (_schedule.period.years < 1) {
1838
- _schedule.period.years = 1;
1839
- }
1840
- this.onChange(_schedule);
1841
- }}
1842
- />,
1843
- <span key="text">{I18n.t('sch_periodYear')}</span>,
1844
- ]}
1845
- </div>,
1846
- ];
1847
- }
1848
-
1849
- static now2string(isEnd?: boolean): string {
1850
- const d = new Date();
1851
- d.setHours(0);
1852
- d.setMinutes(0);
1853
- d.setSeconds(0);
1854
- d.setMilliseconds(0);
1855
- if (isEnd) {
1856
- d.setDate(d.getDate() + 2);
1857
- d.setMilliseconds(d.getMilliseconds() - 1);
1858
- }
1859
-
1860
- return `${padding(d.getDate())}.${padding(d.getMonth() + 1)}.${padding(d.getFullYear())}`;
1861
- }
1862
-
1863
- static string2date(str: string): Date {
1864
- let parts = str.split('.'); // 31.12.2019
1865
- if (parts.length === 1) {
1866
- parts = str.split('-'); // 2018-12-31
1867
- return new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10));
1868
- }
1869
- return new Date(parseInt(parts[2], 10), parseInt(parts[1], 10) - 1, parseInt(parts[0], 10));
1870
- }
1871
-
1872
- getValidSettings(): JSX.Element {
1873
- const schedule = this.state.schedule;
1874
- // ----- from ---
1875
- return (
1876
- <div style={styles.rowDiv}>
1877
- <div style={{ ...styles.modeDiv, verticalAlign: 'middle' }}>
1878
- <span style={{ fontWeight: 'bold', paddingRight: 10 }}>{I18n.t('sch_valid')}</span>
1879
- <span>{I18n.t('sch_validFrom')}</span>
1880
- </div>
1881
- <div style={styles.settingsDiv}>
1882
- <TextField
1883
- variant="standard"
1884
- style={{ ...styles.inputDate, marginRight: 10 }}
1885
- key="exactTimeFrom"
1886
- inputRef={this.refFrom}
1887
- defaultValue={string2USdate(schedule.valid.from)}
1888
- type="date"
1889
- // inputComponent={TextDate}
1890
- onChange={e => {
1891
- this.timerFrom && clearTimeout(this.timerFrom);
1892
-
1893
- if (this.refFrom.current) {
1894
- this.refFrom.current.style.background = '#ff000030';
1895
- }
1896
-
1897
- this.timerFrom = setTimeout(
1898
- value => {
1899
- this.timerFrom = null;
1900
- if (this.refFrom.current) {
1901
- this.refFrom.current.style.background = '';
1902
- }
1903
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1904
- const date = Schedule.string2date(value);
1905
- if (date.toString() !== 'Invalid Date') {
1906
- _schedule.valid.from = `${padding(date.getDate())}.${padding(date.getMonth() + 1)}.${date.getFullYear()}`;
1907
- this.onChange(_schedule);
1908
- }
1909
- },
1910
- 1500,
1911
- e.target.value,
1912
- );
1913
- }}
1914
- slotProps={{
1915
- inputLabel: { shrink: true },
1916
- }}
1917
- margin="normal"
1918
- />
1919
- <FormControlLabel
1920
- control={
1921
- <Checkbox
1922
- style={styles.inputRadio}
1923
- checked={!!schedule.valid.to}
1924
- onClick={() => {
1925
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1926
- _schedule.valid.to = _schedule.valid.to ? '' : Schedule.now2string(true);
1927
- this.onChange(_schedule);
1928
- }}
1929
- />
1930
- }
1931
- label={I18n.t('sch_validTo')}
1932
- />
1933
- {!!schedule.valid.to && (
1934
- <TextField
1935
- variant="standard"
1936
- inputRef={this.refTo}
1937
- style={{ ...styles.inputDate, marginRight: 10 }}
1938
- key="exactTimeFrom"
1939
- type="date"
1940
- defaultValue={string2USdate(schedule.valid.to)}
1941
- // inputComponent={TextDate}
1942
- onChange={e => {
1943
- this.timerTo && clearTimeout(this.timerTo);
1944
-
1945
- if (this.refTo.current) {
1946
- this.refTo.current.style.background = '#ff000030';
1947
- }
1948
- this.timerTo = setTimeout(
1949
- value => {
1950
- this.timerTo = null;
1951
- if (this.refTo.current) {
1952
- this.refTo.current.style.background = '';
1953
- }
1954
- const _schedule = JSON.parse(JSON.stringify(this.state.schedule));
1955
- const date = Schedule.string2date(value);
1956
- if (date.toString() !== 'Invalid Date') {
1957
- _schedule.valid.to = `${padding(date.getDate())}.${padding(date.getMonth() + 1)}.${date.getFullYear()}`;
1958
- this.onChange(_schedule);
1959
- }
1960
- },
1961
- 1500,
1962
- e.target.value,
1963
- );
1964
- }}
1965
- slotProps={{
1966
- inputLabel: { shrink: true },
1967
- }}
1968
- margin="normal"
1969
- />
1970
- )}
1971
- </div>
1972
- </div>
1973
- );
1974
- }
1975
-
1976
- render(): JSX.Element {
1977
- return (
1978
- <div style={{ height: 'calc(100% - 48px)', width: '100%', overflow: 'hidden' }}>
1979
- <div>{this.state.desc}</div>
1980
- <div style={styles.scrollWindow}>
1981
- <h5>{I18n.t('sch_time')}</h5>
1982
- {this.getTimePeriodElements()}
1983
- {this.getTimeExactElements()}
1984
- {Schedule.getDivider()}
1985
- <h5>{I18n.t('sch_period')}</h5>
1986
- {this.getPeriodModes()}
1987
- {!this.state.schedule.period.once && Schedule.getDivider()}
1988
- {!this.state.schedule.period.once && this.getValidSettings()}
1989
- </div>
1990
- </div>
1991
- );
1992
- }
1993
- }
1994
-
1995
- export default Schedule;