diff --git a/src/api/queries/TextdepartRecursiveWithDepth.gql b/src/api/queries/TextdepartRecursiveWithDepth.gql new file mode 100644 index 0000000..87e4951 --- /dev/null +++ b/src/api/queries/TextdepartRecursiveWithDepth.gql @@ -0,0 +1,7 @@ +#import "../fragments/TextrefTreeFields.gql" + +query TextdepartRecursive($id: Int!) { + textref(id: $id) { +INPUT + } +} diff --git a/src/pages/Map.vue b/src/pages/Map.vue index 2a4310e..1364c20 100644 --- a/src/pages/Map.vue +++ b/src/pages/Map.vue @@ -3,24 +3,24 @@

Carte avec duplication

- +
+ +

Carte avec liens multiples

- +
+ +
@@ -28,10 +28,20 @@ + + + + Afficher les numéros @@ -57,6 +67,7 @@ export default { return { textId: undefined, showId: true, + depth: 3, data: null, mapSingle: { nodes: null, links: null }, mapMany: { nodes: null, links: null } @@ -67,9 +78,11 @@ export default { ...mapGetters(['textsDepartOptions']) }, - watch: { - textId (id) { - this.$store.dispatch('GET_TREE', id).then((data) => { + methods: { + query () { + const { textId: id, depth } = this + this.data = null + this.$store.dispatch('GET_TREE_WITH_DEPTH', { id, depth }).then((data) => { this.mapSingle = toSingleManyData(data) this.mapMany = toManyManyData(data) this.data = data @@ -102,7 +115,12 @@ export default { } .node-map { + height: 100%; border: 1px solid grey; } + +} +.col > * { + width: auto; } diff --git a/src/store/modules/texts.js b/src/store/modules/texts.js index c1537ad..7911d73 100644 --- a/src/store/modules/texts.js +++ b/src/store/modules/texts.js @@ -3,7 +3,7 @@ import { print } from 'graphql/language/printer' import { TextsDepart, TextRef, TextdepartRecursive } from '@/api/queries' - +import TextdepartRecursiveWithDepth from '@/api/queries/TextdepartRecursiveWithDepth.gql' export default { state: { @@ -24,14 +24,30 @@ export default { }) }, - 'GET_TEXT' ({ state }, { id }) { + 'GET_TEXT' (store, { id }) { return api.post('', { query: print(TextRef), variables: { id } }) .then(data => (data.data.data)) }, - 'GET_TREE' ({ dispatch }, id) { + 'GET_TREE' (store, id) { return api.post('', { query: print(TextdepartRecursive), variables: { id } }) .then(({ data }) => (data.data.textref)) + }, + + 'GET_TREE_WITH_DEPTH' (store, { id, depth }) { + const baseQuery = print(TextdepartRecursiveWithDepth) + function formatQuery (str, depth) { + if (depth > 0) { + return formatQuery( + str.replace('INPUT', '...TextrefTreeFields\ntext_en_rebond {\nINPUT\n}'), + --depth + ) + } else { + return str.replace('INPUT', '...TextrefTreeFields') + } + } + return api.post('', { query: formatQuery(baseQuery, depth), variables: { id } }) + .then(({ data }) => (data.data.textref)) } },