课程动态公共表的完成,去掉课程动态表的与我相关功能,动态的页面显示

This commit is contained in:
sw 2015-08-12 16:24:27 +08:00
parent 053587bd53
commit 2f77adfe9c
6 changed files with 89 additions and 163 deletions

View File

@ -663,92 +663,9 @@ class CoursesController < ApplicationController
end
def show
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
return
end
@users_by_role = @course.users_by_role
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
@key = User.current.rss_key
#新增内容
@days = Setting.activity_days_default.to_i
if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end
has = {
"show_course_files" => true,
"show_course_news" => true,
"show_course_messages" => true,
#"show_course_journals_for_messages" => true,
# "show_bids" => true,
# "show_homeworks" => true,
"show_polls" => true
}
@date_to ||= Date.today + 1
@date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
if @author.nil?
# 显示老师和助教的活动
# @authors = searchTeacherAndAssistant(@course)
@authors = course_all_member(@course)
events = []
key = "course_events_#{@course.id}".to_sym
if Rails.env.production? && Setting.course_cahce_enabled?
events = Rails.cache.read(key) || []
end
if events.empty?
@authors.each do |author|
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false,
:author => author.user)
@activity.scope_select {|t| has["show_#{t}"]}
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events += @activity.events(@days, @course.created_at)
else
events += @activity.events(@days, @course.created_at, :is_public => 1)
end
end
Rails.cache.write(key, events) if Rails.env.production? && Setting.course_cahce_enabled?
end
else
# @author = @course.teacher
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
:with_subprojects => false,
:author => @author)
@activity.scope_select {|t| has["show_#{t}"]}
# modify by nwb
# 添加私密性判断
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events(@days, @course.created_at)
else
events = @activity.events(@days, @course.created_at, :is_public => 1)
end
end
# 无新动态时,显示老动态
if events.count == 0
if User.current.member_of_course?(@course)|| User.current.admin?
events = @activity.events
else
events = @activity.events(:is_public => 1)
end
end
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
end
sorted_events = sort_activity_events_course(events)
events = paginateHelper sorted_events,10
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
# documents
course_activities = @course.course_activities.order("created_at desc")
@canShowRealName = User.current.member_of_course? @course
@course_activities = paginateHelper course_activities,10
respond_to do |format|
format.html{render :layout => 'base_courses'}
format.api

View File

@ -676,4 +676,57 @@ module CoursesHelper
end
result
end
#生成课程相关动态的链接
def course_activity_link activity
# activity = CourseActivity.first
title = ""
url = ""
case activity.course_act_type
when "Course"
title = activity.course_act.name
url = course_path activity.course
when "HomeworkCommon"
title = "作业&nbsp;" + activity.course_act.name
url = student_work_index_path(:homework => activity.course_act.id)
when "News"
title = "通知公告&nbsp;" + activity.course_act.title
url = course_news_index_path(activity.course)
when "Attachment"
title = "课件&nbsp;" + activity.course_act.filename
url = course_files_path(activity.course)
when "Message"
title = "课程讨论区&nbsp;" + activity.course_act.subject
url = course_boards_path(activity.course,:parent_id => activity.course_act.parent_id ? activity.course_act.parent_id : activity.course_act.id, :topic_id => activity.course_act.id)
when "JournalsForMessage"
title = "留言&nbsp;" + activity.course_act.notes
url = course_feedback_path(activity.course)
when "Poll"
title = "问卷&nbsp;" + activity.course_act.polls_name
url = poll_index_path(:polls_type => "Course", :polls_group_id => activity.course_id)
end
link_to title.gsub(/<(?!img)[^>]*>/,'').html_safe, url, :class => "problem_tit c_dblue fl fb"
end
#课程动态的描述
def course_activity_desc activity
desc = ""
case activity.course_act_type
when "Course"
desc = ""
when "HomeworkCommon"
desc = activity.course_act.description
when "News"
desc = activity.course_act.description
when "Attachment"
desc = ""
when "Message"
desc = activity.course_act.content
when "JournalsForMessage"
desc = ""
when "Poll"
desc = activity.course_act.polls_description
end
desc.html_safe
end
end

