add api module
This commit is contained in:
@@ -0,0 +1,92 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
import { print } from 'graphql/language/printer'
|
||||||
|
|
||||||
|
import { Node, Nodes, NodesTrees } from '@/api/queries'
|
||||||
|
import * as nodesFragments from '@/api/fragments'
|
||||||
|
|
||||||
|
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: window.location.origin + '/api/gql',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getQueryString (query, levels) {
|
||||||
|
const FRAGMENTS_NAMES = ['NodeInitial', 'NodePartial', 'NodeFull']
|
||||||
|
const names = levels.map(level => FRAGMENTS_NAMES[level])
|
||||||
|
const fragments = names.map(name => '...' + name).join('\n')
|
||||||
|
const fragmentsDefs = names.map(name => print(nodesFragments[name])).join('\n')
|
||||||
|
return print(query).replace('FRAGMENTS', fragments) + fragmentsDefs
|
||||||
|
},
|
||||||
|
|
||||||
|
query (query, variables = {}) {
|
||||||
|
return api
|
||||||
|
.post('', { query: print(query), variables })
|
||||||
|
.then(response => {
|
||||||
|
return response.data.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
queryNodes (ids, levels) {
|
||||||
|
return api.post('', {
|
||||||
|
query: this.getQueryString(Nodes, levels),
|
||||||
|
variables: { ids }
|
||||||
|
}).then(response => response.data.data)
|
||||||
|
},
|
||||||
|
|
||||||
|
queryNode (id, levels) {
|
||||||
|
return api.post('', {
|
||||||
|
query: this.getQueryString(Node, levels),
|
||||||
|
variables: { id }
|
||||||
|
}).then(response => response.data.data)
|
||||||
|
},
|
||||||
|
|
||||||
|
queryRecursiveNodes (ids, depth = 4) {
|
||||||
|
const baseQuery = print(NodesTrees)
|
||||||
|
const prodFragment = `
|
||||||
|
... on Textprod {
|
||||||
|
parents: text_de_depart {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
|
siblings: text_en_rebond {
|
||||||
|
id
|
||||||
|
FRAGMENT_REF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const refFragment = `
|
||||||
|
... on Textref {
|
||||||
|
siblings: text_en_rebond {
|
||||||
|
id
|
||||||
|
FRAGMENT_REF
|
||||||
|
}
|
||||||
|
|
||||||
|
children: text_produits {
|
||||||
|
id
|
||||||
|
FRAGMENT_PROD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
function formatFragment (str, depth) {
|
||||||
|
if (depth > 0) {
|
||||||
|
return formatFragment(
|
||||||
|
str.replaceAll('FRAGMENT_REF', refFragment).replaceAll('FRAGMENT_PROD', prodFragment),
|
||||||
|
--depth
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return str.replaceAll('FRAGMENT_REF', '').replaceAll('FRAGMENT_PROD', '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.post('', {
|
||||||
|
query: baseQuery.replace('FRAGMENT', formatFragment(refFragment + prodFragment, depth)),
|
||||||
|
variables: { id: ids[0] }
|
||||||
|
}).then(response => response.data.data.node)
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-8
@@ -1,9 +1,4 @@
|
|||||||
import axios from 'axios'
|
import api from './api'
|
||||||
|
|
||||||
export default axios.create({
|
export default api
|
||||||
baseURL: window.location.origin + '/api/gql',
|
export * from './queries'
|
||||||
headers: {
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
<div v-for="(parents, char) in orderedTextsDepart" :key="char">
|
<div v-for="(parents, char) in orderedTextsDepart" :key="char">
|
||||||
<h3>{{ char }}</h3>
|
<h3>{{ char }}</h3>
|
||||||
<div class="text-group">
|
<div class="text-group">
|
||||||
<text-mini-card
|
<node-view
|
||||||
v-for="parent in parents" :key="parent.id"
|
v-for="parent in parents" :key="parent.id"
|
||||||
:id="parent.id"
|
:node="parent"
|
||||||
:text-data="parent"
|
mode="card"
|
||||||
@open="$emit('open', $event)"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -20,14 +19,14 @@
|
|||||||
// FIXME let events bubble
|
// FIXME let events bubble
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
|
|
||||||
import TextMiniCard from '@/components/text/TextMiniCard'
|
import { NodeView } from '@/components/nodes'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CardList',
|
name: 'CardList',
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
TextMiniCard
|
NodeView
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
@@ -45,11 +44,6 @@ export default {
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
&-container {
|
|
||||||
overflow-x: hidden;
|
|
||||||
padding: 0 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
font-family: $font-family-text;
|
font-family: $font-family-text;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
:x="node.x" :y="node.y"
|
:x="node.x" :y="node.y"
|
||||||
:transform="`rotate(${node.rotate})`"
|
:transform="`rotate(${node.rotate})`"
|
||||||
>
|
>
|
||||||
<text-mini-card
|
<node-view
|
||||||
:id="texts[i].id"
|
:node="texts[i]"
|
||||||
:text-data="texts[i]"
|
mode="card"
|
||||||
/>
|
/>
|
||||||
</foreignObject>
|
</foreignObject>
|
||||||
</g>
|
</g>
|
||||||
@@ -31,14 +31,14 @@ import {
|
|||||||
} from 'd3-force'
|
} from 'd3-force'
|
||||||
|
|
||||||
|
|
||||||
import TextMiniCard from '@/components/text/TextMiniCard'
|
import { NodeView } from '@/components/nodes'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CardMap',
|
name: 'CardMap',
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
TextMiniCard
|
NodeView
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
|
|||||||
Reference in New Issue
Block a user