2013-08-01 10:33:49 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class PreviewsController < ApplicationController
|
2014-06-13 09:38:51 +08:00
|
|
|
before_filter :find_project, :find_attachments, :find_contest, except: [:contestnotification]
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
def issue
|
|
|
|
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
2014-06-04 20:29:15 +08:00
|
|
|
@issue = @contest.issues.find_by_id(params[:id]) unless params[:id].blank?
|
2013-08-01 10:33:49 +08:00
|
|
|
if @issue
|
|
|
|
@description = params[:issue] && params[:issue][:description]
|
|
|
|
if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
|
|
|
|
@description = nil
|
|
|
|
end
|
|
|
|
# params[:notes] is useful for preview of notes in issue history
|
|
|
|
@notes = params[:notes] || (params[:issue] ? params[:issue][:notes] : nil)
|
|
|
|
else
|
|
|
|
@description = (params[:issue] ? params[:issue][:description] : nil)
|
|
|
|
end
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
def news
|
|
|
|
if params[:id].present? && news = News.visible.find_by_id(params[:id])
|
|
|
|
@previewed = news
|
|
|
|
end
|
|
|
|
@text = (params[:news] ? params[:news][:description] : nil)
|
|
|
|
render :partial => 'common/preview'
|
|
|
|
end
|
|
|
|
|
2014-06-13 09:38:51 +08:00
|
|
|
def contestnotification
|
|
|
|
@previewed = Contestnotification.find(params[:id])
|
|
|
|
@text = (params[:contestnotification] ? params[:contestnotification][:description] : nil)
|
|
|
|
render :partial => 'common/preview'
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
|
|
|
@project = Project.find(project_id)
|
2013-08-03 22:18:30 +08:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2013-08-01 10:33:49 +08:00
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2014-06-04 20:29:15 +08:00
|
|
|
def contestnotifications
|
|
|
|
if params[:id].present? && contestnotifications = Contestnotifications.visible.find_by_id(params[:id])
|
|
|
|
@previewed = contestnotifications
|
|
|
|
end
|
|
|
|
@text = (params[:contestnotifications] ? params[:contestnotifications][:description] : nil)
|
|
|
|
render :partial => 'common/preview'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def find_contest
|
|
|
|
contest_id = (params[:issue] && params[:issue][:contest_id]) || params[:contest_id]
|
|
|
|
@contest = Contest.find(contest_id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|