<commit_before>Mod.require 'Operation',
 'OPERATIONS'
 (Base, OPERATIONS) ->
  class SearchDeleteRows extends Base
   @extend()

   @initialize ->
    @elems.inputs = {}

   operationName: 'Search and Delete Rows'
   @operationName: 'Search and Delete Rows'
   type: 'searchDeleteRows'
   @type: 'searchDeleteRows'

   json: ->
    column: @column
    delimiter: @delimiter

   render: ->
    @elems.sidebar.innerHTML = ''

    Weya elem: @elems.sidebar, context: this, ->
     @$.elems.inputsDiv = @div
      on: {click: @$.on.removeClick}

     @button on: {click: @$.on.cancel}, 'Cancel'
     @$.elems.btn = @button '.button-primary', 'Delete',
      on: {click: @$.on.apply}
      style: {display: 'none'}

   @listen 'cancel', (e) ->
    e.preventDefault()
    @callbacks.cancel()

   @listen 'apply', (e) ->
    e.preventDefault()
    text = @textEditor.getValue()
    @data = text.split '\n'
    @callbacks.apply()

   @listen 'tableSelect', (r, c, table) ->
    @table = table
    id = table.columns[c].id
    @addInputs id, table.columns[c].name, table.data[id][r]
    @refresh()

   @listen 'change', ->
    @refresh()

   @listen 'removeClick', (e) ->
    n = e.target
    while n?
     if n._id?
      @elems.inputsDiv.removeChild @elems.inputs[n._id].div
      delete @elems.inputs[n._id]
      @refresh()
     n = n.parentNode

   addInputs: (id, name, search) ->
    if @elems.inputs[id]?
     @elems.inputsDiv.removeChild @elems.inputs[id].div

    Weya elem: @elems.inputsDiv, context: this, ->
     elems = {}
     elems.div = @div ->
      elems.label = @label for: "search-#{id}", name
      elems.input = @input "#search-#{id}",
       value: search
       type: 'text'
       on: {change: @$.on.change}
      elems.remove = @button 'Remove'
     elems.remove._id = id
     @$.elems.inputs[id] = elems

   refresh: ->
    @search = {}
    n = 0
    for id, elems of @elems.inputs
     @search[id] = elems.input.value
     n++

    if n > 0
     @elems.btn.style.display = 'block'
    else
     @elems.btn.style.display = 'none'

    @table.highlight.rows = {}
    highlight = (true for i in [0...@table.size])
    for id, s of @search
     regex = new RegExp s, ''
     for d, r in @table.data[id]
      if not regex.test d
       highlight[r] = false

    for d, r in highlight when d
     @table.highlight.rows[r] = true

    @table.refresh()

   apply: ->
    cidx = -1
    for c, i in @table.columns when c.id is @column
     cidx = i

    data = @table.data[@column].join '\n'
    data = dsv
     separator: @delimiter
     quote: @quote.charCodeAt 0
     text: data

    nColumns = data.length
    col = @table.columns[cidx]
    args = [cidx, 1]
    for i in [1..nColumns]
     args.push
      id: "#{col.id}_#{i}"
      name: "#{col.name}_#{i}"
      type: 'string'
      default: ''

    @table.columns.splice.apply @table.columns, args
    for d, i in data
     @table.data["#{col.id}_#{i + 1}"] = d



  OPERATIONS.set SearchDeleteRows.type, SearchDeleteRows<commit_msg>search & delete rows<commit_after>Mod.require 'Operation',
 'OPERATIONS'
 (Base, OPERATIONS) ->
  class SearchDeleteRows extends Base
   @extend()

   @initialize ->
    @elems.inputs = {}

   operationName: 'Search and Delete Rows'
   @operationName: 'Search and Delete Rows'
   type: 'searchDeleteRows'
   @type: 'searchDeleteRows'

   json: ->
    column: @column
    delimiter: @delimiter

   render: ->
    @elems.sidebar.innerHTML = ''

    Weya elem: @elems.sidebar, context: this, ->
     @$.elems.inputsDiv = @div
      on: {click: @$.on.removeClick}

     @button on: {click: @$.on.cancel}, 'Cancel'
     @$.elems.btn = @button '.button-primary', 'Delete',
      on: {click: @$.on.apply}
      style: {display: 'none'}

   @listen 'cancel', (e) ->
    e.preventDefault()
    @callbacks.cancel()

   @listen 'apply', (e) ->
    e.preventDefault()
    @callbacks.apply()

   @listen 'tableSelect', (r, c, table) ->
    @table = table
    id = table.columns[c].id
    @addInputs id, table.columns[c].name, table.data[id][r]
    @refresh()

   @listen 'change', ->
    @refresh()

   @listen 'removeClick', (e) ->
    n = e.target
    while n?
     if n._id?
      @elems.inputsDiv.removeChild @elems.inputs[n._id].div
      delete @elems.inputs[n._id]
      @refresh()
     n = n.parentNode

   addInputs: (id, name, search) ->
    if @elems.inputs[id]?
     @elems.inputsDiv.removeChild @elems.inputs[id].div

    Weya elem: @elems.inputsDiv, context: this, ->
     elems = {}
     elems.div = @div ->
      elems.label = @label for: "search-#{id}", name
      elems.input = @input "#search-#{id}",
       value: search
       type: 'text'
       on: {change: @$.on.change}
      elems.remove = @button 'Remove'
     elems.remove._id = id
     @$.elems.inputs[id] = elems

   refresh: ->
    @search = {}
    n = 0
    for id, elems of @elems.inputs
     @search[id] = elems.input.value
     n++

    if n > 0
     @elems.btn.style.display = 'block'
    else
     @elems.btn.style.display = 'none'

    @table.highlight.rows = {}
    highlight = (true for i in [0...@table.size])
    for id, s of @search
     regex = new RegExp s, ''
     for d, r in @table.data[id]
      if not regex.test d
       highlight[r] = false

    for d, r in highlight when d
     @table.highlight.rows[r] = true

    @table.refresh()

   apply: ->
    @search = {}
    for id, elems of @elems.inputs
     @search[id] = elems.input.value

    highlight = (true for i in [0...@table.size])
    for id, s of @search
     regex = new RegExp s, ''
     for d, r in @table.data[id]
      if not regex.test d
       highlight[r] = false

    for id, data of @table.data
     @table.data[id] = (data[r] for d, r in highlight when not d)
     @table.size = @table.data[id].length



  OPERATIONS.set SearchDeleteRows.type, SearchDeleteRows
{'fraction_non_alphanumeric': 0.16065292096219932, 'fraction_numerical': 0.002061855670103093, 'mean_word_length': 2.3569780853517877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '7578564', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2044, 'n_words': 512}