From b90e84b9fe252df464d084f0222c65367407a4ba Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 13 May 2007 17:09:56 +0000 Subject: [PATCH] Per project forums added. Permissions for forums management can be set in "Admin -> Roles & Permissions". Forums can be created on the project settings screen ("Forums" tab). Once a project has a forum, a "Forums" link appears in the project menu. For now, posting messages in forums requires to be logged in. Files can be attached to messages. git-svn-id: http://redmine.rubyforge.org/svn/trunk@529 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/boards_controller.rb | 87 +++++++++++++++++++++++ app/controllers/messages_controller.rb | 66 +++++++++++++++++ app/helpers/application_helper.rb | 5 ++ app/helpers/boards_helper.rb | 19 +++++ app/helpers/messages_helper.rb | 28 ++++++++ app/models/board.rb | 28 ++++++++ app/models/message.rb | 37 ++++++++++ app/models/permission.rb | 3 +- app/models/project.rb | 1 + app/views/boards/_form.rhtml | 8 +++ app/views/boards/edit.rhtml | 6 ++ app/views/boards/index.rhtml | 30 ++++++++ app/views/boards/new.rhtml | 6 ++ app/views/boards/show.rhtml | 36 ++++++++++ app/views/layouts/base.rhtml | 2 + app/views/messages/_form.rhtml | 17 +++++ app/views/messages/new.rhtml | 6 ++ app/views/messages/show.rhtml | 29 ++++++++ app/views/projects/_boards.rhtml | 24 +++++++ app/views/projects/settings.rhtml | 5 ++ config/routes.rb | 2 + db/migrate/045_create_boards.rb | 18 +++++ db/migrate/046_create_messages.rb | 21 ++++++ db/migrate/047_add_boards_permissions.rb | 13 ++++ lang/bg.yml | 9 +++ lang/de.yml | 9 +++ lang/en.yml | 9 +++ lang/es.yml | 9 +++ lang/fr.yml | 9 +++ lang/it.yml | 9 +++ lang/ja.yml | 9 +++ lang/pt-br.yml | 9 +++ lang/pt.yml | 9 +++ lang/zh.yml | 9 +++ public/images/22x22/comment.png | Bin 520 -> 1078 bytes public/stylesheets/application.css | 2 + test/fixtures/boards.yml | 19 +++++ test/fixtures/messages.yml | 25 +++++++ test/unit/board_test.rb | 30 ++++++++ test/unit/message_test.rb | 44 ++++++++++++ 40 files changed, 706 insertions(+), 1 deletion(-) create mode 100644 app/controllers/boards_controller.rb create mode 100644 app/controllers/messages_controller.rb create mode 100644 app/helpers/boards_helper.rb create mode 100644 app/helpers/messages_helper.rb create mode 100644 app/models/board.rb create mode 100644 app/models/message.rb create mode 100644 app/views/boards/_form.rhtml create mode 100644 app/views/boards/edit.rhtml create mode 100644 app/views/boards/index.rhtml create mode 100644 app/views/boards/new.rhtml create mode 100644 app/views/boards/show.rhtml create mode 100644 app/views/messages/_form.rhtml create mode 100644 app/views/messages/new.rhtml create mode 100644 app/views/messages/show.rhtml create mode 100644 app/views/projects/_boards.rhtml create mode 100644 db/migrate/045_create_boards.rb create mode 100644 db/migrate/046_create_messages.rb create mode 100644 db/migrate/047_add_boards_permissions.rb create mode 100644 test/fixtures/boards.yml create mode 100644 test/fixtures/messages.yml create mode 100644 test/unit/board_test.rb create mode 100644 test/unit/message_test.rb diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb new file mode 100644 index 000000000..b3be6b7a2 --- /dev/null +++ b/app/controllers/boards_controller.rb @@ -0,0 +1,87 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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 BoardsController < ApplicationController + layout 'base' + before_filter :find_project + before_filter :authorize, :except => [:index, :show] + before_filter :check_project_privacy, :only => [:index, :show] + + helper :messages + include MessagesHelper + helper :sort + include SortHelper + + def index + @boards = @project.boards + # show the board if there is only one + if @boards.size == 1 + @board = @boards.first + show + render :action => 'show' + end + end + + def show + sort_init "#{Message.table_name}.updated_on", "desc" + sort_update + + @topic_count = @board.topics.count + @topic_pages = Paginator.new self, @topic_count, 25, params['page'] + @topics = @board.topics.find :all, :order => sort_clause, + :include => [:author, {:last_reply => :author}], + :limit => @topic_pages.items_per_page, + :offset => @topic_pages.current.offset + render :action => 'show', :layout => false if request.xhr? + end + + verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index } + + def new + @board = Board.new(params[:board]) + @board.project = @project + if request.post? && @board.save + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' + end + end + + def edit + if request.post? && @board.update_attributes(params[:board]) + case params[:position] + when 'highest'; @board.move_to_top + when 'higher'; @board.move_higher + when 'lower'; @board.move_lower + when 'lowest'; @board.move_to_bottom + end if params[:position] + redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' + end + end + + def destroy + @board.destroy + redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' + end + +private + def find_project + @project = Project.find(params[:project_id]) + @board = @project.boards.find(params[:id]) if params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb new file mode 100644 index 000000000..16a04097f --- /dev/null +++ b/app/controllers/messages_controller.rb @@ -0,0 +1,66 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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 MessagesController < ApplicationController + layout 'base' + before_filter :find_project, :check_project_privacy + before_filter :require_login, :only => [:new, :reply] + + verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } + + def show + @reply = Message.new(:subject => "RE: #{@message.subject}") + render :action => "show", :layout => false if request.xhr? + end + + def new + @message = Message.new(params[:message]) + @message.author = logged_in_user + @message.board = @board + if request.post? && @message.save + params[:attachments].each { |file| + next unless file.size > 0 + Attachment.create(:container => @message, :file => file, :author => logged_in_user) + } if params[:attachments] and params[:attachments].is_a? Array + redirect_to :action => 'show', :id => @message + end + end + + def reply + @reply = Message.new(params[:reply]) + @reply.author = logged_in_user + @reply.board = @board + @message.children << @reply + redirect_to :action => 'show', :id => @message + end + + def download + @attachment = @message.attachments.find(params[:attachment_id]) + send_file @attachment.diskfile, :filename => @attachment.filename + rescue + render_404 + end + +private + def find_project + @board = Board.find(params[:board_id], :include => :project) + @project = @board.project + @message = @board.topics.find(params[:id]) if params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f5d262961..cd1b2ea09 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -215,6 +215,11 @@ module ApplicationHelper image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") end + + def wikitoolbar_for(field_id) + return '' unless Setting.text_formatting == 'textile' + javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();") + end end class TabularFormBuilder < ActionView::Helpers::FormBuilder diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb new file mode 100644 index 000000000..3719e0fe8 --- /dev/null +++ b/app/helpers/boards_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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. + +module BoardsHelper +end diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb new file mode 100644 index 000000000..bf23275c3 --- /dev/null +++ b/app/helpers/messages_helper.rb @@ -0,0 +1,28 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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. + +module MessagesHelper + + def link_to_message(message) + return '' unless message + link_to h(truncate(message.subject, 60)), :controller => 'messages', + :action => 'show', + :board_id => message.board_id, + :id => message.root, + :anchor => (message.parent_id ? "message-#{message.id}" : nil) + end +end diff --git a/app/models/board.rb b/app/models/board.rb new file mode 100644 index 000000000..a6ea22f67 --- /dev/null +++ b/app/models/board.rb @@ -0,0 +1,28 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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 Board < ActiveRecord::Base + belongs_to :project + 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 => :delete_all, :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 + + validates_presence_of :name, :description + validates_length_of :name, :maximum => 30 + validates_length_of :description, :maximum => 255 +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 000000000..1f8dde540 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,37 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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 Message < ActiveRecord::Base + belongs_to :board + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" + has_many :attachments, :as => :container, :dependent => :destroy + belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' + + validates_presence_of :subject, :content + validates_length_of :subject, :maximum => 255 + + def after_create + board.update_attribute(:last_message_id, self.id) + board.increment! :messages_count + if parent + parent.reload.update_attribute(:last_reply_id, self.id) + else + board.increment! :topics_count + end + end +end diff --git a/app/models/permission.rb b/app/models/permission.rb index 609d5d561..f78118d86 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -31,7 +31,8 @@ class Permission < ActiveRecord::Base 1200 => :label_document_plural, 1300 => :label_attachment_plural, 1400 => :label_repository, - 1500 => :label_time_tracking + 1500 => :label_time_tracking, + 2000 => :label_board_plural }.freeze @@cached_perms_for_public = nil diff --git a/app/models/project.rb b/app/models/project.rb index 018efe37e..6dd6b2644 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -26,6 +26,7 @@ class Project < ActiveRecord::Base has_many :documents, :dependent => :destroy has_many :news, :dependent => :delete_all, :include => :author has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" + has_many :boards, :order => "position ASC" has_one :repository, :dependent => :destroy has_one :wiki, :dependent => :destroy has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' diff --git a/app/views/boards/_form.rhtml b/app/views/boards/_form.rhtml new file mode 100644 index 000000000..7ede589ab --- /dev/null +++ b/app/views/boards/_form.rhtml @@ -0,0 +1,8 @@ +<%= error_messages_for 'board' %> + + +
+

