Thing details: Make link in Thing status description clickable (#2996)

Resolve #2994

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/3000/head
jimtng 2025-01-10 04:24:04 +10:00 committed by GitHub
parent a9954c3ee9
commit d16fe3ac60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,9 @@
import ThingStatusLabels from '@/assets/i18n/thing-status/en'
// Applies to Thing statusInfo.description containing a pattern of
// http(s)://[YOUROPENHAB]:[YOURPORT]/path
const linkRegex = /^(?<pretext>.*)http[^:]*:\/\/[^/]?YOUROPENHAB[^/]?:[^/]?YOURPORT[^/]?\/(?<path>\S+)(?<posttext>.*)$/
export default {
methods: {
thingStatusBadgeColor (statusInfo) {
@ -12,6 +16,19 @@ export default {
thingStatusBadgeText (statusInfo) {
if (statusInfo.statusDetail !== 'NONE') return ThingStatusLabels[statusInfo.statusDetail]
return statusInfo.status
},
thingStatusDescription (statusInfo) {
const description = statusInfo.description
if (statusInfo.statusDetail === 'CONFIGURATION_PENDING' && description) {
const result = linkRegex.exec(description)
if (result) {
const { pretext, path, posttext } = result.groups
if (!path) return description
const root = location.protocol + '//' + location.host
return `${pretext}<a href="${root}/${path}" target="_blank" class="link color-blue external">${root}/${path}</a>${posttext}`
}
}
return description
}
}
}

View File

@ -35,9 +35,7 @@
<div>
<strong>{{ (thing.statusInfo.statusDetail !== 'NONE') ? thing.statusInfo.statusDetail : '&nbsp;' }}</strong>
<br>
<div v-if="thing.statusInfo.description">
{{ thing.statusInfo.description }}
</div>
<div v-if="thingStatusDescription(thing.statusInfo)" v-html="thingStatusDescription(thing.statusInfo)" />
</div>
</f7-col>
</f7-block>