Show only 2 tasks of the same periodic_task_group at dashboard
This commit is contained in:
parent
ad96159336
commit
47e4a9afdf
2 changed files with 13 additions and 3 deletions
|
@ -8,7 +8,7 @@ class HomeController < ApplicationController
|
||||||
@next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
|
@next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
|
||||||
# count tasks with no responsible person
|
# count tasks with no responsible person
|
||||||
# tasks for groups the current user is not a member are ignored
|
# 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
|
end
|
||||||
|
|
||||||
def profile
|
def profile
|
||||||
|
|
|
@ -52,6 +52,16 @@ class Task < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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?
|
def periodic?
|
||||||
not periodic_task_group.nil?
|
not periodic_task_group.nil?
|
||||||
end
|
end
|
||||||
|
@ -59,11 +69,11 @@ class Task < ActiveRecord::Base
|
||||||
def is_assigned?(user)
|
def is_assigned?(user)
|
||||||
self.assignments.detect {|ass| ass.user_id == user.id }
|
self.assignments.detect {|ass| ass.user_id == user.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_accepted?(user)
|
def is_accepted?(user)
|
||||||
self.assignments.detect {|ass| ass.user_id == user.id && ass.accepted }
|
self.assignments.detect {|ass| ass.user_id == user.id && ass.accepted }
|
||||||
end
|
end
|
||||||
|
|
||||||
def enough_users_assigned?
|
def enough_users_assigned?
|
||||||
assignments.to_a.count(&:accepted) >= required_users ? true : false
|
assignments.to_a.count(&:accepted) >= required_users ? true : false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue