optimize the show of forge

This commit is contained in:
xianbo 2014-03-24 10:18:42 +08:00
parent 2e3b44c830
commit 8db09739a1
4 changed files with 60 additions and 5 deletions

View File

@ -9,9 +9,14 @@ module CoursesHelper
=end =end
TeacherRoles = [3, 4, 7, 9] TeacherRoles = [3, 4, 7, 9]
StudentRoles = [5, 10] StudentRoles = [5, 10]
AllPeople = StudentRoles+TeacherRoles
## return people count ## return people count
# 返回x项目成员数量即roles表中定义的所有成员
def projectCount project
searchCountByRoles project, AllPeople
end
# 返回教师数量即roles表中定义的Manager # 返回教师数量即roles表中定义的Manager
def teacherCount project def teacherCount project
searchCountByRoles project, TeacherRoles searchCountByRoles project, TeacherRoles

View File

@ -286,6 +286,7 @@ module ProjectsHelper
WHERE project_type = 0 ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") WHERE project_type = 0 ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ")
end end
# 判断课程是否结束,快别用,这个定日子的方法有问题 # 判断课程是否结束,快别用,这个定日子的方法有问题
def course_timeout? project def course_timeout? project
return true if (project.nil? && project.course_extra.nil?) return true if (project.nil? && project.course_extra.nil?)

View File

@ -39,6 +39,13 @@ module WelcomeHelper
end end
end end
def get_project_avatar project
if get_avatar?(project)
url_to_avatar(project)
else
'../images/avatars/Project/project.jpg'
end
end
# 前略·天国の首页君/Earth has been unable stop to welcomePage's. # 前略·天国の首页君/Earth has been unable stop to welcomePage's.
# sum - 要搜索的项目数量 # sum - 要搜索的项目数量
# max_rate - 新项目所占所有项目的比重10分制 # max_rate - 新项目所占所有项目的比重10分制
@ -57,10 +64,23 @@ module WelcomeHelper
(c1.take(max)+c2).take(sum) (c1.take(max)+c2).take(sum)
end end
def find_miracle_project(sum=10, max_rate=7)
max = sum*(max_rate.to_f/10)
c1 = find_new_project(sum).to_a.dup
c2 = find_all_hot_project(sum).to_a.dup
c2 = c2 - c1
(c1.take(max)+c2).take(sum)
end
def find_new_course limit=15 def find_new_course limit=15
Project.visible.joins(:course_extra).where("#{Project.table_name}.project_type = ? ", 1).order("courses.time DESC, #{Project.table_name}.created_on DESC").limit(limit).all Project.visible.joins(:course_extra).where("#{Project.table_name}.project_type = ? ", 1).order("courses.time DESC, #{Project.table_name}.created_on DESC").limit(limit).all
end end
def find_new_project limit=15
Project.visible.joins(:course_extra).where("#{Project.table_name}.project_type = ? ", 0).order("courses.time DESC, #{Project.table_name}.created_on DESC").limit(limit).all
end
def find_all_hot_project limit=15 def find_all_hot_project limit=15
sort_project_by_hot limit sort_project_by_hot limit
end end

View File

@ -106,9 +106,7 @@
<%= stylesheet_link_tag 'welcome' %> <%= stylesheet_link_tag 'welcome' %>
<!-- <div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<h3 style="margin-left: 5px; color: #e8770d;"><strong>热门项目</strong></h3> <h3 style="margin-left: 5px; color: #e8770d;"><strong>热门项目</strong></h3>
<span style="margin-top: -20px;float: right; display: block;"><%= link_to "更多>>", { :controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}, :target => "_blank" %></span> <span style="margin-top: -20px;float: right; display: block;"><%= link_to "更多>>", { :controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}, :target => "_blank" %></span>
<div class="d-p-projectlist-box"> <div class="d-p-projectlist-box">
@ -135,6 +133,37 @@
<% end %> <% end %>
</ul> </ul>
</div> </div>
</div> -->
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<h3 style="margin-left: 5px; color: #e8770d;"><strong>热门项目</strong></h3>
<span style="margin-top: -20px;float: right; display: block;"><%= link_to "更多>>", {:controller => 'projects', :action => 'course', :project_type => 1}, :target => "_blank" %></span>
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
<% find_miracle_project(11, 7).map do |project| %>
<li style="position:relative;height:5em;" class='<%= cycle("odd", "even") %>'>
<div style="float: left;">
<%= image_tag(get_project_avatar(project), :class => "avatar-4") %>
</div>
<!-- 上左下右 -->
<div style="float: left; margin-left: 10px; width: 380px;">
<%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%>
(<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>)
</div>
<div style="float: left;margin:5px; margin-left: 10px; width: 380px;">
<span class='font_lighter' title =<%=project.description.to_s%>><%=project.description.truncate(35, omission: '...')%></span>
</div>
<div style="position:absolute; bottom:0;right:0;margin:5px 10px 5px 5px ;">
<%= content_tag "span", show_grade(project),
:style => "cursor: pointer; display: inline-block; float: right; color: #ec6300; ",
:title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度",
:class => "tooltip",
:id => "tooltip-#{project.id}" %>
</p>
</div>
</li>
<% end; reset_cycle %>
</ul>
</div>
</div> </div>
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject" style="float: right;"> <div id="J_Slide" class="d-p-index-box d-p-index-hotproject" style="float: right;">