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/assets/javascripts/enterprises.js.coffee b/app/assets/javascripts/enterprises.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/enterprises.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/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/enterprises.css.scss b/app/assets/stylesheets/enterprises.css.scss new file mode 100644 index 000000000..174f3a2ec --- /dev/null +++ b/app/assets/stylesheets/enterprises.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Enterprises controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ 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/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index f5c42f7b4..f2c0eb056 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -6,13 +6,18 @@ class AppliedProjectController < ApplicationController @project = Project.find_by_id(params[:project_id]) if params[:project_join] if @project - @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) - if @applieds.count == 0 - appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) - Mailer.applied_project(appliedproject).deliver - @status = 2 + user = User.find @user_id + if user.member_of?(@project) + @status = 3 else - @status = 1 + @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) + if @applieds.count == 0 + appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) + Mailer.applied_project(appliedproject).deliver + @status = 2 + else + @status = 1 + end end else @status = 0 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/enterprises_controller.rb b/app/controllers/enterprises_controller.rb new file mode 100644 index 000000000..c15b6dc8f --- /dev/null +++ b/app/controllers/enterprises_controller.rb @@ -0,0 +1,6 @@ +class EnterprisesController < ApplicationController + layout 'project_base' + def index + @enterprises = Project.find_by_sql("select enterprise_name from projects") + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a2e793a10..64706887b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -14,41 +14,35 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Time 2015-01-28 16:34:21 +# Author lizanle +# Description 封装代码,简化代码,格式化代码, class ProjectsController < ApplicationController layout :select_project_layout menu_item :overview menu_item :roadmap, :only => :roadmap menu_item :settings, :only => :settings - - menu_item l(:label_sort_by_time), :only => :index - menu_item l(:label_sort_by_active), :only => :index - menu_item l(:label_sort_by_influence), :only => :index - - # menu_item l(:label_homework), :only => :homework - # menu_item l(:label_course_feedback), :only => :feedback menu_item :homework, :only => [:homework, :new_homework] 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] + before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, + :reopen,:view_homework_attaches,:course] 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 - #before_filter :find_project_repository, :only => [:show] # 除非项目内人员,不可查看成员, TODO: 完了写报表里去 before_filter :memberAccess, only: :member - accept_rss_auth :index + # accept_rss_auth :index accept_api_auth :index, :show, :create, :update, :destroy after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| @@ -82,369 +76,66 @@ class ProjectsController < ApplicationController ### added by william include ActsAsTaggableOn::TagsHelper - def find_project_repository - unless @project.repositories.nil? - @project.repositories.each do |repository| - repository.fetch_changesets if Setting.autofetch_changesets? - end - end - end - - def enterprise_course - session[:enterprise_college] = 2 - respond_to do |format| - format.html { redirect_to :back } - #format.api { render_api_ok } - end - end - - def course_enterprise - session[:enterprise_college] = 1 - respond_to do |format| - format.html { redirect_to :back } - #format.api { render_api_ok } - end - end - def index render_404 - #调用存储过程更新提交次数 - #ActiveRecord::Base.connection.execute("CALL sp_project_status_cursor();") - #Modified by nie - @project_type = params[:project_type].to_i - per_page_option = 10 - - @projects_all = Project.active.visible. - 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'] - -#gcm activity count - - @project_activity_count=Hash.new - - @projects_all.each do |project| - @project_activity_count[project.id]=0 - end - - @project_activity_count=get_project_activity @projects_all,@project_activity_count - -#gcm end - - case params[:project_sort_type] - when '0' - @projects = @projects_all.order("created_on desc") - @s_type = 0 - when '1' - @projects = @projects_all.order("score desc") - @s_type = 1 - when '2' - @projects = @projects_all.order("watchers_count desc") - @s_type = 2 - - #gcm - when '3' - #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) - @projects=handle_project @projects_all,@project_activity_count - @s_type = 3 - @projects = @projects[@project_pages.offset, @project_pages.per_page] - - else - @projects = @projects = @projects_all.order("score desc") - @s_type = 1 - end - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - - respond_to do |format| - format.html { - # render :layout => 'base' - # scope = Project - # unless params[:closed] - # scope = scope.active - # end - } - format.api { - # @offset, @limit = api_offset_and_limit - # @project_count = Project.visible.count - # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all - } - format.atom { - projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") - } - end end def course - @project_type = params[:project_type] - @school_id = params[:school_id] - per_page_option = 10 - if @school_id == "0" or @school_id.nil? - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). - where("#{Project.table_name}.project_type = ? ", Project::ProjectType_course) - else - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). - joins(:course_extra). - where("#{Project.table_name}.project_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) - end - - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] - - #gcm activity count - - @project_activity_count=Hash.new - #count initialize - @projects_all.each do |project| - @project_activity_count[project.id]=0 - end - - #@project_activity_count=get_project_activity @projects_all,@project_activity_count - #gcm end - - - case params[:project_sort_type] - when '0' - @projects = @projects_all.order("created_on desc") - @s_type = 0 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - when '1' - @projects = @projects_all.order("course_ac_para desc") - @s_type = 1 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - when '2' - @projects = @projects_all.order("watchers_count desc") - @s_type = 2 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - #gcm - when '3' - - #gcm - @project_activity_count=get_project_activity @projects_all,@project_activity_count - #gcmend - - @projects=handle_project @projects_all,@project_activity_count - @s_type = 3 - @projects = @projects[@project_pages.offset, @project_pages.per_page] - else - @s_type = 0 - @projects = @projects_all.order("created_on desc") - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - end - - respond_to do |format| - format.html { - render :layout => 'base' - } - format.api { - # @offset, @limit = api_offset_and_limit - # @project_count = Project.visible.count - # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all - } - format.atom { - projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") - } - end + render_404 end -#gcm + # Time 2015-01-29 11:19:11 + # Author lizanle + # Description 项目搜索方法 def search - #modified by nie - project_type = params[:project_type].to_i - projects_all = (project_type.eql? Project::ProjectType_course) ? Project.course_entities : Project.project_entities - @projects = projects_all.visible - #@projects_all = @projects.visible.like(params[:name]) if params[:name].present? + # 如果有名字,就按名字搜索,如果没有,就展示所有,用Karminari分页 if params[:name].present? - @projects_all = @projects.visible.like(params[:name]) + @project_pages = Project.project_entities.visible.like(params[:name]).page(params[:page]).per(10) else - @projects_all = @projects; + @project_pages = Project.project_entities.visible.page(params[:page] ).per(10) end - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] - - #gcm activity count - - @project_activity_count=Hash.new - # count initialize - @projects_all.each do |project| - @project_activity_count[project.id]=0 - end - - #@project_activity_count=get_project_activity @projects_all,@project_activity_count - - #gcm end - - - case params[:project_sort_type] - when '0' - @projects = @projects_all.order("created_on desc") - @s_type = 0 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - when '1' - @projects = @projects_all.order("course_ac_para desc") - @s_type = 1 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - when '2' - @projects = @projects_all.order("watchers_count desc") - @s_type = 2 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - when '3' - #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) - @project_activity_count=get_project_activity @projects_all,@project_activity_count_array #gcm - @projects=handle_project @projects_all,@project_activity_count - @s_type = 3 - @projects = @projects[@project_pages.offset, @project_pages.per_page] - - else - @s_type = 0 - @projects = @projects_all.order("created_on desc") - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) - - #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count - #gcmend - - end - + @projects = @project_pages.order("created_on desc") respond_to do |format| format.html { render :layout => 'base' scope = Project unless params[:closed] - scope = scope.active + scope = scope.active end } - format.api { - # @offset, @limit = api_offset_and_limit - # @project_count = Project.visible.count - # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all - } + # 需要到处atom使用的格式 (redmine自带) format.atom { projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") } end end -#gcmend - - - #Added by young - def homework - @offset, @limit = api_offset_and_limit({:limit => 10}) - @bids = @project.homeworks.order('deadline') - @bids = @bids.like(params[:name]) if params[:name].present? - - @bids = paginateHelper @bids - render :layout => 'base_courses' - - end - - def new_homework - # Dear maintainer: - # once you are done trying to 'optimize' this Magic routine, - # well, it's on you, I'll leave it to you. - if (User.current.logged? && - (User.current.admin? || - ( - !Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.nil? && - ( - Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.roles && - ( Role.where(id: [3, 4, 7, 9]).size > 0 ) - ) - ) - ) - ) - @homework = Bid.new - @homework.safe_attributes = params[:bid] - render :layout => 'base_courses' - else - render_404 - end - - end - #Ended by young + # Time 2015-01-29 16:13:20 + # Author lizanle + # Description 项目首页中用户反馈 方法 def feedback - @page = params[:page] - @page = @page.to_i + @page = params[:page].to_i # Find the page of the requested reply @jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 + limit = 10 offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) - page = 1 + offset / @limit + page = 1 + offset / limit if params[:r] && @page.nil? - @page = page + @page = @page < 0 ? 1 : @page end - - puts @page - if @page < 0 - @page = 1 - end - if @page > page - @page = page - end - - - #@feedback_count = @jours.count - #@feedback_pages = Paginator.new @feedback_count, @limit, @page - #@offset ||= @feedback_pages.offset + @page = @page > page ? page : @page @jour = paginateHelper @jours,10 @state = false - @base_courses_tag = @project.project_type - - respond_to do |format| - format.html{render :layout => 'base_courses' if @base_courses_tag==1} + format.html format.api end end def project_respond - # will_reply = JournalsForMessage.find(params[:reference_id]) if params[:reference_id] project_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1] - # @project = Project.find_by_id(project_id) parent_id = params[:reference_id] author_id = User.current.id reply_user_id = params[:reference_user_id] @@ -460,12 +151,8 @@ class ProjectsController < ApplicationController @jfm = Project.add_new_jour(nil, nil, project_id, options) @save_succ = @jfm.errors.empty? - # flash[:notice]=l(:label_projects_feedback_respond_success) - respond_to do |format| - # format.html { redirect_to :back } format.js - #format.api { render_api_ok } end end @@ -556,45 +243,18 @@ class ProjectsController < ApplicationController render_404 end - # Show @project + # Time 2015-01-29 10:42:00 + # Author lizanle + # Description 项目动态展示方法,删除了不必要的代码 def show - if(@project && !@project.is_public && !User.current.member_of?(@project)) - render_403 + # 试图跳转到请求的按钮 + if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return end - @project_type = params[:project_type] - - # try to redirect to the requested menu item - if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) - return - end - - @users_by_role = @project.users_by_role - @subprojects = @project.children.visible.all - @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all - @trackers = @project.rolled_up_trackers - if(User.find_by_id(ProjectInfo.find_by_project_id(@project.id).try(:user_id))) - @user = User.find_by_id(ProjectInfo.find_by_project_id(@project.id).user_id) - end cond = @project.project_condition(Setting.display_subprojects_issues?) - @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) - @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) - - if User.current.allowed_to?(:view_time_entries, @project) - @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f - 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_issues" => true, + "show_issues" => true , "show_files" => true, "show_documents" => true, "show_messages" => true, @@ -604,59 +264,40 @@ class ProjectsController < ApplicationController "show_wiki_edits"=>true, "show_journals_for_messages" => true } - - + # 读取项目默认展示的动态时间天数 + @days = Setting.activity_days_default.to_i + @date_to ||= Date.today + 1 + # 时间跨度不能太大,不然很慢,所以删掉了-1.years + @date_from = @date_to - @days @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])) + @author = params[:user_id].blank? ? nil : User.active.find(params[:user_id]) # 决定显示所用用户或单个用户活动 - @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, - :with_subprojects => @with_subprojects, - :author => @author) + @activity = Redmine::Activity::Fetcher.new(User.current, + :project => @project, + :with_subprojects => @with_subprojects, + :author => @author) @activity.scope_select {|t| !has["show_#{t}"].nil?} - # logger.debug "=========================================#{@activity.scope}" - # @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? - # modify by nwb - # 添加私密性判断 - if User.current.member_of?(@project)|| User.current.admin? - events = @activity.events(@days) + # 根据私密性,取出符合条件的所有数据 + if User.current.member_of?(@project) || User.current.admin? + 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}) @events_count = events.count @events_pages = Paginator.new @events_count, @limit, params['page'] @offset ||= @events_pages.offset + # 总的数据中取出某一页 events = events.slice(@offset,@limit) - #Ended by young + # 按天分组 @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' - documents = @project.documents.includes(:attachments, :category).all - case @sort_by - when 'date' - @grouped = documents.group_by {|d| d.updated_on.to_date } - when 'title' - @grouped = documents.group_by {|d| d.title.first.upcase} - when 'author' - @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} - else - @grouped = documents.group_by(&:category) - end - @document = @project.documents.build - # - @base_courses_tag = @project.project_type - #判断能否显示真名(当前用户为课程的教师时显示真名) - if @project.project_type == Project::ProjectType_course - @teachers= searchTeacherAndAssistant(@project) - @canShowRealName = isCourseTeacher(User.current.id) - end - # real_name action为虚拟的该方法并不存在,用来辅助判断真名权限 - # @canShowRealName = User.current.allowed_to?({:controller => "projects", :action => "real_name"}, @project || @projects, :global => false) + # 根据对应的请求,返回对应的数据 respond_to do |format| - format.html{render :layout => 'base_courses' if @base_courses_tag==1} + format.html format.api end end @@ -667,23 +308,13 @@ class ProjectsController < ApplicationController @member ||= @project.members.new @trackers = Tracker.sorted.all @wiki ||= @project.wiki - #Added by young - # @course_tag = params[:course] - # if @course_tag == '1' - #@course = Course.find_by_extra(@project.identifier) - # if @project.project_type == 1 - # render :layout => 'base_courses' - # else - # render :layout => 'base_projects' - # end - #Ended by young end def edit end - #by young - include CoursesHelper + # by young + # include CoursesHelper def member ## 有角色参数的才是课程,没有的就是项目 @render_file = 'member_list' @@ -702,11 +333,10 @@ class ProjectsController < ApplicationController @subPage_title = '' @members = @project.member_principals.includes(:roles, :principal).all.sort end - else # @project.project_type == Project::ProjectType_project + else roles = Role.find_all_givable @subPage_title = l :label_member_list @members = @project.member_principals.includes(:roles, :principal).joins("LEFT JOIN #{OptionNumber.table_name} ON #{OptionNumber.table_name}.user_id = #{Member.table_name}.user_id and #{OptionNumber.table_name}.score_type = 2 AND #{Member.table_name}.project_id = #{OptionNumber.table_name}.project_id").order("#{OptionNumber.table_name}.total_score DESC").all - #@members = sort_project_members(@project, @members) @applied_members = appied_project_members(@project, @members) end @members = paginateHelper @members @@ -971,91 +601,6 @@ class ProjectsController < ApplicationController end end - - - #gcm - def get_project_activity projects,activities - @project_ids=activities.keys() - - days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years - - #issue_count - Issue.where(project_id: @project_ids).where("updated_on>?",date_from).each do |issue| -# activities[issue.project_id.to_s]+=1 - activities[issue.project_id]+=issue.journals.where("created_on>?",date_from).count - end - - #repository_count - Repository.where(project_id: @project_ids).each do |repository| -# activities[repository.project_id.to_s]+=1 - activities[repository.project_id]+=repository.changesets.where("committed_on>?",date_from).count - end - - - #news_count - News.where(project_id: @project_ids).where("created_on>?",date_from).each do |news| - activities[news.project_id]+=1 - end - - #document_count - Document.where(project_id: @project_ids).where("created_on>?",date_from).each do |document| - activities[document.project_id]+=1 - end - - #file_count - Attachment.where(container_id: @project_ids, container_type: Project).where("created_on>?",date_from).each do |attachment| - activities[attachment.container_id]+=1 - end - - #message_count - Board.where(project_id: @project_ids).each do |board| -# activities[board.project_id]+=1 - activities[board.project_id]+=board.messages.where("updated_on>?",date_from).count - end - - #time_entry_count - TimeEntry.where(project_id: @project_ids).where("updated_on>?",date_from).each do |timeentry| - activities[timeentry.project_id]+=1 - end - - #feedbackc_count - JournalsForMessage.where(jour_id: @project_ids, jour_type: Project).each do |jourformess| - activities[jourformess.jour_id]+=1 - end - - #activities!=0 - i=0; - projects.each do |project| - id=project.id - if activities[id]==0 - activities[id]=1 - end - end - - return activities - end - #gcmend - - #gcm - def handle_project projects,activities - project_activity_count_array=activities.values() - - project_array=[] - i=0; - projects.each do |project| - project_array[i]=project - i=i+1 - end - - projects=desc_sort_course_by_avtivity(project_activity_count_array,project_array) - - return projects - end - #gcmend - - #gcm def desc_sort_course_by_avtivity(activity_count,projects) return projects if activity_count.size<2 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/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 8e11bceb5..6c28ec502 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -25,6 +25,17 @@ class WelcomeController < ApplicationController before_filter :entry_select, :only => [:index] def index + unless params[:enterprise].nil? + @enterprise = params[:enterprise] + @enterprise_projects = Project.find_by_sql(["select * from projects where enterprise_name =? ", @enterprise]) + @e_count = @enterprise_projects.count + if @e_count < 10 + part_count = 10 -@e_count + # @part_projects = find_all_hot_project part_count, order + @part_projects = find_miracle_project(part_count, 3,"score desc") + limit = 10 - @e_count + end + end if @first_page.nil? || @first_page.sort_type.nil? @projects = find_miracle_project(10, 3,"score desc") else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8254c5313..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'} diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb new file mode 100644 index 000000000..10321ba16 --- /dev/null +++ b/app/helpers/enterprises_helper.rb @@ -0,0 +1,2 @@ +module EnterprisesHelper +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/projects_helper.rb b/app/helpers/projects_helper.rb index 5df3644ad..fe6714186 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -36,67 +36,8 @@ module ProjectsHelper {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} ] tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} - end - # added bu huang - def sort_project_enterprise(state, project_type) - content = ''.html_safe - case state - when 0 - - content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") - when 1 - - content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0', :project_type => project_type))) - when 2 - content << content_tag('li', link_to(l(:label_sort_by_active), projects_path(:project_sort_type => '1', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_influence), projects_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_time), projects_path(:project_sort_type => '0', :project_type => project_type))) - end - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs_enterprise") - end - - def sort_course(state, project_type, school_id) - content = ''.html_safe - case state - when 0 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type), :school_id => school_id, :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type, :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:project_sort_type => '3', :project_type => project_type, :school_id => school_id))) - - when 1 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type, :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type, :school_id => school_id), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:project_sort_type => '3', :project_type => project_type, :school_id => school_id))) - - when 2 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type, :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type, :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:project_sort_type => '3', :project_type => project_type, :school_id => school_id))) - - #gcm - when 3 - content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type, :school_id => school_id))) - content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type, :school_id => school_id))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_activity), course_path(:project_sort_type => '3', :project_type => project_type, :school_id => school_id), :class=>"selected"), :class=>"selected") - end - #gcmend - - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs") - end - # end - def sort_project(state, project_type) content = ''.html_safe case state @@ -118,30 +59,7 @@ module ProjectsHelper content = content_tag('ul', content) content_tag('div', content, :class => "tabs") end - - # def sort_course(state, project_type) - # content = ''.html_safe - # case state - # when 0 -# - # content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type))) - # content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") - # when 1 -# - # content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type))) - # content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type))) - # when 2 - # content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type))) - # content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type))) - # end - # content = content_tag('ul', content) - # content_tag('div', content, :class => "tabs") - # end - # Added by young def course_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'}, @@ -153,9 +71,6 @@ module ProjectsHelper end # Ended by young - - - def parent_project_select_tag(project) selected = project.parent # retrieve the requested parent project @@ -375,4 +290,85 @@ module ProjectsHelper end end end + + # Time 2015-01-29 11:39:02 + # Author lizanle + # Description 计算projects + def get_project_activity projects,activities + @project_ids=activities.keys() + + days = Setting.activity_days_default.to_i + date_to ||= Date.today + 1 + date_from = date_to - days-1.years + + #issue_count + Issue.where(project_id: @project_ids).where("updated_on>?",date_from).each do |issue| +# activities[issue.project_id.to_s]+=1 + activities[issue.project_id]+=issue.journals.where("created_on>?",date_from).count + end + + #repository_count + Repository.where(project_id: @project_ids).each do |repository| +# activities[repository.project_id.to_s]+=1 + activities[repository.project_id]+=repository.changesets.where("committed_on>?",date_from).count + end + + + #news_count + News.where(project_id: @project_ids).where("created_on>?",date_from).each do |news| + activities[news.project_id]+=1 + end + + #document_count + Document.where(project_id: @project_ids).where("created_on>?",date_from).each do |document| + activities[document.project_id]+=1 + end + + #file_count + Attachment.where(container_id: @project_ids, container_type: Project).where("created_on>?",date_from).each do |attachment| + activities[attachment.container_id]+=1 + end + + #message_count + Board.where(project_id: @project_ids).each do |board| +# activities[board.project_id]+=1 + activities[board.project_id]+=board.messages.where("updated_on>?",date_from).count + end + + #time_entry_count + TimeEntry.where(project_id: @project_ids).where("updated_on>?",date_from).each do |timeentry| + activities[timeentry.project_id]+=1 + end + + #feedbackc_count + JournalsForMessage.where(jour_id: @project_ids, jour_type: Project).each do |jourformess| + activities[jourformess.jour_id]+=1 + end + + #activities!=0 + i=0; + projects.each do |project| + id=project.id + if activities[id]==0 + activities[id]=1 + end + end + + return activities + end + + def handle_project projects,activities + project_activity_count_array=activities.values() + + project_array=[] + i=0; + projects.each do |project| + project_array[i]=project + i=i+1 + end + + projects=desc_sort_course_by_avtivity(project_activity_count_array,project_array) + + return projects + end end diff --git a/app/helpers/system_log_helper.rb b/app/helpers/system_log_helper.rb new file mode 100644 index 000000000..2ca5baaed --- /dev/null +++ b/app/helpers/system_log_helper.rb @@ -0,0 +1,186 @@ +# 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 && !(log =~ Regexp.new("SystemLogController#",'i')) } + 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) } + # 过滤掉日志中日志分析请求 + logs.collect! do |log| + log = "" if log =~ Regexp.new("SystemLogController",'i') + log + end + 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/course.rb b/app/models/course.rb index a5de93cf7..c986597b3 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -6,7 +6,7 @@ class Course < ActiveRecord::Base STATUS_CLOSED = 5 STATUS_ARCHIVED = 9 - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 diff --git a/app/models/course_group.rb b/app/models/course_group.rb index c7fc81df4..c6aa1299d 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -12,8 +12,7 @@ class CourseGroup < ActiveRecord::Base before_destroy :set_member_nil attr_accessible :name - validates :name, :presence => true, :length => {:maximum => 20} - validate :unique_name_and_course + validates :name, :presence => true, :length => {:maximum => 20}, :uniqueness => { :scope => :course_id} @@ -22,10 +21,5 @@ class CourseGroup < ActiveRecord::Base self.members.update_all("course_group_id = 0") end end - private - def unique_name_and_course - if CourseGroup.where("name=? and course_id=?", name, course_id).first - errors.add(:name, :groupname_repeat) - end - end + 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 14763347f..df403bb5c 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 @@ -113,9 +114,10 @@ class Project < ActiveRecord::Base validates_presence_of :name, :identifier validates_uniqueness_of :identifier validates_uniqueness_of :name - validates_associated :repository, :wiki - # validates_length_of :description, :maximum => 255 + validates_associated :wiki#, :repository + # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 + validates_length_of :enterprise_name, :maximum => 255 validates_length_of :homepage, :maximum => 255 validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH # donwcase letters, digits, dashes but not digits only @@ -125,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] @@ -760,7 +764,8 @@ class Project < ActiveRecord::Base 'issue_custom_field_ids', 'project_type', 'dts_test', - 'attachmenttype' + 'attachmenttype', + 'enterprise_name' @@ -1148,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/applied_project/applied_join_project.js.erb b/app/views/applied_project/applied_join_project.js.erb index deac2c9ce..3f4f6aff7 100644 --- a/app/views/applied_project/applied_join_project.js.erb +++ b/app/views/applied_project/applied_join_project.js.erb @@ -4,6 +4,8 @@ alert("请勿重复申请加入该项目"); <% elsif @status == 2%> alert("申请成功"); +<% elsif @status == 3%> + alert("您已加入该项目"); <%else%> alert("申请失败"); <%end%> \ No newline at end of file diff --git a/app/views/enterprises/index.html.erb b/app/views/enterprises/index.html.erb new file mode 100644 index 000000000..6124f5c7f --- /dev/null +++ b/app/views/enterprises/index.html.erb @@ -0,0 +1,25 @@ +
+

+ <%= link_to l(:label_all_enterprises) %> +

+

+ <% if @enterprises.count == 0 %> +

<%= l(:label_enterprise_nil) %>

+ <% else %> + <% @enterprises.each do |enterprise| %> + <% unless enterprise.enterprise_name.blank? %> +
    +
  • + <%= link_to enterprise.enterprise_name, home_path(:enterprise => enterprise.enterprise_name) %> +
  • +
+ <% end %> + <% end %> + <% end %> +

+
+
+
+
    +
    +<% html_title(l(:label_enterprise_all)) -%> 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 @@