Skip to content

Commit

Permalink
Prepare for json-config-with-dm
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed May 29, 2024
1 parent 929f33a commit c65e964
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@honkhonk/vite-plugin-svgr": "^1.1.0",
"@iobroker/adapter-react-v5": "^5.0.0",
"@iobroker/admin-component-easy-access": "^0.3.2",
"@iobroker/dm-utils": "^0.1.9",
"@iobroker/dm-utils": "^0.2.0",
"@iobroker/legacy-testing": "^1.0.12",
"@iobroker/socket-client": "^2.4.13",
"@iobroker/testing": "^4.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ws": "^8.17.0"
},
"devDependencies": {
"@iobroker/json-config": "file:../jsonConfig",
"@iobroker/json-config-with-dm": "file:../jsonConfig",
"@types/ace": "^0.0.52"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
},
webpack: {
alias: {
'@iobroker/json-config': path.resolve(__dirname, '..', '..', 'jsonConfig', 'src'),
'@iobroker/json-config-with-dm': path.resolve(__dirname, '..', '..', 'jsonConfig', 'src'),
'@iobroker/dm-gui-components': path.resolve(__dirname, '..', '..', 'dm-gui-components', 'src'),
'@': path.resolve(__dirname, 'src'),
'#DM': path.resolve(__dirname, '..', '..', 'dm-gui-components', 'src'),
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"not op_mini all"
],
"dependencies": {
"@iobroker/json-config": "file:../../jsonConfig"
"@iobroker/json-config-with-dm": "file:../../jsonConfig"
},
"proxy": "http://127.0.0.1:8081",
"plugins": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import {
Confirm as ConfirmDialog,
} from '@iobroker/adapter-react-v5';

import type { ConfigItemPanel } from '@iobroker/json-config/src/types';
import { JsonConfigComponent, ConfigGeneric, JsonConfigComponentClass } from '@iobroker/json-config';
import {
JsonConfigComponent, ConfigGeneric,
JsonConfigComponentClass, type ConfigItemPanel,
} from '@iobroker/json-config-with-dm';
import { deepClone } from '@mui/x-data-grid/utils/utils';
import Utils from '@/Utils';
import type { BasicComponentProps } from '@/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/src/dialogs/GenerateInputsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type ThemeName, type ThemeType,
} from '@iobroker/adapter-react-v5';

import { ConfigPanel } from '@iobroker/json-config';
import { ConfigPanel } from '@iobroker/json-config-with-dm';

