From 2f77adfe9cdb3f194bbd3475f2d466e77dd9a0e7 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 12 Aug 2015 16:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E8=A1=A8=E7=9A=84=E5=AE=8C=E6=88=90=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E4=B8=8E=E6=88=91=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=9A=84=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 89 +------------------- app/helpers/courses_helper.rb | 53 ++++++++++++ app/models/course.rb | 2 + app/views/courses/show.html.erb | 104 +++++++----------------- app/views/layouts/base_courses.html.erb | 2 +- public/stylesheets/courses.css | 2 +- 6 files changed, 89 insertions(+), 163 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d9980e286..aa66dd7a0 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 597d5749c..da7a34a98 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -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 = "作业 " + activity.course_act.name + url = student_work_index_path(:homework => activity.course_act.id) + when "News" + title = "通知公告 " + activity.course_act.title + url = course_news_index_path(activity.course) + when "Attachment" + title = "课件 " + activity.course_act.filename + url = course_files_path(activity.course) + when "Message" + title = "课程讨论区 " + 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 = "留言 " + activity.course_act.notes + url = course_feedback_path(activity.course) + when "Poll" + title = "问卷 " + 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 diff --git a/app/models/course.rb b/app/models/course.rb index a56ea5949..89990dd48 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -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, diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 654c25a42..7159c3c83 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -1,83 +1,37 @@
-<% if @controller_name=='ActivityNotifys' %> - <%= l(:label_activity)%> -

与我相关 - -

-
- - - -
-<% else %>

<%= l(:label_activity)%>

- <% if User.current.logged? %> - 与我相关 - - - <% end %> -<% end %>
-<% 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| -%> -
- - <%= image_tag(url_to_avatar(e.event_author), :width => "42", :height => "42") %> - -
- <%= 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) %> -   - <%= l(:label_new_activity) %>: - <% - 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%> - - <%end%> -
-

<%= e.event_description.html_safe %> -
-

- <%= l :label_activity_time %> : <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %> -

- <%= link_to_attachments_course(e) if e.class.to_s == "News" %> -
-
-
- <% end%> - <% end%> -<% elsif @controller_name=='ActivityNotifys' %> -

<%= l(:label_no_data) %>

-<% end%> -<% if @obj_pages.next_page.nil? && @controller_name!='ActivityNotifys' %> -
- - <%= image_tag(url_to_avatar(@user), :width => "42", :height => "42") %> - -
- <%= 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 %> - <%= l(:label_user_create_project) %>: - <%= link_to @course.name,course_path(@course),:class => "problem_tit c_dblue fl fb"%> -
-

-
- <%= l :label_create_time %> : <%= format_time(@course.created_at) %> -

-
-
-
+<%@course_activities.each do |activity|%> +
+ + <%= image_tag(url_to_avatar(activity.user), :width => "42", :height => "42") %> + +
+ <%= link_to_user_header(activity.user,false,:class => 'problem_name c_orange fl') %> +   + <%= activity.course_act_type == "Course" ? "创建了课程" : l(:label_new_activity) %>: + <%#= 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%> + + <%#end%> + <%= link_to course_activity_link activity%> +
+

+ <%= course_activity_desc activity%> +
+

+ <%= l :label_activity_time %> : <%= format_time(activity.created_at) %> +

+ <%= link_to_attachments_course(activity.course_act) if activity.course_act_type.to_s == "News" %> +
+
+
<% end%> + diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 7a32cb67d..3242d79e9 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -113,7 +113,7 @@