<commit_before>var CoreView = require('backbone/core-view');
var _ = require('underscore');
var cellTemplate = require('./table-body-cell.tpl');
var pointGeojsonParser = require('builder/helpers/point-geojson-parser');
var checkAndBuildOpts = require('builder/helpers/required-opts');

var FORMATTED_TYPE_VALUES = {
  'geometry': pointGeojsonParser
};

var REQUIRED_OPTS = [
  'columnsCollection',
  'tableViewModel',
  'canHideColumns'
];

/*
 *  Table body row view
 */

module.exports = CoreView.extend({

  className: 'Table-row',
  tagName: 'tr',

  options: {
    simpleGeometry: ''
  },

  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this.el.setAttribute('data-model', this.model.cid);

    this._initBinds();
  },

  render: function () {
    this.$el.empty();
    this._generateRowsHTML();
    return this;
  },

  _initBinds: function () {
    this.model.bind('change', this.render, this);
    this.model.bind('destroy', this.remove, this);
  },

  _generateRowsHTML: function () {
    var r = [];

    for (var i = 0, l = this._columnsCollection.size(); i < l; i++) {
      var model = this._columnsCollection.at(i);
      var columnName = model.get('name');

      if (!(this._tableViewModel.isCustomQueryApplied() && columnName === 'the_geom_webmercator')) {
        continue;
      }

      if (this._hasTradeAnalysis && columnName === 'center' && model.isGeometryColumn()) {
        continue;
      }

      r[i] = this._generateCellHTML(columnName);
    }

    this.el.innerHTML = r.join('');
  },

  _generateCellHTML: function (columnName) {
    var simpleGeometry = this.options.simpleGeometry;
    var columnModel = _.first(this._columnsCollection.where({ name: columnName }));
    var columnType = columnModel.get('type');
    var value = this.model.get(columnName);
    var formattedValue = value;

    if (columnType === 'geometry') {
      if (simpleGeometry === 'point') {
        formattedValue = FORMATTED_TYPE_VALUES[columnType](value);
      } else {
        formattedValue = simpleGeometry && (simpleGeometry.charAt(0).toUpperCase() + simpleGeometry.slice(1));
      }
    } else if (FORMATTED_TYPE_VALUES[columnType]) {
      formattedValue = FORMATTED_TYPE_VALUES[columnType](value);
    }

    return cellTemplate({
      value: value,
      formattedValue: formattedValue,
      type: columnType,
      columnName: columnName,
      geometry: simpleGeometry
    });
  }
});
<commit_msg>fix table body row<commit_after>var CoreView = require('backbone/core-view');
var _ = require('underscore');
var cellTemplate = require('./table-body-cell.tpl');
var pointGeojsonParser = require('builder/helpers/point-geojson-parser');
var checkAndBuildOpts = require('builder/helpers/required-opts');

var FORMATTED_TYPE_VALUES = {
  'geometry': pointGeojsonParser
};

var REQUIRED_OPTS = [
  'columnsCollection',
  'tableViewModel',
  'canHideColumns'
];

/*
 *  Table body row view
 */

module.exports = CoreView.extend({

  className: 'Table-row',
  tagName: 'tr',

  options: {
    simpleGeometry: ''
  },

  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this.el.setAttribute('data-model', this.model.cid);

    this._initBinds();
  },

  render: function () {
    this.$el.empty();
    this._generateRowsHTML();
    return this;
  },

  _initBinds: function () {
    this.model.bind('change', this.render, this);
    this.model.bind('destroy', this.remove, this);
  },

  _generateRowsHTML: function () {
    var r = [];

    for (var i = 0, l = this._columnsCollection.size(); i < l; i++) {
      var model = this._columnsCollection.at(i);
      var columnName = model.get('name');

      if (!this._tableViewModel.isCustomQueryApplied() && columnName === 'the_geom_webmercator') {
        continue;
      }

      if (this._hasTradeAnalysis && columnName === 'center' && model.isGeometryColumn()) {
        continue;
      }

      r[i] = this._generateCellHTML(columnName);
    }

    this.el.innerHTML = r.join('');
  },

  _generateCellHTML: function (columnName) {
    var simpleGeometry = this.options.simpleGeometry;
    var columnModel = _.first(this._columnsCollection.where({ name: columnName }));
    var columnType = columnModel.get('type');
    var value = this.model.get(columnName);
    var formattedValue = value;

    if (columnType === 'geometry') {
      if (simpleGeometry === 'point') {
        formattedValue = FORMATTED_TYPE_VALUES[columnType](value);
      } else {
        formattedValue = simpleGeometry && (simpleGeometry.charAt(0).toUpperCase() + simpleGeometry.slice(1));
      }
    } else if (FORMATTED_TYPE_VALUES[columnType]) {
      formattedValue = FORMATTED_TYPE_VALUES[columnType](value);
    }

    return cellTemplate({
      value: value,
      formattedValue: formattedValue,
      type: columnType,
      columnName: columnName,
      geometry: simpleGeometry
    });
  }
});

{'fraction_non_alphanumeric': 0.14578680203045685, 'fraction_numerical': 0.001218274111675127, 'mean_word_length': 3.429856115107914, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2017811', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1529, 'n_words': 287}