View File

@ -36,6 +36,8 @@ class Course < ActiveRecord::Base
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
has_many :course_activities
acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy
acts_as_attachable :view_permission => :view_course_files,

View File

@ -1,83 +1,37 @@
<div class="project_r_h">
<% if @controller_name=='ActivityNotifys' %>
<a class="fl about_me" style="width:80px;" href="<%=course_path(@course)%>"><%= l(:label_activity)%></a>
<h2 class="fl project_h2" style="width:100px;">与我相关
<span class="c_orange f12" style="display:none;">(<font id="new_notify_count"><%=get_new_notify_count(@course,'Course')%></font>)</span>
</h2>
<div class="fr mt10 mr5 c_grey02">
<a class="c_dblue">
<label class="mr5" style="cursor:pointer;" data-href="<%= course_activity_notifys_path(@course) %>/chang_read_flag" nhname='nh_act_link_all'>全部标为已读</label>
</a>
</div>
<% else %>
<h2 class="fl project_h2"><%= l(:label_activity)%></h2>
<% if User.current.logged? %>
<a class="fl about_me" href="<%=course_activity_notifys_path(@course)%>">与我相关
<span class="c_orange f12" style="display:none;">(<font id="new_notify_count"><%=get_new_notify_count(@course,'Course')%></font>)</span>
</a>
<% end %>
<% end %>
</div>
<% if @events_by_day != nil && @events_by_day.size >0 %>
<% @events_by_day.keys.sort.reverse.each do |day| %>
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
<div class="problem_main" nhname="container">
<a class="problem_pic fl">
<%= image_tag(url_to_avatar(e.event_author), :width => "42", :height => "42") %>
</a>
<div class="problem_txt fl mt5 upload_img">
<%= link_to_user_header(e.event_author,false,:class => 'problem_name c_orange fl') if e.respond_to?(:event_author) %>
<%= link_to_user_header("(#{e.event_author})", @canShowRealName,:class => 'problem_name c_orange fl') if @canShowRealName && e.respond_to?(:event_author) %>
<span class="fl"> &nbsp;</span>
<span class="fl"> <%= l(:label_new_activity) %></span>
<%
link = (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) :
(e.event_type.eql?("bid") ? homework_course_path(@course) :
(e.event_type.eql?("message") || e.event_type.eql?("reply") ?
course_boards_path(@course,:topic_id => e.id,:parent_id=>(e.parent_id ? e.parent_id : e.id)) : e.event_url))
%>
<%= link_to "#{eventToLanguageCourse(e.event_type, @course)} "<< format_activity_title(e.event_title), link,
:class => "problem_tit c_dblue fl fb",'data-type'=>e.event_type,
'data-notify-id'=>(e.respond_to?('get_notify_id') ? e.get_notify_id : ''),:nhname=>"nh_act_link",
'data-href'=>(course_activity_notifys_path(@course)+"/chang_read_flag?an_id="+(e.respond_to?('get_notify_id') ? e.get_notify_id : '').to_s)%>
<%if @controller_name=='ActivityNotifys' && e.get_notify_is_read!=1%>
<span nhname="nh_act_flag" class="ml10 fl"><img src="/images/new.png" width="35" height="15"/></span>
<%end%>
<br />
<p class="mt5 break_word"><%= e.event_description.html_safe %>
<br />
<div class="cl"></div>
<%= l :label_activity_time %> <%= format_activity_day(day) %>&nbsp;<%= format_time(e.event_datetime, false) %>
</p>
<%= link_to_attachments_course(e) if e.class.to_s == "News" %>
</div>
<div class="cl"></div>
</div><!--课程动态 end-->
<% end%>
<% end%>
<% elsif @controller_name=='ActivityNotifys' %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end%>
<% if @obj_pages.next_page.nil? && @controller_name!='ActivityNotifys' %>
<div class="problem_main">
<a class="problem_pic fl">
<%= image_tag(url_to_avatar(@user), :width => "42", :height => "42") %>
</a>
<div class="problem_txt fl mt5">
<%= link_to_user_header(@user,false,:class => 'problem_name c_orange fl') %>
<%= link_to_user_header("(#{@user})", @canShowRealName,:class => 'problem_name c_orange fl') if @canShowRealName %>
<span class="fl"> <%= l(:label_user_create_project) %></span>
<%= link_to @course.name,course_path(@course),:class => "problem_tit c_dblue fl fb"%>
<br />
<p class="mt5">
<br />
<%= l :label_create_time %> <%= format_time(@course.created_at) %>
</p>
</div>
<div class="cl"></div>
</div><!--课程动态 end-->
<%@course_activities.each do |activity|%>
<div class="problem_main" nhname="container">
<a class="problem_pic fl">
<%= image_tag(url_to_avatar(activity.user), :width => "42", :height => "42") %>
</a>
<div class="problem_txt fl mt5 upload_img">
<%= link_to_user_header(activity.user,false,:class => 'problem_name c_orange fl') %>
<span class="fl"> &nbsp;</span>
<span class="fl"> <%= activity.course_act_type == "Course" ? "创建了课程" : l(:label_new_activity) %></span>
<%#= link_to "#{eventToLanguageCourse(e.event_type, @course)} "<< format_activity_title(e.event_title), link,
:class => "problem_tit c_dblue fl fb",'data-type'=>e.event_type,
'data-notify-id'=>(e.respond_to?('get_notify_id') ? e.get_notify_id : ''),:nhname=>"nh_act_link",
'data-href'=>(course_activity_notifys_path(@course)+"/chang_read_flag?an_id="+(e.respond_to?('get_notify_id') ? e.get_notify_id : '').to_s)%>
<%#if @controller_name=='ActivityNotifys' && e.get_notify_is_read!=1%>
<!--span nhname="nh_act_flag" class="ml10 fl"><img src="/images/new.png" width="35" height="15"/></span-->
<%#end%>
<%= link_to course_activity_link activity%>
<div class="cl"></div>
<p class="mt5 break_word">
<%= course_activity_desc activity%>
<br />
<div class="cl"></div>
<%= l :label_activity_time %> <%= format_time(activity.created_at) %>
</p>
<%= link_to_attachments_course(activity.course_act) if activity.course_act_type.to_s == "News" %>
</div>
<div class="cl"></div>
</div><!--课程动态 end-->
<% end%>
<ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>

