From b04fe3d1bbc8bc34e86e4f1e8aff482eee4b280d Mon Sep 17 00:00:00 2001 From: nieguanghui Date: Mon, 21 Oct 2013 09:42:09 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=AF=84=E5=88=86=20=E4=B8=AA=E4=BA=BA=E8=AF=84=E5=88=86=20?= =?UTF-8?q?=EF=BC=8C=E4=B8=AA=E4=BA=BA=E5=9C=A8=E9=A1=B9=E7=9B=AE=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E5=88=86=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 5 +- app/controllers/members_controller.rb | 14 +- app/controllers/projects_controller.rb | 43 ++- app/controllers/users_controller.rb | 4 +- app/helpers/application_helper.rb | 4 +- app/models/project.rb | 1 + app/models/user_grade.rb | 4 + app/views/bids/_list_projects.html.erb | 4 +- app/views/projects/_project.html.erb | 13 +- app/views/projects/member.html.erb | 35 +- app/views/projects/search.html.erb | 16 +- app/views/users/index.html.erb | 8 +- config/locales/zh.yml | 5 + .../20130828004955_stored_status_procedure.rb | 325 ++++++++++++++++-- ...017080750_add_grade_to_project_statuses.rb | 5 + ...131017120541_add_grade_to_user_statuses.rb | 5 + .../20131017131615_create_user_grades.rb | 10 + ...20131017135933_add_index_to_user_grades.rb | 7 + ...0104_add_missing_index_to_user_statuses.rb | 5 + ...3_add_missing_index_to_project_statuses.rb | 5 + db/schema.rb | 41 ++- .../2013/10/131007102834__my_course.html.erb | 68 ++++ lib/redmine/activity/fetcher.rb | 4 +- .../stylesheets/application.css | 10 +- 24 files changed, 553 insertions(+), 88 deletions(-) create mode 100644 app/models/user_grade.rb create mode 100644 db/migrate/20131017080750_add_grade_to_project_statuses.rb create mode 100644 db/migrate/20131017120541_add_grade_to_user_statuses.rb create mode 100644 db/migrate/20131017131615_create_user_grades.rb create mode 100644 db/migrate/20131017135933_add_index_to_user_grades.rb create mode 100644 db/migrate/20131017140104_add_missing_index_to_user_statuses.rb create mode 100644 db/migrate/20131017140123_add_missing_index_to_project_statuses.rb create mode 100644 files/2013/10/131007102834__my_course.html.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 9e51a8598..f2e197cd8 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -307,11 +307,14 @@ class BidsController < ApplicationController # a = [1] # @project = Project.where("id in []", a) @user = @bid.author - @bidding_project = @bid.biding_projects + @bidding_project = @bid.biding_projects.all + + @bidding_project = @bidding_project.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} if @bid.homework_type == 1 @homework = HomeworkAttach.new @homework_list = @bid.homeworks end + respond_to do |format| if @bid.reward_type == 3 format.html { diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index fadeec3e0..940172e9c 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -48,12 +48,14 @@ class MembersController < ApplicationController def create members = [] project_info = [] + user_grade = [] if params[:membership] if params[:membership][:user_ids] attrs = params[:membership].dup user_ids = attrs.delete(:user_ids) user_ids.each do |user_id| members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) + user_grade << UserGrade.new(:user_id => user_id, :project_id => @project.id) ## added by nie if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) @@ -65,13 +67,14 @@ class MembersController < ApplicationController members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) ## added by nie if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") - project_info << ProjectInfo.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) + project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id]) end ## end end @project.members << members # added by nie @project.project_infos << project_info + @project.user_grades << user_grade # end end @@ -124,13 +127,20 @@ class MembersController < ApplicationController def destroy if request.delete? && @member.deletable? @member.destroy - end + # end user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) if user_admin.size > 0 user_admin.each do |user| user.destroy end end + user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id) + if user_grade.size > 0 + user_grade.each do |grade| + grade.destroy + end + end + end respond_to do |format| format.html { redirect_to_settings_in_projects } format.js diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 783e8222a..b7427b1e9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -146,8 +146,20 @@ class ProjectsController < ApplicationController # # end # end + # @projects = Project.where("project_type <> ? or project_type is null", 1) # @projects.each do |project| - # ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) + # @id = project.id + # @users = Member.find_by_sql("SELECT + # members.user_id + # FROM members + # INNER JOIN users + # ON members.user_id = users.id + # WHERE members.project_id = #{@id} + # AND (users.type = 'User' AND users.status = 1);") + # @users.each do |user| + # UserGrade.create(:project_id => project.id, :user_id => user.user_id) + # end + # #ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) # end # @projects_status = Project.visible.like(params[:name]) if params[:name].present? @project_count = @projects_status.count @@ -175,13 +187,13 @@ class ProjectsController < ApplicationController when '1' @offset ||= @project_pages.reverse_offset unless @offset == 0 - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit if limit == 0 limit = @limit end - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse end @s_type = 1 @@ -202,13 +214,13 @@ class ProjectsController < ApplicationController else @offset ||= @project_pages.reverse_offset unless @offset == 0 - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit if limit == 0 limit = @limit end - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse end @s_type = 1 # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } @@ -524,8 +536,9 @@ class ProjectsController < ApplicationController r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) - if (params[:project][:is_public] == '1' && @course_tag != "1") || (@course_tag=="1" && params[:project][:is_public] == '1') - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @course_tag) + UserGrade.create(:user_id => User.current.id, :project_id => @project.id, :grade => 0) + if params[:project][:is_public] == '1' + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :project_type => @course_tag) end @project.members << m @project.project_infos << project @@ -747,6 +760,20 @@ class ProjectsController < ApplicationController if @project.project_type == 1 render :layout => 'base_courses' 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 end # def news @@ -790,7 +817,7 @@ class ProjectsController < ApplicationController project_status = ProjectStatus.find_by_project_id(@project.id) project_status.destroy elsif params[:project][:is_public] == '1' - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => 1) + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0,:grade => 0, :project_type => 1) end respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f9d4a30ea..eb8e675ec 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -280,13 +280,13 @@ class UsersController < ApplicationController when '1' @offset ||= @user_pages.reverse_offset unless @offset == 0 - @users_statuses = scope.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse + @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse else limit = @user_count % @limit if limit == 0 limit = @limit end - @users_statuses = scope.reorder('changesets_count').offset(@offset).limit(limit).all.reverse + @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse end @s_type = 1 #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 571eb0b81..0db12e244 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -254,11 +254,13 @@ module ApplicationHelper s << "" end if @project.project_type == 1 - unless Course.find_by_extra(@project.identifier).tea_id == User.current.id + unless Course.find_by_extra(@project.identifier).nil? + unless Course.find_by_extra(@project.identifier).tea_id == User.current.id s << "" s << join_in_course(@project, User.current)#, ['whiteButton']) s << "" end + end end s << (render :partial => 'projects/project', :locals => {:project => project}).to_s s << "\n" diff --git a/app/models/project.rb b/app/models/project.rb index e45c8dc29..ab558ec97 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -70,6 +70,7 @@ class Project < ActiveRecord::Base has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy + has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy #end has_one :wiki, :dependent => :destroy diff --git a/app/models/user_grade.rb b/app/models/user_grade.rb new file mode 100644 index 000000000..f79fcd2c6 --- /dev/null +++ b/app/models/user_grade.rb @@ -0,0 +1,4 @@ +class UserGrade < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :project +end diff --git a/app/views/bids/_list_projects.html.erb b/app/views/bids/_list_projects.html.erb index 42812a5fa..06a7a85f3 100644 --- a/app/views/bids/_list_projects.html.erb +++ b/app/views/bids/_list_projects.html.erb @@ -8,12 +8,14 @@
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %> +
@@ -21,7 +23,7 @@
<%= link_to(b_project.project.name, project_path(b_project.project)) %> + <%= l(:label_join_bidding)%> - + <%= l(:label_system_grade) %>:<%= (b_project.project.project_status.grade.nil? ? 0 : b_project.project.project_status.grade) unless (b_project.project.project_status.nil? && b_project.project.nil?) %> <% if get_prize(b_project).nil? or get_prize(b_project) == "" %> <% if @bid.deadline < Date.today %> <%= l(:label_noawards)%> diff --git a/app/views/projects/_project.html.erb b/app/views/projects/_project.html.erb index ad750fe94..0a4f0b0e7 100644 --- a/app/views/projects/_project.html.erb +++ b/app/views/projects/_project.html.erb @@ -87,19 +87,12 @@
<%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(@project.created_on)) %>
+
+ <%= content_tag('span', "#{l(:label_project_grade)}: ")%><%= @project.project_status.grade%> +
- -
diff --git a/app/views/projects/member.html.erb b/app/views/projects/member.html.erb index f0b94c6eb..a3cd24cee 100644 --- a/app/views/projects/member.html.erb +++ b/app/views/projects/member.html.erb @@ -4,16 +4,29 @@ <%= error_messages_for 'member' %> <% roles = Role.find_all_givable members = @project.member_principals.includes(:roles, :principal).all.sort %> -<% if members.any? %> -<% members.each do |member| %> + <% + 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 %> +<% if temps.any? %> +<% temps.each do |member| %>
- <% next if member.new_record? %> - <% unless member.created_on.nil? %> + <% next if member.new_record? %> + <% unless member.created_on.nil? %> <%= content_tag "p", "#{format_date(member.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %> <% end %> <%= member.user.nil? ? '' : (link_to image_tag(url_to_avatar(member.user), :class => 'avatar'), :class => "avatar") %> <%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %> + <% if @project.project_type == 1 %>

@@ -26,9 +39,17 @@ <% else %> <% end %> -

+

+
<% else%> <%= content_tag "div", content_tag("p", member.roles.sort.collect(&:to_s).join(', ')), :class => "clear avatar_name" %> + <% users.each do |user|%> + <% if user[:user_id] == member[:user_id]%> +
+

<%= l(:label_user_for_project_grade) %>: <%= user[:grade] %>

+
+ <% end %> + <% end %> <% end %> <%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %> @@ -40,4 +61,6 @@ <%= l(:label_no_data) %>

<% end %> - \ No newline at end of file + + + diff --git a/app/views/projects/search.html.erb b/app/views/projects/search.html.erb index 8671d5add..195e49618 100644 --- a/app/views/projects/search.html.erb +++ b/app/views/projects/search.html.erb @@ -28,25 +28,13 @@ <%end%> - +
<%= render_project_hierarchy(@projects)%>
- +