mod/05_email/set/all/follow.rb in card-1.15.1 vs mod/05_email/set/all/follow.rb in card-1.15.2
- old
+ new
@@ -17,41 +17,41 @@
event :cache_expired_because_of_new_user_rule, :before=>:extend, :when=>proc { |c| c.follow_rule_card? } do
Card.follow_caches_expired
end
format do
-
+
def follow_link_hash args
toggle = args[:toggle] || ( card.followed? ? :off : :on )
hash = { :class => "follow-toggle-#{toggle}" }
-
case toggle
when :off
hash[:content] = '*never'
hash[:title] = "stop sending emails about changes to #{card.follow_label}"
hash[:verb] = 'unfollow'
when :on
hash[:content] = '*always'
hash[:title] = "send emails about changes to #{card.follow_label}"
hash[:verb] = 'follow'
end
+ follow_rule_name = card.default_follow_set_card.follow_rule_name( Auth.current.name )
+ hash[:path] = path :name=>follow_rule_name, :action=>:update,
+ :success=>{ :view=>:modal_content },
+ :card=>{ :content=>"[[#{hash[:content]}]]" }
hash
-
end
-
-
+
end
-
format :json do
view :follow_status do |args|
follow_link_hash args
end
end
format :html do
-
+
view :follow_link, :tags=>:unknown_ok, :perms=>:none do |args|
hash = follow_link_hash args
text = %[<span class="follow-verb">#{hash[:verb]}</span> #{args[:label]}]
opts = {
:title => hash[:title],
@@ -60,16 +60,32 @@
'data-rule_name' => card.default_follow_set_card.follow_rule_name( Auth.current.name ).to_name.url_key,
'data-card_key' => card.key
}
link_to text, '', opts
end
-
+
def default_follow_link_args args
args[:toggle] ||= card.followed? ? :off : :on
args[:label] ||= card.follow_label
end
-
+
+
+ view :follow_modal_link, :tags=>:unknown_ok, :perms=>:none do |args|
+ hash = follow_link_hash args
+ text = %[#{glyphicon 'flag'}<span class="follow-verb menu-item-label">#{hash[:verb]}</span>]
+ follow_rule_card = Card.fetch(card.default_follow_set_card.follow_rule_name( Auth.current.name ), :new=>{})
+ opts = ( args[:html_args] || {} ).clone
+ opts.merge!(
+ :title => hash[:title],
+ 'data-path' => hash[:path],
+ 'data-toggle' => 'modal',
+ 'data-target' => "#modal-#{card.cardname.safe_key}",
+ )
+ opts[:class] = "follow-link #{opts[:class]}"
+ link_to text, hash[:path], opts
+ end
+
end
def follow_label
name
@@ -89,11 +105,11 @@
def follow_rule_card?
is_user_rule? && rule_setting_name == '*follow'
end
def follow_option?
- codename && FollowOption.codenames.include?(codename.to_sym)
+ codename && FollowOption.codenames.include?(codename.to_sym)
end
# used for the follow menu
# overwritten in type/set.rb and type/cardtype.rb
# for sets and cardtypes it doesn't check whether the users is following the card itself
@@ -109,39 +125,39 @@
return false
end
end
def followed?
- followed_by? Auth.current_id
+ followed_by? Auth.current_id
end
def follow_rule_applies? follower_id
follow_rule = rule :follow, :user_id=>follower_id
if follow_rule.present?
follow_rule.split("\n").each do |value|
-
+
value_code = value.to_name.code
- accounted_ids = (
+ accounted_ids = (
@follower_candidate_ids[ value_code ] ||=
if block = FollowOption.follower_candidate_ids[ value_code ]
block.call self
else
[]
end
)
-
- applicable =
+
+ applicable =
if test = FollowOption.test[ value_code ]
test.call follower_id, accounted_ids
else
accounted_ids.include? follower_id
end
-
+
return value.gsub( /[\[\]]/, '' ) if applicable
end
- end
+ end
return false
end
def with_follower_candidate_ids
@@ -155,11 +171,11 @@
def default_follow_set_card
Card.fetch("#{name}+*self")
end
-# returns true if according to the follow_field_rule followers of self also
+# returns true if according to the follow_field_rule followers of self also
# follow changes of field_card
def followed_field? field_card
(follow_field_rule = rule_card(:follow_fields)) || follow_field_rule.item_names.find do |item|
item.to_name.key == field_card.key || (item.to_name.key == Card[:includes].key && included_card_ids.include?(field_card.id) )
end
@@ -190,11 +206,11 @@
# all ids of users that follow this card because of a follow rule that applies to this card
# doesn't include users that follow this card because they are following parent cards or other cards that include this card
def direct_follower_ids args={}
result = ::Set.new
with_follower_candidate_ids do
- set_names.each do |set_name|
+ set_names.each do |set_name|
set_card = Card.fetch(set_name)
set_card.all_user_ids_with_rule_for(:follow).each do |user_id|
if (!result.include? user_id) and self.follow_rule_applies?(user_id)
result << user_id
end
@@ -203,13 +219,13 @@
end
result
end
def all_direct_follower_ids_with_reason
- with_follower_candidate_ids do
+ with_follower_candidate_ids do
visited = ::Set.new
- set_names.each do |set_name|
+ set_names.each do |set_name|
set_card = Card.fetch(set_name)
set_card.all_user_ids_with_rule_for(:follow).each do |user_id|
if (!visited.include?(user_id)) && (follow_option = self.follow_rule_applies?(user_id))
visited << user_id
yield(user_id, :set_card=>set_card, :option=>follow_option)
@@ -241,10 +257,10 @@
end
def follower_ids_cache
Card.cache.read(FOLLOWER_IDS_CACHE_KEY) || {}
end
-
+
def write_follower_ids_cache hash
Card.cache.write FOLLOWER_IDS_CACHE_KEY, hash
end
def clear_follower_ids_cache