From f58b5304843e5ce91e572e2faf7d43bab5dfda95 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 18 Jun 2015 09:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E8=AF=BE=E7=A8=8B=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E6=85=A2=E5=8A=A0=E4=B8=8A=E7=BC=93=E5=AD=98=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E5=8A=A0=E5=85=A5=E4=BA=86=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 33 +++++++++++++-------- app/helpers/application_helper.rb | 7 +++++ app/models/activity.rb | 2 ++ app/models/forge_activity.rb | 1 + app/views/courses/show.html.erb | 2 +- app/views/files/_course_list.html.erb | 6 ++-- app/views/files/_project_file_list.html.erb | 6 ++-- config/settings.yml | 3 +- lib/trustie/cache/clear_course_event.rb | 17 +++++++++++ 9 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 lib/trustie/cache/clear_course_event.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 61354add7..524bde9d7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -695,21 +695,28 @@ class CoursesController < ApplicationController # 显示老师和助教的活动 # @authors = searchTeacherAndAssistant(@course) @authors = course_all_member(@course) + Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require file } events = [] - @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) + 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ae70fd7c..5af4e2038 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2330,4 +2330,11 @@ module ApplicationHelper def cur_user_works_for_homework homework homework.student_works.where("user_id = ?",User.current).first end + + def file_preview_tag(file, html_options={}) + if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)} + link_to '预览', download_named_attachment_path(file.id, file.filename, preview: true),html_options + end + end + end diff --git a/app/models/activity.rb b/app/models/activity.rb index e871ae735..5ec778641 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -5,4 +5,6 @@ class Activity < ActiveRecord::Base validates :act_id, presence: true validates :act_type, presence: true validates :user_id, presence: true + + include Trustie::Cache::ClearCourseEvent end diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index e94a29867..6b75552c0 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -19,4 +19,5 @@ class ForgeActivity < ActiveRecord::Base validates :project_id,presence: true validates :forge_act_id,presence: true validates :forge_act_type, presence: true + end diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 09d1aa27d..654c25a42 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -126,4 +126,4 @@ }); nh_new_notify_count_show(); }); - \ No newline at end of file + diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 7f3e426fc..8bb6f8970 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -25,7 +25,9 @@ <% if file.is_public? || User.current.member_of_course?(course) %>