thecore_ui_rails_admin 3.6.0 → 3.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f0f9ff82a9d4a2cc4314ccc51dd88fcfe37059009d1938ed60368da30568813
4
- data.tar.gz: ff995296978667fe0d7c63195bda829687a5d11d7dc048d139750990e5171ea9
3
+ metadata.gz: 50e80608e69b0ee8cfd136957a049fa919a6b332310d89c6c7122e6c35b09444
4
+ data.tar.gz: 30dd4923a3702ce54f4f223fddea9b9f29c327d768b8d46174bcdaff09121847
5
5
  SHA512:
6
- metadata.gz: 9a1f1bc950e6dce9e7cfd85d3353bbd565665c902d796db09d636bb2a624d88bf2cb0ee59753453f42649dbdd6fd40204cdab4fbb8db63b4ddf5499dc431386b
7
- data.tar.gz: 61a7520b5a29ace19b4d42950484efd0dae62371bd07baf3210d937286478a821afeb2f2ebd80056a1780f1db1d9e41a277f423b6e23fcd5102bc5bc58f5bc1f
6
+ metadata.gz: 7131d117f2d46e39b1a5cb7935e01ed5e0aa2307bb87bf76c4f174db009726cc4be0ca8cb9508d068716d0aa908811461e090411b5c3a6dcbdc8d314afdca9a2
7
+ data.tar.gz: 93a7655e5c9aea60c1eeb3157177066728dc1e98660711301a797d2d2899d5cb92e203ed135e3a43bd206b739362281b2c2068b2b1b036e680d7c54f382dd257
@@ -1,7 +1,7 @@
1
1
  <span class="hide-toolbar"></span>
2
2
 
3
3
  <div class="container mt-4">
4
- <h2>Push Notification Test</h2>
4
+ <h2><%= t("admin.actions.push_notification_test.title") %></h2>
5
5
 
6
6
  <% if flash[:success].present? %>
7
7
  <div class="alert alert-success"><%= flash[:success] %></div>
@@ -10,10 +10,41 @@
10
10
  <div class="alert alert-danger"><%= flash[:error] %></div>
11
11
  <% end %>
12
12
 
13
- <%= form_with url: push_notification_test_path, method: :post, local: true do |form| %>
13
+ <datalist id="subscriber-email-list">
14
+ <% @subscriber_emails.each do |email| %>
15
+ <option value="<%= email %>">
16
+ <% end %>
17
+ </datalist>
18
+
19
+ <%= form_with url: push_notification_test_path, method: :get, local: true do |f| %>
20
+ <div class="card mb-4">
21
+ <div class="card-header d-flex align-items-center justify-content-between">
22
+ <h5 class="mb-0"><%= t("admin.actions.push_notification_test.filter_title") %></h5>
23
+ <span class="badge bg-secondary">
24
+ <%= t("admin.actions.push_notification_test.total_count", count: @total_count) %>
25
+ </span>
26
+ </div>
27
+ <div class="card-body">
28
+ <div class="input-group">
29
+ <%= f.text_field :q,
30
+ value: params[:q],
31
+ class: "form-control",
32
+ placeholder: t("admin.actions.push_notification_test.filter_placeholder"),
33
+ list: "subscriber-email-list",
34
+ autocomplete: "off" %>
35
+ <%= f.submit t("admin.actions.push_notification_test.filter_button"),
36
+ class: "btn btn-secondary" %>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <% end %>
41
+
42
+ <%= form_with url: push_notification_test_path, method: :post, local: true, id: "send-push-form" do |form| %>
43
+ <%= hidden_field_tag :q, params[:q] %>
44
+
14
45
  <div class="card mb-4">
15
46
  <div class="card-header">
16
- <h5 class="mb-0">Select Subscribers</h5>
47
+ <h5 class="mb-0"><%= t("admin.actions.push_notification_test.select_subscribers") %></h5>
17
48
  </div>
18
49
  <div class="card-body">
19
50
  <% if @subscribers.any? %>
@@ -22,7 +53,7 @@
22
53
  <%= check_box_tag "subscriber_ids[]",
23
54
  subscriber.id,
24
55
  false,
25
- class: "form-check-input",
56
+ class: "form-check-input subscriber-checkbox",
26
57
  id: "subscriber_#{subscriber.id}" %>
27
58
  <label class="form-check-label" for="subscriber_<%= subscriber.id %>">
28
59
  <strong><%= subscriber.user&.email || "user ##{subscriber.user_id}" %></strong>
@@ -33,44 +64,73 @@
33
64
  </label>
34
65
  </div>
35
66
  <% end %>
67
+ <% elsif params[:q].present? %>
68
+ <p class="text-muted"><%= t("admin.actions.push_notification_test.no_results") %></p>
36
69
  <% else %>
37
- <p class="text-muted">No active subscribers found.</p>
70
+ <p class="text-muted">
71
+ <%= t("admin.actions.push_notification_test.disclaimer_no_filter", count: @total_count) %>
72
+ </p>
38
73
  <% end %>
