refactor memberlist

This commit is contained in:
yanxd 2013-11-04 22:00:06 +08:00
parent ea8a87c3a6
commit 397eb11dca
4 changed files with 51 additions and 63 deletions

View File

@ -760,24 +760,45 @@ class ProjectsController < ApplicationController
end
#by young
include CoursesHelper
def member
## 有角色参数的才是课程,没有的就是项目
@render_file = 'member_list'
# 判断是否课程
if @project.project_type == 1
render :layout => 'base_courses'
case params[:role]
when '1'
@subPage_title = l :label_teacher_list
@members = searchTeacherAndAssistant(@project)
when '2'
@subPage_title = l :label_student_list
@members = searchStudent(@project)
else
@subPage_title = 'unKown'
@members = []
end
# roles = Role.find_all_givable
# members = @project.member_principals.includes(:roles, :principal).all.sort
#
# users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]}
#
# temp = []
# users.each do |user|
# members.each do |member|
# if member[:user_id] == user[:user_id]
# temp << member
# end
# end
# end
# temps = temp.reverse
else
roles = Role.find_all_givable
@subPage_title = l :label_member_list
@members = @project.member_principals.includes(:roles, :principal).all
@members = sort_project_members(@project, @members)
end
render :layout => 'base_courses' if @project.project_type == 1
end
def sort_project_members project, members
#userGrade = UserGrade.where(:project_id => project.id)
users = UserGrade.where(:project_id => project.id).order('grade DESC').joins("LEFT JOIN users ON users.id = user_grades.id")
memberlist = []
users.each do |user|
members.each do |member|
if member[:user_id] == user[:user_id]
memberlist << member
end
end
end
memberlist
end
# def news

View File

@ -9,17 +9,8 @@
<%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %>
<% if @project.project_type == 1 %>
<div class ="clear avatar_name">
<div class ="clear avatar_name"> &nbsp;
<p>
<% if member.roles.sort.collect(&:to_s).join(', ') =='Manager' %>
<%= l(:label_teacher) %>
<% elsif member.roles.sort.collect(&:to_s).join(', ') =='Reporter' %>
<%= l(:label_student) %>
<% elsif member.roles.sort.collect(&:to_s).join(', ') =='TA' %>
<%= l(:label_TA) %>
<% else %>
<% end %>
</p>
</div>
<% else%>

View File

@ -1,36 +1,10 @@
<div class="member_header">
<p>
<%= l(:label_member_list) if params[:role].blank? %>
<%= @subPage_title %>
</p>
</div>
<div class="member_content">
<%= error_messages_for 'member' %>
<% roles = Role.find_all_givable %>
<% members = @project.member_principals.includes(:roles, :principal).all.sort %>
<!-- 如果是课程且点击教师或者学生,则对成员进行过滤 -->
<% members = searchTeacherAndAssistant(@project) if params[:role] == '1' %>
<% members = searchStudent(@project) if params[:role] == '2' %>
<% if @project.project_type == 1 %>
<%= render :partial => 'member_list', :locals => {:members => members} %>
<% else %>
<% users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}")%>
<% if users %>
<% users = users.sort {|a,b| b[:grade] <=> a[:grade]} %>
<% temp = [] %>
<% users.each do |user|%>
<% members.each do |member|%>
<% if member[:user_id] == user[:user_id] %>
<% temp << member %>
<% end %>
<% end %>
<% end %>
<% temps = temp %>
<%= render :partial => 'member_list', :locals => {:members => temps} %>
<% end %>
<% end %>
<!-- <%= render :partial => 'member_list', :locals => {:members => members} %> -->
<%= render :partial => @render_file, :locals => {:members => @members} %>
</div>

View File

@ -546,6 +546,8 @@ zh:
label_winter: 冬季学期
label_followers: 关注
label_teacher: 教师
label_teacher_list: 教师列表
label_student_list: 学生列表
label_limit_time: 截止日期
label_commit_homework: 提交作业
label_course_homework: 对应课程