| 
					
				 | 
			
			
				@@ -1,4 +1,5 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import api from '@/api' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { formatData } from '@/helpers/formatter' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { print } from 'graphql/language/printer' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   TextsDepart, TextCard, TextdepartRecursive 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -7,34 +8,39 @@ import TextdepartRecursiveWithDepth from '@/api/queries/TextdepartRecursiveWithD 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 export default { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   state: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    textsDepart: undefined 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    textsDepart: undefined, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    textDepart: undefined 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   mutations: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'SET_TEXTS_DEPART' (state, texts) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       state.textsDepart = texts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    'SET_TEXT_DEPART' (state, text) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      state.textDepart = text 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   actions: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'GET_TEXTS_DEPART' ({ state, commit }) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return api.post('', { query: print(TextsDepart) }).then(({ data }) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        commit('SET_TEXTS_DEPART', data.data.textsdepart) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        commit('SET_TEXTS_DEPART', formatData(data.data.textsdepart)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return state.textsDepart 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'GET_TEXT' (store, { id }) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return api.post('', { query: print(TextCard), variables: { id } }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .then(data => (data.data.data.text)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        .then(data => formatData(data.data.data.text, true)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'GET_TREE' (store, id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return api.post('', { query: print(TextdepartRecursive), variables: { id } }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .then(({ data }) => (data.data.textref)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        .then(({ data }) => formatData(data.data.textref)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    'GET_TREE_WITH_DEPTH' (store, { id, depth }) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    'GET_TREE_WITH_DEPTH' ({ state, commit }, { id, depth = 4 }) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const baseQuery = print(TextdepartRecursiveWithDepth) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       function formatQuery (str, depth) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (depth > 0) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -46,14 +52,20 @@ export default { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           return str.replace('INPUT', '...TextrefTreeFields') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      return api.post('', { query: formatQuery(baseQuery, depth), variables: { id } }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        .then(({ data }) => (data.data.textref)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      commit('SET_TEXT_DEPART', undefined) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      return api.post('', { query: formatQuery(baseQuery, depth), variables: { id } }).then(({ data }) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        console.log(data.data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        commit('SET_TEXT_DEPART', formatData(data.data.textref)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return state.textDepart 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   getters: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     textsDepart: state => state.textsDepart, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    textDepart: state => state.textDepart, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     textsDepartOptions: state => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if (!state.textsDepart) return undefined 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return state.textsDepart.map(({ id, title }) => ({ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -68,11 +80,11 @@ export default { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return state.textsDepart.sort((a, b) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!b.authors) return -1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!a.authors) return +1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (a.authors[0].name < b.authors[0].name) return -1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (a.authors[0].name > b.authors[0].name) return 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (a.authors[0].last_name < b.authors[0].last_name) return -1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (a.authors[0].last_name > b.authors[0].last_name) return 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       }).reduce((dict, text) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        const firstChar = text.authors ? text.authors[0].name[0] : '&' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        const firstChar = text.authors ? text.authors[0].last_name[0] : 'Pas de noms' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!(firstChar in dict)) dict[firstChar] = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         dict[firstChar].push(text) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return dict 
			 |