@iobroker/json-config 6.17.6 → 6.17.13
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 -21
- package/build/JsonConfig.d.ts +1 -1
- package/build/JsonConfig.js +18 -19
- package/build/JsonConfig.js.map +1 -1
- package/build/JsonConfigComponent/ChipInput.d.ts +89 -11
- package/build/JsonConfigComponent/ChipInput.js +48 -137
- package/build/JsonConfigComponent/ChipInput.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAccordion.d.ts +7 -14
- package/build/JsonConfigComponent/ConfigAccordion.js +10 -21
- package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAlive.d.ts +5 -1
- package/build/JsonConfigComponent/ConfigAlive.js +0 -1
- package/build/JsonConfigComponent/ConfigAlive.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocomplete.d.ts +5 -29
- package/build/JsonConfigComponent/ConfigAutocomplete.js +7 -5
- package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.d.ts +5 -14
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js +3 -3
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCRON.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigCertCollection.d.ts +7 -13
- package/build/JsonConfigComponent/ConfigCertCollection.js +8 -18
- package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertificateSelect.d.ts +7 -13
- package/build/JsonConfigComponent/ConfigCertificateSelect.js +5 -18
- package/build/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertificates.d.ts +7 -13
- package/build/JsonConfigComponent/ConfigCertificates.js +7 -18
- package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckbox.d.ts +3 -11
- package/build/JsonConfigComponent/ConfigCheckbox.js +2 -2
- package/build/JsonConfigComponent/ConfigCheckbox.js.map +1 -1
- package/build/JsonConfigComponent/ConfigChip.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigColor.d.ts +13 -20
- package/build/JsonConfigComponent/ConfigColor.js +9 -23
- package/build/JsonConfigComponent/ConfigColor.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCoordinates.d.ts +8 -13
- package/build/JsonConfigComponent/ConfigCoordinates.js +29 -39
- package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCustom.d.ts +4 -50
- package/build/JsonConfigComponent/ConfigCustom.js +0 -1
- package/build/JsonConfigComponent/ConfigCustom.js.map +1 -1
- package/build/JsonConfigComponent/ConfigDatePicker.d.ts +8 -3
- package/build/JsonConfigComponent/ConfigDatePicker.js +21 -13
- package/build/JsonConfigComponent/ConfigDatePicker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigDeviceManager.d.ts +5 -1
- package/build/JsonConfigComponent/ConfigDeviceManager.js +1 -1
- package/build/JsonConfigComponent/ConfigDeviceManager.js.map +1 -1
- package/build/JsonConfigComponent/ConfigFile.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigFunc.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigGeneric.d.ts +46 -32
- package/build/JsonConfigComponent/ConfigGeneric.js +23 -12
- package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIP.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigImageSendTo.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigInstanceSelect.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigInterface.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigJsonEditor.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigLanguage.d.ts +3 -2
- package/build/JsonConfigComponent/ConfigLanguage.js +2 -2
- package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -1
- package/build/JsonConfigComponent/ConfigNumber.d.ts +3 -13
- package/build/JsonConfigComponent/ConfigNumber.js +2 -2
- package/build/JsonConfigComponent/ConfigNumber.js.map +1 -1
- package/build/JsonConfigComponent/ConfigObjectId.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigPanel.d.ts +7 -2
- package/build/JsonConfigComponent/ConfigPanel.js +5 -40
- package/build/JsonConfigComponent/ConfigPanel.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPassword.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigPort.d.ts +6 -1
- package/build/JsonConfigComponent/ConfigPort.js +2 -3
- package/build/JsonConfigComponent/ConfigPort.js.map +1 -1
- package/build/JsonConfigComponent/ConfigRoom.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigSelect.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigSelectSendTo.d.ts +7 -16
- package/build/JsonConfigComponent/ConfigSelectSendTo.js +15 -61
- package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSendto.d.ts +3 -20
- package/build/JsonConfigComponent/ConfigSendto.js +8 -8
- package/build/JsonConfigComponent/ConfigSendto.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSetState.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigSlider.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigStaticDivider.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigStaticHeader.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigStaticImage.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigStaticText.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigTable.d.ts +4 -25
- package/build/JsonConfigComponent/ConfigTable.js +5 -4
- package/build/JsonConfigComponent/ConfigTable.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTabs.d.ts +8 -33
- package/build/JsonConfigComponent/ConfigTabs.js +10 -43
- package/build/JsonConfigComponent/ConfigTabs.js.map +1 -1
- package/build/JsonConfigComponent/ConfigText.d.ts +7 -13
- package/build/JsonConfigComponent/ConfigText.js +13 -18
- package/build/JsonConfigComponent/ConfigText.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTextSendTo.d.ts +7 -9
- package/build/JsonConfigComponent/ConfigTextSendTo.js +11 -21
- package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTimePicker.d.ts +9 -3
- package/build/JsonConfigComponent/ConfigTimePicker.js +28 -18
- package/build/JsonConfigComponent/ConfigTimePicker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTopic.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigUUID.d.ts +12 -13
- package/build/JsonConfigComponent/ConfigUUID.js +1 -6
- package/build/JsonConfigComponent/ConfigUUID.js.map +1 -1
- package/build/JsonConfigComponent/ConfigUser.d.ts +1 -1
- package/build/JsonConfigComponent/index.d.ts +66 -25
- package/build/JsonConfigComponent/index.js +48 -61
- package/build/JsonConfigComponent/index.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/package.json +27 -26
- package/src/JsonConfig.tsx +710 -0
- package/src/JsonConfigComponent/ChipInput.tsx +752 -0
- package/src/JsonConfigComponent/ConfigAccordion.tsx +278 -0
- package/src/JsonConfigComponent/ConfigAlive.tsx +74 -0
- package/src/JsonConfigComponent/ConfigAutocomplete.tsx +108 -0
- package/src/JsonConfigComponent/ConfigAutocompleteSendTo.tsx +183 -0
- package/src/JsonConfigComponent/ConfigCRON.jsx +101 -0
- package/src/JsonConfigComponent/ConfigCertCollection.tsx +102 -0
- package/src/JsonConfigComponent/ConfigCertificateSelect.tsx +92 -0
- package/src/JsonConfigComponent/ConfigCertificates.tsx +202 -0
- package/src/JsonConfigComponent/ConfigCheckLicense.jsx +662 -0
- package/src/JsonConfigComponent/ConfigCheckbox.tsx +67 -0
- package/src/JsonConfigComponent/ConfigChip.jsx +81 -0
- package/src/JsonConfigComponent/ConfigColor.tsx +86 -0
- package/src/JsonConfigComponent/ConfigCoordinates.tsx +234 -0
- package/src/JsonConfigComponent/ConfigCustom.tsx +246 -0
- package/src/JsonConfigComponent/ConfigDatePicker.tsx +48 -0
- package/src/JsonConfigComponent/ConfigDeviceManager.tsx +33 -0
- package/src/JsonConfigComponent/ConfigFile.jsx +181 -0
- package/src/JsonConfigComponent/ConfigFileSelector.jsx +520 -0
- package/src/JsonConfigComponent/ConfigFunc.jsx +90 -0
- package/src/JsonConfigComponent/ConfigGeneric.tsx +1027 -0
- package/src/JsonConfigComponent/ConfigIP.jsx +96 -0
- package/src/JsonConfigComponent/ConfigImageSendTo.jsx +79 -0
- package/src/JsonConfigComponent/ConfigImageUpload.jsx +114 -0
- package/src/JsonConfigComponent/ConfigInstanceSelect.jsx +172 -0
- package/src/JsonConfigComponent/ConfigInterface.jsx +112 -0
- package/src/JsonConfigComponent/ConfigJsonEditor.jsx +103 -0
- package/src/JsonConfigComponent/ConfigLanguage.tsx +153 -0
- package/src/JsonConfigComponent/ConfigLicense.jsx +148 -0
- package/src/JsonConfigComponent/ConfigNumber.tsx +207 -0
- package/src/JsonConfigComponent/ConfigObjectId.jsx +113 -0
- package/src/JsonConfigComponent/ConfigPanel.tsx +360 -0
- package/src/JsonConfigComponent/ConfigPassword.jsx +160 -0
- package/src/JsonConfigComponent/ConfigPattern.jsx +50 -0
- package/src/JsonConfigComponent/ConfigPort.tsx +232 -0
- package/src/JsonConfigComponent/ConfigRoom.jsx +90 -0
- package/src/JsonConfigComponent/ConfigSelect.jsx +124 -0
- package/src/JsonConfigComponent/ConfigSelectSendTo.tsx +251 -0
- package/src/JsonConfigComponent/ConfigSendto.tsx +340 -0
- package/src/JsonConfigComponent/ConfigSetState.jsx +116 -0
- package/src/JsonConfigComponent/ConfigSlider.jsx +97 -0
- package/src/JsonConfigComponent/ConfigStaticDivider.jsx +51 -0
- package/src/JsonConfigComponent/ConfigStaticHeader.jsx +63 -0
- package/src/JsonConfigComponent/ConfigStaticImage.jsx +48 -0
- package/src/JsonConfigComponent/ConfigStaticText.jsx +72 -0
- package/src/JsonConfigComponent/ConfigTable.tsx +1040 -0
- package/src/JsonConfigComponent/ConfigTabs.tsx +150 -0
- package/src/JsonConfigComponent/ConfigText.tsx +188 -0
- package/src/JsonConfigComponent/ConfigTextSendTo.tsx +102 -0
- package/src/JsonConfigComponent/ConfigTimePicker.tsx +63 -0
- package/src/JsonConfigComponent/ConfigTopic.jsx +78 -0
- package/src/JsonConfigComponent/ConfigUUID.tsx +55 -0
- package/src/JsonConfigComponent/ConfigUser.jsx +104 -0
- package/src/JsonConfigComponent/index.tsx +435 -0
- package/src/JsonConfigComponent/wrapper/Components/CustomModal.jsx +145 -0
- package/src/JsonConfigComponent/wrapper/Components/Editor.jsx +65 -0
- package/src/Utils.jsx +1683 -0
- package/src/index.tsx +14 -0
- package/src/types.d.ts +372 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withStyles } from '@mui/styles';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
InputLabel,
|
|
7
|
+
FormControl,
|
|
8
|
+
Button,
|
|
9
|
+
TextField,
|
|
10
|
+
} from '@mui/material';
|
|
11
|
+
|
|
12
|
+
import { Cron as DialogCron, I18n } from '@iobroker/adapter-react-v5';
|
|
13
|
+
|
|
14
|
+
import ConfigGeneric from './ConfigGeneric';
|
|
15
|
+
|
|
16
|
+
const styles = () => ({
|
|
17
|
+
fullWidth: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
},
|
|
20
|
+
flex: {
|
|
21
|
+
display: 'flex',
|
|
22
|
+
},
|
|
23
|
+
button: {
|
|
24
|
+
height: 48,
|
|
25
|
+
marginLeft: 4,
|
|
26
|
+
minWidth: 48,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
class ConfigCRON extends ConfigGeneric {
|
|
31
|
+
async componentDidMount() {
|
|
32
|
+
super.componentDidMount();
|
|
33
|
+
const { data, attr } = this.props;
|
|
34
|
+
const value = ConfigGeneric.getValue(data, attr) || '';
|
|
35
|
+
this.setState({ value, showDialog: false });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
renderItem(error, disabled /* , defaultValue */) {
|
|
39
|
+
const { classes, schema, attr } = this.props;
|
|
40
|
+
const { value, showDialog } = this.state;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<FormControl className={classes.fullWidth} variant="standard">
|
|
44
|
+
{schema.label ? <InputLabel shrink>{this.getText(schema.label)}</InputLabel> : null}
|
|
45
|
+
<div className={classes.flex}>
|
|
46
|
+
<TextField
|
|
47
|
+
variant="standard"
|
|
48
|
+
fullWidth
|
|
49
|
+
value={value ?? ''}
|
|
50
|
+
error={!!error}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
placeholder={this.getText(schema.placeholder)}
|
|
53
|
+
label={this.getText(schema.label)}
|
|
54
|
+
helperText={this.renderHelp(schema.help, schema.helpLink, schema.noTranslation)}
|
|
55
|
+
onChange={e => {
|
|
56
|
+
const value_ = e.target.value;
|
|
57
|
+
this.setState({ value: value_ }, () => this.onChange(attr, value_));
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
<Button
|
|
61
|
+
color="grey"
|
|
62
|
+
className={this.props.classes.button}
|
|
63
|
+
size="small"
|
|
64
|
+
variant="outlined"
|
|
65
|
+
onClick={() => this.setState({ showDialog: true })}
|
|
66
|
+
>
|
|
67
|
+
...
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
{showDialog ? (
|
|
71
|
+
<DialogCron
|
|
72
|
+
title={I18n.t('ra_Define schedule')}
|
|
73
|
+
simple={schema.simple}
|
|
74
|
+
complex={schema.complex}
|
|
75
|
+
cron={value}
|
|
76
|
+
language={I18n.getLanguage()}
|
|
77
|
+
onClose={() => this.setState({ showDialog: false })}
|
|
78
|
+
cancel={I18n.t('ra_Cancel')}
|
|
79
|
+
ok={I18n.t('ra_Ok')}
|
|
80
|
+
onOk={value_ => this.setState({ showDialog: false, value: value_ }, () => this.onChange(attr, value_))}
|
|
81
|
+
/>
|
|
82
|
+
) : null}
|
|
83
|
+
</FormControl>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ConfigCRON.propTypes = {
|
|
89
|
+
themeType: PropTypes.string,
|
|
90
|
+
themeName: PropTypes.string,
|
|
91
|
+
style: PropTypes.object,
|
|
92
|
+
className: PropTypes.string,
|
|
93
|
+
data: PropTypes.object.isRequired,
|
|
94
|
+
schema: PropTypes.object,
|
|
95
|
+
onError: PropTypes.func,
|
|
96
|
+
onChange: PropTypes.func,
|
|
97
|
+
dateFormat: PropTypes.string,
|
|
98
|
+
isFloatComma: PropTypes.bool,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default withStyles(styles)(ConfigCRON);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withStyles } from '@mui/styles';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
InputLabel,
|
|
7
|
+
MenuItem,
|
|
8
|
+
FormControl,
|
|
9
|
+
Select,
|
|
10
|
+
FormHelperText,
|
|
11
|
+
} from '@mui/material';
|
|
12
|
+
|
|
13
|
+
import { I18n } from '@iobroker/adapter-react-v5';
|
|
14
|
+
import type { ConfigItemCertCollection } from '#JC/types';
|
|
15
|
+
import ConfigGeneric, {type ConfigGenericProps, type ConfigGenericState} from './ConfigGeneric';
|
|
16
|
+
|
|
17
|
+
const styles: Record<string, any> = {
|
|
18
|
+
fullWidth: {
|
|
19
|
+
width: '100%',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface ConfigCertCollectionProps extends ConfigGenericProps {
|
|
24
|
+
schema: ConfigItemCertCollection;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ConfigCertCollectionState extends ConfigGenericState {
|
|
28
|
+
collectionsOptions?: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface CertCollection {
|
|
32
|
+
/** Source of the certificate */
|
|
33
|
+
from: string;
|
|
34
|
+
key: string;
|
|
35
|
+
cert: string;
|
|
36
|
+
chain: string[],
|
|
37
|
+
domains: string[],
|
|
38
|
+
staging?: boolean,
|
|
39
|
+
tsExpires?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class ConfigCertCollection extends ConfigGeneric<ConfigCertCollectionProps, ConfigCertCollectionState> {
|
|
43
|
+
async componentDidMount() {
|
|
44
|
+
super.componentDidMount();
|
|
45
|
+
|
|
46
|
+
let collectionsOptions: string[];
|
|
47
|
+
const collectionsOptionsObj = await this.props.socket.getObject('system.certificates');
|
|
48
|
+
if (collectionsOptionsObj?.native?.collections) {
|
|
49
|
+
collectionsOptions = Object.keys(collectionsOptionsObj.native.collections as Record<string, CertCollection>);
|
|
50
|
+
} else {
|
|
51
|
+
collectionsOptions = [];
|
|
52
|
+
}
|
|
53
|
+
this.setState({ collectionsOptions });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
renderItem(error: unknown, disabled: boolean /* , defaultValue */) {
|
|
57
|
+
if (!this.state.collectionsOptions) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const leCollection = (ConfigGeneric.getValue(this.props.data, this.props.schema.leCollectionName || 'leCollection') || 'false').toString();
|
|
61
|
+
|
|
62
|
+
return <FormControl className={this.props.classes.fullWidth} variant="standard">
|
|
63
|
+
{this.props.schema.label ? <InputLabel shrink>{this.getText(this.props.schema.label)}</InputLabel> : null}
|
|
64
|
+
<Select
|
|
65
|
+
variant="standard"
|
|
66
|
+
error={!!error}
|
|
67
|
+
displayEmpty
|
|
68
|
+
disabled={!!disabled}
|
|
69
|
+
value={leCollection}
|
|
70
|
+
onChange={e => this.onChange(
|
|
71
|
+
this.props.schema.leCollectionName || 'leCollection',
|
|
72
|
+
e.target.value === 'false' ? false : (e.target.value === 'true' ? true : e.target.value),
|
|
73
|
+
)}
|
|
74
|
+
>
|
|
75
|
+
<MenuItem
|
|
76
|
+
key="_false"
|
|
77
|
+
value="false"
|
|
78
|
+
style={{ fontWeight: 'bold' }}
|
|
79
|
+
>
|
|
80
|
+
{I18n.t('ra_Do not use let\'s encrypt')}
|
|
81
|
+
</MenuItem>
|
|
82
|
+
<MenuItem
|
|
83
|
+
key="_true"
|
|
84
|
+
value="true"
|
|
85
|
+
style={{ fontWeight: 'bold' }}
|
|
86
|
+
>
|
|
87
|
+
{I18n.t('ra_Use all available let\'s encrypt certificates')}
|
|
88
|
+
</MenuItem>
|
|
89
|
+
{this.state.collectionsOptions?.map(item =>
|
|
90
|
+
<MenuItem
|
|
91
|
+
key={item}
|
|
92
|
+
value={item}
|
|
93
|
+
>
|
|
94
|
+
{item}
|
|
95
|
+
</MenuItem>)}
|
|
96
|
+
</Select>
|
|
97
|
+
{this.props.schema.help ? <FormHelperText>{this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}</FormHelperText> : null}
|
|
98
|
+
</FormControl>;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default withStyles(styles)(ConfigCertCollection);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withStyles } from '@mui/styles';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
InputLabel,
|
|
6
|
+
MenuItem,
|
|
7
|
+
FormControl,
|
|
8
|
+
Select,
|
|
9
|
+
FormHelperText,
|
|
10
|
+
} from '@mui/material';
|
|
11
|
+
|
|
12
|
+
import { I18n } from '@iobroker/adapter-react-v5';
|
|
13
|
+
import type { ConfigItemCertificateSelect } from '#JC/types';
|
|
14
|
+
import ConfigGeneric, {type ConfigGenericProps, type ConfigGenericState} from './ConfigGeneric';
|
|
15
|
+
|
|
16
|
+
const styles: Record<string, any> = {
|
|
17
|
+
fullWidth: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface ConfigCertificateSelectProps extends ConfigGenericProps {
|
|
23
|
+
schema: ConfigItemCertificateSelect;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ConfigCertificateSelectState extends ConfigGenericState {
|
|
27
|
+
selectOptions?: { label: string; value: string }[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class ConfigCertificateSelect extends ConfigGeneric<ConfigCertificateSelectProps, ConfigCertificateSelectState> {
|
|
31
|
+
async componentDidMount() {
|
|
32
|
+
super.componentDidMount();
|
|
33
|
+
const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
|
|
34
|
+
const certificates = await this.props.socket.getCertificates();
|
|
35
|
+
|
|
36
|
+
const selectOptions: { label: string; value: string }[] = certificates
|
|
37
|
+
.filter(el => {
|
|
38
|
+
const name = this.props.attr.toLowerCase();
|
|
39
|
+
|
|
40
|
+
if (name.includes(el.type)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (el.type === 'public' && name.includes('cert')) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (el.type === 'private' && (name.includes('priv') || name.includes('key'))) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return !!(el.type === 'chained' && (name.includes('chain') || name.includes('ca')));
|
|
50
|
+
})
|
|
51
|
+
.map(el => ({ label: el.name, value: el.name }));
|
|
52
|
+
|
|
53
|
+
selectOptions.unshift({ label: I18n.t(ConfigGeneric.NONE_LABEL), value: ConfigGeneric.NONE_VALUE });
|
|
54
|
+
|
|
55
|
+
this.setState({ value, selectOptions });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
renderItem(error: unknown, disabled: boolean /* , defaultValue */) {
|
|
59
|
+
if (!this.state.selectOptions) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const item = this.state.selectOptions?.find(item => item.value === this.state.value);
|
|
64
|
+
|
|
65
|
+
return <FormControl className={this.props.classes.fullWidth} variant="standard">
|
|
66
|
+
{this.props.schema.label ? <InputLabel shrink>{this.getText(this.props.schema.label)}</InputLabel> : null}
|
|
67
|
+
<Select
|
|
68
|
+
variant="standard"
|
|
69
|
+
error={!!error}
|
|
70
|
+
displayEmpty
|
|
71
|
+
disabled={!!disabled}
|
|
72
|
+
value={this.state.value}
|
|
73
|
+
renderValue={() => this.getText(item?.label, this.props.schema.noTranslation !== false)}
|
|
74
|
+
onChange={e =>
|
|
75
|
+
this.setState({ value: e.target.value }, () =>
|
|
76
|
+
this.onChange(this.props.attr, this.state.value))}
|
|
77
|
+
>
|
|
78
|
+
{this.state.selectOptions?.map(item_ =>
|
|
79
|
+
<MenuItem
|
|
80
|
+
key={item_.value}
|
|
81
|
+
value={item_.value}
|
|
82
|
+
style={item_.value === ConfigGeneric.NONE_VALUE ? { opacity: 0.5 } : {}}
|
|
83
|
+
>
|
|
84
|
+
{this.getText(item_.label, this.props.schema.noTranslation !== false)}
|
|
85
|
+
</MenuItem>)}
|
|
86
|
+
</Select>
|
|
87
|
+
{this.props.schema.help ? <FormHelperText>{this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}</FormHelperText> : null}
|
|
88
|
+
</FormControl>;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default withStyles(styles)(ConfigCertificateSelect);
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withStyles } from '@mui/styles';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
InputLabel,
|
|
6
|
+
MenuItem,
|
|
7
|
+
FormControl,
|
|
8
|
+
Select,
|
|
9
|
+
} from '@mui/material';
|
|
10
|
+
|
|
11
|
+
import { I18n } from '@iobroker/adapter-react-v5';
|
|
12
|
+
import type { ConfigItemCertificates } from '#JC/types';
|
|
13
|
+
import ConfigGeneric, {type ConfigGenericProps, type ConfigGenericState} from './ConfigGeneric';
|
|
14
|
+
|
|
15
|
+
const styles: Record<string, any> = {
|
|
16
|
+
fullWidth: {
|
|
17
|
+
width: '100%',
|
|
18
|
+
},
|
|
19
|
+
leWidth: {
|
|
20
|
+
width: 620,
|
|
21
|
+
marginBottom: 10,
|
|
22
|
+
},
|
|
23
|
+
certWidth: {
|
|
24
|
+
width: 200,
|
|
25
|
+
marginRight: 10,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
interface ConfigCertificatesProps extends ConfigGenericProps {
|
|
30
|
+
schema: ConfigItemCertificates;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface ConfigCertificatesState extends ConfigGenericState {
|
|
34
|
+
certsPublicOptions?: { label: string; value: string }[];
|
|
35
|
+
certsChainOptions?: { label: string; value: string }[];
|
|
36
|
+
certsPrivateOptions?: { label: string; value: string }[];
|
|
37
|
+
collectionsOptions?: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class ConfigCertificates extends ConfigGeneric<ConfigCertificatesProps, ConfigCertificatesState> {
|
|
41
|
+
async componentDidMount() {
|
|
42
|
+
super.componentDidMount();
|
|
43
|
+
const certificates = await this.props.socket.getCertificates();
|
|
44
|
+
const certsPublicOptions: { label: string; value: string }[] = [];
|
|
45
|
+
const certsPrivateOptions: { label: string; value: string }[] = [];
|
|
46
|
+
const certsChainOptions: { label: string; value: string }[] = [];
|
|
47
|
+
|
|
48
|
+
let collectionsOptions: string[] | null = [];
|
|
49
|
+
const collectionsOptionsObj = await this.props.socket.getObject('system.certificates');
|
|
50
|
+
if (collectionsOptionsObj?.native?.collections) {
|
|
51
|
+
collectionsOptions = Object.keys(collectionsOptionsObj.native.collections);
|
|
52
|
+
} else {
|
|
53
|
+
collectionsOptions = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
certificates
|
|
57
|
+
.forEach(el => {
|
|
58
|
+
if (el.type === 'public') {
|
|
59
|
+
certsPublicOptions.push({ label: el.name, value: el.name });
|
|
60
|
+
} else if (el.type === 'private') {
|
|
61
|
+
certsPrivateOptions.push({ label: el.name, value: el.name });
|
|
62
|
+
} else if (el.type === 'chained') {
|
|
63
|
+
certsChainOptions.push({ label: el.name, value: el.name });
|
|
64
|
+
} else {
|
|
65
|
+
certsPublicOptions.push({ label: el.name, value: el.name });
|
|
66
|
+
certsPrivateOptions.push({ label: el.name, value: el.name });
|
|
67
|
+
certsChainOptions.push({ label: el.name, value: el.name });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
certsPublicOptions.unshift({ label: I18n.t(ConfigGeneric.NONE_LABEL), value: ConfigGeneric.NONE_VALUE });
|
|
72
|
+
certsPrivateOptions.unshift({ label: I18n.t(ConfigGeneric.NONE_LABEL), value: ConfigGeneric.NONE_VALUE });
|
|
73
|
+
certsChainOptions.unshift({ label: I18n.t(ConfigGeneric.NONE_LABEL), value: ConfigGeneric.NONE_VALUE });
|
|
74
|
+
|
|
75
|
+
this.setState({
|
|
76
|
+
certsPublicOptions,
|
|
77
|
+
certsChainOptions,
|
|
78
|
+
certsPrivateOptions,
|
|
79
|
+
collectionsOptions,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
renderItem(error: unknown, disabled: boolean /* , defaultValue */) {
|
|
84
|
+
if (!this.state.certsPublicOptions || !this.state.certsPrivateOptions || !this.state.certsChainOptions) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const leCollection = (ConfigGeneric.getValue(this.props.data, this.props.schema.leCollectionName || 'leCollection') || 'false').toString();
|
|
88
|
+
const certPublic = ConfigGeneric.getValue(this.props.data, this.props.schema.certPublicName || 'certPublic');
|
|
89
|
+
const certPrivate = ConfigGeneric.getValue(this.props.data, this.props.schema.certPrivateName || 'certPrivate');
|
|
90
|
+
const certChained = ConfigGeneric.getValue(this.props.data, this.props.schema.certChainedName || 'certChained');
|
|
91
|
+
|
|
92
|
+
const itemCertPublic = this.state.certsPublicOptions?.find(item => item.value === certPublic);
|
|
93
|
+
const itemCertPrivate = this.state.certsPrivateOptions?.find(item => item.value === certPrivate);
|
|
94
|
+
const itemCertChained = this.state.certsChainOptions?.find(item => item.value === certChained);
|
|
95
|
+
|
|
96
|
+
return <div className={this.props.classes.fullWidth}>
|
|
97
|
+
{this.state.collectionsOptions ? <FormControl className={this.props.classes.leWidth} variant="standard">
|
|
98
|
+
<InputLabel shrink>Let's encrypt</InputLabel>
|
|
99
|
+
<Select
|
|
100
|
+
variant="standard"
|
|
101
|
+
error={!!error}
|
|
102
|
+
displayEmpty
|
|
103
|
+
disabled={!!disabled}
|
|
104
|
+
value={leCollection}
|
|
105
|
+
onChange={e => this.onChange(
|
|
106
|
+
this.props.schema.leCollectionName || 'leCollection',
|
|
107
|
+
e.target.value === 'false' ? false : (e.target.value === 'true' ? true : e.target.value),
|
|
108
|
+
)}
|
|
109
|
+
>
|
|
110
|
+
<MenuItem
|
|
111
|
+
key="_false"
|
|
112
|
+
value="false"
|
|
113
|
+
style={{ fontWeight: 'bold' }}
|
|
114
|
+
>
|
|
115
|
+
{I18n.t('ra_Do not use let\'s encrypt')}
|
|
116
|
+
</MenuItem>
|
|
117
|
+
<MenuItem
|
|
118
|
+
key="_true"
|
|
119
|
+
value="true"
|
|
120
|
+
style={{ fontWeight: 'bold' }}
|
|
121
|
+
>
|
|
122
|
+
{I18n.t('ra_Use all available let\'s encrypt certificates')}
|
|
123
|
+
</MenuItem>
|
|
124
|
+
{this.state.collectionsOptions?.map(item =>
|
|
125
|
+
<MenuItem
|
|
126
|
+
key={item}
|
|
127
|
+
value={item}
|
|
128
|
+
>
|
|
129
|
+
{item}
|
|
130
|
+
</MenuItem>)}
|
|
131
|
+
</Select>
|
|
132
|
+
</FormControl> : null}
|
|
133
|
+
{this.state.collectionsOptions ? <br /> : null}
|
|
134
|
+
{this.state.collectionsOptions && leCollection !== 'false' ? <div>{I18n.t('ra_Fallback custom certificates')}</div> : null}
|
|
135
|
+
<FormControl className={this.props.classes.certWidth} variant="standard">
|
|
136
|
+
<InputLabel shrink>{I18n.t('ra_Public certificate')}</InputLabel>
|
|
137
|
+
<Select
|
|
138
|
+
variant="standard"
|
|
139
|
+
error={!!error}
|
|
140
|
+
displayEmpty
|
|
141
|
+
disabled={!!disabled}
|
|
142
|
+
value={certPublic || ''}
|
|
143
|
+
renderValue={() => this.getText(itemCertPublic?.label)}
|
|
144
|
+
onChange={e => this.onChange(this.props.schema.certPublicName || 'certPublic', e.target.value)}
|
|
145
|
+
>
|
|
146
|
+
{this.state.certsPublicOptions?.map((item, i) =>
|
|
147
|
+
<MenuItem
|
|
148
|
+
key={`${item.value}_${i}`}
|
|
149
|
+
value={item.value}
|
|
150
|
+
style={item.value === ConfigGeneric.NONE_VALUE ? { opacity: 0.5 } : {}}
|
|
151
|
+
>
|
|
152
|
+
{this.getText(item.label)}
|
|
153
|
+
</MenuItem>)}
|
|
154
|
+
</Select>
|
|
155
|
+
</FormControl>
|
|
156
|
+
<FormControl className={this.props.classes.certWidth} variant="standard">
|
|
157
|
+
<InputLabel shrink>{I18n.t('ra_Private certificate')}</InputLabel>
|
|
158
|
+
<Select
|
|
159
|
+
variant="standard"
|
|
160
|
+
error={!!error}
|
|
161
|
+
displayEmpty
|
|
162
|
+
disabled={!!disabled}
|
|
163
|
+
value={certPrivate || ''}
|
|
164
|
+
renderValue={() => this.getText(itemCertPrivate?.label)}
|
|
165
|
+
onChange={e => this.onChange(this.props.schema.certPrivateName || 'certPrivate', e.target.value)}
|
|
166
|
+
>
|
|
167
|
+
{this.state.certsPrivateOptions?.map((item, i) =>
|
|
168
|
+
<MenuItem
|
|
169
|
+
key={`${item.value}_${i}`}
|
|
170
|
+
value={item.value}
|
|
171
|
+
style={item.value === ConfigGeneric.NONE_VALUE ? { opacity: 0.5 } : {}}
|
|
172
|
+
>
|
|
173
|
+
{this.getText(item.label)}
|
|
174
|
+
</MenuItem>)}
|
|
175
|
+
</Select>
|
|
176
|
+
</FormControl>
|
|
177
|
+
<FormControl className={this.props.classes.certWidth} variant="standard">
|
|
178
|
+
<InputLabel shrink>{I18n.t('ra_Chained certificate')}</InputLabel>
|
|
179
|
+
<Select
|
|
180
|
+
variant="standard"
|
|
181
|
+
error={!!error}
|
|
182
|
+
displayEmpty
|
|
183
|
+
disabled={!!disabled}
|
|
184
|
+
value={certChained || ''}
|
|
185
|
+
renderValue={() => this.getText(itemCertChained?.label)}
|
|
186
|
+
onChange={e => this.onChange(this.props.schema.certChainedName || 'certChained', e.target.value)}
|
|
187
|
+
>
|
|
188
|
+
{this.state.certsChainOptions?.map((item, i) =>
|
|
189
|
+
<MenuItem
|
|
190
|
+
key={`${item.value}_${i}`}
|
|
191
|
+
value={item.value}
|
|
192
|
+
style={item.value === ConfigGeneric.NONE_VALUE ? { opacity: 0.5 } : {}}
|
|
193
|
+
>
|
|
194
|
+
{this.getText(item.label)}
|
|
195
|
+
</MenuItem>)}
|
|
196
|
+
</Select>
|
|
197
|
+
</FormControl>
|
|
198
|
+
</div>;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export default withStyles(styles)(ConfigCertificates);
|