Class: FilesController

Inherits:
ApplicationController show all
Includes:
SortHelper
Defined in:
app/controllers/files_controller.rb

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

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.

See doc/COPYRIGHT.rdoc for more details. ++

Instance Method Summary collapse

Methods included from SortHelper

#sort_clause, #sort_clear, #sort_header_tag, #sort_init, #sort_link, #sort_name, #sort_update

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Methods included from Redmine::Search::Controller

#default_search_scope, #default_search_scopes, included

Methods included from Redmine::I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/files_controller.rb', line 39

def create
  container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
  attachments = Attachment.attach_files(container, params[:attachments])
  render_attachment_warning_if_needed(container)

  if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
    # TODO: refactor
    recipients = attachments[:files].first.container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect  {|u| u.mail}
    recipients.each do |recipient|
      Mailer.deliver_attachments_added(attachments[:files], recipient)
    end
  end
  redirect_to project_files_path(@project)
end

#indexObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/files_controller.rb', line 23

def index
  sort_init 'filename', 'asc'
  sort_update 'filename' => "#{Attachment.table_name}.filename",
              'created_on' => "#{Attachment.table_name}.created_on",
              'size' => "#{Attachment.table_name}.filesize",
              'downloads' => "#{Attachment.table_name}.downloads"

  @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
  @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
  render :layout => !request.xhr?
end

#newObject



35
36
37
# File 'app/controllers/files_controller.rb', line 35

def new
  @versions = @project.versions.sort
end