diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 28156ac0c..0d459e3ba 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -41,8 +41,8 @@ class FilesController < ApplicationController @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset - @curse_attachments_all = @all_attachments[@offset, @limit] - @curse_attachments = paginateHelper @all_attachments,10 + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 end def search @@ -132,16 +132,30 @@ class FilesController < ApplicationController attribute = "downloads" when "created_on" attribute = "created_on" + when "quotes" + attribute = "quotes" end - - if order_by.count == 1 - sort += "#{Attachment.table_name}.#{attribute} asc " if attribute - elsif order_by.count == 2 - sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " if attribute && order_by[1] - end - if sort_type != params[:sort].split(",").last - sort += "," + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end end + # if order_by.count == 1 + # sort += "#{Attachment.table_name}.#{attribute} asc " if attribute + # elsif order_by.count == 2 + # sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " if attribute && order_by[1] + # end + # if sort_type != params[:sort].split(",").last + # sort += "," + # end end end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 2e07421f8..8843b1a76 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -77,6 +77,7 @@ module AttachmentsHelper end end + #判断课程course中是否包含课件attachment,course中引用了attachment也算作包含 def course_contains_attachment? course,attachment course.attachments.each do |att| if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from @@ -85,6 +86,15 @@ module AttachmentsHelper end false end + #判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 + def project_contains_attachment? project,attachment + project.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false + end def get_qute_number attachment if attachment.copy_from diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 884ebc2eb..08b17ea7a 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -66,6 +66,17 @@ module FilesHelper result end + #判断用户是否拥有不包含当前资源的项目,需用户在该项目中有资源管理相关资源 + def has_project? user,file + result = false + user.projects.each do |project| + if !project_contains_attachment?(project,file) && User.current.allowed_to?(:manage_files, project) + return true + end + end + result + end + # 判断指定的资源时候符合类型 def isTypeOk(attachment, type, contentType) result = false diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index ea499477a..b6f65e9b2 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -55,7 +55,7 @@
- <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@curse_attachments} %> + <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
diff --git a/app/views/files/_project_file_list.html.erb b/app/views/files/_project_file_list.html.erb new file mode 100644 index 000000000..60675194b --- /dev/null +++ b/app/views/files/_project_file_list.html.erb @@ -0,0 +1,58 @@ + +
+

共有 <%= all_attachments.count%> 个资源

+

+ <% 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=>"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=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 + <% end %> +

+
+
+
+ <% project_attachments.each do |file| %> +
+
+ <%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %> + <% if User.current.logged? %> + <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && project_contains_attachment?(project,file) %> + <%= link_to(l(:label_slected_to_other_project),quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> + + <% if manage_allowed && file.container_id == project.id && file.container_type == "Project" %> + + <%= link_to (file.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"f_l re_open",:method => :post %> + + <% else %> + + <% end %> + <% else %> + <%= link_to(l(:label_slected_to_project),quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,file) %> + <% end %> + <% else %> + <% end %> +
+
+
+

文件大小:<%= 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 manage_allowed && file.container_id == project.id && file.container_type == "Project"%> +

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

+
+
+
+ <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "10"} %> + <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "10"} %> +
+
+
+ <% end %> +
+ +
\ No newline at end of file diff --git a/app/views/files/_project_file_new.html.erb b/app/views/files/_project_file_new.html.erb new file mode 100644 index 000000000..977a7e5ab --- /dev/null +++ b/app/views/files/_project_file_new.html.erb @@ -0,0 +1,65 @@ + +
+

<%= l(:lable_file_sharingarea) %>

+
+ + + + +
+
+
+ <%#= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search f_l",:remote=>true) do %> + <%#= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%> + <%#= submit_tag "课内搜索", :class => "re_schbtn b_lblue",:name => "incourse",:id => "incourse", :onmouseover => "presscss('incourse')",:onmouseout =>"buttoncss()" %> + <%#= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> + <%# end %> + <% manage_allowed = User.current.allowed_to?(:manage_files, @project) %> + <% if manage_allowed %> + 上传资源 + <% end %> +
+
+ +
+ <%= render :partial => 'project_file_list',:locals => {project: @project,all_attachments: @all_attachments,sort:@sort,order:@order,project_attachments:@obj_attachments,:manage_allowed => manage_allowed} %> +
+ +
+
+<% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 4b6df47cb..aefa1a5a9 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,6 +1,6 @@
<% if @isproject %> - <%= render :partial => 'project_file', locals: {project: @project} %> + <%= render :partial => 'project_file_new', locals: {project: @project} %> <% else %> <%= render :partial => 'course_file', locals: {course: @course} %> <% end %> diff --git a/config/locales/projects/zh.yml b/config/locales/projects/zh.yml index 9f1a95201..bb78fda4d 100644 --- a/config/locales/projects/zh.yml +++ b/config/locales/projects/zh.yml @@ -106,7 +106,8 @@ zh: lable_file_sharingarea: 资源共享区 label_upload_files: 上传文件 - + label_slected_to_other_project: 选入我的其他项目 + label_slected_to_project: 选入我的项目 # 资源库(附件)公用 > 关联资源 label_relation_files: 关联已有资源 diff --git a/db/schema.rb b/db/schema.rb index b149a870b..295b459e6 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 => 20150309090143) do +ActiveRecord::Schema.define(:version => 20150324021043) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -638,16 +638,6 @@ ActiveRecord::Schema.define(:version => 20150309090143) do add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" - create_table "journal_details_copy", :force => true do |t| - t.integer "journal_id", :default => 0, :null => false - t.string "property", :limit => 30, :default => "", :null => false - t.string "prop_key", :limit => 30, :default => "", :null => false - t.text "old_value" - t.text "value" - end - - add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id" - create_table "journal_replies", :id => false, :force => true do |t| t.integer "journal_id" t.integer "user_id" @@ -1069,12 +1059,12 @@ ActiveRecord::Schema.define(:version => 20150309090143) do end create_table "roles", :force => true do |t| - t.string "name", :limit => 90 - t.integer "position" - t.boolean "assignable" - t.integer "builtin" + t.string "name", :limit => 30, :default => "", :null => false + t.integer "position", :default => 1 + t.boolean "assignable", :default => true + t.integer "builtin", :default => 0, :null => false t.text "permissions" - t.string "issues_visibility", :limit => 90 + t.string "issues_visibility", :limit => 30, :default => "default", :null => false end create_table "schools", :force => true do |t|