Chris@1494: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1494: # Chris@1494: # This program is free software; you can redistribute it and/or Chris@1494: # modify it under the terms of the GNU General Public License Chris@1494: # as published by the Free Software Foundation; either version 2 Chris@1494: # of the License, or (at your option) any later version. Chris@1494: # Chris@1494: # This program is distributed in the hope that it will be useful, Chris@1494: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1494: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1494: # GNU General Public License for more details. Chris@1494: # Chris@1494: # You should have received a copy of the GNU General Public License Chris@1494: # along with this program; if not, write to the Free Software Chris@1494: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1494: Chris@1494: class JournalsController < ApplicationController Chris@1494: before_filter :find_journal, :only => [:edit, :diff] Chris@1494: before_filter :find_issue, :only => [:new] Chris@1494: before_filter :find_optional_project, :only => [:index] Chris@1494: before_filter :authorize, :only => [:new, :edit, :diff] Chris@1494: accept_rss_auth :index Chris@1494: menu_item :issues Chris@1494: Chris@1494: helper :issues Chris@1494: helper :custom_fields Chris@1494: helper :queries Chris@1494: include QueriesHelper Chris@1494: helper :sort Chris@1494: include SortHelper Chris@1494: Chris@1494: def index Chris@1494: retrieve_query Chris@1494: sort_init 'id', 'desc' Chris@1494: sort_update(@query.sortable_columns) Chris@1494: Chris@1494: if @query.valid? Chris@1494: @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", Chris@1494: :limit => 25) Chris@1494: end Chris@1494: @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) Chris@1494: render :layout => false, :content_type => 'application/atom+xml' Chris@1494: rescue ActiveRecord::RecordNotFound Chris@1494: render_404 Chris@1494: end Chris@1494: Chris@1494: def diff Chris@1494: @issue = @journal.issue Chris@1494: if params[:detail_id].present? Chris@1494: @detail = @journal.details.find_by_id(params[:detail_id]) Chris@1494: else Chris@1494: @detail = @journal.details.detect {|d| d.prop_key == 'description'} Chris@1494: end Chris@1494: (render_404; return false) unless @issue && @detail Chris@1494: @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) Chris@1494: end Chris@1494: Chris@1494: def new Chris@1494: @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id] Chris@1494: if @journal Chris@1494: user = @journal.user Chris@1494: text = @journal.notes Chris@1494: else Chris@1494: user = @issue.author Chris@1494: text = @issue.description Chris@1494: end Chris@1494: # Replaces pre blocks with [...] Chris@1494: text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') Chris@1494: @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " Chris@1494: @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" Chris@1494: rescue ActiveRecord::RecordNotFound Chris@1494: render_404 Chris@1494: end Chris@1494: Chris@1494: def edit Chris@1494: (render_403; return false) unless @journal.editable_by?(User.current) Chris@1494: if request.post? Chris@1494: @journal.update_attributes(:notes => params[:notes]) if params[:notes] Chris@1494: @journal.destroy if @journal.details.empty? && @journal.notes.blank? Chris@1494: call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) Chris@1494: respond_to do |format| Chris@1494: format.html { redirect_to issue_path(@journal.journalized) } Chris@1494: format.js { render :action => 'update' } Chris@1494: end Chris@1494: else Chris@1494: respond_to do |format| Chris@1494: format.html { Chris@1494: # TODO: implement non-JS journal update Chris@1494: render :nothing => true Chris@1494: } Chris@1494: format.js Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: private Chris@1494: Chris@1494: def find_journal Chris@1494: @journal = Journal.visible.find(params[:id]) Chris@1494: @project = @journal.journalized.project Chris@1494: rescue ActiveRecord::RecordNotFound Chris@1494: render_404 Chris@1494: end Chris@1494: end