Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rulesWithTags to oh-repeater #1724

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bundles/org.openhab.ui/doc/components/oh-repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Iterate over an array and repeat the children components in the default slot
<PropOption value="itemsWithTags" label="Items with tags in the &quot;itemTags&quot; parameter" />
<PropOption value="itemStateOptions" label="State options of the item specified in &quot;itemOptions&quot;" />
<PropOption value="itemCommandOptions" label="Command options of the item specified in &quot;itemOptions&quot;" />
<PropOption value="rulesWithTags" label="Rules with tags in the &quot;ruleTags&quot; parameter" />
</PropOptions>
</PropBlock>
<PropBlock type="TEXT" name="in" label="Source array">
Expand Down Expand Up @@ -76,6 +77,11 @@ Iterate over an array and repeat the children components in the default slot
Iterate over items with the given tags (comma-separated, for "itemsWithTags" source type)
</PropDescription>
</PropBlock>
<PropBlock type="TEXT" name="ruleTags" label="Rule Tags">
<PropDescription>
Iterate over rules with the given tags (comma-separated, for "rulesWithTags" source type)
</PropDescription>
</PropBlock>
<PropBlock type="TEXT" name="itemOptions" label="Item with Options">
<PropDescription>
Iterate over the state options or command options of this item (for "itemStateOptions" or "itemCommandOptions" source type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export default () => [
{ value: 'itemsInGroup', label: 'Member of the group defined in the "groupItem" parameter' },
{ value: 'itemsWithTags', label: 'Items with tags in the "itemTags" parameter' },
{ value: 'itemStateOptions', label: 'State options of the item specified in "itemOptions"' },
{ value: 'itemCommandOptions', label: 'Command options of the item specified in "itemOptions"' }
{ value: 'itemCommandOptions', label: 'Command options of the item specified in "itemOptions"' },
{ value: 'rulesWithTags', label: 'Rules with tags in the "ruleTags" parameter' },
]),
pt('in', 'Source array', 'Source array (for "array" source type)'),
pn('rangeStart', 'Range Start', 'Start of range (for "range" source type)'),
pn('rangeStop', 'Range Stop', 'End of range (for "range" source type)'),
pn('rangeStep', 'Range Step', 'Step of range (for "range" source type)'),
pi('groupItem', 'Group Item', 'Group item to whose members will be iterated (for "itemsInGroup" source type)'),
pt('itemTags', 'Item Tags', 'Iterate over items with the given tags (comma-separated, for "itemsWithTags" source type)'),
pt('ruleTags', 'Rule Tags', 'Iterate over rules with the given tags (comma-separated, for "rulesWithTags" source type)'),
stefan-hoehn marked this conversation as resolved.
Show resolved Hide resolved
pt('itemOptions', 'Item with Options', 'Iterate over the state options or command options of this item (for "itemStateOptions" or "itemCommandOptions" source type)'),
pt('fetchMetadata', 'Fetch Item Metadata Namespaces', 'Fetch the metadata from these namespaces (for "itemsInGroup" and "itemsWithTags" source types)'),
pt('filter', 'Filter expression', 'Specify an expression WITHOUT THE = PREFIX to filter the resulting array'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script>
import mixin from '../widget-mixin'
import { OhRepeaterDefinition } from '@/assets/definitions/widgets/system'
import { compareItems } from '@/components/widgets/widget-order'
import { compareItems, compareRules } from '@/components/widgets/widget-order'
import { Fragment } from 'vue-fragment'

export default {
Expand Down Expand Up @@ -75,14 +75,16 @@ export default {
const stop = this.config.rangeStop || 10
const step = this.config.rangeStep || 1
return Promise.resolve(Array(Math.ceil((stop + 1 - start) / step)).fill(start).map((x, y) => x + y * step))
} else if (this.config.sourceType === 'itemsWithTags' && this.config.itemTags) {
return this.$oh.api.get('/rest/items?metadata=' + this.config.fetchMetadata + '&tags=' + this.config.itemTags).then((d) => d.sort(compareItems))
} else if (this.config.sourceType === 'itemsInGroup') {
} else if (this.config.sourceType === 'itemsWithTags' && this.config.itemTags) {
return this.$oh.api.get('/rest/items?metadata=' + this.config.fetchMetadata + '&tags=' + this.config.itemTags).then((d) => Promise.resolve(d.sort(compareItems)))
} else if (this.config.sourceType === 'itemsInGroup') {
return this.$oh.api.get('/rest/items/' + this.config.groupItem + '?metadata=' + this.config.fetchMetadata + '&tags=' + this.config.itemTags).then((i) => Promise.resolve(i.members.sort(compareItems)))
} else if (this.config.sourceType === 'itemStateOptions') {
return this.$oh.api.get('/rest/items/' + this.config.itemOptions).then((i) => Promise.resolve((i.stateDescription) ? i.stateDescription.options : []))
} else if (this.config.sourceType === 'itemCommandOptions') {
return this.$oh.api.get('/rest/items/' + this.config.itemOptions).then((i) => Promise.resolve((i.commandDescription) ? i.commandDescription.commandOptions : []))
} else if (this.config.sourceType === 'rulesWithTags' && this.config.ruleTags) {
return this.$oh.api.get('/rest/rules?summary=true' + '&tags=' + this.config.ruleTags).then((r) => Promise.resolve(r.sort(compareRules)))
stefan-hoehn marked this conversation as resolved.
Show resolved Hide resolved
} else {
return Promise.resolve(this.config.in)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ export function compareParents (i1, i2) {
}
return modelOrder
}

export function compareRules (r1, r2) {
return r1.name.localeCompare(r2.name)
}