<commit_before>var cdb = require('cartodb-deep-insights.js');
var template = require('./layer.tpl');

/**
 * View for an individual layer definition model.
 */
module.exports = cdb.core.View.extend({

  tagName: 'li',

  className: 'BlockList-item',

  events: {
    'click .js-remove': '_onRemove'
  },

  initialize: function (opts) {
    if (!opts.layerAnalysisViewFactory) throw new Error('layerAnalysisViewFactory is required');
    if (!opts.layerDefinitionsCollection) throw new Error('layerDefinitionsCollection is required');

    this._layerAnalysisViewFactory = opts.layerAnalysisViewFactory;
    this._layerDefinitionsCollection = opts.layerDefinitionsCollection;

    this.listenTo(this.model, 'change', this.render);
    this.listenToOnce(this.model, 'destroy', this._onDestroy);
  },

  render: function () {
    this.clearSubViews();

    var m = this.model;

    this.$el.html(template({
      title: m.getName(),
      letter: m.get('letter')
    }));

    this._renderAnalysisView();

    return this;
  },

  _renderAnalysisView: function () {
    var source = this.model.get('source');
    if (source) {
      var analysisView = this._layerAnalysisViewFactory.createView(source, this.model);
      this.$('.js-analysis').append(analysisView.render().$el);
    }
  },

  _onRemove: function (ev) {
    this.killEvent(ev); // to avoid the general click to trigger (i.e. do not try to edit on removal)
    this.model.destroy();
  },

  _onDestroy: function () {
    this.clean();<commit_msg>Added stack layout model to layer view<commit_after>var cdb = require('cartodb-deep-insights.js');
var template = require('./layer.tpl');

/**
 * View for an individual layer definition model.
 */
module.exports = cdb.core.View.extend({

  tagName: 'li',

  className: 'BlockList-item',

  events: {
    'click .js-remove': '_onRemove',
    'click': '_onEdit'
  },

  initialize: function (opts) {
    if (!opts.layerAnalysisViewFactory) throw new Error('layerAnalysisViewFactory is required');
    if (!opts.layerDefinitionsCollection) throw new Error('layerDefinitionsCollection is required');
    if (!opts.stackLayoutModel) throw new Error('stackLayoutModel is required');

    this._layerAnalysisViewFactory = opts.layerAnalysisViewFactory;
    this._layerDefinitionsCollection = opts.layerDefinitionsCollection;
    this._stackLayoutModel = opts.stackLayoutModel;

    this.listenTo(this.model, 'change', this.render);
    this.listenToOnce(this.model, 'destroy', this._onDestroy);
  },

  render: function () {
    this.clearSubViews();

    var m = this.model;

    this.$el.html(template({
      title: m.getName(),
      letter: m.get('letter')
    }));

    this._renderAnalysisView();

    return this;
  },

  _renderAnalysisView: function () {
    var source = this.model.get('source');
    if (source) {
      var analysisView = this._layerAnalysisViewFactory.createView(source, this.model);
      this.$('.js-analysis').append(analysisView.render().$el);
    }
  },

  _onRemove: function (ev) {
    this.killEvent(ev); // to avoid the general click to trigger (i.e. do not try to edit on removal)
    this.model.destroy();
  },

  _onEdit: function () {
    this._stackLayoutModel.nextStep(this.model, 'layers');
  },

  _onDestroy: function () {
    this.clean();
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 3.69472182596291, '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': '5998186', 'n_tokens_mistral': 997, 'n_tokens_neox': 961, 'n_words': 218}