<commit_before>define (require) ->
  BaseView = require('cs!helpers/backbone/views/base')
  template = require('hbs!./filter-template')
  require('less!./filter')

  return class SearchResultsFilterView extends BaseView
    template: template
    templateHelpers: () ->
      limits = @model.toJSON().results.limits

      filters = {}
      _.each limits, (limit) ->
        _.each _.keys(limit), (key) ->
          if key isnt 'count'
            name = limit[key]
            filterName = key
            if filterName is 'mediaType' then filterName = 'type'
            if name is 'application/vnd.org.cnx.collection' then name = 'book'
            else if name is 'application/vnd.org.cnx.module' then name = 'page'
            filters[filterName] = filters[filterName] or {}
            filters[filterName][name] = {count: limit['count'], filter: filterName}

      return {filters: filters, url: Backbone.history.fragment}

    initialize: () ->
      super()
      @listenTo(@model, 'change:results', @render)<commit_msg>Capitalize search filter limit names<commit_after>define (require) ->
  BaseView = require('cs!helpers/backbone/views/base')
  template = require('hbs!./filter-template')
  require('less!./filter')

  FILTER_NAMES = {
    "author": "Author"
    "keyword": "Keyword"
    "mediaType": "Type"
    "pubYear": "Publication Date"
    "subject": "Subject"
  }

  capitalize: (str) ->
    return (str.split(' ').map (word) -> word[0].toUpperCase() + word[1..-1].toLowerCase()).join ' '

  return class SearchResultsFilterView extends BaseView
    template: template
    templateHelpers: () ->
      limits = @model.toJSON().results.limits

      filters = {}
      _.each limits, (limit) ->
        _.each _.keys(limit), (key) ->
          if key isnt 'count'
            filterName = FILTER_NAMES[key] or capitalize(key)
            name = limit[key]
            if name is 'application/vnd.org.cnx.collection' then name = 'book'
            else if name is 'application/vnd.org.cnx.module' then name = 'page'
            filters[filterName] = filters[filterName] or {}
            filters[filterName][name] = {count: limit['count'], filter: filterName}

      return {filters: filters, url: Backbone.history.fragment}

    initialize: () ->
      super()
      @listenTo(@model, 'change:results', @render)
{'fraction_non_alphanumeric': 0.14390034364261167, 'fraction_numerical': 0.001288659793814433, 'mean_word_length': 2.750402576489533, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 15, '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': '2271908', 'n_tokens_mistral': 690, 'n_tokens_neox': 678, 'n_words': 162}