From 5eac7275849c626e13823f3e7413a29bc4bf5f9c Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 31 Mar 2015 15:57:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=B5=84=E6=BA=90=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90=EF=BC=88=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=B0=9A=E6=9C=AA=E8=B0=83=E6=95=B4=EF=BC=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=B0=9A=E6=9C=AA=E5=BA=94=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 40 ++++++++++ app/controllers/files_controller.rb | 60 ++++++++++++++- app/helpers/files_helper.rb | 31 ++++++-- .../add_exist_file_to_projects.js.erb | 7 ++ app/views/files/_project_file_list.html.erb | 4 +- app/views/files/_project_file_new.html.erb | 76 +++++++++---------- .../_show_quote_resource_project.html.erb | 31 ++++++++ app/views/files/_upload_show_project.html.erb | 29 +++++++ app/views/files/create.js.erb | 50 ++++++------ .../files/quote_resource_show_project.js.erb | 11 +++ app/views/files/search_project.js.erb | 1 + config/locales/zh.yml | 1 + config/routes.rb | 5 ++ 13 files changed, 274 insertions(+), 72 deletions(-) create mode 100644 app/views/attachments/add_exist_file_to_projects.js.erb create mode 100644 app/views/files/_show_quote_resource_project.html.erb create mode 100644 app/views/files/_upload_show_project.html.erb create mode 100644 app/views/files/quote_resource_show_project.js.erb create mode 100644 app/views/files/search_project.js.erb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index ddda15ce7..d880ebe35 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -320,6 +320,46 @@ class AttachmentsController < ApplicationController end end + def add_exist_file_to_projects + file = Attachment.find(params[:file_id]) + projects = params[:projects][:project] + @message = "" + projects.each do |project| + c = Project.find(project); + if project_contains_attachment?(c,file) + if @message && @message == "" + @message += l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + else + @message += "
" + l(:label_project_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end + end + 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 + 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 + end + end + def add_exist_file_to_courses file = Attachment.find(params[:file_id]) courses = params[:courses][:course] diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 4a6daf77a..b48569f2c 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,7 +23,7 @@ class FilesController < ApplicationController before_filter :auth_login1, :only => [:index] before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] - before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] + before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:search_project,:quote_resource_show_project] helper :sort include SortHelper @@ -79,6 +79,39 @@ class FilesController < ApplicationController end end + def search_project + sort = "" + @sort = "" + @order = "" + @is_remote = true + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] + end + sort = "#{@sort} #{@order}" + end + + begin + 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,sort + @result = visable_attachemnts_insite @result,@project + @searched_attach = paginateHelper @result,10 + else + @result = find_project_attache q,@project,sort + @result = visable_attachemnts @result + @searched_attach = paginateHelper @result,10 + end + + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url + end + end + def find_course_attache keywords,course,sort = "" if sort == "" sort = "created_on DESC" @@ -88,6 +121,26 @@ class FilesController < ApplicationController #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") end + def find_project_attache keywords,project,sort = "" + if sort == "" + sort = "created_on DESC" + end + ids = "" + len = 0 + count = project.versions.count + project.versions.each do |version| + len = len + 1 + if len != count + ids += version.id.to_s + ',' + else + ids += version.id.to_s + end + end + resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%"). + reorder(sort) + #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC") + end + def find_public_attache keywords,sort = "" # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。 @@ -230,6 +283,11 @@ class FilesController < ApplicationController @can_quote = attachment_candown @file end + def quote_resource_show_project + @file = Attachment.find(params[:id]) + @can_quote = attachment_candown @file + end + def new @versions = @project.versions.sort @course_tag = @project.project_type diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 02699f6aa..3c8ed63d4 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -45,6 +45,7 @@ module FilesHelper File.new(zipfile_name,'w+') end + #带勾选框的课程列表 def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| @@ -55,6 +56,17 @@ module FilesHelper s.html_safe end + #带勾选框的项目列表 + def projects_check_box_tags(name,projects,current_project,attachment) + s = '' + projects.each do |project| + if !project_contains_attachment?(project,attachment) && User.current.allowed_to?(:manage_files, project) + s << "" + end + end + s.html_safe + end + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user,file result = false @@ -108,14 +120,23 @@ module FilesHelper result end - def visable_attachemnts_insite attachments,course + def visable_attachemnts_insite attachments,obj result = [] - attachments.each do |attachment| - if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id - result << attachment + if obj.is_a?(Course) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == obj.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end end + else if obj.is_a?(Project) + attachments.each do |attachment| + if attachment.is_public? || (attachment.container_type == "Project" && attachment.container_id == obj.id && User.current.member_of_course?(Project.find(attachment.container_id)))|| attachment.author_id == User.current.id + result << attachment + end + end end - result + end + result end diff --git a/app/views/attachments/add_exist_file_to_projects.js.erb b/app/views/attachments/add_exist_file_to_projects.js.erb new file mode 100644 index 000000000..88f45e2cf --- /dev/null +++ b/app/views/attachments/add_exist_file_to_projects.js.erb @@ -0,0 +1,7 @@ +<% if !@save_flag && @save_message %> +$("#error_show").html("<%= @save_message.join(', ') %>"); +<% elsif @message && @message != "" %> +$("#error_show").html("<%= @message.html_safe %>"); +<% else %> +closeModal(); +<% end %> \ No newline at end of file diff --git a/app/views/files/_project_file_list.html.erb b/app/views/files/_project_file_list.html.erb index 42c454965..c7e0cec29 100644 --- a/app/views/files/_project_file_list.html.erb +++ b/app/views/files/_project_file_list.html.erb @@ -21,7 +21,7 @@ <%= 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 (manage_allowed || 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(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> + <%= link_to(l(:label_slected_to_other_project),quote_resource_show_project_project_file_path(project,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" %> @@ -31,7 +31,7 @@ <% 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) %> + <%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> <% end %> <% else %> <% end %> diff --git a/app/views/files/_project_file_new.html.erb b/app/views/files/_project_file_new.html.erb index 977a7e5ab..89088a295 100644 --- a/app/views/files/_project_file_new.html.erb +++ b/app/views/files/_project_file_new.html.erb @@ -5,50 +5,50 @@
- <%#= 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 %> + <%= form_tag( search_project_project_files_path(@project), 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 %> 上传资源 diff --git a/app/views/files/_show_quote_resource_project.html.erb b/app/views/files/_show_quote_resource_project.html.erb new file mode 100644 index 000000000..7df1dc2f3 --- /dev/null +++ b/app/views/files/_show_quote_resource_project.html.erb @@ -0,0 +1,31 @@ +
+
+

