function createVariableNode(variableByLang) {
  let ontologyNode = {'data': {}}
  let traitNode = {'data': {}}
  let traitClassNode = {'data': {}}
  let variableNode = {'data': {}}

  for (let language in variableByLang) {
    let variable = variableByLang[language][0]

    // Ontology node
    let ontology = {
      'ontologyDbId': variable.ontologyDbId,
      'ontologyName': variable.ontologyName
    }
    if (!ontologyNode['id']) {
      ontologyNode = createOntologyNode(ontology, language)
    }
    ontologyNode['data'][language] = {...ontology}

    // Variable node
    if (!variableNode['id']) {
      variableNode['id'] = variable.observationVariableDbId
      variableNode['parent'] = ontologyNode['id']
      variableNode['type'] = 'variable'
    }
    variableNode['data'][language] = {...ontology, ...variable}

    // Trait node
    let trait = variable.trait
    if (trait) {
      if (!traitNode['id']) {
        traitNode['id'] = trait.traitDbId
        traitNode['parent'] = ontologyNode['id']
        traitNode['type'] = 'trait'
      }
      traitNode['data'][language] = {...ontology, ...trait}

      variableNode['parent'] = traitNode['id']

      // Trait class
      let traitClass = trait.class && trait.class.trim()
      if (traitClass) {
        if (! traitClassNode['id']) {
          traitClassNode['id'] = `${ontology.ontologyDbId}:${traitClass}`
          traitClassNode['parent'] = ontologyNode['id']
          traitClassNode['type'] = 'traitClass'
        }
        traitClassNode['data'][language] = {...ontology, 'name': traitClass}

        traitNode['parent'] = traitClassNode['id']
      }
    }
  }

  // List tree nodes in correct dependency order (parent-child node relation)
  let nodes = [ontologyNode]
  if (traitClassNode['id']) nodes.push(traitClassNode)
  if (traitNode['id']) nodes.push(traitNode)
  nodes.push(variableNode)
  return nodes
}
/**
 * Transforms a Breeding API variable into jstree nodes for the trait class,
 * the trait and variable
 */
Transforms a Breeding API variable into jstree nodes for the trait class,
the trait and variable
Transforms a Breeding API variable into jstree nodes for the trait class the trait and variable
function createVariableNode(variableByLang) {
  let ontologyNode = {'data': {}}
  let traitNode = {'data': {}}
  let traitClassNode = {'data': {}}
  let variableNode = {'data': {}}
  for (let language in variableByLang) {
    let variable = variableByLang[language][0]
    let ontology = {
      'ontologyDbId': variable.ontologyDbId,
      'ontologyName': variable.ontologyName
    }
    if (!ontologyNode['id']) {
      ontologyNode = createOntologyNode(ontology, language)
    }
    ontologyNode['data'][language] = {...ontology}
    if (!variableNode['id']) {
      variableNode['id'] = variable.observationVariableDbId
      variableNode['parent'] = ontologyNode['id']
      variableNode['type'] = 'variable'
    }
    variableNode['data'][language] = {...ontology, ...variable}
    let trait = variable.trait
    if (trait) {
      if (!traitNode['id']) {
        traitNode['id'] = trait.traitDbId
        traitNode['parent'] = ontologyNode['id']
        traitNode['type'] = 'trait'
      }
      traitNode['data'][language] = {...ontology, ...trait}
      variableNode['parent'] = traitNode['id']
      let traitClass = trait.class && trait.class.trim()
      if (traitClass) {
        if (! traitClassNode['id']) {
          traitClassNode['id'] = `${ontology.ontologyDbId}:${traitClass}`
          traitClassNode['parent'] = ontologyNode['id']
          traitClassNode['type'] = 'traitClass'
        }
        traitClassNode['data'][language] = {...ontology, 'name': traitClass}
        traitNode['parent'] = traitClassNode['id']
      }
    }
  }
  let nodes = [ontologyNode]
  if (traitClassNode['id']) nodes.push(traitClassNode)
  if (traitNode['id']) nodes.push(traitNode)
  nodes.push(variableNode)
  return nodes
}
function createVariableNode ( variableByLang ) { let ontologyNode = { 'data' : { } } let traitNode = { 'data' : { } } let traitClassNode = { 'data' : { } } let variableNode = { 'data' : { } } for ( let language in variableByLang ) { let variable = variableByLang [ language ] [ 0 ] let ontology = { 'ontologyDbId' : variable . ontologyDbId , 'ontologyName' : variable . ontologyName } if ( ! ontologyNode [ 'id' ] ) { ontologyNode = createOntologyNode ( ontology , language ) } ontologyNode [ 'data' ] [ language ] = { ... ontology } if ( ! variableNode [ 'id' ] ) { variableNode [ 'id' ] = variable . observationVariableDbId variableNode [ 'parent' ] = ontologyNode [ 'id' ] variableNode [ 'type' ] = 'variable' } variableNode [ 'data' ] [ language ] = { ... ontology , ... variable } let trait = variable . trait if ( trait ) { if ( ! traitNode [ 'id' ] ) { traitNode [ 'id' ] = trait . traitDbId traitNode [ 'parent' ] = ontologyNode [ 'id' ] traitNode [ 'type' ] = 'trait' } traitNode [ 'data' ] [ language ] = { ... ontology , ... trait } variableNode [ 'parent' ] = traitNode [ 'id' ] let traitClass = trait . class && trait . class . trim ( ) if ( traitClass ) { if ( ! traitClassNode [ 'id' ] ) { traitClassNode [ 'id' ] = ` ${ ontology . ontologyDbId } ${ traitClass } ` traitClassNode [ 'parent' ] = ontologyNode [ 'id' ] traitClassNode [ 'type' ] = 'traitClass' } traitClassNode [ 'data' ] [ language ] = { ... ontology , 'name' : traitClass } traitNode [ 'parent' ] = traitClassNode [ 'id' ] } } } let nodes = [ ontologyNode ] if ( traitClassNode [ 'id' ] ) nodes . push ( traitClassNode ) if ( traitNode [ 'id' ] ) nodes . push ( traitNode ) nodes . push ( variableNode ) return nodes }
Transforms a Breeding API variable into jstree nodes for the trait class,
 the trait and variable
Transforms a Breeding API variable into jstree nodes for the trait class the trait and variable
// Ontology node // Variable node // Trait node // Trait class // List tree nodes in correct dependency order (parent-child node relation)