<%= f.text_field :name, :required => true %>

+

<%= f.text_field :description, :required => true, :size => 80 %>

+
+ diff --git a/app/views/boards/edit.rhtml b/app/views/boards/edit.rhtml new file mode 100644 index 000000000..ba4c8b5ac --- /dev/null +++ b/app/views/boards/edit.rhtml @@ -0,0 +1,6 @@ +

<%= l(:label_board) %>

+ +<% labelled_tabular_form_for :board, @board, :url => {:action => 'edit', :id => @board} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <%= submit_tag l(:button_save) %> +<% end %> diff --git a/app/views/boards/index.rhtml b/app/views/boards/index.rhtml new file mode 100644 index 000000000..3291d0194 --- /dev/null +++ b/app/views/boards/index.rhtml @@ -0,0 +1,30 @@ +

<%= l(:label_board_plural) %>

+ + + + + + + + + +<% for board in @boards %> + + + + + + +<% end %> + +
<%= l(:label_board) %><%= l(:label_topic_plural) %><%= l(:label_message_plural) %><%= l(:label_message_last) %>
+ <%= link_to h(board.name), {:action => 'show', :id => board}, :class => "icon22 icon22-comment" %>
+ <%=h board.description %> +
<%= board.topics_count %><%= board.messages_count %> + + <% if board.last_message %> + <%= board.last_message.author.name %>, <%= format_time(board.last_message.created_on) %>
+ <%= link_to_message board.last_message %> + <% end %> +
+
diff --git a/app/views/boards/new.rhtml b/app/views/boards/new.rhtml new file mode 100644 index 000000000..b89121880 --- /dev/null +++ b/app/views/boards/new.rhtml @@ -0,0 +1,6 @@ +

