From 8db09739a1b2bf6cd124f45c44b2b79811415335 Mon Sep 17 00:00:00 2001 From: xianbo Date: Mon, 24 Mar 2014 10:18:42 +0800 Subject: [PATCH] optimize the show of forge --- app/helpers/courses_helper.rb | 7 ++++++- app/helpers/projects_helper.rb | 1 + app/helpers/welcome_helper.rb | 22 +++++++++++++++++++- app/views/welcome/index.html.erb | 35 +++++++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 78e20c2a7..d474b5587 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -9,8 +9,13 @@ module CoursesHelper =end TeacherRoles = [3, 4, 7, 9] StudentRoles = [5, 10] - + AllPeople = StudentRoles+TeacherRoles ## return people count + + # 返回x项目成员数量,即roles表中定义的所有成员 + def projectCount project + searchCountByRoles project, AllPeople + end # 返回教师数量,即roles表中定义的Manager def teacherCount project diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 35314efcc..b9d8ef932 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -285,6 +285,7 @@ module ProjectsHelper SELECT project_id,grade FROM project_statuses WHERE project_type = 0 ORDER BY grade DESC LIMIT #{limit} ) AS t ON p.id = t.project_id ") end + # 判断课程是否结束,快别用,这个定日子的方法有问题 def course_timeout? project diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index ed90dd24f..fd00c83e2 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -39,6 +39,13 @@ module WelcomeHelper 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. # sum - 要搜索的项目数量 # max_rate - 新项目所占所有项目的比重,10分制 @@ -56,10 +63,23 @@ module WelcomeHelper c2 = c2 - c1 (c1.take(max)+c2).take(sum) 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 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 + + 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 sort_project_by_hot limit diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index c9fad6757..eae4cba2a 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -105,10 +105,8 @@ <%= stylesheet_link_tag 'welcome' %> - - -
+ +
+

热门项目

+ <%= link_to "更多>>", {:controller => 'projects', :action => 'course', :project_type => 1}, :target => "_blank" %> +
+
    + <% find_miracle_project(11, 7).map do |project| %> +
  • +
    + <%= image_tag(get_project_avatar(project), :class => "avatar-4") %> +
    + +
    + <%= 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' %>) +
    +
    + ><%=project.description.truncate(35, omission: '...')%> +
    +
    + <%= content_tag "span", show_grade(project), + :style => "cursor: pointer; display: inline-block; float: right; color: #ec6300; ", + :title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度", + :class => "tooltip", + :id => "tooltip-#{project.id}" %> +

    +
    +
  • + <% end; reset_cycle %> +
+