const useStyles = makeStyles<IobTheme>(theme => ({
root: {
Expand Down
6 changes: 4 additions & 2 deletions packages/admin/src/src/tabs/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import {
} from '@mui/icons-material';

import {
Router, Utils, Icon, Confirm as ConfirmDialog,
Router, Utils,
Icon,
Confirm as ConfirmDialog,
} from '@iobroker/adapter-react-v5';

import { JsonConfig } from '@iobroker/json-config';
import { JsonConfig } from '@iobroker/json-config-with-dm';
import BasicUtils from '../Utils';

const arrayLogLevel = ['silly', 'debug', 'info', 'warn', 'error'];
Expand Down
18 changes: 8 additions & 10 deletions packages/dm-gui-components/src/Communication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Communication<P extends CommunicationProps, S extends CommunicationState>
return;
}
if (action.inputBefore) {
this.setState({ showInput: action, inputValue: action.inputValue.defaultValue || '' });
this.setState({ showInput: action, inputValue: action.inputBefore.defaultValue || '' });
return;
}

Expand Down Expand Up @@ -569,9 +569,9 @@ class Communication<P extends CommunicationProps, S extends CommunicationState>
const min = this.state.showInput.inputBefore.min === undefined ? 0 : this.state.showInput.inputBefore.min;
const max = this.state.showInput.inputBefore.max === undefined ? 100 : this.state.showInput.inputBefore.max;

if (this.state.inputValue < min) {
if ((this.state.inputValue as number) < min) {
this.setState({ inputValue: min });
} else if (this.state.inputValue > max) {
} else if ((this.state.inputValue as number) > max) {
this.setState({ inputValue: max });
}
}}
Expand All @@ -591,13 +591,11 @@ class Communication<P extends CommunicationProps, S extends CommunicationState>
variant="contained"
disabled={okDisabled}
color="primary"
onClick={() => {
this.setState({ showInput: null }, () =>
this.sendActionToInstance('dm:instanceAction', {
actionId: this.state.showInput.id,
value: this.state.showInput.inputBefore.type === 'checkbox' ? !!this.state.inputValue : (this.state.showInput.inputBefore.type === 'number' ? parseFloat(this.state.inputValue) || 0 : this.state.inputValue),
}));
}}
onClick={() => this.setState({ showInput: null }, () =>
this.sendActionToInstance('dm:instanceAction', {
actionId: this.state.showInput.id,
value: this.state.showInput.inputBefore.type === 'checkbox' ? !!this.state.inputValue : (this.state.showInput.inputBefore.type === 'number' ? parseFloat(this.state.inputValue as string) || 0 : this.state.inputValue),
}))}
startIcon={<Check />}
>
{getTranslation('yesButtonText')}
Expand Down
10 changes: 6 additions & 4 deletions packages/jsonConfig/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@iobroker/json-config",
"name": "@iobroker/json-config-with-dm",
"description": "This package contains the ioBroker JSON config UI components",
"version": "6.17.14",
"main": "./build/index.js",
Expand All @@ -8,16 +8,18 @@
"build": "tsc && tsc-alias",
"clean": "rimraf build",
"prepublishOnly": "npm run build",
"build:ts": "tsc -p tsconfig.json"
"build:ts": "tsc -p tsconfig.json",
"with-dm": "node with_dm",
"without-dm": "node without_dm"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@iobroker/adapter-react-v5": "^5.0.0",
"@iobroker/dm-gui-components": "file:../dm-gui-components",
"crypto-js": "^4.2.0",
"react-ace": "^11.0.1"
"react-ace": "^11.0.1",
"@iobroker/dm-gui-components": "6.17.14"
},
"files": [
"build/",
Expand Down
34 changes: 17 additions & 17 deletions packages/jsonConfig/src/JsonConfigComponent/ConfigDeviceManager.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

// START-WITH-DM
// import DeviceManager from '@iobroker/dm-gui-components';
import DeviceManager from '@iobroker/dm-gui-components';
// END-WITH-DM

import type { ConfigItemDeviceManager } from '#JC/types';
Expand All @@ -20,25 +20,25 @@ class ConfigDeviceManager extends ConfigGeneric<ConfigDeviceManagerProps, Config
}

// START-WITHOUT-DM
return <div>
Use
<b> @iobroker/json-config-with-dm </b>
instead of
<b> @iobroker/json-config</b>
</div>;
// return <div>
// Use
// <b> @iobroker/json-config-with-dm </b>
// instead of
// <b> @iobroker/json-config</b>
// </div>;
// END-WITHOUT-DM

// START-WITH-DM
// return <DeviceManager
// uploadImagesToInstance={`${this.props.adapterName}.${this.props.instance}`}
// title={this.getText(this.props.schema.label)}
// socket={this.props.socket}
// selectedInstance={`${this.props.adapterName}.${this.props.instance}`}
// themeName={this.props.themeName}
// themeType={this.props.themeType}
// isFloatComma={this.props.isFloatComma}
// dateFormat={this.props.dateFormat}
// />;
return <DeviceManager
uploadImagesToInstance={`${this.props.adapterName}.${this.props.instance}`}
title={this.getText(this.props.schema.label)}
socket={this.props.socket}
selectedInstance={`${this.props.adapterName}.${this.props.instance}`}
themeName={this.props.themeName}
themeType={this.props.themeType}
isFloatComma={this.props.isFloatComma}
dateFormat={this.props.dateFormat}
/>;
// END-WITH-DM
}
}
Expand Down
48 changes: 48 additions & 0 deletions packages/jsonConfig/with_dm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('node:fs');