<%= l(:label_board_new) %>

+ +<% labelled_tabular_form_for :board, @board, :url => {:action => 'new'} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <%= submit_tag l(:button_create) %> +<% end %> diff --git a/app/views/boards/show.rhtml b/app/views/boards/show.rhtml new file mode 100644 index 000000000..13a056046 --- /dev/null +++ b/app/views/boards/show.rhtml @@ -0,0 +1,36 @@ +
+<%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %> +
+ +

<%=h @board.name %>

+ + + + + + <%= sort_header_tag("#{Message.table_name}.created_on", :caption => l(:field_created_on)) %> + + <%= sort_header_tag("#{Message.table_name}.updated_on", :caption => l(:label_message_last)) %> + + + <% @topics.each do |topic| %> + + + + + + + + <% end %> + +
<%= l(:field_subject) %><%= l(:field_author) %><%= l(:label_reply_plural) %>
<%= link_to h(topic.subject), :controller => 'messages', :action => 'show', :board_id => @board, :id => topic %><%= link_to_user topic.author %><%= format_time(topic.created_on) %><%= topic.replies_count %> + + <% if topic.last_reply %> + <%= topic.last_reply.author.name %>, <%= format_time(topic.last_reply.created_on) %>
+ <%= link_to_message topic.last_reply %> + <% end %> +
+
+ +

