Skip to content

Commit 0e6fe03

Browse files
First implementation search links in mappingDetail (#743)
1 parent 1a144da commit 0e6fe03

File tree

5 files changed

+97
-16
lines changed

5 files changed

+97
-16
lines changed

config/cocoda.default.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@
396396
"prefLabel": {
397397
"en": "K10plus"
398398
},
399-
"url": "https://opac.k10plus.de/DB=2.299/CLK?IKT=5004&TRM={notation}",
399+
"url": "https://opac.k10plus.de/DB=2.299/CMD?ACT=SRCHA&IKT=5004&TRM={notation}",
400+
"separator": "+and+",
400401
"schemeUris": [
401402
"http://bartoc.org/en/node/18785"
402403
]

src/components/ConceptDetail.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ export default {
513513
async updateSearchLinks(searchLinkInfo) {
514514
this.searchLinks = await this.$store.dispatch("getSearchLinks", {
515515
scheme: getItem(this.selected.scheme[this.isLeft]),
516-
...searchLinkInfo,
516+
info: searchLinkInfo,
517517
})
518518
},
519519
sortByLanguage(a, b) {

src/components/MappingDetail.vue

+31
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@
6868
</p>
6969
</b-col>
7070
</b-row>
71+
<!-- Seachr Links -->
72+
<b-row>
73+
<b-col cols="3">
74+
{{ $t('conceptDetail.searchLinks') }}:
75+
</b-col>
76+
<b-col
77+
v-if="searchLinks.length"
78+
:key="`MappingDetail-searchLinks`"
79+
:title="$t('conceptDetail.searchLinks')">
80+
<ul style="margin-bottom: 0;">
81+
<li
82+
v-for="(searchLink, index) of searchLinks"
83+
:key="`searchLink-${index}`">
84+
<a
85+
:href="searchLink.url"
86+
target="_blank">
87+
{{ searchLink.label }}
88+
</a>
89+
</li>
90+
</ul>
91+
</b-col>
92+
</b-row>
7193
<!-- Mapping Type -->
7294
<b-row v-if="mapping.type && mapping.type.length">
7395
<b-col cols="3">
@@ -244,6 +266,15 @@ export default {
244266
default: null,
245267
},
246268
269+
/**
270+
* Search Links Array
271+
*/
272+
searchLinks: {
273+
type: Array,
274+
default: null,
275+
},
276+
277+
247278
},
248279
computed: {
249280
catalogEnrichmentLink() {

src/components/MappingEditor.vue

+31-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@
232232
<!-- Mapping detail modal -->
233233
<mapping-detail
234234
ref="mappingDetail"
235-
:mapping="mapping" />
235+
:mapping="mapping"
236+
:search-links="searchLinks" />
236237
<div
237238
class="mappingEditor-infoIcon">
238239
<font-awesome-icon
@@ -281,6 +282,11 @@ export default {
281282
name: "MappingEditor",
282283
components: { ItemName, MappingTypeSelection, ComponentSettings, MappingDetail, RegistryNotation, ConcordanceSelection, AnnotationPopover },
283284
mixins: [auth, objects, dragandrop, hotkeys, computed],
285+
data () {
286+
return {
287+
searchLinks: [],
288+
}
289+
},
284290
computed: {
285291
mapping() {
286292
return this.$store.state.mapping.mapping
@@ -456,6 +462,18 @@ export default {
456462
currentGuidelines() {
457463
return (this.config.guidelines || []).find(g => this.$jskos.compare(g.fromScheme, getItem(this.selected.scheme[true])) && this.$jskos.compare(g.toScheme, getItem(this.selected.scheme[false])))
458464
},
465+
searchLinkInfo() {
466+
return this.items.map(item => ({
467+
uri: item?.uri,
468+
language: this.locale,
469+
notation: this.$jskos.notation(item),
470+
prefLabel: this.$jskos.prefLabel(item, { fallbackToUri: false }),
471+
}))
472+
},
473+
items() {
474+
return this.$store.getters["mapping/getConcepts"](false).map(getItem)
475+
// return getItem(this.selected.concept[true]) // Correct!
476+
},
459477
},
460478
watch: {
461479
mappingEncoded() {
@@ -488,14 +506,26 @@ export default {
488506
mapping() {
489507
this.setCreator()
490508
},
509+
searchLinkInfo(newValue, oldValue) {
510+
if (!_.isEqual(newValue, oldValue)) {
511+
this.updateSearchLinks(newValue)
512+
}
513+
},
491514
},
492515
mounted() {
493516
// Enable shortcuts
494517
this.enableShortcuts()
495518
// Set creator (fixes #560)
496519
this.setCreator()
520+
this.updateSearchLinks(this.searchLinkInfo)
497521
},
498522
methods: {
523+
async updateSearchLinks(searchLinkInfo) {
524+
this.searchLinks = await this.$store.dispatch("getSearchLinks", {
525+
scheme: getItem(this.selected.scheme[true]),
526+
info: searchLinkInfo,
527+
})
528+
},
499529
refreshAnnotations(data) {
500530
if (data.uri === this.original.uri && this.original.registry) {
501531
// Send mapping refresh request

src/store/actions.js

+32-13
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,41 @@ export default {
335335
}
336336
return conceptLists
337337
},
338-
339-
async getSearchLinks({ state }, { scheme, ...info }) {
338+
async getSearchLinks({ state }, { scheme, info }) {
340339
let searchLinks = []
340+
const infoArray = Array.isArray(info) ? info : [info]
341+
let notationValues = infoArray.map(item => item.notation)
342+
343+
for (let infoItem of infoArray) {
344+
for (let searchLink of (state.config.searchLinks || []).filter(l => l.schemes.length === 0 || jskos.isContainedIn(scheme, l.schemes))) {
345+
346+
// Construct URL
347+
let url = searchLink.url + (searchLink.urlSuffix ?? "")
348+
349+
// Replace notation values
350+
const notationReplacement = notationValues.length > 0
351+
? notationValues.join(searchLink.separator) // Use default separator if not provided
352+
: notationValues[0]
353+
354+
url = url.replace(/{notation}/g, notationReplacement)
355+
356+
// Replace other keys
357+
_.forOwn(infoItem, (value, key) => {
358+
if (key !== "notation") { // Skip notation as it is handled above
359+
url = url.replace(new RegExp(`{${key}}`, "g"), value)
360+
}
361+
})
362+
363+
// Add URL and label to searchLinks
364+
searchLinks.push({
365+
url,
366+
label: jskos.prefLabel(searchLink, { language: infoItem.locale }),
367+
})
368+
}
341369

342-
for (let searchLink of (state.config.searchLinks || []).filter(l => l.schemes.length === 0 || jskos.isContainedIn(scheme, l.schemes))) {
343-
// Construct URL
344-
let url = searchLink.url + (searchLink.urlSuffix ?? "")
345-
_.forOwn(info, (value, key) => {
346-
// Replace all occurrences of {key} with value
347-
url = _.replace(url, new RegExp(`{${key}}`, "g"), value)
348-
})
349-
searchLinks.push({
350-
url,
351-
label: jskos.prefLabel(searchLink, { language: info.locale }),
352-
})
353370
}
371+
372+
354373
// Add custom WebDewey links for DDC
355374
if (jskos.compare(scheme, { uri: "http://bartoc.org/en/node/241" })) {
356375
let recordIdPrefix = "ddc"

0 commit comments

Comments
 (0)