将此课件引入我的资源库

+ <% if error == '403' %> +
+
您没有权限引用此资源
+
+ <% else %> +
+
+ <%= form_tag attach_relations_path, + method: :post, + remote: true, + id: "relation_file_form" do %> + <%= hidden_field_tag(:file_id, file.id) %> + <%= content_tag('div', projects_check_box_tags('projects[project][]', User.current.projects,project,file), :id => 'projects')%> + 引  用取  消 + <% end -%> +
+ <% end %> + + +
+
+ + \ No newline at end of file diff --git a/app/views/files/_upload_show_project.html.erb b/app/views/files/_upload_show_project.html.erb new file mode 100644 index 000000000..25a03b347 --- /dev/null +++ b/app/views/files/_upload_show_project.html.erb @@ -0,0 +1,29 @@ + +
+
+

<%= l(:label_upload_files)%>

+
+ <%= error_messages_for 'attachment' %> + + + <%= form_tag(project_files_path(project), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> + + <%= render :partial => 'attachement_list',:locals => {:project => project} %> +
+ <%= l(:button_cancel)%> + <%= l(:button_confirm)%> + <% 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 69ea896c9..b00ae3612 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -1,35 +1,33 @@ -<%if @addTag%> -<% if @obj_flag == '3'%> - -$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', +<% if @addTag%> + <% if @obj_flag == '3'%> + $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -//$('#put-tag-form-issue').hide(); -$('#name-issue').val(""); -<% elsif @obj_flag == '6'%> -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', + //$('#put-tag-form-issue').hide(); + $('#name-issue').val(""); + <% elsif @obj_flag == '6'%> + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -$("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); -$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); -<% else %> - -$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', + $("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); + $("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); + <% else %> + $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -$('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); -$('#put-tag-form #name').val(""); -//$('#put-tag-form').hide(); -<% end %> -<%else%> + $('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); + $('#put-tag-form #name').val(""); + //$('#put-tag-form').hide(); + <% end %> +<% else %> $("#attachments_fields").children().remove(); $("#upload_file_count").text("未上传文件"); $('#upload_file_div').slideToggle('slow'); -<%if @project%> -$("#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%> + <% if @project%> + closeModal(); + $("#resource_list").html('<%= j(render partial: "project_file_new" ,locals: {project: @project}) %>'); + <%elsif @course%> + closeModal(); + $("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); + <% end %> <% end %> $(document).ready(img_thumbnails); diff --git a/app/views/files/quote_resource_show_project.js.erb b/app/views/files/quote_resource_show_project.js.erb new file mode 100644 index 000000000..440004357 --- /dev/null +++ b/app/views/files/quote_resource_show_project.js.erb @@ -0,0 +1,11 @@ +<% if @can_quote %> + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_project',:locals => {:project => @project,:file => @file,:error => ''}) %>'); +<% else %> + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_project',:locals => {:project => @project,:file => @file,:error => '403'}) %>'); +<% end %> + +showModal('ajax-modal', '513px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/files/search_project.js.erb b/app/views/files/search_project.js.erb new file mode 100644 index 000000000..f64b8beeb --- /dev/null +++ b/app/views/files/search_project.js.erb @@ -0,0 +1 @@ +$("#course_list").html("<%= escape_javascript(render :partial => 'project_file_list',:locals => {project: @project,all_attachments: @result,sort:@sort,order:@order,project_attachments:@searched_attach,:manage_allowed => User.current.allowed_to?(:manage_files, @project)})%>"); \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index f1dbe7d3c..3c8bb5a6d 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1966,6 +1966,7 @@ zh: field_open_anonymous_evaluation: 是否使用匿评 label_course_empty_select: 尚未选择课程! label_course_prompt: 课程: + label_project_prompt: 项目: label_contain_resource: 已包含资源: label_quote_resource_failed: ",此资源引用失败! " label_file_lost: 以下无法成功下载,请联系相关人员重新上传: diff --git a/config/routes.rb b/config/routes.rb index 27bc59ffc..6ca3edd67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -431,8 +431,12 @@ RedmineApp::Application.routes.draw do match 'issues/update_form', :to => 'issues#update_form', :via => [:put, :post], :as => 'issue_form' resources :files, :only => [:index, :new, :create] do + member do + match "quote_resource_show_project",:via => [:get] + end collection do match "getattachtype" , :via => [:get, :post] + match "search_project",:via => [:post,:get] #match 'getattachtype/:attachtype', :to => 'files#getattachtype', :via => [:get, :post] end end @@ -590,6 +594,7 @@ RedmineApp::Application.routes.draw do get 'attachments/autocomplete' match 'attachments/autocomplete', :to => 'attachments#autocomplete', :via => [:post] post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation' + post 'attachments/relationfiles', to: 'attachments#add_exist_file_to_projects', as: 'attach_relations' post 'attachments/courserelationfile', to: 'attachments#add_exist_file_to_course', as: 'course_attach_relation' post 'attachments/courserelationfiles', to: 'attachments#add_exist_file_to_courses', as: 'course_attach_relations' get 'attachments/renderTag/:attchmentId', :to => 'attachments#renderTag', :attchmentId => /\d+/