Skip to content

Commit

Permalink
Thing details: Make link in Thing status description clickable (#2996)
Browse files Browse the repository at this point in the history
Resolve #2994

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng authored Jan 9, 2025
1 parent a9954c3 commit d16fe3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d16fe3a

Please sign in to comment.