annotate app/helpers/watchers_helper.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@441 3 # Redmine - project management software
Chris@1494 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@909 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@909 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@0 20 module WatchersHelper
Chris@909 21
Chris@441 22 def watcher_tag(object, user, options={})
Chris@1464 23 ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
Chris@1464 24 watcher_link(object, user)
Chris@0 25 end
Chris@909 26
Chris@1464 27 def watcher_link(objects, user)
Chris@1464 28 return '' unless user && user.logged?
Chris@1464 29 objects = Array.wrap(objects)
Chris@1517 30 return '' unless objects.any?
Chris@909 31
Chris@1464 32 watched = Watcher.any_watched?(objects, user)
Chris@1464 33 css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
Chris@1464 34 text = watched ? l(:button_unwatch) : l(:button_watch)
Chris@1464 35 url = watch_path(
Chris@1464 36 :object_type => objects.first.class.to_s.underscore,
Chris@1464 37 :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
Chris@1464 38 )
Chris@1464 39 method = watched ? 'delete' : 'post'
Chris@1464 40
Chris@1464 41 link_to text, url, :remote => true, :method => method, :class => css
Chris@0 42 end
Chris@909 43
Chris@441 44 # Returns the css class used to identify watch links for a given +object+
Chris@1464 45 def watcher_css(objects)
Chris@1464 46 objects = Array.wrap(objects)
Chris@1464 47 id = (objects.size == 1 ? objects.first.id : 'bulk')
Chris@1464 48 "#{objects.first.class.to_s.underscore}-#{id}-watcher"
Chris@441 49 end
Chris@909 50
Chris@0 51 # Returns a comma separated list of users watching the given object
Chris@0 52 def watchers_list(object)
Chris@0 53 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
Chris@1115 54 content = ''.html_safe
Chris@0 55 lis = object.watcher_users.collect do |user|
Chris@1115 56 s = ''.html_safe
Chris@1115 57 s << avatar(user, :size => "16").to_s
Chris@1115 58 s << link_to_user(user, :class => 'user')
Chris@0 59 if remove_allowed
Chris@0 60 url = {:controller => 'watchers',
Chris@0 61 :action => 'destroy',
Chris@0 62 :object_type => object.class.to_s.underscore,
Chris@0 63 :object_id => object.id,
Chris@0 64 :user_id => user}
Chris@1115 65 s << ' '
Chris@1115 66 s << link_to(image_tag('delete.png'), url,
Chris@1464 67 :remote => true, :method => 'delete', :class => "delete")
Chris@0 68 end
Chris@1464 69 content << content_tag('li', s, :class => "user-#{user.id}")
Chris@0 70 end
Chris@1464 71 content.present? ? content_tag('ul', content, :class => 'watchers') : content
Chris@1115 72 end
Chris@1115 73
Chris@1115 74 def watchers_checkboxes(object, users, checked=nil)
Chris@1115 75 users.map do |user|
Chris@1115 76 c = checked.nil? ? object.watched_by?(user) : checked
Chris@1115 77 tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
Chris@1115 78 content_tag 'label', "#{tag} #{h(user)}".html_safe,
Chris@1115 79 :id => "issue_watcher_user_ids_#{user.id}",
Chris@1115 80 :class => "floating"
Chris@1115 81 end.join.html_safe
Chris@0 82 end
Chris@0 83 end