diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 36dd61105..f00cbb03d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -26,6 +26,7 @@ class AttachmentsController < ApplicationController accept_api_auth :show, :download, :upload require 'iconv' + def show respond_to do |format| format.html { @@ -41,6 +42,13 @@ class AttachmentsController < ApplicationController render :action => 'diff' elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte @content = File.new(@attachment.diskfile, "rb").read + # 编码为非 UTF-8先进行间接转码 + # 部分unicode编码不直接支持转为 UTF-8 + # modify by nwb + if @content.encoding.name != 'UTF-8' + @content = @content.force_encoding('GBK') + @content = @content.encode('UTF-8') + end render :action => 'file' else download @@ -173,7 +181,7 @@ class AttachmentsController < ApplicationController respond_to do |format| # modify by nwb - if !@attachment.container.nil? && (@attachment.container.is_a?(Course) || @attachment.container.course) + if !@attachment.container.nil? && (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) &&(@attachment.container.is_a?(Course) || @attachment.container.course) if @attachment.container.is_a?(News) format.html { redirect_to_referer_or news_path(@attachment.container) } elsif @course.nil? @@ -235,6 +243,9 @@ class AttachmentsController < ApplicationController attach_copied_obj.container = obj attach_copied_obj.created_on = Time.now attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end @obj = obj @save_flag = attach_copied_obj.save @save_message = attach_copied_obj.errors.full_messages @@ -264,6 +275,9 @@ class AttachmentsController < ApplicationController attach_copied_obj.container = obj attach_copied_obj.created_on = Time.now attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end @obj = obj @save_flag = attach_copied_obj.save @save_message = attach_copied_obj.errors.full_messages diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index eedb29329..15a26fbae 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -747,7 +747,7 @@ class ProjectsController < ApplicationController def update @project.safe_attributes = params[:project] - @project.dts_test = params[:project][:dts_test] + #@project.dts_test = params[:project][:dts_test] if validate_parent_id && @project.save @course = Course.find_by_extra(@project.identifier) unless @course.nil? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3bb96aa9..1d5dd65eb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -263,9 +263,6 @@ class UsersController < ApplicationController 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}) @@ -274,16 +271,9 @@ class UsersController < ApplicationController end # retrieve all users - scope = UserStatus.visible - - # if role has something, change scope. - case params[:role] - when 'teacher' - scope = UserStatus.teacher - when 'student' - scope = UserStatus.student - else - end + # 先内连一下statuses 保证排序之后数量一致 + scope = User.visible. + joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id") # unknow scope = scope.in_group(params[:group_id]) if params[:group_id].present? @@ -295,25 +285,32 @@ class UsersController < ApplicationController # 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') + @users = scope.reorder('users.created_on DESC') when '1' + # 活跃度排序, 就是所谓的得分情况 @s_type = 1 - @us_ordered = scope.reorder('user_statuses.grade DESC') + @users = scope. + joins("LEFT JOIN user_scores ON users.id = user_scores.user_id"). + reorder('user_scores.active DESC') when '2' + # 粉丝数排序 @s_type = 2 - @us_ordered = scope.reorder('user_statuses.watchers_count DESC') + @users = scope. + #joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id"). + reorder('user_statuses.watchers_count DESC') + else + # 默认活跃度排序 @s_type = 1 - @us_ordered = scope.reorder('user_statuses.grade DESC') + @users = scope. + joins("LEFT JOIN user_scores ON users.id = user_scores.user_id"). + reorder('user_scores.active DESC') end # limit and offset - @users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page) - # get users ActiveRecord - @users = @users_statuses.includes(:user).map(&:user) + @users = @users.limit(@user_pages.per_page).offset(@user_pages.offset) @user_base_tag = params[:id] ? 'base_users':'users_base' respond_to do |format| diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index f5781b26a..47a87f441 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -15,9 +15,11 @@

<%= f.check_box :is_public, :style => "margin-left:10px;" %>

<%= f.check_box :hidden_repo, :style => "margin-left:10px;" %>

+

<%= f.text_field :project_type, :value => 0 %>

<%= wikitoolbar_for 'project_description' %> diff --git a/app/views/projects/_tools_expand.html.erb b/app/views/projects/_tools_expand.html.erb index 5ee70fa9d..df6cd481b 100644 --- a/app/views/projects/_tools_expand.html.erb +++ b/app/views/projects/_tools_expand.html.erb @@ -16,7 +16,7 @@
  • <%= link_to l(:project_module_gantt) ,project_gantt_path(@project) %>