Skip to content

Commit

Permalink
Working on TS
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 24, 2024
1 parent 8cf2df1 commit 3c7f89d
Show file tree
Hide file tree
Showing 80 changed files with 5,064 additions and 2,919 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions src-editor/public/google-blockly/media/delete-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src-editor/public/google-blockly/media/foldout-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src-editor/public/google-blockly/media/resize-handle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { GenericBlock, type GenericBlockProps } from '../GenericBlock';
import type { RuleBlockDescription, RuleTagCardTitle } from '@/Components/RulesEditor/types';
import type {
RuleBlockConfigActionEmpty,
RuleBlockDescription,
RuleTagCardTitle,
} from '@/Components/RulesEditor/types';

class ActionEmpty extends GenericBlock {
constructor(props: GenericBlockProps) {
class ActionEmpty extends GenericBlock<RuleBlockConfigActionEmpty> {
constructor(props: GenericBlockProps<RuleBlockConfigActionEmpty>) {
super(props, ActionEmpty.getStaticData());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GenericBlock, type GenericBlockProps } from '../GenericBlock';
import type { RuleBlockConfigActionExec, RuleBlockDescription, RuleContext, RuleTagCardTitle } from '../../types';

class ActionExec extends GenericBlock {
constructor(props: GenericBlockProps) {
class ActionExec extends GenericBlock<RuleBlockConfigActionExec> {
constructor(props: GenericBlockProps<RuleBlockConfigActionExec>) {
super(props, ActionExec.getStaticData());
}

Expand All @@ -13,7 +13,8 @@ class ActionExec extends GenericBlock {
\t\tconsole.log(subActionVar${config._id});`;
}

renderDebug(debugMessage: { data: { exec: string } }): string {
// eslint-disable-next-line class-methods-use-this
renderDebug(debugMessage: { data: RuleBlockConfigActionExec }): string {
return `Exec: ${debugMessage.data.exec}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
RuleTagCardTitle,
} from '@/Components/RulesEditor/types';

class ActionFunction extends GenericBlock {
constructor(props: GenericBlockProps) {
class ActionFunction extends GenericBlock<RuleBlockConfigActionFunction> {
constructor(props: GenericBlockProps<RuleBlockConfigActionFunction>) {
super(props, ActionFunction.getStaticData());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
RuleTagCardTitle,
} from '@/Components/RulesEditor/types';

class ActionHTTPCall extends GenericBlock {
constructor(props: GenericBlockProps) {
class ActionHTTPCall extends GenericBlock<RuleBlockConfigActionHTTPCall> {
constructor(props: GenericBlockProps<RuleBlockConfigActionHTTPCall>) {
super(props, ActionHTTPCall.getStaticData());
}

Expand All @@ -18,6 +18,7 @@ class ActionHTTPCall extends GenericBlock {
\t\trequest(subActionVar${config._id});`;
}

// eslint-disable-next-line class-methods-use-this
renderDebug(debugMessage: { data: RuleBlockConfigActionHTTPCall }): string {
return `URL: ${debugMessage.data.url}`;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React from 'react';
import { I18n } from '@iobroker/adapter-react-v5';
import { GenericBlock, type GenericBlockProps } from '../GenericBlock';
import { renderValue } from '../../helpers/utils';
import type {
RuleBlockConfigActionOperationState,
RuleBlockDescription,
RuleInputAny,
RuleInputNameText,
RuleInputObjectID,
RuleInputSelect,
} from '@/Components/RulesEditor/types';

class ActionOperateStates extends GenericBlock<RuleBlockConfigActionOperationState> {
constructor(props: GenericBlockProps<RuleBlockConfigActionOperationState>) {
super(props, ActionOperateStates.getStaticData());
}

isAllTriggersOnState(): boolean {
return (
this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!this.props.userRules?.triggers?.find(item => item.id !== 'TriggerState')
);
}

static compile(config: RuleBlockConfigActionOperationState): string {
const oid1 = `const val2_${config._id} = (await getStateAsync("${config.oid1}")).val;`;
const oid2 = `const val1_${config._id} = (await getStateAsync("${config.oid2}")).val;`;

return `// ${config.oid1} ${config.operation} ${config.oid2} => ${config.oidResult}
\t\t ${oid1}
\t\t ${oid2}
\t\t_sendToFrontEnd(${config._id}, {val: val1_${config._id} ${config.operation} val2_${config._id}, ack: ${config.tagCard === 'update'}});
\t\tawait setStateAsync("${config.oidResult}", val1_${config._id} ${config.operation} val2_${config._id}, ${config.tagCard === 'update'});`;
}

renderDebug(debugMessage: { data: { ack: boolean; val: any } }): React.JSX.Element {
return (
<span>
{I18n.t('Set:')}{' '}
<span className={debugMessage.data.ack ? this.props.classes.valueAck : this.props.classes.valueNotAck}>
{renderValue(debugMessage.data.val)}
</span>
</span>
);
}

onTagChange(): void {
const inputs: RuleInputAny[] = [];

inputs.push({
nameRender: 'renderObjectID',
title: 'ID1',
attr: 'oid1',
defaultValue: '',
checkReadOnly: false,
} as RuleInputObjectID);

inputs.push({
nameRender: 'renderSelect',
// frontText: 'with',
options: [
{ value: '+', title: '+' },
{ value: '-', title: '-' },
{ value: '*', title: '*' },
{ value: '/', title: '/' },
],
doNotTranslate: true,
defaultValue: '+',
attr: 'operation',
} as RuleInputSelect);

inputs.push({
nameRender: 'renderObjectID',
title: 'ID2',
attr: 'oid2',
defaultValue: '',
checkReadOnly: false,
} as RuleInputObjectID);

inputs.push({
nameRender: 'renderNameText',
defaultValue: 'store in',
attr: 'textEqual',
} as RuleInputNameText);

inputs.push({
nameRender: 'renderObjectID',
attr: 'oidResult',
defaultValue: '',
checkReadOnly: true,
} as RuleInputObjectID);

this.setState({ inputs }, () =>
super.onTagChange(null, () => {
const settings = JSON.parse(JSON.stringify(this.state.settings));
this.props.onChange(settings);
}),
);
}

onValueChanged(_value: any, _attr: string): void {
this.onTagChange();
}

onUpdate(): void {
this.onTagChange();
}

static getStaticData(): RuleBlockDescription {
return {
acceptedBy: 'actions',
name: 'Operate two states',
id: 'ActionOperateStates',
icon: 'AddBox',
tagCardArray: ['control', 'update'],
title: 'Operations with two states',
};
}

// eslint-disable-next-line class-methods-use-this
getData(): RuleBlockDescription {
return ActionOperateStates.getStaticData();
}
}

export default ActionOperateStates;
Loading

0 comments on commit 3c7f89d

Please sign in to comment.