<commit_before>class Roadmap.EditRoadmapView extends Roadmap.RoadmapView
  MAX_BANDS = 4
  $newMilestone: null
  newMilestoneX: null
  supportsCreate: false
  
  
  constructor: (milestones, options={})->
    @project = options.project
    super(milestones, options)
    $(document.body).on 'keyup', (e)=>
      return unless @$newMilestone and @supportsCreate
      @cancelCreate() if e.keyCode is 27
  
  
  createMilestone: (callback)->
    @supportsCreate = !!callback
    @_createMilestoneCallback = callback
    @
  
  
  render: ->
    super
    @$el.on 'mouseleave', => @cancelCreate()
    
    @$el.on 'mouseup', (e)=>
      return unless @$newMilestone and @supportsCreate
      newMilestoneWidth = e.screenX - @newMilestoneX
      if newMilestoneWidth > 10
        band = +@$newMilestone.closest('.roadmap-band').attr('data-band')
        startDate = @x.invert(@$newMilestone.position().left)
        endDate = @x.invert(@$newMilestone.position().left + @$newMilestone.width())
        attributes = 
          band: band
          startDate: d3.time.monday.round(startDate)
          endDate: d3.time.saturday.round(endDate)
        @$newMilestone.addClass('creating').text('Saving...')
        @$el.removeClass('drag-create')
        [$newMilestone, @$newMilestone] = [@$newMilestone, null]
        @_createMilestoneCallback attributes, -> $newMilestone.remove()
      else
        @cancelCreate()
    
    @$el.on 'mousemove', (e)=>
      return unless @$newMilestone and @supportsCreate
      newMilestoneWidth = e.screenX - @newMilestoneX
      newMilestoneWidth = 0 if newMilestoneWidth < 0
      
      startDate = @x.invert(@$newMilestone.position().left)
      endDate = d3.time.saturday.round(@x.invert(@$newMilestone.position().left + newMilestoneWidth))
      milliseconds = endDate.getTime() - startDate.getTime() + 2 * Duration.DAY
      weeks = Math.floor(milliseconds / Duration.WEEK)
      
      @$newMilestone.css(width: newMilestoneWidth)
      if weeks < 2
        @$newMilestone.html("&nbsp;")
      else
        @$newMilestone.html("<span>#{weeks}&nbsp;weeks</span>")
  
  
  cancelCreate: ->
    return unless @$newMilestone and @supportsCreate
    @$el.removeClass('drag-create')
    @$newMilestone.remove()
    @$newMilestone = null
  
  
  groupMilestonesIntoBands: ->
    milestoneBands = super
    
    nextBand = +d3.max(milestoneBands, (band)-> band.number) + 1
    nextBand = 1 if _.isNaN(nextBand)
    if nextBand <= MAX_BANDS
      milestoneBands.push
        key: "#{@project.id}-#{nextBand}"
        projectId: @project.id
        color: @project.color
        number: nextBand
        milestones: []
    
    milestoneBands
  
  
  initializeBand: (band)->
    view = @
    
    $(band).droppable
      hoverClass: 'sort-active'
      over: (event, ui)->
        return unless view.drag
        view.drag.bandOver = +$(@).attr('data-band')
        
      drop: (event, ui)->
        band = +$(@).attr('data-band')
        id = ui.draggable.attr('data-cid')
        milestone = view.milestones.get(id)
        return unless milestone
        
        startDate = d3.time.monday.round(view.x.invert(ui.position.left))
        ui.draggable.css left: view.x(startDate)
        
        milestone.set
          band: band
          startDate: startDate
          endDate: milestone.duration().after startDate
        
        return unless view.drag
        return unless view.drag.band is view.drag.bandOver
        return unless view.drag.maxLeft
        return unless ui.position.left > view.drag.maxLeft
        
        delta = ui.position.left - view.drag.offsetLeft + view.drag.originalLeft - view.drag.maxLeft
        
        for i in [0...view.drag.milestonesAfter.length]
          milestone = view.drag.milestonesAfter[i]<commit_msg>[fix] Fixed dragging a row of milestones (8m)<commit_after>class Roadmap.EditRoadmapView extends Roadmap.RoadmapView
  MAX_BANDS = 4
  $newMilestone: null
  newMilestoneX: null
  supportsCreate: false
  
  
  constructor: (milestones, options={})->
    @project = options.project
    super(milestones, options)
    $(document.body).on 'keyup', (e)=>
      return unless @$newMilestone and @supportsCreate
      @cancelCreate() if e.keyCode is 27
  
  
  createMilestone: (callback)->
    @supportsCreate = !!callback
    @_createMilestoneCallback = callback
    @
  
  
  render: ->
    super
    @$el.on 'mouseleave', => @cancelCreate()
    
    @$el.on 'mouseup', (e)=>
      return unless @$newMilestone and @supportsCreate
      newMilestoneWidth = e.screenX - @newMilestoneX
      if newMilestoneWidth > 10
        band = +@$newMilestone.closest('.roadmap-band').attr('data-band')
        startDate = @x.invert(@$newMilestone.position().left)
        endDate = @x.invert(@$newMilestone.position().left + @$newMilestone.width())
        attributes = 
          band: band
          startDate: d3.time.monday.round(startDate)
          endDate: d3.time.saturday.round(endDate)
        @$newMilestone.addClass('creating').text('Saving...')
        @$el.removeClass('drag-create')
        [$newMilestone, @$newMilestone] = [@$newMilestone, null]
        @_createMilestoneCallback attributes, -> $newMilestone.remove()
      else
        @cancelCreate()
    
    @$el.on 'mousemove', (e)=>
      return unless @$newMilestone and @supportsCreate
      newMilestoneWidth = e.screenX - @newMilestoneX
      newMilestoneWidth = 0 if newMilestoneWidth < 0
      
      startDate = @x.invert(@$newMilestone.position().left)
      endDate = d3.time.saturday.round(@x.invert(@$newMilestone.position().left + newMilestoneWidth))
      milliseconds = endDate.getTime() - startDate.getTime() + 2 * Duration.DAY
      weeks = Math.floor(milliseconds / Duration.WEEK)
      
      @$newMilestone.css(width: newMilestoneWidth)
      if weeks < 2
        @$newMilestone.html("&nbsp;")
      else
        @$newMilestone.html("<span>#{weeks}&nbsp;weeks</span>")
  
  
  cancelCreate: ->
    return unless @$newMilestone and @supportsCreate
    @$el.removeClass('drag-create')
    @$newMilestone.remove()
    @$newMilestone = null
  
  
  groupMilestonesIntoBands: ->
    milestoneBands = super
    
    nextBand = +d3.max(milestoneBands, (band)-> band.number) + 1
    nextBand = 1 if _.isNaN(nextBand)
    if nextBand <= MAX_BANDS
      milestoneBands.push
        key: "#{@project.id}-#{nextBand}"
        projectId: @project.id
        color: @project.color
        number: nextBand
        milestones: []
    
    milestoneBands
  
  
  initializeBand: (band)->
    view = @
    
    $(band).droppable
      hoverClass: 'sort-active'
      over: (event, ui)->
        return unless view.drag
        view.drag.bandOver = +$(@).attr('data-band')
        
      drop: (event, ui)->
        band = +$(@).attr('data-band')
        id = ui.draggable.attr('data-cid')
        milestone = view.milestones.get(id)
        return unless milestone
        
        startDate = d3.time.monday.round(view.x.invert(ui.position.left))
        ui.draggable.css left: view.x(startDate)
        
        milestone.set
          band: band
          startDate: startDate
          endDate: milestone.duration().after startDate
        
        return unless view.drag
        return unless view.drag.band is view.drag.bandOver
        
        delta = ui.position.left - view.drag.offsetLeft + view.drag.originalLeft - view.drag.maxLeft
        return if delta <= 0
        
        for i in [0...view.drag.milestonesAfter.length]
          milestone = view.drag.milestonesAfter[i]
{'fraction_non_alphanumeric': 0.1291135881104034, 'fraction_numerical': 0.004777070063694267, 'mean_word_length': 2.503951650395165, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 38, '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': '679606', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2383, 'n_words': 443}