修改新闻model、路由、index方法
This commit is contained in:
parent
3165d97417
commit
d6280befca
|
@ -64,7 +64,7 @@ class NewsController < ApplicationController
|
||||||
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
||||||
end
|
end
|
||||||
elsif @course
|
elsif @course
|
||||||
scope = @course ? @course.news.visible : News.visible
|
scope = @course ? @course.news.course_visible : News.course_visible
|
||||||
|
|
||||||
@news_count = scope.count
|
@news_count = scope.count
|
||||||
@news_pages = Paginator.new @news_count, @limit, params['page']
|
@news_pages = Paginator.new @news_count, @limit, params['page']
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
class News < ActiveRecord::Base
|
class News < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
#added by nwb
|
||||||
|
belongs_to :course
|
||||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
|
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
|
||||||
# fq
|
# fq
|
||||||
|
@ -33,9 +35,13 @@ class News < ActiveRecord::Base
|
||||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||||
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||||
:author_key => :author_id
|
:author_key => :author_id
|
||||||
|
#added by nwb
|
||||||
|
#课程新闻独立于项目
|
||||||
|
acts_as_activity_provider :type => 'course_news',
|
||||||
|
:find_options => {:include => [:project, :author]},
|
||||||
|
:author_key => :author_id
|
||||||
acts_as_watchable
|
acts_as_watchable
|
||||||
|
|
||||||
|
|
||||||
after_create :add_author_as_watcher
|
after_create :add_author_as_watcher
|
||||||
# fq
|
# fq
|
||||||
after_create :act_as_activity
|
after_create :act_as_activity
|
||||||
|
@ -45,6 +51,9 @@ class News < ActiveRecord::Base
|
||||||
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :course_visible, lambda {|*args|
|
||||||
|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_news, *args))
|
||||||
|
}
|
||||||
safe_attributes 'title', 'summary', 'description'
|
safe_attributes 'title', 'summary', 'description'
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
|
|
|
@ -566,7 +566,7 @@ RedmineApp::Application.routes.draw do
|
||||||
get 'appliedproject'
|
get 'appliedproject'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :news, :except => [:show, :edit, :update, :destroy]
|
||||||
end # end of resources :courses
|
end # end of resources :courses
|
||||||
match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback'
|
match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback'
|
||||||
match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post]
|
match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140606028512) do
|
ActiveRecord::Schema.define(:version => 20140611161801) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -578,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20140606028512) do
|
||||||
t.integer "author_id", :default => 0, :null => false
|
t.integer "author_id", :default => 0, :null => false
|
||||||
t.datetime "created_on"
|
t.datetime "created_on"
|
||||||
t.integer "comments_count", :default => 0, :null => false
|
t.integer "comments_count", :default => 0, :null => false
|
||||||
|
t.integer "course_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "news", ["author_id"], :name => "index_news_on_author_id"
|
add_index "news", ["author_id"], :name => "index_news_on_author_id"
|
||||||
|
|
|
@ -419,6 +419,7 @@ Redmine::Activity.map do |activity|
|
||||||
# end
|
# end
|
||||||
#added by nwb
|
#added by nwb
|
||||||
#activity.register :course_journals_for_messages
|
#activity.register :course_journals_for_messages
|
||||||
|
activity.register :course_news, :class_name => 'News'
|
||||||
end
|
end
|
||||||
|
|
||||||
Redmine::Search.map do |search|
|
Redmine::Search.map do |search|
|
||||||
|
|
Loading…
Reference in New Issue