Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
050a780b50
|
@ -161,7 +161,13 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete
|
def autocomplete
|
||||||
|
# modify by nwb
|
||||||
|
if params[:project_id]
|
||||||
@project = Project.find_by_id(params[:project_id])
|
@project = Project.find_by_id(params[:project_id])
|
||||||
|
elsif params[:course_id]
|
||||||
|
@course = Course.find_by_id(params[:course_id])
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,7 +115,7 @@ module AttachmentsHelper
|
||||||
|
|
||||||
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
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|
|
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 }
|
link_to text, attachments_autocomplete_path( parameters.merge(:project_id=>project.id,:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
|
||||||
|
@ -133,6 +133,35 @@ module AttachmentsHelper
|
||||||
# return searched_attach.to_json
|
# return searched_attach.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
def render_attachments_for_new_course(course, limit=nil)
|
||||||
|
# 查询条件
|
||||||
|
params[:q] ||= ""
|
||||||
|
filename_condition = params[:q].strip
|
||||||
|
|
||||||
|
attachAll = Attachment.scoped
|
||||||
|
|
||||||
|
# 除去当前课程的所有资源
|
||||||
|
nobelong_attach = Attachment.where("!(container_type = '#{course.class}' and container_id = #{course.id})") unless course.blank?
|
||||||
|
|
||||||
|
# 搜索域确定
|
||||||
|
domain = course.nil? ? attachAll : nobelong_attach
|
||||||
|
|
||||||
|
# 搜索到的资源
|
||||||
|
searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc')
|
||||||
|
searched_attach = private_filter searched_attach
|
||||||
|
searched_attach = paginateHelper(searched_attach, 10)
|
||||||
|
|
||||||
|
#testattach = Attachment.public_attachments
|
||||||
|
|
||||||
|
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(:course_id=>course.id,:q => params[:q], :format => 'js')), :remote => true }
|
||||||
|
|
||||||
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def attachments_check_box_tags(name, attachs)
|
def attachments_check_box_tags(name, attachs)
|
||||||
s = ''
|
s = ''
|
||||||
attachs.each do |attach|
|
attachs.each do |attach|
|
||||||
|
@ -144,18 +173,22 @@ module AttachmentsHelper
|
||||||
def private_filter resultSet
|
def private_filter resultSet
|
||||||
result = resultSet.to_a.dup
|
result = resultSet.to_a.dup
|
||||||
|
|
||||||
|
# modify by nwb
|
||||||
|
#添加对课程资源文件的判断
|
||||||
resultSet.map { |res|
|
resultSet.map { |res|
|
||||||
if(res.container.nil? ||
|
if(res.container.nil? ||
|
||||||
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
||||||
(res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
|
(res.container.has_attribute?(:project) && res.container.project && res.container.project.is_public == false) ||
|
||||||
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
||||||
false
|
(res.container.class.to_s=="Course" && res.container.is_public == false) ||
|
||||||
|
(res.container.has_attribute?(:course) && res.container.course && res.container.course.is_public == false)
|
||||||
)
|
)
|
||||||
result.delete(res)
|
result.delete(res)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
include Redmine::Pagination
|
include Redmine::Pagination
|
||||||
def paginateHelper obj, pre_size=10
|
def paginateHelper obj, pre_size=10
|
||||||
@obj_count = obj.count
|
@obj_count = obj.count
|
||||||
|
|
|
@ -68,6 +68,106 @@ class Attachment < ActiveRecord::Base
|
||||||
before_save :be_user_score # user_score
|
before_save :be_user_score # user_score
|
||||||
after_destroy :delete_from_disk
|
after_destroy :delete_from_disk
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 获取所有可公开的资源文件列表
|
||||||
|
scope :public_attachments, lambda {
|
||||||
|
#joins(Project.table_name).where("container_type = 'Project' and ")
|
||||||
|
joins("LEFT JOIN #{Project.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Project.table_name}.id = #{Attachment.table_name}.container_id and #{Project.table_name}.is_public=1 " +
|
||||||
|
" LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Document.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{Issue.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Issue.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Project' AND #{Version.table_name}.project_id in "+self.public_project_id +
|
||||||
|
" LEFT JOIN #{WikiPage.table_name} ON #{Attachment.table_name}.container_type='WikiPage' AND #{WikiPage.table_name}.parent_id in "+self.public_wiki_id +
|
||||||
|
" LEFT JOIN #{Message.table_name} ON #{Attachment.table_name}.container_type='Message' AND #{Message.table_name}.parent_id in "+self.public_board_id +
|
||||||
|
" LEFT JOIN #{Course.table_name} ON #{Attachment.table_name}.container_type='Course' AND #{Course.table_name}.is_public=1 " +
|
||||||
|
" LEFT JOIN #{News.table_name} ON #{Attachment.table_name}.container_type='News' AND (#{News.table_name}.project_id in "+self.public_project_id + " OR #{News.table_name}.course_id in " + self.public_course_id + ")" +
|
||||||
|
" LEFT JOIN #{HomeworkAttach.table_name} ON #{Attachment.table_name}.container_type='HomeworkAttach' AND #{HomeworkAttach.table_name}.bid_id in "+self.public_bid_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的项目id列表
|
||||||
|
def self.public_project_id
|
||||||
|
idlist = "("
|
||||||
|
projects=Project.all_public
|
||||||
|
count = projects.count
|
||||||
|
for i in 0...count
|
||||||
|
project = projects[i]
|
||||||
|
idlist+="'" + project.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist+=","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的课程id列表
|
||||||
|
def self.public_course_id
|
||||||
|
idlist = "("
|
||||||
|
courses=Course.all_public
|
||||||
|
count = courses.count
|
||||||
|
for i in 0...count
|
||||||
|
course = courses[i]
|
||||||
|
idlist+="'" + course.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的wiki id列表
|
||||||
|
def self.public_wiki_id
|
||||||
|
idlist = "("
|
||||||
|
wikis=Wiki.where("project_id in " + public_project_id)
|
||||||
|
count = wikis.count
|
||||||
|
for i in 0...count
|
||||||
|
wiki = wikis[i]
|
||||||
|
idlist+="'" + wiki.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的board id列表
|
||||||
|
def self.public_board_id
|
||||||
|
idlist = "("
|
||||||
|
boards=Board.where("project_id in " + public_project_id + " or course_id in " + public_course_id)
|
||||||
|
count = boards.count
|
||||||
|
for i in 0...count
|
||||||
|
board = boards[i]
|
||||||
|
idlist+="'" + board.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
|
# add by nwb
|
||||||
|
# 公开的bid id列表
|
||||||
|
def self.public_bid_id
|
||||||
|
idlist = "("
|
||||||
|
bids=Bid.where("reward_type=3")
|
||||||
|
count = bids.count
|
||||||
|
for i in 0...count
|
||||||
|
bid = bids[i]
|
||||||
|
idlist+="'" + bid.id.to_s + "'"
|
||||||
|
if i != count-1
|
||||||
|
idlist = idlist + ","
|
||||||
|
end
|
||||||
|
end
|
||||||
|
idlist += ")"
|
||||||
|
idlist
|
||||||
|
end
|
||||||
|
|
||||||
# Returns an unsaved copy of the attachment
|
# Returns an unsaved copy of the attachment
|
||||||
def copy(attributes=nil)
|
def copy(attributes=nil)
|
||||||
copy = self.class.new
|
copy = self.class.new
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
$('#relation_file_form').show();
|
$('#relation_file_form').show();
|
||||||
|
<% if @project%>
|
||||||
$('#relation_file').html('<%=render_attachments_for_new_project(@project, nil)%>');
|
$('#relation_file').html('<%=render_attachments_for_new_project(@project, nil)%>');
|
||||||
|
<% elsif @course%>
|
||||||
|
$('#relation_file').html('<%=render_attachments_for_new_course(@course, nil)%>');
|
||||||
|
<% end%>
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
<%= select_tag "version_id", content_tag('option', '') +
|
<%= select_tag "version_id", content_tag('option', '') +
|
||||||
options_from_collection_for_select(versions, "id", "name"), {style: 'width:100px'} %>
|
options_from_collection_for_select(versions, "id", "name"), {style: 'width:100px'} %>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
|
||||||
<td><p></p></td> <td></td>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if attachmenttypes.any? %>
|
<% if attachmenttypes.any? %>
|
||||||
<td><%= l(:attachment_type) %></label></td>
|
<td><%= l(:attachment_type) %></label></td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -25,6 +21,17 @@
|
||||||
"typeName", 2), {style: 'width:100px'} %>
|
"typeName", 2), {style: 'width:100px'} %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<p>
|
||||||
|
<% if attachmenttypes.any? %>
|
||||||
|
<%= l(:attachment_type) %></label>
|
||||||
|
<%= select_tag "attachment_type",
|
||||||
|
options_from_collection_for_select(attachmenttypes, "id",
|
||||||
|
"typeName", 2), {style: 'width:100px'} %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
|
@ -1853,7 +1853,7 @@ a.remove-upload:hover {text-decoration:none !important;}
|
||||||
|
|
||||||
/*gcm upload file count and deleteall*/
|
/*gcm upload file count and deleteall*/
|
||||||
#upload_file_count #count {color:red; font-size:1.5em;}
|
#upload_file_count #count {color:red; font-size:1.5em;}
|
||||||
span.add_attachment .remove_all {background:none;background: url(../images/delete.png) no-repeat 1px 50%; width:1px; display:inline-block;position:absolute;right:10%;text-decoration:none;}
|
span.add_attachment .remove_all {background:none;background: url(../images/delete.png) no-repeat 1px 50%; width:1px; display:inline-block;right:10%;text-decoration:none;}
|
||||||
|
|
||||||
|
|
||||||
div.fileover { background-color: lavender; }
|
div.fileover { background-color: lavender; }
|
||||||
|
|
|
@ -1071,6 +1071,16 @@ div.tags_area {
|
||||||
border-bottom: 1px solid #c8d4fd;
|
border-bottom: 1px solid #c8d4fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ver-zebra #vzebra-attachmenttype, #ver-zebra #vzebra-children {
|
||||||
|
background: #ffffff;
|
||||||
|
border-bottom: 1px solid #c8d4fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ver-zebra #vzebra-contenttype, #ver-zebra #vzebra-children {
|
||||||
|
background: #ffffff;
|
||||||
|
border-bottom: 1px solid #c8d4fd;
|
||||||
|
}
|
||||||
|
|
||||||
#ver-zebra #vzebra-comedy, #ver-zebra #vzebra-action {
|
#ver-zebra #vzebra-comedy, #ver-zebra #vzebra-action {
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border-bottom: 1px solid #d6dfff;
|
border-bottom: 1px solid #d6dfff;
|
||||||
|
|
Loading…
Reference in New Issue