<commit_before>var CoreView = require('backbone/core-view');
var BasemapHeaderView = require('./basemap-content-views/basemap-header-view');
var BasemapCategoryView = require('./basemap-content-views/basemap-category-view');
var BasemapSelectView = require('./basemap-content-views/basemap-select-view');
var CarouselCollection = require('../../components/custom-carousel/custom-carousel-collection');
var _ = require('underscore');
var Backbone = require('backbone');
var template = require('./basemap-content.tpl');

module.exports = CoreView.extend({

  events: {
    'click .js-back': '_onClickBack'
  },

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

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

    this._baseLayer = this._layerDefinitionsCollection.getBaseLayer();

    this._initCollections();
    this._initBinds();
  },

  _initCollections: function () {
    this._basemapsCollection = new Backbone.Collection();

    _(this._layerDefinitionsCollection._basemaps).each(function (categoryLayers, category) {
      _.map(categoryLayers, function (m, key) {
        var tmpLayer = {
          default: m.default,
          urlTemplate: m.url,
          subdomains: m.subdomains,
          minZoom: m.minZoom,
          maxZoom: m.maxZoom,
          name: m.name,
          className: m.className,
          attribution: m.attribution,
          category: category,
          labels: m.labels,
          type: 'Tiled',
          selected: this._baseLayer.get('className') === m.className,
          val: m.className,
          label: m.name,
          template: function () {
            return m.className;
          }
        };

        // default basemaps are defined in app_config.yml
        this._basemapsCollection.add(tmpLayer);
      }, this);
    }, this);

    this._basemapsCollection.add({
      default: false,
      color: this._baseLayer.get('color') || '',
      image: this._baseLayer.get('image') || '',
      maxZoom: 32,
      className: 'plain',
      category: 'Color',
      type: 'Plain',
      selected: this._baseLayer.get('className') === 'plain',
      val: 'plain',
      label: 'plain',
      template: function () {
        return 'plain';
      }
    });

    this._categoriesCollection = new CarouselCollection(
      _.map(this._getCategories(), function (category) {
        return {
          selected: this._getBaseLayerCategory() === category,
          val: category,
          label: category,
          template: function () {
            return category;
          }
        };
      }, this)
    );
  },

  _initBinds: function () {
    var self = this;

    this._categoriesCollection.bind('change:selected', this._renderSelect, this);
    this.add_related_model(this._categoriesCollection);

    this._layerDefinitionsCollection.bind('change', function () {
      self._baseLayer = this._layerDefinitionsCollection.getBaseLayer();

      self._renderHeader();
      self._renderSelect();
    }, this);
    this.add_related_model(this._layerDefinitionsCollection);
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template());

    this._initViews();
    return this;
  },

  _getCategories: function () {
    var categories = [];

    this._basemapsCollection.filter(function (mdl) {
      var s = mdl.get('category');

      if (!_.contains(categories, s)) {
        categories.push(s);
      }
    });

    // TODO: push mapbox basemaps
    categories.push('Mapbox')

    // TODO: push custom basemaps
    categories.push('Custom')

    return categories;
  },

  _getDefaultCategory: function () {
    var defaultCategory = this._basemapsCollection.find(function (basemapMdl) {
      return basemapMdl.get('default');
    }, this);<commit_msg>linter<commit_after>var CoreView = require('backbone/core-view');
var BasemapHeaderView = require('./basemap-content-views/basemap-header-view');
var BasemapCategoryView = require('./basemap-content-views/basemap-category-view');
var BasemapSelectView = require('./basemap-content-views/basemap-select-view');
var CarouselCollection = require('../../components/custom-carousel/custom-carousel-collection');
var _ = require('underscore');
var Backbone = require('backbone');
var template = require('./basemap-content.tpl');

module.exports = CoreView.extend({

  events: {
    'click .js-back': '_onClickBack'
  },

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

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

    this._baseLayer = this._layerDefinitionsCollection.getBaseLayer();

    this._initCollections();
    this._initBinds();
  },

  _initCollections: function () {
    this._basemapsCollection = new Backbone.Collection();

    _(this._layerDefinitionsCollection._basemaps).each(function (categoryLayers, category) {
      _.map(categoryLayers, function (m, key) {
        var tmpLayer = {
          default: m.default,
          urlTemplate: m.url,
          subdomains: m.subdomains,
          minZoom: m.minZoom,
          maxZoom: m.maxZoom,
          name: m.name,
          className: m.className,
          attribution: m.attribution,
          category: category,
          labels: m.labels,
          type: 'Tiled',
          selected: this._baseLayer.get('className') === m.className,
          val: m.className,
          label: m.name,
          template: function () {
            return m.className;
          }
        };

        // default basemaps are defined in app_config.yml
        this._basemapsCollection.add(tmpLayer);
      }, this);
    }, this);

    this._basemapsCollection.add({
      default: false,
      color: this._baseLayer.get('color') || '',
      image: this._baseLayer.get('image') || '',
      maxZoom: 32,
      className: 'plain',
      category: 'Color',
      type: 'Plain',
      selected: this._baseLayer.get('className') === 'plain',
      val: 'plain',
      label: 'plain',
      template: function () {
        return 'plain';
      }
    });

    this._categoriesCollection = new CarouselCollection(
      _.map(this._getCategories(), function (category) {
        return {
          selected: this._getBaseLayerCategory() === category,
          val: category,
          label: category,
          template: function () {
            return category;
          }
        };
      }, this)
    );
  },

  _initBinds: function () {
    var self = this;

    this._categoriesCollection.bind('change:selected', this._renderSelect, this);
    this.add_related_model(this._categoriesCollection);

    this._layerDefinitionsCollection.bind('change', function () {
      self._baseLayer = this._layerDefinitionsCollection.getBaseLayer();

      self._renderHeader();
      self._renderSelect();
    }, this);
    this.add_related_model(this._layerDefinitionsCollection);
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template());

    this._initViews();
    return this;
  },

  _getCategories: function () {
    var categories = [];

    this._basemapsCollection.filter(function (mdl) {
      var s = mdl.get('category');

      if (!_.contains(categories, s)) {
        categories.push(s);
      }
    });

    // TODO: push mapbox basemaps
    categories.push('Mapbox');

    // TODO: push custom basemaps
    categories.push('Custom');

    return categories;
  },

  _getDefaultCategory: function () {
    var defaultCategory = this._basemapsCollection.find(function (basemapMdl) {
      return basemapMdl.get('default');
    }, this);
{'fraction_non_alphanumeric': 0.13373630525122782, 'fraction_numerical': 0.0005037148973680896, 'mean_word_length': 2.812770043206913, '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': '4442388', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2205, 'n_words': 425}