39
74
  </div>
40
75
  </div>
41
76
 
42
- <div class="card mb-4">
43
- <div class="card-header">
44
- <h5 class="mb-0">Message</h5>
45
- </div>
46
- <div class="card-body">
47
- <div class="mb-3">
48
- <%= form.label :title, "Title", class: "form-label" %>
49
- <%= form.text_field :title, class: "form-control", required: true,
50
- placeholder: "Notification title" %>
77
+ <% if @subscribers.any? %>
78
+ <div class="card mb-4">
79
+ <div class="card-header">
80
+ <h5 class="mb-0"><%= t("admin.actions.push_notification_test.message_title") %></h5>
51
81
  </div>
82
+ <div class="card-body">
83
+ <div class="mb-3">
84
+ <%= form.label :title, t("admin.actions.push_notification_test.title_label"), class: "form-label" %>
85
+ <%= form.text_field :title, class: "form-control", required: true,
86
+ placeholder: t("admin.actions.push_notification_test.title_placeholder") %>
87
+ </div>
52
88
 
53
- <div class="mb-3">
54
- <%= form.label :body, "Body", class: "form-label" %>
55
- <%= form.text_area :body, class: "form-control", rows: 3, required: true,
56
- placeholder: "Notification body text" %>
57
- </div>
89
+ <div class="mb-3">
90
+ <%= form.label :body, t("admin.actions.push_notification_test.body_label"), class: "form-label" %>
91
+ <%= form.text_area :body, class: "form-control", rows: 3,
92
+ placeholder: t("admin.actions.push_notification_test.body_placeholder") %>
93
+ </div>
58
94
 
59
- <div class="mb-3">
60
- <%= form.label :url, "URL (optional)", class: "form-label" %>
61
- <%= form.url_field :url, class: "form-control",
62
- placeholder: "https://example.com/target-page" %>
63
- </div>
95
+ <div class="mb-3">
96
+ <%= form.label :url, t("admin.actions.push_notification_test.url_label"), class: "form-label" %>
97
+ <%= form.url_field :url, class: "form-control",
98
+ placeholder: "https://example.com/target-page" %>
99
+ </div>
64
100
 
65
- <div class="mb-3">
66
- <%= form.label :icon, "Icon URL (optional)", class: "form-label" %>
67
- <%= form.url_field :icon, class: "form-control",
68
- placeholder: "https://example.com/icon.png" %>
69
- </div>
101
+ <div class="mb-3">
102
+ <%= form.label :icon, t("admin.actions.push_notification_test.icon_label"), class: "form-label" %>
103
+ <%= form.url_field :icon, class: "form-control",
104
+ placeholder: "https://example.com/icon.png" %>
105
+ </div>
70
106
 
71
- <%= form.submit "Send Test", class: "btn btn-primary",
72
- disabled: @subscribers.empty? %>
107
+ <%= form.submit t("admin.actions.push_notification_test.send_button"),
108
+ class: "btn btn-primary",
109
+ id: "send-push-btn" %>
110
+ </div>
73
111
  </div>
74
- </div>
112
+ <% end %>
75
113
  <% end %>
76
114
  </div>
115
+
116
+ <script>
117
+ (function () {
118
+ var form = document.getElementById("send-push-form");
119
+ if (!form) return;
120
+
121
+ var threshold = <%= @large_subscriber_threshold %>;
122
+ var warningTemplate = "<%= j t('admin.actions.push_notification_test.large_selection_warning',
123
+ count: '__N__',
124
+ threshold: @large_subscriber_threshold) %>";
125
+
126
+ form.addEventListener("submit", function (e) {
127
+ var checked = form.querySelectorAll(".subscriber-checkbox:checked").length;
128
+ if (checked > threshold) {
129
+ var msg = warningTemplate.replace("__N__", checked);
130
+ if (!confirm(msg)) {
131
+ e.preventDefault();
132
+ }
133
+ }
134
+ });
135
+ })();
136
+ </script>
@@ -38,6 +38,8 @@ Rails.application.configure do
38
38
  Role.send :include, ThecoreUiRailsAdminRoleConcern
39
39
  User.send :include, ThecoreUiRailsAdminUserConcern
40
40
  RoleUser.send :include, ThecoreUiRailsAdminRoleUserConcern
41
+ PushSubscriber.send :include, ThecoreUiRailsAdminPushSubscriberConcern
42
+ PushMessage.send :include, ThecoreUiRailsAdminPushMessageConcern
41
43
  Action.send :include, ThecoreUiRailsAdminActionConcern
42
44
  PermissionRole.send :include, ThecoreUiRailsAdminPermissionRoleConcern
43
45
  Permission.send :include, ThecoreUiRailsAdminPermissionConcern
