forked from OpenCatalogi/opencatalogi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed some merge conflicts that gitkraken forgot about
- Loading branch information
1 parent
ef56ca9
commit 8487bcd
Showing
3 changed files
with
75 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,65 @@ | ||
/* eslint-disable no-console */ | ||
import { defineStore } from 'pinia' | ||
|
||
export const useSearchStore = defineStore( | ||
'search', { | ||
state: () => ({ | ||
search: '', | ||
searchResults: '', | ||
searchError: '', | ||
}), | ||
actions: { | ||
setSearch(search) { | ||
this.search = search | ||
console.log('Active search set to ' + search) | ||
}, | ||
setSearchResults(searchResults) { | ||
this.searchResults = searchResults | ||
console.log('Active search set to ' + searchResults) | ||
}, | ||
/* istanbul ignore next */ // ignore this for Jest until moved into a service | ||
getSearchResults() { | ||
fetch( | ||
'/index.php/apps/opencatalogi/api/search?_search=' + this.search, | ||
{ | ||
method: 'GET', | ||
export const useSearchStore = defineStore('search', { | ||
state: () => ({ | ||
search: '', | ||
metadata: {}, | ||
searchResults: '', | ||
searchError: '', | ||
}), | ||
actions: { | ||
setSearch(search) { | ||
this.search = search | ||
console.log('Active search set to ' + search) | ||
}, | ||
toggleMetadataSearch(metadataId, value = undefined) { | ||
this.metadata[metadataId] = value || !this.metadata[metadataId] || false | ||
}, | ||
setSearchResults(searchResults) { | ||
this.searchResults = searchResults | ||
console.log('Active search set to ' + searchResults) | ||
}, | ||
/* istanbul ignore next */ // ignore this for Jest until moved into a service | ||
getSearchResults() { | ||
const enabledMetadataIds = Object.entries(this.metadata) | ||
.filter(([key, value]) => value === true) | ||
.map((metadata) => metadata[0]) | ||
|
||
console.log(enabledMetadataIds) | ||
|
||
fetch( | ||
'/index.php/apps/opencatalogi/api/search?_search=' + this.search, | ||
{ | ||
method: 'GET', | ||
}, | ||
) | ||
.then( | ||
(response) => { | ||
response.json().then( | ||
(data) => { | ||
if (data?.code === 403 && data?.message) { | ||
this.searchError = data.message | ||
Check failure on line 42 in src/store/modules/search.js GitHub Actions / build
|
||
console.log(this.searchError) | ||
} else { | ||
this.searchError = '' // Clear any previous errors | ||
} | ||
this.searchResults = data | ||
}, | ||
) | ||
}, | ||
) | ||
.catch( | ||
(err) => { | ||
this.searchError = err.message || 'An error occurred' | ||
console.error(err.message ?? err) | ||
}, | ||
) | ||
.then( | ||
(response) => { | ||
response.json().then( | ||
(data) => { | ||
if (data?.code === 403 && data?.message) { | ||
this.searchError = data.message | ||
console.log(this.searchError) | ||
} else { | ||
this.searchError = '' // Clear any previous errors | ||
} | ||
this.searchResults = data | ||
}, | ||
) | ||
}, | ||
) | ||
.catch( | ||
(err) => { | ||
this.searchError = err.message || 'An error occurred' | ||
console.error(err.message ?? err) | ||
}, | ||
) | ||
}, | ||
clearSearch() { | ||
this.search = '' | ||
this.searchError = '' | ||
}, | ||
}, | ||
clearSearch() { | ||
this.search = '' | ||
this.searchError = '' | ||
}, | ||
}, | ||
}, | ||
) |