Skip to content

Commit

Permalink
Group publishers with a low number of vocabularies under "Others"
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed May 31, 2024
1 parent a6ed854 commit a7acff9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"aboutTitle": "Über diesen Dienst",
"quickSelection": "Schnellzugriff",
"publisher": "Herausgeber",
"publisherOthers": "Sonstige",
"vocabularyType": "Vokabulartyp",
"vocSearch": "Suche nach Vokabular",
"conceptSearch": "Suche nach Konzept"
Expand All @@ -13,6 +14,7 @@
"aboutTitle": "About This Service",
"quickSelection": "Quick Selection",
"publisher": "Publisher",
"publisherOthers": "Others",
"vocabularyType": "Vocabulary Type",
"vocSearch": "Searching for vocabulary",
"conceptSearch": "Searching for concept"
Expand Down
27 changes: 24 additions & 3 deletions src/client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,34 @@ import nkostypeConcepts from "@/nkostype-concepts.json"
export const quickSelection = computed(() => config.quickSelection.map(scheme => schemes.value?.find(s => jskos.compare(s, scheme))).filter(Boolean))

export const publisherSelection = computed(() => {
const publishers = new Set()
let publishers = []
schemes.value?.forEach(scheme => {
scheme.publisher?.forEach(publisher => {
publishers.add(publisher.uri || jskos.prefLabel(publisher))
const id = publisher.uri || jskos.prefLabel(publisher)
const name = jskos.prefLabel(publisher) || publisher.uri
const entry = publishers.find(p => p.id === id)
if (entry) {
entry.schemes.push(scheme)
} else {
publishers.push({
id, name, schemes: [scheme],
})
}
})
})
return [...publishers].sort()
publishers.sort((a, b) => b.name > a.name)
// Put all publishers with only one scheme (+ schemes without publisher) into "others"
const otherLimit = 3
const otherSchemes = publishers.filter(p => p.schemes.length < otherLimit).reduce((p, c) => p.concat(c.schemes), []).concat(schemes.value?.filter(s => !s.publisher?.length) || [])
if (otherSchemes.length) {
publishers = publishers.filter(p => p.schemes.length >= otherLimit)
publishers.push({
id: "__others__",
name: i18n.global.t("publisherOthers"),
schemes: otherSchemes,
})
}
return publishers
})

export const typeSelection = computed(() => {
Expand Down
14 changes: 8 additions & 6 deletions src/client/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const mode = computed(() => {
return "default"
})
const selectedPublisher = computed(() => route.query?.publisher ? publisherSelection.value.find(p => p.id === route.query?.publisher) : null)
const conceptSearchResults = ref([])
watch(() => route.query?.conceptSearch, async (value) => {
if (!value) {
Expand Down Expand Up @@ -57,7 +59,7 @@ const filteredSchemes = computed(() => {
}
switch (mode.value) {
case "publisher":
return schemes.value.filter(s => s.publisher?.find(p => p.uri === route.query.publisher || jskos.prefLabel(p) === route.query.publisher))
return selectedPublisher.value?.schemes || []
case "type":
return schemes.value.filter(s => s.type?.includes(route.query.type))
case "search":
Expand Down Expand Up @@ -113,7 +115,7 @@ watch(mode, () => {
{{ $t("quickSelection") }}
</h2>
<h2 v-else-if="mode === 'publisher'">
{{ $t("publisher") }}: {{ route.query.publisher }}
{{ $t("publisher") }}: {{ selectedPublisher?.name }}
</h2>
<h2 v-else-if="mode === 'type'">
{{ $t("vocabularyType") }}: {{ jskos.prefLabel(typeSelection.find(t => t.uri === route.query.type) || route.query.type) }}
Expand Down Expand Up @@ -173,11 +175,11 @@ watch(mode, () => {
<h2>{{ $t("publisher") }}</h2>
<div class="selection">
<RouterLink
v-for="publisher in publisherSelection"
:key="publisher"
v-for="{ id, name } in publisherSelection"
:key="id"
class="category-selection"
:to="`?publisher=${encodeURIComponent(publisher)}`">
{{ publisher }}
:to="`?publisher=${encodeURIComponent(id)}`">
{{ name }}
</RouterLink>
</div>
</div>
Expand Down

0 comments on commit a7acff9

Please sign in to comment.