Skip to content

Commit

Permalink
Adjust components to display a registry
Browse files Browse the repository at this point in the history
In particular, add more logic to determine a registry's name so that we know the source of a scheme after changes in #670.
  • Loading branch information
stefandesu committed Mar 1, 2022
1 parent fdf90d9 commit 8f32669
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/components/RegistryInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:class="{
'fontWeight-heavy': $store.state.settings.settings.mappingBrowserShowRegistry[registry.uri] !== false
}">
{{ $jskos.prefLabel(registry, { language: locale }) }}
{{ registryName }}
</span>
<a
v-if="showDetails"
Expand Down Expand Up @@ -73,6 +73,7 @@

<script>
import RegistryNotation from "./RegistryNotation.vue"
import { getRegistryName } from "@/utils"
// Import mixins
import auth from "../mixins/auth.js"
Expand Down Expand Up @@ -104,6 +105,11 @@ export default {
default: false,
},
},
computed: {
registryName() {
return getRegistryName({ registry: this.registry, locale: this.locale })
},
},
}
</script>

Expand Down
12 changes: 3 additions & 9 deletions src/components/RegistryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<script>
import computed from "../mixins/computed.js"
import { getRegistryName } from "@/utils"
export default {
name: "RegistryName",
Expand All @@ -21,15 +22,8 @@ export default {
},
},
computed: {
registryName: function () {
let label = this.$jskos.prefLabel(this.registry, { language: this.locale })
let notation = this.$jskos.notation(this.registry)
if (label) {
return label.replace(notation, function () { return "<b>"+notation+"</b>" })
} else {
notation = 0
return notation || "?"
}
registryName() {
return getRegistryName({ registry: this.registry, locale: this.locale })
},
tooltipHtml() {
return this.$jskos.definition(this.registry, { language: this.locale }).join("<br>")
Expand Down
8 changes: 6 additions & 2 deletions src/components/RegistryNotation.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<template>
<div
v-if="notation"
v-b-tooltip.html.left="tooltip ? $jskos.prefLabel(registry, { language: locale }) : ''"
:class="{
[isCurrentRegistry ? 'registry-current-enabled' : 'registry-enabled']: !disabled,
'registry-notation-current': isCurrentRegistry,
}"
:style="`width: ${18 + 9 * ($jskos.notation(registry).length - 1)}px;`"
:style="`width: ${18 + 9 * (notation.length - 1)}px;`"
class="registry-notation">
{{ $jskos.notation(registry) }}
{{ notation }}
</div>
</template>

Expand Down Expand Up @@ -35,6 +36,9 @@ export default {
isCurrentRegistry() {
return this.$jskos.compareFast(this.registry, this.$store.getters.getCurrentRegistry)
},
notation() {
return this.$jskos.notation(this.registry) || ""
},
},
}
</script>
Expand Down
28 changes: 28 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import _ from "lodash"
import jskos from "jskos-tools"

export function getRegistryName({ registry, locale }) {
if (!registry) {
return ""
}
let label = jskos.prefLabel(registry, { language: locale, fallbackToUri: false })
if (label) {
return label
}
// Try _config (i.e. result of /status endpoint)
label = _.get(registry, "_config.title")
if (label) {
const baseUrl = _.get(registry, "_config.baseUrl")
return baseUrl ? `${label} (${baseUrl})` : label
}
// Try URI
if (registry.uri) {
return registry.uri
}
// Try API URL
label = _.get(registry, "_api.api")
if (label) {
return label
}
return ""
}

0 comments on commit 8f32669

Please sign in to comment.