add texts store & add Textsdepart query
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
query TextsDepart {
|
||||||
|
textsdepart {
|
||||||
|
id,
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export { default as TextsDepart } from './TextsDepart.gql'
|
||||||
|
export { default as TextRef } from './TextRef.gql'
|
||||||
|
export { default as TextdepartRecursive } from './TextdepartRecursive.gql'
|
||||||
+2
-45
@@ -1,56 +1,13 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
import api from '@/api'
|
import texts from './modules/texts'
|
||||||
import { print } from 'graphql/language/printer'
|
|
||||||
import TextRef from '@/api/queries/TextRef.gql'
|
|
||||||
import TextdepartRecursive from '@/api/queries/TextdepartRecursive.gql'
|
|
||||||
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
},
|
texts
|
||||||
|
|
||||||
state: {
|
|
||||||
},
|
|
||||||
|
|
||||||
mutations: {
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
'GET_TEXT' ({ state }, { id }) {
|
|
||||||
return api.post('', { query: print(TextRef), variables: { id } }).then(data => (data.data.data))
|
|
||||||
},
|
|
||||||
|
|
||||||
'GET_TREE' ({ dispatch }, id) {
|
|
||||||
return api.post('', { query: print(TextdepartRecursive), variables: { id } }).then(({ data }) => {
|
|
||||||
return data.data.textref
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Temp data processing
|
|
||||||
function parse (d, originalId) {
|
|
||||||
const child = {
|
|
||||||
name: d.title,
|
|
||||||
type: d.__typename.toLowerCase(),
|
|
||||||
class: 'family-' + d.familles[0].id
|
|
||||||
}
|
|
||||||
if (d.id === originalId) {
|
|
||||||
child.class += ' first'
|
|
||||||
}
|
|
||||||
let children = []
|
|
||||||
for (const key of ['text_en_rebond', 'text_produits']) {
|
|
||||||
if (d[key]) {
|
|
||||||
children = [...children, ...d[key].filter(text => text.id !== originalId)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (children.length) {
|
|
||||||
child.children = children.map(child => parse(child, originalId))
|
|
||||||
}
|
|
||||||
return child
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
export default {
|
|
||||||
namespaced: true,
|
|
||||||
// initial state
|
|
||||||
state: {
|
|
||||||
// items: [],
|
|
||||||
},
|
|
||||||
// getters
|
|
||||||
getters: {
|
|
||||||
|
|
||||||
},
|
|
||||||
// mutations
|
|
||||||
mutations: {
|
|
||||||
|
|
||||||
},
|
|
||||||
// actions
|
|
||||||
actions: {
|
|
||||||
|
|
||||||
},
|
|
||||||
// methods
|
|
||||||
methods: {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import api from '@/api'
|
||||||
|
import { print } from 'graphql/language/printer'
|
||||||
|
import {
|
||||||
|
TextsDepart, TextRef, TextdepartRecursive
|
||||||
|
} from '@/api/queries'
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
state: {
|
||||||
|
textsDepart: undefined
|
||||||
|
},
|
||||||
|
|
||||||
|
mutations: {
|
||||||
|
'SET_TEXTS_DEPART' (state, texts) {
|
||||||
|
state.textsDepart = texts
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
'GET_TEXTS_DEPART' ({ state, commit }) {
|
||||||
|
return api.post('', { query: print(TextsDepart) }).then(({ data }) => {
|
||||||
|
commit('SET_TEXTS_DEPART', data.data.textsdepart)
|
||||||
|
return state.textsDepart
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
'GET_TEXT' ({ state }, { id }) {
|
||||||
|
return api.post('', { query: print(TextRef), variables: { id } })
|
||||||
|
.then(data => (data.data.data))
|
||||||
|
},
|
||||||
|
|
||||||
|
'GET_TREE' ({ dispatch }, id) {
|
||||||
|
return api.post('', { query: print(TextdepartRecursive), variables: { id } })
|
||||||
|
.then(({ data }) => (data.data.textref))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getters: {
|
||||||
|
textsDepartOptions: state => {
|
||||||
|
if (!state.textsDepart) return undefined
|
||||||
|
return state.textsDepart.map(({ id, title }) => ({
|
||||||
|
value: id,
|
||||||
|
text: `(${id}) ${title}`
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user