From 2541ab81d92d398d80645b18e57eb5da80da8753 Mon Sep 17 00:00:00 2001 From: f-osorio Date: Tue, 10 Dec 2024 08:23:47 -0500 Subject: [PATCH 1/4] use `loadSimpleLookupKeyword()` for loading from suggest2 This existing function can handle preparing results from `suggest2` to be used in a simple lookup. --- .../panels/edit/fields/LookupSimple.vue | 50 ++++++++----------- src/lib/utils_network.js | 38 ++++++++++++-- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/components/panels/edit/fields/LookupSimple.vue b/src/components/panels/edit/fields/LookupSimple.vue index 19010a3e..15cf8517 100644 --- a/src/components/panels/edit/fields/LookupSimple.vue +++ b/src/components/panels/edit/fields/LookupSimple.vue @@ -357,6 +357,7 @@ export default { simpleLookupValues(){ // profileStore.setActiveField() + console.info("getting values") let values = this.profileStore.returnSimpleLookupValueFromProfile(this.guid, this.propertyPath) if (this.readOnly && values.length==0){ this.showField=false @@ -459,7 +460,7 @@ export default { }, - focused: function(){ + focused: async function(){ // set the state active field this.activeField = this.myGuid @@ -473,14 +474,22 @@ export default { } this.uri = this.structure.valueConstraint.useValuesFrom[0] - utilsNetwork.loadSimpleLookup(this.uri) - - + if (this.uri == "http://id.loc.gov/vocabulary/resourceComponents"){ + this.uri = "https://id.loc.gov/vocabulary/suggest2?q=*&memberOf=http://id.loc.gov/vocabulary/resourceComponents/collection_LanguageResource" + } + if (!this.uri.includes("suggest2")){ + utilsNetwork.loadSimpleLookup(this.uri) + } else { + console.info("doing the thing") + let uriParts = this.uri.split("/suggest2?q=") + console.info(uriParts) + 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 @@ -537,8 +546,14 @@ export default { } } - Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword]).forEach((v)=>{ + console.info("utilsNetwork.lookupLibrary", utilsNetwork.lookupLibrary) + console.info("this.uri: ", this.uri) + console.info("addKeyword: ", addKeyword) + console.info("!!!", utilsNetwork.lookupLibrary[this.uri+addKeyword]) + console.info("???", Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword])) + Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword]).forEach((v)=>{ + console.info("v: ", v) // the list has a special key metdata that contains more info if (v==='metadata'){return false} // no filter yet show first 25 @@ -594,9 +609,6 @@ export default { if (!recursive){ - - - if (this.uri.includes('id.loc.gov/vocabulary/')){ if (this.activeFilter.length>2){ @@ -712,8 +724,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() @@ -727,25 +737,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')){ @@ -876,19 +876,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{ diff --git a/src/lib/utils_network.js b/src/lib/utils_network.js index d750f771..14c98575 100644 --- a/src/lib/utils_network.js +++ b/src/lib/utils_network.js @@ -48,6 +48,7 @@ const utilsNetwork = { * @return {object} - returns the results processing */ loadSimpleLookup: async function(uris){ + console.info("loadSimpleLookup") // TODO make this better for multuple lookup list (might not be needed) if (!Array.isArray(uris)){ uris=[uris] @@ -56,7 +57,7 @@ const utilsNetwork = { let url = uri // TODO more checks here - if (!uri.includes('.json')){ + if (!uri.includes('.json') && !uri.includes("suggest2")){ url = url + '.json' } @@ -83,7 +84,8 @@ const utilsNetwork = { */ simpleLookupProcess: function(data,parentURI){ - + console.info("parentURI: ", parentURI) + console.info("processing the data", data) let dataProcessed = { // all the URIs will live here but also the metadata obj about the uris @@ -100,7 +102,7 @@ const utilsNetwork = { // something that has the parent URI data.forEach((d)=>{ - + console.info("d: ", 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 @@ -128,6 +130,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 @@ -167,6 +191,7 @@ const utilsNetwork = { */ loadSimpleLookupKeyword: async function(uris,keyword){ + console.info("loadSimpleLookupKeyword") if (!Array.isArray(uris)){ uris=[uris] } @@ -184,18 +209,20 @@ const utilsNetwork = { let url = `${uri}/suggest2/?q=${keyword}&count=25` + console.info("url: ", url) let r = await this.fetchSimpleLookup(url) + console.info("r", r) if (r.hits && r.hits.length==0){ url = `${uri}/suggest2/?q=${keyword}&count=25&searchtype=keyword` r = await this.fetchSimpleLookup(url) - } if (r.hits && r.hits.length>0){ for (let hit of r.hits){ + console.info("hit: ", hit) results.metadata.values[hit.uri] = {uri:hit.uri, label: [hit.suggestLabel], authLabel:hit.aLabel, code: [], displayLabel: [hit.suggestLabel] } results[hit.uri] = [hit.suggestLabel] } @@ -206,6 +233,8 @@ const utilsNetwork = { this.lookupLibrary[uris[0]+'KEYWORD'] = results + console.info("results: ", results) + return results }, @@ -252,7 +281,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 } From 67926c9cc1459104a6b8e306b06aec43a26f57c9 Mon Sep 17 00:00:00 2001 From: f-osorio Date: Tue, 10 Dec 2024 08:38:07 -0500 Subject: [PATCH 2/4] Clean console statements --- src/components/panels/edit/fields/LookupSimple.vue | 10 ---------- src/lib/utils_network.js | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/src/components/panels/edit/fields/LookupSimple.vue b/src/components/panels/edit/fields/LookupSimple.vue index 15cf8517..aa0aca22 100644 --- a/src/components/panels/edit/fields/LookupSimple.vue +++ b/src/components/panels/edit/fields/LookupSimple.vue @@ -357,7 +357,6 @@ export default { simpleLookupValues(){ // profileStore.setActiveField() - console.info("getting values") let values = this.profileStore.returnSimpleLookupValueFromProfile(this.guid, this.propertyPath) if (this.readOnly && values.length==0){ this.showField=false @@ -480,9 +479,7 @@ export default { if (!this.uri.includes("suggest2")){ utilsNetwork.loadSimpleLookup(this.uri) } else { - console.info("doing the thing") let uriParts = this.uri.split("/suggest2?q=") - console.info(uriParts) let results = await utilsNetwork.loadSimpleLookupKeyword(uriParts[0], uriParts[1]) utilsNetwork.lookupLibrary[this.uri] = results } @@ -546,14 +543,7 @@ export default { } } - console.info("utilsNetwork.lookupLibrary", utilsNetwork.lookupLibrary) - console.info("this.uri: ", this.uri) - console.info("addKeyword: ", addKeyword) - console.info("!!!", utilsNetwork.lookupLibrary[this.uri+addKeyword]) - console.info("???", Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword])) - Object.keys(utilsNetwork.lookupLibrary[this.uri+addKeyword]).forEach((v)=>{ - console.info("v: ", v) // the list has a special key metdata that contains more info if (v==='metadata'){return false} // no filter yet show first 25 diff --git a/src/lib/utils_network.js b/src/lib/utils_network.js index 14c98575..2414f1da 100644 --- a/src/lib/utils_network.js +++ b/src/lib/utils_network.js @@ -48,7 +48,6 @@ const utilsNetwork = { * @return {object} - returns the results processing */ loadSimpleLookup: async function(uris){ - console.info("loadSimpleLookup") // TODO make this better for multuple lookup list (might not be needed) if (!Array.isArray(uris)){ uris=[uris] @@ -84,8 +83,6 @@ const utilsNetwork = { */ simpleLookupProcess: function(data,parentURI){ - console.info("parentURI: ", parentURI) - console.info("processing the data", data) let dataProcessed = { // all the URIs will live here but also the metadata obj about the uris @@ -102,7 +99,6 @@ const utilsNetwork = { // something that has the parent URI data.forEach((d)=>{ - console.info("d: ", 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 @@ -191,7 +187,6 @@ const utilsNetwork = { */ loadSimpleLookupKeyword: async function(uris,keyword){ - console.info("loadSimpleLookupKeyword") if (!Array.isArray(uris)){ uris=[uris] } @@ -209,10 +204,8 @@ const utilsNetwork = { let url = `${uri}/suggest2/?q=${keyword}&count=25` - console.info("url: ", url) let r = await this.fetchSimpleLookup(url) - console.info("r", r) if (r.hits && r.hits.length==0){ url = `${uri}/suggest2/?q=${keyword}&count=25&searchtype=keyword` @@ -222,7 +215,6 @@ const utilsNetwork = { if (r.hits && r.hits.length>0){ for (let hit of r.hits){ - console.info("hit: ", hit) results.metadata.values[hit.uri] = {uri:hit.uri, label: [hit.suggestLabel], authLabel:hit.aLabel, code: [], displayLabel: [hit.suggestLabel] } results[hit.uri] = [hit.suggestLabel] } @@ -233,8 +225,6 @@ const utilsNetwork = { this.lookupLibrary[uris[0]+'KEYWORD'] = results - console.info("results: ", results) - return results }, From a9de98bf601351564a7160e2b5d2354fb07862e2 Mon Sep 17 00:00:00 2001 From: f-osorio Date: Tue, 10 Dec 2024 08:38:40 -0500 Subject: [PATCH 3/4] version++ --- src/stores/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/config.js b/src/stores/config.js index 9e121e67..1309141c 100644 --- a/src/stores/config.js +++ b/src/stores/config.js @@ -7,7 +7,7 @@ export const useConfigStore = defineStore('config', { versionMajor: 0, versionMinor: 16, - versionPatch: 28, + versionPatch: 29, regionUrls: { From 836ef7b5c6ddb4cb848536768c3ab067b7804d5f Mon Sep 17 00:00:00 2001 From: f-osorio Date: Tue, 10 Dec 2024 08:40:21 -0500 Subject: [PATCH 4/4] Remove hard coded URL Was used for testing without relying on the profile. --- src/components/panels/edit/fields/LookupSimple.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/panels/edit/fields/LookupSimple.vue b/src/components/panels/edit/fields/LookupSimple.vue index aa0aca22..409178b1 100644 --- a/src/components/panels/edit/fields/LookupSimple.vue +++ b/src/components/panels/edit/fields/LookupSimple.vue @@ -473,9 +473,6 @@ export default { } this.uri = this.structure.valueConstraint.useValuesFrom[0] - if (this.uri == "http://id.loc.gov/vocabulary/resourceComponents"){ - this.uri = "https://id.loc.gov/vocabulary/suggest2?q=*&memberOf=http://id.loc.gov/vocabulary/resourceComponents/collection_LanguageResource" - } if (!this.uri.includes("suggest2")){ utilsNetwork.loadSimpleLookup(this.uri) } else {