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

journals_controller.rb 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 JournalsController < ApplicationController
  18. before_filter :find_journal, :only => [:edit, :diff]
  19. before_filter :find_issue, :only => [:new]
  20. before_filter :find_optional_project, :only => [:index]
  21. before_filter :authorize, :only => [:new, :edit, :diff]
  22. accept_rss_auth :index
  23. menu_item :issues
  24. helper :issues
  25. helper :custom_fields
  26. helper :queries
  27. include QueriesHelper
  28. helper :sort
  29. include SortHelper
  30. def index
  31. retrieve_query
  32. sort_init 'id', 'desc'
  33. sort_update(@query.sortable_columns)
  34. if @query.valid?
  35. @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
  36. :limit => 25)
  37. end
  38. @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
  39. render :layout => false, :content_type => 'application/atom+xml'
  40. rescue ActiveRecord::RecordNotFound
  41. render_404
  42. end
  43. def diff
  44. @issue = @journal.issue
  45. if params[:detail_id].present?
  46. @detail = @journal.details.find_by_id(params[:detail_id])
  47. else
  48. @detail = @journal.details.detect {|d| d.prop_key == 'description'}
  49. end
  50. (render_404; return false) unless @issue && @detail
  51. @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
  52. end
  53. def new
  54. @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
  55. if @journal
  56. user = @journal.user
  57. text = @journal.notes
  58. else
  59. user = @issue.author
  60. text = @issue.description
  61. end
  62. # Replaces pre blocks with [...]
  63. text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
  64. @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
  65. @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  66. rescue ActiveRecord::RecordNotFound
  67. render_404
  68. end
  69. def edit
  70. (render_403; return false) unless @journal.editable_by?(User.current)
  71. if request.post?
  72. @journal.update_attributes(:notes => params[:notes]) if params[:notes]
  73. @journal.destroy if @journal.details.empty? && @journal.notes.blank?
  74. call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
  75. respond_to do |format|
  76. format.html { redirect_to issue_path(@journal.journalized) }
  77. format.js { render :action => 'update' }
  78. end
  79. else
  80. respond_to do |format|
  81. format.html {
  82. # TODO: implement non-JS journal update
  83. render :nothing => true
  84. }
  85. format.js
  86. end
  87. end
  88. end
  89. private
  90. def find_journal
  91. @journal = Journal.visible.find(params[:id])
  92. @project = @journal.journalized.project
  93. rescue ActiveRecord::RecordNotFound
  94. render_404
  95. end
  96. end