给资源栏目增加board

This commit is contained in:
ouyangxuhua 2015-12-30 10:34:37 +08:00
parent 2cd48a1ca2
commit 40bf109223
7 changed files with 40 additions and 1 deletions

View File

@ -19,6 +19,7 @@ class Board < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project,:touch => true
belongs_to :course,:touch=>true
belongs_to :org_subfield, :touch => true
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id

View File

@ -4,7 +4,22 @@ class OrgSubfield < ActiveRecord::Base
has_many :files
has_many :org_subfield_messages, :dependent => :destroy
has_many :messages, :through => :org_subfield_messages
has_many :boards, :dependent => :destroy
acts_as_attachable
after_create :create_board_sync
# 创建资源栏目讨论区
def create_board_sync
@board = self.boards.build
#self.name=" #{l(:label_borad_course) }"
@board.name = " #{l(:label_borad_org_subfield) }"#self.name
@board.description = self.name.to_s
@board.project_id = -1
if @board.save
logger.debug "[OrgSubfield Model] ===> #{@board.to_json}"
else
logger.error "[OrgSubfield Model] ===> Auto create board when org_subfield saved, because #{@board.full_messages}"
end
end
def project
end

View File

@ -1728,6 +1728,7 @@ zh:
label_hot_project: '热门项目'
label_borad_project: 项目讨论区
label_borad_course: 课程讨论区
label_borad_org_subfield: 资源栏目讨论区
view_borad_course: 课程讨论
label_memo_create_succ: 发布成功
label_memo_create_fail: 发布失败

View File

@ -0,0 +1,4 @@
class AddQuotesToMessages < ActiveRecord::Migration
def change
end
end

View File

@ -0,0 +1,5 @@
class AddOrgSubfieldIdToBoards < ActiveRecord::Migration
def change
add_column :boards, :org_subfield_id, :integer
end
end

View File

@ -0,0 +1,11 @@
# encoding: utf-8
class SetBoardForOrgSubfields < ActiveRecord::Migration
def up
OrgSubfield.where("field_type='Post'").each do |field|
Board.create(:org_subfield_id => field.id, :name => "资源栏目讨论区", :project_id => -1, :description => field.name)
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151224090313) do
ActiveRecord::Schema.define(:version => 20151230015904) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -198,6 +198,7 @@ ActiveRecord::Schema.define(:version => 20151224090313) do
t.integer "last_message_id"
t.integer "parent_id"
t.integer "course_id"
t.integer "org_subfield_id"
end
add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id"
@ -1045,6 +1046,7 @@ ActiveRecord::Schema.define(:version => 20151224090313) do
t.boolean "locked", :default => false
t.integer "sticky", :default => 0
t.integer "reply_id"
t.integer "quotes"
end
add_index "messages", ["author_id"], :name => "index_messages_on_author_id"