From a5d829b95ef320184497a65f8dd15a11f86e39ab Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 22 Jul 2014 16:49:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A8=A1=E5=9D=97=202.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 +++- app/controllers/news_controller.rb | 10 ++++++---- .../acts_as_attachable/lib/acts_as_attachable.rb | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index bef128e50..f1fc1fc15 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -172,7 +172,7 @@ class AttachmentsController < ApplicationController respond_to do |format| # modify by nwb - if @attachment.container_type == 'Course' + if @attachment.container.is_a?(Course) || @attachment.container.course if @course.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } else @@ -285,6 +285,8 @@ private raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename if @attachment.container_type == 'Course' @course = @attachment.course + elsif @attachment.container.course + @course = @attachment.container.course else unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' @project = @attachment.project diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 8bce84f90..650f65555 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -98,10 +98,12 @@ class NewsController < ApplicationController end def new - @news = News.new(:project => @project, :author => User.current) - @course_tag = @project.project_type - if @course_tag - render :layout => 'base_courses' + #modify by nwb + if @project + @news = News.new(:project => @project, :author => User.current) + elsif @course + @news = News.new(:course => @course, :author => User.current) + render :layout => 'base_courses' end end diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index 1318f8afa..8b368ab1e 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -83,6 +83,12 @@ module Redmine end def save_attachments(attachments, author=User.current) + # 清除临时文件 + tempAttach = attachments[:dummy] + if tempAttach && tempAttach[:file] + attachments.delete(:dummy) + end + if attachments.is_a?(Hash) attachments = attachments.stringify_keys attachments = attachments.to_a.sort {|a, b| From cccbd941cec3589fb2a50d686e7a62d5f16986ce Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 22 Jul 2014 17:17:23 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8E=BB=E6=8E=92=E5=BA=8F=EF=BC=8C=E5=88=A0=E9=99=A4=E5=90=8E?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=EF=BC=8C=E5=8E=BB=E6=97=A0=E6=95=88=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 111 ++-------------------------- app/controllers/users_controller.rb | 2 +- app/views/admin/search.html.erb | 6 +- app/views/admin/users.html.erb | 6 +- 4 files changed, 15 insertions(+), 110 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 05045ab12..1ed1581d1 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -36,15 +36,12 @@ class AdminController < ApplicationController scope = Project.status(@status).order('lft') scope = scope.like(params[:name]) if params[:name].present? - @projects = scope.all + @projects = scope.where(project_type: Project::ProjectType_project).all render :action => "projects", :layout => false if request.xhr? end def users - @project_type = params[:project_type] - role = params[:role] - sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) @@ -56,95 +53,14 @@ class AdminController < ApplicationController 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 - - scope = UserStatus.visible - case role - when 'teacher' - scope = UserStatus.teacher - when 'student' - scope = UserStatus.student - else - - end - + scope = User.logged.status(@status) + scope = User.like(params[:name]) if params[:name].present? 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 + @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 - - 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}") - end + @offset ||= @user_pages.offset + @users = scope.order(sort_clause).limit(@limit).offset(@offset).all respond_to do |format| @@ -209,24 +125,13 @@ class AdminController < ApplicationController end @status = params[:status] || 1 - has = { - "show_changesets" => true - } scope = User.logged.status(@status) scope = scope.like(params[:name]) if params[:name].present? @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] @user_base_tag = params[:id] ? 'base_users':'base' - @offset ||= @user_pages.reverse_offset - unless @offset == 0 - @users = scope.offset(@offset).limit(@limit).all.reverse - else - limit = @user_count % @limit - if limit == 0 - limit = @limit - end - @users = scope.offset(@offset).limit(limit).all.reverse - end + + @users = scope.offset(@user_pages.offset).limit(@user_pages.per_page) respond_to do |format| format.html { diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0ca810cbe..c1f8bba97 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -586,7 +586,7 @@ class UsersController < ApplicationController def destroy @user.destroy respond_to do |format| - format.html { redirect_back_or_default(users_path) } + format.html { redirect_back_or_default(admin_users_path) } format.api { render_api_ok } end end diff --git a/app/views/admin/search.html.erb b/app/views/admin/search.html.erb index 17d91e78b..67c97366e 100644 --- a/app/views/admin/search.html.erb +++ b/app/views/admin/search.html.erb @@ -5,7 +5,7 @@

<%= l(:label_user_plural)%>

