竞赛通知 index方法

This commit is contained in:
huang 2016-12-23 17:00:11 +08:00
parent 544702e11f
commit 0877aae0d6
8 changed files with 188 additions and 50 deletions

View File

@ -42,6 +42,8 @@ class NewsController < ApplicationController
@limit = 10
end
@contest = Contest.find(params[:contest_id]) if params[:contest_id]
# modify by nwb
if params[:course_id] && @course==nil
@course = Course.find(params[:course_id])
@ -69,6 +71,83 @@ class NewsController < ApplicationController
format.api
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
elsif @contest
if (User.current.admin? || @contest.is_public == 1 || (@contest.is_public == 0 && User.current.member_of_contest?(@contest)))
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
#确定 sort_type 1升序 2 降序
if @order.to_i == @type.to_i
@b_sort = @b_sort.to_i == 1 ? 2 : 1
else
@b_sort = 2
end
sort_name = "updated_at"
sort_type = @b_sort == 1 ? "asc" : "desc"
#scope = News.find_by_sql("select a.*,b.updated_at from news a, course_activities b where a.course_id = 532 and a.course_id = b.course_id and b.course_act_id = a.id ) ")
scope = @contest ? @contest.news.visible : News.visible
# @newss = scope.all(:include => [:author, :contest], :order => "#{News.table_name}.created_on DESC")
#
# @page = params[:page] ? params[:page].to_i + 1 : 0
news_page = 0 #@page *10
# @news_count = @newss.count
# @is_new = params[:is_new]
@q = params[:subject]
if params[:subject].nil? || params[:subject].blank?
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on #{sort_type}").offset(news_page).includes(:author,:course).all()
else
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:contest).all()
end
scope_order.each do |topic|
topic[:updated_at] = topic.contest_acts.first.updated_at
#topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at
end
#根据 赞+回复数排序
if @order.to_i == 2
@type = 2
scope_order.each do |topic|
topic[:infocount] = get_praise_num(topic) + topic.comments.count
if topic[:infocount] < 0
topic[:infocount] = 0
end
end
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:infocount] <=> y[:infocount] } : scope_order = scope_order.sort{|x,y| y[:infocount] <=> x[:infocount] }
scope_order = sort_by_sticky scope_order
scope_order = sortby_time_countcommon_hassticky scope_order,sort_name
else
@type = 1
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:updated_at] <=> y[:updated_at] } : scope_order = scope_order.sort{|x,y| y[:updated_at] <=> x[:updated_at] }
scope_order = sort_by_sticky scope_order
end
@newss = scope_order
#分页
@limit = 15
@is_remote = true
@atta_count = @newss.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
@newss = paginateHelper @newss,@limit
#@newss = paginateHelper scope_order,10
@left_nav_type = 4
respond_to do |format|
format.html {
@news = News.new
render :layout => 'base_contests'
}
format.js
format.api
end
else
render_403
end
elsif @course
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1

View File

@ -14,6 +14,8 @@ class Contest < ActiveRecord::Base
has_many :contestants, :class_name => 'ContestantForContest', :source => :user
has_many :works
has_many :news, :dependent => :destroy, :include => :author
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
has_many :contest_activities
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy

View File

@ -25,6 +25,7 @@ class News < ActiveRecord::Base
has_many_kindeditor_assets :assets, :dependent => :destroy
#added by nwb
belongs_to :course,:touch => true
belongs_to :contest,:touch => true
belongs_to :org_subfield, :touch => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :comments, :as => :commented, :dependent => :destroy, :order => "created_on"
@ -79,6 +80,10 @@ class News < ActiveRecord::Base
scope :course_visible, lambda {|*args|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
}
scope :contest_visible, lambda {|*args|
includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contest_news, *args))
}
safe_attributes 'title', 'summary', 'description', 'sticky'
#动态的更新

View File

@ -0,0 +1,34 @@
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_news(){
$("#news_title").val("");
$("#title_notice_span").text("");
$("#description_notice_span").text("");
document.getElementById("news_sticky").checked=false;
$("#news_attachments").html("<%= escape_javascript(render :partial => 'attachments/new_form', :locals => {:container => News.new})%>");
news_description_editor.html("");
$("#news_editor").toggle();
}
<% if @is_new%>
$(function(){
$("#news_title").focus();
});
<%end%>
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
班级通知
</div>
</div>
<% if @course && User.current.allowed_to?(:manage_news, @course) %>
<%= labelled_form_for @news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id},
:html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %>
<%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => false, :course => @course} %>
<% end %>
<% end %>
<%= render :partial=> 'course_news_detail',:locals =>{:newss => @newss, :page => 0} %>
</div>

View File

@ -2,6 +2,8 @@
<%= render :partial => 'project_news', locals: {project: @project} %>
<% elsif @course %>
<%= render :partial => 'course_news', locals: {course: @course} %>
<% elsif @contest %>
<%= render :partial => 'contest_news', locals: {course: @contest} %>
<% end %>

View File

