Merge branch 'store' into develop
This commit is contained in:
commit
aed57c6c0a
|
@ -16,7 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
before_filter :find_project, :except => :upload
|
before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy, :delete_homework]#, :except => [:upload, :autocomplete]
|
||||||
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
|
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
|
||||||
before_filter :delete_authorize, :only => :destroy
|
before_filter :delete_authorize, :only => :destroy
|
||||||
before_filter :authorize_global, :only => :upload
|
before_filter :authorize_global, :only => :upload
|
||||||
|
@ -131,6 +131,41 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autocomplete
|
||||||
|
@project = Project.find_by_id(params[:project_id])
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_exist_file_to_project
|
||||||
|
classname = params[:class_name]
|
||||||
|
class_id = params[:class_id]
|
||||||
|
attachments = params[:attachment][:attach]
|
||||||
|
|
||||||
|
obj = Object.const_get(classname).find_by_id(class_id)
|
||||||
|
attachments.collect do |attach_id|
|
||||||
|
ori = Attachment.find_by_id(attach_id)
|
||||||
|
next if ori.blank?
|
||||||
|
attach_copied_obj = ori.copy
|
||||||
|
attach_copied_obj.container = obj
|
||||||
|
attach_copied_obj.created_on = Time.now
|
||||||
|
@obj = obj
|
||||||
|
@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
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@attachment = Attachment.find(params[:id])
|
@attachment = Attachment.find(params[:id])
|
||||||
|
|
|
@ -85,4 +85,82 @@ module AttachmentsHelper
|
||||||
Attachment.tagged_with(tag_name).order('created_on desc')
|
Attachment.tagged_with(tag_name).order('created_on desc')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_attachments_for_new_project(project, limit=nil)
|
||||||
|
# 查询条件
|
||||||
|
params[:q] ||= ""
|
||||||
|
filename_condition = params[:q]
|
||||||
|
|
||||||
|
attachAll = Attachment.scoped
|
||||||
|
# 当前项目所有资源
|
||||||
|
# attachments = Attachment.find_all_by_container_type_and_container_id(project.class, project.id)
|
||||||
|
# attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
|
||||||
|
|
||||||
|
# 除去当前项目的所有资源
|
||||||
|
nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}") unless project.blank?
|
||||||
|
|
||||||
|
# 搜索域确定
|
||||||
|
domain = project.nil? ? attachAll : nobelong_attach
|
||||||
|
|
||||||
|
# 搜索到的资源
|
||||||
|
searched_attach = domain.where("filename like '%#{filename_condition}%' ").limit(limit).order('created_on desc')
|
||||||
|
searched_attach = private_filter searched_attach
|
||||||
|
searched_attach = paginateHelper(searched_attach, 10)
|
||||||
|
|
||||||
|
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
||||||
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
|
||||||
|
# ================================================================================================
|
||||||
|
|
||||||
|
# attach_count = searched_attach.count
|
||||||
|
# attach_pages = Redmine::Pagination::Paginator.new attach_count, 10, params['page'] #by young
|
||||||
|
# attachs = searched_attach.offset(attach_pages.offset).limit(attach_pages.per_page).all
|
||||||
|
|
||||||
|
# s = content_tag('div', attachments_check_box_tags('attachment[attach][]', attachs), :id => 'attachments')
|
||||||
|
# links = pagination_links_full(attach_pages, attach_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
# link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
|
# return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
# return searched_attach.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def attachments_check_box_tags(name, attachs)
|
||||||
|
s = ''
|
||||||
|
attachs.each do |attach|
|
||||||
|
s << "<label>#{ check_box_tag name, attach.id, false, :id => nil } #{h attach.filename}</label><br/>"
|
||||||
|
end
|
||||||
|
s.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def private_filter resultSet
|
||||||
|
result = resultSet.to_a.dup
|
||||||
|
|
||||||
|
resultSet.map { |res|
|
||||||
|
if(res.container.nil? ||
|
||||||
|
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
||||||
|
(res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
|
||||||
|
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
||||||
|
false
|
||||||
|
)
|
||||||
|
result.delete(res)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
result
|
||||||
|
end
|
||||||
|
include Redmine::Pagination
|
||||||
|
def paginateHelper obj, pre_size=10
|
||||||
|
@obj_count = obj.count
|
||||||
|
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
|
||||||
|
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||||
|
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
||||||
|
elsif obj.kind_of? Array
|
||||||
|
obj[@obj_pages.offset, @obj_pages.per_page]
|
||||||
|
else
|
||||||
|
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||||
|
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -169,7 +169,7 @@ class Attachment < ActiveRecord::Base
|
||||||
|
|
||||||
def deletable?(user=User.current)
|
def deletable?(user=User.current)
|
||||||
if container_id
|
if container_id
|
||||||
container && container.attachments_deletable?(user)
|
container && (container.is_a?(Project) ? container.attachments_deletable?(user) : true )
|
||||||
else
|
else
|
||||||
author == user
|
author == user
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,14 +9,14 @@
|
||||||
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
||||||
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||||||
<% if options[:deletable] %>
|
<% if options[:deletable] %>
|
||||||
<% unless attachment.container_type == 'HomeworkAttach' %>
|
<% if attachment.container_type == 'HomeworkAttach' %>
|
||||||
<%= link_to image_tag('delete.png'), attachment_path(attachment),
|
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id},
|
||||||
:data => {:confirm => l(:text_are_you_sure)},
|
:data => {:confirm => l(:text_are_you_sure)},
|
||||||
:method => :delete,
|
:method => :delete,
|
||||||
:class => 'delete',
|
:class => 'delete',
|
||||||
:title => l(:button_delete) %>
|
:title => l(:button_delete) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id},
|
<%= link_to image_tag('delete.png'), attachment_path(attachment),
|
||||||
:data => {:confirm => l(:text_are_you_sure)},
|
:data => {:confirm => l(:text_are_you_sure)},
|
||||||
:method => :delete,
|
:method => :delete,
|
||||||
:class => 'delete',
|
:class => 'delete',
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<% if @save_flag %>
|
||||||
|
window.location.reload();
|
||||||
|
<% else %>
|
||||||
|
// alert('添加文件失败:\n<%=@save_message[0]%>');
|
||||||
|
$('#ajax-modal').html('<h3 class="title">添加文件失败</h3><%=@save_message.join(', ')%>');
|
||||||
|
|
||||||
|
var el = $('#ajax-modal').first();
|
||||||
|
var title = el.find('h3.title').text();
|
||||||
|
el.dialog({
|
||||||
|
width: '200px',
|
||||||
|
modal: true,
|
||||||
|
resizable: false,
|
||||||
|
dialogClass: 'modal',
|
||||||
|
title: title
|
||||||
|
});
|
||||||
|
|
||||||
|
<% end %>
|
|
@ -0,0 +1,2 @@
|
||||||
|
$('#relation_file_form').show();
|
||||||
|
$('#relation_file').html('<%=render_attachments_for_new_project(@project, nil)%>');
|
|
@ -81,25 +81,77 @@ div.tags_area {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
div.pagination{
|
||||||
|
margin: 10px 0px;
|
||||||
|
height: 1.5em;
|
||||||
|
text-align: left;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.m5p5{
|
||||||
|
display: inline-block;
|
||||||
|
height: auto;
|
||||||
|
color: white !important;
|
||||||
|
margin: 8px;
|
||||||
|
padding: 3px 7px;
|
||||||
|
}
|
||||||
|
.m5p5:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
/*padding-bottom: 3px;*/
|
||||||
|
/*border-bottom: 1px solid #666666;*/
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid #15bccf;
|
||||||
|
box-shadow: 3px 3px 3px #666666;
|
||||||
|
}
|
||||||
|
#relation_file_div{
|
||||||
|
margin: 0px 25px;
|
||||||
|
}
|
||||||
|
#relation_file_div fieldset{
|
||||||
|
margin: 0px 25px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
<span class="borad-title"><%=(@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>文件共享专区</span>
|
<span class="borad-title"><%=(@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>文件共享专区</span>
|
||||||
|
|
||||||
<div class="content-title-top">
|
<div class="content-title-top">
|
||||||
<%= link_to(l(:label_attachment_new), new_project_file_path(@project), :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %>
|
<%= link_to(l(:label_attachment_new), 'javascript:void(0);', :onclick=>"$('#file_buttons').slideToggle();", :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
<div id="file_buttons" class="hidden">
|
||||||
|
<%= link_to('上传文件', new_project_file_path(@project), :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %>
|
||||||
|
<%= link_to('关联已有文件', 'javascript:void(0);', :onclick => "$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %>
|
||||||
|
|
||||||
<% if Rails.env.development? %>
|
<div id="relation_file_div" class="hidden" >
|
||||||
<a href="#" class = 'icon' onclick="modalWin();">~测试测试~</a>
|
<fieldset>
|
||||||
<script type="text/javascript">
|
<legend>搜索</legend>
|
||||||
function modalWin () {
|
<%= form_tag(
|
||||||
$('#ajax-modal').html('<h3 class="title">~测试测试~</h3><p>导入勾选文件xxx test</p>');
|
attachments_autocomplete_path(:format => 'js'),
|
||||||
showModal('ajax-modal', '400px');
|
:remote => true,
|
||||||
|
:method => :post) do %>
|
||||||
|
<%= label_tag(:attach_search, "按文件名搜索:") %>
|
||||||
|
<%= text_field_tag(:attach_search) %>
|
||||||
|
<%#= submit_tag("Search") %>
|
||||||
|
<% end -%>
|
||||||
|
<%= form_tag attach_relation_path(:format => 'js'),
|
||||||
|
method: :post,
|
||||||
|
remote: true,
|
||||||
|
id:"relation_file_form",
|
||||||
|
:class => 'hidden' do %>
|
||||||
|
<%= hidden_field_tag(:class_name, 'Project') %>
|
||||||
|
<%= hidden_field_tag(:class_id, params[:project_id]) %>
|
||||||
|
<div id="relation_file" >
|
||||||
|
</div>
|
||||||
|
<div class="kclearfix" style='margin-top: 10px;' >
|
||||||
|
<%= submit_tag(l(:button_add)) -%>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
<%= javascript_tag "observeSearchfield('attach_search', null, '#{ escape_javascript attachments_autocomplete_path(:project_id => @project.id, :format => 'js') }')" %>
|
||||||
|
|
||||||
|
|
||||||
<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
|
<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
|
||||||
<table class="list files" id="ver-zebra" >
|
<table class="list files" id="ver-zebra" >
|
||||||
|
@ -130,7 +182,7 @@ div.tags_area {
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% container.attachments.each do |file| %>
|
<% container.attachments.each do |file| %>
|
||||||
<tr class="file <%= cycle("odd", "odd") %>">
|
<tr class="file <%= cycle("odd", "odd") %>">
|
||||||
<td class="filename" style="font-size: 13px; width: 240px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
|
<td class="filename" style="font-size: 13px; width: 240px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
|
||||||
<td class="created_on"><%= format_time(file.created_on) %></td>
|
<td class="created_on"><%= format_time(file.created_on) %></td>
|
||||||
<td class="filesize"><%= number_to_human_size(file.filesize) %></td>
|
<td class="filesize"><%= number_to_human_size(file.filesize) %></td>
|
||||||
<td class="downloads"><%= file.downloads %></td>
|
<td class="downloads"><%= file.downloads %></td>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% elsif object_flag == '6' %>
|
<% elsif object_flag == '6' %>
|
||||||
<span><%= image_tag("/images/sidebar/tags.png") %></span>
|
<span><%#= image_tag("/images/sidebar/tags.png") %></span>
|
||||||
<span>
|
<span>
|
||||||
<%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %>
|
<%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %>
|
||||||
<%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %>
|
<%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %>
|
||||||
|
|
|
@ -1150,6 +1150,7 @@ zh:
|
||||||
button_export: 导出
|
button_export: 导出
|
||||||
label_export_options: "%{export_format} 导出选项"
|
label_export_options: "%{export_format} 导出选项"
|
||||||
error_attachment_too_big: 该文件无法上传。超过文件大小限制 (%{max_size})
|
error_attachment_too_big: 该文件无法上传。超过文件大小限制 (%{max_size})
|
||||||
|
error_attachment_empty: 文件不能为空
|
||||||
notice_failed_to_save_time_entries: "无法保存下列所选取的 %{total} 个项目中的 %{count} 工时: %{ids}。"
|
notice_failed_to_save_time_entries: "无法保存下列所选取的 %{total} 个项目中的 %{count} 工时: %{ids}。"
|
||||||
label_x_issues:
|
label_x_issues:
|
||||||
zero: 0 问题
|
zero: 0 问题
|
||||||
|
|
|
@ -385,6 +385,9 @@ RedmineApp::Application.routes.draw do
|
||||||
get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'
|
get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'
|
||||||
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
|
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
|
||||||
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
|
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
|
||||||
|
get 'attachments/autocomplete'
|
||||||
|
match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:post]
|
||||||
|
post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation'
|
||||||
resources :attachments, :only => [:show, :destroy]
|
resources :attachments, :only => [:show, :destroy]
|
||||||
|
|
||||||
resources :groups do
|
resources :groups do
|
||||||
|
|
|
@ -1898,7 +1898,7 @@ input[type="submit"], .button_submit {
|
||||||
font-family: '微软雅黑',Arial,Helvetica,sans-serif;
|
font-family: '微软雅黑',Arial,Helvetica,sans-serif;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
padding: 0px;
|
padding: 3px 9px;
|
||||||
background: #15bccf;
|
background: #15bccf;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
border: 1px solid #15bccf;
|
border: 1px solid #15bccf;
|
||||||
|
|
|
@ -267,3 +267,31 @@ attachments_020:
|
||||||
filename: root_attachment.txt
|
filename: root_attachment.txt
|
||||||
filesize: 54
|
filesize: 54
|
||||||
author_id: 2
|
author_id: 2
|
||||||
|
attachments_021:
|
||||||
|
content_type: text/plain
|
||||||
|
downloads: 0
|
||||||
|
created_on: 2012-05-12 16:14:50 +09:00
|
||||||
|
disk_filename: 120512161450_project_test.txt
|
||||||
|
disk_directory:
|
||||||
|
container_id: 2
|
||||||
|
digest: b0fe2abdb2599743d554a61d7da7ff74
|
||||||
|
id: 21
|
||||||
|
container_type: Project
|
||||||
|
description: ""
|
||||||
|
filename: project_test.txt
|
||||||
|
filesize: 54
|
||||||
|
author_id: 2
|
||||||
|
attachments_022:
|
||||||
|
content_type: text/plain
|
||||||
|
downloads: 0
|
||||||
|
created_on: 2012-05-12 16:14:50 +09:00
|
||||||
|
disk_filename: 120512161450_course_test.txt
|
||||||
|
disk_directory:
|
||||||
|
container_id: 1
|
||||||
|
digest: b0fe2abdb2599743d554a61d7da7ff74
|
||||||
|
id: 22
|
||||||
|
container_type: Project
|
||||||
|
description: ""
|
||||||
|
filename: course_test.txt
|
||||||
|
filesize: 54
|
||||||
|
author_id: 2
|
|
@ -0,0 +1,20 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AttachmentsTest < ActiveSupport::TestCase
|
||||||
|
include AttachmentsHelper
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@file_belong_to = attachments(:attachments_021)
|
||||||
|
@file_not_belong_to = attachments(:attachments_022)
|
||||||
|
@project = @file_belong_to.container
|
||||||
|
end
|
||||||
|
|
||||||
|
test "can be find file not belong to project" do
|
||||||
|
params = {:q => @file_not_belong_to}
|
||||||
|
found_file = render_attachments_for_new_project(@project)
|
||||||
|
assert found_file.include?(@file_not_belong_to)
|
||||||
|
assert_not found_file.include?(@file_belong_to)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue