班级的通知模块增加“历史通知”的入口和显示

This commit is contained in:
cxt 2017-08-31 09:46:55 +08:00
parent 374827d3a4
commit a8c166ae52
5 changed files with 146 additions and 3 deletions

View File

@ -22,8 +22,8 @@ class NewsController < ApplicationController
before_filter :authorize1, :only => [:show]
default_search_scope :news
model_object News
before_filter :find_model_object, :except => [:new, :create, :index]
before_filter :find_project_from_association, :except => [:new, :create, :index]
before_filter :find_model_object, :except => [:new, :create, :index, :news_history]
before_filter :find_project_from_association, :except => [:new, :create, :index, :news_history]
before_filter :find_project_by_project_id, :only => [:new, :create]
before_filter :authorize, :except => [:index]
before_filter :find_optional_project, :only => :index
@ -233,6 +233,88 @@ class NewsController < ApplicationController
end
end
def news_history
@order, @b_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
@course = Course.find(params[:course])
#确定 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 ) ")
syllabus = @course.syllabus
scope = News.where(:course_id => syllabus.courses.map(&:id))
#scope = @course ? @course.news.course_visible : News.course_visible
news_arr = scope.map{|news| news.id}
@page = params[:page] ? params[:page].to_i + 1 : 0
news_page = 0 #@page *10
@news_count = scope.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()
#all(:include => [:author, :course],
#:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page)
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,:course).all()
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
end
scope_order.each do |topic|
topic[:updated_at] = topic.course_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_courses'
}
format.js
format.api
format.atom { render_feed(@newss, :title => (@course ? @course.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
end
def show
# 更新news对应的forge_messages的消息viewed字段
ids = @news.comments.map { |comment| comment.id }.join(",") unless @news.comments.nil?

View File

@ -0,0 +1,55 @@
<div class="listbox mt10" >
<p class="list-h2">历史通知列表
<%= link_to '返回', course_news_index_path(@course), :class => 'link-blue fr f14', :remote => true %>
</p>
<div class="category">
<span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'news', :action => 'news_history', :course => @course.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'news', :action => 'news_history', :course => @course.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<%= link_to "人气", {:controller => 'news', :action => 'news_history', :course => @course.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'news', :action => 'news_history', :course => @course.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<div class="cl"></div>
</div>
<div class="bloglistbox">
<% if @newss.any? %>
<% @newss.each do |activity| %>
<div class="list-file">
<div><span class="item_list fl"></span>
<%= link_to activity.title.to_s, User.current.logged? ? news_path(activity) : signin_url_without_domain, :class => "list-title-normal fl" %>
<% if activity.sticky == 1 %>
<span class="fl ml10 red-cir-btn">顶</span>
<% end%>
<% u = User.where("id=?",activity.author_id).first%>
<div class="cl"></div>
</div>
<!--<div class="massages-content ml15">-->
<!--<p><%#=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>activity.description, :maxheight=>54, :maxwordsnum=>100, :maxwidth=>563} %></p>-->
<!--</div>-->
<div class="ml15 mt10">
<span class="grayTxt mr15">
发布者:<%= link_to activity.author.show_name, user_path(activity.author), :class => "link-blue" %>
</span>
<span class="grayTxt">更新:<%= format_time(@course ? activity.course_acts.first.try(:updated_at) : activity.contest_acts.first.try(:updated_at)) %></span>
<% count=0 %>
<% count=activity.comments.count %>
<p class="list-info fr grayTxt"><span><%= count>0 ? "#{count}" : "0" %></span><span>回复</span><span>|</span><span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %></span><span>赞</span></p>
</div>
<div class="cl"></div>
</div>
<% end %>
<div>
<ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<div class="cl"></div>
</div>
<% else %>
<div class="icons_tishi"><img src="/images/sy/icons_smile.png" width="110" height="110" alt="" ></div>
<p class="sy_tab_con_p">没有数据可以显示!</p>
<% end %>
</div>
</div>

View File

@ -0,0 +1 @@
$("#course-newslist").html("<%= j(render :partial => 'sy_news_history') %>");

View File

@ -1,7 +1,11 @@
<div class = "cl"> </div>
<div id="course-newslist">
<div class="listbox mt10" >
<p class="list-h2">通知列表</p>
<p class="list-h2">通知列表
<% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %>
<%= link_to '历史通知', news_news_history_path(:course => @course.id), :class => 'link-blue fr f14', :remote => true %>
<% end %>
</p>
<div class="category">
<span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'news', :action => 'index', :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>

View File

@ -583,6 +583,7 @@ RedmineApp::Application.routes.draw do
post '/courses/:id/course_activity', :to => 'courses#show', :as => 'course_activity'
get '/boards/:id/boards_topic', :to =>'boards#show', :as => 'boards_topic'
match 'courses/:course_id/news/index', :to => 'news#index', :via => [:get, :post], :as => 'new_course_news'
get 'news/news_history', :to => 'news#news_history'
match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post]
match 'contests/:contest_id/news/index', :to => 'news#index', :via => [:get, :post], :as => 'new_contest_news'
match 'contests/:contest_id/news/new', :to => 'news#new', :via => [:get, :post]