To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / journals_controller.rb @ 1535:e2c122809c5c

History | View | Annotate | Download (3.46 KB)

1 245:051f544170fe Chris
# Redmine - project management software
2 1494:e248c7af89ec Chris
# Copyright (C) 2006-2014  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# 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 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# 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
18
class JournalsController < ApplicationController
19 245:051f544170fe Chris
  before_filter :find_journal, :only => [:edit, :diff]
20 14:1d32c0a0efbf Chris
  before_filter :find_issue, :only => [:new]
21
  before_filter :find_optional_project, :only => [:index]
22 245:051f544170fe Chris
  before_filter :authorize, :only => [:new, :edit, :diff]
23 507:0c939c159af4 Chris
  accept_rss_auth :index
24 245:051f544170fe Chris
  menu_item :issues
25 909:cbb26bc654de Chris
26 14:1d32c0a0efbf Chris
  helper :issues
27 441:cbce1fd3b1b7 Chris
  helper :custom_fields
28 14:1d32c0a0efbf Chris
  helper :queries
29
  include QueriesHelper
30
  helper :sort
31
  include SortHelper
32
33
  def index
34
    retrieve_query
35
    sort_init 'id', 'desc'
36
    sort_update(@query.sortable_columns)
37 909:cbb26bc654de Chris
38 14:1d32c0a0efbf Chris
    if @query.valid?
39 909:cbb26bc654de Chris
      @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
40 14:1d32c0a0efbf Chris
                                  :limit => 25)
41
    end
42
    @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
43
    render :layout => false, :content_type => 'application/atom+xml'
44
  rescue ActiveRecord::RecordNotFound
45
    render_404
46
  end
47 909:cbb26bc654de Chris
48 245:051f544170fe Chris
  def diff
49
    @issue = @journal.issue
50
    if params[:detail_id].present?
51
      @detail = @journal.details.find_by_id(params[:detail_id])
52
    else
53
      @detail = @journal.details.detect {|d| d.prop_key == 'description'}
54
    end
55
    (render_404; return false) unless @issue && @detail
56
    @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
57
  end
58 909:cbb26bc654de Chris
59 14:1d32c0a0efbf Chris
  def new
60 1115:433d4f72a19b Chris
    @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
61
    if @journal
62
      user = @journal.user
63
      text = @journal.notes
64 14:1d32c0a0efbf Chris
    else
65
      user = @issue.author
66
      text = @issue.description
67
    end
68
    # Replaces pre blocks with [...]
69 1517:dffacf8a6908 Chris
    text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
70 1115:433d4f72a19b Chris
    @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
71
    @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
72
  rescue ActiveRecord::RecordNotFound
73
    render_404
74 14:1d32c0a0efbf Chris
  end
75 909:cbb26bc654de Chris
76 0:513646585e45 Chris
  def edit
77 245:051f544170fe Chris
    (render_403; return false) unless @journal.editable_by?(User.current)
78 0:513646585e45 Chris
    if request.post?
79
      @journal.update_attributes(:notes => params[:notes]) if params[:notes]
80
      @journal.destroy if @journal.details.empty? && @journal.notes.blank?
81
      call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
82
      respond_to do |format|
83 1464:261b3d9a4903 Chris
        format.html { redirect_to issue_path(@journal.journalized) }
84 0:513646585e45 Chris
        format.js { render :action => 'update' }
85
      end
86 245:051f544170fe Chris
    else
87
      respond_to do |format|
88
        format.html {
89
          # TODO: implement non-JS journal update
90 909:cbb26bc654de Chris
          render :nothing => true
91 245:051f544170fe Chris
        }
92
        format.js
93
      end
94 0:513646585e45 Chris
    end
95
  end
96 909:cbb26bc654de Chris
97 245:051f544170fe Chris
  private
98 909:cbb26bc654de Chris
99 0:513646585e45 Chris
  def find_journal
100 1115:433d4f72a19b Chris
    @journal = Journal.visible.find(params[:id])
101 0:513646585e45 Chris
    @project = @journal.journalized.project
102
  rescue ActiveRecord::RecordNotFound
103
    render_404
104
  end
105
end