Skip to content

Commit

Permalink
Merge pull request #160 from lcnetdev/bfp-128-language-lookups
Browse files Browse the repository at this point in the history
[BFP 128] language lookups
  • Loading branch information
f-osorio authored Dec 10, 2024
2 parents b66ccb7 + 4a8592f commit 5f12f77
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
37 changes: 9 additions & 28 deletions src/components/panels/edit/fields/LookupSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export default {
},
focused: function(){
focused: async function(){
// set the state active field
this.activeField = this.myGuid
Expand All @@ -473,14 +473,17 @@ export default {
}
this.uri = this.structure.valueConstraint.useValuesFrom[0]
utilsNetwork.loadSimpleLookup(this.uri)
if (!this.uri.includes("suggest2")){
utilsNetwork.loadSimpleLookup(this.uri)
} else {
let uriParts = this.uri.split("/suggest2?q=")
let results = await utilsNetwork.loadSimpleLookupKeyword(uriParts[0], uriParts[1])
utilsNetwork.lookupLibrary[this.uri] = results
}
},
actionButtonCommand: function(cmd){
this.$refs.input.focus()
},
// Takes the list of values from this lookup uri and filters it based on the input
Expand Down Expand Up @@ -538,7 +541,6 @@ export default {
}
Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword]).forEach((v)=>{
// the list has a special key metdata that contains more info
if (v==='metadata'){return false}
// no filter yet show first 25
Expand Down Expand Up @@ -594,9 +596,6 @@ export default {
if (!recursive){
if (this.uri.includes('id.loc.gov/vocabulary/')){
if (this.activeFilter.length>2){
Expand Down Expand Up @@ -712,8 +711,6 @@ export default {
},
keyDownEvent: function(event, reposLeft){
if (event && event.keyCode == 220 && event.ctrlKey == true){
let id = `action-button-${event.target.dataset.guid}`
document.getElementById(id).click()
Expand All @@ -727,25 +724,15 @@ export default {
if (reposLeft){
this.findSelectListTime = window.setInterval(()=>{
if (this.$refs.selectlist && this.$refs.selectlist.style){
window.clearTimeout(this.findSelectListTime)
var rect = event.target.getBoundingClientRect();
this.$refs.selectlist.style.left = rect.left + 'px'
}
},100)
}
this.activeValue = event.target.value
if (event && event.key && this.displayAutocomplete == true && (event.key==='ArrowUp' || event.key==='ArrowDown')){
Expand Down Expand Up @@ -876,19 +863,13 @@ export default {
event.preventDefault()
}else if (event.target.value == ''){
} else if (event.target.value == '') {
this.activeFilter = ''
this.activeValue = ''
this.activeSelect = ''
this.displayAutocomplete=false
}
if (this.displayAutocomplete){
// this.$store.dispatch("disableMacroNav")
}else{
Expand Down
28 changes: 23 additions & 5 deletions src/lib/utils_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const utilsNetwork = {
let url = uri

// TODO more checks here
if (!uri.includes('.json')){
if (!uri.includes('.json') && !uri.includes("suggest2")){
url = url + '.json'
}

Expand All @@ -83,7 +83,6 @@ const utilsNetwork = {
*/

simpleLookupProcess: function(data,parentURI){

let dataProcessed = {

// all the URIs will live here but also the metadata obj about the uris
Expand All @@ -100,7 +99,6 @@ const utilsNetwork = {
// something that has the parent URI

data.forEach((d)=>{

let label = null
let labelData = null // it has a URI and that URI is not the parent uri
// assume it is one of the values we want
Expand Down Expand Up @@ -128,6 +126,28 @@ const utilsNetwork = {
label = labelWithCode
}
})
} else if (parentURI.includes("suggest2") && d.uri && d.aLabel) {
this.possibleLabelURIs.forEach((result)=>{
// if it has this label URI and does not yet have a label
if ( !dataProcessed[result.uri] ){

label = d.aLabel

let labelWithCode = []
// build the metadata for each item that will go along it with structured fields
let metadata = {uri:d.uri, label: [], code: [], displayLabel: [] }
label.forEach((l)=>{
labelWithCode.push(`${l} (${d.uri.split('/').pop()})`)
metadata.displayLabel.push(`${l.trim()} (${d.uri.split('/').pop()})`)

metadata.label.push(l.trim())
metadata.code.push(d.uri.split('/').pop())

})
labelData = metadata
label = labelWithCode
}
})
}else if (d['http://id.loc.gov/ontologies/RecordInfo#recordStatus']){
// this is just a record info blank node, skip it
return false
Expand Down Expand Up @@ -190,7 +210,6 @@ const utilsNetwork = {
if (r.hits && r.hits.length==0){
url = `${uri}/suggest2/?q=${keyword}&count=25&searchtype=keyword`
r = await this.fetchSimpleLookup(url)

}


Expand Down Expand Up @@ -252,7 +271,6 @@ const utilsNetwork = {
}catch(err){
//alert("There was an error retriving the record from:",url)
console.error("There was an error retriving the record from ", url, ". Likely from the search being aborted because the user was typing.");

return false
// Handle errors here
}
Expand Down
3 changes: 1 addition & 2 deletions src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const useConfigStore = defineStore('config', {

versionMajor: 0,
versionMinor: 17,
versionPatch: 0,

versionPatch: 1,

regionUrls: {

Expand Down

0 comments on commit 5f12f77

Please sign in to comment.