Skip to content
Snippets Groups Projects
nameAndClassification.js 1.47 KiB
Newer Older
import RequestNotifications from '@/web-components-submodule/utils/RequestNotifications.js'
import IndexNames from '~/web-components-submodule/standardisation/IndexNames.js'
import EntityNames from '~/web-components-submodule/standardisation/EntityNames.js'
import ESProxyService from '~/web-components-submodule/services/ESProxyService.js'

export const state = () => ({
  nameAndClassificationData: {},
  dataLoaded: false,
})

export const mutations = {
  SET_DATA_LOADED(state, dataLoaded) {
    state.dataLoaded = dataLoaded
  },
  SET_NAME_AND_CLASSIFICATION_DATA(state, nameAndClassificationData) {
    state.nameAndClassificationData = nameAndClassificationData
  },
}

export const actions = {
  loadData({ commit, state, dispatch }, itemID) {
    const docSource = [
      'target_type',
      'pref_name',
      'target_components',
      'organism',
      'species_group_flag',
      '_metadata.protein_classification',
    ]
    const entityID = EntityNames.EubopenTarget.entityID
    const indexName = IndexNames.getIndexNameFromEntityID(entityID)

    ESProxyService.getESDocument(indexName, itemID, docSource)
      .then((response) => {
        commit('SET_NAME_AND_CLASSIFICATION_DATA', response.data._source)
        commit('SET_DATA_LOADED', true)
      })
      .catch((error) => {
        RequestNotifications.dispatchRequestErrorNotification(
          error,
          dispatch,
          `There was an error while loading the name and classification!`
        )
      })
  },
}