const pack = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
pack.name = '@iobroker/json-config-with-dm';
pack.dependencies['@iobroker/dm-gui-components'] = pack.version;
fs.writeFileSync('./package.json', `${JSON.stringify(pack, null, 2)}\n`, 'utf8');

function getSpaces(line) {
let spaces = 0;
while (line[spaces] === ' ') {
spaces++;
}
return spaces;
}

const original = fs.readFileSync('./src/JsonConfigComponent/ConfigDeviceManager.tsx', 'utf8');
const file = original.split('\n');
let uncomment = null;
let comment = null;
for (let l = 0; l < file.length; l++) {
file[l] = file[l].replace(/\r/g, '');
if (file[l].includes('// START-WITH-DM')) {
uncomment = getSpaces(file[l]);
} else if (file[l].includes('// END-WITH-DM')) {
uncomment = null;
} else if (file[l].includes('// START-WITHOUT-DM')) {
comment = getSpaces(file[l]);
} else if (file[l].includes('// END-WITHOUT-DM')) {
comment = null;
} else if (comment !== null) {
if (file[l].substring(comment, comment + 2) !== '//') {
file[l] = `${file[l].substring(0, comment)}// ${file[l].substring(comment)}`;
}
} else if (uncomment !== null) {
if (file[l].substring(uncomment, uncomment + 2) === '//') {
file[l] = `${file[l].substring(0, uncomment)}${file[l].substring(uncomment + 3)}`;
}
}
}

while (file[file.length - 1].trim() === '') {
file.pop();
}
file.push('');

if (original !== file.join('\n')) {
fs.writeFileSync('./src/JsonConfigComponent/ConfigDeviceManager.tsx', file.join('\n'), 'utf8');
}
48 changes: 48 additions & 0 deletions packages/jsonConfig/without_dm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('node:fs');

const pack = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
pack.name = '@iobroker/json-config';
delete pack.dependencies['@iobroker/dm-gui-components'];
fs.writeFileSync('./package.json', `${JSON.stringify(pack, null, 2)}\n`, 'utf8');

function getSpaces(line) {
let spaces = 0;
while (line[spaces] === ' ') {
spaces++;
}
return spaces;
}

const original = fs.readFileSync('./src/JsonConfigComponent/ConfigDeviceManager.tsx', 'utf8');
const file = original.split('\n');
let uncomment = null;
let comment = null;
for (let l = 0; l < file.length; l++) {
file[l] = file[l].replace(/\r/g, '');
if (file[l].includes('// START-WITH-DM')) {
comment = getSpaces(file[l]);
} else if (file[l].includes('// END-WITH-DM')) {
comment = null;
} else if (file[l].includes('// START-WITHOUT-DM')) {
uncomment = getSpaces(file[l]);
} else if (file[l].includes('// END-WITHOUT-DM')) {
uncomment = null;
} else if (comment !== null) {
if (file[l].substring(comment, comment + 2) !== '//') {
file[l] = `${file[l].substring(0, comment)}// ${file[l].substring(comment)}`;
}
} else if (uncomment !== null) {
if (file[l].substring(uncomment, uncomment + 2) === '//') {
file[l] = `${file[l].substring(0, uncomment)}${file[l].substring(uncomment + 3)}`;
}
}
}

while (file[file.length - 1].trim() === '') {
file.pop();
}
file.push('');

if (original !== file.join('\n')) {
fs.writeFileSync('./src/JsonConfigComponent/ConfigDeviceManager.tsx', file.join('\n'), 'utf8');
}

0 comments on commit c65e964

Please sign in to comment.