Class: Signum::Signal

Inherits:
ApplicationRecord show all
Defined in:
app/models/signum/signal.rb

Instance Method Summary collapse

Instance Method Details

#broadcast_createObject



13
14
15
16
17
18
19
20
21
# File 'app/models/signum/signal.rb', line 13

def broadcast_create
  broadcast! if can_broadcast?

  broadcast_prepend_to(:signals, target: Signum.config.balloon_notifications_container_id.call(key || signalable),
    html: ActionController::Base.render(Signum::Notification::Component.new(self)))

  broadcast_prepend_to(:signals, target: Signum.config.drawer_notifications_container_id.call(key || signalable),
    html: ActionController::Base.render(Signum::NotificationDrawerItem::Component.new(signal: self)))
end

#broadcast_updateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/signum/signal.rb', line 23

def broadcast_update
  return if saved_change_to_state? && (broadcasted? || shown?)

  if saved_change_to_state? && closed?
    broadcast_remove_to(:signals, target: "notification_drawer_item_parent_#{signalable_id}_#{id}")
    return
  end

  broadcast_replace_to(:signals, target: Signum.config.notification_body_id.call(:balloon, self),
    html: ActionController::Base.render(Signum::NotificationBody::Component.new(self, {type: :balloon, timeout: 5})))
  broadcast_replace_to(:signals, target: Signum.config.notification_body_id.call(:drawer_item, self),
    html: ActionController::Base.render(Signum::NotificationBody::Component.new(self, {type: :drawer_item, timeout: 5})))
end