<%= pagination_links_full @topic_pages %> +[ <%= @topic_pages.current.first_item %> - <%= @topic_pages.current.last_item %> / <%= @topic_count %> ]

diff --git a/app/views/layouts/base.rhtml b/app/views/layouts/base.rhtml index 5d23f6bbc..db9356f7f 100644 --- a/app/views/layouts/base.rhtml +++ b/app/views/layouts/base.rhtml @@ -79,6 +79,7 @@ <%= link_to l(:label_roadmap), {:controller => 'projects', :action => 'roadmap', :id => @project }, :class => "menuItem" %> <%= link_to l(:label_document_plural), {:controller => 'projects', :action => 'list_documents', :id => @project }, :class => "menuItem" %> <%= link_to l(:label_wiki), {:controller => 'wiki', :id => @project, :page => nil }, :class => "menuItem" if @project.wiki and !@project.wiki.new_record? %> + <%= link_to l(:label_board_plural), {:controller => 'boards', :project_id => @project }, :class => "menuItem" unless @project.boards.empty? %> <%= link_to l(:label_attachment_plural), {:controller => 'projects', :action => 'list_files', :id => @project }, :class => "menuItem" %> <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project }, :class => "menuItem" %> <%= link_to l(:label_repository), {:controller => 'repositories', :action => 'show', :id => @project}, :class => "menuItem" if @project.repository and !@project.repository.new_record? %> @@ -103,6 +104,7 @@
  • <%= link_to l(:label_roadmap), :controller => 'projects', :action => 'roadmap', :id => @project %>
  • <%= link_to l(:label_document_plural), :controller => 'projects', :action => 'list_documents', :id => @project %>
  • <%= content_tag("li", link_to(l(:label_wiki), :controller => 'wiki', :id => @project, :page => nil)) if @project.wiki and !@project.wiki.new_record? %> + <%= content_tag("li", link_to(l(:label_board_plural), :controller => 'boards', :project_id => @project)) unless @project.boards.empty? %>
  • <%= link_to l(:label_attachment_plural), :controller => 'projects', :action => 'list_files', :id => @project %>
  • <%= link_to l(:label_search), :controller => 'search', :action => 'index', :id => @project %>
  • <%= content_tag("li", link_to(l(:label_repository), :controller => 'repositories', :action => 'show', :id => @project)) if @project.repository and !@project.repository.new_record? %> diff --git a/app/views/messages/_form.rhtml b/app/views/messages/_form.rhtml new file mode 100644 index 000000000..453bd8b2a --- /dev/null +++ b/app/views/messages/_form.rhtml @@ -0,0 +1,17 @@ +<%= error_messages_for 'message' %> + +
    + +


    +<%= f.text_field :subject, :required => true, :size => 80 %>

    + +

    <%= f.text_area :content, :required => true, :cols => 80, :rows => 15 %>

    +<%= wikitoolbar_for 'message_content' %> + + + +

    +<%= file_field_tag 'attachments[]', :size => 30 %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

    +
    +
    diff --git a/app/views/messages/new.rhtml b/app/views/messages/new.rhtml new file mode 100644 index 000000000..5c688f465 --- /dev/null +++ b/app/views/messages/new.rhtml @@ -0,0 +1,6 @@ +

    <%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %>

    + +<% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <%= submit_tag l(:button_create) %> +<% end %> diff --git a/app/views/messages/show.rhtml b/app/views/messages/show.rhtml new file mode 100644 index 000000000..8f3d83a7e --- /dev/null +++ b/app/views/messages/show.rhtml @@ -0,0 +1,29 @@ +

    <%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%=h @message.subject %>

    + +

    <%= @message.author.name %>, <%= format_time(@message.created_on) %>

    +
    +<%= textilizable(@message.content) %> +
    +
    +<% @message.attachments.each do |attachment| %> +<%= link_to attachment.filename, { :action => 'download', :id => @message, :attachment_id => attachment }, :class => 'icon icon-attachment' %> +(<%= number_to_human_size(attachment.filesize) %>)
    +<% end %> +
    +
    +

    <%= l(:label_reply_plural) %>

    +<% @message.children.each do |message| %> + "> +

    <%=h message.subject %> - <%= message.author.name %>, <%= format_time(message.created_on) %>

    +

    <%= textilizable message.content %>

    +<% end %> + +

    <%= toggle_link l(:button_reply), "reply", :focus => "reply_content" %>

    + diff --git a/app/views/projects/_boards.rhtml b/app/views/projects/_boards.rhtml new file mode 100644 index 000000000..e3f4629c1 --- /dev/null +++ b/app/views/projects/_boards.rhtml @@ -0,0 +1,24 @@ + + + +<% @project.boards.each do |board| + next if board.new_record? %> + + + + + + + +<% end %> + +
    <%= l(:label_board) %><%= l(:field_description) %>
    <%=h board.name %><%=h board.description %> + <% if authorize_for("boards", "edit") %> + <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %> + <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> - + <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %> + <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %> + <% end %> + <%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %><%= link_to_if_authorized l(:button_delete), {:controller => 'boards', :action => 'destroy', :project_id => @project, :id => board}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
    +  +

    <%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project} %>

    diff --git a/app/views/projects/settings.rhtml b/app/views/projects/settings.rhtml index 3405bfb64..81150dd54 100644 --- a/app/views/projects/settings.rhtml +++ b/app/views/projects/settings.rhtml @@ -6,6 +6,7 @@
  • <%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %>
  • <%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %>
  • <%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %>
  • +
  • <%= link_to l(:label_board_plural), {}, :id=> "tab-boards", :onclick => "showTab('boards'); this.blur(); return false;" %>
  • @@ -76,5 +77,9 @@ <% end %> + + <%= tab = params[:tab] ? h(params[:tab]) : 'info' javascript_tag "showTab('#{tab}');" %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8e2670a99..a980f3f51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,8 @@ ActionController::Routing::Routes.draw do |map| #map.connect ':controller/:action/:id/:sort_key/:sort_order' map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' + map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' + map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' # Allow downloading Web Service WSDL as a file with an extension # instead of a file named 'wsdl' diff --git a/db/migrate/045_create_boards.rb b/db/migrate/045_create_boards.rb new file mode 100644 index 000000000..b8647c812 --- /dev/null +++ b/db/migrate/045_create_boards.rb @@ -0,0 +1,18 @@ +class CreateBoards < ActiveRecord::Migration + def self.up + create_table :boards do |t| + t.column :project_id, :integer, :null => false + t.column :name, :string, :default => "", :null => false + t.column :description, :string + t.column :position, :integer, :default => 1, :null => false + t.column :topics_count, :integer, :default => 0, :null => false + t.column :messages_count, :integer, :default => 0, :null => false + t.column :last_message_id, :integer + end + add_index :boards, [:project_id], :name => :boards_project_id + end + + def self.down + drop_table :boards + end +end diff --git a/db/migrate/046_create_messages.rb b/db/migrate/046_create_messages.rb new file mode 100644 index 000000000..d99aaf842 --- /dev/null +++ b/db/migrate/046_create_messages.rb @@ -0,0 +1,21 @@ +class CreateMessages < ActiveRecord::Migration + def self.up + create_table :messages do |t| + t.column :board_id, :integer, :null => false + t.column :parent_id, :integer + t.column :subject, :string, :default => "", :null => false + t.column :content, :text + t.column :author_id, :integer + t.column :replies_count, :integer, :default => 0, :null => false + t.column :last_reply_id, :integer + t.column :created_on, :datetime, :null => false + t.column :updated_on, :datetime, :null => false + end + add_index :messages, [:board_id], :name => :messages_board_id + add_index :messages, [:parent_id], :name => :messages_parent_id + end + + def self.down + drop_table :messages + end +end diff --git a/db/migrate/047_add_boards_permissions.rb b/db/migrate/047_add_boards_permissions.rb new file mode 100644 index 000000000..cafdc1eac --- /dev/null +++ b/db/migrate/047_add_boards_permissions.rb @@ -0,0 +1,13 @@ +class AddBoardsPermissions < ActiveRecord::Migration + def self.up + Permission.create :controller => "boards", :action => "new", :description => "button_add", :sort => 2000, :is_public => false, :mail_option => 0, :mail_enabled => 0 + Permission.create :controller => "boards", :action => "edit", :description => "button_edit", :sort => 2005, :is_public => false, :mail_option => 0, :mail_enabled => 0 + Permission.create :controller => "boards", :action => "destroy", :description => "button_delete", :sort => 2010, :is_public => false, :mail_option => 0, :mail_enabled => 0 + end + + def self.down + Permission.find_by_controller_and_action("boards", "new").destroy + Permission.find_by_controller_and_action("boards", "edit").destroy + Permission.find_by_controller_and_action("boards", "destroy").destroy + end +end diff --git a/lang/bg.yml b/lang/bg.yml index fb8e4b8dc..9c750b2e7 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Вход button_submit: Изпращане @@ -413,6 +421,7 @@ button_log_time: Отделяне на време button_rollback: Върни се към тази ревизия button_watch: Наблюдавай button_unwatch: Спри наблюдението +button_reply: Reply status_active: активен status_registered: регистриран diff --git a/lang/de.yml b/lang/de.yml index fa4125391..9d8b30292 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Einloggen button_submit: OK @@ -413,6 +421,7 @@ button_log_time: Log time button_rollback: Rollback to this version button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: aktiv status_registered: angemeldet diff --git a/lang/en.yml b/lang/en.yml index 2e1ff6e1b..574abcd58 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Login button_submit: Submit @@ -413,6 +421,7 @@ button_log_time: Log time button_rollback: Rollback to this version button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: active status_registered: registered diff --git a/lang/es.yml b/lang/es.yml index 56d251426..22373b3c6 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Conexión button_submit: Someter @@ -413,6 +421,7 @@ button_log_time: Log time button_rollback: Rollback to this version button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: active status_registered: registered diff --git a/lang/fr.yml b/lang/fr.yml index 3da0c1cef..20925ac3e 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Rester connecté label_disabled: désactivé label_show_completed_versions: Voire les versions passées label_me: moi +label_board: Forum +label_board_new: Nouveau forum +label_board_plural: Forums +label_topic_plural: Discussions +label_message_plural: Messages +label_message_last: Dernier message +label_message_new: Nouveau message +label_reply_plural: Réponses button_login: Connexion button_submit: Soumettre @@ -413,6 +421,7 @@ button_log_time: Saisir temps button_rollback: Revenir à cette version button_watch: Surveiller button_unwatch: Ne plus surveiller +button_reply: Répondre status_active: actif status_registered: enregistré diff --git a/lang/it.yml b/lang/it.yml index 1f61077c9..6188fbc8a 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Login button_submit: Invia @@ -413,6 +421,7 @@ button_log_time: Registra tempo button_rollback: Ripristina questa versione button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: attivo status_registered: registrato diff --git a/lang/ja.yml b/lang/ja.yml index 45acde369..ee1d49b43 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -386,6 +386,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: ログイン button_submit: 変更 @@ -414,6 +422,7 @@ button_log_time: 時間を記録 button_rollback: このバージョンにロールバック button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: 有効 status_registered: 登録 diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 6f127a4ca..e02e278b4 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Login button_submit: Enviar @@ -413,6 +421,7 @@ button_log_time: Tempo de trabalho button_rollback: Voltar para esta versao button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: ativo status_registered: registrado diff --git a/lang/pt.yml b/lang/pt.yml index 0809b3588..b9f833f6a 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -385,6 +385,14 @@ label_stay_logged_in: Rester connecté label_disabled: désactivé label_show_completed_versions: Voire les versions passées label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: Login button_submit: Enviar @@ -413,6 +421,7 @@ button_log_time: Tempo de trabalho button_rollback: Voltar para esta versão button_watch: Observar button_unwatch: Não observar +button_reply: Reply status_active: ativo status_registered: registrado diff --git a/lang/zh.yml b/lang/zh.yml index 4e8e3f38b..aa768e815 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -388,6 +388,14 @@ label_stay_logged_in: Stay logged in label_disabled: disabled label_show_completed_versions: Show completed versions label_me: me +label_board: Forum +label_board_new: New forum +label_board_plural: Forums +label_topic_plural: Topics +label_message_plural: Messages +label_message_last: Last message +label_message_new: New message +label_reply_plural: Replies button_login: 登录 button_submit: 提交 @@ -416,6 +424,7 @@ button_log_time: 登记工时 button_rollback: Rollback to this version button_watch: Watch button_unwatch: Unwatch +button_reply: Reply status_active: 激活 status_registered: 已注册 diff --git a/public/images/22x22/comment.png b/public/images/22x22/comment.png index c5186abd9857e715283d7d2dbcad8091fb41f9c0..e2f4e701ca50d3b8bb201796a68f9d725cce1230 100644 GIT binary patch literal 1078 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H3?x5i&EW)6dL^zACC){ui6xo&c?uz!xv2~( znYnrj<_cMfd1ZPEMg|7v3WkSQnR^mS#w&dS3rtRuI( zBp)cmS>O>_%)r3)0fZTy)|kuy3bLd-`Z_W&Z0zU$lgP@zz|0Wf6XJUA+_`JluHCzL z@A>oR@87@w{{8!Z28REmU^E0qMhJwhDoX+9p&-9th>sbhyqVpALOGr;jv*Dd_FfF+ zYcSwozOb#~&i`XZ>Jwe|zkM#9xZ&Xso_`68wYJRBaSc;?_2psj(sybm{H4Z4#kWEP zD>weWcEjt&QO5Vjym$X%(A2)<zy?WJ~uWEc%|Gx98 YPYB_x+ss#A3AC5N)78&qol`;+0CP}etpET3 delta 441 zcmV;q0Y?6|2#5rb83+OZ002wY`)rXRM1KJX5-BBfxT}l+000SaNLh0L01FZT01FZU z(%pXi00004XF*Lt006O%3;baP00049Nkl<(RRTPD;fZTN*REnZV(^Qfq*L9iDL;~~E>15kB z4)KfKFQ9_4s;Vr@JkO&llPu2Xv*S3A{C)~N4QGNNn8%6JaK2nFc~Qz?Dr|!L@Ao?< z6Nx;}*XuRUXXbfw+qNL%K6ts^ZhsRAq>UgE7{X)s^W>&!>bjCY j*LD3RlY#vIwHUquVK^rzLA*ZS00000NkvXXu0mjfUf;|Z diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 0503e36fb..48079adf8 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -475,6 +475,8 @@ position: relative; margin: 0 5px 5px; } +div.attachments {padding-left: 6px; border-left: 2px solid #ccc;} + .overlay{ position: absolute; margin-left:0; diff --git a/test/fixtures/boards.yml b/test/fixtures/boards.yml new file mode 100644 index 000000000..7f2944fac --- /dev/null +++ b/test/fixtures/boards.yml @@ -0,0 +1,19 @@ +--- +boards_001: + name: Help + project_id: 1 + topics_count: 1 + id: 1 + description: Help board + position: 1 + last_message_id: 2 + messages_count: 2 +boards_002: + name: Discussion + project_id: 1 + topics_count: 0 + id: 2 + description: Discussion board + position: 2 + last_message_id: + messages_count: 0 diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml new file mode 100644 index 000000000..88f54dbc2 --- /dev/null +++ b/test/fixtures/messages.yml @@ -0,0 +1,25 @@ +--- +messages_001: + created_on: 2007-05-12 17:15:32 +02:00 + updated_on: 2007-05-12 17:15:32 +02:00 + subject: First post + id: 1 + replies_count: 1 + last_reply_id: 2 + content: "This is the very first post\n\ + in the forum" + author_id: 1 + parent_id: + board_id: 1 +messages_002: + created_on: 2007-05-12 17:18:00 +02:00 + updated_on: 2007-05-12 17:18:00 +02:00 + subject: First reply + id: 2 + replies_count: 0 + last_reply_id: + content: "Reply to the first post" + author_id: 1 + parent_id: 1 + board_id: 1 + \ No newline at end of file diff --git a/test/unit/board_test.rb b/test/unit/board_test.rb new file mode 100644 index 000000000..3ba4b2d97 --- /dev/null +++ b/test/unit/board_test.rb @@ -0,0 +1,30 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BoardTest < Test::Unit::TestCase + fixtures :projects, :boards, :messages + + def setup + @project = Project.find(1) + end + + def test_create + board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description') + assert board.save + board.reload + assert_equal 'Test board', board.name + assert_equal 'Test board description', board.description + assert_equal @project, board.project + assert_equal 0, board.topics_count + assert_equal 0, board.messages_count + assert_nil board.last_message + # last position + assert_equal @project.boards.size, board.position + end + + def test_destroy + board = Board.find(1) + assert board.destroy + # make sure that the associated messages are removed + assert_equal 0, Message.count(:conditions => {:board_id => 1}) + end +end diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb new file mode 100644 index 000000000..6d8458bfc --- /dev/null +++ b/test/unit/message_test.rb @@ -0,0 +1,44 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class MessageTest < Test::Unit::TestCase + fixtures :projects, :boards, :messages + + def setup + @board = Board.find(1) + @user = User.find(1) + end + + def test_create + topics_count = @board.topics_count + messages_count = @board.messages_count + + message = Message.new(:board => @board, :subject => 'Test message', :content => 'Test message content', :author => @user) + assert message.save + @board.reload + # topics count incremented + assert_equal topics_count+1, @board[:topics_count] + # messages count incremented + assert_equal messages_count+1, @board[:messages_count] + assert_equal message, @board.last_message + end + + def test_reply + topics_count = @board.topics_count + messages_count = @board.messages_count + @message = Message.find(1) + replies_count = @message.replies_count + + reply = Message.new(:board => @board, :subject => 'Test reply', :content => 'Test reply content', :parent => @message, :author => @user) + assert reply.save + @board.reload + # same topics count + assert_equal topics_count, @board[:topics_count] + # messages count incremented + assert_equal messages_count+1, @board[:messages_count] + assert_equal reply, @board.last_message + @message.reload + # replies count incremented + assert_equal replies_count+1, @message[:replies_count] + assert_equal reply, @message.last_reply + end +end -- 2.39.5