Show only 2 tasks of the same periodic_task_group at dashboard

This commit is contained in:
Patrick Gansterer 2017-10-20 01:01:12 +02:00
parent ad96159336
commit 47e4a9afdf
2 changed files with 13 additions and 3 deletions

View file

@ -8,7 +8,7 @@ class HomeController < ApplicationController
@next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
# count tasks with no responsible person
# tasks for groups the current user is not a member are ignored
@unassigned_tasks = Task.order(:due_date).unassigned_tasks_for(current_user)
@unassigned_tasks = Task.order(:due_date).next_unassigned_tasks_for(current_user)
end
def profile

View file

@ -52,6 +52,16 @@ class Task < ActiveRecord::Base
end
end
def self.next_unassigned_tasks_for(user, max = 2)
periodic_task_group_count = {}
self.unassigned_tasks_for(user).reject do |item|
return false unless item.periodic_task_group
count = periodic_task_group_count[item.periodic_task_group] || 0
periodic_task_group_count[item.periodic_task_group] = count + 1
count >= max
end
end
def periodic?
not periodic_task_group.nil?
end
@ -59,11 +69,11 @@ class Task < ActiveRecord::Base
def is_assigned?(user)
self.assignments.detect {|ass| ass.user_id == user.id }
end
def is_accepted?(user)
self.assignments.detect {|ass| ass.user_id == user.id && ass.accepted }
end
def enough_users_assigned?
assignments.to_a.count(&:accepted) >= required_users ? true : false
end