@ -0,0 +1,5 @@
class AddContestIdToNews < ActiveRecord::Migration
def change
add_column :news, :contest_id, :integer
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 => 20161222063638) do
ActiveRecord::Schema.define(:version => 20161223083022) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -337,14 +337,16 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids"
create_table "changesets", :force => true do |t|
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.string "committer"
t.datetime "committed_on", :null => false
t.datetime "committed_on", :null => false
t.text "comments"
t.date "commit_date"
t.string "scmid"
t.integer "user_id"
t.integer "project_id"
t.integer "type", :default => 0
end
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on"
@ -495,12 +497,12 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "user_id"
t.integer "contest_id"
t.integer "contest_message_id"
t.string "contest_message_type"
t.boolean "viewed", :default => false
t.string "course_message_type"
t.boolean "viewed", :default => false
t.text "content"
t.integer "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "contest_messages", ["contest_id"], :name => "index_contest_messages_on_contest_id"
@ -605,20 +607,6 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "container_id", :default => 0
end
create_table "course_class_post", :id => false, :force => true do |t|
t.integer "班级id", :default => 0, :null => false
t.string "班级名"
t.integer "帖子id", :default => 0, :null => false
t.integer "主贴id"
t.string "帖子标题", :default => "", :null => false
t.text "帖子内容"
t.integer "帖子用户id"
t.integer "帖子回复数", :default => 0, :null => false
t.integer "最后回帖id"
t.datetime "发帖时间", :null => false
t.datetime "帖子更新时间", :null => false
end
create_table "course_contributor_scores", :force => true do |t|
t.integer "course_id"
t.integer "user_id"
@ -687,8 +675,8 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.string "code"
t.integer "time"
t.string "extra"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "location"
t.string "term"
t.string "string"
@ -698,27 +686,28 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.string "class_period"
t.integer "school_id"
t.text "description"
t.integer "status", :default => 1
t.integer "attachmenttype", :default => 2
t.integer "status", :default => 1
t.integer "attachmenttype", :default => 2
t.integer "lft"
t.integer "rgt"
t.integer "is_public", :limit => 1, :default => 1
t.integer "inherit_members", :limit => 1, :default => 1
t.integer "open_student", :default => 0
t.integer "outline", :default => 0
t.integer "publish_resource", :default => 0
t.integer "is_delete", :default => 0
t.integer "is_public", :limit => 1, :default => 1
t.integer "inherit_members", :limit => 1, :default => 1
t.integer "open_student", :default => 0
t.integer "outline", :default => 0
t.integer "publish_resource", :default => 0
t.integer "is_delete", :default => 0
t.integer "end_time"
t.string "end_term"
t.integer "is_excellent", :default => 0
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
t.integer "is_excellent", :default => 0
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
t.integer "syllabus_id"
t.string "invite_code"
t.string "qrcode"
t.integer "qrcode_expiretime", :default => 0
t.integer "invite_code_halt", :limit => 1, :default => 0
t.integer "qrcode_expiretime", :default => 0
t.integer "professional_level_id", :limit => 1
t.integer "invite_code_halt", :limit => 1, :default => 0
end
add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true
@ -793,6 +782,11 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "disciplines", :force => true do |t|
t.string "name"
t.integer "professional_level_id", :limit => 1
end
create_table "discuss_demos", :force => true do |t|
t.string "title"
t.text "body"
@ -918,13 +912,11 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "exercise_status"
t.integer "user_id"
t.integer "time"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "publish_time"
t.datetime "end_time"
t.integer "show_result"
t.integer "question_random", :default => 0
t.integer "choice_random", :default => 0
end
create_table "first_pages", :force => true do |t|
@ -1113,6 +1105,10 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.datetime "updated_at", :null => false
end
create_table "innodb_monitor", :id => false, :force => true do |t|
t.integer "a"
end
create_table "invite_lists", :force => true do |t|
t.integer "project_id"
t.integer "user_id"
@ -1376,6 +1372,7 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "course_id"
t.integer "sticky", :default => 0
t.integer "org_subfield_id"
t.integer "contest_id"
end
add_index "news", ["author_id"], :name => "index_news_on_author_id"
@ -1644,9 +1641,12 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
end
create_table "professional_levels", :force => true do |t|
t.string "level"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "level"
end
create_table "professions", :force => true do |t|
t.string "name"
t.integer "discipline_id", :limit => 1
end
create_table "project_infos", :force => true do |t|
@ -1709,7 +1709,6 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1
t.integer "user_id"
t.integer "dts_test", :default => 0
t.string "enterprise_name"
t.integer "organization_id"
t.integer "project_new_type"
@ -1717,6 +1716,11 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "forked_from_project_id"
t.integer "forked_count"
t.integer "publish_resource", :default => 0
t.integer "boards_count", :default => 0
t.integer "news_count", :default => 0
t.integer "acts_count", :default => 0
t.integer "journals_count", :default => 0
t.integer "boards_reply_count", :default => 0
t.integer "visits", :default => 0
t.integer "hot", :default => 0
t.string "invite_code"
@ -2114,8 +2118,8 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "eng_name"
t.integer "syllabus_type"
t.integer "credit"
@ -2124,8 +2128,9 @@ ActiveRecord::Schema.define(:version => 20161222063638) do
t.integer "practice_hours"
t.string "applicable_major"
t.string "pre_course"
t.integer "visits", :default => 0
t.integer "des_status", :default => 0
t.integer "visits", :default => 0
t.integer "des_status", :default => 0
t.integer "professional_level_id", :limit => 1
end
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"

View File

@ -132,6 +132,12 @@ Redmine::AccessControl.map do |map|
map.permission :comment_news, {:comments => :create}
end
map.contest_module :news do |map|
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
map.permission :view_contest_news, {:news => [:index, :show]}, :public => true, :read => true
map.permission :comment_news, {:comments => :create}
end
map.course_module :bids do |map|
map.permission :view_homework_attaches, {:bids => [:show, :show_project, :revision]}, :read => true,:belong_to_course => true
map.permission :paret_in_homework,{},:require => :member ,:belong_to_course => true