From 249ea19c0c45314a7726c99b1708e071e864b71a Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 10 Jul 2014 15:26:34 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=A5=9E=E5=9D=91=EF=BC=8Cusers=E5=92=8Cus?= =?UTF-8?q?er=5Fstatuses=E8=A1=A8=E4=B8=AD=EF=BC=8C=E5=85=B3=E6=B3=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=8D=E5=90=8C=E6=AD=A5=EF=BC=8C=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E5=BD=B1=E5=93=8D=E5=8A=9B=E6=8E=92=E5=BA=8F=E8=BF=98?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E9=97=AE=E9=A2=98=E3=80=82=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?users=E8=A1=A8=E4=B8=AD=E5=9C=A8us=E8=A1=A8=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E6=9D=A1=E7=9B=AE=EF=BC=8C=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=B8=AD=E6=98=AF=E4=B8=8D=E4=BC=9A=E6=98=BE=E7=A4=BA=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 115 ++++++++-------------------- app/models/user_status.rb | 2 +- 2 files changed, 34 insertions(+), 83 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c2db7f79..063d32b84 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -255,112 +255,63 @@ class UsersController < ApplicationController #end def index - - @project_type = params[:project_type] - role = params[:role] - + @status = params[:status] || 1 sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) + # Deprecation + @project_type = params[:project_type] + case params[:format] when 'xml', 'json' @offset, @limit = api_offset_and_limit({:limit => 15}) else - @limit = 15#per_page_option + @limit = 15 end - @status = params[:status] || 1 - has = { - "show_changesets" => true - } - # @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count - + # retrieve all users scope = UserStatus.visible - case role + + # if role has something, change scope. + case params[:role] when 'teacher' scope = UserStatus.teacher when 'student' scope = UserStatus.student else - end + # unknow scope = scope.in_group(params[:group_id]) if params[:group_id].present? - # scope.each do |user| - # UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id) - # end + + # pagination @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] - #@offset ||= @user_pages.offset - #@users = scope.order(sort_clause).limit(@limit).offset(@offset).all - @user_base_tag = params[:id] ? 'base_users':'base' - if params[:user_sort_type].present? - case params[:user_sort_type] - when '0' - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @users_statuses = scope.offset(@offset).limit(@limit).all.reverse - else - limit = @user_count % @limit - if limit == 0 - limit = @limit - end - @users_statuses = scope.offset(@offset).limit(limit).all.reverse - end - @s_type = 0 - # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } - # @projects = @projects[@offset, @limit] - when '1' - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @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('grade').offset(@offset).limit(limit).all.reverse - end - @s_type = 1 - #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} - #@users = @users[@offset, @limit] - when '2' - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse - else - limit = @user_count % @limit - if limit == 0 - limit = @limit - end - @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse - end - @s_type = 2 - #@users = @users[@offset, @limit] - end + # users classify + case params[:user_sort_type] + when '0' + @s_type = 0 + @us_ordered = scope. + joins("LEFT JOIN users ON user_statuses.user_id = users.id"). + reorder('users.created_on DESC') + when '1' + @s_type = 1 + @us_ordered = scope.reorder('user_statuses.grade DESC') + when '2' + @s_type = 2 + @us_ordered = scope.reorder('user_statuses.watchers_count DESC') else - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @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('grade').offset(@offset).limit(limit).all.reverse - end - @s_type = 1 - # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } - # @projects = @projects[@offset, @limit] - end - - @users = [] - @users_statuses.each do |obj| - @users << User.find_by_id("#{obj.user_id}") + @s_type = 1 + @us_ordered = scope.reorder('user_statuses.grade DESC') end - + + # limit and offset + @users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page) + # get users ActiveRecord + @users = @users_statuses.map(&:user) + @user_base_tag = params[:id] ? 'base_users':'base' respond_to do |format| format.html { @groups = Group.all.sort diff --git a/app/models/user_status.rb b/app/models/user_status.rb index f6dd0c8b6..3b4d38373 100644 --- a/app/models/user_status.rb +++ b/app/models/user_status.rb @@ -1,6 +1,6 @@ class UserStatus < ActiveRecord::Base attr_accessible :changesets_count, :user_id, :watchers_count - belongs_to :users + belongs_to :user belongs_to :watchers belongs_to :changesets validates_presence_of :user_id From e573438e4390451500eba0b93278c46de44411d2 Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 10 Jul 2014 15:39:40 +0800 Subject: [PATCH 2/4] eager_load --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 063d32b84..a3d512b5d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -309,7 +309,7 @@ class UsersController < ApplicationController # limit and offset @users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page) # get users ActiveRecord - @users = @users_statuses.map(&:user) + @users = @users_statuses.includes(:user).map(&:user) @user_base_tag = params[:id] ? 'base_users':'base' respond_to do |format| From 803e9cbdb51e93c1028376320e70cc046ce9c28e Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 10 Jul 2014 16:21:55 +0800 Subject: [PATCH 3/4] =?UTF-8?q?globel=20issue#858,=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E9=AB=98=E6=A0=A1--=E8=BE=93=E5=85=A5=E6=97=A0=E6=95=88?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E7=82=B9=E5=87=BB=E6=90=9C=E7=B4=A2=EF=BC=8C?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE=E7=BB=99=E5=87=BA=E6=8F=90=E7=A4=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/school_controller.rb | 15 ++++++++------- config/locales/en.yml | 1 + config/locales/zh.yml | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 3fb42b64d..8b3692449 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -99,16 +99,17 @@ class SchoolController < ApplicationController def search_school q = "%#{params[:key_word].strip}%" - if params[:province].nil? or params[:province] == "0" - @school = School.where("name LIKE ?", q); - else - @school = School.where("province = ? AND name LIKE ?", params[:province], q); - end + + @school = School.where("name LIKE ?", q) + @school = @school.where("province = ?", params[:province]) if (params[:province] != '0' ) + options = "" @school.each do |s| options << "
  • #{s.name}
  • " end - - render :text => options + + options = "
    #{l(:label_school_not_fount)}
    " if options.blank? + + render :text => options end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 4c177b58e..a23bbfadb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1469,6 +1469,7 @@ en: label_teacher: Teacher label_student: Student label_school_all: Schools + label_school_not_fount: Not found by your input query condition. label_other: Other label_gender: Gender label_gender_male: male diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 1b3774d65..2fe9f754e 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1857,6 +1857,7 @@ zh: #added by Wen label_school_all: 中国高校 + label_school_not_fount: 没有符合的高校信息 label_project_grade: 项目得分 From 056f86caad29ca95632d9da9e1e616cd00e2349a Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 10 Jul 2014 16:41:34 +0800 Subject: [PATCH 4/4] can't download, html. after exception return; --- app/controllers/attachments_controller.rb | 1 + public/file_not_found.html | 55 +++++++++++++++-------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0b2ae02b3..330e1cde6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -61,6 +61,7 @@ class AttachmentsController < ApplicationController end rescue => e redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" + return end #更新资源文件类型 diff --git a/public/file_not_found.html b/public/file_not_found.html index 5b9b8bc1d..c927e13c0 100644 --- a/public/file_not_found.html +++ b/public/file_not_found.html @@ -1,23 +1,40 @@ - + -File not found - + + File not found + + -

    Sorry, this file can not be downloaded now.

    -

    Trustie Team.

    -

    Back

    +
    +

    Sorry, this file can not be downloaded now.

    +

    Goto Home page

    + +
    +
    +

    Trustie Team.

    +
    +
    + +