import Ember from 'ember'
export default Ember.Controller.extend
  grouped_tracker_groups_setter: (->
    project_groups = Ember.A()
    @get("model.workflow_groups").then (workflow_groups) ->
      workflow_groups.forEach (workflow_group) ->
        if existing_group = project_groups.findBy("model.id", workflow_group.get("project.id"))
          existing_group.get("workflow_groups").pushObject(workflow_group)
        else
          project_groups.push Ember.Object.create
            model: workflow_group.get('project')
            workflow_groups: Ember.A([workflow_group])
    @set("grouped_projects", project_groups)
  ).observes("model.workflow_groups.[]")
