Skip to content

Instantly share code, notes, and snippets.

@onlymejosh
Created December 16, 2016 11:30
Show Gist options
  • Save onlymejosh/0f7307bdfe8db464e8503eac5c4188f8 to your computer and use it in GitHub Desktop.
Save onlymejosh/0f7307bdfe8db464e8503eac5c4188f8 to your computer and use it in GitHub Desktop.
reorderTicket: (first_id, order, second_id) ->
tickets = @get('tickets').sortBy('position')
ticket_ids = tickets.mapBy('id').removeObject(first_id)
second_pos = ticket_ids.indexOf(second_id)
new_pos = if order == 'above' then second_pos else second_pos+1
ticket_ids.splice(new_pos, 0, first_id)
for ticket_id, position in ticket_ids
ticket = tickets.findBy('id', ticket_id)
ticket.set('position', position)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment