2013-08-01 10:33:49 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class FilesController < ApplicationController
|
2013-08-04 11:08:30 +08:00
|
|
|
layout 'base_projects'#by young
|
2013-08-01 10:33:49 +08:00
|
|
|
menu_item :files
|
|
|
|
|
2014-05-13 11:54:21 +08:00
|
|
|
before_filter :find_project_by_project_id#, :except => [:getattachtype]
|
|
|
|
before_filter :authorize, :except => [:getattachtype]
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
|
|
|
|
|
|
|
def index
|
2014-04-01 22:21:05 +08:00
|
|
|
#sort_init 'filename', 'asc'
|
|
|
|
sort_init 'created_on', 'desc'
|
|
|
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
|
|
|
'filename' => "#{Attachment.table_name}.filename",
|
|
|
|
'size' => "#{Attachment.table_name}.filesize",
|
|
|
|
'downloads' => "#{Attachment.table_name}.downloads"
|
2014-06-09 14:23:31 +08:00
|
|
|
|
|
|
|
if params[:project_id]
|
|
|
|
@isproject = true
|
|
|
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
|
|
|
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
|
|
|
|
render :layout => !request.xhr?
|
|
|
|
elsif params[:course_id]
|
|
|
|
@isproject = false
|
|
|
|
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
|
2013-08-30 09:34:21 +08:00
|
|
|
render :layout => 'base_courses'
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@versions = @project.versions.sort
|
2013-08-30 09:34:21 +08:00
|
|
|
@course_tag = @project.project_type
|
2013-09-29 19:46:59 +08:00
|
|
|
if @project.project_type == 1
|
2013-08-30 09:34:21 +08:00
|
|
|
render :layout => 'base_courses'
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-05-28 14:43:20 +08:00
|
|
|
if params[:add_tag]
|
|
|
|
@addTag=true
|
|
|
|
#render :back
|
2014-05-20 11:33:17 +08:00
|
|
|
tag_saveEx
|
2014-05-28 14:43:20 +08:00
|
|
|
#render :text =>"success"
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2014-05-20 11:33:17 +08:00
|
|
|
else
|
|
|
|
@addTag=false
|
|
|
|
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
|
|
|
attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type])
|
|
|
|
render_attachment_warning_if_needed(container)
|
2013-08-01 10:33:49 +08:00
|
|
|
|
2014-05-20 11:33:17 +08:00
|
|
|
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
|
|
|
Mailer.attachments_added(attachments[:files]).deliver
|
|
|
|
end
|
2014-05-28 14:43:20 +08:00
|
|
|
|
2014-05-30 10:49:49 +08:00
|
|
|
# TODO: 临时用 nyan
|
2014-05-28 14:43:20 +08:00
|
|
|
sort_init 'created_on', 'desc'
|
|
|
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
|
|
|
'filename' => "#{Attachment.table_name}.filename",
|
|
|
|
'size' => "#{Attachment.table_name}.filesize",
|
|
|
|
'downloads' => "#{Attachment.table_name}.downloads"
|
|
|
|
|
|
|
|
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
|
|
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
|
|
|
|
|
|
|
@attachtype = 0
|
|
|
|
@contenttype = 0
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html {
|
|
|
|
redirect_to project_files_path(@project)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
end
|
2014-05-09 17:13:23 +08:00
|
|
|
|
2014-05-20 11:33:17 +08:00
|
|
|
def tag_saveEx
|
|
|
|
@tags = params[:tag_name][:name]
|
|
|
|
@obj_id = params[:object_id]
|
|
|
|
@obj_flag = params[: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)
|
|
|
|
else
|
|
|
|
@obj = nil
|
|
|
|
end
|
|
|
|
unless @obj.nil?
|
|
|
|
@obj.tag_list.add(@tags.split(","))
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if @obj.save
|
|
|
|
## 执行成功的操作。
|
|
|
|
else
|
|
|
|
#捕获异常
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-13 11:54:21 +08:00
|
|
|
# 返回制定资源类型的资源列表
|
|
|
|
def getattachtype
|
|
|
|
sort_init 'created_on', 'desc'
|
|
|
|
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
2014-05-12 18:46:39 +08:00
|
|
|
'filename' => "#{Attachment.table_name}.filename",
|
|
|
|
'size' => "#{Attachment.table_name}.filesize",
|
|
|
|
'downloads' => "#{Attachment.table_name}.downloads"
|
2014-05-13 11:54:21 +08:00
|
|
|
|
2014-05-12 18:46:39 +08:00
|
|
|
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
|
|
|
|
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
|
2014-05-13 11:54:21 +08:00
|
|
|
|
|
|
|
@attachtype = params[:type].to_i
|
2014-05-13 16:34:53 +08:00
|
|
|
@contenttype = params[:contentType].to_s
|
2014-05-09 17:13:23 +08:00
|
|
|
|
2014-05-13 11:54:21 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
2014-05-12 18:46:39 +08:00
|
|
|
end
|
2014-05-09 17:13:23 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|