<commit_before>root.SearchResultsTable_Framework = class SearchResultsTable_Framework
  constructor:(options = {}) ->
    @options = root._.extend {
      top: 0
      onTableClick: (e) =>
      loadMoreOnClick: =>
      resetResultsOnClick: =>
      infiniteScroll: true
      infiniteScrollCallback: (e) => Ti.API.info("scrolled to bottom")
      rowClassName: "SearchResultsTableRow"
      noResultsRowClassName: "SearchResultsTableNoResultsRow"
      loadMoreRowClassName: "SearchResultsTableMoreRow"
      pullToRefresh: false
      pullToRefreshCallback: (e) => Ti.API.info("pull to refresh fired")
    }, options
    
    @table = Ti.UI.createTableView {
      top: @options.top
      separatorColor: "#ddd"
    }
    @table.addEventListener("click", (e) =>
      switch e.row.type
        when "noResultsRow", "loadMoreRow", "retryRow"
          Ti.API.info("do nothing")
        else @options.onTableClick(e)
    )
    
    @moreRow = @createMoreRow()
    @noResultsRow = @createNoResultsRow()

    if @options.infiniteScroll
      @lastDistance = 0
      @addScrollListener()
  
  createMoreRow: =>
    root.app.create(@options.loadMoreRowClassName, {
      loadMoreOnClick: @options.loadMoreOnClick
    })
    
  createNoResultsRow: =>
    root.app.create(@options.noResultsRowClassName, {
      resetResultsOnClick: @options.resetResultsOnClick
    })
     
  addScrollListener: ->
    
  update: (items, hasMoreRows) =>
    Ti.API.info("----- Update Table -----")
    
    @table.scrollable = true

    if @table.data != null && @table.data.length > 0 && @table.data[0].rows.length > 0
      rowToDeleteIndex = @table.data[0].rows.length - 1

    if items.length > 0
      @i = 0
      for item in items
        @table.appendRow(root.app.create(@options.rowClassName, { item: item }).row)
      
        if @i == 0 && rowToDeleteIndex
          @table.deleteRow(rowToDeleteIndex)
      
        @i++
    else
      @table.scrollable = false
      @table.setData([@noResultsRow.noResultsRow])

    if hasMoreRows
      @table.hasMoreRows = true
      @table.appendRow(@moreRow.moreRow)
    else
      @table.hasMoreRows = false
    
    Ti.API.info("-- Finish Update Table --")

  clear: ->
    @table.setData [] <commit_msg>Added the ability to add an optional 'Ad Row' to a search results table. Customizable indexes for where to display the ads<commit_after>root.SearchResultsTable_Framework = class SearchResultsTable_Framework
  constructor:(options = {}) ->
    @options = root._.extend {
      top: 0
      onTableClick: (e) =>
      loadMoreOnClick: =>
      resetResultsOnClick: =>
      infiniteScroll: true
      infiniteScrollCallback: (e) => Ti.API.info("scrolled to bottom")
      rowClassName: "SearchResultsTableRow"
      noResultsRowClassName: "SearchResultsTableNoResultsRow"
      loadMoreRowClassName: "SearchResultsTableMoreRow"
      pullToRefresh: false
      pullToRefreshCallback: (e) => Ti.API.info("pull to refresh fired")
      adRowSettings: null
    }, options
    
    @table = Ti.UI.createTableView {
      top: @options.top
      separatorColor: "#ddd"
    }
    @table.addEventListener("click", (e) =>
      switch e.row.type
        when "noResultsRow", "loadMoreRow", "retryRow"
          Ti.API.info("do nothing")
        else @options.onTableClick(e)
    )
    
    @moreRow = @createMoreRow()
    @noResultsRow = @createNoResultsRow()

    if @options.infiniteScroll
      @lastDistance = 0
      @addScrollListener()
  
  createMoreRow: =>
    root.app.create(@options.loadMoreRowClassName, {
      loadMoreOnClick: @options.loadMoreOnClick
    })
    
  createNoResultsRow: =>
    root.app.create(@options.noResultsRowClassName, {
      resetResultsOnClick: @options.resetResultsOnClick
    })
     
  addScrollListener: ->
    
  update: (items, hasMoreRows) =>
    Ti.API.info("----- Update Table -----")
    
    @table.scrollable = true

    if @table.data != null && @table.data.length > 0 && @table.data[0].rows.length > 0
      rowToDeleteIndex = @table.data[0].rows.length - 1

    if items.length > 0
      @i = 0
      for item in items
        
        if @options.adRowSettings? && root._.contains(@options.adRowSettings.indexes, @i)
          adRow = root.app.create(@options.adRowSettings.rowClassName).row
          @table.appendRow(adRow)
        
        @table.appendRow(root.app.create(@options.rowClassName, { item: item }).row)
      
        if @i == 0 && rowToDeleteIndex
          @table.deleteRow(rowToDeleteIndex)
      
        @i++
    else
      @table.scrollable = false
      @table.setData([@noResultsRow.noResultsRow])

    if hasMoreRows
      @table.hasMoreRows = true
      @table.appendRow(@moreRow.moreRow)
    else
      @table.hasMoreRows = false
    
    Ti.API.info("-- Finish Update Table --")

  clear: ->
    @table.setData [] 
{'fraction_non_alphanumeric': 0.12329050973891421, 'fraction_numerical': 0.004144218814753419, 'mean_word_length': 2.6157303370786518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2890095', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1471, 'n_words': 280}