added content type filter to search, displaying reults
This commit is contained in:
@@ -3,19 +3,22 @@ import { print } from 'graphql/language/printer'
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
// import REST from '@api/rest-axios'
|
||||
// import GQL from '@api/graphql-axios'
|
||||
import GQL from '@api/graphql-axios'
|
||||
// import JSONAPI from '@api/json-axios'
|
||||
import MA from '@api/ma-axios'
|
||||
|
||||
import qs from 'querystring-es3'
|
||||
|
||||
// import StaticsFields from '@api/gql/statics.fragment.gql'
|
||||
import ResultsConcernementFields from '@api/gql/results_concernement.fragment.gql'
|
||||
import ResultsEntiteFields from '@api/gql/results_entite.fragment.gql'
|
||||
|
||||
export const SearchStore = defineStore({
|
||||
id: 'search',
|
||||
state: () => ({
|
||||
keys: null,
|
||||
contentTypesFilter: [],
|
||||
results: []
|
||||
contentTypeFilter: [],
|
||||
results: [],
|
||||
loaded_results: []
|
||||
}),
|
||||
getters: {
|
||||
|
||||
@@ -24,26 +27,70 @@ export const SearchStore = defineStore({
|
||||
setKeys (value) {
|
||||
this.keys = value.split(' ');
|
||||
},
|
||||
setContentTypes (v) {
|
||||
this.contentTypesFilter = v
|
||||
setContentType (v) {
|
||||
this.contentTypeFilter = v
|
||||
},
|
||||
loadResults () {
|
||||
newSearch () {
|
||||
console.log('search store loadResults', this.keys);
|
||||
// this.keys = keys;
|
||||
const params = {
|
||||
keys: this.keys.join(', ')
|
||||
keys: this.keys.join(', '),
|
||||
content_type: this.contentTypeFilter
|
||||
}
|
||||
const q = qs.stringify(params)
|
||||
return MA.get('/ouatt_searchapi/getresults?' + q)
|
||||
.then(({ data }) => {
|
||||
console.log('search MA getresults data', data, data.nids)
|
||||
this.results = data.nids;
|
||||
this.results = data;
|
||||
this.loadeResults();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('Issue with getResults', error)
|
||||
// window.location.reload()
|
||||
Promise.reject(error)
|
||||
})
|
||||
},
|
||||
loadeResults () {
|
||||
return new Promise((resolve, reject) => {
|
||||
let ast;
|
||||
if (this.contentTypeFilter === 'entites') {
|
||||
ast = gql`{
|
||||
entites(ids: [${this.results.nids}]) {
|
||||
...ResultsEntiteFields
|
||||
}
|
||||
}
|
||||
${ResultsEntiteFields}
|
||||
`
|
||||
GQL.post('', { query: print(ast) })
|
||||
.then(({ data : { data : { entites } } }) => {
|
||||
console.log('entites all loaded', entites)
|
||||
this.loaded_results = entites
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with loadResults', error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
} else {
|
||||
ast = gql`{
|
||||
concernements(ids: [${this.results.nids}]) {
|
||||
...ResultsConcernementFields
|
||||
}
|
||||
}
|
||||
${ResultsConcernementFields}
|
||||
`
|
||||
|
||||
GQL.post('', { query: print(ast) })
|
||||
.then(({ data : { data : { concernements } } }) => {
|
||||
console.log('concernements all loaded', concernements)
|
||||
this.loaded_results = concernements
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('Issue with loadResults', error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
}
|
||||
// console.log('ast', ast);
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user