signum 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.shipkit.yml +1 -1
- data/Gemfile.lock +9 -8
- data/README.md +29 -1
- data/app/components/signum/notification_body/component.css +10 -0
- data/app/components/signum/notification_body/component.html.slim +3 -2
- data/app/components/signum/notification_body/component_controller.js +2 -0
- data/app/components/signum/notifications/component.html.slim +5 -6
- data/app/components/signum/notifications/component.rb +16 -1
- data/app/controllers/signum/signal_controller.rb +7 -2
- data/app/models/signum/signal.rb +22 -5
- data/lib/signum/configuration.rb +3 -0
- data/lib/signum/version.rb +1 -1
- data/lib/signum.rb +26 -2
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 168e5eb648c14976253f8dd27f28fbb58db9d34314634429a345276fbcbb819e
|
|
4
|
+
data.tar.gz: 67d09a0cbf834adb9f0ac8d0c38bd615227b3a39d021e214241778c1ae3a0403
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9505524f16669be863221503c544925d9c6675ac1b87b678858354b4e60c8d2347e7c06ea1c37b8500b1d30637ee361b246fed0f4947a192bcd91741039c2d05
|
|
7
|
+
data.tar.gz: 40ee6d6d62829e106edc4d38e6e238d388dce749a641444628c5cda90ec6cda6f37f991c445b15973044860331a222147d661733c115586d0ea68b7ead940478
|
data/.gitignore
CHANGED
data/.shipkit.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
previous_version: 0.
|
|
2
|
+
previous_version: 0.9.1
|
data/Gemfile.lock
CHANGED
|
@@ -13,7 +13,7 @@ GIT
|
|
|
13
13
|
PATH
|
|
14
14
|
remote: .
|
|
15
15
|
specs:
|
|
16
|
-
signum (0.
|
|
16
|
+
signum (0.9.1)
|
|
17
17
|
importmap-rails
|
|
18
18
|
pg
|
|
19
19
|
rails (> 6.0)
|
|
@@ -163,6 +163,7 @@ GEM
|
|
|
163
163
|
ast (~> 2.4.1)
|
|
164
164
|
racc
|
|
165
165
|
pg (1.7.0)
|
|
166
|
+
prism (2.1.0)
|
|
166
167
|
psych (5.1.2)
|
|
167
168
|
stringio
|
|
168
169
|
pundit (2.3.1)
|
|
@@ -273,10 +274,10 @@ GEM
|
|
|
273
274
|
stimulus-rails (1.3.4)
|
|
274
275
|
railties (>= 6.0.0)
|
|
275
276
|
stringio (3.1.0)
|
|
276
|
-
tailwindcss-rails (4.
|
|
277
|
+
tailwindcss-rails (4.7.0)
|
|
277
278
|
railties (>= 7.0.0)
|
|
278
279
|
tailwindcss-ruby (~> 4.0)
|
|
279
|
-
tailwindcss-ruby (4.3.
|
|
280
|
+
tailwindcss-ruby (4.3.4)
|
|
280
281
|
temple (0.10.7)
|
|
281
282
|
thor (1.3.1)
|
|
282
283
|
tilt (2.9.0)
|
|
@@ -287,15 +288,15 @@ GEM
|
|
|
287
288
|
tzinfo (2.0.6)
|
|
288
289
|
concurrent-ruby (~> 1.0)
|
|
289
290
|
unicode-display_width (2.5.0)
|
|
290
|
-
view_component (4.
|
|
291
|
+
view_component (4.25.0)
|
|
291
292
|
actionview (>= 7.1.0)
|
|
292
293
|
activesupport (>= 7.1.0)
|
|
293
|
-
|
|
294
|
+
prism (>= 1.0)
|
|
294
295
|
webrick (1.8.1)
|
|
295
|
-
websocket-driver (0.
|
|
296
|
+
websocket-driver (0.9.1)
|
|
296
297
|
base64
|
|
297
|
-
websocket-extensions (>= 0.
|
|
298
|
-
websocket-extensions (0.
|
|
298
|
+
websocket-extensions (>= 0.2.0)
|
|
299
|
+
websocket-extensions (0.3.0)
|
|
299
300
|
zeitwerk (2.6.13)
|
|
300
301
|
|
|
301
302
|
GEM
|
data/README.md
CHANGED
|
@@ -4,7 +4,35 @@ Short description and motivation.
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Send a notification to:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
Signum.info(user, text: "Your export is ready") # a user: theirs alone
|
|
11
|
+
Signum.info(account, text: "Maintenance tonight") # a group: the users whose pages have it among config.groups
|
|
12
|
+
Signum.info(:all, text: "New version") # every page
|
|
13
|
+
Signum.error(request.session.id, text: "Not found") # a key: the pages that pass it to the component
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Also `success`, `warning` and `signal`. Each goes to the Turbo stream of whom it is for, `[user, :signals]`,
|
|
17
|
+
`[account, :signals]` or `[:signals, key]`, and a page subscribes only to its own: its user's, every page's, its user's
|
|
18
|
+
groups' and the keys it passes:
|
|
19
|
+
|
|
20
|
+
```erb
|
|
21
|
+
<%= render Signum::Notifications::Component.new %> <%# signed in %>
|
|
22
|
+
<%= render Signum::Notifications::Component.new([request.session.id]) %> <%# nobody signed in yet %>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
Signum.setup do |config|
|
|
27
|
+
config.current_user = -> { Current.user }
|
|
28
|
+
config.groups = -> { [Current.account].compact } # none without a user
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Only the current user's own notification is theirs to show or close (`Signum::SignalController`).
|
|
33
|
+
|
|
34
|
+
Before 0.10, every notification was broadcast to one stream, `:signals`, that every page subscribed to, so each
|
|
35
|
+
browser received every user's (and only didn't show them).
|
|
8
36
|
|
|
9
37
|
## Installation
|
|
10
38
|
|
|
@@ -101,3 +101,13 @@
|
|
|
101
101
|
/* progress bar container */
|
|
102
102
|
@apply basis-full p-1;
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
.signum-notification-body__pbc__pb {
|
|
106
|
+
/* progress bar */
|
|
107
|
+
@apply h-1.5 w-full overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.signum-notification-body__pbc__pb__b {
|
|
111
|
+
/* progress bar's bar */
|
|
112
|
+
@apply h-full rounded-full bg-blue-500 dark:bg-blue-600;
|
|
113
|
+
}
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
a.signum-notification-body__mb__bmc__bc__b*{href: button.fetch('url', '#'), target: button.fetch("target", "_blank"), 'data-action': button["close"] ? "click->signum-notification-body#close" : "" }.merge(button.fetch("link_attributes", {}))
|
|
39
39
|
= button["title"]
|
|
40
40
|
- if signal.count.present?
|
|
41
|
-
- percentage = signal.total.
|
|
41
|
+
- percentage = (signal.total.to_f.positive? ? signal.count.fdiv(signal.total) * 100 : signal.count.to_f).clamp(0, 100)
|
|
42
42
|
.signum-notification-body__pbc
|
|
43
|
-
|
|
43
|
+
.signum-notification-body__pbc__pb role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow=percentage.round
|
|
44
|
+
.signum-notification-body__pbc__pb__b style="width: #{percentage}%"
|
|
@@ -12,6 +12,8 @@ export default class extends ApplicationController {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
close(event) {
|
|
15
|
+
// Marked, so the host app can animate it out before it's removed
|
|
16
|
+
this.element?.parentElement?.setAttribute("data-closing", "")
|
|
15
17
|
setTimeout(() => {
|
|
16
18
|
this.element?.parentElement?.remove()
|
|
17
19
|
if (event && this.typeValue != "balloon") {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/ Only the page's own streams: its user's, every page's, its groups' and its keys' (Signum.streams_for)
|
|
2
|
+
- streams.each do |stream|
|
|
3
|
+
= helpers.turbo_stream_from(*stream)
|
|
2
4
|
|
|
3
5
|
.pointer-events-none.fixed.inset-0.items-end.px-2.py-6.sm:items-start.sm:p-6.z-10 data-turbo-permanent="true" id="signum_notifications"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
div.flex.w-full.flex-col.items-center.space-y-2.sm:items-end[id="notifications_all"]
|
|
7
|
-
- keys&.each do |key|
|
|
8
|
-
div.flex.w-full.flex-col.items-center.space-y-2.sm:items-end[id="notifications_#{key}"]
|
|
6
|
+
- containers.each do |id|
|
|
7
|
+
div.flex.w-full.flex-col.items-center.space-y-2.sm:items-end[id=id]
|
|
@@ -2,8 +2,23 @@ module Signum
|
|
|
2
2
|
module Notifications
|
|
3
3
|
class Component < ViewComponent::Base
|
|
4
4
|
attr_reader :keys
|
|
5
|
+
|
|
6
|
+
# keys: those whose signals the page gets besides its user's, every page's and its groups' (Signum.streams_for),
|
|
7
|
+
# e.g. [request.session.id] where nobody is signed in
|
|
5
8
|
def initialize(keys = nil)
|
|
6
|
-
@keys = keys
|
|
9
|
+
@keys = Array(keys).compact_blank.map(&:to_s)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def user = Signum.config.current_user.call
|
|
13
|
+
|
|
14
|
+
def streams = Signum.streams_for(user, keys)
|
|
15
|
+
|
|
16
|
+
# A container per receiver, which its signals are prepended to
|
|
17
|
+
def containers
|
|
18
|
+
receivers = [Signum::ALL, *Signum.groups_for(user), *keys]
|
|
19
|
+
ids = receivers.map { |receiver| Signum.config.balloon_notifications_container_id.call(receiver) }
|
|
20
|
+
ids.unshift(Signum.config.balloon_notifications_container_id.call(user)) if user
|
|
21
|
+
ids.uniq
|
|
7
22
|
end
|
|
8
23
|
end
|
|
9
24
|
end
|
|
@@ -3,13 +3,11 @@ require_dependency 'signum/application_controller'
|
|
|
3
3
|
module Signum
|
|
4
4
|
class SignalController < ApplicationController
|
|
5
5
|
def show
|
|
6
|
-
signal = Signum::Signal.find(signal_params[:id])
|
|
7
6
|
signal.show! if signal.broadcasted?
|
|
8
7
|
head :ok
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
def close
|
|
12
|
-
signal = Signum::Signal.find(signal_params[:id])
|
|
13
11
|
signal.close!
|
|
14
12
|
head :ok
|
|
15
13
|
end
|
|
@@ -22,6 +20,13 @@ module Signum
|
|
|
22
20
|
|
|
23
21
|
private
|
|
24
22
|
|
|
23
|
+
# Only the current user's own, or one for a group or key
|
|
24
|
+
def signal
|
|
25
|
+
@signal ||= Signum::Signal.find(signal_params[:id]).tap do |signal|
|
|
26
|
+
raise ActiveRecord::RecordNotFound unless signal.for?(Signum.config.current_user.call)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
25
30
|
def signal_params
|
|
26
31
|
params.require(:signal).permit(:id)
|
|
27
32
|
end
|
data/app/models/signum/signal.rb
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
module Signum
|
|
2
|
+
# A notification, broadcast to the stream of whom it is for, never to everyone's (Signum::Notifications::Component
|
|
3
|
+
# subscribes a page to its streams):
|
|
4
|
+
#
|
|
5
|
+
# - a user's (signalable a user): [user, :signals], theirs alone
|
|
6
|
+
# - a group's (signalable another record, e.g. an account): [record, :signals], of the users whose page has it among
|
|
7
|
+
# Signum.config.groups
|
|
8
|
+
# - a key's: [:signals, key], of the pages that pass it (the component's keys), or every page's for "all"
|
|
2
9
|
class Signal < ApplicationRecord
|
|
3
10
|
belongs_to :signalable, polymorphic: true, optional: true
|
|
4
11
|
belongs_to :subjectable, polymorphic: true, optional: true
|
|
@@ -10,13 +17,23 @@ module Signum
|
|
|
10
17
|
after_create_commit :broadcast_create
|
|
11
18
|
after_update_commit :broadcast_update
|
|
12
19
|
|
|
20
|
+
# The stream it is broadcast to
|
|
21
|
+
def stream = Signum.stream_for(key.presence || signalable)
|
|
22
|
+
|
|
23
|
+
# Whether it is the user's to show or close: their own, or one for a group or key, which isn't anyone's
|
|
24
|
+
def for?(user)
|
|
25
|
+
return signalable == user if signalable_type == Signum.config.user_model_name
|
|
26
|
+
|
|
27
|
+
true
|
|
28
|
+
end
|
|
29
|
+
|
|
13
30
|
def broadcast_create
|
|
14
31
|
broadcast! if can_broadcast?
|
|
15
32
|
|
|
16
|
-
broadcast_prepend_to(
|
|
33
|
+
broadcast_prepend_to(*stream, target: Signum.config.balloon_notifications_container_id.call(key.presence || signalable),
|
|
17
34
|
html: ActionController::Base.render(Signum::Notification::Component.new(self)))
|
|
18
35
|
|
|
19
|
-
broadcast_prepend_to(
|
|
36
|
+
broadcast_prepend_to(*stream, target: Signum.config.drawer_notifications_container_id.call(key.presence || signalable),
|
|
20
37
|
html: ActionController::Base.render(Signum::NotificationDrawerItem::Component.new(signal: self)))
|
|
21
38
|
end
|
|
22
39
|
|
|
@@ -24,13 +41,13 @@ module Signum
|
|
|
24
41
|
return if saved_change_to_state? && (broadcasted? || shown?)
|
|
25
42
|
|
|
26
43
|
if saved_change_to_state? && closed?
|
|
27
|
-
broadcast_remove_to(
|
|
44
|
+
broadcast_remove_to(*stream, target: "notification_drawer_item_parent_#{signalable_id}_#{id}")
|
|
28
45
|
return
|
|
29
46
|
end
|
|
30
47
|
|
|
31
|
-
broadcast_replace_to(
|
|
48
|
+
broadcast_replace_to(*stream, target: Signum.config.notification_body_id.call(:balloon, self),
|
|
32
49
|
html: ActionController::Base.render(Signum::NotificationBody::Component.new(self, {type: :balloon, timeout: 5})))
|
|
33
|
-
broadcast_replace_to(
|
|
50
|
+
broadcast_replace_to(*stream, target: Signum.config.notification_body_id.call(:drawer_item, self),
|
|
34
51
|
html: ActionController::Base.render(Signum::NotificationBody::Component.new(self, {type: :drawer_item, timeout: 5})))
|
|
35
52
|
end
|
|
36
53
|
|
data/lib/signum/configuration.rb
CHANGED
|
@@ -33,6 +33,9 @@ module Signum
|
|
|
33
33
|
option :hide_after, default: 3000
|
|
34
34
|
option :base_controller, default: "::ApplicationController"
|
|
35
35
|
option :current_user, default: lambda {}
|
|
36
|
+
# The records whose signals the current user gets besides their own, e.g. -> { [Current.account] }; a page without
|
|
37
|
+
# a user gets none of them
|
|
38
|
+
option :groups, default: -> { [] }
|
|
36
39
|
option :drawer_notifications_container_id, default: ->(signalable = nil) {
|
|
37
40
|
signalable.is_a?(String) ? "drawer_notifications_#{signalable}" : "drawer_notifications_#{(signalable || Signum.config.current_user.call)&.class&.name}_#{(signalable || Signum.config.current_user.call)&.id}"
|
|
38
41
|
}
|
data/lib/signum/version.rb
CHANGED
data/lib/signum.rb
CHANGED
|
@@ -6,6 +6,9 @@ module Signum
|
|
|
6
6
|
class Error < StandardError
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
# The key of the signals for every page
|
|
10
|
+
ALL = "all"
|
|
11
|
+
|
|
9
12
|
class << self
|
|
10
13
|
def config
|
|
11
14
|
@config ||= Configuration.new
|
|
@@ -20,13 +23,20 @@ module Signum
|
|
|
20
23
|
# @i18n_store ||= Nuntius::I18nStore.new
|
|
21
24
|
# end
|
|
22
25
|
|
|
23
|
-
# Generic notice
|
|
26
|
+
# Generic notice, for:
|
|
27
|
+
#
|
|
28
|
+
# - a user: theirs alone
|
|
29
|
+
# - another record (an account, say): the users whose pages have it among config.groups
|
|
30
|
+
# - several of these (an array or a relation): each of them
|
|
31
|
+
# - a key (a string or symbol): the pages that pass it to Signum::Notifications::Component (a session's id, say),
|
|
32
|
+
# or every page for :all
|
|
24
33
|
def signal(signalable_receiver, options)
|
|
25
34
|
return unless signalable_receiver
|
|
26
35
|
|
|
27
36
|
if signalable_receiver.is_a?(Signum.config.user_model_name.constantize)
|
|
28
37
|
signalable_receiver.signals.create!(options)
|
|
29
|
-
|
|
38
|
+
elsif signalable_receiver.is_a?(ActiveRecord::Base)
|
|
39
|
+
Signal.create!(options.merge(signalable: signalable_receiver))
|
|
30
40
|
elsif signalable_receiver.respond_to?(:each)
|
|
31
41
|
signalable_receiver.each { |signalable| signal(signalable, options) }
|
|
32
42
|
nil
|
|
@@ -35,6 +45,20 @@ module Signum
|
|
|
35
45
|
end
|
|
36
46
|
end
|
|
37
47
|
|
|
48
|
+
# The Turbo stream of a user, group (a record) or key, which its signals are broadcast to
|
|
49
|
+
def stream_for(receiver)
|
|
50
|
+
receiver.is_a?(ActiveRecord::Base) ? [receiver, :signals] : [:signals, receiver.to_s]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The streams a page subscribes to: its user's, every page's (:all), its user's groups' (config.groups) and its
|
|
54
|
+
# keys'. Without a user, no groups: they're for the users of a group, not whoever visits its pages.
|
|
55
|
+
def streams_for(user, keys = [])
|
|
56
|
+
([user, ALL] + groups_for(user) + Array(keys)).compact_blank.uniq.map { |receiver| stream_for(receiver) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The groups whose signals the user gets (config.groups), none without one
|
|
60
|
+
def groups_for(user) = user ? Array(config.groups.call).compact : []
|
|
61
|
+
|
|
38
62
|
# Signal about something that happened
|
|
39
63
|
def info(signalable, options)
|
|
40
64
|
return unless signalable
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: signum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: pg
|
|
@@ -288,7 +287,6 @@ homepage: https://github.com/entdec/signum
|
|
|
288
287
|
licenses:
|
|
289
288
|
- MIT
|
|
290
289
|
metadata: {}
|
|
291
|
-
post_install_message:
|
|
292
290
|
rdoc_options: []
|
|
293
291
|
require_paths:
|
|
294
292
|
- lib
|
|
@@ -303,8 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
303
301
|
- !ruby/object:Gem::Version
|
|
304
302
|
version: '0'
|
|
305
303
|
requirements: []
|
|
306
|
-
rubygems_version: 3.
|
|
307
|
-
signing_key:
|
|
304
|
+
rubygems_version: 3.6.9
|
|
308
305
|
specification_version: 4
|
|
309
306
|
summary: Replacement for flash messages, also from background jobs
|
|
310
307
|
test_files: []
|