Patch #4331 » 0001-Add-a-second-action-menu-to-IssuesController-show.-4.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
| 72 | 72 |
|
| 73 | 73 |
def set_watcher(user, watching) |
| 74 | 74 |
@watched.set_watcher(user, watching) |
| 75 |
if params[:replace].present? |
|
| 76 |
if params[:replace].is_a? Array |
|
| 77 |
replace_ids = params[:replace] |
|
| 78 |
else |
|
| 79 |
replace_ids = [params[:replace]] |
|
| 80 |
end |
|
| 81 |
else |
|
| 82 |
replace_ids = 'watcher' |
|
| 83 |
end |
|
| 75 | 84 |
respond_to do |format| |
| 76 | 85 |
format.html { redirect_to :back }
|
| 77 |
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
|
| 86 |
format.js do |
|
| 87 |
render(:update) do |page| |
|
| 88 |
replace_ids.each do |replace_id| |
|
| 89 |
page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) |
|
| 90 |
end |
|
| 91 |
end |
|
| 92 |
end |
|
| 78 | 93 |
end |
| 79 | 94 |
rescue ::ActionController::RedirectBackError |
| 80 | 95 |
render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
| app/helpers/watchers_helper.rb | ||
|---|---|---|
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | 17 | |
| 18 | 18 |
module WatchersHelper |
| 19 |
def watcher_tag(object, user) |
|
| 20 |
content_tag("span", watcher_link(object, user), :id => 'watcher')
|
|
| 19 | ||
| 20 |
# Valid options |
|
| 21 |
# * :id - the element id |
|
| 22 |
# * :replace - a string or array of element ids that will be |
|
| 23 |
# replaced |
|
| 24 |
def watcher_tag(object, user, options={:replace => 'watcher'})
|
|
| 25 |
id = options[:id] |
|
| 26 |
id ||= options[:replace] if options[:replace].is_a? String |
|
| 27 |
content_tag("span", watcher_link(object, user, options), :id => id)
|
|
| 21 | 28 |
end |
| 22 | 29 |
|
| 23 |
def watcher_link(object, user) |
|
| 30 |
# Valid options |
|
| 31 |
# * :replace - a string or array of element ids that will be |
|
| 32 |
# replaced |
|
| 33 |
def watcher_link(object, user, options={:replace => 'watcher'})
|
|
| 24 | 34 |
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
| 25 | 35 |
watched = object.watched_by?(user) |
| 26 | 36 |
url = {:controller => 'watchers',
|
| 27 | 37 |
:action => (watched ? 'unwatch' : 'watch'), |
| 28 | 38 |
:object_type => object.class.to_s.underscore, |
| 29 |
:object_id => object.id} |
|
| 39 |
:object_id => object.id, |
|
| 40 |
:replace => options[:replace]} |
|
| 30 | 41 |
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), |
| 31 | 42 |
{:url => url},
|
| 32 | 43 |
:href => url_for(url), |
| app/views/issues/_action_menu.rhtml | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<%= link_to_if_authorized(l(:button_update), {:controller => 'issues', :action => 'edit', :id => @issue }, :onclick => 'showAndScrollTo("update", "notes"); return false;', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %>
|
|
| 3 |
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time-add' %>
|
|
| 4 |
<% replace_watcher ||= 'watcher' %> |
|
| 5 |
<%= watcher_tag(@issue, User.current, {:id => replace_watcher, :replace => ['watcher','watcher2']}) %>
|
|
| 6 |
<%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
|
|
| 7 |
<%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %>
|
|
| 8 |
<%= 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' %>
|
|
| 9 |
</div> |
|
| app/views/issues/show.rhtml | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<%= link_to_if_authorized(l(:button_update), {:controller => 'issues', :action => 'edit', :id => @issue }, :onclick => 'showAndScrollTo("update", "notes"); return false;', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %>
|
|
| 3 |
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time-add' %>
|
|
| 4 |
<%= watcher_tag(@issue, User.current) %> |
|
| 5 |
<%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
|
|
| 6 |
<%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %>
|
|
| 7 |
<%= 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' %>
|
|
| 8 |
</div> |
|
| 1 |
<%= render :partial => 'action_menu' %> |
|
| 9 | 2 | |
| 10 | 3 |
<h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> |
| 11 | 4 | |
| ... | ... | |
| 93 | 86 |
<%= render :partial => 'history', :locals => { :journals => @journals } %>
|
| 94 | 87 |
</div> |
| 95 | 88 |
<% end %> |
| 89 | ||
| 90 |
<%= render :partial => 'action_menu', :locals => {:replace_watcher => 'watcher2' } %>
|
|
| 91 | ||
| 96 | 92 |
<div style="clear: both;"></div> |
| 97 | 93 | |
| 98 | 94 |
<% if authorize_for('issues', 'edit') %>
|
| test/functional/watchers_controller_test.rb | ||
|---|---|---|
| 47 | 47 |
end |
| 48 | 48 |
assert Issue.find(1).watched_by?(User.find(3)) |
| 49 | 49 |
end |
| 50 | ||
| 51 |
def test_watch_with_multiple_replacements |
|
| 52 |
@request.session[:user_id] = 3 |
|
| 53 |
assert_difference('Watcher.count') do
|
|
| 54 |
xhr :post, :watch, :object_type => 'issue', :object_id => '1', :replace => ['watch_item_1','watch_item_2'] |
|
| 55 |
assert_response :success |
|
| 56 |
assert_select_rjs :replace_html, 'watch_item_1' |
|
| 57 |
assert_select_rjs :replace_html, 'watch_item_2' |
|
| 58 |
end |
|
| 59 |
end |
|
| 50 | 60 |
|
| 51 | 61 |
def test_unwatch |
| 52 | 62 |
@request.session[:user_id] = 3 |
| ... | ... | |
| 57 | 67 |
end |
| 58 | 68 |
assert !Issue.find(1).watched_by?(User.find(3)) |
| 59 | 69 |
end |
| 60 |
|
|
| 70 | ||
| 71 |
def test_unwatch_with_multiple_replacements |
|
| 72 |
@request.session[:user_id] = 3 |
|
| 73 |
assert_difference('Watcher.count', -1) do
|
|
| 74 |
xhr :post, :unwatch, :object_type => 'issue', :object_id => '2', :replace => ['watch_item_1', 'watch_item_2'] |
|
| 75 |
assert_response :success |
|
| 76 |
assert_select_rjs :replace_html, 'watch_item_1' |
|
| 77 |
assert_select_rjs :replace_html, 'watch_item_2' |
|
| 78 |
end |
|
| 79 |
assert !Issue.find(1).watched_by?(User.find(3)) |
|
| 80 |
end |
|
| 81 | ||
| 61 | 82 |
def test_new_watcher |
| 62 | 83 |
@request.session[:user_id] = 2 |
| 63 | 84 |
assert_difference('Watcher.count') do
|
- « Previous
- 1
- 2
- Next »