kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.2 KiB
94 lines
3.2 KiB
class Meeting < ActiveRecord::Base
|
|
unloadable
|
|
|
|
belongs_to :project
|
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
|
has_one :agenda, :dependent => :destroy, :class_name => 'MeetingAgenda'
|
|
has_one :minutes, :dependent => :destroy, :class_name => 'MeetingMinutes'
|
|
has_many :contents, :class_name => 'MeetingContent', :readonly => true
|
|
has_many :participants, :dependent => :destroy, :class_name => 'MeetingParticipant'
|
|
|
|
acts_as_watchable
|
|
|
|
acts_as_searchable :columns => ["#{table_name}.title", "#{MeetingContent.table_name}.text"],
|
|
:include => [:contents, :project],
|
|
:date_column => "#{table_name}.created_at"
|
|
|
|
acts_as_event :title => Proc.new {|o| "#{l :label_meeting}: #{o.title} (#{format_date o.start_time} #{format_time o.start_time, false}-#{format_time o.end_time, false})"},
|
|
:description => :text,
|
|
:datetime => :created_at,
|
|
:url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o}}
|
|
|
|
acts_as_activity_provider :timestamp => "#{table_name}.created_at",
|
|
:author_key => :author_id,
|
|
:find_options => {:include => [:agenda, :project, :author]}
|
|
|
|
accepts_nested_attributes_for :participants, :reject_if => proc {|attrs| !(attrs['attended'] || attrs['invited'])}
|
|
|
|
validates_presence_of :title, :start_time, :duration
|
|
|
|
after_create :add_author_as_watcher
|
|
|
|
def self.find_time_sorted(*args)
|
|
by_start_year_month_date = ActiveSupport::OrderedHash.new
|
|
self.find(*args).group_by(&:start_year).each do |year,objs|
|
|
by_start_year_month_date[year] = ActiveSupport::OrderedHash.new
|
|
objs.group_by(&:start_month).each do |month,objs|
|
|
by_start_year_month_date[year][month] = ActiveSupport::OrderedHash.new
|
|
objs.group_by(&:start_date).each do |date,objs|
|
|
by_start_year_month_date[year][month][date] = objs.sort_by {|m| m.start_time}.reverse
|
|
end
|
|
end
|
|
end
|
|
by_start_year_month_date
|
|
end
|
|
|
|
def start_date
|
|
# the text_field + calendar_for form helpers expect a Date
|
|
start_time.to_date if start_time.present?
|
|
end
|
|
|
|
def start_month
|
|
start_time.month
|
|
end
|
|
|
|
def start_year
|
|
start_time.year
|
|
end
|
|
|
|
def end_time
|
|
start_time + duration.hours
|
|
end
|
|
|
|
def to_s
|
|
title
|
|
end
|
|
|
|
def text
|
|
agenda.text if agenda.present?
|
|
end
|
|
|
|
def copy(attrs)
|
|
copy = self.clone
|
|
copy.attributes = attrs
|
|
copy.send(:after_initialize)
|
|
copy_participant_user_ids = copy.participants.collect(&:user_id)
|
|
copy.participants << self.participants.invited.reject{|p| copy_participant_user_ids.include? p.user_id}.collect(&:clone).each{|p| p.attended=false} # Make sure the participants have no id
|
|
copy
|
|
end
|
|
|
|
protected
|
|
|
|
def after_initialize
|
|
# set defaults
|
|
self.start_time ||= Date.tomorrow + 10.hours
|
|
self.duration ||= 1
|
|
self.participants.build(:user => self.author, :invited => true) if (self.new_record? && self.participants.empty? && self.author) # Don't add the author as participant if we already have some through nested attributes
|
|
end
|
|
|
|
private
|
|
|
|
def add_author_as_watcher
|
|
add_watcher(author)
|
|
end
|
|
end
|
|
|