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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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.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. render(:update) { |page|
  67. page.<< "$('notes').value = \"#{escape_javascript content}\";"
  68. page.show 'update'
  69. page << "Form.Element.focus('notes');"
  70. page << "Element.scrollTo('update');"
  71. page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
  72. }
  73. end
  74. def edit
  75. (render_403; return false) unless @journal.editable_by?(User.current)
  76. if request.post?
  77. @journal.update_attributes(:notes => params[:notes]) if params[:notes]
  78. @journal.destroy if @journal.details.empty? && @journal.notes.blank?
  79. call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
  80. respond_to do |format|
  81. format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
  82. format.js { render :action => 'update' }
  83. end
  84. else
  85. respond_to do |format|
  86. format.html {
  87. # TODO: implement non-JS journal update
  88. render :nothing => true
  89. }
  90. format.js
  91. end
  92. end
  93. end
  94. private
  95. def find_journal
  96. @journal = Journal.find(params[:id])
  97. @project = @journal.journalized.project
  98. rescue ActiveRecord::RecordNotFound
  99. render_404
  100. end
  101. # TODO: duplicated in IssuesController
  102. def find_issue
  103. @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
  104. @project = @issue.project
  105. rescue ActiveRecord::RecordNotFound
  106. render_404
  107. end
  108. end