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.

documents_controller.rb 3.5 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 DocumentsController < ApplicationController
  18. layout 'base_projects'#by young
  19. default_search_scope :documents
  20. model_object Document
  21. before_filter :find_project_by_project_id, :only => [:index, :new, :create]
  22. before_filter :find_model_object, :except => [:index, :new, :create]
  23. before_filter :find_project_from_association, :except => [:index, :new, :create]
  24. before_filter :authorize , :except => [:index]#Added by young
  25. helper :attachments
  26. def index
  27. @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
  28. documents = @project.documents.includes(:attachments, :category).all
  29. case @sort_by
  30. when 'date'
  31. @grouped = documents.group_by {|d| d.updated_on.to_date }
  32. when 'title'
  33. @grouped = documents.group_by {|d| d.title.first.upcase}
  34. when 'author'
  35. @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
  36. else
  37. @grouped = documents.group_by(&:category)
  38. end
  39. @document = @project.documents.build
  40. if @project.project_type == 1
  41. render :layout => 'base_courses'
  42. else
  43. render :layout => false if request.xhr?
  44. end
  45. end
  46. def show
  47. @attachments = @document.attachments.all
  48. if @project.project_type ==1
  49. render :action => 'show', :layout => 'base_courses'
  50. end
  51. end
  52. def new
  53. @document = @project.documents.build
  54. @document.safe_attributes = params[:document]
  55. end
  56. def create
  57. @document = @project.documents.build
  58. @document.safe_attributes = params[:document]
  59. @document.user = User.current
  60. @document.save_attachments(params[:attachments])
  61. if @document.save
  62. render_attachment_warning_if_needed(@document)
  63. flash[:notice] = l(:notice_successful_create)
  64. redirect_to project_documents_path(@project)
  65. else
  66. render :action => 'new'
  67. end
  68. end
  69. def edit
  70. end
  71. def update
  72. @document.safe_attributes = params[:document]
  73. if request.put? and @document.save
  74. flash[:notice] = l(:notice_successful_update)
  75. redirect_to document_path(@document)
  76. else
  77. render :action => 'edit'
  78. end
  79. end
  80. def destroy
  81. @document.destroy if request.delete?
  82. redirect_to project_documents_path(@project)
  83. end
  84. def add_attachment
  85. attachments = Attachment.attach_files(@document, params[:attachments])
  86. render_attachment_warning_if_needed(@document)
  87. if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
  88. Mailer.attachments_added(attachments[:files]).deliver
  89. end
  90. redirect_to document_path(@document)
  91. end
  92. end

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