Skip to content

Commit e96e4b7

Browse files
committed
improvements
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
1 parent a759d21 commit e96e4b7

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

bundles/org.openhab.ui.cometvisu/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@
4141
<attribute name="maven.pomderived" value="true"/>
4242
</attributes>
4343
</classpathentry>
44+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
45+
<attributes>
46+
<attribute name="optional" value="true"/>
47+
<attribute name="test" value="true"/>
48+
</attributes>
49+
</classpathentry>
4450
<classpathentry kind="output" path="target/classes"/>
4551
</classpath>

bundles/org.openhab.ui/web/src/components/persistence/item-persistence-details.vue

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,24 @@ export default {
4747
persistedBadges () {
4848
const badges = {}
4949
this.services.forEach((service) => {
50-
badges[service.id] = service.persisted ? (Number.isInteger(service.persisted.count) ? service.persisted.count : 'values') : null
50+
const persisted = service.persisted
51+
if (!persisted) {
52+
// Query for persistence items not supported
53+
badges[service.id] = null
54+
} else if (persisted.count != null && Number.isInteger(Number(persisted.count))) {
55+
// Show numeric count when available
56+
badges[service.id] = String(persisted.count)
57+
} else if (persisted.name) {
58+
// No numeric count, but persisted value(s): show a presence indicator (empty badge)
59+
badges[service.id] = ' '
60+
} else {
61+
// Item has not been persisted
62+
// badges[service.id] = '0'
63+
// TODO: Currently, the API call does not distinguish between API call not supported for service and item not persisted.
64+
// To avoid showing misleading information, don't show badge if we don't get anything back (should be covered by first case if REST API is fixed.)
65+
// This can be reverted to showing 0 if the API is fixed.
66+
badges[service.id] = null
67+
}
5168
})
5269
return badges
5370
}
@@ -65,9 +82,9 @@ export default {
6582
async load () {
6683
this.loaded = false
6784
const services = await this.$oh.api.get('/rest/persistence')
68-
this.services = await Promise.all(
85+
this.services = (await Promise.all(
6986
services.map((service) => this.loadService(service))
70-
).sort((s1, s2) => s1.label.localCompare(s2.label))
87+
)).sort((s1, s2) => s1.label.localeCompare(s2.label))
7188
this.loaded = true
7289
},
7390
async loadService (service) {
@@ -77,22 +94,28 @@ export default {
7794
} catch (err) {
7895
if (err?.response?.status === 404) {
7996
// No configuration yet, continue with an empty one
97+
} else {
98+
console.debug('Error loading persistence config for', service.id, err)
8099
}
81100
}
82101
83-
let itemsPersisted = []
102+
let itemsPersisted = null
84103
try {
85104
itemsPersisted = await this.$oh.api.get('/rest/persistence/items?serviceId=' + service.id)
86105
} catch (err) {
87-
// Do nothing if not found
106+
if (err?.response?.status === 400) {
107+
// Not supported for service, leave itemsPersisted null
108+
} else {
109+
console.debug('Error loading persistence items for', service.id, err)
110+
}
88111
}
89112
90113
return {
91114
...service,
92115
configs: serviceConfig.configs || [],
93116
aliases: serviceConfig.aliases,
94117
editable: serviceConfig.editable === undefined ? true : serviceConfig.editable,
95-
persisted: itemsPersisted.find((item) => item.name === this.item.name) || null
118+
persisted: itemsPersisted ? (itemsPersisted.find((item) => item.name === this.item.name) || {}) : null
96119
}
97120
},
98121
serviceStrategies (serviceId) {

0 commit comments

Comments
 (0)