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 / previews_controller.rb @ 1360:45dbcd39b9e9

History | View | Annotate | Download (1.97 KB)

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

    
18
class PreviewsController < ApplicationController
19
  before_filter :find_project
20

    
21
  def issue
22
    @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
23
    if @issue
24
      @attachements = @issue.attachments
25
      @description = params[:issue] && params[:issue][:description]
26
      if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
27
        @description = nil
28
      end
29
      # params[:notes] is useful for preview of notes in issue history
30
      @notes = params[:notes] || (params[:issue] ? params[:issue][:notes] : nil)
31
    else
32
      @description = (params[:issue] ? params[:issue][:description] : nil)
33
    end
34
    render :layout => false
35
  end
36

    
37
  def news
38
    if params[:id].present? && news = News.visible.find_by_id(params[:id])
39
      @previewed = news
40
      @attachments = news.attachments
41
    end
42
    @text = (params[:news] ? params[:news][:description] : nil)
43
    render :partial => 'common/preview'
44
  end
45

    
46
  private
47

    
48
  def find_project
49
    project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
50
    @project = Project.find(project_id)
51
  rescue ActiveRecord::RecordNotFound
52
    render_404
53
  end
54

    
55
end