- <%= form_tag(:controller => 'admin', :action => 'search', :method => :get) do %> + <%= form_tag(:controller => 'admin', :action => 'search') do %>
<%= l(:label_filter_plural) %> @@ -51,7 +51,7 @@ <%= format_time(user.created_on) %> <%= format_time(user.last_login_on) unless user.last_login_on.nil? %> <%= change_status_link(user) %> - <%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %> + <%= delete_link user_path(user, :back_url => admin_users_path(params)) unless User.current == user %> <% end -%> @@ -65,4 +65,4 @@ <% html_title(l(:label_user_plural)) -%> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/admin/users.html.erb b/app/views/admin/users.html.erb index 4dceb5fd9..41df178d8 100644 --- a/app/views/admin/users.html.erb +++ b/app/views/admin/users.html.erb @@ -5,7 +5,7 @@

<%= l(:label_user_plural)%>

- <%= form_tag(:controller => 'admin', :action => 'search', :method => :get) do %> + <%= form_tag(:controller => 'admin', :action => 'search') do %>
<%= l(:label_filter_plural) %> @@ -51,7 +51,7 @@ <%= format_time(user.created_on) %> <%= format_time(user.last_login_on) unless user.last_login_on.nil? %> <%= change_status_link(user) %> - <%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %> + <%= delete_link user_path(user, :back_url => admin_users_path(params)) unless User.current == user %> <% end -%> @@ -66,4 +66,4 @@ <% html_title(l(:label_user_plural)) -%> <%else %> -<% end%> \ No newline at end of file +<% end%> From 18d096f0d88353a51f1894add15a35b225322ca0 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 22 Jul 2014 17:40:32 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=AB=9E=E8=B5=9B=E8=A1=A8project=5Fid=E4=BC=9A?= =?UTF-8?q?=E7=BD=AE=E7=A9=BA=EF=BC=8Cprojecting=5Fsoftapplications?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=8D=E7=9F=A5=E9=81=93=E5=B9=B2=E5=98=9B?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E6=AD=A4=E8=A1=A8=E4=B9=9F=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softapplications_controller.rb | 26 +++++++++---------- app/models/softapplication.rb | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index d7b2477a8..1808a3eaa 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -19,20 +19,20 @@ class SoftapplicationsController < ApplicationController #new added sort if params[:softapplication_sort_type].present? - case params[:softapplication_sort_type] + case params[:softapplication_sort_type] when '0' - @softapplications = @softapplications[@offset, @limit] + @softapplications = @softapplications[@offset, @limit] @s_state = 0 when '1' - @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] + @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] @s_state = 1 end - else - @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] - @s_state = 1 + else + @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit] + @s_state = 1 end #new added end - + respond_to do |format| format.html # index.html.erb format.json { render json: @softapplications } @@ -216,19 +216,19 @@ class SoftapplicationsController < ApplicationController def new_message @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] if @jour - user = @jour.user - text = @jour.notes + user = @jour.user + text = @jour.notes else - user = @softapplication.user - text = @softapplication.description + user = @softapplication.user + text = @softapplication.description end text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> " @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" @id = user.id - rescue ActiveRecord::RecordNotFound + rescue ActiveRecord::RecordNotFound render_404 - end + end #新建评价 def create_message diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index f7eed43fc..770d70d53 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -10,7 +10,6 @@ class Softapplication < ActiveRecord::Base belongs_to :user belongs_to :project has_many :contests, :through => :contesting_softapplications - belongs_to :project def add_jour(user, notes, reference_user_id = 0, options = {}) if options.count == 0 From ee95d9b115b277d74aeccfc1f5ef3253f1ae6736 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 22 Jul 2014 17:57:11 +0800 Subject: [PATCH 4/5] user_activity page --- 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 c1f8bba97..a3bb96aa9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -151,7 +151,7 @@ class UsersController < ApplicationController # added by fq def user_activities - redirect_to user_path(@user, type: params[:type]) + redirect_to user_path(@user, type: params[:type], page: params[:page]) return # useless abort. @watcher = User.watched_by_id(@user) From 5d22bc551096e52c0a7eb7b4b9e416e82d02ff9c Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 23 Jul 2014 08:43:23 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 +- lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b5c67478c..a8ba3d426 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -163,7 +163,7 @@ class FilesController < ApplicationController end end - # 返回制定资源类型的资源列表 + # 返回指定资源类型的资源列表 # added by nwb def getattachtype sort_init 'created_on', 'desc' diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index 8b368ab1e..b9e6174ae 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -84,9 +84,11 @@ module Redmine def save_attachments(attachments, author=User.current) # 清除临时文件 - tempAttach = attachments[:dummy] - if tempAttach && tempAttach[:file] - attachments.delete(:dummy) + if attachments + tempAttach = attachments[:dummy] + if tempAttach && tempAttach[:file] + attachments.delete(:dummy) + end end if attachments.is_a?(Hash)