<commit_before>var PageView = require('./base');
var templates = require('../templates');
var FacetCollectionView = require('../views/facet-collection');

// Assumption:
var Dataset = require('../models/dataset'); // this.model instanceof Dataset
var Facets = require('../models/facet-collection'); // this.collection instanceof facet-collection

module.exports = PageView.extend({
  pageTitle: 'Facets',
  template: templates.pages.facets,
  render: function () {
    this.renderWithTemplate();

    if (this.collection) {
      this.collection.sort();
      this.renderCollection(this.collection, FacetCollectionView, this.queryByHook('facet-list'));
    }
  },
  initialize: function () {
    if (!(this.model instanceof Dataset) && (this.collection instanceof Facets)) {
      console.error('Analyze page should have a dataset and a facet collection', this.model, this.collection);
    }
    this.needle = this.collection.needle;
    this.showSearch = this.collection.showSearch;

    this.on('remove', function () {
      this.collection.needle = this.needle;
      this.collection.showSearch = this.showSearch;
    });

    this.update();
  },
  session: {
    needle: 'string',
    showSearch: 'boolean'
  },
  bindings: {
    'showSearch': {
      type: 'toggle',
      hook: 'search-bar'
    },
    'needle': {
      type: 'value',
      hook: 'facet-selector'
    }
  },
  events: {
    'input [data-hook~=facet-selector]': 'input',
    'click [data-hook~=add-button]': 'add',
    'click [data-hook~=rescan-button]': 'rescan',
    'click [data-hook~=search-button]': 'search',
    'click [data-hook~=clear-button]': 'clear'
  },
  input: function () {
    var select = this.el.querySelector('[data-hook~="facet-selector"]');
    this.needle = select.value;

    this.update();
  },
  add: function () {
    this.collection.add({name: 'New Facet'});
  },
  rescan: function () {
    this.model.scanData();
  },
  search: function () {
    this.showSearch = !this.showSearch;
  },
  clear: function () {
    this.needle = '';
    this.update();
  },
  update: function () {
    // build regexp for searching
    var regexp = new RegExp(this.needle, 'i'); // case insensitive search

    // search through collection, check both name and description
    this.collection.forEach(function (e) {
      var hay = e.name + e.description;
      e.show = regexp.test(hay.toLowerCase());
    });
  }
});<commit_msg>BUGFIX: upgrade mdl components when collection has changed<commit_after>var PageView = require('./base');
var templates = require('../templates');
var FacetCollectionView = require('../views/facet-collection');

// Assumption:
var Dataset = require('../models/dataset'); // this.model instanceof Dataset
var Facets = require('../models/facet-collection'); // this.collection instanceof facet-collection

module.exports = PageView.extend({
  pageTitle: 'Facets',
  template: templates.pages.facets,
  render: function () {
    this.renderWithTemplate();

    if (this.collection) {
      this.collection.sort();
      this.renderCollection(this.collection, FacetCollectionView, this.queryByHook('facet-list'));
    }
  },
  initialize: function () {
    if (!(this.model instanceof Dataset) && (this.collection instanceof Facets)) {
      console.error('Analyze page should have a dataset and a facet collection', this.model, this.collection);
    }
    this.needle = this.collection.needle;
    this.showSearch = this.collection.showSearch;

    this.on('remove', function () {
      this.collection.needle = this.needle;
      this.collection.showSearch = this.showSearch;
    });

    this.update();
  },
  session: {
    needle: 'string',
    showSearch: 'boolean'
  },
  bindings: {
    'showSearch': {
      type: 'toggle',
      hook: 'search-bar'
    },
    'needle': {
      type: 'value',
      hook: 'facet-selector'
    }
  },
  events: {
    'input [data-hook~=facet-selector]': 'input',
    'click [data-hook~=add-button]': 'add',
    'click [data-hook~=rescan-button]': 'rescan',
    'click [data-hook~=search-button]': 'search',
    'click [data-hook~=clear-button]': 'clear'
  },
  input: function () {
    var select = this.el.querySelector('[data-hook~="facet-selector"]');
    this.needle = select.value;

    this.update();
  },
  add: function () {
    this.collection.add({name: 'New Facet'});
    window.componentHandler.upgradeDom();
  },
  rescan: function () {
    this.model.scanData();
    window.componentHandler.upgradeDom();
  },
  search: function () {
    this.showSearch = !this.showSearch;
  },
  clear: function () {
    this.needle = '';
    this.update();
  },
  update: function () {
    // build regexp for searching
    var regexp = new RegExp(this.needle, 'i'); // case insensitive search

    // search through collection, check both name and description
    this.collection.forEach(function (e) {
      var hay = e.name + e.description;
      e.show = regexp.test(hay.toLowerCase());
    });
  }
});
{'fraction_non_alphanumeric': 0.16602783941900343, 'fraction_numerical': 0.0, 'mean_word_length': 3.1875, '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': '7519949', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1525, 'n_words': 319}