<commit_before>class App.ControllerTable extends App.Controller
  minColWidth: 40
  baseColWidth: 130
  minTableWidth: 612

  checkBoxColWidth: 40
  radioColWidth: 22

  constructor: (params) ->
    for key, value of params
      @[key] = value

    # apply personal preferences
    data = @preferencesGet()
    if data['order']
      for key, value of data['order']
        @[key] = value

    @headerWidth = {}
    if data['headerWidth']
      for key, value of data['headerWidth']
        @headerWidth[key] = value

    @render()

  render: =>
    @html @tableGen()

  ###

    # table based on model

    rowClick = (id, e) ->
      e.preventDefault()
      console.log('rowClick', id)
    rowMouseover = (id, e) ->
      e.preventDefault()
      console.log('rowMouseover', id)
    rowMouseout = (id, e) ->
      e.preventDefault()
      console.log('rowMouseout', id)
    rowDblClick = (id, e) ->
      e.preventDefault()
      console.log('rowDblClick', id)

    colClick = (id, e) ->
      e.preventDefault()
      console.log('colClick', e.target)

    checkboxClick = (id, e) ->
      e.preventDefault()
      console.log('checkboxClick', e.target)

    callbackHeader = (header) ->
      console.log('current header is', header)
      # add new header item
      attribute =
        name: 'some name'
        display: 'Some Name'
      header.push attribute
      console.log('new header is', header)

    callbackAttributes = (value, object, attribute, header, refObject) ->
      console.log('data of item col', value, object, attribute, header, refObject)
      value = 'New Data To Show'
      value

    new App.ControllerTable(
      table_id: 'some_id_to_idientify_user_based_table_preferences'
      el:       element
      overview: ['host', 'user', 'adapter', 'active']
      model:    App.Channel
      objects:  data
      groupBy:  'adapter'
      checkbox: false
      radio:    false
      class:    'some-css-class'
      bindRow:
        events:
          'click':      rowClick
          'mouseover':  rowMouseover
          'mouseout':   rowMouseout
          'dblclick':   rowDblClick
      bindCol:
        host:
          events:
            'click': colClick
      bindCheckbox:
        events:
          'click':      rowClick
          'mouseover':  rowMouseover
          'mouseout':   rowMouseout
          'dblclick':   rowDblClick
      callbackHeader:   [callbackHeader]
      callbackAttributes:
        attributeName: [
          callbackAttributes
        ]
    )

    new App.ControllerTable(
      el:       element
      overview: ['time', 'area', 'level', 'browser', 'location', 'data']
      attributes: [
        { name: 'time',     display: 'Time',      tag: 'datetime' },
        { name: 'area',     display: 'Area',      type: 'text' },
        { name: 'level',    display: 'Level',     type: 'text' },
        { name: 'browser',  display: 'Browser',   type: 'text' },
        { name: 'location', display: 'Location',  type: 'text' },
        { name: 'data',     display: 'Data',      type: 'text' },
      ]
      objects:  data
    )

  ###

  tableGen: =>
    if !@model
      @model = {}
    overview   = @overview || @model.configure_overview || []
    attributes = @attributes || @model.configure_attributes || {}
    attributes = App.Model.attributesGet(false, attributes)
    destroy    = @model.configure_delete

    # check if table is empty
    if _.isEmpty(@objects)
      table = App.view('generic/admin/empty')
        explanation: @explanation
      return $(table)

    # get header data
    headers = []
    for item in overview
      headerFound = false
      for attributeName, attribute of attributes

        if !attribute.style
          attribute.style = {}

        if attributeName is item
          # e.g. column: owner
          headerFound = true
          if @headerWidth[attribute.name]
            attribute.width = "#{@headerWidth[attribute.name]}px"
          headers.push attribute
        else
          # e.g. column: owner_id
          rowWithoutId = item + '_id'
          if attributeName is rowWithoutId
            headerFound = true
            if @headerWidth[attribute.name]
              attribute.width = "#{@headerWidth[attribute.name]}px"
            headers.push attribute

    if @orderDirection && @orderBy
      for header in headers
        if header.name is @orderBy
          @objects = _.sortBy(
            @objects
            (item) ->
              # if we need to sort translated col.
              if header.translate
                App.i18n.translateInline(item[header.name])
              # if we need to sort a relation
              if header.relation
                if item[header.name]
                  App[header.relation].find(item[header.name]).displayName()
                else
                  ''
              else
                item[header.name]
          )
          if @orderDirection is 'DESC'
            header.sortOrderIcon = ['arrow-down', 'table-sort-arrow']
            @objects = @objects.reverse()
          else
            header.sortOrderIcon = ['arrow-up', 'table-sort-arrow']
        else
          header.sortOrderIcon = undefined

    # execute header callback
    if @callbackHeader
      for callback in @callbackHeader
        headers = callback(headers)

    headers = @adjustHeaderWidths headers

    # group by
    if @groupBy

      # remove group by attribute from header
      overview = _.filter(
        overview
        (item) =>
          return item if item isnt @groupBy
          return
      )

      # get new order
      groupObjects = _.groupBy(
        @objects
        (item) =>
          return '' if !item[@groupBy]
          return item[@groupBy].displayName() if item[@groupBy].displayName
          item[@groupBy]
      )
      groupOrder = []
      for group, value of groupObjects
        groupOrder.push group

      # sort new groups
      groupOrder = _.sortBy(
        groupOrder
        (item) ->
          item
      )

      # create new data array
      @objects = []
      for group in groupOrder
        @objects = @objects.concat groupObjects[group]<commit_msg>Remove group by attribute from header.<commit_after>class App.ControllerTable extends App.Controller
  minColWidth: 40
  baseColWidth: 130
  minTableWidth: 612

  checkBoxColWidth: 40
  radioColWidth: 22

  constructor: (params) ->
    for key, value of params
      @[key] = value

    # apply personal preferences
    data = @preferencesGet()
    if data['order']
      for key, value of data['order']
        @[key] = value

    @headerWidth = {}
    if data['headerWidth']
      for key, value of data['headerWidth']
        @headerWidth[key] = value

    @render()

  render: =>
    @html @tableGen()

  ###

    # table based on model

    rowClick = (id, e) ->
      e.preventDefault()
      console.log('rowClick', id)
    rowMouseover = (id, e) ->
      e.preventDefault()
      console.log('rowMouseover', id)
    rowMouseout = (id, e) ->
      e.preventDefault()
      console.log('rowMouseout', id)
    rowDblClick = (id, e) ->
      e.preventDefault()
      console.log('rowDblClick', id)

    colClick = (id, e) ->
      e.preventDefault()
      console.log('colClick', e.target)

    checkboxClick = (id, e) ->
      e.preventDefault()
      console.log('checkboxClick', e.target)

    callbackHeader = (header) ->
      console.log('current header is', header)
      # add new header item
      attribute =
        name: '<NAME>'
        display: 'Some Name'
      header.push attribute
      console.log('new header is', header)

    callbackAttributes = (value, object, attribute, header, refObject) ->
      console.log('data of item col', value, object, attribute, header, refObject)
      value = 'New Data To Show'
      value

    new App.ControllerTable(
      table_id: 'some_id_to_idientify_user_based_table_preferences'
      el:       element
      overview: ['host', 'user', 'adapter', 'active']
      model:    App.Channel
      objects:  data
      groupBy:  'adapter'
      checkbox: false
      radio:    false
      class:    'some-css-class'
      bindRow:
        events:
          'click':      rowClick
          'mouseover':  rowMouseover
          'mouseout':   rowMouseout
          'dblclick':   rowDblClick
      bindCol:
        host:
          events:
            'click': colClick
      bindCheckbox:
        events:
          'click':      rowClick
          'mouseover':  rowMouseover
          'mouseout':   rowMouseout
          'dblclick':   rowDblClick
      callbackHeader:   [callbackHeader]
      callbackAttributes:
        attributeName: [
          callbackAttributes
        ]
    )

    new App.ControllerTable(
      el:       element
      overview: ['time', 'area', 'level', 'browser', 'location', 'data']
      attributes: [
        { name: 'time',     display: 'Time',      tag: 'datetime' },
        { name: 'area',     display: 'Area',      type: 'text' },
        { name: 'level',    display: 'Level',     type: 'text' },
        { name: 'browser',  display: 'Browser',   type: 'text' },
        { name: 'location', display: 'Location',  type: 'text' },
        { name: 'data',     display: 'Data',      type: 'text' },
      ]
      objects:  data
    )

  ###

  tableGen: =>
    if !@model
      @model = {}
    overview   = @overview || @model.configure_overview || []
    attributes = @attributes || @model.configure_attributes || {}
    attributes = App.Model.attributesGet(false, attributes)
    destroy    = @model.configure_delete

    # check if table is empty
    if _.isEmpty(@objects)
      table = App.view('generic/admin/empty')
        explanation: @explanation
      return $(table)

    # get header data
    headers = []
    for item in overview
      headerFound = false
      for attributeName, attribute of attributes

        # remove group by attribute from header
        if !@groupBy || @groupBy isnt item

          if !attribute.style
            attribute.style = {}

          if attributeName is item
            # e.g. column: owner
            headerFound = true
            if @headerWidth[attribute.name]
              attribute.width = "#{@headerWidth[attribute.name]}px"
            headers.push attribute
          else
            # e.g. column: owner_id
            rowWithoutId = item + '_id'
            if attributeName is rowWithoutId
              headerFound = true
              if @headerWidth[attribute.name]
                attribute.width = "#{@headerWidth[attribute.name]}px"
              headers.push attribute

    if @orderDirection && @orderBy
      for header in headers
        if header.name is @orderBy
          @objects = _.sortBy(
            @objects
            (item) ->
              # if we need to sort translated col.
              if header.translate
                App.i18n.translateInline(item[header.name])
              # if we need to sort a relation
              if header.relation
                if item[header.name]
                  App[header.relation].find(item[header.name]).displayName()
                else
                  ''
              else
                item[header.name]
          )
          if @orderDirection is 'DESC'
            header.sortOrderIcon = ['arrow-down', 'table-sort-arrow']
            @objects = @objects.reverse()
          else
            header.sortOrderIcon = ['arrow-up', 'table-sort-arrow']
        else
          header.sortOrderIcon = undefined

    # execute header callback
    if @callbackHeader
      for callback in @callbackHeader
        headers = callback(headers)

    headers = @adjustHeaderWidths headers

    # group by
    if @groupBy

      # get new order
      groupObjects = _.groupBy(
        @objects
        (item) =>
          return '' if !item[@groupBy]
          return item[@groupBy].displayName() if item[@groupBy].displayName
          item[@groupBy]
      )
      groupOrder = []
      for group, value of groupObjects
        groupOrder.push group

      # sort new groups
      groupOrder = _.sortBy(
        groupOrder
        (item) ->
          item
      )

      # create new data array
      @objects = []
      for group in groupOrder
        @objects = @objects.concat groupObjects[group]
{'fraction_non_alphanumeric': 0.10907461713913327, 'fraction_numerical': 0.002280873248615184, 'mean_word_length': 1.8597717214069416, 'pattern_counts': {'":': 0, '<': 4, '<?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': '2017737', 'n_tokens_mistral': 3440, 'n_tokens_neox': 3344, 'n_words': 901}