From 29d4266c6c6ebc93f25ac2adeae7e5d3cdf06266 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 2 Dec 2014 15:30:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BC=95=E7=94=A8=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E7=BB=9F=E8=AE=A1=E4=BF=AE=E6=94=B9=E5=8F=8A=E6=8C=89?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 25 +++++++++++++++---- app/controllers/files_controller.rb | 18 +++++++------ app/helpers/attachments_helper.rb | 13 ++++++++++ app/helpers/files_helper.rb | 13 +--------- app/views/files/_course_list.html.erb | 10 ++++---- ...0141201085218_add_qutoes_to_attachments.rb | 5 ++++ db/schema.rb | 3 ++- 7 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 db/migrate/20141201085218_add_qutoes_to_attachments.rb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 25bb31cbb..2d0eb2b6c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -371,15 +371,30 @@ class AttachmentsController < ApplicationController @obj = c @save_flag = attach_copied_obj.save @save_message = attach_copied_obj.errors.full_messages + update_quotes attach_copied_obj end respond_to do |format| format.js end - rescue NoMethodError - @save_flag = false - @save_message = [] << l(:label_course_empty_select) - respond_to do |format| - format.js + #rescue NoMethodError + # @save_flag = false + # @save_message = [] << l(:label_course_empty_select) + # respond_to do |format| + # format.js + # end + end + + def update_quotes attachment + if attachment.copy_from + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}") + else + attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}") + end + attachment.quotes = get_qute_number attachment + attachment.save + attachments.each do |att| + att.quotes = attachment.quotes + att.save end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c20b5a0de..320c8fc93 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -171,6 +171,8 @@ class FilesController < ApplicationController attribute = "downloads" when "created_on" attribute = "created_on" + when "quotes" + attribute = "quotes" end @sort = order_by[0] @order = order_by[1] @@ -391,14 +393,14 @@ class FilesController < ApplicationController end end - # show_attachments @containers - # @attachtype = params[:type].to_i - # @contenttype = params[:contentType].to_s - # - # respond_to do |format| - # format.js - # format.html - # end + show_attachments @containers + @attachtype = params[:type].to_i + @contenttype = params[:contentType].to_s + + respond_to do |format| + format.js + format.html + end end end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 52002b028..50dd79a08 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -76,6 +76,19 @@ module AttachmentsHelper false end + def get_qute_number attachment + if attachment.copy_from + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") + else + result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") + end + if result.nil? || result.count <= 0 + return 0 + else + return result[0].number + end + end + private def deletable? container, user=User.current diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index e1aebefdc..5683b9a05 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -114,16 +114,5 @@ module FilesHelper end - def get_qute_number attachment - if attachment.copy_from - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}") - else - result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}") - end - if result.nil? || result.count <= 0 - return 0 - else - return result[0].number - end - end + end \ No newline at end of file diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 02dc816b2..58fbcb2e9 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -4,12 +4,12 @@

<% if order == "asc" %> 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> 排序 + <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% else %> 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> 排序 + <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>  /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% end %>

@@ -40,7 +40,7 @@

文件大小:<%= number_to_human_size(file.filesize) %>

<%= link_to( l(:button_delete), attachment_path(file), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> -

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= get_qute_number file %>

+

<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>  |  下载<%= file.downloads %>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

diff --git a/db/migrate/20141201085218_add_qutoes_to_attachments.rb b/db/migrate/20141201085218_add_qutoes_to_attachments.rb new file mode 100644 index 000000000..95a284ab6 --- /dev/null +++ b/db/migrate/20141201085218_add_qutoes_to_attachments.rb @@ -0,0 +1,5 @@ +class AddQutoesToAttachments < ActiveRecord::Migration + def change + add_column("attachments","quotes",:integer) + end +end diff --git a/db/schema.rb b/db/schema.rb index 4baec2343..883dd74c5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20141127072548) do +ActiveRecord::Schema.define(:version => 20141201085218) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -53,6 +53,7 @@ ActiveRecord::Schema.define(:version => 20141127072548) do t.integer "attachtype", :default => 1 t.integer "is_public", :default => 1 t.integer "copy_from" + t.integer "quotes" end add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id" From 78ba3abc237bde63a2eeae33d60a13bc02b0cb24 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 2 Dec 2014 15:34:30 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=BA=E9=80=89=E6=8B=A9=E8=AF=BE=E7=A8=8B=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2d0eb2b6c..111ec2cca 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -376,12 +376,12 @@ class AttachmentsController < ApplicationController respond_to do |format| format.js end - #rescue NoMethodError - # @save_flag = false - # @save_message = [] << l(:label_course_empty_select) - # respond_to do |format| - # format.js - # end + rescue NoMethodError + @save_flag = false + @save_message = [] << l(:label_course_empty_select) + respond_to do |format| + format.js + end end def update_quotes attachment From 2fdc6ff9880de3ed20e5911cf54de77154f6ed71 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 2 Dec 2014 15:41:10 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=85=A8=E7=AB=99=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E6=9E=9C=E4=B8=AD=E4=B8=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BC=95=E7=94=A8=E7=9A=84=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 320c8fc93..1ed40f691 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -93,7 +93,7 @@ class FilesController < ApplicationController if sort == "" sort = "created_on DESC" end - resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). + resultSet = Attachment.where("attachments.container_type IS NOT NULL AND attachments.copy_from IS NULL AND filename LIKE :like ", like: "%#{keywords}%"). reorder(sort) end From d8e9dba40427358ae5bfd8f8a12f766461f07876 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 2 Dec 2014 16:25:49 +0800 Subject: [PATCH 4/4] =?UTF-8?q?#1647=20=E6=AD=A3=E5=BC=8F=E7=89=88--?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=90=9C=E7=B4=A2=E7=AA=97=E5=8F=A3=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=BF=94=E5=9B=9E500=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=88=E8=B5=84=E6=BA=90=E5=8F=AF=E8=A7=81=E6=80=A7=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E4=BF=AE=E5=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 4 ++-- lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index 6bb7a75d4..05b96414b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ActiveRecord::Base STATUS_ARCHIVED = 9 attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student - belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier + #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 has_many :bid @@ -31,7 +31,7 @@ class Course < ActiveRecord::Base acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy - acts_as_attachable :view_permission => :view_files, + acts_as_attachable :view_permission => :view_course_files, :delete_permission => :manage_files validates_presence_of :password, :term,:name,:description 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 609b35415..377f2b112 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -46,6 +46,9 @@ module Redmine if self.respond_to?(:project) (respond_to?(:visible?) ? visible?(user) : true) && user.allowed_to?(self.class.attachable_options[:view_permission], self.project) + elsif self.is_a?(Course) + (respond_to?(:visible?) ? visible?(user) : true) && + user.allowed_to?(self.class.attachable_options[:view_permission], self) else return true end