<commit_before>class Scheduler.EditTicketsEffortView extends Backbone.View
  className: "edit-estimates-view hide-completed"
  
  
  events:
    'click #show_completed_tickets': 'toggleShowCompleted'
  
  
  initialize: ->
    @template = HandlebarsTemplates['houston-scheduler/tickets/edit_tickets_effort']
    @ticketsTemplate = HandlebarsTemplates['houston-scheduler/tickets/edit_tickets_effort_tickets']
    @tickets = @options.tickets
    @visibleTickets = @tickets.ableToEstimate().withoutEffortEstimate()
    
    @tickets.on 'change', _.bind(@render, @)
    
    @$el.on 'click', 'th', (e)=> @toggleSort $(e.target).closest('th')
    
    @$el.on 'click', '[rel="ticket"]', (e)=>
      e.preventDefault()
      e.stopImmediatePropagation()
      number = +$(e.target).closest('[rel="ticket"]').attr('data-number')
      App.showTicket number, null,
        tickets: @visibleTickets
        taskView: (el, ticket)-> new Scheduler.EditTicketEffortView
          el: el
          ticket: ticket
  
  
  
  render: ->
    @$el.html @template()
    @$tickets = @$el.find('#tickets')
    @renderTickets()
    @
  
  renderTickets: ->
    tickets = @visibleTickets.map (ticket)->
      json = ticket.toJSON()
      json.effort = ticket.estimatedEffort()
      json.saved = ticket.estimated()
      json
    @$tickets.html @ticketsTemplate(tickets: tickets)
    @$tickets.find('.ticket').pseudoHover()
  
  
  toggleShowCompleted: (e)->
    $button = $(e.target)
    if $button.hasClass('active')
      $button.removeClass('btn-success')
      @visibleTickets = @tickets.ableToEstimate().withoutEffortEstimate()
      @renderTickets()
    else
      $button.addClass('btn-success')
      @visibleTickets = @tickets
      @renderTickets()



  toggleSort: ($th)->
    if $th.hasClass('sort-asc')
      $th.removeClass('sort-asc').addClass('sort-desc')
    else if $th.hasClass('sort-desc')
      $th.removeClass('sort-desc').addClass('sort-asc')
    else
      @$el.find('.sort-asc, .sort-desc').removeClass('sort-asc sort-desc')
      $th.addClass('sort-desc')
    
    attribute = $th.attr('data-attribute')
    order = if $th.hasClass('sort-desc') then 'desc' else 'asc'
    @performSort attribute, order
  
  performSort: (attribute, order)->
    sorter = @["#{attribute}Sorter"]
    return console.log "#{attribute}Sorter is undefined!" unless sorter
    
    @visibleTickets = @visibleTickets.sortBy(sorter)
    @visibleTickets = @visibleTickets.reverse() if order == 'desc'
    @render()
<commit_msg>[skip] Fixed a few glitches with sorting tickets in the Estimate Effort view (4m)<commit_after>class Scheduler.EditTicketsEffortView extends Backbone.View
  className: "edit-estimates-view hide-completed"
  
  
  events:
    'click #show_completed_tickets': 'toggleShowCompleted'
  
  
  initialize: ->
    @template = HandlebarsTemplates['houston-scheduler/tickets/edit_tickets_effort']
    @ticketsTemplate = HandlebarsTemplates['houston-scheduler/tickets/edit_tickets_effort_tickets']
    @tickets = @options.tickets
    @visibleTickets = @tickets.ableToEstimate().withoutEffortEstimate()
    
    @tickets.on 'change', _.bind(@render, @)
    
    @$el.on 'click', 'th', (e)=> @toggleSort $(e.target).closest('th')
    
    @$el.on 'click', '[rel="ticket"]', (e)=>
      e.preventDefault()
      e.stopImmediatePropagation()
      number = +$(e.target).closest('[rel="ticket"]').attr('data-number')
      App.showTicket number, null,
        tickets: @visibleTickets
        taskView: (el, ticket)-> new Scheduler.EditTicketEffortView
          el: el
          ticket: ticket
  
  
  
  render: ->
    @$el.html @template()
    @$tickets = @$el.find('#tickets')
    @renderTickets()
    @
  
  renderTickets: ->
    tickets = @visibleTickets.map (ticket)->
      json = ticket.toJSON()
      json.effort = ticket.estimatedEffort()
      json.saved = ticket.estimated()
      json
    @$tickets.html @ticketsTemplate(tickets: tickets)
    @$tickets.find('.ticket').pseudoHover()
  
  
  toggleShowCompleted: (e)->
    $button = $(e.target)
    if $button.hasClass('active')
      $button.removeClass('btn-success')
      @visibleTickets = @tickets.ableToEstimate().withoutEffortEstimate()
      @renderTickets()
    else
      $button.addClass('btn-success')
      @visibleTickets = @tickets
      @renderTickets()



  toggleSort: ($th)->
    if $th.hasClass('sort-asc')
      $th.removeClass('sort-asc').addClass('sort-desc')
    else if $th.hasClass('sort-desc')
      $th.removeClass('sort-desc').addClass('sort-asc')
    else
      @$el.find('.sort-asc, .sort-desc').removeClass('sort-asc sort-desc')
      $th.addClass('sort-desc')
    
    attribute = $th.attr('data-attribute')
    order = if $th.hasClass('sort-desc') then 'desc' else 'asc'
    @performSort attribute, order
  
  performSort: (attribute, order)->
    sorter = @["#{attribute}Sorter"]
    return console.log "#{attribute}Sorter is undefined!" unless sorter
    
    @visibleTickets = @visibleTickets.sortBy(sorter)
    @visibleTickets = @visibleTickets.reverse() if order == 'desc'
    @visibleTickets = new Scheduler.Tickets(@visibleTickets)
    @renderTickets()

{'fraction_non_alphanumeric': 0.15578865578865578, 'fraction_numerical': 0.00019425019425019425, 'mean_word_length': 3.3598645215918714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6002743', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1699, 'n_words': 282}