diff --git a/src/api/ma-axios.js b/src/api/ma-axios.js new file mode 100644 index 0000000..f7989c5 --- /dev/null +++ b/src/api/ma-axios.js @@ -0,0 +1,33 @@ +import axios from 'axios' + +// https://github.com/alvar0hurtad0/drupal-vuejs-todo/blob/master/frontend/src/api/axiosInterceptor.js + +// console.log('drupalSettings', drupalSettings) + +const MA = axios.create({ + baseURL: `${window.location.origin}/api`, + withCredentials: true, + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + } +}) + + + + +MA.interceptors.response.use( + response => { + return Promise.resolve(response) + }, + error => { + const { status } = error.response + console.warn('error in ma-axios interceptor', status) + // if (status === 403) { + // window.location = '/' + // } + return Promise.reject(error) + } +) + +export default MA diff --git a/src/assets/main.scss b/src/assets/main.scss index 127d62a..6750f10 100644 --- a/src/assets/main.scss +++ b/src/assets/main.scss @@ -501,6 +501,15 @@ body{ &>*{ flex: 0 1 auto; } + + .content-type-checkboxes{ + padding:1em 0; + display: flex; + flex-direction: row; + label{ + padding: 0 1em 0 0.2em; + } + } } } diff --git a/src/stores/search.js b/src/stores/search.js index 5c74bbb..0367efe 100644 --- a/src/stores/search.js +++ b/src/stores/search.js @@ -3,48 +3,47 @@ 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 StaticsFields from '@api/gql/statics.fragment.gql' export const SearchStore = defineStore({ id: 'search', state: () => ({ - // loaded: false, + keys: null, + contentTypesFilter: [], + results: [] }), getters: { }, actions: { + setKeys (value) { + this.keys = value.split(' '); + }, + setContentTypes (v) { + this.contentTypesFilter = v + }, loadResults () { - console.log('search store loadResults'); - // return new Promise((resolve, reject) => { - // const ast = gql`{ - // promotedstatics { - // ...StaticsFields - // } - // } - // ${StaticsFields} - // ` - // console.log('ast', ast); - // GQL.post('', { query: print(ast) }) - // .then(({ data : { data : { promotedstatics } } }) => { - // console.log('loadstatics loaded', promotedstatics) - // this.statics = promotedstatics - - // promotedstatics.forEach((s) => { - // // console.log("s", s); - // this.statics_byid[s.id] = s - // }); - // console.log("statics_byid", this.statics_byid); - // this.loaded = true; - // }) - // .catch(error => { - // console.warn('Issue with loadStatics', error) - // Promise.reject(error) - // }) - // }) + console.log('search store loadResults', this.keys); + // this.keys = keys; + const params = { + keys: this.keys.join(', ') + } + 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; + }) + .catch((error) => { + console.warn('Issue with getResults', error) + // window.location.reload() + Promise.reject(error) + }) } } }) \ No newline at end of file diff --git a/src/views/Search.vue b/src/views/Search.vue index fc9649f..89382b7 100644 --- a/src/views/Search.vue +++ b/src/views/Search.vue @@ -5,21 +5,42 @@ import { SearchStore } from '@/stores/search' export default { props: [], - // data(){ - // return { - // block: null - // } - // }, + data(){ + return { + value: null, + content_types: ['concernement', 'entite'] + } + }, computed: { - // ...mapState(SearchStore,['loaded', 'statics_byid']) + ...mapState(SearchStore,['keys', 'contentTypesFilter', 'results']), + // value(){ + // return this.keys + // } }, created () { console.log("search created"); + this.setContentTypes(this.content_types); + }, + watch: { + value: { + handler (n,o){ + this.setKeys(n); + }, + deep: true + }, + content_types: { + handler (n,o){ + this.setContentTypes(n); + }, + deep: true + }, }, methods: { - ...mapActions(SearchStore,['loadResults']), + ...mapActions(SearchStore,['setKeys','setContentTypes','loadResults']), onSubmitSearch (event) { - console.log("onSubmitSearch", event); + console.log("onSubmitSearch", event, this.value); + // let value = event.target[0].value; + this.loadResults(); } }, components: { @@ -33,12 +54,21 @@ export default {