|
@@ -3,19 +3,22 @@ import { print } from 'graphql/language/printer'
|
|
import gql from 'graphql-tag'
|
|
import gql from 'graphql-tag'
|
|
|
|
|
|
// import REST from '@api/rest-axios'
|
|
// 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 JSONAPI from '@api/json-axios'
|
|
import MA from '@api/ma-axios'
|
|
import MA from '@api/ma-axios'
|
|
|
|
+
|
|
import qs from 'querystring-es3'
|
|
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({
|
|
export const SearchStore = defineStore({
|
|
id: 'search',
|
|
id: 'search',
|
|
state: () => ({
|
|
state: () => ({
|
|
keys: null,
|
|
keys: null,
|
|
- contentTypesFilter: [],
|
|
|
|
- results: []
|
|
|
|
|
|
+ contentTypeFilter: [],
|
|
|
|
+ results: [],
|
|
|
|
+ loaded_results: []
|
|
}),
|
|
}),
|
|
getters: {
|
|
getters: {
|
|
|
|
|
|
@@ -24,26 +27,70 @@ export const SearchStore = defineStore({
|
|
setKeys (value) {
|
|
setKeys (value) {
|
|
this.keys = value.split(' ');
|
|
this.keys = value.split(' ');
|
|
},
|
|
},
|
|
- setContentTypes (v) {
|
|
|
|
- this.contentTypesFilter = v
|
|
|
|
|
|
+ setContentType (v) {
|
|
|
|
+ this.contentTypeFilter = v
|
|
},
|
|
},
|
|
- loadResults () {
|
|
|
|
|
|
+ newSearch () {
|
|
console.log('search store loadResults', this.keys);
|
|
console.log('search store loadResults', this.keys);
|
|
// this.keys = keys;
|
|
// this.keys = keys;
|
|
const params = {
|
|
const params = {
|
|
- keys: this.keys.join(', ')
|
|
|
|
|
|
+ keys: this.keys.join(', '),
|
|
|
|
+ content_type: this.contentTypeFilter
|
|
}
|
|
}
|
|
const q = qs.stringify(params)
|
|
const q = qs.stringify(params)
|
|
return MA.get('/ouatt_searchapi/getresults?' + q)
|
|
return MA.get('/ouatt_searchapi/getresults?' + q)
|
|
.then(({ data }) => {
|
|
.then(({ data }) => {
|
|
console.log('search MA getresults data', data, data.nids)
|
|
console.log('search MA getresults data', data, data.nids)
|
|
- this.results = data.nids;
|
|
|
|
|
|
+ this.results = data;
|
|
|
|
+ this.loadeResults();
|
|
})
|
|
})
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
console.warn('Issue with getResults', error)
|
|
console.warn('Issue with getResults', error)
|
|
// window.location.reload()
|
|
// window.location.reload()
|
|
Promise.reject(error)
|
|
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);
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|