Chris@1115
|
1 # Redmine - project management software
|
Chris@1295
|
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
|
Chris@1115
|
3 #
|
Chris@1115
|
4 # This program is free software; you can redistribute it and/or
|
Chris@1115
|
5 # modify it under the terms of the GNU General Public License
|
Chris@1115
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@1115
|
7 # of the License, or (at your option) any later version.
|
Chris@1115
|
8 #
|
Chris@1115
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@1115
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@1115
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@1115
|
12 # GNU General Public License for more details.
|
Chris@1115
|
13 #
|
Chris@1115
|
14 # You should have received a copy of the GNU General Public License
|
Chris@1115
|
15 # along with this program; if not, write to the Free Software
|
Chris@1115
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@1115
|
17
|
chris@22
|
18 class FilesController < ApplicationController
|
chris@22
|
19 menu_item :files
|
chris@22
|
20
|
chris@22
|
21 before_filter :find_project_by_project_id
|
chris@22
|
22 before_filter :authorize
|
chris@22
|
23
|
chris@22
|
24 helper :sort
|
chris@22
|
25 include SortHelper
|
chris@22
|
26
|
chris@22
|
27 def index
|
chris@22
|
28 sort_init 'filename', 'asc'
|
chris@22
|
29 sort_update 'filename' => "#{Attachment.table_name}.filename",
|
chris@22
|
30 'created_on' => "#{Attachment.table_name}.created_on",
|
chris@22
|
31 'size' => "#{Attachment.table_name}.filesize",
|
chris@22
|
32 'downloads' => "#{Attachment.table_name}.downloads"
|
Chris@441
|
33
|
Chris@1295
|
34 @containers = [ Project.includes(:attachments).reorder(sort_clause).find(@project.id)]
|
Chris@1295
|
35 @containers += @project.versions.includes(:attachments).reorder(sort_clause).all.sort.reverse
|
chris@22
|
36 render :layout => !request.xhr?
|
chris@22
|
37 end
|
chris@22
|
38
|
chris@22
|
39 def new
|
chris@22
|
40 @versions = @project.versions.sort
|
chris@22
|
41 end
|
chris@22
|
42
|
chris@22
|
43 def create
|
chris@22
|
44 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
chris@22
|
45 attachments = Attachment.attach_files(container, params[:attachments])
|
chris@22
|
46 render_attachment_warning_if_needed(container)
|
chris@22
|
47
|
chris@37
|
48 if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
Chris@1115
|
49 Mailer.attachments_added(attachments[:files]).deliver
|
chris@22
|
50 end
|
chris@22
|
51 redirect_to project_files_path(@project)
|
chris@22
|
52 end
|
chris@22
|
53 end
|