From f9216653a64f6c4bbe657e8805380f3e7ddf8b99 Mon Sep 17 00:00:00 2001 From: axolotle Date: Tue, 6 Jul 2021 14:39:19 +0200 Subject: [PATCH] add Creation queries fields & simulate it as a text_produit --- src/api/fragments/NodeFull.gql | 3 +- src/api/fragments/NodeInitial.gql | 39 +++++++++++++++++++++++++- src/api/fragments/NodePartial.gql | 4 ++- src/components/nodes/NodeViewTitle.vue | 2 +- src/messages/fr.json | 3 +- src/store/modules/library.js | 3 +- src/store/nodes.js | 13 +++++++++ src/store/utils.js | 28 ++++++++++++++++-- 8 files changed, 87 insertions(+), 8 deletions(-) diff --git a/src/api/fragments/NodeFull.gql b/src/api/fragments/NodeFull.gql index 456f226..ec80a6c 100644 --- a/src/api/fragments/NodeFull.gql +++ b/src/api/fragments/NodeFull.gql @@ -5,7 +5,7 @@ fragment NodeFull on MapItemInterface { ... on Textref { preTitle: field_titre_regular - title: field_titre_italique + italTitle: field_titre_italique link: lien_reference { title url @@ -33,6 +33,7 @@ fragment NodeFull on MapItemInterface { variant: familles { id } + ... on Textprod { parents: text_de_depart { id diff --git a/src/api/fragments/NodeInitial.gql b/src/api/fragments/NodeInitial.gql index 3aaca24..0755a82 100644 --- a/src/api/fragments/NodeInitial.gql +++ b/src/api/fragments/NodeInitial.gql @@ -63,7 +63,7 @@ fragment NodeInitial on MapItemInterface { } preTitle: field_titre_regular - title: field_titre_italique + italTitle: field_titre_italique edition { name @@ -75,5 +75,42 @@ fragment NodeInitial on MapItemInterface { id } } + + creations: field_creations { + id + } + } + + ... on Creation { + parents: texte_de_depart { + id + variant: familles { + id + } + } + + siblings: rebonds { + id + } + + authors: auteurs { + id + name + first_name + last_name + } + + date { + start + # end + } + + images { + id + url + alt + } + + title } } diff --git a/src/api/fragments/NodePartial.gql b/src/api/fragments/NodePartial.gql index e58b554..9243534 100644 --- a/src/api/fragments/NodePartial.gql +++ b/src/api/fragments/NodePartial.gql @@ -28,7 +28,9 @@ fragment NodePartial on MapItemInterface { strangeness: degres_detrangement } - + ... on Creation { + content: texte + } # For debug path diff --git a/src/components/nodes/NodeViewTitle.vue b/src/components/nodes/NodeViewTitle.vue index f98ebbf..e2cb758 100644 --- a/src/components/nodes/NodeViewTitle.vue +++ b/src/components/nodes/NodeViewTitle.vue @@ -13,7 +13,7 @@ {{ toCommaList(node.authors) }}, - + ,
diff --git a/src/messages/fr.json b/src/messages/fr.json index 6653ba9..57f5559 100644 --- a/src/messages/fr.json +++ b/src/messages/fr.json @@ -16,7 +16,8 @@ "reflexion": "Réflexion théorique", "lecture": "Lecture rapprochée", "sensible": "Expérience sensible", - "kit": "Fiche-outil de désapprentisage" + "kit": "Fiche-outil de désapprentisage", + "creation": "Création numérique" }, "options": { "display": { diff --git a/src/store/modules/library.js b/src/store/modules/library.js index 8d781d2..04554a7 100644 --- a/src/store/modules/library.js +++ b/src/store/modules/library.js @@ -7,6 +7,7 @@ import { getUniqueNodesIds, getRelatedNodesIds, getRandomIds, + parseTree, buildTree } from '@/store/utils.js' @@ -185,7 +186,7 @@ export default { commit('SET_NODE_DEPART_ID', id) if (!(id in state.trees)) { - const treeData = await api.queryRecursiveNodes([id]) + const treeData = parseTree(await api.queryRecursiveNodes([id])) const nodes = await dispatch('GET_NODES', { ids: getUniqueNodesIds(treeData), dataLevel: 'initial' }) commit('ADD_NODE_TREE', [id, buildTree(treeData, nodes)]) } diff --git a/src/store/nodes.js b/src/store/nodes.js index 22a50bd..b8c67eb 100644 --- a/src/store/nodes.js +++ b/src/store/nodes.js @@ -34,6 +34,19 @@ export default { function addNode (node, level) { const stateNode = node.id in state.nodes ? state.nodes[node.id] : undefined + if ('creations' in node) { + if (node.creations) { + if (!Array.isArray(node.children)) { + node.children = [] + } + node.creations.forEach(item => { + item.variant = [{ id: 0 }] + node.children.push(item) + }) + } + delete node.creations + } + if (node.variant === null || Array.isArray(node.variant)) { node.variant = node.variant !== null ? ID_VARIANTS[node.variant[0].id] : 'dark' } diff --git a/src/store/utils.js b/src/store/utils.js index 7a9428c..42bf68d 100644 --- a/src/store/utils.js +++ b/src/store/utils.js @@ -20,8 +20,8 @@ export const ID_VARIANTS = { 6: 'reflexion', 7: 'lecture', 8: 'sensible', - 23: 'kit' - // undefined: 'creation' + 23: 'kit', + 0: 'creation' } export const VARIANT_IDS = Object.fromEntries( @@ -86,6 +86,30 @@ export function getRandomIds (ids, count = 3) { } +export function parseTree (treeData) { + if ('creations' in treeData) { + if (treeData.creations) { + if (!Array.isArray(treeData.children)) { + treeData.children = [] + } + treeData.creations.forEach(item => { + item.variant = [{ id: 0 }] + treeData.children.push(item) + }) + } + delete treeData.creations + } + + for (const relation of RELATIONS) { + if (relation in treeData && treeData[relation]) { + treeData[relation] = treeData[relation].map(node => parseTree(node)) + } + } + + return treeData +} + + export function buildTree (treeData, nodesData) { const uniqueIds = [] const nodes = []