You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

files_controller.rb 6.6 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
13 years ago
​
​
​
13 years ago
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  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. class FilesController < ApplicationController
  18. layout 'base_projects'#by young
  19. menu_item :files
  20. before_filter :find_project_by_project_id#, :except => [:getattachtype]
  21. before_filter :authorize, :except => [:getattachtype]
  22. helper :sort
  23. include SortHelper
  24. def index
  25. #sort_init 'filename', 'asc'
  26. sort_init 'created_on', 'desc'
  27. sort_update 'created_on' => "#{Attachment.table_name}.created_on",
  28. 'filename' => "#{Attachment.table_name}.filename",
  29. 'size' => "#{Attachment.table_name}.filesize",
  30. 'downloads' => "#{Attachment.table_name}.downloads"
  31. if params[:project_id]
  32. @isproject = true
  33. @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
  34. @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
  35. render :layout => !request.xhr?
  36. elsif params[:course_id]
  37. @isproject = false
  38. @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
  39. render :layout => 'base_courses'
  40. end
  41. end
  42. def new
  43. @versions = @project.versions.sort
  44. @course_tag = @project.project_type
  45. if @project.project_type == 1
  46. render :layout => 'base_courses'
  47. end
  48. end
  49. def create
  50. if params[:add_tag]
  51. @addTag=true
  52. #render :back
  53. tag_saveEx
  54. #render :text =>"success"
  55. respond_to do |format|
  56. format.js
  57. end
  58. else
  59. #modify by nwb
  60. if @project
  61. @addTag=false
  62. container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
  63. attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type])
  64. render_attachment_warning_if_needed(container)
  65. if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
  66. Mailer.attachments_added(attachments[:files]).deliver
  67. end
  68. # TODO: 临时用 nyan
  69. sort_init 'created_on', 'desc'
  70. sort_update 'created_on' => "#{Attachment.table_name}.created_on",
  71. 'filename' => "#{Attachment.table_name}.filename",
  72. 'size' => "#{Attachment.table_name}.filesize",
  73. 'downloads' => "#{Attachment.table_name}.downloads"
  74. @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
  75. @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
  76. @attachtype = 0
  77. @contenttype = 0
  78. respond_to do |format|
  79. format.js
  80. format.html {
  81. redirect_to project_files_path(@project)
  82. }
  83. end
  84. elsif @course
  85. @addTag=false
  86. attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
  87. if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
  88. Mailer.attachments_added(attachments[:files]).deliver
  89. end
  90. # TODO: 临时用 nyan
  91. sort_init 'created_on', 'desc'
  92. sort_update 'created_on' => "#{Attachment.table_name}.created_on",
  93. 'filename' => "#{Attachment.table_name}.filename",
  94. 'size' => "#{Attachment.table_name}.filesize",
  95. 'downloads' => "#{Attachment.table_name}.downloads"
  96. @containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
  97. @attachtype = 0
  98. @contenttype = 0
  99. respond_to do |format|
  100. format.js
  101. format.html {
  102. redirect_to course_files_path(@course)
  103. }
  104. end
  105. end
  106. end
  107. end
  108. def tag_saveEx
  109. @tags = params[:tag_name][:name]
  110. @obj_id = params[:object_id]
  111. @obj_flag = params[:object_flag]
  112. case @obj_flag
  113. when '1' then
  114. @obj = User.find_by_id(@obj_id)
  115. when '2' then
  116. @obj = Project.find_by_id(@obj_id)
  117. when '3' then
  118. @obj = Issue.find_by_id(@obj_id)
  119. when '4' then
  120. @obj = Bid.find_by_id(@obj_id)
  121. when '5' then
  122. @obj = Forum.find_by_id(@obj_id)
  123. when '6'
  124. @obj = Attachment.find_by_id(@obj_id)
  125. when '7' then
  126. @obj = Contest.find_by_id(@obj_id)
  127. when '8'
  128. @obj = OpenSourceProject.find_by_id(@obj_id)
  129. when '9'
  130. @obj = Course.find_by_id(@obj_id)
  131. else
  132. @obj = nil
  133. end
  134. unless @obj.nil?
  135. @obj.tag_list.add(@tags.split(","))
  136. else
  137. return
  138. end
  139. if @obj.save
  140. ## 执行成功的操作。
  141. else
  142. #捕获异常
  143. end
  144. end
  145. # 返回制定资源类型的资源列表
  146. # added by nwb
  147. def getattachtype
  148. sort_init 'created_on', 'desc'
  149. sort_update 'created_on' => "#{Attachment.table_name}.created_on",
  150. 'filename' => "#{Attachment.table_name}.filename",
  151. 'size' => "#{Attachment.table_name}.filesize",
  152. 'downloads' => "#{Attachment.table_name}.downloads"
  153. if @project
  154. @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
  155. @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
  156. elsif @course
  157. @containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
  158. end
  159. @attachtype = params[:type].to_i
  160. @contenttype = params[:contentType].to_s
  161. respond_to do |format|
  162. format.js
  163. end
  164. end
  165. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...