annotate .svn/pristine/ab/abd5fdb1f4d3a8db5bc870f482b9f0ab10c084c0.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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