From 397eb11dcadb4249d4ed1c9fe86d9d7d95b46947 Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 4 Nov 2013 22:00:06 +0800 Subject: [PATCH] refactor memberlist --- app/controllers/projects_controller.rb | 71 +++++++++++++++--------- app/views/projects/_member_list.html.erb | 11 +--- app/views/projects/member.html.erb | 30 +--------- config/locales/zh.yml | 2 + 4 files changed, 51 insertions(+), 63 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c0050d646..74564abd8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -510,14 +510,14 @@ class ProjectsController < ApplicationController @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.safe_attributes = params[:project][:course] @course.tea_id = User.current.id - # added by bai + # added by bai @course.term = params[:term] @course.time = params[:time] - @course.setup_time = params[:setup_time] - @course.endup_time = params[:endup_time] - @course.class_period = params[:class_period] + @course.setup_time = params[:setup_time] + @course.endup_time = params[:endup_time] + @course.class_period = params[:class_period] end - # end + # end # @course.save # project = ProjectInfo.create(:user_id => User.current.id, :project_id => @project.id) # project_status = ProjectStatus.create(:project_id => @project.id) @@ -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 + 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 - # 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 + + 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 @@ -809,13 +830,13 @@ class ProjectsController < ApplicationController @course = Course.find_by_extra(@project.identifier) unless @course.nil? @course.password = params[:project][:course][:password] - # added by bai + # added by bai @course.term = params[:term] @course.time = params[:time] - @course.setup_time = params[:setup_time] - @course.endup_time = params[:endup_time] - @course.class_period = params[:class_period] - # end + @course.setup_time = params[:setup_time] + @course.endup_time = params[:endup_time] + @course.class_period = params[:class_period] + # end @course.save end @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') diff --git a/app/views/projects/_member_list.html.erb b/app/views/projects/_member_list.html.erb index 9700de1b7..120c49963 100644 --- a/app/views/projects/_member_list.html.erb +++ b/app/views/projects/_member_list.html.erb @@ -9,17 +9,8 @@ <%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %> <% if @project.project_type == 1 %> -
+
 

- <% 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 %>

<% else%> diff --git a/app/views/projects/member.html.erb b/app/views/projects/member.html.erb index c922399e7..33eac5da1 100644 --- a/app/views/projects/member.html.erb +++ b/app/views/projects/member.html.erb @@ -1,36 +1,10 @@

- <%= l(:label_member_list) if params[:role].blank? %> + <%= @subPage_title %>

<%= 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 => @render_file, :locals => {:members => @members} %>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index b65fd5780..2e15dfcda 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 对应课程