To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / files_controller.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (2.05 KB)

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