Browse Source

rename main store module

axolotle 3 years ago
parent
commit
e3b1afc325
3 changed files with 2 additions and 96 deletions
  1. 2 2
      src/store/index.js
  2. 0 94
      src/store/modules/texts.js
  3. 0 0
      src/store/nodes.js

+ 2 - 2
src/store/index.js

@@ -1,13 +1,13 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
 
-import texts from './texts'
+import nodes from './nodes'
 import library from './modules/library'
 
 Vue.use(Vuex)
 
 export default new Vuex.Store({
-  ...texts,
+  ...nodes,
   modules: {
     library
   }

+ 0 - 94
src/store/modules/texts.js

@@ -1,94 +0,0 @@
-import api from '@/api'
-import { formatData } from '@/helpers/formatter'
-import { print } from 'graphql/language/printer'
-import {
-  TextsDepart, TextCard, TextdepartRecursive
-} from '@/api/queries'
-import TextdepartRecursiveWithDepth from '@/api/queries/TextdepartRecursiveWithDepth.gql'
-
-export default {
-  state: {
-    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', formatData(data.data.textsdepart))
-        return state.textsDepart
-      })
-    },
-
-    'GET_TEXT' (store, { id }) {
-      return api.post('', { query: print(TextCard), variables: { id } })
-        .then(data => formatData(data.data.data.text, true))
-    },
-
-    'GET_TREE' (store, id) {
-      return api.post('', { query: print(TextdepartRecursive), variables: { id } })
-        .then(({ data }) => formatData(data.data.textref))
-    },
-
-    'GET_TREE_WITH_DEPTH' ({ state, commit }, { id, depth = 4 }) {
-      const baseQuery = print(TextdepartRecursiveWithDepth)
-      function formatQuery (str, depth) {
-        if (depth > 0) {
-          return formatQuery(
-            str.replace('INPUT', '...TextrefTreeFields\nsiblings: text_en_rebond {\nINPUT\n}'),
-            --depth
-          )
-        } else {
-          return str.replace('INPUT', '...TextrefTreeFields')
-        }
-      }
-      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 }) => ({
-        value: id,
-        text: `(${id}) ${title}`
-      }))
-    },
-
-    orderedParents: state => {
-      // FIXME duplicates references if multiple authors ?
-      if (!state.textsDepart) return undefined
-      return state.textsDepart.sort((a, b) => {
-        if (!b.authors) return -1
-        if (!a.authors) 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].last_name[0] : 'Pas de noms'
-        if (!(firstChar in dict)) dict[firstChar] = []
-        dict[firstChar].push(text)
-        return dict
-      }, {})
-    }
-  }
-}

+ 0 - 0
src/store/texts.js → src/store/nodes.js