@@ -1,50 +1,54 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class PreviewsController < ApplicationController |
|
18 | class PreviewsController < ApplicationController | |
19 | before_filter :find_project |
|
19 | before_filter :find_project | |
20 |
|
20 | |||
21 | def issue |
|
21 | def issue | |
22 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
22 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
23 | if @issue |
|
23 | if @issue | |
24 | @attachements = @issue.attachments |
|
24 | @attachements = @issue.attachments | |
25 | @description = params[:issue] && params[:issue][:description] |
|
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") |
|
26 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") | |
27 | @description = nil |
|
27 | @description = nil | |
28 | end |
|
28 | end | |
29 | @notes = params[:notes] |
|
29 | @notes = params[:notes] | |
30 | else |
|
30 | else | |
31 | @description = (params[:issue] ? params[:issue][:description] : nil) |
|
31 | @description = (params[:issue] ? params[:issue][:description] : nil) | |
32 | end |
|
32 | end | |
33 | render :layout => false |
|
33 | render :layout => false | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def news |
|
36 | def news | |
|
37 | if params[:id].present? && news = News.visible.find_by_id(params[:id]) | |||
|
38 | @previewed = news | |||
|
39 | @attachments = news.attachments | |||
|
40 | end | |||
37 | @text = (params[:news] ? params[:news][:description] : nil) |
|
41 | @text = (params[:news] ? params[:news][:description] : nil) | |
38 | render :partial => 'common/preview' |
|
42 | render :partial => 'common/preview' | |
39 | end |
|
43 | end | |
40 |
|
44 | |||
41 | private |
|
45 | private | |
42 |
|
46 | |||
43 | def find_project |
|
47 | def find_project | |
44 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
48 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] | |
45 | @project = Project.find(project_id) |
|
49 | @project = Project.find(project_id) | |
46 | rescue ActiveRecord::RecordNotFound |
|
50 | rescue ActiveRecord::RecordNotFound | |
47 | render_404 |
|
51 | render_404 | |
48 | end |
|
52 | end | |
49 |
|
53 | |||
50 | end |
|
54 | end |
@@ -1,12 +1,12 | |||||
1 | <h2><%=l(:label_news)%></h2> |
|
1 | <h2><%=l(:label_news)%></h2> | |
2 |
|
2 | |||
3 | <%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> |
|
3 | <%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> | |
4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
4 | <%= render :partial => 'form', :locals => { :f => f } %> | |
5 | <%= submit_tag l(:button_save) %> |
|
5 | <%= submit_tag l(:button_save) %> | |
6 | <%= preview_link preview_news_path(:project_id => @project), 'news-form' %> |
|
6 | <%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | |
7 | <% end %> |
|
7 | <% end %> | |
8 | <div id="preview" class="wiki"></div> |
|
8 | <div id="preview" class="wiki"></div> | |
9 |
|
9 | |||
10 | <% content_for :header_tags do %> |
|
10 | <% content_for :header_tags do %> | |
11 | <%= stylesheet_link_tag 'scm' %> |
|
11 | <%= stylesheet_link_tag 'scm' %> | |
12 | <% end %> |
|
12 | <% end %> |
@@ -1,62 +1,62 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= watcher_tag(@news, User.current) %> |
|
2 | <%= watcher_tag(@news, User.current) %> | |
3 | <%= link_to(l(:button_edit), |
|
3 | <%= link_to(l(:button_edit), | |
4 | edit_news_path(@news), |
|
4 | edit_news_path(@news), | |
5 | :class => 'icon icon-edit', |
|
5 | :class => 'icon icon-edit', | |
6 | :accesskey => accesskey(:edit), |
|
6 | :accesskey => accesskey(:edit), | |
7 | :onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_news, @project) %> |
|
7 | :onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_news, @project) %> | |
8 | <%= delete_link news_path(@news) if User.current.allowed_to?(:manage_news, @project) %> |
|
8 | <%= delete_link news_path(@news) if User.current.allowed_to?(:manage_news, @project) %> | |
9 | </div> |
|
9 | </div> | |
10 |
|
10 | |||
11 | <h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2> |
|
11 | <h2><%= avatar(@news.author, :size => "24") %><%=h @news.title %></h2> | |
12 |
|
12 | |||
13 | <% if authorize_for('news', 'edit') %> |
|
13 | <% if authorize_for('news', 'edit') %> | |
14 | <div id="edit-news" style="display:none;"> |
|
14 | <div id="edit-news" style="display:none;"> | |
15 | <%= labelled_form_for :news, @news, :url => news_path(@news), |
|
15 | <%= labelled_form_for :news, @news, :url => news_path(@news), | |
16 | :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> |
|
16 | :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> | |
17 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
17 | <%= render :partial => 'form', :locals => { :f => f } %> | |
18 | <%= submit_tag l(:button_save) %> |
|
18 | <%= submit_tag l(:button_save) %> | |
19 | <%= preview_link preview_news_path(:project_id => @project), 'news-form' %> | |
|
19 | <%= preview_link preview_news_path(:project_id => @project, :id => @news), 'news-form' %> | | |
20 | <%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %> |
|
20 | <%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %> | |
21 | <% end %> |
|
21 | <% end %> | |
22 | <div id="preview" class="wiki"></div> |
|
22 | <div id="preview" class="wiki"></div> | |
23 | </div> |
|
23 | </div> | |
24 | <% end %> |
|
24 | <% end %> | |
25 |
|
25 | |||
26 | <p><% unless @news.summary.blank? %><em><%=h @news.summary %></em><br /><% end %> |
|
26 | <p><% unless @news.summary.blank? %><em><%=h @news.summary %></em><br /><% end %> | |
27 | <span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
27 | <span class="author"><%= authoring @news.created_on, @news.author %></span></p> | |
28 | <div class="wiki"> |
|
28 | <div class="wiki"> | |
29 | <%= textilizable(@news, :description) %> |
|
29 | <%= textilizable(@news, :description) %> | |
30 | </div> |
|
30 | </div> | |
31 | <%= link_to_attachments @news %> |
|
31 | <%= link_to_attachments @news %> | |
32 | <br /> |
|
32 | <br /> | |
33 |
|
33 | |||
34 | <div id="comments" style="margin-bottom:16px;"> |
|
34 | <div id="comments" style="margin-bottom:16px;"> | |
35 | <h3 class="comments"><%= l(:label_comment_plural) %></h3> |
|
35 | <h3 class="comments"><%= l(:label_comment_plural) %></h3> | |
36 | <% @comments.each do |comment| %> |
|
36 | <% @comments.each do |comment| %> | |
37 | <% next if comment.new_record? %> |
|
37 | <% next if comment.new_record? %> | |
38 | <div class="contextual"> |
|
38 | <div class="contextual"> | |
39 | <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment}, |
|
39 | <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment}, | |
40 | :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %> |
|
40 | :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %> | |
41 | </div> |
|
41 | </div> | |
42 | <h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4> |
|
42 | <h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4> | |
43 | <%= textilizable(comment.comments) %> |
|
43 | <%= textilizable(comment.comments) %> | |
44 | <% end if @comments.any? %> |
|
44 | <% end if @comments.any? %> | |
45 | </div> |
|
45 | </div> | |
46 |
|
46 | |||
47 | <% if @news.commentable? %> |
|
47 | <% if @news.commentable? %> | |
48 | <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p> |
|
48 | <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p> | |
49 | <%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %> |
|
49 | <%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %> | |
50 | <div class="box"> |
|
50 | <div class="box"> | |
51 | <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> |
|
51 | <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> | |
52 | <%= wikitoolbar_for 'comment_comments' %> |
|
52 | <%= wikitoolbar_for 'comment_comments' %> | |
53 | </div> |
|
53 | </div> | |
54 | <p><%= submit_tag l(:button_add) %></p> |
|
54 | <p><%= submit_tag l(:button_add) %></p> | |
55 | <% end %> |
|
55 | <% end %> | |
56 | <% end %> |
|
56 | <% end %> | |
57 |
|
57 | |||
58 | <% html_title @news.title -%> |
|
58 | <% html_title @news.title -%> | |
59 |
|
59 | |||
60 | <% content_for :header_tags do %> |
|
60 | <% content_for :header_tags do %> | |
61 | <%= stylesheet_link_tag 'scm' %> |
|
61 | <%= stylesheet_link_tag 'scm' %> | |
62 | <% end %> |
|
62 | <% end %> |
@@ -1,68 +1,83 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class PreviewsControllerTest < ActionController::TestCase |
|
20 | class PreviewsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
23 | :projects_trackers, |
|
23 | :projects_trackers, | |
24 | :roles, |
|
24 | :roles, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :members, |
|
26 | :members, | |
27 | :enabled_modules, |
|
27 | :enabled_modules, | |
28 | :workflows, |
|
28 | :workflows, | |
29 | :journals, :journal_details |
|
29 | :journals, :journal_details, | |
|
30 | :news | |||
30 |
|
31 | |||
31 | def test_preview_new_issue |
|
32 | def test_preview_new_issue | |
32 | @request.session[:user_id] = 2 |
|
33 | @request.session[:user_id] = 2 | |
33 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} |
|
34 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} | |
34 | assert_response :success |
|
35 | assert_response :success | |
35 | assert_template 'preview' |
|
36 | assert_template 'preview' | |
36 | assert_not_nil assigns(:description) |
|
37 | assert_not_nil assigns(:description) | |
37 | end |
|
38 | end | |
38 |
|
39 | |||
39 | def test_preview_issue_notes |
|
40 | def test_preview_issue_notes | |
40 | @request.session[:user_id] = 2 |
|
41 | @request.session[:user_id] = 2 | |
41 | post :issue, :project_id => '1', :id => 1, |
|
42 | post :issue, :project_id => '1', :id => 1, | |
42 | :issue => {:description => Issue.find(1).description}, |
|
43 | :issue => {:description => Issue.find(1).description}, | |
43 | :notes => 'Foo' |
|
44 | :notes => 'Foo' | |
44 | assert_response :success |
|
45 | assert_response :success | |
45 | assert_template 'preview' |
|
46 | assert_template 'preview' | |
46 | assert_not_nil assigns(:notes) |
|
47 | assert_not_nil assigns(:notes) | |
47 | end |
|
48 | end | |
48 |
|
49 | |||
49 | def test_preview_journal_notes_for_update |
|
50 | def test_preview_journal_notes_for_update | |
50 | @request.session[:user_id] = 2 |
|
51 | @request.session[:user_id] = 2 | |
51 | post :issue, :project_id => '1', :id => 1, :notes => 'Foo' |
|
52 | post :issue, :project_id => '1', :id => 1, :notes => 'Foo' | |
52 | assert_response :success |
|
53 | assert_response :success | |
53 | assert_template 'preview' |
|
54 | assert_template 'preview' | |
54 | assert_not_nil assigns(:notes) |
|
55 | assert_not_nil assigns(:notes) | |
55 | assert_tag :p, :content => 'Foo' |
|
56 | assert_tag :p, :content => 'Foo' | |
56 | end |
|
57 | end | |
57 |
|
58 | |||
58 | def test_news |
|
59 | def test_preview_new_news | |
59 | get :news, :project_id => 1, |
|
60 | get :news, :project_id => 1, | |
60 | :news => {:title => '', |
|
61 | :news => {:title => '', | |
61 | :description => 'News description', |
|
62 | :description => 'News description', | |
62 | :summary => ''} |
|
63 | :summary => ''} | |
63 | assert_response :success |
|
64 | assert_response :success | |
64 | assert_template 'common/_preview' |
|
65 | assert_template 'common/_preview' | |
65 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, |
|
66 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, | |
66 | :content => /News description/ |
|
67 | :content => /News description/ | |
67 | end |
|
68 | end | |
|
69 | ||||
|
70 | def test_existing_new_news | |||
|
71 | get :news, :project_id => 1, :id => 2, | |||
|
72 | :news => {:title => '', | |||
|
73 | :description => 'News description', | |||
|
74 | :summary => ''} | |||
|
75 | assert_response :success | |||
|
76 | assert_template 'common/_preview' | |||
|
77 | assert_equal News.find(2), assigns(:previewed) | |||
|
78 | assert_not_nil assigns(:attachments) | |||
|
79 | ||||
|
80 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, | |||
|
81 | :content => /News description/ | |||
|
82 | end | |||
68 | end |
|
83 | end |
General Comments 0
You need to be logged in to leave comments.
Login now