PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/app/controllers/journals_controller.rb

https://bitbucket.org/prdixit/redmine
Ruby | 111 lines | 82 code | 10 blank | 19 comment | 10 complexity | b686d4dafdf68121638766ecaa8404c0 MD5 | raw file
Possible License(s): GPL-2.0
  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. end
  67. def edit
  68. (render_403; return false) unless @journal.editable_by?(User.current)
  69. if request.post?
  70. @journal.update_attributes(:notes => params[:notes]) if params[:notes]
  71. @journal.destroy if @journal.details.empty? && @journal.notes.blank?
  72. call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
  73. respond_to do |format|
  74. format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
  75. format.js { render :action => 'update' }
  76. end
  77. else
  78. respond_to do |format|
  79. format.html {
  80. # TODO: implement non-JS journal update
  81. render :nothing => true
  82. }
  83. format.js
  84. end
  85. end
  86. end
  87. private
  88. def find_journal
  89. @journal = Journal.find(params[:id])
  90. @project = @journal.journalized.project
  91. rescue ActiveRecord::RecordNotFound
  92. render_404
  93. end
  94. # TODO: duplicated in IssuesController
  95. def find_issue
  96. @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
  97. @project = @issue.project
  98. rescue ActiveRecord::RecordNotFound
  99. render_404
  100. end
  101. end