@@ -1,82 +1,92 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class BoardsController < ApplicationController |
|
19 | 19 | before_filter :find_project, :authorize |
|
20 | 20 | |
|
21 | 21 | helper :messages |
|
22 | 22 | include MessagesHelper |
|
23 | 23 | helper :sort |
|
24 | 24 | include SortHelper |
|
25 | 25 | helper :watchers |
|
26 | 26 | include WatchersHelper |
|
27 | 27 | |
|
28 | 28 | def index |
|
29 | 29 | @boards = @project.boards |
|
30 | 30 | # show the board if there is only one |
|
31 | 31 | if @boards.size == 1 |
|
32 | 32 | @board = @boards.first |
|
33 | 33 | show |
|
34 | 34 | end |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def show |
|
38 | sort_init 'updated_on', 'desc' | |
|
39 | sort_update 'created_on' => "#{Message.table_name}.created_on", | |
|
40 | 'replies' => "#{Message.table_name}.replies_count", | |
|
41 |
|
|
|
42 | ||
|
43 | @topic_count = @board.topics.count | |
|
44 | @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page'] | |
|
45 | @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '), | |
|
46 | :include => [:author, {:last_reply => :author}], | |
|
47 | :limit => @topic_pages.items_per_page, | |
|
48 | :offset => @topic_pages.current.offset | |
|
49 | @message = Message.new | |
|
50 | render :action => 'show', :layout => !request.xhr? | |
|
38 | respond_to do |format| | |
|
39 | format.html { | |
|
40 | sort_init 'updated_on', 'desc' | |
|
41 | sort_update 'created_on' => "#{Message.table_name}.created_on", | |
|
42 | 'replies' => "#{Message.table_name}.replies_count", | |
|
43 | 'updated_on' => "#{Message.table_name}.updated_on" | |
|
44 | ||
|
45 | @topic_count = @board.topics.count | |
|
46 | @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page'] | |
|
47 | @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '), | |
|
48 | :include => [:author, {:last_reply => :author}], | |
|
49 | :limit => @topic_pages.items_per_page, | |
|
50 | :offset => @topic_pages.current.offset | |
|
51 | @message = Message.new | |
|
52 | render :action => 'show', :layout => !request.xhr? | |
|
53 | } | |
|
54 | format.atom { | |
|
55 | @messages = @board.messages.find :all, :order => 'created_on DESC', | |
|
56 | :include => [:author, :board], | |
|
57 | :limit => Setting.feeds_limit.to_i | |
|
58 | render_feed(@messages, :title => "#{@project}: #{@board}") | |
|
59 | } | |
|
60 | end | |
|
51 | 61 | end |
|
52 | 62 | |
|
53 | 63 | verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index } |
|
54 | 64 | |
|
55 | 65 | def new |
|
56 | 66 | @board = Board.new(params[:board]) |
|
57 | 67 | @board.project = @project |
|
58 | 68 | if request.post? && @board.save |
|
59 | 69 | flash[:notice] = l(:notice_successful_create) |
|
60 | 70 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
|
61 | 71 | end |
|
62 | 72 | end |
|
63 | 73 | |
|
64 | 74 | def edit |
|
65 | 75 | if request.post? && @board.update_attributes(params[:board]) |
|
66 | 76 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
|
67 | 77 | end |
|
68 | 78 | end |
|
69 | 79 | |
|
70 | 80 | def destroy |
|
71 | 81 | @board.destroy |
|
72 | 82 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
|
73 | 83 | end |
|
74 | 84 | |
|
75 | 85 | private |
|
76 | 86 | def find_project |
|
77 | 87 | @project = Project.find(params[:project_id]) |
|
78 | 88 | @board = @project.boards.find(params[:id]) if params[:id] |
|
79 | 89 | rescue ActiveRecord::RecordNotFound |
|
80 | 90 | render_404 |
|
81 | 91 | end |
|
82 | 92 | end |
@@ -1,42 +1,46 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Board < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC" |
|
21 | 21 | has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC" |
|
22 | 22 | belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id |
|
23 | 23 | acts_as_list :scope => :project_id |
|
24 | 24 | acts_as_watchable |
|
25 | 25 | |
|
26 | 26 | validates_presence_of :name, :description |
|
27 | 27 | validates_length_of :name, :maximum => 30 |
|
28 | 28 | validates_length_of :description, :maximum => 255 |
|
29 | 29 | |
|
30 | def to_s | |
|
31 | name | |
|
32 | end | |
|
33 | ||
|
30 | 34 | def reset_counters! |
|
31 | 35 | self.class.reset_counters!(id) |
|
32 | 36 | end |
|
33 | 37 | |
|
34 | 38 | # Updates topics_count, messages_count and last_message_id attributes for +board_id+ |
|
35 | 39 | def self.reset_counters!(board_id) |
|
36 | 40 | board_id = board_id.to_i |
|
37 | 41 | update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," + |
|
38 | 42 | " messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," + |
|
39 | 43 | " last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})", |
|
40 | 44 | ["id = ?", board_id]) |
|
41 | 45 | end |
|
42 | 46 | end |
@@ -1,62 +1,70 | |||
|
1 | 1 | <%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}) %> |
|
2 | 2 | |
|
3 | 3 | <div class="contextual"> |
|
4 | 4 | <%= link_to_if_authorized l(:label_message_new), |
|
5 | 5 | {:controller => 'messages', :action => 'new', :board_id => @board}, |
|
6 | 6 | :class => 'icon icon-add', |
|
7 | 7 | :onclick => 'Element.show("add-message"); Form.Element.focus("message_subject"); return false;' %> |
|
8 | 8 | <%= watcher_tag(@board, User.current) %> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | 11 | <div id="add-message" style="display:none;"> |
|
12 | 12 | <h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %></h2> |
|
13 | 13 | <% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true, :id => 'message-form'} do |f| %> |
|
14 | 14 | <%= render :partial => 'messages/form', :locals => {:f => f} %> |
|
15 | 15 | <p><%= submit_tag l(:button_create) %> |
|
16 | 16 | <%= link_to_remote l(:label_preview), |
|
17 | 17 | { :url => { :controller => 'messages', :action => 'preview', :board_id => @board }, |
|
18 | 18 | :method => 'post', |
|
19 | 19 | :update => 'preview', |
|
20 | 20 | :with => "Form.serialize('message-form')", |
|
21 | 21 | :complete => "Element.scrollTo('preview')" |
|
22 | 22 | }, :accesskey => accesskey(:preview) %> | |
|
23 | 23 | <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %></p> |
|
24 | 24 | <% end %> |
|
25 | 25 | <div id="preview" class="wiki"></div> |
|
26 | 26 | </div> |
|
27 | 27 | |
|
28 | 28 | <h2><%=h @board.name %></h2> |
|
29 | 29 | <p class="subtitle"><%=h @board.description %></p> |
|
30 | 30 | |
|
31 | 31 | <% if @topics.any? %> |
|
32 | 32 | <table class="list messages"> |
|
33 | 33 | <thead><tr> |
|
34 | 34 | <th><%= l(:field_subject) %></th> |
|
35 | 35 | <th><%= l(:field_author) %></th> |
|
36 | 36 | <%= sort_header_tag('created_on', :caption => l(:field_created_on)) %> |
|
37 | 37 | <%= sort_header_tag('replies', :caption => l(:label_reply_plural)) %> |
|
38 | 38 | <%= sort_header_tag('updated_on', :caption => l(:label_message_last)) %> |
|
39 | 39 | </tr></thead> |
|
40 | 40 | <tbody> |
|
41 | 41 | <% @topics.each do |topic| %> |
|
42 | 42 | <tr class="message <%= cycle 'odd', 'even' %> <%= topic.sticky? ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"> |
|
43 | 43 | <td class="subject"><%= link_to h(topic.subject), { :controller => 'messages', :action => 'show', :board_id => @board, :id => topic }, :class => 'icon' %></td> |
|
44 | 44 | <td class="author" align="center"><%= topic.author %></td> |
|
45 | 45 | <td class="created_on" align="center"><%= format_time(topic.created_on) %></td> |
|
46 | 46 | <td class="replies" align="center"><%= topic.replies_count %></td> |
|
47 | 47 | <td class="last_message"> |
|
48 | 48 | <% if topic.last_reply %> |
|
49 | 49 | <%= authoring topic.last_reply.created_on, topic.last_reply.author %><br /> |
|
50 | 50 | <%= link_to_message topic.last_reply %> |
|
51 | 51 | <% end %> |
|
52 | 52 | </td> |
|
53 | 53 | </tr> |
|
54 | 54 | <% end %> |
|
55 | 55 | </tbody> |
|
56 | 56 | </table> |
|
57 | 57 | <p class="pagination"><%= pagination_links_full @topic_pages, @topic_count %></p> |
|
58 | 58 | <% else %> |
|
59 | 59 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
60 | 60 | <% end %> |
|
61 | 61 | |
|
62 | <% other_formats_links do |f| %> | |
|
63 | <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> | |
|
64 | <% end %> | |
|
65 | ||
|
62 | 66 | <% html_title h(@board.name) %> |
|
67 | ||
|
68 | <% content_for :header_tags do %> | |
|
69 | <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@project}: #{@board}") %> | |
|
70 | <% end %> |
@@ -1,260 +1,261 | |||
|
1 | 1 | ActionController::Routing::Routes.draw do |map| |
|
2 | 2 | # Add your own custom routes here. |
|
3 | 3 | # The priority is based upon order of creation: first created -> highest priority. |
|
4 | 4 | |
|
5 | 5 | # Here's a sample route: |
|
6 | 6 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' |
|
7 | 7 | # Keep in mind you can assign values other than :controller and :action |
|
8 | 8 | |
|
9 | 9 | # Allow Redmine plugins to map routes and potentially override them |
|
10 | 10 | Rails.plugins.each do |plugin| |
|
11 | 11 | map.from_plugin plugin.name.to_sym |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | map.home '', :controller => 'welcome' |
|
15 | 15 | |
|
16 | 16 | map.signin 'login', :controller => 'account', :action => 'login' |
|
17 | 17 | map.signout 'logout', :controller => 'account', :action => 'logout' |
|
18 | 18 | |
|
19 | 19 | map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' |
|
20 | 20 | map.connect 'help/:ctrl/:page', :controller => 'help' |
|
21 | 21 | |
|
22 | 22 | map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog' |
|
23 | 23 | map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog' |
|
24 | 24 | map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog' |
|
25 | 25 | |
|
26 | 26 | map.with_options :controller => 'timelog' do |timelog| |
|
27 | 27 | timelog.connect 'projects/:project_id/time_entries', :action => 'details' |
|
28 | 28 | |
|
29 | 29 | timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details| |
|
30 | 30 | time_details.connect 'time_entries' |
|
31 | 31 | time_details.connect 'time_entries.:format' |
|
32 | 32 | time_details.connect 'issues/:issue_id/time_entries' |
|
33 | 33 | time_details.connect 'issues/:issue_id/time_entries.:format' |
|
34 | 34 | time_details.connect 'projects/:project_id/time_entries.:format' |
|
35 | 35 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries' |
|
36 | 36 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format' |
|
37 | 37 | end |
|
38 | 38 | timelog.connect 'projects/:project_id/time_entries/report', :action => 'report' |
|
39 | 39 | timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report| |
|
40 | 40 | time_report.connect 'time_entries/report' |
|
41 | 41 | time_report.connect 'time_entries/report.:format' |
|
42 | 42 | time_report.connect 'projects/:project_id/time_entries/report.:format' |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit| |
|
46 | 46 | time_edit.connect 'issues/:issue_id/time_entries/new' |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post} |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post} |
|
53 | 53 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get} |
|
54 | 54 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post} |
|
55 | 55 | map.with_options :controller => 'wiki' do |wiki_routes| |
|
56 | 56 | wiki_routes.with_options :conditions => {:method => :get} do |wiki_views| |
|
57 | 57 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i |
|
58 | 58 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil |
|
59 | 59 | wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit' |
|
60 | 60 | wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename' |
|
61 | 61 | wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history' |
|
62 | 62 | wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff' |
|
63 | 63 | wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate' |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | wiki_routes.connect 'projects/:id/wiki/:page/:action', |
|
67 | 67 | :action => /edit|rename|destroy|preview|protect/, |
|
68 | 68 | :conditions => {:method => :post} |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | map.with_options :controller => 'messages' do |messages_routes| |
|
72 | 72 | messages_routes.with_options :conditions => {:method => :get} do |messages_views| |
|
73 | 73 | messages_views.connect 'boards/:board_id/topics/new', :action => 'new' |
|
74 | 74 | messages_views.connect 'boards/:board_id/topics/:id', :action => 'show' |
|
75 | 75 | messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit' |
|
76 | 76 | end |
|
77 | 77 | messages_routes.with_options :conditions => {:method => :post} do |messages_actions| |
|
78 | 78 | messages_actions.connect 'boards/:board_id/topics/new', :action => 'new' |
|
79 | 79 | messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply' |
|
80 | 80 | messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/ |
|
81 | 81 | end |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | map.with_options :controller => 'boards' do |board_routes| |
|
85 | 85 | board_routes.with_options :conditions => {:method => :get} do |board_views| |
|
86 | 86 | board_views.connect 'projects/:project_id/boards', :action => 'index' |
|
87 | 87 | board_views.connect 'projects/:project_id/boards/new', :action => 'new' |
|
88 | 88 | board_views.connect 'projects/:project_id/boards/:id', :action => 'show' |
|
89 | board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show' | |
|
89 | 90 | board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit' |
|
90 | 91 | end |
|
91 | 92 | board_routes.with_options :conditions => {:method => :post} do |board_actions| |
|
92 | 93 | board_actions.connect 'projects/:project_id/boards', :action => 'new' |
|
93 | 94 | board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/ |
|
94 | 95 | end |
|
95 | 96 | end |
|
96 | 97 | |
|
97 | 98 | map.with_options :controller => 'documents' do |document_routes| |
|
98 | 99 | document_routes.with_options :conditions => {:method => :get} do |document_views| |
|
99 | 100 | document_views.connect 'projects/:project_id/documents', :action => 'index' |
|
100 | 101 | document_views.connect 'projects/:project_id/documents/new', :action => 'new' |
|
101 | 102 | document_views.connect 'documents/:id', :action => 'show' |
|
102 | 103 | document_views.connect 'documents/:id/edit', :action => 'edit' |
|
103 | 104 | end |
|
104 | 105 | document_routes.with_options :conditions => {:method => :post} do |document_actions| |
|
105 | 106 | document_actions.connect 'projects/:project_id/documents', :action => 'new' |
|
106 | 107 | document_actions.connect 'documents/:id/:action', :action => /destroy|edit/ |
|
107 | 108 | end |
|
108 | 109 | end |
|
109 | 110 | |
|
110 | 111 | map.with_options :controller => 'issues' do |issues_routes| |
|
111 | 112 | issues_routes.with_options :conditions => {:method => :get} do |issues_views| |
|
112 | 113 | issues_views.connect 'issues', :action => 'index' |
|
113 | 114 | issues_views.connect 'issues.:format', :action => 'index' |
|
114 | 115 | issues_views.connect 'projects/:project_id/issues', :action => 'index' |
|
115 | 116 | issues_views.connect 'projects/:project_id/issues.:format', :action => 'index' |
|
116 | 117 | issues_views.connect 'projects/:project_id/issues/new', :action => 'new' |
|
117 | 118 | issues_views.connect 'projects/:project_id/issues/gantt', :action => 'gantt' |
|
118 | 119 | issues_views.connect 'projects/:project_id/issues/calendar', :action => 'calendar' |
|
119 | 120 | issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new' |
|
120 | 121 | issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/ |
|
121 | 122 | issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/ |
|
122 | 123 | issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/ |
|
123 | 124 | issues_views.connect 'issues/:id/move', :action => 'move', :id => /\d+/ |
|
124 | 125 | end |
|
125 | 126 | issues_routes.with_options :conditions => {:method => :post} do |issues_actions| |
|
126 | 127 | issues_actions.connect 'projects/:project_id/issues', :action => 'new' |
|
127 | 128 | issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ |
|
128 | 129 | issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/ |
|
129 | 130 | end |
|
130 | 131 | issues_routes.connect 'issues/:action' |
|
131 | 132 | end |
|
132 | 133 | |
|
133 | 134 | map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations| |
|
134 | 135 | relations.connect 'issues/:issue_id/relations/:id', :action => 'new' |
|
135 | 136 | relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy' |
|
136 | 137 | end |
|
137 | 138 | |
|
138 | 139 | map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports| |
|
139 | 140 | reports.connect 'projects/:id/issues/report' |
|
140 | 141 | reports.connect 'projects/:id/issues/report/:detail' |
|
141 | 142 | end |
|
142 | 143 | |
|
143 | 144 | map.with_options :controller => 'news' do |news_routes| |
|
144 | 145 | news_routes.with_options :conditions => {:method => :get} do |news_views| |
|
145 | 146 | news_views.connect 'news', :action => 'index' |
|
146 | 147 | news_views.connect 'projects/:project_id/news', :action => 'index' |
|
147 | 148 | news_views.connect 'projects/:project_id/news.:format', :action => 'index' |
|
148 | 149 | news_views.connect 'news.:format', :action => 'index' |
|
149 | 150 | news_views.connect 'projects/:project_id/news/new', :action => 'new' |
|
150 | 151 | news_views.connect 'news/:id', :action => 'show' |
|
151 | 152 | news_views.connect 'news/:id/edit', :action => 'edit' |
|
152 | 153 | end |
|
153 | 154 | news_routes.with_options do |news_actions| |
|
154 | 155 | news_actions.connect 'projects/:project_id/news', :action => 'new' |
|
155 | 156 | news_actions.connect 'news/:id/edit', :action => 'edit' |
|
156 | 157 | news_actions.connect 'news/:id/destroy', :action => 'destroy' |
|
157 | 158 | end |
|
158 | 159 | end |
|
159 | 160 | |
|
160 | 161 | map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new' |
|
161 | 162 | |
|
162 | 163 | map.with_options :controller => 'users' do |users| |
|
163 | 164 | users.with_options :conditions => {:method => :get} do |user_views| |
|
164 | 165 | user_views.connect 'users', :action => 'list' |
|
165 | 166 | user_views.connect 'users', :action => 'index' |
|
166 | 167 | user_views.connect 'users/new', :action => 'add' |
|
167 | 168 | user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil |
|
168 | 169 | end |
|
169 | 170 | users.with_options :conditions => {:method => :post} do |user_actions| |
|
170 | 171 | user_actions.connect 'users', :action => 'add' |
|
171 | 172 | user_actions.connect 'users/new', :action => 'add' |
|
172 | 173 | user_actions.connect 'users/:id/edit', :action => 'edit' |
|
173 | 174 | user_actions.connect 'users/:id/memberships', :action => 'edit_membership' |
|
174 | 175 | user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership' |
|
175 | 176 | user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership' |
|
176 | 177 | end |
|
177 | 178 | end |
|
178 | 179 | |
|
179 | 180 | map.with_options :controller => 'projects' do |projects| |
|
180 | 181 | projects.with_options :conditions => {:method => :get} do |project_views| |
|
181 | 182 | project_views.connect 'projects', :action => 'index' |
|
182 | 183 | project_views.connect 'projects.:format', :action => 'index' |
|
183 | 184 | project_views.connect 'projects/new', :action => 'add' |
|
184 | 185 | project_views.connect 'projects/:id', :action => 'show' |
|
185 | 186 | project_views.connect 'projects/:id/:action', :action => /roadmap|changelog|destroy|settings/ |
|
186 | 187 | project_views.connect 'projects/:id/files', :action => 'list_files' |
|
187 | 188 | project_views.connect 'projects/:id/files/new', :action => 'add_file' |
|
188 | 189 | project_views.connect 'projects/:id/versions/new', :action => 'add_version' |
|
189 | 190 | project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category' |
|
190 | 191 | project_views.connect 'projects/:id/settings/:tab', :action => 'settings' |
|
191 | 192 | end |
|
192 | 193 | |
|
193 | 194 | projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity| |
|
194 | 195 | activity.connect 'projects/:id/activity' |
|
195 | 196 | activity.connect 'projects/:id/activity.:format' |
|
196 | 197 | activity.connect 'activity', :id => nil |
|
197 | 198 | activity.connect 'activity.:format', :id => nil |
|
198 | 199 | end |
|
199 | 200 | |
|
200 | 201 | projects.with_options :conditions => {:method => :post} do |project_actions| |
|
201 | 202 | project_actions.connect 'projects/new', :action => 'add' |
|
202 | 203 | project_actions.connect 'projects', :action => 'add' |
|
203 | 204 | project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/ |
|
204 | 205 | project_actions.connect 'projects/:id/files/new', :action => 'add_file' |
|
205 | 206 | project_actions.connect 'projects/:id/versions/new', :action => 'add_version' |
|
206 | 207 | project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category' |
|
207 | 208 | end |
|
208 | 209 | end |
|
209 | 210 | |
|
210 | 211 | map.with_options :controller => 'repositories' do |repositories| |
|
211 | 212 | repositories.with_options :conditions => {:method => :get} do |repository_views| |
|
212 | 213 | repository_views.connect 'projects/:id/repository', :action => 'show' |
|
213 | 214 | repository_views.connect 'projects/:id/repository/edit', :action => 'edit' |
|
214 | 215 | repository_views.connect 'projects/:id/repository/statistics', :action => 'stats' |
|
215 | 216 | repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions' |
|
216 | 217 | repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions' |
|
217 | 218 | repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision' |
|
218 | 219 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff' |
|
219 | 220 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff' |
|
220 | 221 | repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path' |
|
221 | 222 | repository_views.connect 'projects/:id/repository/:action/*path' |
|
222 | 223 | end |
|
223 | 224 | |
|
224 | 225 | repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post} |
|
225 | 226 | end |
|
226 | 227 | |
|
227 | 228 | map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/ |
|
228 | 229 | map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/ |
|
229 | 230 | map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/ |
|
230 | 231 | |
|
231 | 232 | |
|
232 | 233 | #left old routes at the bottom for backwards compat |
|
233 | 234 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' |
|
234 | 235 | map.connect 'projects/:project_id/documents/:action', :controller => 'documents' |
|
235 | 236 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' |
|
236 | 237 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' |
|
237 | 238 | map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki' |
|
238 | 239 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' |
|
239 | 240 | map.connect 'projects/:project_id/news/:action', :controller => 'news' |
|
240 | 241 | map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/ |
|
241 | 242 | map.with_options :controller => 'repositories' do |omap| |
|
242 | 243 | omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse' |
|
243 | 244 | omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes' |
|
244 | 245 | omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff' |
|
245 | 246 | omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry' |
|
246 | 247 | omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate' |
|
247 | 248 | omap.connect 'repositories/revision/:id/:rev', :action => 'revision' |
|
248 | 249 | end |
|
249 | 250 | |
|
250 | 251 | map.with_options :controller => 'sys' do |sys| |
|
251 | 252 | sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get} |
|
252 | 253 | sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post} |
|
253 | 254 | end |
|
254 | 255 | |
|
255 | 256 | # Install the default route as the lowest priority. |
|
256 | 257 | map.connect ':controller/:action/:id' |
|
257 | 258 | map.connect 'robots.txt', :controller => 'welcome', :action => 'robots' |
|
258 | 259 | # Used for OpenID |
|
259 | 260 | map.root :controller => 'account', :action => 'login' |
|
260 | 261 | end |
@@ -1,133 +1,146 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'boards_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class BoardsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class BoardsControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = BoardsController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_index_routing |
|
35 | 35 | assert_routing( |
|
36 | 36 | {:method => :get, :path => '/projects/world_domination/boards'}, |
|
37 | 37 | :controller => 'boards', :action => 'index', :project_id => 'world_domination' |
|
38 | 38 | ) |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_index |
|
42 | 42 | get :index, :project_id => 1 |
|
43 | 43 | assert_response :success |
|
44 | 44 | assert_template 'index' |
|
45 | 45 | assert_not_nil assigns(:boards) |
|
46 | 46 | assert_not_nil assigns(:project) |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def test_index_not_found |
|
50 | 50 | get :index, :project_id => 97 |
|
51 | 51 | assert_response 404 |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_index_should_show_messages_if_only_one_board |
|
55 | 55 | Project.find(1).boards.slice(1..-1).each(&:destroy) |
|
56 | 56 | |
|
57 | 57 | get :index, :project_id => 1 |
|
58 | 58 | assert_response :success |
|
59 | 59 | assert_template 'show' |
|
60 | 60 | assert_not_nil assigns(:topics) |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def test_new_routing |
|
64 | 64 | assert_routing( |
|
65 | 65 | {:method => :get, :path => '/projects/world_domination/boards/new'}, |
|
66 | 66 | :controller => 'boards', :action => 'new', :project_id => 'world_domination' |
|
67 | 67 | ) |
|
68 | 68 | assert_recognizes( |
|
69 | 69 | {:controller => 'boards', :action => 'new', :project_id => 'world_domination'}, |
|
70 | 70 | {:method => :post, :path => '/projects/world_domination/boards'} |
|
71 | 71 | ) |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def test_post_new |
|
75 | 75 | @request.session[:user_id] = 2 |
|
76 | 76 | assert_difference 'Board.count' do |
|
77 | 77 | post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'} |
|
78 | 78 | end |
|
79 | 79 | assert_redirected_to '/projects/ecookbook/settings/boards' |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | def test_show_routing |
|
83 | 83 | assert_routing( |
|
84 | 84 | {:method => :get, :path => '/projects/world_domination/boards/44'}, |
|
85 | 85 | :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination' |
|
86 | 86 | ) |
|
87 | assert_routing( | |
|
88 | {:method => :get, :path => '/projects/world_domination/boards/44.atom'}, | |
|
89 | :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination', :format => 'atom' | |
|
90 | ) | |
|
87 | 91 | end |
|
88 | 92 | |
|
89 | 93 | def test_show |
|
90 | 94 | get :show, :project_id => 1, :id => 1 |
|
91 | 95 | assert_response :success |
|
92 | 96 | assert_template 'show' |
|
93 | 97 | assert_not_nil assigns(:board) |
|
94 | 98 | assert_not_nil assigns(:project) |
|
95 | 99 | assert_not_nil assigns(:topics) |
|
96 | 100 | end |
|
97 | 101 | |
|
102 | def test_show_atom | |
|
103 | get :show, :project_id => 1, :id => 1, :format => 'atom' | |
|
104 | assert_response :success | |
|
105 | assert_template 'common/feed.atom' | |
|
106 | assert_not_nil assigns(:board) | |
|
107 | assert_not_nil assigns(:project) | |
|
108 | assert_not_nil assigns(:messages) | |
|
109 | end | |
|
110 | ||
|
98 | 111 | def test_edit_routing |
|
99 | 112 | assert_routing( |
|
100 | 113 | {:method => :get, :path => '/projects/world_domination/boards/44/edit'}, |
|
101 | 114 | :controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination' |
|
102 | 115 | ) |
|
103 | 116 | assert_recognizes(#TODO: use PUT method to board_path, modify form accordingly |
|
104 | 117 | {:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'}, |
|
105 | 118 | {:method => :post, :path => '/projects/world_domination/boards/44/edit'} |
|
106 | 119 | ) |
|
107 | 120 | end |
|
108 | 121 | |
|
109 | 122 | def test_post_edit |
|
110 | 123 | @request.session[:user_id] = 2 |
|
111 | 124 | assert_no_difference 'Board.count' do |
|
112 | 125 | post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'} |
|
113 | 126 | end |
|
114 | 127 | assert_redirected_to '/projects/ecookbook/settings/boards' |
|
115 | 128 | assert_equal 'Testing', Board.find(2).name |
|
116 | 129 | end |
|
117 | 130 | |
|
118 | 131 | def test_destroy_routing |
|
119 | 132 | assert_routing(#TODO: use DELETE method to board_path, modify form accoringly |
|
120 | 133 | {:method => :post, :path => '/projects/world_domination/boards/44/destroy'}, |
|
121 | 134 | :controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination' |
|
122 | 135 | ) |
|
123 | 136 | end |
|
124 | 137 | |
|
125 | 138 | def test_post_destroy |
|
126 | 139 | @request.session[:user_id] = 2 |
|
127 | 140 | assert_difference 'Board.count', -1 do |
|
128 | 141 | post :destroy, :project_id => 1, :id => 2 |
|
129 | 142 | end |
|
130 | 143 | assert_redirected_to '/projects/ecookbook/settings/boards' |
|
131 | 144 | assert_nil Board.find_by_id(2) |
|
132 | 145 | end |
|
133 | 146 | end |
General Comments 0
You need to be logged in to leave comments.
Login now