Skip to content

Commit

Permalink
Added "adapters" setting for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Jul 12, 2024
1 parent ce52bf0 commit ccc5a45
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ onChange: async (field, data, changeData, socket) => {
- `type`: default value is '' and just an input field. It can have the following values:
- `instance` - Instance selector. It could have additional settings:
- `adapter` - [optional] Additionally, you can provide `adapter` to filter the instances of specific adapter. With special adapter name `_dataSources` you can get all adapters with flag `common.getHistory`.
- `adapters` - [optional] Additionally, you can provide `adapters` to filter the instances of specific adapters. It is an array of adapter names.
- `isShort` - [optional] In this case only instance number (like `0`) is shown and not `history.0`. It can be set to true only with non-empty `adapter` setting.
- `number` - Number input. It could have additional settings:
- `min` - [optional] minimum value
Expand Down
35 changes: 28 additions & 7 deletions packages/iobroker.vis-2/src/src/Attributes/Widget/WidgetField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,39 @@ const WidgetField = (props: WidgetFieldProps) => {
idShort: obj._id.split('.').pop(),
name: obj.common.name,
icon: obj.common.icon,
}));
}))
.sort((a, b) =>
(a.name > b.name ? 1 : (a.name < b.name ? -1 : 0)));
setInstances(inst);
});
} else if (Array.isArray(field.adapters)) {
props.socket.getAdapterInstances('')
.then(_instances => {
const inst = _instances
.filter(obj => field.adapters.includes(obj.common.name))
.map(obj => ({
id: obj._id.replace('system.adapter.', ''),
idShort: obj._id.split('.').pop(),
name: obj.common.name,
icon: obj.common.icon,
}))
.sort((a, b) =>
(a.name > b.name ? 1 : (a.name < b.name ? -1 : 0)));
setInstances(inst);
});
} else {
props.socket.getAdapterInstances(field.adapter || '')
.then(_instances => {
const inst = _instances.map(obj => ({
id: obj._id.replace('system.adapter.', ''),
idShort: obj._id.split('.').pop(),
name: obj.common.name,
icon: obj.common.icon,
}));
const inst = _instances
.map(obj => ({
id: obj._id.replace('system.adapter.', ''),
idShort: obj._id.split('.').pop(),
name: obj.common.name,
icon: obj.common.icon,
}))
.sort((a, b) =>
(a.name > b.name ? 1 : (a.name < b.name ? -1 : 0)));

setInstances(inst);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import React from 'react';
import { Tab, Tabs } from '@mui/material';
import { Icon } from '@iobroker/adapter-react-v5';

import type { RxRenderWidgetProps } from '@iobroker/types-vis-2';
// eslint-disable-next-line import/no-cycle
import VisRxWidget, { type VisRxWidgetState } from '../../visRxWidget';
import type {RxRenderWidgetProps} from "@iobroker/types-vis-2";

interface RxData {
show_tabs: number;
Expand Down
5 changes: 2 additions & 3 deletions packages/iobroker.vis-2/src/src/Vis/visRxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
* (Free for non-commercial use).
*/

import type { Component } from 'react';
import React from 'react';
import React, { type Component } from 'react';
import {
Card,
CardContent,
} from '@mui/material';

import { type LegacyConnection, I18n, Icon } from '@iobroker/adapter-react-v5';

import {
import type {
Project,
AnyWidgetId,
RxWidgetInfo,
Expand Down
2 changes: 2 additions & 0 deletions packages/iobroker.vis-2/src/src/Vis/visWidgetsCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export type RxWidgetInfoAttributesFieldAll = {
filter?: ObjectBrowserCustomFilter | ObjectBrowserType | ((data: WidgetData, index: number) => Record<string, any>) | string;
/** Additionally, you can provide `adapter` to filter the instances of specific adapter. With special adapter name `_dataSources` you can get all adapters with flag `common.getHistory`. */
readonly adapter?: string;
/** Additionally, you can provide `adapters` to filter the instances of specific adapters. */
readonly adapters?: string[];
/** In this case, only instance number (like `0`) is shown and not `history.0`. It can be set to true only with non-empty `adapter` setting. */
readonly iShort?: boolean;
/** Options for a select type */
Expand Down
2 changes: 2 additions & 0 deletions packages/types-vis-2/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export type RxWidgetInfoAttributesFieldInstance = {
readonly default?: string;
/** Additionally, you can provide `adapter` to filter the instances of specific adapter. With special adapter name `_dataSources` you can get all adapters with flag `common.getHistory`. */
readonly adapter?: string;
/** Additionally, you can provide `adapters` to filter the instances of specific adapters. */
readonly adapters?: string;
/** In this case, only instance number (like `0`) is shown and not `history.0`. It can be set to true only with non-empty `adapter` setting. */
readonly iShort?: boolean;

Expand Down

0 comments on commit ccc5a45

Please sign in to comment.