Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept page mappings: style and visibility fixes #1613

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions resource/js/concept-mappings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global Vue */
/* global fetchWithAbort */

const conceptMappingsApp = Vue.createApp({
data () {
Expand All @@ -9,15 +10,29 @@ const conceptMappingsApp = Vue.createApp({
provide: {
content_lang: window.SKOSMOS.content_lang
},
computed: {
hasMappings () {
return Object.keys(this.mappings).length > 0
}
},
methods: {
loadMappings () {
fetch('rest/v1/' + window.SKOSMOS.vocab + '/mappings?uri=' + window.SKOSMOS.uri + '&external=true&clang=' + window.SKOSMOS.lang + '&lang=' + window.SKOSMOS.content_lang)
this.mappings = [] // clear mappings before starting to load new ones
const url = 'rest/v1/' + window.SKOSMOS.vocab + '/mappings?uri=' + window.SKOSMOS.uri + '&external=true&clang=' + window.SKOSMOS.lang + '&lang=' + window.SKOSMOS.content_lang
fetchWithAbort(url, 'concept')
.then(data => {
return data.json()
})
.then(data => {
this.mappings = this.group_by(data.mappings, 'typeLabel')
})
.catch(error => {
if (error.name === 'AbortError') {
console.log('Fetching of mappings aborted')
} else {
throw error
}
})
},
// from https://stackoverflow.com/a/71505541
group_by (arr, prop) {
Expand All @@ -37,7 +52,9 @@ const conceptMappingsApp = Vue.createApp({
},
template: `
<div v-load-concept-page="loadMappings">
<concept-mappings :mappings="mappings" v-if="mappings.length !== 0"></concept-mappings>
<div v-if="hasMappings" class="main-content-section p-5">
<concept-mappings :mappings="mappings"></concept-mappings>
</div>
</div>
`
})
Expand Down
34 changes: 33 additions & 1 deletion resource/js/partial-page-load.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
const fetchWithAbort = (function () {
const controllers = {}

return function (url, category, options = {}) {
// Abort the previous request in the same category if it exists
if (controllers[category]) {
controllers[category].abort()
}

// Create a new AbortController instance for this request
controllers[category] = new AbortController()

// Add the AbortController signal to the fetch options
options.signal = controllers[category].signal

// Perform the fetch request
return fetch(url, options)
.then(response => {
// Remove the abort controller after the request is done
delete controllers[category]
return response
})
}
})()

const updateMainContent = (conceptHTML) => {
// concept card
const conceptMainContent = conceptHTML.querySelectorAll('#main-content > :not(#concept-mappings)') // all elements from concept card except concept mappings
Expand Down Expand Up @@ -53,7 +78,7 @@ const partialPageLoad = (event, pageUri) => {
event.preventDefault()

// fetching html content of the concept page
fetch(pageUri)
fetchWithAbort(pageUri, 'concept')
.then(data => {
return data.text()
})
Expand All @@ -77,5 +102,12 @@ const partialPageLoad = (event, pageUri) => {
const event = new Event('loadConceptPage')
document.dispatchEvent(event)
})
.catch(error => {
if (error.name === 'AbortError') {
console.log('Fetch aborted for ' + pageUri)
} else {
throw error
}
})
}
/* eslint-disable no-unused-vars */
12 changes: 10 additions & 2 deletions resource/js/tab-alpha.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Vue */
/* global partialPageLoad, getConceptURL */
/* global partialPageLoad, getConceptURL, fetchWithAbort */

const tabAlphaApp = Vue.createApp({
data () {
Expand Down Expand Up @@ -47,14 +47,22 @@ const tabAlphaApp = Vue.createApp({
},
loadConcepts (letter) {
this.loadingConcepts = true
fetch('rest/v1/' + window.SKOSMOS.vocab + '/index/' + letter + '?lang=' + window.SKOSMOS.lang + '&limit=50')
const url = 'rest/v1/' + window.SKOSMOS.vocab + '/index/' + letter + '?lang=' + window.SKOSMOS.lang + '&limit=50'
fetchWithAbort(url, 'alpha')
.then(data => {
return data.json()
})
.then(data => {
this.indexConcepts = data.indexConcepts
this.loadingConcepts = false
})
.catch(error => {
if (error.name === 'AbortError') {
console.log('Fetch aborted for letter ' + letter)
} else {
throw error
}
})
}
},
template: `
Expand Down
2 changes: 1 addition & 1 deletion src/view/concept-card.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
</div>
</div>
<!-- appendix / concept mapping properties -->
<div id="concept-mappings" class="main-content-section p-5">
<div id="concept-mappings">
</div>

</div>
Expand Down
Loading