diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 3c815c7d8..a57b5f8a5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -141,6 +141,23 @@ class AttachmentsController < ApplicationController end end + def update_file_dense + @attachment = Attachment.find(params[:attachmentid]) + if @attachment != nil + filedense = params[:newtype].to_s + if filedense == "1" + @attachment.is_public = 1 + else + @attachment.is_public = 0 + end + @attachment.save + @newfiledense = filedense + end + respond_to do |format| + format.js + end + end + def thumbnail if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size]) if stale?(:etag => thumbnail) @@ -326,6 +343,35 @@ class AttachmentsController < ApplicationController end end + def add_exist_file_to_courses + file = Attachment.find(params[:file_id]) + courses = params[:courses][:course] + courses.each do |course| + c = Course.find(course); + attach_copied_obj = file.copy + attach_copied_obj.tag_list.add(file.tag_list) # tag关联 + attach_copied_obj.container = c + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + @obj = c + @save_flag = attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + end + respond_to do |format| + format.js + end + rescue NoMethodError + @save_flag = false + @save_message = [] << l(:error_attachment_empty) + respond_to do |format| + format.js + end + end + private def find_project @attachment = Attachment.find(params[:id]) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 91176efdf..ca7f8e040 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -22,22 +22,55 @@ class FilesController < ApplicationController menu_item :files before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] helper :sort include SortHelper helper :project_score def show_attachments obj - all_attachments = [] + @all_attachments = [] obj.each do |container| - all_attachments += container.attachments + @all_attachments += container.attachments end @limit = 10 - @feedback_count = all_attachments.count + @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset - @curse_attachments = all_attachments[@offset, @limit] + @curse_attachments_all = @all_attachments[@offset, @limit] + @curse_attachments = paginateHelper @all_attachments,10 + end + + def search + begin + @is_remote = true + q = "%#{params[:name].strip}%" + #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + if params[:insite] + @result = find_public_attache q + @searched_attach = paginateHelper @result,10 + else + @result = find_course_attache q,@course + @searched_attach = paginateHelper @result,10 + end + + rescue Exception => e + #render 'stores' + redirect_to stores_url + end + end + + def find_course_attache keywords,course + resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%"). + reorder("created_on DESC") + end + + def find_public_attache keywords + # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map + # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。 + # 现在还木有思路 药丸 + resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). + reorder("created_on DESC") end def index @@ -48,7 +81,9 @@ class FilesController < ApplicationController 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" sort = "" - + @sort = "" + @order = "" + @is_remote = false if params[:project_id] @isproject = true @@ -113,7 +148,8 @@ class FilesController < ApplicationController when "created_on" attribute = "created_on" end - + @sort = order_by[0] + @order = order_by[1] if order_by.count == 1 sort += "#{Attachment.table_name}.#{attribute} asc " elsif order_by.count == 2 @@ -134,6 +170,10 @@ class FilesController < ApplicationController end + def quote_resource_show + @file = Attachment.find(params[:id]) + end + def new @versions = @project.versions.sort @course_tag = @project.project_type diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index b64c18b33..5bd5fb0e3 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -14,12 +14,14 @@ class TagsController < ApplicationController include AttachmentsHelper include ContestsHelper include ActsAsTaggableOn::TagsHelper + include TagsHelper helper :projects helper :courses helper :tags include OpenSourceProjectsHelper before_filter :require_admin,:only => [:delete,:show_all] + before_filter :require_login,:only => [:tag_save] # $selected_tags = Array.new # $related_tags = Array.new @@ -187,6 +189,83 @@ class TagsController < ApplicationController # end end end + + # 只删除某个对象的该tag + def remove_tag_new + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + # end + end + end + + def tag_save + @tags = params[:tag_for_save][:name] + @obj_id = params[:tag_for_save][:object_id] + @obj_flag = params[:tag_for_save][:object_flag] + + case @obj_flag + when '1' then + @obj = User.find_by_id(@obj_id) + when '2' then + @obj = Project.find_by_id(@obj_id) + when '3' then + @obj = Issue.find_by_id(@obj_id) + when '4' then + @obj = Bid.find_by_id(@obj_id) + when '5' then + @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) + when '7' then + @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) + when '9' + @obj = Course.find_by_id(@obj_id) + else + @obj = nil + end + unless @obj.nil? + @obj.tag_list.add(@tags.split(",")) + else + return + end + if @obj.save + logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" + else + logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" + end + respond_to do |format| + format.js + format.html + end + end private # 这里用来刷新搜索结果的区域 @@ -307,5 +386,7 @@ class TagsController < ApplicationController return end end + + end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 7ea49dad2..3c882d393 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -177,6 +177,8 @@ module AttachmentsHelper s.html_safe end + + # Modified by Longjun # 有参数的方法要加() def private_filter(resultSet) diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 052aae468..9a0a1127f 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -44,6 +44,16 @@ module FilesHelper File.new(zipfile_name,'w+') end + def courses_check_box_tags(name,courses,current_course) + s = '' + courses.each do |course| + if course.id != current_course.id && is_course_teacher(User.current,course) + s << "
" + end + end + s.html_safe + end + # 判断指定的资源时候符合类型 def isTypeOk(attachment, type, contentType) result = false diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb new file mode 100644 index 000000000..23761647f --- /dev/null +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -0,0 +1,5 @@ +<% if !@save_flag%> + $("#error_show").html("<%= @save_message.join(', ') %>"); +<% else %> + closeModal(); +<% end %> diff --git a/app/views/attachments/update_file_dense.js.erb b/app/views/attachments/update_file_dense.js.erb new file mode 100644 index 000000000..d99481d08 --- /dev/null +++ b/app/views/attachments/update_file_dense.js.erb @@ -0,0 +1,2 @@ +$("#is_public_<%= @attachment.id %>").html("<%= escape_javascript(link_to (@attachment.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>@attachment.id,:newtype=>(@attachment.is_public? ? 0:1)), + :remote=>true,:class=>"f_l re_open",:method => :post) %>"); diff --git a/app/views/files/_arrow_show.erb b/app/views/files/_arrow_show.erb new file mode 100644 index 000000000..d8f094719 --- /dev/null +++ b/app/views/files/_arrow_show.erb @@ -0,0 +1,10 @@ + +<% if sort == current %> + <% if order =="asc" %> + ↑ + <% elsif order == "desc" %> + ↓ + <% else %> + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb new file mode 100644 index 000000000..f65ba8d41 --- /dev/null +++ b/app/views/files/_attachement_list.html.erb @@ -0,0 +1,46 @@ +
+ +<% if defined?(container) && container && container.saved_attachments %> + <% container.attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + <%= l(:field_is_public)%>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%> + <%= if attachment.id.nil? + #待补充代码 + else + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') + end + %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + + <% end %> +<% end %> + +
+ + +<%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => 'file_selector', + :multiple => true, + :onchange => 'addInputFiles(this);', + :style => 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description) + } %> + + \ No newline at end of file diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 46a954746..49747ae11 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -2,84 +2,43 @@ <% sufixtypes = @course.contenttypes %> -<%= t(:label_user_course) %>资源共享区 - -
- - <%#= link_to(l(:label_attachment_new), 'javascript:void(0);', :onclick=>"$('#file_buttons').slideToggle();", :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @course) %> -
-
- - <%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @course) %> - <%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @course) %> -