@@ -0,0 +1,21 @@
1
+ require 'active_support/concern'
2
+
3
+ module ThecoreUiRailsAdminPushMessageConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ navigation_label 'Push Notifications'
9
+ navigation_icon 'fa fa-envelope'
10
+
11
+ parent PushSubscriber
12
+
13
+ configure :created_at do
14
+ hide
15
+ end
16
+ configure :updated_at do
17
+ hide
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/concern'
2
+
3
+ module ThecoreUiRailsAdminPushSubscriberConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ navigation_label 'Push Notifications'
9
+ navigation_icon 'fa fa-bell'
10
+
11
+ configure :created_at do
12
+ hide
13
+ end
14
+ configure :updated_at do
15
+ hide
16
+ end
17
+ configure :p256dh do
18
+ hide
19
+ end
20
+ configure :auth do
21
+ hide
22
+ end
23
+ end
24
+ end
25
+ end
@@ -60,6 +60,22 @@ en:
60
60
  breadcrumb: Test Push Notification
61
61
  success: "Sent test notification to %{count} subscriber(s)"
62
62
  error_blank_title: "Title can't be blank"
63
+ filter_title: "Filter Subscribers"
64
+ filter_placeholder: "Search by email..."
65
+ filter_button: "Search"
66
+ total_count: "%{count} active subscriber(s)"
67
+ disclaimer_no_filter: "There are %{count} active subscriber(s) in the system. Start typing an email address in the search field above to filter and select recipients."
68
+ no_results: "No active subscribers found for this email."
69
+ select_subscribers: "Select Subscribers"
70
+ message_title: "Message"
71
+ title_label: "Title"
72
+ title_placeholder: "Notification title"
73
+ body_label: "Body"
74
+ body_placeholder: "Notification body text"
75
+ url_label: "URL (optional)"
76
+ icon_label: "Icon URL (optional)"
77
+ send_button: "Send Test"
78
+ large_selection_warning: "You are about to send to %{count} subscriber(s). This may take a while. Do you want to continue?"
63
79
  scopes:
64
80
  _all: All
65
81
  flash:
@@ -60,6 +60,22 @@ it:
60
60
  breadcrumb: Test Notifica Push
61
61
  success: "Notifica di test inviata a %{count} sottoscrittore/i"
62
62
  error_blank_title: "Il titolo non può essere vuoto"
63
+ filter_title: "Filtra Subscriber"
64
+ filter_placeholder: "Cerca per email..."
65
+ filter_button: "Cerca"
66
+ total_count: "%{count} subscriber/i attivi"
67
+ disclaimer_no_filter: "Ci sono %{count} subscriber/i attivi nel sistema. Inizia a digitare un indirizzo email nel campo di ricerca per filtrare e selezionare i destinatari."
68
+ no_results: "Nessun subscriber attivo trovato per questa email."
69
+ select_subscribers: "Seleziona Subscriber"
70
+ message_title: "Messaggio"
71
+ title_label: "Titolo"
72
+ title_placeholder: "Titolo della notifica"
73
+ body_label: "Testo"
74
+ body_placeholder: "Testo del messaggio"
75
+ url_label: "URL (opzionale)"
76
+ icon_label: "URL icona (opzionale)"
77
+ send_button: "Invia Test"
78
+ large_selection_warning: "Stai per inviare a %{count} subscriber/i. L'operazione potrebbe richiedere del tempo. Vuoi continuare?"
63
79
  scopes:
64
80
  _all: Tutti
65
81
  flash:
@@ -1,3 +1,5 @@
1
+ LARGE_SUBSCRIBER_THRESHOLD = 10
2
+
1
3
  RailsAdmin::Config::Actions.add_action "push_notification_test", :base, :root do
2
4
  show_in_sidebar true
3
5
  show_in_navigation false
@@ -12,7 +14,16 @@ RailsAdmin::Config::Actions.add_action "push_notification_test", :base, :root do
12
14
 
13
15
  controller do
14
16
  proc do
15
- @subscribers = PushSubscriber.active.includes(:user)
17
+ @large_subscriber_threshold = LARGE_SUBSCRIBER_THRESHOLD
18
+ @total_count = PushSubscriber.active.count
19
+ @subscriber_emails = User.joins(:push_subscribers).merge(PushSubscriber.active).distinct.pluck(:email)
20
+
21
+ filter_query = params[:q].presence
22
+ @subscribers = if filter_query
23
+ PushSubscriber.active.includes(:user).joins(:user).where("users.email ILIKE ?", "%#{filter_query}%")
24
+ else
25
+ []
26
+ end
16
27
 
17
28
  if request.post?
18
29
  params.permit!
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiRailsAdmin
2
- VERSION = "3.6.0".freeze
2
+ VERSION = "3.7.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_ui_rails_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
@@ -107,6 +107,8 @@ files:
107
107
  - config/initializers/concern_permission.rb
108
108
  - config/initializers/concern_permission_role.rb
109
109
  - config/initializers/concern_predicate.rb
110
+ - config/initializers/concern_push_message.rb
111
+ - config/initializers/concern_push_subscriber.rb
110
112
  - config/initializers/concern_r_a_application_controller.rb
111
113
  - config/initializers/concern_role.rb
112
114
  - config/initializers/concern_role_user.rb