Skip to content

Commit bdfb271

Browse files
authored
Fix repeater range step and stop (openhab#3440)
Fixes two small issues when using the `sourceType: range` of oh-repeater. 1) step values less than one or with decimal components improperly calculate number of elements in the final array (go beyond stop value to next whole number). 2) stop value cannot be set to 0 (falsy value results in default value of 10 for stop). Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
1 parent b11d06d commit bdfb271

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

bundles/org.openhab.ui/web/src/components/widgets/system/oh-repeater.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export default {
9191
let sourceResult
9292
if (this.config.sourceType === 'range') {
9393
const start = this.config.rangeStart || 0
94-
const stop = this.config.rangeStop || 10
94+
const stop = isNaN(this.config.rangeStop) ? 10 : this.config.rangeStop
9595
const step = this.config.rangeStep || 1
96-
sourceResult = Promise.resolve(Array(Math.ceil((stop + 1 - start) / step)).fill(start).map((x, y) => x + y * step))
96+
sourceResult = Promise.resolve(Array(Math.floor((stop + step - start) / step)).fill(start).map((x, y) => x + y * step))
9797
} else if (this.config.sourceType === 'itemsWithTags' && this.config.itemTags) {
9898
sourceResult = this.$oh.api.get('/rest/items?metadata=' + this.config.fetchMetadata + '&tags=' + this.config.itemTags).then((d) => Promise.resolve(d.sort(compareItems)))
9999
this.sourceCache = (this.config.cacheSource) ? sourceResult : null

0 commit comments

Comments
 (0)