Skip to content

Commit

Permalink
Merge pull request #43 from lcnetdev/minor-search-updates
Browse files Browse the repository at this point in the history
Minor search updates
  • Loading branch information
thisismattmiller authored Sep 23, 2024
2 parents 1f1a411 + fb9cc52 commit e36a9af
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/components/panels/edit/fields/LookupComplex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ export default {
this.authorityLookup = label
this.searchValue = label
this.displaySubjectModal = true
},
Expand Down
14 changes: 8 additions & 6 deletions src/components/panels/edit/modals/ComplexLookupModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
}
})
this.searchTimeout = window.setTimeout(async ()=>{
this.activeComplexSearchInProgress = true
this.activeComplexSearch = []
Expand All @@ -186,7 +185,6 @@
},
inputKeydown: function(event){
if (event.key==='ArrowDown'){
this.$refs.selectOptions.focus()
Expand Down Expand Up @@ -332,9 +330,13 @@
}
},
},
forceSearch: function(){
//reset the search and do it again
this.currentPage = 1
this.doSearch()
},
},
updated: function(){
if (this.authorityLookup == null){
Expand Down Expand Up @@ -448,10 +450,10 @@
</select>
</template>
<input class="lookup-input" v-model="searchValueLocal" ref="inputLookup" @keydown="inputKeydown($event)" type="text" />

<button @click="forceSearch()">Search</button>
<hr style="margin-top: 5px;">
<div>


<select size="100" ref="selectOptions" class="modal-entity-select" @change="selectChange($event)" @keydown="selectNav($event)">

<option v-if="activeComplexSearch.length == 0 && activeComplexSearchInProgress == false && initalSearchState != true">
Expand Down
30 changes: 23 additions & 7 deletions src/components/panels/edit/modals/SubjectEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,12 @@ methods: {
* @param {obj} incomingSubjects - the existing subject data
*/
buildLookupComponents: function(incomingSubjects){
this.typeLookup = []
for (let subjIdx in incomingSubjects){
this.componetLookup[subjIdx] = {}
let type = incomingSubjects[subjIdx]["@type"]
let lookUp
if (type.includes("http://www.loc.gov/mads/rdf/v1#Topic")){
Expand Down Expand Up @@ -800,13 +802,15 @@ methods: {
this.componetLookup[subjIdx][label] = {
label: incomingSubjects[subjIdx][lookUp][0][lookUp],
literal: incomingSubjects[subjIdx]["@id"] ? false : true,
uri: incomingSubjects[subjIdx]["@id"] ? incomingSubjects[subjIdx]["@id"] : null
uri: incomingSubjects[subjIdx]["@id"] ? incomingSubjects[subjIdx]["@id"] : null,
type: this.typeLookup[subjIdx]
}
} catch(err){
console.error(err)
}
}
},
/**
* Creates components from the search string
Expand All @@ -817,6 +821,7 @@ methods: {
buildComponents: function(searchString){
let subjectStringSplit = searchString.split('--')
let targetIndex = []
let componentLookUpCount = Object.keys(this.componetLookup).length
if (componentLookUpCount > 0){ //We are dealing with a hierarchical GEO and need to stitch some terms together
if (componentLookUpCount < subjectStringSplit.length){
Expand All @@ -825,6 +830,7 @@ methods: {
for (let j in this.componetLookup[i]) {
if (this.componetLookup[i][j].label.includes("--")){
target = this.componetLookup[i][j].label.replaceAll("-", "")
targetIndex = i // needs this to ensure the target will go into the search string in the right place
}
}
}
Expand All @@ -840,7 +846,8 @@ methods: {
subjectStringSplit.splice(matchIndx[i], 1)
}
// add the combined terms
subjectStringSplit.push(target)
// subjectStringSplit.push(target)
subjectStringSplit.splice(targetIndex, 0, target)
}
}
}
Expand All @@ -857,9 +864,15 @@ methods: {
let type = null
let literal = null
if (this.componetLookup[id] && this.componetLookup[id][ss]){
uri = this.componetLookup[id][ss].uri
if (this.componetLookup[id][ss]["type"] == "madsrdf:Geographic"){
literal = this.componetLookup[id][ss].literal = false
uri = this.componetLookup[id][ss].uri = null
}
literal = this.componetLookup[id][ss].literal
uri = this.componetLookup[id][ss].uri
}
if (this.typeLookup[id]){
Expand All @@ -885,6 +898,8 @@ methods: {
//make sure the searchString matches the components
this.subjectString = this.components.map((component) => component.label).join("--")
},
/**
Expand Down Expand Up @@ -1177,7 +1192,6 @@ methods: {
}, 10000)
searchString=searchString.replaceAll('','-')
searchStringFull=searchStringFull.replaceAll('','-')
Expand Down Expand Up @@ -1584,7 +1598,6 @@ methods: {
this.searchModeSwitch("WORKS")
}else if (this.searchMode == 'GEO' && event.key == "-"){
if (this.components.length>0){
let lastC = this.components[this.components.length-1]
console.log(lastC)
Expand Down Expand Up @@ -1754,7 +1767,9 @@ methods: {
this.componetLookup = {}
this.typeLookup={}
}
this.buildComponents(this.subjectString)
if (!this.subjectString.endsWith("-")){
this.buildComponents(this.subjectString)
}
this.renderHintBoxes()
Expand Down Expand Up @@ -2325,6 +2340,7 @@ updated: function() {
// this was opened from an existing subject
let profileData = this.profileData
let incomingSubjects
if (profileData && profileData.propertyLabel != "Subjects"){
incomingSubjects = false
} else if (profileData) {
Expand All @@ -2337,7 +2353,7 @@ updated: function() {
//When there is existing data, we need to make sure that the number of components matches
// the number subjects in the searchValue
if (this.searchValue && this.components.length != this.searchValue.split("--")){
if (this.searchValue && this.components.length != this.searchValue.split("--") && !this.searchValue.endsWith('-')){
this.buildLookupComponents(incomingSubjects)
this.buildComponents(this.searchValue)
Expand Down
22 changes: 19 additions & 3 deletions src/lib/utils_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const utilsNetwork = {
// a cache to keep previosuly requested vocabularies and lookups in memory for use again
lookupLibrary : {},

//abort controller
controller: null,

/**
* processes the data returned from id vocabularies
Expand Down Expand Up @@ -198,6 +200,13 @@ const utilsNetwork = {
* @return {object|string} - returns the JSON object parsed into JS Object or the text body of the response depending if it is json or not
*/
fetchSimpleLookup: async function(url, json) {
// if there is already a controller, send the abort command
// if (this.controller){
// this.controller.abort()
// }
// this.controller = new AbortController();
// const signal = this.controller.signal

url = url || config.profileUrl
if (url.includes("id.loc.gov")){
url = url.replace('http://','https://')
Expand All @@ -213,6 +222,7 @@ const utilsNetwork = {
// console.log("url:",url)
// console.log('options:',options)
try{
// let response = await fetch(url,options, {signal: signal});
let response = await fetch(url,options);
let data = null
if (response.status == 404){
Expand All @@ -224,10 +234,19 @@ const utilsNetwork = {
}else{
data = await response.json()
}
//reset the controller
// this.controller = false

//If the signal was abort, don't return anything
// if (signal.aborted){
// console.info("aborted")
// return false
// }
return data;
}catch(err){
//alert("There was an error retriving the record from:",url)
console.error(err);
this.controller = null
return false
// Handle errors here
}
Expand Down Expand Up @@ -283,8 +302,6 @@ const utilsNetwork = {
* @return {array} - An array of {@link searchComplexResult} results
*/
searchComplex: async function(searchPayload){


// console.log("searchPayload",searchPayload)


Expand Down Expand Up @@ -1949,7 +1966,6 @@ const utilsNetwork = {
* @return {} -
*/
subjectSearch: async function(searchVal,complexVal,mode){

let namesUrl = useConfigStore().lookupConfig['http://preprod.id.loc.gov/authorities/names'].modes[0]['NAF All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=4').replace("<OFFSET>", "1")+'&memberOf=http://id.loc.gov/authorities/subjects/collection_NamesAuthorizedHeadings'
let namesUrlSubdivision = useConfigStore().lookupConfig['http://preprod.id.loc.gov/authorities/names'].modes[0]['NAF All'].url.replace('<QUERY>',searchVal).replace('&count=25','&count=5').replace("<OFFSET>", "1")+'&memberOf=http://id.loc.gov/authorities/subjects/collection_Subdivisions'

Expand Down

0 comments on commit e36a9af

Please sign in to comment.