- - - - -
-
- - <% if attachmenttypes.any? %> -       - - <%= select_tag "attachment_browse", content_tag(:option, l(:attachment_all), :value => '0' ) +options_from_collection_for_select(attachmenttypes, "id", "typeName", params[:type]), - - :onchange => "course_attachmenttypes_searchex(this.value)" %> - <% end %> - <% if sufixtypes.any? %> -   - - <%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes), - :onchange => "course_attachment_contenttypes_searchex(this.value)" %> - <% end %> -
+<%= stylesheet_link_tag 'resource', :media => 'all' %> + + +
+
+
+ <%= 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_dblue",:name => "incourse"%> + <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite" %> + <% end %> + <% if is_course_teacher(User.current,@course) %> + 上传资源 + <% end %> +
+
+ +
+<%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@curse_attachments} %> +
-<%= javascript_tag "observeSearchfield('attach_search', null, '#{ escape_javascript attachments_autocomplete_path(:course_id => @course.id, :format => 'js') }')" %> - -<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> - -
- <%#= render :partial => 'course_show_all_attachment' %> - <% if (@attachtype==0 && @contenttype=='0') || (@attachtype.nil? && @contenttype.nil?) %> - - <%= render partial: "course_show_all_attachment"%> - - <%else%> - - <%= render partial: "course_sort_by_attachtypel"%> - - <%end%>
- <% html_title(l(:label_attachment_plural)) -%> \ No newline at end of file diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb new file mode 100644 index 000000000..554a3aea5 --- /dev/null +++ b/app/views/files/_course_list.html.erb @@ -0,0 +1,51 @@ +<% delete_allowed = User.current.allowed_to?(:manage_files, course) %> +
+

共有 <%= User.current.member_of_course?(course) ? all_attachments.count : 0 %> 个资源

+ +
+
+<% curse_attachments.each do |file| %> + <%if file.is_public == 0 && !User.current.member_of_course?(@course)%> + <%next%> + <%end%> +
+
+ <%= link_to_attachment file, :download => true, :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 is_course_teacher(User.current,@course) %> + <%= link_to "选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true %> + + <%= 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 %> + <%= link_to (file.is_public? ? "公开":"私有"),"javascript:void(0)",:class=>"f_l re_open" %> + <% 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 delete_allowed %> +

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

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

将此课件引入我的课程资源库

+
+ <%= form_tag course_attach_relations_path, + method: :post, + remote: true, + id: "relation_file_form" do %> + <%= hidden_field_tag(:file_id, file.id) %> + <%= content_tag('div', courses_check_box_tags('courses[course][]', User.current.courses,course), :id => 'courses')%> + 引  用取  消 + <% end -%> +
+ +
+
+ + \ No newline at end of file diff --git a/app/views/files/_upload_show.html.erb b/app/views/files/_upload_show.html.erb new file mode 100644 index 000000000..a979715de --- /dev/null +++ b/app/views/files/_upload_show.html.erb @@ -0,0 +1,26 @@ +
+
+

上传资源

+
+ <%= error_messages_for 'attachment' %> + + <%= form_tag(course_files_path(course), :multipart => true,:remote => true,:method => :post,:name=>"upload_form") do %> + + <%= render :partial => 'attachement_list',:locals => {:course => course} %> +
+ 上传资源取  消 + <% end %> +
+ +
+ <% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> + <% end %> +
+ + \ No newline at end of file diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb index 0eca9c1ed..90215c16c 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -27,6 +27,8 @@ $('#upload_file_div').slideToggle('slow'); $("#all_browse_div").html('<%= j(render partial: "show_all_attachment")%>'); <%elsif @course%> $("#all_browse_div").html('<%= j(render partial: "course_show_all_attachment")%>'); +closeModal(); +$("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); <%end%> <% end %> diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 69b41fc28..fe04c4e3f 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,10 +1,11 @@ +
<% if @isproject %> <%= render :partial => 'project_file', locals: {project: @project} %> <% else %> <%= render :partial => 'course_file', locals: {course: @course} %> <% end %> - +