Removed fancybox. Fixed profile, my ordergroup and tasks.

This commit is contained in:
benni 2012-11-12 09:03:23 +01:00
parent dce79802e0
commit 1d9815731c
37 changed files with 124 additions and 518 deletions

View file

@ -3,9 +3,12 @@ class Task < ActiveRecord::Base
has_many :users, :through => :assignments
belongs_to :workgroup
scope :non_group, :conditions => { :workgroup_id => nil, :done => false }
scope :done, :conditions => {:done => true}, :order => "due_date DESC"
scope :non_group, where(workgroup_id: nil, done: false)
scope :done, where(done: true)
scope :undone, where(done: false)
attr_accessor :current_user_id
# form will send user in string. responsibilities will added later
attr_protected :users
@ -15,7 +18,33 @@ class Task < ActiveRecord::Base
validates_length_of :description, maximum: 250
after_save :update_ordergroup_stats
# Find all tasks, for which the current user should be responsible
# but which aren't accepted yet
def self.unaccepted_tasks_for(user)
user.tasks.undone.where(assignments: {accepted: false})
end
# Find all accepted tasks, which aren't done
def self.accepted_tasks_for(user)
user.tasks.undone.where(assignments: {accepted: true})
end
# find all tasks in the next week (or another number of days)
def self.next_assigned_tasks_for(user, number = 7)
user.tasks.undone.where(assignments: {accepted: true}).
where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now])
end
# count tasks with no responsible person
# tasks for groups the user is not a member are ignored
def self.unassigned_tasks_for(user)
Task.undone.where(assigned: false).includes(:workgroup).all.select do |task|
!task.workgroup or user.member_of?(task.workgroup)
end
end
def is_assigned?(user)
self.assignments.detect {|ass| ass.user_id == user.id }
end
@ -35,13 +64,13 @@ class Task < ActiveRecord::Base
new_users = list - users.collect(&:id)
old_users = users.reject { |user| list.include?(user.id) }
logger.debug "New users: #{new_users}"
logger.debug "[debug] New users: #{new_users}"
logger.debug "Old users: #{old_users}"
self.class.transaction do
# delete old assignments
if old_users.any?
assignments.find(:all, :conditions => ["user_id IN (?)", old_users.collect(&:id)]).each(&:destroy)
assignments.where(user_id: old_users.map(&:id)).each(&:destroy)
end
# create new assignments
new_users.each do |id|
@ -49,7 +78,7 @@ class Task < ActiveRecord::Base
if user.blank?
errors.add(:user_list)
else
if user == User.current_user
if id == current_user_id
# current_user will accept, when he puts himself to the list of users
self.assignments.build :user => user, :accepted => true
else

View file

@ -138,44 +138,6 @@ class User < ActiveRecord::Base
ordergroup ? ordergroup.name : "keine Bestellgruppe"
end
# Find all tasks, for which the current user should be responsible
# but which aren't accepted yet
def unaccepted_tasks
# this doesn't work. Produces "undefined method", when later use task.users... Rails Bug?
# self.tasks.find :all, :conditions => ["accepted = ?", false], :order => "due_date DESC"
Task.find_by_sql ["SELECT t.* FROM tasks t, assignments a, users u
WHERE u.id = a.user_id
AND t.id = a.task_id
AND u.id = ?
AND a.accepted = ?
AND t.done = ?
ORDER BY t.due_date ASC", self.id, false, false]
end
# Find all accepted tasks, which aren't done
def accepted_tasks
Task.find_by_sql ["SELECT t.* FROM tasks t, assignments a, users u
WHERE u.id = a.user_id
AND t.id = a.task_id
AND u.id = ?
AND a.accepted = ?
AND t.done = ?
ORDER BY t.due_date ASC", self.id, true, false]
end
# find all tasks in the next week (or another number of days)
def next_tasks(number = 7)
Task.find_by_sql ["SELECT t.* FROM tasks t, assignments a, users u
WHERE u.id = a.user_id
AND t.id = a.task_id
AND u.id = ?
AND t.due_date >= ?
AND t.due_date <= ?
AND t.done = ?
AND a.accepted = ?
ORDER BY t.due_date ASC", self.id, Time.now, number.days.from_now, false, true]
end
# returns true if user is a member of a given group
def member_of?(group)
group.users.exists?(self.id)