View File

@ -113,7 +113,7 @@
<div class="subNav">
<%= link_to l(:label_activity), course_path(@course), :class => "f14 c_blue02" %>
<!--暂时不显示课程动态数,优化后在显示-->
<%= link_to "(#{course_activity_count @course})", course_path(@course), :class => "subnav_num c_orange"%>
<%= link_to "(#{@course.course_activities.count})", course_path(@course), :class => "subnav_num c_orange"%>
</div>
<div class="subNav">
<%= link_to l(:label_homework), homework_common_index_path(:course => @course.id), :class => "f14 c_blue02"%>

View File

@ -55,7 +55,7 @@ a:hover.problem_pic{border:1px solid #64bdd9;}
.problem_txt{ width:610px; margin-left:10px; color:#777777;word-break: break-all;word-wrap: break-word;}
a.problem_name{ color:#ff5722;max-width:60px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
a:hover.problem_name{ color:#d33503;}
a.problem_tit{ color:#0781b4; max-width:410px; display:block; overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
a.problem_tit{ color:#0781b4; max-width:410px; display:block; overflow:hidden; white-space: nowrap; text-overflow:ellipsis;vertical-align: top;}
a.pro_mes_w{ height:20px; float:right;display:block; color:#999999;}
a:hover.problem_tit{ color:#09658c; }
.problem_main{ border-bottom:1px dashed #d4d4d4; padding-bottom:10px; margin-bottom:10px;}