<commit_before>//= require jquery.scrollTo

window.FactRelationsView = Backbone.View.extend({
  tagName: "div",
  className: "page evidence-list fact-relations-container",
  _views: [],
  _loading: true,

  template: 'fact_relations/fact_relations',

  initialize: function(options) {
    this.collection.bind('add', this.addFactRelation, this);
    this.collection.bind('remove', this.removeFactRelation, this);
    this.collection.bind('reset', this.resetFactRelations, this);

    this.showNoEvidenceMessage();

    this.initializeSearchView();
  },

  initializeSearchView: function() {
    this.factRelationSearchView = new FactRelationSearchView({
      factRelations: this.collection,
      type: this.options.type
    });
  },

  highlightFactRelation: function(view) {
    $( 'ul.evidence-listing', this.el)
      .scrollTo(view.el, 800);

    view.highlight();
  },

  addFactRelation: function(factRelation, factRelations, options) {
    if ( !options ) {
      options = {};
    }

    var factRelationView = new FactRelationView({model: factRelation});

    this.hideNoEvidenceMessage();

    this._views.push(factRelationView);

    factRelationView.render();
    this.$el.find('ul.evidence-listing').append(factRelationView.el);

    if ( options.highlight ) {
      this.highlightFactRelation(factRelationView);
    }
  },

  resetFactRelations: function() {
    var self = this;

    this.collection.forEach(function(factRelation) {
      self.addFactRelation(factRelation);
    });

    if ( this.collection.length === 0 ) {
      this.showNoEvidenceMessage();
    }
  },

  removeFactRelation: function(factRelation) {
    console.info( "Removing one FactRelation" );
  },

  render: function() {
    this.$el
      .html(this.templateRender())
      .prepend(this.factRelationSearchView.render().el);

    return this;
  },

  hide: function() {
    this.$el.hide();
  },

  show: function() {
    this.$el.show();
  },

  showAndFetch: function() {
    var self = this;

    if ( ! this._fetched ) {
      this._fetched = true;

      this.collection.reset();

      this.showLoadingIndicator();

      this.collection.fetch({
        success: function() {
          self.hideLoadingIndicator();
        }
      });
    }

    this.$el.show();
  },

  showLoadingIndicator: function() {
    this.$el.find('.loading-evidence').show();
    this.hideNoEvidenceMessage();
  },

  hideLoadingIndicator: function() {
    this.$el.find('.loading-evidence').hide();
  },

  showNoEvidenceMessage: function() {
    this.$el.find('.no-evidence-message').show();
    this.hideLoadingIndicator();
  },

  hideNoEvidenceMessage: function() {
    this.$el.find('.no-evidence-message').hide();
  }
});
_.extend(FactRelationsView.prototype, TemplateMixin);<commit_msg>moved init<commit_after>//= require jquery.scrollTo

window.FactRelationsView = Backbone.View.extend({
  tagName: "div",
  className: "page evidence-list fact-relations-container",

  template: 'fact_relations/fact_relations',

  initialize: function(options) {
    this._views = [];
    this._loading = true;

    this.collection.bind('add', this.addFactRelation, this);
    this.collection.bind('remove', this.removeFactRelation, this);
    this.collection.bind('reset', this.resetFactRelations, this);

    this.showNoEvidenceMessage();

    this.initializeSearchView();
  },

  initializeSearchView: function() {
    this.factRelationSearchView = new FactRelationSearchView({
      factRelations: this.collection,
      type: this.options.type
    });
  },

  highlightFactRelation: function(view) {
    $( 'ul.evidence-listing', this.el)
      .scrollTo(view.el, 800);

    view.highlight();
  },

  addFactRelation: function(factRelation, factRelations, options) {
    if ( !options ) {
      options = {};
    }

    var factRelationView = new FactRelationView({model: factRelation});

    this.hideNoEvidenceMessage();

    this._views.push(factRelationView);

    factRelationView.render();
    this.$el.find('ul.evidence-listing').append(factRelationView.el);

    if ( options.highlight ) {
      this.highlightFactRelation(factRelationView);
    }
  },

  resetFactRelations: function() {
    var self = this;

    this.collection.forEach(function(factRelation) {
      self.addFactRelation(factRelation);
    });

    if ( this.collection.length === 0 ) {
      this.showNoEvidenceMessage();
    }
  },

  removeFactRelation: function(factRelation) {
    console.info( "Removing one FactRelation" );
  },

  render: function() {
    this.$el
      .html(this.templateRender())
      .prepend(this.factRelationSearchView.render().el);

    return this;
  },

  hide: function() {
    this.$el.hide();
  },

  show: function() {
    this.$el.show();
  },

  showAndFetch: function() {
    var self = this;

    if ( ! this._fetched ) {
      this._fetched = true;

      this.collection.reset();

      this.showLoadingIndicator();

      this.collection.fetch({
        success: function() {
          self.hideLoadingIndicator();
        }
      });
    }

    this.$el.show();
  },

  showLoadingIndicator: function() {
    this.$el.find('.loading-evidence').show();
    this.hideNoEvidenceMessage();
  },

  hideLoadingIndicator: function() {
    this.$el.find('.loading-evidence').hide();
  },

  showNoEvidenceMessage: function() {
    this.$el.find('.no-evidence-message').show();
    this.hideLoadingIndicator();
  },

  hideNoEvidenceMessage: function() {
    this.$el.find('.no-evidence-message').hide();
  }
});
_.extend(FactRelationsView.prototype, TemplateMixin);
{'fraction_non_alphanumeric': 0.1510791366906475, 'fraction_numerical': 0.0014388489208633094, 'mean_word_length': 3.2678434382194936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5927947', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1670, 'n_words': 252}