annotate app/controllers/journals_controller.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@245 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class JournalsController < ApplicationController
Chris@245 19 before_filter :find_journal, :only => [:edit, :diff]
Chris@14 20 before_filter :find_issue, :only => [:new]
Chris@14 21 before_filter :find_optional_project, :only => [:index]
Chris@245 22 before_filter :authorize, :only => [:new, :edit, :diff]
Chris@507 23 accept_rss_auth :index
Chris@245 24 menu_item :issues
Chris@909 25
Chris@14 26 helper :issues
Chris@441 27 helper :custom_fields
Chris@14 28 helper :queries
Chris@14 29 include QueriesHelper
Chris@14 30 helper :sort
Chris@14 31 include SortHelper
Chris@14 32
Chris@14 33 def index
Chris@14 34 retrieve_query
Chris@14 35 sort_init 'id', 'desc'
Chris@14 36 sort_update(@query.sortable_columns)
Chris@909 37
Chris@14 38 if @query.valid?
Chris@909 39 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
Chris@14 40 :limit => 25)
Chris@14 41 end
Chris@14 42 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
Chris@14 43 render :layout => false, :content_type => 'application/atom+xml'
Chris@14 44 rescue ActiveRecord::RecordNotFound
Chris@14 45 render_404
Chris@14 46 end
Chris@909 47
Chris@245 48 def diff
Chris@245 49 @issue = @journal.issue
Chris@245 50 if params[:detail_id].present?
Chris@245 51 @detail = @journal.details.find_by_id(params[:detail_id])
Chris@245 52 else
Chris@245 53 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
Chris@245 54 end
Chris@245 55 (render_404; return false) unless @issue && @detail
Chris@245 56 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
Chris@245 57 end
Chris@909 58
Chris@14 59 def new
Chris@1115 60 @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
Chris@1115 61 if @journal
Chris@1115 62 user = @journal.user
Chris@1115 63 text = @journal.notes
Chris@14 64 else
Chris@14 65 user = @issue.author
Chris@14 66 text = @issue.description
Chris@14 67 end
Chris@14 68 # Replaces pre blocks with [...]
Chris@1517 69 text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
Chris@1115 70 @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
Chris@1115 71 @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
Chris@1115 72 rescue ActiveRecord::RecordNotFound
Chris@1115 73 render_404
Chris@14 74 end
Chris@909 75
Chris@0 76 def edit
Chris@245 77 (render_403; return false) unless @journal.editable_by?(User.current)
Chris@0 78 if request.post?
Chris@0 79 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
Chris@0 80 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
Chris@0 81 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
Chris@0 82 respond_to do |format|
Chris@1464 83 format.html { redirect_to issue_path(@journal.journalized) }
Chris@0 84 format.js { render :action => 'update' }
Chris@0 85 end
Chris@245 86 else
Chris@245 87 respond_to do |format|
Chris@245 88 format.html {
Chris@245 89 # TODO: implement non-JS journal update
Chris@909 90 render :nothing => true
Chris@245 91 }
Chris@245 92 format.js
Chris@245 93 end
Chris@0 94 end
Chris@0 95 end
Chris@909 96
Chris@245 97 private
Chris@909 98
Chris@0 99 def find_journal
Chris@1115 100 @journal = Journal.visible.find(params[:id])
Chris@0 101 @project = @journal.journalized.project
Chris@0 102 rescue ActiveRecord::RecordNotFound
Chris@0 103 render_404
Chris@0 104 end
Chris@0 105 end