app/js/models/thesaurus.js
//once the data is loaded, prepares a tree for nav rendering
once the data is loaded, prepares a tree for nav rendering
once the data is loaded prepares a tree for nav rendering
function prepareDataThesaurus(data){
    var that = this;
    this.provData = data;
    var data = data.map(function(element){
      var parent = this.getParent(element, data);
      if(parent && parent.length>0){
        element.parents = parent;
      }
      return element;
    }.bind(this));
    if(this.models.length === 1){
      this.add(data);
    }else{
      this.reset(data);
    }
    if(this.models.length>1){
      var filteredTree = this.models.filter(function(element){
        return element.attributes["skos:topConceptOf"] !== undefined || that.getName(element.attributes["skos:prefLabel"]).match(/^Ethnologie --/);
      })
      .map(function (element){
        var children = that.getChildren(element.attributes);
        var result = { name : that.getName(element.attributes["skos:prefLabel"]),
          uri : element.attributes["@id"],
          id : element.attributes["id"]};
        if(children.length > 0) {
          result.children = children;
          result.size = children.length;
        }else{
          result.size = 1;
        }
        return result;
      });
      var dataTree = this.getActiveThesaurus();
      dataTree.children = filteredTree;
      this.counter = 1;
      this.findRank(dataTree.children);
      this.models = _.sortBy(this.models, function(elt){ return Number(elt.attributes.rank);});
      this.conceptTree = dataTree;
      this.trigger("dataChanged");
    }
  }
function prepareDataThesaurus ( data ) { var that = this ; this . provData = data ; var data = data . map ( function ( element ) { var parent = this . getParent ( element , data ) ; if ( parent && parent . length > 0 ) { element . parents = parent ; } return element ; } . bind ( this ) ) ; if ( this . models . length === 1 ) { this . add ( data ) ; } else { this . reset ( data ) ; } if ( this . models . length > 1 ) { var filteredTree = this . models . filter ( function ( element ) { return element . attributes [ "skos:topConceptOf" ] !== undefined || that . getName ( element . attributes [ "skos:prefLabel" ] ) . match ( / ^Ethnologie -- / ) ; } ) . map ( function ( element ) { var children = that . getChildren ( element . attributes ) ; var result = { name : that . getName ( element . attributes [ "skos:prefLabel" ] ) , uri : element . attributes [ "@id" ] , id : element . attributes [ "id" ] } ; if ( children . length > 0 ) { result . children = children ; result . size = children . length ; } else { result . size = 1 ; } return result ; } ) ; var dataTree = this . getActiveThesaurus ( ) ; dataTree . children = filteredTree ; this . counter = 1 ; this . findRank ( dataTree . children ) ; this . models = _ . sortBy ( this . models , function ( elt ) { return Number ( elt . attributes . rank ) ; } ) ; this . conceptTree = dataTree ; this . trigger ( "dataChanged" ) ; } }
once the data is loaded, prepares a tree for nav rendering
once the data is loaded prepares a tree for nav rendering
//add parent hierarchy //creates hierarchical tree for nav // dataTree = this.sortThesaurus(dataTree, 1); //orders the collection according to the tree //console.log(this.counter, this.models); //console.log(dataTree);