diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 5b7106ee3..35b681c97 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -63,7 +63,7 @@ class ForumsController < ApplicationController respond_to do |format| if @forum.save - format.html { redirect_to @forum, notice: 'Forum was successfully created.' } + format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } format.json { render json: @forum, status: :created, location: @forum } else format.html { render action: "new" } diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index d95fc2623..0908a1071 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -125,7 +125,7 @@ module WelcomeHelper # user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") activity = Redmine::Activity::Fetcher.new(nil) - activity.events_welcome(nil, nil, {:limit => limit}) + activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'}) end #取得论坛数据 diff --git a/app/models/bid.rb b/app/models/bid.rb index bb7868ef8..97a81fe03 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -1,131 +1,131 @@ -####by fq -class Bid < ActiveRecord::Base - attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password - include Redmine::SafeAttributes - - belongs_to :author, :class_name => 'User', :foreign_key => :author_id - belongs_to :course - has_many :biding_projects, :dependent => :destroy - has_many :projects, :through => :biding_projects - has_many :projects_member, :class_name => 'User', :through => :projects - has_many :journals_for_messages, :as => :jour, :dependent => :destroy - has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy - has_many :homework_for_courses, :dependent => :destroy - has_many :courses, :through => :homework_for_courses, :source => :project - has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy - has_many :join_in_contests, :dependent => :destroy - # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" - - - acts_as_attachable - - NAME_LENGTH_LIMIT = 60 - DESCRIPTION_LENGTH_LIMIT = 250 - - validates_length_of :name, :maximum => NAME_LENGTH_LIMIT - validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT - validates_presence_of :author_id, :name, :deadline - # validates_presence_of :deadline, :message => 'test' - # validates_format_of :deadline, :with => - validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ - validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/, - :if => Proc.new { |p| p.reward_type == 1 } - validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{1})$/, :if => Proc.new { |p| p.reward_type == 3 } - validate :validate_user - validate :validate_reward_type - after_create :act_as_activity - - scope :visible, lambda {|*args| - nil - } - - scope :like, lambda {|arg| - if arg.blank? - where(nil) - else - pattern = "%#{arg.to_s.strip.downcase}%" - where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern) - end - } - - acts_as_watchable - acts_as_taggable - - acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" }, - :description => :description, - :author => :author, - :url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}} - - acts_as_activity_provider :find_options => {:include => [:projects, :author]}, - :author_key => :author_id - - safe_attributes 'name', - 'description', - 'budget', - 'deadline', - 'homework_type', - 'reward_type', - 'password' - - - # safe_attributes 'name', - # 'description', - # 'deadline' - def add_jour(user, notes, reference_user_id = 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) - end - - def self.creat_bids(budget, deadline, name, description=nil, reward_type) - self.create(:author_id => User.current.id, :budget => budget, - :deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type) - # self.acts << Activity.new(:user_id => self.author_id) - end - - def update_bids(budget, deadline, name, description=nil) - if(User.current.id == self.author_id) - self.name = name - self.budget = budget - self.deadline = deadline - self.description = description - self.save - end - end - - def delete_bids - unless self.nil? - if User.current.id == self.author_id - self.destroy - end - end - end - - def set_commit(commit) - self.update_attribute(:commit, commit) - end - - private - - def validate_user - errors.add :author_id, :invalid if author.nil? || !author.active? - end - - def validate_reward_type - errors.add :reward_type, :invalid if self.reward_type == 0 - end - - def act_as_activity - self.acts << Activity.new(:user_id => self.author_id) - end - - # used to validate weather the user is the creater of the bid - # added by william - def validate_bid_manager(user_id) - unless user_id.nil? - if self.author_id == user_id - return true - else - return false - end - end - end -end +####by fq +class Bid < ActiveRecord::Base + attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password + include Redmine::SafeAttributes + + belongs_to :author, :class_name => 'User', :foreign_key => :author_id + belongs_to :course + has_many :biding_projects, :dependent => :destroy + has_many :projects, :through => :biding_projects + has_many :projects_member, :class_name => 'User', :through => :projects + has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy + has_many :homework_for_courses, :dependent => :destroy + has_many :courses, :through => :homework_for_courses, :source => :project + has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy + has_many :join_in_contests, :dependent => :destroy + # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" + + + acts_as_attachable + + NAME_LENGTH_LIMIT = 60 + DESCRIPTION_LENGTH_LIMIT = 250 + + validates_length_of :name, :maximum => NAME_LENGTH_LIMIT + validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT + validates_presence_of :author_id, :name, :deadline + # validates_presence_of :deadline, :message => 'test' + # validates_format_of :deadline, :with => + validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ + validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/, + :if => Proc.new { |p| p.reward_type == 1 } + validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{1})$/, :if => Proc.new { |p| p.reward_type == 3 } + validate :validate_user + validate :validate_reward_type + after_create :act_as_activity + + scope :visible, lambda {|*args| + nil + } + + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern) + end + } + + acts_as_watchable + acts_as_taggable + + acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" }, + :description => :description, + :author => :author, + :url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}} + + acts_as_activity_provider :find_options => {:include => [:projects, :author]}, + :author_key => :author_id + + safe_attributes 'name', + 'description', + 'budget', + 'deadline', + 'homework_type', + 'reward_type', + 'password' + + + # safe_attributes 'name', + # 'description', + # 'deadline' + def add_jour(user, notes, reference_user_id = 0) + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + end + + def self.creat_bids(budget, deadline, name, description=nil, reward_type) + self.create(:author_id => User.current.id, :budget => budget, + :deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type) + # self.acts << Activity.new(:user_id => self.author_id) + end + + def update_bids(budget, deadline, name, description=nil) + if(User.current.id == self.author_id) + self.name = name + self.budget = budget + self.deadline = deadline + self.description = description + self.save + end + end + + def delete_bids + unless self.nil? + if User.current.id == self.author_id + self.destroy + end + end + end + + def set_commit(commit) + self.update_attribute(:commit, commit) + end + + private + + def validate_user + errors.add :author_id, :invalid if author.nil? || !author.active? + end + + def validate_reward_type + errors.add :reward_type, :invalid if self.reward_type == 0 + end + + def act_as_activity + self.acts << Activity.new(:user_id => self.author_id) + end + + # used to validate weather the user is the creater of the bid + # added by william + def validate_bid_manager(user_id) + unless user_id.nil? + if self.author_id == user_id + return true + else + return false + end + end + end +end diff --git a/app/models/memo.rb b/app/models/memo.rb index b494064be..a06d8dcf5 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -16,14 +16,16 @@ class Memo < ActiveRecord::Base # #:include => { :forum => :p} # #:project_key => "#{Forum.table_name}.project_id" # :date_column => "#{table_name}.created_at" - # acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"}, - # :description => :content, - # :group => :parent, - # :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, - # :url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "memo-#{o.id}"})} - acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, - :author_key => :author_id - acts_as_watchable + acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"}, + :datetime => :created_at, + :description => :content, + :author => :author, + :type => Proc.new {|o| o.parent_id.nil? ? 'Forum' : 'Memo'}, + :url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :anchor => "reply-#{o.id}"})} + acts_as_activity_provider :author_key => :author_id, + :func => 'memos' + # :find_options => {:type => 'memos'} + # acts_as_watchable safe_attributes "author_id", "subject", diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 6b9d82dfd..96f7d2a4b 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -1,7 +1,4 @@ -
- <%= notice %> -