diff --git a/.gitignore b/.gitignore index ca12f81a9..af337a4e7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,11 @@ /config/configuration.yml /files/* /log/* +/public/tmp/* /tmp/* +/public/cache/* .gitignore +/config/newrelic.yml /public/images/avatars/* /Gemfile /Gemfile.lock diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree new file mode 100644 index 000000000..942a97c51 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 new file mode 100644 index 000000000..971c3ef7e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 @@ -0,0 +1,3 @@ +#safe table +#Mon Jan 05 10:27:54 CST 2015 +connections=connections.15 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 new file mode 100644 index 000000000..01bf076fe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 @@ -0,0 +1,4 @@ +#safe table +#Mon Jan 05 10:27:54 CST 2015 +defaultConnection=defaultConnection.15 +sites=sites.15 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 new file mode 100644 index 000000000..26cede301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 @@ -0,0 +1,3 @@ +#safe table +#Mon Jan 05 10:27:28 CST 2015 +webservers=webservers.12 diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history new file mode 100644 index 000000000..664784aa9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index new file mode 100644 index 000000000..d5428a792 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index @@ -0,0 +1,2 @@ +1420424676858 Delete resource 'trustie2' +1420424775104 Delete resource 'trustie2' diff --git a/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml new file mode 100644 index 000000000..27eb4040f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml @@ -0,0 +1,7 @@ + +
+
+ + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index eba54f80b..09856e2e7 100644 --- a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -11,4 +11,16 @@ +
+ + +
+
+ + +
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml index f7e4d66f0..c8c1e4f77 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -1,7 +1,9 @@
+
+
- + diff --git a/Gemfile b/Gemfile index af85ff339..afd6a667a 100644 --- a/Gemfile +++ b/Gemfile @@ -3,13 +3,13 @@ source 'http://rubygems.org' unless RUBY_PLATFORM =~ /w32/ # unix-like only - gem 'iconv' + gem 'iconv' gem 'rubyzip' gem 'zip-zip' end -gem 'grape', '~> 0.9.0' -gem 'grape-entity' +gem 'grape', '~> 0.9.0' +gem 'grape-entity' gem 'seems_rateable', path: 'lib/seems_rateable' gem "rails", "3.2.13" gem "jquery-rails", "~> 2.0.2" @@ -23,9 +23,9 @@ gem 'ruby-ole' #gem 'email_verifier' group :development do - gem 'grape-swagger' - gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' - #gem 'puma' + gem 'grape-swagger' + gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git' + #gem 'puma' gem 'better_errors', path: 'lib/better_errors' gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' end diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index e2c4aa357..bee78a20e 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -39,7 +39,7 @@ module Mobile mount Apis::Homeworks #add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'}) - add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? + #add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? end end diff --git a/app/assets/javascripts/system_log.js.coffee b/app/assets/javascripts/system_log.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/system_log.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/system_log.css.scss b/app/assets/stylesheets/system_log.css.scss new file mode 100644 index 000000000..aa1f18587 --- /dev/null +++ b/app/assets/stylesheets/system_log.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the system_log controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e81b57ad7..7653be94d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -828,6 +828,7 @@ class CoursesController < ApplicationController end def show + # try to redirect to the requested menu item if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) return @@ -866,6 +867,7 @@ class CoursesController < ApplicationController @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 @@ -890,14 +892,13 @@ class CoursesController < ApplicationController @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} # documents @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - # - @teachers= searchTeacherAndAssistant(@course) - @canShowRealName = isCourseTeacher(User.current.id,@course) + # 这写变量发现没有用而且拖慢速度 + #@teachers= searchTeacherAndAssistant(@course) + #@canShowRealName = isCourseTeacher(User.current.id,@course) 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 - respond_to do |format| format.html{render :layout => 'base_courses'} format.api diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 394c52f13..1b2794034 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -83,6 +83,12 @@ class PollController < ApplicationController def destroy if @poll && @poll.destroy + if @is_teacher + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}") + else + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2") + end + @polls = paginateHelper polls,20 #分页 respond_to do |format| format.js end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a2e793a10..e3a804ef8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -31,16 +31,14 @@ class ProjectsController < ApplicationController menu_item :feedback, :only => :feedback menu_item l(:label_course_file), :only => :index menu_item l(:label_course_news), :only => :index + -# edit - before_filter :authorize1, :only => [:show] -# before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project] # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] #此条勿删 课程相关权限 ,:new_homework,:homework,:feedback,,:member - before_filter :authorize, :only => [:settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] + before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :file, :statistics, :watcherlist @@ -118,8 +116,8 @@ class ProjectsController < ApplicationController joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id"). where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project) - @poll_questions_count = @projects_all.count - @poll_questions_pages = Paginator.new @project_count, per_page_option, params['page'] + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] #gcm activity count @@ -558,11 +556,6 @@ class ProjectsController < ApplicationController # Show @project def show - if(@project && !@project.is_public && !User.current.member_of?(@project)) - render_403 - return - end - @project_type = params[:project_type] # try to redirect to the requested menu item @@ -594,7 +587,7 @@ class ProjectsController < ApplicationController end has = { - "show_issues" => true, + "show_issues" => true , "show_files" => true, "show_documents" => true, "show_messages" => true, @@ -604,8 +597,8 @@ class ProjectsController < ApplicationController "show_wiki_edits"=>true, "show_journals_for_messages" => true } - - + @date_to ||= Date.today + 1 + @date_from = @date_to - @days#-1.years #modified by lizanle 去掉這個1年的時間跨度 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) # 决定显示所用用户或单个用户活动 @@ -619,9 +612,9 @@ class ProjectsController < ApplicationController # modify by nwb # 添加私密性判断 if User.current.member_of?(@project)|| User.current.admin? - events = @activity.events(@days) + events = @activity.events(@date_from, @date_to) else - events = @activity.events(@days,nil, :is_public => 1) + events = @activity.events(@date_from, @date_to, :is_public => 1) end @offset, @limit = api_offset_and_limit({:limit => 10}) diff --git a/app/controllers/system_log_controller.rb b/app/controllers/system_log_controller.rb new file mode 100644 index 000000000..274cb18a9 --- /dev/null +++ b/app/controllers/system_log_controller.rb @@ -0,0 +1,59 @@ +# Time 2015-01-26 17:12:23 +# Author lizanle +# Description 显示和清理系统日志 +class SystemLogController < ApplicationController + + before_filter :require_admin + # 默认每页显示20条记录 + PER_PAGE = 20 + layout "base" + include SystemLogHelper + + # Time 2015-01-26 17:12:46 + # Author lizanle + # Description 查看所有日志 + def index + @logs = SystemLog.logo_data(params[:page]||1, params[:per]||PER_PAGE, params[:search], params[:day]) + end + + # Time 2015-01-26 14:42:38 + # Author lizanle + # Description 清除日志 + def clear + SystemLog.clear params[:day] + redirect_to :action => :index + end + + # Time 2015-01-26 17:24:25 + # Author lizanle + # Description 访问分析 + def access_analysis + #解析日志,然后逆序 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + @access_module = Hash.new + #日誌可能為空 + if @log_result && !@log_result.empty? + #将数组中的模块访问统计出来放到hash中 每条记录的第四个值是Controller#action的形式 + @log_result.collect! { |r| @access_module[r[3]].nil? ? + @access_module[r[3]] = 1 : @access_module[r[3]] +=1 } + # 去掉key可能为空记录 排序,然后取逆序 + @access_module = @access_module.delete_if { |k, v| k.nil? }.sort_by { |key, val| val }.reverse + else + @access_module + end + end + + # Time 2015-01-26 17:24:36 + # Author lizanle + # Description 耗时分析 + def time_analysis + #解析日志 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + if @log_result && !@log_result.empty? + #分页 + @log_result = Kaminari.paginate_array(@log_result).page(params[:page]||1).per(params[:per]||PER_PAGE) + else + @log_result = [] + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1face5c38..5579fe79b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1844,7 +1844,7 @@ module ApplicationHelper users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} # contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} - forum_link = link_to l(:label_project_module_forums), {:controller => "forums", :action => "index"} + forum_link = link_to l(:label_forum_all), {:controller => "forums", :action => "index"} stores_link = link_to l(:label_stores_index), {:controller => 'stores', :action=> 'index'} school_all_school_link = link_to l(:label_school_all), {:controller => 'school', :action => 'index'} @@ -1963,6 +1963,15 @@ module ApplicationHelper end def get_technical_title user - #user.user_extensions.technical_title + if user.user_extensions.technical_title == "Professor" || user.user_extensions.technical_title == "教授" + technical_title = l(:label_technicl_title_professor) + elsif user.user_extensions.technical_title == "Associate professor" || user.user_extensions.technical_title == "副教授" + technical_title = l(:label_technicl_title_associate_professor) + elsif user.user_extensions.technical_title == "Lecturer" || user.user_extensions.technical_title == "讲师" + technical_title = l(:label_technicl_title_lecturer) + elsif user.user_extensions.technical_title == "Teaching assistant" || user.user_extensions.technical_title == "助教" + technical_title = l(:label_technicl_title_teaching_assistant) + end + technical_title end end diff --git a/app/helpers/expire_helper.rb b/app/helpers/expire_helper.rb new file mode 100644 index 000000000..0a9cab69c --- /dev/null +++ b/app/helpers/expire_helper.rb @@ -0,0 +1,16 @@ +module ExpireHelper + #index.html 中 “projects”塊 緩存過期 + def expire_project_cache + ActionController::Base.new.expire_fragment('projects') + end + + #index.html 中 “activities”塊 緩存過期 + def expire_activitie_cache + ActionController::Base.new.expire_fragment('activities') + end + + #welcome/index.html 中 “forums”塊 緩存過期 + def expire_forum_cache + ActionController::Base.new.expire_fragment('forums') + end +end diff --git a/app/helpers/system_log_helper.rb b/app/helpers/system_log_helper.rb new file mode 100644 index 000000000..918d6a608 --- /dev/null +++ b/app/helpers/system_log_helper.rb @@ -0,0 +1,180 @@ +# Time 2015-01-26 17:30:16 +# Author lizanle +# Description 日志帮助类 +module SystemLogHelper + class SystemLog + class << self + # Time 2015-01-26 17:29:17 + # Author lizanle + # Description 分页(支持多关键字查询) + def logo_data(page, per, search, day) + logs = find_all_logs day + if logs.empty? #如果返回的是空數組,就說明日誌文件不存在 + return logs + end + # 根据search参数来决定是否需要查询 + keywords = search + if keywords && !keywords.strip.blank? + # 把keywords转化成正则表达式数组 + keywords = keywords.strip.split(/\s+/).collect! { |w| Regexp.new(w, 'i') } + # 一条记录应该匹配每个关键字 log =~ r 是对log记录进行判断是否符合r的正则表达式 + logs = logs.find_all do |log| + keywords.all? { |r| log =~ r } + end + #用Kaminari分页 + logs = Kaminari.paginate_array(logs).page(page).per(per).collect! { |log| parse(log) } + #将分页后的记录的搜索结果添加样式,样式中的\0是给给r占位置的。 + logs.collect! do |log| + keywords.each { |r| log.gsub!(r, '\0') } + log + end + else + logs = Kaminari.paginate_array(logs).page(page).per(per).collect! { |log| parse(log) } + end + logs + end + + # Time 2015-01-26 17:28:57 + # Author lizanle + # Description 清除日誌 + def clear day + if File::exists?(logfile_path day) + File.open(logfile_path(day), 'w') do |f| + f.print '' + end + else + end + end + + # Time 2015-01-26 17:28:49 + # Author lizanle + # Description 讀取日誌 + private + def find_all_logs day + if File::exists?(logfile_path day) + File.open(logfile_path day) do |f| + #打开文件,并按照正则表达式切分,逆序,最新一个记录可以扔掉(因为最新的记录永远都是访问System_log) + f.read.split("Processing").reverse[1..-1] + end + else + [] + end + end + + # Time 2015-01-26 17:28:34 + # Author lizanle + # Description 日志文件的路径,一般在Rails.root/log下,根据环境配置 + # 依次记录到product.log development.log test.log中 + def logfile_path day + #将日期处理成2015-01-01的形式 + unless day.nil? + dayArr = day.split('-') + if dayArr[1].length == 1 + dayArr[1] = "0" + dayArr[1] + end + if dayArr[2].length == 1 + dayArr[2] = "0" + dayArr[2] + end + day = dayArr.join('-') + end + #如果不是當天,則需要加後綴 + if !day.nil? && !day.strip.blank? && day != Time.now.strftime("%Y-%m-%d") + File.join(Rails.root, "log", "#{Rails.env}.log.#{day.gsub('-', '')}") + else + File.join(Rails.root, "log", "#{Rails.env}.log") + end + end + + # Time 2015-01-26 17:28:22 + # Author lizanle + # Description 替換換行符 + def parse(log) + ERB::Util.html_escape(log.gsub(/\e\[[\d;m]+/, '')).gsub("\n", "
") + end + + # Time 2015-01-26 17:28:07 + # Author lizanle + # Description 定义响应正则表达式 2015-01-20 11:31:13 INFO -- Completed 200 OK in 125ms (Views: 81.0ms | ActiveRecord: 2.0ms) + def response_regex + 'Completed \d+ \w+ in (\d+)ms \(Views: (\d+\.\d+)?ms \| ActiveRecord: (\d+\.\d+)?ms\)' + end + + # Time 2015-01-26 17:27:51 + # Author lizanle + # Description 将一条记录中的地址主机等都分析出来 + def get_status(paragraph) + request_regex = 'Started GET \"(\/.*)\" for ([\d]+\.[\d]+\.[\d]+\.[\d]+) at [\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*)' + controller_regex = 'Processing by ([\w]+#[\w]+)' + page_time_regex = 'Views: \d+(\.\d+)?ms' + activeRecord_time_regex = 'ActiveRecord: \d+(\.\d+)?ms' + + #解析请求中的正则,主机,时间 + if paragraph.match(request_regex) != nil + request_url = paragraph.match(request_regex)[1] #正则表达式中的括号能够截取成数组 + request_host = paragraph.match(request_regex)[2] + request_at = paragraph.match(request_regex)[3] + end + + #解析控制器 + if paragraph.match(controller_regex) != nil + controller_name = paragraph.match(controller_regex)[1] + end + + #解析响应时间以及计算百分比 + if paragraph.match(response_regex) != nil + #print(paragraph.match(response_regex)) + total_time = paragraph.match(response_regex)[1] + page_time = paragraph.match(response_regex)[2] + activeRecord_time = paragraph.match(response_regex)[3] + page_time_percent = page_time.to_f/(total_time.to_f) + activeRecord_time_percent = activeRecord_time.to_f/(total_time.to_f) + else + end + #将解析结果当做一条记录数组返回 + request_status = [request_url, request_host, request_at, + controller_name, total_time, page_time, page_time_percent, activeRecord_time, activeRecord_time_percent] + request_status + end + + # Time 2015-01-26 16:41:51 + # Author lizanle + # Description 分析日志 + public + def analysis day + csv = Array.new + #如果文件不存在,则直接返回空数组 + if File::exists?(logfile_path day) + File.open(logfile_path(day), "r:utf-8") do |file| + paragraph = "" + begin_flag = false + # 对每一行进行判断 + file.each do |line| + # 以"Started GET "开头为一个paragraph + #print(line.match('[\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*) INFO -- Started GET ') == nil) + if (line.match('[\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*) \w+ -- Started GET ') != nil) + if !begin_flag + begin_flag = true + paragraph.concat(line) + else + # 另一个paragraph的开头 + if (paragraph.match(response_regex) != nil) + csv << get_status(paragraph) + end + begin_flag = true + paragraph = line + end + else + if begin_flag + paragraph.concat(line) + else + end + end + end + end + end + csv + end + end + end +end + diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 27caa8306..d101fd36c 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -314,38 +314,38 @@ module WelcomeHelper str = ' '.html_safe case event.event_type when 'news' - str << content_tag("span", "发表了") << + str << content_tag("span", l(:field_user_active_published)) << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(strip_tags(event.event_description).gsub(/ /,''), event.event_url, {:title => event.event_description}) when 'issue', 'message' , 'bid' , 'wiki-page' , 'document' - str << content_tag("span", "发表了") << + str << content_tag("span", l(:field_user_active_published)) << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(event.event_title, event.event_url, {:title => event.event_title}) when 'reply' ,'Reply', 'Memo' - str << content_tag("span", "发表了") << - content_tag("span", find_all_event_type(event)) << + str << content_tag("span", l(:field_user_active_published)) << + content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(strip_tags(event.event_description).gsub(/ /,''), event.event_url, {:title => event.event_description}) when 'attachment' - str << content_tag('span', '上传了') << + str << content_tag('span', l(:field_user_active_uploaded)) << content_tag('span', find_all_event_type(event)) << ': '.html_safe << link_to(event.event_title, event.event_url, {:title => event.event_title}) << link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container.project), :class => "attachments_list_color") else - str << content_tag("span", "更新了") << + str << content_tag("span", l(:field_user_active_updated)) << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(event.event_title, event.event_url, {:title => event.event_title}) end str rescue Exception => e - str << content_tag("span", '未知内容') + str << content_tag("span", l(:field_user_active_unknow)) end def show_event_reply event - str = "回复(" + str = l(:field_active_reply) case event.event_type when 'news' str << link_to( event.comments.count, news_path(event)) << ")" @@ -463,25 +463,25 @@ module WelcomeHelper def find_all_event_type event case event.event_type when 'news' - '新闻' + l(:field_user_active_news) when 'issue' - '缺陷' + l(:field_user_active_issue) when 'attachment' - '附件' + l(:field_user_active_attachment) when 'message' - '主题' + l(:field_user_active_message) when 'Reply','reply' - '回复' + l(:field_user_active_reply) when 'bid' - '作业' + l(:field_user_active_bid) when 'Memo' - '主题' + l(:field_user_active_memo) when 'document' - '文件' + l(:field_user_active_document) when 'changeset' - '版本库' + l(:field_user_active_changeset) when 'issue-note' - '问题说明' + l(:field_user_active_issue_note) else event.event_type end diff --git a/app/models/bid.rb b/app/models/bid.rb index 88014477b..f423266b8 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -17,6 +17,7 @@ class Bid < ActiveRecord::Base HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes + include ExpireHelper belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :course @@ -32,7 +33,11 @@ class Bid < ActiveRecord::Base has_many :join_in_contests, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" - + + + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache acts_as_attachable @@ -149,4 +154,6 @@ class Bid < ActiveRecord::Base end end end + + end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e05a7d2da..101647824 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Changeset < ActiveRecord::Base + include ExpireHelper belongs_to :repository belongs_to :user include UserScoreHelper @@ -64,8 +65,9 @@ class Changeset < ActiveRecord::Base includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) } - after_create :scan_for_issues,:refresh_changests#:be_user_score # user_score - after_update :be_user_score + after_create :scan_for_issues,:refresh_changests,:expire_activitie_cache#:be_user_score # user_score + after_update :be_user_score,:expire_activitie_cache + before_destroy :expire_activitie_cache after_destroy :down_user_score before_create :before_create_cs diff --git a/app/models/contest_notification.rb b/app/models/contest_notification.rb index 1613f1378..0ccd0d5a7 100644 --- a/app/models/contest_notification.rb +++ b/app/models/contest_notification.rb @@ -1,4 +1,10 @@ class ContestNotification < ActiveRecord::Base + include ExpireHelper attr_accessible :content, :title validates :title, length: {maximum: 30} + after_create :expire_forum_cache + after_update :expire_forum_cache + before_destroy :expire_forum_cache + + end diff --git a/app/models/document.rb b/app/models/document.rb index 7c2fa5a6d..48a0151eb 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -17,18 +17,22 @@ class Document < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper belongs_to :project belongs_to :user belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" include UserScoreHelper after_save :be_user_score # user_score after_destroy :down_user_score - + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache acts_as_attachable :delete_permission => :delete_documents acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"}, - :author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) }, + #:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) }, + :author => Proc.new {|o| User.find(o.user_id)}, :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}} acts_as_activity_provider :find_options => {:include => :project}, :is_public => 'documents.is_public' @@ -76,4 +80,6 @@ class Document < ActiveRecord::Base update_document(self.user,1) update_document(self.user,2,self.project) end + + end diff --git a/app/models/forum.rb b/app/models/forum.rb index eb8bb19d2..e47d18b02 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,8 +1,13 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" - belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' + belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' + + after_create :expire_forum_cache + after_update :expire_forum_cache + before_destroy :expire_forum_cache safe_attributes 'name', 'description', 'topic_count', @@ -45,5 +50,7 @@ class Forum < ActiveRecord::Base " memo_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NOT NULL)," + " last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})", ["id = ?", forum_id]) - end + end + + end diff --git a/app/models/issue.rb b/app/models/issue.rb index 4dc685b3b..a7b1a5943 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -19,7 +19,7 @@ class Issue < ActiveRecord::Base include Redmine::SafeAttributes include Redmine::Utils::DateCalculation include UserScoreHelper - + include ExpireHelper belongs_to :project belongs_to :tracker belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' @@ -80,6 +80,9 @@ class Issue < ActiveRecord::Base after_create :act_as_activity,:be_user_score_new_issue after_update :be_user_score after_destroy :down_user_score + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache # after_create :be_user_score # end @@ -1553,4 +1556,5 @@ class Issue < ActiveRecord::Base end + end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4819cd253..c71fbaf47 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -4,6 +4,7 @@ class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ExpireHelper safe_attributes "jour_type", # 留言所属类型 "jour_id", # 留言所属类型的id "notes", # 留言内容 @@ -54,7 +55,9 @@ class JournalsForMessage < ActiveRecord::Base has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy validates :notes, presence: true - after_create :act_as_activity #huang + after_create :act_as_activity ,:expire_activitie_cache#huang + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -162,4 +165,6 @@ class JournalsForMessage < ActiveRecord::Base end end end + + end diff --git a/app/models/memo.rb b/app/models/memo.rb index f9482911a..165f8e144 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,9 +1,13 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ExpireHelper belongs_to :forum - belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + after_create :expire_cache + after_update :expire_cache + before_destroy :expire_cache validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 #validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } @@ -170,5 +174,8 @@ class Memo < ActiveRecord::Base update_memo_number(User.current,1) update_replay_for_memo(User.current,1) end - + def expire_cache + expire_forum_cache + expire_activitie_cache + end end diff --git a/app/models/message.rb b/app/models/message.rb index 8af3265cc..9ce4d583a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,7 +18,7 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper - + include ExpireHelper belongs_to :board belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy @@ -59,8 +59,9 @@ class Message < ActiveRecord::Base validates_length_of :subject, :maximum => 255 validate :cannot_reply_to_locked_topic, :on => :create - after_create :add_author_as_watcher, :reset_counters! - after_update :update_messages_board + after_create :add_author_as_watcher, :reset_counters!,:expire_activitie_cache + after_update :update_messages_board,:expire_activitie_cache + before_destroy :expire_activitie_cache after_destroy :reset_counters!,:down_user_score # fq @@ -195,4 +196,6 @@ class Message < ActiveRecord::Base end end end + + end diff --git a/app/models/news.rb b/app/models/news.rb index 4d153e81f..9c37719f3 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -17,6 +17,7 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper belongs_to :project #added by nwb belongs_to :course @@ -47,6 +48,9 @@ class News < ActiveRecord::Base # fq after_create :act_as_activity # end + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -91,4 +95,6 @@ class News < ActiveRecord::Base def act_as_activity self.acts << Activity.new(:user_id => self.author_id) end + + end diff --git a/app/models/project.rb b/app/models/project.rb index d5f3e381e..085851c29 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,6 +17,7 @@ class Project < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper ProjectType_project = 0 ProjectType_course = 1 @@ -126,10 +127,12 @@ class Project < ActiveRecord::Base #此代码功能:为原redmine中项目的树形结构按名称首字母排序,本系统项目非树形结构,且项目排序方式无按首字母排序,另该代码执行会使空数据库时创建项目时出异常故注释掉 #after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} + #ActiveModel::Dirty 这里有一个changed方法。对任何对象都可以用 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_create :create_board_sync - before_destroy :delete_all_members + after_create :create_board_sync,:expire_project_cache + after_update :expire_project_cache + before_destroy :delete_all_members,:expire_project_cache def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -1150,7 +1153,7 @@ class Project < ActiveRecord::Base logger.error "[Project Model] ===> Auto create board when Project saved, because #{@board.full_messages}" end end - - + + end diff --git a/app/views/layouts/_base_feedback.html.erb b/app/views/layouts/_base_feedback.html.erb index bf4b12daf..2039735bc 100644 --- a/app/views/layouts/_base_feedback.html.erb +++ b/app/views/layouts/_base_feedback.html.erb @@ -63,7 +63,7 @@ a:hover.opnionButton{ text-decoration:underline;} (function($){ $.fn.fix = function(options){ var defaults = { - float : 'left', + float : 'right', minStatue : false, skin : 'blue', durationTime : 1000 @@ -81,7 +81,7 @@ a:hover.opnionButton{ text-decoration:underline;} var defaultTop = thisBox.offset().top; //????????top thisBox.css(options.float, 0); - if(options.minStatue){ + if(options.minStatue == "true"){ $(".show_btn").css("float", options.float); sideContent.css('width', 0); show_btn.css('width', 25); @@ -106,15 +106,18 @@ a:hover.opnionButton{ text-decoration:underline;} closeBtn.bind("click",function(){ sideContent.animate({width: '0px'},"fast"); show_btn.stop(true, true).delay(300).animate({ width: '25px'},"fast"); + cookiesave('minStatue','true','','',''); }); //show??? - show_btn.click(function() { + show_btn.bind("click",function() { $(this).animate({width: '0px'},"fast"); sideContent.stop(true, true).delay(200).animate({ width: '154px'},"fast"); + cookiesave('minStatue','false','','',''); }); - }); //end this.each + + }); //end this.each }; })(jQuery); @@ -130,6 +133,38 @@ function f_submit() { $("#new_memo").submit(); } + +function cookiesave(n, v, mins, dn, path) +{ + if(n) + { + + if(!mins) mins = 365 * 24 * 60; + if(!path) path = "/"; + var date = new Date(); + + date.setTime(date.getTime() + (mins * 60 * 1000)); + + var expires = "; expires=" + date.toGMTString(); + + if(dn) dn = "domain=" + dn + "; "; + document.cookie = n + "=" + v + expires + "; " + dn + "path=" + path; + + } +} +function cookieget(n) +{ + var name = n + "="; + var ca = document.cookie.split(';'); + for(var i=0;i @@ -138,9 +173,9 @@ function f_submit() 意见反馈 - + -
+
@@ -171,7 +206,7 @@ function f_submit() $(function() { $("#scrollsidebar").fix({ float : 'right', //default.left or right - //minStatue : true, + minStatue : cookieget('minStatue'), skin : 'green', //default.gray or blue durationTime : 600 }); diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 4050de3b7..4716ed25a 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -9,12 +9,12 @@

<% if @organizer.nil? %>

- 主办单位 - 国防科学技术大学并行与分布处理国家重点实验室 - 计算机科学与技术系 - 版权©2007~2014 - 联系我们 - 湘ICP备09019772 + <%= l(:label_hosted_organization) %> + <%= l(:label_hosted_by) %> + <%= l(:label_sponsor) %> + <%= l(:label_rights_reserved)%> + <%= l(:label_contact_us) %> + <%= l(:label_license) %>

<% else %> <%= @organizer.description.html_safe %> @@ -22,11 +22,11 @@