@iobroker/json-config 1.0.0
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.
- package/LICENSE +21 -0
- package/build/JsonConfig.d.ts +22 -0
- package/build/JsonConfig.js +535 -0
- package/build/JsonConfig.js.map +1 -0
- package/build/JsonConfigComponent/ChipInput.d.ts +12 -0
- package/build/JsonConfigComponent/ChipInput.js +595 -0
- package/build/JsonConfigComponent/ChipInput.js.map +1 -0
- package/build/JsonConfigComponent/ConfigAccordion.d.ts +15 -0
- package/build/JsonConfigComponent/ConfigAccordion.js +185 -0
- package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -0
- package/build/JsonConfigComponent/ConfigAlive.d.ts +10 -0
- package/build/JsonConfigComponent/ConfigAlive.js +63 -0
- package/build/JsonConfigComponent/ConfigAlive.js.map +1 -0
- package/build/JsonConfigComponent/ConfigAutocomplete.d.ts +37 -0
- package/build/JsonConfigComponent/ConfigAutocomplete.js +69 -0
- package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -0
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.d.ts +17 -0
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js +127 -0
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCRON.d.ts +15 -0
- package/build/JsonConfigComponent/ConfigCRON.js +55 -0
- package/build/JsonConfigComponent/ConfigCRON.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCertCollection.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigCertCollection.js +50 -0
- package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCertificateSelect.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigCertificateSelect.js +59 -0
- package/build/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCertificates.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigCertificates.js +104 -0
- package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCheckLicense.d.ts +3 -0
- package/build/JsonConfigComponent/ConfigCheckLicense.js +546 -0
- package/build/JsonConfigComponent/ConfigCheckLicense.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCheckbox.d.ts +15 -0
- package/build/JsonConfigComponent/ConfigCheckbox.js +36 -0
- package/build/JsonConfigComponent/ConfigCheckbox.js.map +1 -0
- package/build/JsonConfigComponent/ConfigChip.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigChip.js +67 -0
- package/build/JsonConfigComponent/ConfigChip.js.map +1 -0
- package/build/JsonConfigComponent/ConfigColor.d.ts +22 -0
- package/build/JsonConfigComponent/ConfigColor.js +57 -0
- package/build/JsonConfigComponent/ConfigColor.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCoordinates.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigCoordinates.js +146 -0
- package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -0
- package/build/JsonConfigComponent/ConfigCustom.d.ts +26 -0
- package/build/JsonConfigComponent/ConfigCustom.js +195 -0
- package/build/JsonConfigComponent/ConfigCustom.js.map +1 -0
- package/build/JsonConfigComponent/ConfigDatePicker.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigDatePicker.js +39 -0
- package/build/JsonConfigComponent/ConfigDatePicker.js.map +1 -0
- package/build/JsonConfigComponent/ConfigDeviceManager.d.ts +6 -0
- package/build/JsonConfigComponent/ConfigDeviceManager.js +14 -0
- package/build/JsonConfigComponent/ConfigDeviceManager.js.map +1 -0
- package/build/JsonConfigComponent/ConfigFile.d.ts +15 -0
- package/build/JsonConfigComponent/ConfigFile.js +131 -0
- package/build/JsonConfigComponent/ConfigFile.js.map +1 -0
- package/build/JsonConfigComponent/ConfigFileSelector.d.ts +3 -0
- package/build/JsonConfigComponent/ConfigFileSelector.js +434 -0
- package/build/JsonConfigComponent/ConfigFileSelector.js.map +1 -0
- package/build/JsonConfigComponent/ConfigFunc.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigFunc.js +56 -0
- package/build/JsonConfigComponent/ConfigFunc.js.map +1 -0
- package/build/JsonConfigComponent/ConfigGeneric.d.ts +95 -0
- package/build/JsonConfigComponent/ConfigGeneric.js +632 -0
- package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -0
- package/build/JsonConfigComponent/ConfigIP.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigIP.js +64 -0
- package/build/JsonConfigComponent/ConfigIP.js.map +1 -0
- package/build/JsonConfigComponent/ConfigImageSendTo.d.ts +10 -0
- package/build/JsonConfigComponent/ConfigImageSendTo.js +62 -0
- package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -0
- package/build/JsonConfigComponent/ConfigImageUpload.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigImageUpload.js +91 -0
- package/build/JsonConfigComponent/ConfigImageUpload.js.map +1 -0
- package/build/JsonConfigComponent/ConfigInstanceSelect.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigInstanceSelect.js +133 -0
- package/build/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -0
- package/build/JsonConfigComponent/ConfigInterface.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigInterface.js +74 -0
- package/build/JsonConfigComponent/ConfigInterface.js.map +1 -0
- package/build/JsonConfigComponent/ConfigJsonEditor.d.ts +13 -0
- package/build/JsonConfigComponent/ConfigJsonEditor.js +59 -0
- package/build/JsonConfigComponent/ConfigJsonEditor.js.map +1 -0
- package/build/JsonConfigComponent/ConfigLanguage.d.ts +7 -0
- package/build/JsonConfigComponent/ConfigLanguage.js +105 -0
- package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -0
- package/build/JsonConfigComponent/ConfigLicense.d.ts +24 -0
- package/build/JsonConfigComponent/ConfigLicense.js +95 -0
- package/build/JsonConfigComponent/ConfigLicense.js.map +1 -0
- package/build/JsonConfigComponent/ConfigNumber.d.ts +17 -0
- package/build/JsonConfigComponent/ConfigNumber.js +114 -0
- package/build/JsonConfigComponent/ConfigNumber.js.map +1 -0
- package/build/JsonConfigComponent/ConfigObjectId.d.ts +17 -0
- package/build/JsonConfigComponent/ConfigObjectId.js +59 -0
- package/build/JsonConfigComponent/ConfigObjectId.js.map +1 -0
- package/build/JsonConfigComponent/ConfigPanel.d.ts +3 -0
- package/build/JsonConfigComponent/ConfigPanel.js +271 -0
- package/build/JsonConfigComponent/ConfigPanel.js.map +1 -0
- package/build/JsonConfigComponent/ConfigPassword.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigPassword.js +105 -0
- package/build/JsonConfigComponent/ConfigPassword.js.map +1 -0
- package/build/JsonConfigComponent/ConfigPattern.d.ts +21 -0
- package/build/JsonConfigComponent/ConfigPattern.js +32 -0
- package/build/JsonConfigComponent/ConfigPattern.js.map +1 -0
- package/build/JsonConfigComponent/ConfigPort.d.ts +3 -0
- package/build/JsonConfigComponent/ConfigPort.js +174 -0
- package/build/JsonConfigComponent/ConfigPort.js.map +1 -0
- package/build/JsonConfigComponent/ConfigRoom.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigRoom.js +56 -0
- package/build/JsonConfigComponent/ConfigRoom.js.map +1 -0
- package/build/JsonConfigComponent/ConfigSelect.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigSelect.js +90 -0
- package/build/JsonConfigComponent/ConfigSelect.js.map +1 -0
- package/build/JsonConfigComponent/ConfigSelectSendTo.d.ts +17 -0
- package/build/JsonConfigComponent/ConfigSelectSendTo.js +175 -0
- package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -0
- package/build/JsonConfigComponent/ConfigSendto.d.ts +24 -0
- package/build/JsonConfigComponent/ConfigSendto.js +290 -0
- package/build/JsonConfigComponent/ConfigSendto.js.map +1 -0
- package/build/JsonConfigComponent/ConfigSetState.d.ts +18 -0
- package/build/JsonConfigComponent/ConfigSetState.js +93 -0
- package/build/JsonConfigComponent/ConfigSetState.js.map +1 -0
- package/build/JsonConfigComponent/ConfigSlider.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigSlider.js +62 -0
- package/build/JsonConfigComponent/ConfigSlider.js.map +1 -0
- package/build/JsonConfigComponent/ConfigStaticDivider.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigStaticDivider.js +39 -0
- package/build/JsonConfigComponent/ConfigStaticDivider.js.map +1 -0
- package/build/JsonConfigComponent/ConfigStaticHeader.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigStaticHeader.js +45 -0
- package/build/JsonConfigComponent/ConfigStaticHeader.js.map +1 -0
- package/build/JsonConfigComponent/ConfigStaticImage.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigStaticImage.js +36 -0
- package/build/JsonConfigComponent/ConfigStaticImage.js.map +1 -0
- package/build/JsonConfigComponent/ConfigStaticText.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigStaticText.js +51 -0
- package/build/JsonConfigComponent/ConfigStaticText.js.map +1 -0
- package/build/JsonConfigComponent/ConfigTable.d.ts +3 -0
- package/build/JsonConfigComponent/ConfigTable.js +670 -0
- package/build/JsonConfigComponent/ConfigTable.js.map +1 -0
- package/build/JsonConfigComponent/ConfigTabs.d.ts +34 -0
- package/build/JsonConfigComponent/ConfigTabs.js +90 -0
- package/build/JsonConfigComponent/ConfigTabs.js.map +1 -0
- package/build/JsonConfigComponent/ConfigText.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigText.js +105 -0
- package/build/JsonConfigComponent/ConfigText.js.map +1 -0
- package/build/JsonConfigComponent/ConfigTextSendTo.d.ts +10 -0
- package/build/JsonConfigComponent/ConfigTextSendTo.js +76 -0
- package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -0
- package/build/JsonConfigComponent/ConfigTimePicker.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigTimePicker.js +37 -0
- package/build/JsonConfigComponent/ConfigTimePicker.js.map +1 -0
- package/build/JsonConfigComponent/ConfigTopic.d.ts +17 -0
- package/build/JsonConfigComponent/ConfigTopic.js +61 -0
- package/build/JsonConfigComponent/ConfigTopic.js.map +1 -0
- package/build/JsonConfigComponent/ConfigUUID.d.ts +15 -0
- package/build/JsonConfigComponent/ConfigUUID.js +31 -0
- package/build/JsonConfigComponent/ConfigUUID.js.map +1 -0
- package/build/JsonConfigComponent/ConfigUser.d.ts +14 -0
- package/build/JsonConfigComponent/ConfigUser.js +70 -0
- package/build/JsonConfigComponent/ConfigUser.js.map +1 -0
- package/build/JsonConfigComponent/index.d.ts +26 -0
- package/build/JsonConfigComponent/index.js +312 -0
- package/build/JsonConfigComponent/index.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/AdminConnection.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/AdminConnection.js +3 -0
- package/build/JsonConfigComponent/wrapper/AdminConnection.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/ColorPicker.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Components/ColorPicker.js +3 -0
- package/build/JsonConfigComponent/wrapper/Components/ColorPicker.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/CustomModal.d.ts +3 -0
- package/build/JsonConfigComponent/wrapper/Components/CustomModal.js +87 -0
- package/build/JsonConfigComponent/wrapper/Components/CustomModal.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/Editor.d.ts +14 -0
- package/build/JsonConfigComponent/wrapper/Components/Editor.js +43 -0
- package/build/JsonConfigComponent/wrapper/Components/Editor.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/Icon.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Components/Icon.js +3 -0
- package/build/JsonConfigComponent/wrapper/Components/Icon.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.js +3 -0
- package/build/JsonConfigComponent/wrapper/Components/TextWithIcon.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/UploadImage.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Components/UploadImage.js +3 -0
- package/build/JsonConfigComponent/wrapper/Components/UploadImage.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Components/Utils.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Components/Utils.js +3 -0
- package/build/JsonConfigComponent/wrapper/Components/Utils.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Confirm.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Cron.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Cron.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Cron.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Error.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Error.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Error.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Message.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Message.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/Message.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectFile.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.js +3 -0
- package/build/JsonConfigComponent/wrapper/Dialogs/SelectID.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/i18n.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/i18n.js +3 -0
- package/build/JsonConfigComponent/wrapper/i18n.js.map +1 -0
- package/build/JsonConfigComponent/wrapper/icons/IconCopy.d.ts +2 -0
- package/build/JsonConfigComponent/wrapper/icons/IconCopy.js +3 -0
- package/build/JsonConfigComponent/wrapper/icons/IconCopy.js.map +1 -0
- package/build/Utils.d.ts +376 -0
- package/build/Utils.js +1595 -0
- package/build/Utils.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/package.json +17 -0
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
import React, { createRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { /* lighten, */ withStyles } from '@mui/styles';
|
|
4
|
+
import Dropzone from 'react-dropzone';
|
|
5
|
+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, InputAdornment, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TableSortLabel, TextField, Toolbar, Tooltip, Typography, FormHelperText, } from '@mui/material';
|
|
6
|
+
import { Add as AddIcon, Delete as DeleteIcon, Close as CloseIcon, ArrowUpward as UpIcon, ArrowDownward as DownIcon, FilterAlt as IconFilterOn, FilterAltOff as IconFilterOff, ContentCopy as CopyContentIcon, Download as ExportIcon, Warning as ErrorIcon, UploadFile as ImportIcon, Close as IconClose, } from '@mui/icons-material';
|
|
7
|
+
import I18n from './wrapper/i18n';
|
|
8
|
+
import Utils from './wrapper/Components/Utils';
|
|
9
|
+
import ConfigGeneric from './ConfigGeneric';
|
|
10
|
+
// eslint-disable-next-line import/no-cycle
|
|
11
|
+
import ConfigPanel from './ConfigPanel';
|
|
12
|
+
const MAX_SIZE = 1024 * 1024; // 1MB
|
|
13
|
+
const styles = theme => ({
|
|
14
|
+
fullWidth: {
|
|
15
|
+
width: '100%',
|
|
16
|
+
},
|
|
17
|
+
root: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
},
|
|
20
|
+
paper: {
|
|
21
|
+
width: '100%',
|
|
22
|
+
marginBottom: theme.spacing(2),
|
|
23
|
+
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
|
24
|
+
},
|
|
25
|
+
headerText: {
|
|
26
|
+
width: '100%',
|
|
27
|
+
},
|
|
28
|
+
table: {
|
|
29
|
+
minWidth: 750,
|
|
30
|
+
},
|
|
31
|
+
visuallyHidden: {
|
|
32
|
+
border: 0,
|
|
33
|
+
clip: 'rect(0 0 0 0)',
|
|
34
|
+
height: 1,
|
|
35
|
+
margin: -1,
|
|
36
|
+
overflow: 'hidden',
|
|
37
|
+
padding: 0,
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
top: 20,
|
|
40
|
+
width: 1,
|
|
41
|
+
},
|
|
42
|
+
label: {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
justifyContent: 'space-between',
|
|
45
|
+
},
|
|
46
|
+
highlight: theme.palette.mode === 'light'
|
|
47
|
+
? {
|
|
48
|
+
color: theme.palette.secondary.main,
|
|
49
|
+
// backgroundColor: lighten(theme.palette.secondary.light, 0.85),
|
|
50
|
+
}
|
|
51
|
+
: {
|
|
52
|
+
color: theme.palette.text.primary,
|
|
53
|
+
backgroundColor: theme.palette.secondary.dark,
|
|
54
|
+
},
|
|
55
|
+
title: {
|
|
56
|
+
flex: '1 1 100%',
|
|
57
|
+
},
|
|
58
|
+
rootTool: {
|
|
59
|
+
paddingLeft: theme.spacing(2),
|
|
60
|
+
paddingRight: theme.spacing(1),
|
|
61
|
+
},
|
|
62
|
+
silver: {
|
|
63
|
+
opacity: 0.2,
|
|
64
|
+
},
|
|
65
|
+
flex: {
|
|
66
|
+
display: 'flex',
|
|
67
|
+
alignItems: 'baseline',
|
|
68
|
+
},
|
|
69
|
+
filteredOut: {
|
|
70
|
+
padding: 10,
|
|
71
|
+
display: 'flex',
|
|
72
|
+
textAlign: 'center',
|
|
73
|
+
},
|
|
74
|
+
buttonEmpty: {
|
|
75
|
+
width: 34,
|
|
76
|
+
display: 'inline-block',
|
|
77
|
+
},
|
|
78
|
+
buttonCell: {
|
|
79
|
+
whiteSpace: 'nowrap',
|
|
80
|
+
},
|
|
81
|
+
dropZone: {
|
|
82
|
+
width: '100%',
|
|
83
|
+
height: 100,
|
|
84
|
+
position: 'relative',
|
|
85
|
+
},
|
|
86
|
+
dropZoneEmpty: {},
|
|
87
|
+
uploadDiv: {
|
|
88
|
+
position: 'relative',
|
|
89
|
+
width: '100%',
|
|
90
|
+
height: 300,
|
|
91
|
+
opacity: 0.9,
|
|
92
|
+
marginTop: 30,
|
|
93
|
+
cursor: 'pointer',
|
|
94
|
+
outline: 'none',
|
|
95
|
+
},
|
|
96
|
+
uploadDivDragging: {
|
|
97
|
+
opacity: 1,
|
|
98
|
+
background: 'rgba(128,255,128,0.1)',
|
|
99
|
+
},
|
|
100
|
+
image: {
|
|
101
|
+
objectFit: 'contain',
|
|
102
|
+
margin: 'auto',
|
|
103
|
+
display: 'flex',
|
|
104
|
+
width: '100%',
|
|
105
|
+
height: '100%',
|
|
106
|
+
},
|
|
107
|
+
uploadCenterDiv: {
|
|
108
|
+
margin: 5,
|
|
109
|
+
border: '3px dashed grey',
|
|
110
|
+
borderRadius: 5,
|
|
111
|
+
width: 'calc(100% - 10px)',
|
|
112
|
+
height: 'calc(100% - 10px)',
|
|
113
|
+
minHeight: 300,
|
|
114
|
+
position: 'relative',
|
|
115
|
+
display: 'flex',
|
|
116
|
+
},
|
|
117
|
+
uploadCenterIcon: {
|
|
118
|
+
paddingTop: 10,
|
|
119
|
+
width: 48,
|
|
120
|
+
height: 48,
|
|
121
|
+
},
|
|
122
|
+
uploadCenterText: {
|
|
123
|
+
fontSize: 16,
|
|
124
|
+
},
|
|
125
|
+
uploadCenterTextAndIcon: {
|
|
126
|
+
textAlign: 'center',
|
|
127
|
+
position: 'absolute',
|
|
128
|
+
top: 0,
|
|
129
|
+
bottom: 0,
|
|
130
|
+
left: 0,
|
|
131
|
+
right: 0,
|
|
132
|
+
display: 'flex',
|
|
133
|
+
flexDirection: 'column',
|
|
134
|
+
alignItems: 'center',
|
|
135
|
+
justifyContent: 'center',
|
|
136
|
+
},
|
|
137
|
+
buttonRemoveWrapper: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
zIndex: 222,
|
|
140
|
+
right: 0,
|
|
141
|
+
},
|
|
142
|
+
error: {
|
|
143
|
+
border: '2px solid red',
|
|
144
|
+
boxSizing: 'border-box',
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
function objectToArray(object, nameOfFirstAttr, nameOfSecondAttr) {
|
|
148
|
+
nameOfFirstAttr = nameOfFirstAttr || 'key';
|
|
149
|
+
const array = [];
|
|
150
|
+
Object.keys(object).forEach(key => {
|
|
151
|
+
const item = {};
|
|
152
|
+
item[nameOfFirstAttr] = key;
|
|
153
|
+
if (nameOfSecondAttr) {
|
|
154
|
+
item[nameOfSecondAttr] = object[key];
|
|
155
|
+
array.push(item);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
array.push(Object.assign(item, object[key]));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return array;
|
|
162
|
+
}
|
|
163
|
+
function arrayToObject(array, nameOfFirstAttr, nameOfSecondAttr) {
|
|
164
|
+
nameOfFirstAttr = nameOfFirstAttr || 'key';
|
|
165
|
+
const object = {};
|
|
166
|
+
array.forEach(row => {
|
|
167
|
+
let key = row[nameOfFirstAttr];
|
|
168
|
+
if (key === null || key === undefined) {
|
|
169
|
+
key = '';
|
|
170
|
+
}
|
|
171
|
+
delete row[nameOfFirstAttr];
|
|
172
|
+
if (nameOfSecondAttr) {
|
|
173
|
+
object[key] = row[nameOfSecondAttr];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
object[key] = row;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return object;
|
|
180
|
+
}
|
|
181
|
+
class ConfigTable extends ConfigGeneric {
|
|
182
|
+
constructor(props) {
|
|
183
|
+
super(props);
|
|
184
|
+
this.filterRefs = {};
|
|
185
|
+
this.props.schema.items = this.props.schema.items || [];
|
|
186
|
+
this.props.schema.items.forEach(el => {
|
|
187
|
+
if (el.filter) {
|
|
188
|
+
this.filterRefs[el.attr] = createRef();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* React lifecycle hook, called once component is mounted
|
|
194
|
+
* @return {Promise<void>}
|
|
195
|
+
*/
|
|
196
|
+
async componentDidMount() {
|
|
197
|
+
super.componentDidMount();
|
|
198
|
+
let value = ConfigGeneric.getValue(this.props.data, this.props.attr) || [];
|
|
199
|
+
// if the list is given as an object
|
|
200
|
+
if (this.props.schema.objKeyName) {
|
|
201
|
+
value = objectToArray(value, this.props.schema.objKeyName, this.props.schema.objValueName);
|
|
202
|
+
}
|
|
203
|
+
if (!Array.isArray(value)) {
|
|
204
|
+
value = [];
|
|
205
|
+
}
|
|
206
|
+
this.setState({
|
|
207
|
+
value,
|
|
208
|
+
visibleValue: null,
|
|
209
|
+
orderBy: /* this.props.schema.items.length ? this.props.schema.items[0].attr : */ '',
|
|
210
|
+
order: 'asc',
|
|
211
|
+
iteration: 0,
|
|
212
|
+
filterOn: [],
|
|
213
|
+
}, () => this.validateUniqueProps());
|
|
214
|
+
}
|
|
215
|
+
componentWillUnmount() {
|
|
216
|
+
this.typingTimer && clearTimeout(this.typingTimer);
|
|
217
|
+
this.typingTimer = null;
|
|
218
|
+
super.componentWillUnmount();
|
|
219
|
+
}
|
|
220
|
+
itemTable(attrItem, data, idx) {
|
|
221
|
+
const { value } = this.state;
|
|
222
|
+
const { schema } = this.props;
|
|
223
|
+
const schemaForAttribute = schema.items && schema.items.find(el => el.attr === attrItem);
|
|
224
|
+
if (!schemaForAttribute) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const schemaItem = {
|
|
228
|
+
items: {
|
|
229
|
+
[attrItem]: schemaForAttribute,
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
return React.createElement(ConfigPanel, { index: idx + this.state.iteration, arrayIndex: idx, changed: this.props.changed, globalData: this.props.data, socket: this.props.socket, adapterName: this.props.adapterName, instance: this.props.instance, common: this.props.common, alive: this.props.alive, themeType: this.props.themeType, themeName: this.props.themeName, data: data, table: true, custom: true, schema: schemaItem, systemConfig: this.props.systemConfig, originalData: this.props.originalData, customs: this.props.customs, onChange: (attr, valueChange) => {
|
|
233
|
+
const newObj = JSON.parse(JSON.stringify(value));
|
|
234
|
+
newObj[idx][attr] = valueChange;
|
|
235
|
+
this.setState({ value: newObj }, () => {
|
|
236
|
+
this.validateUniqueProps();
|
|
237
|
+
this.onChangeWrapper(newObj, true);
|
|
238
|
+
});
|
|
239
|
+
}, onError: (error, attr) => this.onError(error, attr) });
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validate that columns configured in `uniqueColumns` have unique values
|
|
243
|
+
*/
|
|
244
|
+
validateUniqueProps() {
|
|
245
|
+
if (!this.props.schema.uniqueColumns) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
for (const uniqueCol of this.props.schema.uniqueColumns) {
|
|
249
|
+
/** @type {string[]} */
|
|
250
|
+
const allVals = [];
|
|
251
|
+
const found = this.state.value.find(entry => {
|
|
252
|
+
const val = entry[uniqueCol];
|
|
253
|
+
if (allVals.includes(val)) {
|
|
254
|
+
this.onError(uniqueCol, 'is not unique');
|
|
255
|
+
this.setState({ errorMessage: I18n.t('Non-allowed duplicate entry "%s" in column "%s"', val, uniqueCol) });
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
allVals.push(val);
|
|
259
|
+
return false;
|
|
260
|
+
});
|
|
261
|
+
if (!found) {
|
|
262
|
+
this.onError(uniqueCol, null);
|
|
263
|
+
this.setState({ errorMessage: '' });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
static descendingComparator(a, b, orderBy) {
|
|
268
|
+
if (b[orderBy] < a[orderBy]) {
|
|
269
|
+
return -1;
|
|
270
|
+
}
|
|
271
|
+
if (b[orderBy] > a[orderBy]) {
|
|
272
|
+
return 1;
|
|
273
|
+
}
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
static getComparator(order, orderBy) {
|
|
277
|
+
return order === 'desc'
|
|
278
|
+
? (a, b) => ConfigTable.descendingComparator(a, b, orderBy)
|
|
279
|
+
: (a, b) => -ConfigTable.descendingComparator(a, b, orderBy);
|
|
280
|
+
}
|
|
281
|
+
handleRequestSort = (property, orderCheck = false) => {
|
|
282
|
+
const { order, orderBy } = this.state;
|
|
283
|
+
if (orderBy) {
|
|
284
|
+
const isAsc = orderBy === property && order === 'asc';
|
|
285
|
+
const newOrder = orderCheck ? order : (isAsc ? 'desc' : 'asc');
|
|
286
|
+
const newValue = this.stableSort(newOrder, property);
|
|
287
|
+
this.setState({ order: newOrder, orderBy: property, iteration: this.state.iteration + 10000 }, () => this.applyFilter(false, newValue));
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
stableSort = (order, orderBy) => {
|
|
291
|
+
const { value } = this.state;
|
|
292
|
+
const comparator = ConfigTable.getComparator(order, orderBy);
|
|
293
|
+
const stabilizedThis = value.map((el, index) => [el, index]);
|
|
294
|
+
stabilizedThis.sort((a, b) => {
|
|
295
|
+
const order_ = comparator(a[0], b[0]);
|
|
296
|
+
if (order_ !== 0) {
|
|
297
|
+
return order_;
|
|
298
|
+
}
|
|
299
|
+
return a[1] - b[1];
|
|
300
|
+
});
|
|
301
|
+
return stabilizedThis.map(el => el[0]);
|
|
302
|
+
};
|
|
303
|
+
enhancedTableHead(buttonsWidth, doAnyFilterSet) {
|
|
304
|
+
const { schema, classes } = this.props;
|
|
305
|
+
const { order, orderBy } = this.state;
|
|
306
|
+
return React.createElement(TableHead, null,
|
|
307
|
+
React.createElement(TableRow, null,
|
|
308
|
+
schema.items && schema.items.map((headCell, i) => React.createElement(TableCell, { style: { width: typeof headCell.width === 'string' && headCell.width.endsWith('%') ? headCell.width : headCell.width }, key: `${headCell.attr}_${i}`, align: "left", sortDirection: orderBy === headCell.attr ? order : false },
|
|
309
|
+
React.createElement("div", { className: classes.flex, style: schema.showFirstAddOnTop ? { flexDirection: 'column' } : undefined },
|
|
310
|
+
!i && !schema.noDelete ? React.createElement(Tooltip, { title: doAnyFilterSet ? I18n.t('ra_Cannot add items with set filter') : I18n.t('ra_Add row') },
|
|
311
|
+
React.createElement("span", null,
|
|
312
|
+
React.createElement(IconButton, { size: "small", color: "primary", disabled: !!doAnyFilterSet && !this.props.schema.allowAddByFilter, onClick: this.onAdd },
|
|
313
|
+
React.createElement(AddIcon, null)))) : null,
|
|
314
|
+
headCell.sort && React.createElement(TableSortLabel, { active: true, className: Utils.clsx(orderBy !== headCell.attr && classes.silver), direction: orderBy === headCell.attr ? order : 'asc', onClick: () => this.handleRequestSort(headCell.attr) }),
|
|
315
|
+
headCell.filter && this.state.filterOn.includes(headCell.attr) ?
|
|
316
|
+
React.createElement(TextField, { variant: "standard", ref: this.filterRefs[headCell.attr], onChange: () => this.applyFilter(), title: I18n.t('ra_You can filter entries by entering here some text'), InputProps: {
|
|
317
|
+
endAdornment: this.filterRefs[headCell.attr]?.current?.children[0]?.children[0]?.value && React.createElement(InputAdornment, { position: "end" },
|
|
318
|
+
React.createElement(IconButton, { size: "small", onClick: () => {
|
|
319
|
+
this.filterRefs[headCell.attr].current.children[0].children[0].value = '';
|
|
320
|
+
this.applyFilter();
|
|
321
|
+
} },
|
|
322
|
+
React.createElement(CloseIcon, null))),
|
|
323
|
+
}, fullWidth: true, placeholder: this.getText(headCell.title) })
|
|
324
|
+
: React.createElement("span", { className: this.props.classes.headerText }, this.getText(headCell.title)),
|
|
325
|
+
headCell.filter ? React.createElement(IconButton, { title: I18n.t('ra_Show/hide filter input'), size: "small", onClick: () => {
|
|
326
|
+
const filterOn = [...this.state.filterOn];
|
|
327
|
+
const pos = this.state.filterOn.indexOf(headCell.attr);
|
|
328
|
+
if (pos === -1) {
|
|
329
|
+
filterOn.push(headCell.attr);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
filterOn.splice(pos, 1);
|
|
333
|
+
}
|
|
334
|
+
this.setState({ filterOn }, () => {
|
|
335
|
+
if (pos && this.filterRefs[headCell.attr].current.children[0].children[0].value) {
|
|
336
|
+
this.filterRefs[headCell.attr].current.children[0].children[0].value = '';
|
|
337
|
+
this.applyFilter();
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
} }, this.state.filterOn.includes(headCell.attr) ? React.createElement(IconFilterOff, null) : React.createElement(IconFilterOn, null)) : null))),
|
|
341
|
+
!schema.noDelete && React.createElement(TableCell, { style: {
|
|
342
|
+
paddingLeft: 20, paddingRight: 20, width: buttonsWidth, textAlign: 'right',
|
|
343
|
+
}, padding: "checkbox" },
|
|
344
|
+
schema.import ? React.createElement(IconButton, { style: { marginRight: 10 }, size: "small", onClick: () => this.setState({ showImportDialog: true }), title: I18n.t('ra_import data from %s file', 'CSV') },
|
|
345
|
+
React.createElement(ImportIcon, null)) : null,
|
|
346
|
+
schema.export ? React.createElement(IconButton, { style: { marginRight: 10 }, size: "small", onClick: () => this.onExport(), title: I18n.t('ra_Export data to %s file', 'CSV') },
|
|
347
|
+
React.createElement(ExportIcon, null)) : null,
|
|
348
|
+
React.createElement(IconButton, { disabled: true, size: "small" },
|
|
349
|
+
React.createElement(DeleteIcon, null)))));
|
|
350
|
+
}
|
|
351
|
+
onDelete = index => () => {
|
|
352
|
+
const newValue = JSON.parse(JSON.stringify(this.state.value));
|
|
353
|
+
newValue.splice(index, 1);
|
|
354
|
+
this.setState({ value: newValue, iteration: this.state.iteration + 10_000 }, () => this.applyFilter(false, null, () => this.onChangeWrapper(newValue)));
|
|
355
|
+
};
|
|
356
|
+
onExport() {
|
|
357
|
+
const { schema } = this.props;
|
|
358
|
+
const { value } = this.state;
|
|
359
|
+
const cols = schema.items.map(it => it.attr);
|
|
360
|
+
const lines = [cols.join(';')];
|
|
361
|
+
value.forEach(row => {
|
|
362
|
+
const line = [];
|
|
363
|
+
schema.items.forEach(it => {
|
|
364
|
+
if (row[it.attr].includes(';')) {
|
|
365
|
+
line.push(`"${row[it.attr]}"`);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
line.push(row[it.attr]);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
lines.push(line.join(';'));
|
|
372
|
+
});
|
|
373
|
+
const el = document.createElement('a');
|
|
374
|
+
el.setAttribute('href', `data:text/csv;charset=utf-8,${encodeURIComponent(lines.join('\n'))}`);
|
|
375
|
+
const now = new Date();
|
|
376
|
+
el.setAttribute('download', `${now.getFullYear()}_${(now.getMonth() + 1).toString().padStart(2, '0')}_${now.getDate().toString().padStart(2, '0')}_${this.props.adapterName}.${this.props.instance}_${this.props.attr}.csv`);
|
|
377
|
+
el.style.display = 'none';
|
|
378
|
+
document.body.appendChild(el);
|
|
379
|
+
el.click();
|
|
380
|
+
document.body.removeChild(el);
|
|
381
|
+
}
|
|
382
|
+
onImport(text) {
|
|
383
|
+
const lines = text.split('\n').map(line => line.replace('\r', '').trim());
|
|
384
|
+
// the first line is header
|
|
385
|
+
const { schema } = this.props;
|
|
386
|
+
const header = lines.shift().split(';').filter(it => it && schema.items.find(it2 => it2.attr === it));
|
|
387
|
+
const values = [];
|
|
388
|
+
lines.forEach(line => {
|
|
389
|
+
const parts = line.split(';');
|
|
390
|
+
const obj = {};
|
|
391
|
+
for (let p = 0; p < parts.length; p++) {
|
|
392
|
+
let value = parts[p];
|
|
393
|
+
if (value.startsWith('"')) {
|
|
394
|
+
value = value.substring(1);
|
|
395
|
+
while (p < parts.length && !value.endsWith('"')) {
|
|
396
|
+
value += `;${parts[++p]}`;
|
|
397
|
+
}
|
|
398
|
+
value = value.substring(0, value.length - 1);
|
|
399
|
+
}
|
|
400
|
+
if (parts[p] === 'true') {
|
|
401
|
+
parts[p] = true;
|
|
402
|
+
}
|
|
403
|
+
else if (parts[p] === 'false') {
|
|
404
|
+
parts[p] = false;
|
|
405
|
+
// eslint-disable-next-line no-restricted-properties
|
|
406
|
+
}
|
|
407
|
+
else if (window.isFinite(parts[p])) {
|
|
408
|
+
const attr = this.props.schema.items.find(it => it.attr === header[p]);
|
|
409
|
+
if (attr && attr.type === 'number') {
|
|
410
|
+
// if a type of attribute is a "number"
|
|
411
|
+
parts[p] = parseFloat(parts[p]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
obj[header[p]] = parts[p];
|
|
415
|
+
}
|
|
416
|
+
values.push(obj);
|
|
417
|
+
});
|
|
418
|
+
if (values.length) {
|
|
419
|
+
if (this.state.value?.length) {
|
|
420
|
+
this.setState({ showTypeOfImportDialog: values, showImportDialog: false });
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
this.setState({ value: values, showImportDialog: false });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
window.alert('ra_No data found in file');
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
onClone = index => () => {
|
|
431
|
+
const newValue = JSON.parse(JSON.stringify(this.state.value));
|
|
432
|
+
const cloned = JSON.parse(JSON.stringify(newValue[index]));
|
|
433
|
+
if (typeof this.props.schema.clone === 'string' && typeof cloned[this.props.schema.clone] === 'string') {
|
|
434
|
+
let i = 1;
|
|
435
|
+
let text = cloned[this.props.schema.clone];
|
|
436
|
+
const pattern = text.match(/(\d+)$/);
|
|
437
|
+
if (pattern) {
|
|
438
|
+
text = text.replace(pattern[0], '');
|
|
439
|
+
i = parseInt(pattern[0], 10) + 1;
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
text += '_';
|
|
443
|
+
}
|
|
444
|
+
// eslint-disable-next-line no-loop-func
|
|
445
|
+
while (newValue.find(it => it[this.props.schema.clone] === text + i.toString())) {
|
|
446
|
+
i++;
|
|
447
|
+
}
|
|
448
|
+
cloned[this.props.schema.clone] = `${cloned[this.props.schema.clone]}_${i}`;
|
|
449
|
+
}
|
|
450
|
+
newValue.splice(index, 0, cloned);
|
|
451
|
+
this.setState({ value: newValue, iteration: this.state.iteration + 10000 }, () => this.applyFilter(false, null, () => this.onChangeWrapper(newValue)));
|
|
452
|
+
};
|
|
453
|
+
onChangeWrapper = (newValue, updateVisible = false) => {
|
|
454
|
+
this.typingTimer && clearTimeout(this.typingTimer);
|
|
455
|
+
this.typingTimer = setTimeout((value, _updateVisible) => {
|
|
456
|
+
this.typingTimer = null;
|
|
457
|
+
if (this.props.schema.objKeyName) {
|
|
458
|
+
const objValue = arrayToObject(JSON.parse(JSON.stringify(value)), this.props.schema.objKeyName, this.props.schema.objValueName);
|
|
459
|
+
this.onChange(this.props.attr, objValue);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
this.onChange(this.props.attr, value);
|
|
463
|
+
}
|
|
464
|
+
if (_updateVisible) {
|
|
465
|
+
this.applyFilter(false, value);
|
|
466
|
+
this.handleRequestSort(this.state.orderBy, true);
|
|
467
|
+
}
|
|
468
|
+
}, 300, newValue, updateVisible);
|
|
469
|
+
};
|
|
470
|
+
onAdd = () => {
|
|
471
|
+
const { schema } = this.props;
|
|
472
|
+
const newValue = JSON.parse(JSON.stringify(this.state.value));
|
|
473
|
+
const newItem = schema.items && schema.items.reduce((accumulator, currentValue) => {
|
|
474
|
+
let defaultValue;
|
|
475
|
+
if (currentValue.defaultFunc) {
|
|
476
|
+
if (this.props.custom) {
|
|
477
|
+
defaultValue = currentValue.defaultFunc ? this.executeCustom(currentValue.defaultFunc, this.props.schema.default, this.props.data, this.props.instanceObj, newValue.length, this.props.data) : this.props.schema.default;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
defaultValue = currentValue.defaultFunc ? this.execute(currentValue.defaultFunc, this.props.schema.default, this.props.data, newValue.length, this.props.data) : this.props.schema.default;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
defaultValue = currentValue.default === undefined ? null : currentValue.default;
|
|
485
|
+
}
|
|
486
|
+
accumulator[currentValue.attr] = defaultValue;
|
|
487
|
+
return accumulator;
|
|
488
|
+
}, {});
|
|
489
|
+
newValue.push(newItem);
|
|
490
|
+
this.setState({ value: newValue }, () => this.applyFilter(false, null, () => this.onChangeWrapper(newValue)));
|
|
491
|
+
};
|
|
492
|
+
isAnyFilterSet() {
|
|
493
|
+
return Object.keys(this.filterRefs).find(attr => this.filterRefs[attr].current?.children[0].children[0].value);
|
|
494
|
+
}
|
|
495
|
+
applyFilter = (clear, value, cb) => {
|
|
496
|
+
value = value || this.state.value;
|
|
497
|
+
let visibleValue = value.map((_, i) => i);
|
|
498
|
+
Object.keys(this.filterRefs).forEach(attr => {
|
|
499
|
+
let valueInputRef = this.filterRefs[attr].current?.children[0].children[0].value;
|
|
500
|
+
if (!clear && valueInputRef) {
|
|
501
|
+
valueInputRef = valueInputRef.toLowerCase();
|
|
502
|
+
visibleValue = visibleValue.filter(idx => value[idx] && value[idx][attr] && value[idx][attr].toLowerCase().includes(valueInputRef));
|
|
503
|
+
}
|
|
504
|
+
else if (this.filterRefs[attr].current) {
|
|
505
|
+
this.filterRefs[attr].current.children[0].children[0].value = '';
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
if (visibleValue.length === value.length) {
|
|
509
|
+
visibleValue = null;
|
|
510
|
+
}
|
|
511
|
+
if (visibleValue === null && this.state.visibleValue === null) {
|
|
512
|
+
cb && cb();
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (JSON.stringify(visibleValue) !== JSON.stringify(this.state.visibleValue)) {
|
|
516
|
+
this.setState({ visibleValue }, () => cb && cb());
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
cb && cb();
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
onMoveUp(idx) {
|
|
523
|
+
const newValue = JSON.parse(JSON.stringify(this.state.value));
|
|
524
|
+
const item = newValue[idx];
|
|
525
|
+
newValue.splice(idx, 1);
|
|
526
|
+
newValue.splice(idx - 1, 0, item);
|
|
527
|
+
this.setState({ value: newValue, iteration: this.state.iteration + 10000 }, () => this.applyFilter(false, null, () => this.onChangeWrapper(newValue)));
|
|
528
|
+
}
|
|
529
|
+
onMoveDown(idx) {
|
|
530
|
+
const newValue = JSON.parse(JSON.stringify(this.state.value));
|
|
531
|
+
const item = newValue[idx];
|
|
532
|
+
newValue.splice(idx, 1);
|
|
533
|
+
newValue.splice(idx + 1, 0, item);
|
|
534
|
+
this.setState({ value: newValue, iteration: this.state.iteration + 10000 }, () => this.applyFilter(false, null, () => this.onChangeWrapper(newValue)));
|
|
535
|
+
}
|
|
536
|
+
onDrop(acceptedFiles) {
|
|
537
|
+
const file = acceptedFiles[0];
|
|
538
|
+
const reader = new FileReader();
|
|
539
|
+
reader.onabort = () => console.log('file reading was aborted');
|
|
540
|
+
reader.onerror = () => console.log('file reading has failed');
|
|
541
|
+
reader.onload = () => {
|
|
542
|
+
if (file.size > MAX_SIZE) {
|
|
543
|
+
window.alert(I18n.t('ra_File is too big. Max %sk allowed. Try use SVG.', Math.round(MAX_SIZE / 1024)));
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const text = new Uint8Array(reader.result)
|
|
547
|
+
.reduce((data, byte) => data + String.fromCharCode(byte), '');
|
|
548
|
+
this.onImport(text);
|
|
549
|
+
};
|
|
550
|
+
reader.readAsArrayBuffer(file);
|
|
551
|
+
}
|
|
552
|
+
showTypeOfImportDialog() {
|
|
553
|
+
if (!this.state.showTypeOfImportDialog) {
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
return React.createElement(Dialog, { open: !0, onClose: () => this.setState({ showTypeOfImportDialog: false }), maxWidth: "md" },
|
|
557
|
+
React.createElement(DialogTitle, null, I18n.t('ra_Append or replace?')),
|
|
558
|
+
React.createElement(DialogContent, null, I18n.t('ra_Append %s entries or replace existing?', this.state.showTypeOfImportDialog.length)),
|
|
559
|
+
React.createElement(DialogActions, null,
|
|
560
|
+
React.createElement(Button, { variant: "contained", color: "primary", autoFocus: true, onClick: () => {
|
|
561
|
+
const value = JSON.parse(JSON.stringify(this.state.value));
|
|
562
|
+
this.state.showTypeOfImportDialog.forEach(obj => value.push(obj));
|
|
563
|
+
this.setState({
|
|
564
|
+
value,
|
|
565
|
+
iteration: this.state.iteration + 10000,
|
|
566
|
+
showTypeOfImportDialog: false,
|
|
567
|
+
}, () => this.applyFilter(false, null, () => this.onChangeWrapper(value)));
|
|
568
|
+
} }, I18n.t('ra_Append')),
|
|
569
|
+
React.createElement(Button, { variant: "contained", color: "secondary", autoFocus: true, onClick: () => {
|
|
570
|
+
const value = this.state.showTypeOfImportDialog;
|
|
571
|
+
this.setState({
|
|
572
|
+
value,
|
|
573
|
+
iteration: this.state.iteration + 10000,
|
|
574
|
+
showTypeOfImportDialog: false,
|
|
575
|
+
}, () => this.applyFilter(false, null, () => this.onChangeWrapper(value)));
|
|
576
|
+
} }, I18n.t('ra_Replace'))));
|
|
577
|
+
}
|
|
578
|
+
showImportDialog() {
|
|
579
|
+
if (!this.state.showImportDialog) {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
return React.createElement(Dialog, { open: !0, onClose: () => this.setState({ showImportDialog: false }), maxWidth: "md", fullWidth: true },
|
|
583
|
+
React.createElement(DialogTitle, null, I18n.t('ra_Import from %s', 'CSV')),
|
|
584
|
+
React.createElement(DialogContent, null,
|
|
585
|
+
React.createElement(Dropzone, { multiple: false, accept: { 'text/csv': ['.csv'] }, maxSize: MAX_SIZE, onDragEnter: () => this.setState({ uploadFile: 'dragging' }), onDragLeave: () => this.setState({ uploadFile: true }), onDrop: (acceptedFiles, errors) => {
|
|
586
|
+
this.setState({ uploadFile: false });
|
|
587
|
+
if (!acceptedFiles.length) {
|
|
588
|
+
window.alert((errors && errors[0] && errors[0].errors && errors[0].errors[0] && errors[0].errors[0].message) || I18n.t('ra_Cannot upload'));
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
this.onDrop(acceptedFiles);
|
|
592
|
+
}
|
|
593
|
+
} }, ({ getRootProps, getInputProps }) => React.createElement("div", { className: Utils.clsx(this.props.classes.uploadDiv, this.state.uploadFile === 'dragging' && this.props.classes.uploadDivDragging, this.props.classes.dropZone, !this.state.icon && this.props.classes.dropZoneEmpty), ...getRootProps() },
|
|
594
|
+
React.createElement("input", { ...getInputProps() }),
|
|
595
|
+
React.createElement("div", { className: Utils.clsx(this.props.classes.uploadCenterDiv) },
|
|
596
|
+
React.createElement("div", { className: this.props.classes.uploadCenterTextAndIcon },
|
|
597
|
+
React.createElement(ImportIcon, { className: this.props.classes.uploadCenterIcon }),
|
|
598
|
+
React.createElement("div", { className: this.props.classes.uploadCenterText }, this.state.uploadFile === 'dragging' ? I18n.t('ra_Drop file here') :
|
|
599
|
+
I18n.t('ra_Place your files here or click here to open the browse dialog'))))))),
|
|
600
|
+
React.createElement(DialogActions, null,
|
|
601
|
+
React.createElement(Button, { variant: "contained", onClick: () => this.setState({ showImportDialog: false }), color: "primary", startIcon: React.createElement(IconClose, null) }, I18n.t('Cancel'))));
|
|
602
|
+
}
|
|
603
|
+
renderItem( /* error, disabled, defaultValue */) {
|
|
604
|
+
const { classes, schema } = this.props;
|
|
605
|
+
let { visibleValue } = this.state;
|
|
606
|
+
if (!this.state.value) {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
visibleValue = visibleValue || this.state.value.map((_, i) => i);
|
|
610
|
+
const doAnyFilterSet = this.isAnyFilterSet();
|
|
611
|
+
return React.createElement(Paper, { className: classes.paper },
|
|
612
|
+
this.showImportDialog(),
|
|
613
|
+
this.showTypeOfImportDialog(),
|
|
614
|
+
schema.label ? React.createElement("div", { className: classes.label },
|
|
615
|
+
React.createElement(Toolbar, { variant: "dense", className: classes.rootTool },
|
|
616
|
+
React.createElement(Typography, { className: classes.title, variant: "h6", id: "tableTitle", component: "div" }, this.getText(schema.label)))) : null,
|
|
617
|
+
React.createElement(TableContainer, null,
|
|
618
|
+
React.createElement(Table, { className: classes.table, size: "small" },
|
|
619
|
+
this.enhancedTableHead(!doAnyFilterSet && !this.state.orderBy ? 120 : 64, doAnyFilterSet),
|
|
620
|
+
React.createElement(TableBody, null,
|
|
621
|
+
visibleValue.map((idx, i) => React.createElement(TableRow, { hover: true, key: `${idx}_${i}` },
|
|
622
|
+
schema.items && schema.items.map(headCell => React.createElement(TableCell, { key: `${headCell.attr}_${idx}`, align: "left" }, this.itemTable(headCell.attr, this.state.value[idx], idx))),
|
|
623
|
+
!schema.noDelete && React.createElement(TableCell, { align: "left", className: classes.buttonCell },
|
|
624
|
+
!doAnyFilterSet && !this.state.orderBy ? (i ? React.createElement(Tooltip, { title: I18n.t('ra_Move up') },
|
|
625
|
+
React.createElement(IconButton, { size: "small", onClick: () => this.onMoveUp(idx) },
|
|
626
|
+
React.createElement(UpIcon, null))) : React.createElement("div", { className: classes.buttonEmpty })) : null,
|
|
627
|
+
!doAnyFilterSet && !this.state.orderBy ? (i < visibleValue.length - 1 ? React.createElement(Tooltip, { title: I18n.t('ra_Move down') },
|
|
628
|
+
React.createElement(IconButton, { size: "small", onClick: () => this.onMoveDown(idx) },
|
|
629
|
+
React.createElement(DownIcon, null))) : React.createElement("div", { className: classes.buttonEmpty })) : null,
|
|
630
|
+
React.createElement(Tooltip, { title: I18n.t('ra_Delete current row') },
|
|
631
|
+
React.createElement(IconButton, { size: "small", onClick: this.onDelete(idx) },
|
|
632
|
+
React.createElement(DeleteIcon, null))),
|
|
633
|
+
this.props.schema.clone ? React.createElement(Tooltip, { title: I18n.t('ra_Clone current row') },
|
|
634
|
+
React.createElement(IconButton, { size: "small", onClick: this.onClone(idx) },
|
|
635
|
+
React.createElement(CopyContentIcon, null))) : null))),
|
|
636
|
+
!schema.noDelete && visibleValue.length >= (schema.showSecondAddAt || 5) ?
|
|
637
|
+
React.createElement(TableRow, null,
|
|
638
|
+
React.createElement(TableCell, { colSpan: schema.items.length + 1 },
|
|
639
|
+
React.createElement(Tooltip, { title: doAnyFilterSet ? I18n.t('ra_Cannot add items with set filter') : I18n.t('ra_Add row') },
|
|
640
|
+
React.createElement("span", null,
|
|
641
|
+
React.createElement(IconButton, { size: "small", color: "primary", disabled: !!doAnyFilterSet && !this.props.schema.allowAddByFilter, onClick: this.onAdd },
|
|
642
|
+
React.createElement(AddIcon, null)))))) : null)),
|
|
643
|
+
!visibleValue.length && this.state.value.length ?
|
|
644
|
+
React.createElement("div", { className: classes.filteredOut },
|
|
645
|
+
React.createElement(Typography, { className: classes.title, variant: "h6", id: "tableTitle", component: "div" },
|
|
646
|
+
I18n.t('ra_All items are filtered out'),
|
|
647
|
+
React.createElement(IconButton, { size: "small", onClick: () => this.applyFilter(true) },
|
|
648
|
+
React.createElement(CloseIcon, null)))) : null),
|
|
649
|
+
schema.help ?
|
|
650
|
+
React.createElement(FormHelperText, null, this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation))
|
|
651
|
+
: null,
|
|
652
|
+
this.state.errorMessage ? React.createElement("div", { style: { display: 'flex', padding: '5px' } },
|
|
653
|
+
React.createElement(ErrorIcon, { color: "error" }),
|
|
654
|
+
React.createElement("span", { style: { color: 'red', alignSelf: 'center' } }, this.state.errorMessage)) : null);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
ConfigTable.propTypes = {
|
|
658
|
+
socket: PropTypes.object.isRequired,
|
|
659
|
+
changed: PropTypes.bool,
|
|
660
|
+
themeType: PropTypes.string,
|
|
661
|
+
themeName: PropTypes.string,
|
|
662
|
+
style: PropTypes.object,
|
|
663
|
+
className: PropTypes.string,
|
|
664
|
+
data: PropTypes.object.isRequired,
|
|
665
|
+
schema: PropTypes.object,
|
|
666
|
+
onError: PropTypes.func,
|
|
667
|
+
onChange: PropTypes.func,
|
|
668
|
+
};
|
|
669
|
+
export default withStyles(styles)(ConfigTable);
|
|
670
|
+
//# sourceMappingURL=ConfigTable.js.map
|