Added watchers for message boards (watchers controller modified to support any watchable model).
No notification yet when a new message is posted. git-svn-id: http://redmine.rubyforge.org/svn/trunk@530 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b90e84b9fe
commit
bca5bd9c62
@ -25,6 +25,8 @@ class BoardsController < ApplicationController
|
|||||||
include MessagesHelper
|
include MessagesHelper
|
||||||
helper :sort
|
helper :sort
|
||||||
include SortHelper
|
include SortHelper
|
||||||
|
helper :watchers
|
||||||
|
include WatchersHelper
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@boards = @project.boards
|
@boards = @project.boards
|
||||||
|
@ -27,6 +27,8 @@ class IssuesController < ApplicationController
|
|||||||
include IfpdfHelper
|
include IfpdfHelper
|
||||||
helper :issue_relations
|
helper :issue_relations
|
||||||
include IssueRelationsHelper
|
include IssueRelationsHelper
|
||||||
|
helper :watchers
|
||||||
|
include WatchersHelper
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
|
@status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
|
||||||
|
@ -20,19 +20,30 @@ class WatchersController < ApplicationController
|
|||||||
before_filter :require_login, :find_project, :check_project_privacy
|
before_filter :require_login, :find_project, :check_project_privacy
|
||||||
|
|
||||||
def add
|
def add
|
||||||
@issue.add_watcher(logged_in_user)
|
user = logged_in_user
|
||||||
redirect_to :controller => 'issues', :action => 'show', :id => @issue
|
@watched.add_watcher(user)
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :text => 'Watcher added.', :layout => true }
|
||||||
|
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
@issue.remove_watcher(logged_in_user)
|
user = logged_in_user
|
||||||
redirect_to :controller => 'issues', :action => 'show', :id => @issue
|
@watched.remove_watcher(user)
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :text => 'Watcher removed.', :layout => true }
|
||||||
|
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
@issue = Issue.find(params[:issue_id])
|
klass = Object.const_get(params[:object_type].camelcase)
|
||||||
@project = @issue.project
|
return false unless klass.respond_to?('watched_by')
|
||||||
|
@watched = klass.find(params[:object_id])
|
||||||
|
@project = @watched.project
|
||||||
|
rescue
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,4 +16,21 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module WatchersHelper
|
module WatchersHelper
|
||||||
|
def watcher_tag(object, user)
|
||||||
|
content_tag("span", watcher_link(object, user), :id => 'watcher')
|
||||||
|
end
|
||||||
|
|
||||||
|
def watcher_link(object, user)
|
||||||
|
return '' unless user && object.respond_to?('watched_by?')
|
||||||
|
watched = object.watched_by?(user)
|
||||||
|
url = {:controller => 'watchers',
|
||||||
|
:action => (watched ? 'remove' : 'add'),
|
||||||
|
:object_type => object.class.to_s.underscore,
|
||||||
|
:object_id => object.id}
|
||||||
|
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||||
|
{:url => url},
|
||||||
|
:href => url_for(url),
|
||||||
|
:class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,6 +21,7 @@ class Board < ActiveRecord::Base
|
|||||||
has_many :messages, :dependent => :delete_all, :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
|
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
|
||||||
acts_as_list :scope => :project_id
|
acts_as_list :scope => :project_id
|
||||||
|
acts_as_watchable
|
||||||
|
|
||||||
validates_presence_of :name, :description
|
validates_presence_of :name, :description
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %>
|
<%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %>
|
||||||
|
<%= watcher_tag(@board, @logged_in_user) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%=h @board.name %></h2>
|
<h2><%=h @board.name %></h2>
|
||||||
|
@ -58,13 +58,7 @@ end %>
|
|||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit' %>
|
<%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit' %>
|
||||||
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
|
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
|
||||||
<% if @logged_in_user %>
|
<%= watcher_tag(@issue, @logged_in_user) %>
|
||||||
<% if @issue.watched_by?(@logged_in_user) %>
|
|
||||||
<%= link_to l(:button_unwatch), {:controller => 'watchers', :action => 'remove', :issue_id => @issue}, :class => 'icon icon-fav' %>
|
|
||||||
<% else %>
|
|
||||||
<%= link_to l(:button_watch), {:controller => 'watchers', :action => 'add', :issue_id => @issue}, :class => 'icon icon-fav-off' %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
<%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
|
<%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
|
||||||
<%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
|
<%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user