summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-31 17:17:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-07-31 17:17:52 +0000
commitbc153cb61df37e2097c5bec529cabdb15e6887bf (patch)
tree05be0525dc3258c00349e7cc6b5ab333ca4139c0 /app
parent9554f0133ff634264eb110c91ad317be28e6dd32 (diff)
downloadredmine-bc153cb61df37e2097c5bec529cabdb15e6887bf.tar.gz
redmine-bc153cb61df37e2097c5bec529cabdb15e6887bf.zip
Support for subforums (#3831).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10142 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/messages_controller.rb1
-rw-r--r--app/helpers/boards_helper.rb20
-rw-r--r--app/models/board.rb37
-rw-r--r--app/views/boards/_form.html.erb3
-rw-r--r--app/views/boards/index.html.erb4
-rw-r--r--app/views/boards/show.html.erb2
-rw-r--r--app/views/messages/_form.html.erb2
-rw-r--r--app/views/messages/edit.html.erb3
-rw-r--r--app/views/messages/show.html.erb3
-rw-r--r--app/views/projects/settings/_boards.html.erb4
10 files changed, 67 insertions, 12 deletions
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 6b154a81c..7ac7aa365 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -22,6 +22,7 @@ class MessagesController < ApplicationController
before_filter :find_message, :except => [:new, :preview]
before_filter :authorize, :except => [:preview, :edit, :destroy]
+ helper :boards
helper :watchers
helper :attachments
include AttachmentsHelper
diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb
index eb6257784..85d526c22 100644
--- a/app/helpers/boards_helper.rb
+++ b/app/helpers/boards_helper.rb
@@ -18,4 +18,24 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module BoardsHelper
+ def board_breadcrumb(item)
+ board = item.is_a?(Message) ? item.board : item
+ links = [link_to(l(:label_board_plural), project_boards_path(item.project))]
+ boards = board.ancestors.reverse
+ if item.is_a?(Message)
+ boards << board
+ end
+ links += boards.map {|ancestor| link_to(h(ancestor.name), project_board_path(ancestor.project, ancestor))}
+ breadcrumb links
+ end
+
+ def boards_options_for_select(boards)
+ options = []
+ Board.board_tree(boards) do |board, level|
+ label = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
+ label << board.name
+ options << [label, board.id]
+ end
+ options
+ end
end
diff --git a/app/models/board.rb b/app/models/board.rb
index 0b7d36667..42b5499e1 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -21,26 +21,37 @@ class Board < ActiveRecord::Base
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
- acts_as_list :scope => :project_id
+ acts_as_tree :dependent => :nullify
+ acts_as_list :scope => '(project_id = #{project_id} AND parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"})'
acts_as_watchable
validates_presence_of :name, :description
validates_length_of :name, :maximum => 30
validates_length_of :description, :maximum => 255
+ validate :validate_board
scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
- safe_attributes 'name', 'description', 'move_to'
+ safe_attributes 'name', 'description', 'parent_id', 'move_to'
def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_messages, project)
end
+ def reload(*args)
+ @valid_parents = nil
+ super
+ end
+
def to_s
name
end
+ def valid_parents
+ @valid_parents ||= project.boards - self_and_descendants
+ end
+
def reset_counters!
self.class.reset_counters!(id)
end
@@ -53,4 +64,26 @@ class Board < ActiveRecord::Base
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
["id = ?", board_id])
end
+
+ def self.board_tree(boards, parent_id=nil, level=0)
+ tree = []
+ boards.select {|board| board.parent_id == parent_id}.sort_by(&:position).each do |board|
+ tree << [board, level]
+ tree += board_tree(boards, board.id, level+1)
+ end
+ if block_given?
+ tree.each do |board, level|
+ yield board, level
+ end
+ end
+ tree
+ end
+
+ protected
+
+ def validate_board
+ if parent_id && parent_id_changed?
+ errors.add(:parent_id, :invalid) unless valid_parents.include?(parent)
+ end
+ end
end
diff --git a/app/views/boards/_form.html.erb b/app/views/boards/_form.html.erb
index 736028bb1..daaecee53 100644
--- a/app/views/boards/_form.html.erb
+++ b/app/views/boards/_form.html.erb
@@ -3,4 +3,7 @@
<div class="box tabular">
<p><%= f.text_field :name, :required => true %></p>
<p><%= f.text_field :description, :required => true, :size => 80 %></p>
+<% if @board.valid_parents.any? %>
+<p><%= f.select :parent_id, boards_options_for_select(@board.valid_parents), :include_blank => true, :label => :field_board_parent %></p>
+<% end %>
</div>
diff --git a/app/views/boards/index.html.erb b/app/views/boards/index.html.erb
index c516b947f..3caa08d3c 100644
--- a/app/views/boards/index.html.erb
+++ b/app/views/boards/index.html.erb
@@ -8,9 +8,9 @@
<th><%= l(:label_message_last) %></th>
</tr></thead>
<tbody>
-<% for board in @boards %>
+<% Board.board_tree(@boards) do |board, level| %>
<tr class="<%= cycle 'odd', 'even' %>">
- <td>
+ <td style="padding-left: <%= level * 18 %>px;">
<%= link_to h(board.name), {:action => 'show', :id => board}, :class => "board" %><br />
<%=h board.description %>
</td>
diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb
index 1effcb3f9..784c58a52 100644
--- a/app/views/boards/show.html.erb
+++ b/app/views/boards/show.html.erb
@@ -1,4 +1,4 @@
-<%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)) %>
+<%= board_breadcrumb(@board) %>
<div class="contextual">
<%= link_to_if_authorized l(:label_message_new),
diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb
index f7cd8e367..d9f48af5c 100644
--- a/app/views/messages/_form.html.erb
+++ b/app/views/messages/_form.html.erb
@@ -18,7 +18,7 @@
<% if !replying && !@message.new_record? && @message.safe_attribute?('board_id') %>
<p><label><%= l(:label_board) %></label><br />
- <%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p>
+ <%= f.select :board_id, boards_options_for_select(@message.project.boards) %></p>
<% end %>
<p>
diff --git a/app/views/messages/edit.html.erb b/app/views/messages/edit.html.erb
index fdea28e87..7ce0560bb 100644
--- a/app/views/messages/edit.html.erb
+++ b/app/views/messages/edit.html.erb
@@ -1,5 +1,4 @@
-<%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)),
- link_to(h(@board.name), project_board_path(@project, @board)) %>
+<%= board_breadcrumb(@message) %>
<h2><%= avatar(@topic.author, :size => "24") %><%=h @topic.subject %></h2>
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb
index 8e9ecceca..db9a2c8af 100644
--- a/app/views/messages/show.html.erb
+++ b/app/views/messages/show.html.erb
@@ -1,5 +1,4 @@
-<%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)),
- link_to(h(@board.name), project_board_path(@project, @board)) %>
+<%= board_breadcrumb(@message) %>
<div class="contextual">
<%= watcher_tag(@topic, User.current) %>
diff --git a/app/views/projects/settings/_boards.html.erb b/app/views/projects/settings/_boards.html.erb
index 1d095c232..1050ef70c 100644
--- a/app/views/projects/settings/_boards.html.erb
+++ b/app/views/projects/settings/_boards.html.erb
@@ -7,10 +7,10 @@
<th></th>
</tr></thead>
<tbody>
-<% @project.boards.each do |board|
+<% Board.board_tree(@project.boards) do |board, level|
next if board.new_record? %>
<tr class="<%= cycle 'odd', 'even' %>">
- <td><%= link_to board.name, project_board_path(@project, board) %></td>
+ <td style="padding-left: <%= level * 18 %>px;"><%= link_to board.name, project_board_path(@project, board) %></td>
<td><%=h board.description %></td>
<td align="center">
<% if authorize_for("boards", "edit") %>