diff options
-rw-r--r-- | app/controllers/boards_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/issues_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/watchers_controller.rb | 25 | ||||
-rw-r--r-- | app/helpers/watchers_helper.rb | 17 | ||||
-rw-r--r-- | app/models/board.rb | 1 | ||||
-rw-r--r-- | app/views/boards/show.rhtml | 1 | ||||
-rw-r--r-- | app/views/issues/show.rhtml | 8 |
7 files changed, 42 insertions, 14 deletions
diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index b3be6b7a2..0ad2645f8 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -25,6 +25,8 @@ class BoardsController < ApplicationController include MessagesHelper helper :sort include SortHelper + helper :watchers + include WatchersHelper def index @boards = @project.boards diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cec126dd3..0a8d19a31 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -27,6 +27,8 @@ class IssuesController < ApplicationController include IfpdfHelper helper :issue_relations include IssueRelationsHelper + helper :watchers + include WatchersHelper def show @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 09ec5bcd7..f617a5b5a 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -20,19 +20,30 @@ class WatchersController < ApplicationController before_filter :require_login, :find_project, :check_project_privacy def add - @issue.add_watcher(logged_in_user) - redirect_to :controller => 'issues', :action => 'show', :id => @issue + user = logged_in_user + @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 def remove - @issue.remove_watcher(logged_in_user) - redirect_to :controller => 'issues', :action => 'show', :id => @issue + user = logged_in_user + @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 private - def find_project - @issue = Issue.find(params[:issue_id]) - @project = @issue.project + klass = Object.const_get(params[:object_type].camelcase) + return false unless klass.respond_to?('watched_by') + @watched = klass.find(params[:object_id]) + @project = @watched.project + rescue + render_404 end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 23f767611..87b381055 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -16,4 +16,21 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 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 diff --git a/app/models/board.rb b/app/models/board.rb index a6ea22f67..26e2004d3 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -21,6 +21,7 @@ class Board < ActiveRecord::Base 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 + acts_as_watchable validates_presence_of :name, :description validates_length_of :name, :maximum => 30 diff --git a/app/views/boards/show.rhtml b/app/views/boards/show.rhtml index 13a056046..cb38cdb53 100644 --- a/app/views/boards/show.rhtml +++ b/app/views/boards/show.rhtml @@ -1,5 +1,6 @@ <div class="contextual"> <%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %> +<%= watcher_tag(@board, @logged_in_user) %> </div> <h2><%=h @board.name %></h2> diff --git a/app/views/issues/show.rhtml b/app/views/issues/show.rhtml index d7d9bcf6d..1895e7cef 100644 --- a/app/views/issues/show.rhtml +++ b/app/views/issues/show.rhtml @@ -58,13 +58,7 @@ end %> <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_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %> -<% if @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 %> +<%= watcher_tag(@issue, @logged_in_user) %> <%= 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' %> </div> |