From 77ea0092b703fbf2f138274ecdb0557c57a6138b Mon Sep 17 00:00:00 2001
From: kg
Date: Thu, 24 Apr 2014 14:33:15 +0800
Subject: [PATCH] add course homepage activity
---
app/controllers/projects_controller.rb | 79 ++++++++++++++++++++++----
app/helpers/projects_helper.rb | 13 ++++-
app/views/projects/_course.html.erb | 2 +
3 files changed, 81 insertions(+), 13 deletions(-)
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 6c8e75eeb..7389616fe 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -198,9 +198,9 @@ class ProjectsController < ApplicationController
@project_activity_count=Hash.new
@projects_all.each do |project|
- @project_activity_count[project.id]=1
+ @project_activity_count[project.id]=0
end
- project_ids=@project_activity_count.keys()
+ @project_ids=@project_activity_count.keys()
days = Setting.activity_days_default.to_i
date_to ||= Date.today + 1
@@ -251,47 +251,67 @@ class ProjectsController < ApplicationController
#gcm approach 2
#issue_count
- Issue.where(project_id: project_ids).where("updated_on>?",date_from).each do |issue|
+ Issue.where(project_id: @project_ids).where("updated_on>?",date_from).each do |issue|
# @project_activity_count[issue.project_id.to_s]+=1
@project_activity_count[issue.project_id]+=issue.journals.where("created_on>?",date_from).count
end
#repository_count
- Repository.where(project_id: project_ids).each do |repository|
+ Repository.where(project_id: @project_ids).each do |repository|
# @project_activity_count[repository.project_id.to_s]+=1
@project_activity_count[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|
+ News.where(project_id: @project_ids).where("created_on>?",date_from).each do |news|
@project_activity_count[news.project_id]+=1
end
#document_count
- Document.where(project_id: project_ids).where("created_on>?",date_from).each do |document|
+ Document.where(project_id: @project_ids).where("created_on>?",date_from).each do |document|
@project_activity_count[document.project_id]+=1
end
#file_count
- Attachment.where(container_id: project_ids).where("container_type='Project' AND created_on>?",date_from).each do |attachment|
+ Attachment.where(container_id: @project_ids).where("container_type='Project' AND created_on>?",date_from).each do |attachment|
@project_activity_count[attachment.container_id]+=1
end
#message_count
- Board.where(project_id: project_ids).take(1) do |board|
+ Board.where(project_id: @project_ids).each do |board|
# @project_activity_count[board.project_id]+=1
@project_activity_count[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|
+ TimeEntry.where(project_id: @project_ids).where("updated_on>?",date_from).each do |timeentry|
@project_activity_count[timeentry.project_id]+=1
end
+
+ #feedbackc_count
+ JournalsForMessage.where(jour_id: @project_ids).each do |jourformess|
+ @project_activity_count[jourformess.jour_id]+=1
+ end
+
+ #@project_activity_count!=0
+ @project_all_array=[]
+ i=0;
+ @projects_all.each do |project|
+ id=project.id
+ @project_all_array[i]=project
+ if @project_activity_count[id]==0
+ @project_activity_count[id]=1
+ end
+ i=i+1
+ end
@project_activity_count_array=@project_activity_count.values()
- max_ac=@project_activity_count_array.max
+
+
+
+
#gcm end
@@ -300,17 +320,28 @@ class ProjectsController < ApplicationController
when '0'
@projects = @projects_all.order("created_on desc")
@s_type = 0
+ @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)
when '1'
@projects = @projects_all.order("course_ac_para desc")
@s_type = 1
+ @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)
when '2'
@projects = @projects_all.order("watchers_count desc")
@s_type = 2
+ @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)
+
+ #gcm
+ when '3'
+ @projects=desc_sort_course_by_avtivity(@project_ids,@project_activity_count_array,@project_all_array)
+ @s_type = 3
+ @projects = @projects[@project_pages.offset, @project_pages.per_page]
+ #gcmend
+
else
@s_type = 0
@projects = @projects_all.order("created_on desc")
+ @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)
end
- @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page)
respond_to do |format|
format.html {
@@ -992,7 +1023,31 @@ class ProjectsController < ApplicationController
end
end
- def desc_sort_course_by_avtivity(projects,ids,activities)
+ def desc_sort_course_by_avtivity(ids,activity_count,projects)
+ return projects if activity_count.size<2
+ (activity_count.size-2).downto(0) do |i|
+ (0..i).each do |j|
+ if activity_count[j]activity_count[j+1] do
+ # count_temp=activity_count[j]
+
+ # activity_count[j]=activity_count[j+1]
+ # activity_count[j+1]=count_temp
+ # end
+ # end
+ # end
+#desc_sort_course_by_avtivity(@project_ids,@project_activity_count_array,@projects_all)
end
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 2d2934cc2..44fb5d564 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -69,18 +69,29 @@ module ProjectsHelper
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")
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_activity), course_path(:project_sort_type => '3', :project_type => project_type)))
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
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_activity), course_path(:project_sort_type => '3', :project_type => project_type)))
when 2
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
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_activity), course_path(:project_sort_type => '3', :project_type => project_type)))
+
+ #gcm
+ when 3
+ content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
+ 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_activity), course_path(:project_sort_type => '3', :project_type => project_type), :class=>"selected"), :class=>"selected")
end
+ #gcmend
+
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
diff --git a/app/views/projects/_course.html.erb b/app/views/projects/_course.html.erb
index b698b1142..33d222145 100644
--- a/app/views/projects/_course.html.erb
+++ b/app/views/projects/_course.html.erb
@@ -17,7 +17,9 @@
<% @admin = @project.project_infos%>
<%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%>
+ <% unless @project.course_extra.school.nil? %>
<%= @project.course_extra.school.name %>
+ <% end %>
<% end %>