lesli_bell 1.1.1 → 1.1.3

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -0
  3. data/app/assets/stylesheets/lesli_bell/application.css +497 -4
  4. data/app/controllers/lesli_bell/announcements_controller.rb +107 -61
  5. data/app/controllers/lesli_bell/notifications_controller.rb +6 -0
  6. data/app/helpers/lesli_bell/announcements_helper.rb +20 -2
  7. data/app/models/lesli_bell/account.rb +4 -1
  8. data/app/models/lesli_bell/announcement/role_recipient.rb +20 -0
  9. data/app/models/lesli_bell/announcement/user.rb +5 -2
  10. data/app/models/lesli_bell/announcement/user_recipient.rb +20 -0
  11. data/app/models/lesli_bell/announcement.rb +97 -2
  12. data/app/services/lesli_bell/announcement_service.rb +111 -64
  13. data/app/services/lesli_bell/notification_service.rb +8 -0
  14. data/app/views/lesli_bell/announcements/_form.html.erb +34 -0
  15. data/app/views/lesli_bell/announcements/edit.html.erb +6 -10
  16. data/app/views/lesli_bell/announcements/index.html.erb +25 -33
  17. data/app/views/lesli_bell/announcements/new.html.erb +6 -9
  18. data/app/views/lesli_bell/announcements/show.html.erb +27 -10
  19. data/app/views/lesli_bell/dashboards/show.html.erb +1 -1
  20. data/app/views/lesli_bell/notifications/index.html.erb +136 -72
  21. data/config/locales/translations.en.yml +72 -1
  22. data/config/locales/translations.es.yml +72 -1
  23. data/config/locales/translations.fr.yml +2 -1
  24. data/config/locales/translations.it.yml +2 -1
  25. data/config/locales/translations.pt.yml +2 -1
  26. data/config/routes.rb +6 -2
  27. data/db/migrate/v1.0/0308100110_create_lesli_bell_notifications.rb +6 -1
  28. data/db/migrate/v1.0/0308110110_create_lesli_bell_announcements.rb +8 -8
  29. data/db/migrate/v1.0/0308110310_create_lesli_bell_announcement_users.rb +3 -3
  30. data/db/migrate/v1.0/0308110410_create_lesli_bell_announcement_recipients.rb +17 -0
  31. data/db/seed/announcements.rb +10 -14
  32. data/db/seed/seeds.json +2 -1
  33. data/lib/lesli_bell/version.rb +2 -2
  34. data/readme.md +3 -2
  35. metadata +10 -5
  36. data/app/assets/config/lesli_bell_manifest.js +0 -40
  37. data/app/assets/stylesheets/lesli_bell/application.tailwind.css +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 230a04119c05f73f87f6fefcffc2f930301763388864f34fa6feb3bcf510598b
4
- data.tar.gz: 654752028cdbe7d683f2c30a8060156f73b5e4a78de4d6dec07a5b1916cc3aa8
3
+ metadata.gz: 1f9b9cb352ab9a1e0f6ec1cf3be97b85a0ea236e8c5ff408f23b98119233f9d7
4
+ data.tar.gz: c1a09650a703ba04dd09644fca6560b07f423b5739847e70d519860ec0eba76f
5
5
  SHA512:
6
- metadata.gz: f6d3dd2e9d2a37278dc122df57f2ab02b344f1c56d92167e4c4ae5eecef40badfda09cc39d8d4716ecccb72b144e111a7c0d54e9c95b300759f9784d630843fc
7
- data.tar.gz: 77dbd210d847f72c9c923f1c010c73ee8453e83f544876a2df1a03edf3af3528530eccb881c0fb23a404fac81da316ea8b0821215818ff7f415af0422c58f8cd
6
+ metadata.gz: 353a35be16ec75b1873fad071a822550b2de57663f601c171e78c3d910e0b7d27a76d6907ba8cb7dca0fb9535e3fff5a8d1ac0cca30199d6cdd689a5867616e3
7
+ data.tar.gz: e505f7fa1314d354346333873e17a027668c447d057e4575c5c42b5e911449b86e0b37d4a565fc420bd50270af4c2c9cd605560f7fcb93bdb7ca24ea5c7ecf86
data/Rakefile CHANGED
@@ -4,3 +4,6 @@ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
4
  load "rails/tasks/engine.rake"
5
5
 
6
6
  require "bundler/gem_tasks"
7
+
8
+ desc "Run engine tests through the dummy Rails application"
9
+ task test: "app:test"
@@ -1,4 +1,497 @@
1
- /*!***********************************************************************************************************************************************************!*\
2
- !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./node_modules/sass-loader/dist/cjs.js!../LesliBell/lib/scss/application.scss ***!
3
- \***********************************************************************************************************************************************************/
4
-
1
+ /*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
2
+ @layer properties;
3
+ @layer theme, utilities;
4
+ @layer theme {
5
+ :root, :host {
6
+ --color-sky-50: oklch(97.7% 0.013 236.62);
7
+ --color-sky-100: oklch(95.1% 0.026 236.824);
8
+ --color-sky-200: oklch(90.1% 0.058 230.902);
9
+ --color-sky-500: oklch(68.5% 0.169 237.323);
10
+ --color-sky-700: oklch(50% 0.134 242.749);
11
+ --color-sky-800: oklch(44.3% 0.11 240.79);
12
+ --color-slate-50: oklch(98.4% 0.003 247.858);
13
+ --color-slate-100: oklch(96.8% 0.007 247.896);
14
+ --color-slate-200: oklch(92.9% 0.013 255.508);
15
+ --color-slate-400: oklch(70.4% 0.04 256.788);
16
+ --color-slate-500: oklch(55.4% 0.046 257.417);
17
+ --color-slate-600: oklch(44.6% 0.043 257.281);
18
+ --color-slate-800: oklch(27.9% 0.041 260.031);
19
+ --color-white: #fff;
20
+ --spacing: 0.25rem;
21
+ --text-xs: 0.75rem;
22
+ --text-xs--line-height: calc(1 / 0.75);
23
+ --text-sm: 0.875rem;
24
+ --text-sm--line-height: calc(1.25 / 0.875);
25
+ --text-base: 1rem;
26
+ --text-base--line-height: calc(1.5 / 1);
27
+ --text-lg: 1.125rem;
28
+ --text-lg--line-height: calc(1.75 / 1.125);
29
+ --text-xl: 1.25rem;
30
+ --text-xl--line-height: calc(1.75 / 1.25);
31
+ --font-weight-medium: 500;
32
+ --font-weight-semibold: 600;
33
+ --radius-md: 0.375rem;
34
+ --radius-lg: 0.5rem;
35
+ --radius-2xl: 1rem;
36
+ --default-transition-duration: 150ms;
37
+ --default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
38
+ }
39
+ }
40
+ @layer utilities {
41
+ .absolute {
42
+ position: absolute;
43
+ }
44
+ .relative {
45
+ position: relative;
46
+ }
47
+ .inset-y-0 {
48
+ inset-block: 0px;
49
+ }
50
+ .top-3\.5 {
51
+ top: calc(var(--spacing) * 3.5);
52
+ }
53
+ .right-4 {
54
+ right: calc(var(--spacing) * 4);
55
+ }
56
+ .left-0 {
57
+ left: 0px;
58
+ }
59
+ .mt-1 {
60
+ margin-top: var(--spacing);
61
+ }
62
+ .mt-1\.5 {
63
+ margin-top: calc(var(--spacing) * 1.5);
64
+ }
65
+ .mt-6 {
66
+ margin-top: calc(var(--spacing) * 6);
67
+ }
68
+ .mb-6 {
69
+ margin-bottom: calc(var(--spacing) * 6);
70
+ }
71
+ .line-clamp-2 {
72
+ overflow: hidden;
73
+ display: -webkit-box;
74
+ -webkit-box-orient: vertical;
75
+ -webkit-line-clamp: 2;
76
+ }
77
+ .block {
78
+ display: block;
79
+ }
80
+ .flex {
81
+ display: flex;
82
+ }
83
+ .grid {
84
+ display: grid;
85
+ }
86
+ .inline-flex {
87
+ display: inline-flex;
88
+ }
89
+ .size-8 {
90
+ width: calc(var(--spacing) * 8);
91
+ height: calc(var(--spacing) * 8);
92
+ }
93
+ .size-9 {
94
+ width: calc(var(--spacing) * 9);
95
+ height: calc(var(--spacing) * 9);
96
+ }
97
+ .w-1 {
98
+ width: var(--spacing);
99
+ }
100
+ .w-fit {
101
+ width: fit-content;
102
+ }
103
+ .min-w-0 {
104
+ min-width: 0px;
105
+ }
106
+ .flex-1 {
107
+ flex: 1;
108
+ }
109
+ .shrink-0 {
110
+ flex-shrink: 0;
111
+ }
112
+ .flex-wrap {
113
+ flex-wrap: wrap;
114
+ }
115
+ .items-center {
116
+ align-items: center;
117
+ }
118
+ .items-start {
119
+ align-items: flex-start;
120
+ }
121
+ .justify-center {
122
+ justify-content: center;
123
+ }
124
+ .gap-1 {
125
+ gap: var(--spacing);
126
+ }
127
+ .gap-2 {
128
+ gap: calc(var(--spacing) * 2);
129
+ }
130
+ .gap-3 {
131
+ gap: calc(var(--spacing) * 3);
132
+ }
133
+ .gap-4 {
134
+ gap: calc(var(--spacing) * 4);
135
+ }
136
+ .gap-x-2 {
137
+ column-gap: calc(var(--spacing) * 2);
138
+ }
139
+ .gap-y-1 {
140
+ row-gap: var(--spacing);
141
+ }
142
+ :where(.divide-y > :not(:last-child)) {
143
+ --tw-divide-y-reverse: 0;
144
+ border-bottom-style: var(--tw-border-style);
145
+ border-top-style: var(--tw-border-style);
146
+ border-top-width: calc(1px * var(--tw-divide-y-reverse));
147
+ border-bottom-width: calc(1px * calc(1 - var(--tw-divide-y-reverse)));
148
+ }
149
+ :where(.divide-slate-200 > :not(:last-child)) {
150
+ border-color: var(--color-slate-200);
151
+ }
152
+ .overflow-hidden {
153
+ overflow: hidden;
154
+ }
155
+ .rounded-2xl {
156
+ border-radius: var(--radius-2xl);
157
+ }
158
+ .rounded-full {
159
+ border-radius: calc(infinity * 1px);
160
+ }
161
+ .rounded-lg {
162
+ border-radius: var(--radius-lg);
163
+ }
164
+ .rounded-md {
165
+ border-radius: var(--radius-md);
166
+ }
167
+ .border {
168
+ border-style: var(--tw-border-style);
169
+ border-width: 1px;
170
+ }
171
+ .border-slate-200 {
172
+ border-color: var(--color-slate-200);
173
+ }
174
+ .border-transparent {
175
+ border-color: transparent;
176
+ }
177
+ .bg-danger-50 {
178
+ background-color: var(--lesli-color-danger-50);
179
+ }
180
+ .bg-danger-500 {
181
+ background-color: var(--lesli-color-danger-500);
182
+ }
183
+ .bg-info-50 {
184
+ background-color: var(--lesli-color-info-50);
185
+ }
186
+ .bg-info-500 {
187
+ background-color: var(--lesli-color-info-500);
188
+ }
189
+ .bg-neutral-50 {
190
+ background-color: var(--lesli-color-neutral-50);
191
+ }
192
+ .bg-neutral-400 {
193
+ background-color: var(--lesli-color-neutral-400);
194
+ }
195
+ .bg-sky-50 {
196
+ background-color: var(--color-sky-50);
197
+ }
198
+ .bg-slate-100 {
199
+ background-color: var(--color-slate-100);
200
+ }
201
+ .bg-success-50 {
202
+ background-color: var(--lesli-color-success-50);
203
+ }
204
+ .bg-success-500 {
205
+ background-color: var(--lesli-color-success-500);
206
+ }
207
+ .bg-warning-50 {
208
+ background-color: var(--lesli-color-warning-50);
209
+ }
210
+ .bg-warning-500 {
211
+ background-color: var(--lesli-color-warning-500);
212
+ }
213
+ .bg-white {
214
+ background-color: var(--color-white);
215
+ }
216
+ .px-2 {
217
+ padding-inline: calc(var(--spacing) * 2);
218
+ }
219
+ .px-3 {
220
+ padding-inline: calc(var(--spacing) * 3);
221
+ }
222
+ .px-4 {
223
+ padding-inline: calc(var(--spacing) * 4);
224
+ }
225
+ .py-0\.5 {
226
+ padding-block: calc(var(--spacing) * 0.5);
227
+ }
228
+ .py-1\.5 {
229
+ padding-block: calc(var(--spacing) * 1.5);
230
+ }
231
+ .py-3\.5 {
232
+ padding-block: calc(var(--spacing) * 3.5);
233
+ }
234
+ .pr-14 {
235
+ padding-right: calc(var(--spacing) * 14);
236
+ }
237
+ .text-base {
238
+ font-size: var(--text-base);
239
+ line-height: var(--tw-leading, var(--text-base--line-height));
240
+ }
241
+ .text-lg {
242
+ font-size: var(--text-lg);
243
+ line-height: var(--tw-leading, var(--text-lg--line-height));
244
+ }
245
+ .text-sm {
246
+ font-size: var(--text-sm);
247
+ line-height: var(--tw-leading, var(--text-sm--line-height));
248
+ }
249
+ .text-xl {
250
+ font-size: var(--text-xl);
251
+ line-height: var(--tw-leading, var(--text-xl--line-height));
252
+ }
253
+ .text-xs {
254
+ font-size: var(--text-xs);
255
+ line-height: var(--tw-leading, var(--text-xs--line-height));
256
+ }
257
+ .leading-5 {
258
+ --tw-leading: calc(var(--spacing) * 5);
259
+ line-height: calc(var(--spacing) * 5);
260
+ }
261
+ .leading-none {
262
+ --tw-leading: 1;
263
+ line-height: 1;
264
+ }
265
+ .font-medium {
266
+ --tw-font-weight: var(--font-weight-medium);
267
+ font-weight: var(--font-weight-medium);
268
+ }
269
+ .font-semibold {
270
+ --tw-font-weight: var(--font-weight-semibold);
271
+ font-weight: var(--font-weight-semibold);
272
+ }
273
+ .break-words {
274
+ overflow-wrap: break-word;
275
+ }
276
+ .whitespace-pre-wrap {
277
+ white-space: pre-wrap;
278
+ }
279
+ .text-danger-700 {
280
+ color: var(--lesli-color-danger-700);
281
+ }
282
+ .text-info-700 {
283
+ color: var(--lesli-color-info-700);
284
+ }
285
+ .text-neutral-700 {
286
+ color: var(--lesli-color-neutral-700);
287
+ }
288
+ .text-sky-700 {
289
+ color: var(--color-sky-700);
290
+ }
291
+ .text-slate-400 {
292
+ color: var(--color-slate-400);
293
+ }
294
+ .text-slate-500 {
295
+ color: var(--color-slate-500);
296
+ }
297
+ .text-slate-600 {
298
+ color: var(--color-slate-600);
299
+ }
300
+ .text-slate-800 {
301
+ color: var(--color-slate-800);
302
+ }
303
+ .text-success-700 {
304
+ color: var(--lesli-color-success-700);
305
+ }
306
+ .text-warning-700 {
307
+ color: var(--lesli-color-warning-700);
308
+ }
309
+ .shadow-sm {
310
+ --tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
311
+ box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
312
+ }
313
+ .ring-1 {
314
+ --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
315
+ box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
316
+ }
317
+ .ring-danger-200 {
318
+ --tw-ring-color: var(--lesli-color-danger-200);
319
+ }
320
+ .ring-sky-200 {
321
+ --tw-ring-color: var(--color-sky-200);
322
+ }
323
+ .ring-warning-200 {
324
+ --tw-ring-color: var(--lesli-color-warning-200);
325
+ }
326
+ .transition-colors {
327
+ transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to;
328
+ transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
329
+ transition-duration: var(--tw-duration, var(--default-transition-duration));
330
+ }
331
+ .ring-inset {
332
+ --tw-ring-inset: inset;
333
+ }
334
+ @media (hover: hover) {
335
+ .hover\:bg-sky-100:hover {
336
+ background-color: var(--color-sky-100);
337
+ }
338
+ .hover\:bg-slate-50:hover {
339
+ background-color: var(--color-slate-50);
340
+ }
341
+ .hover\:text-sky-700:hover {
342
+ color: var(--color-sky-700);
343
+ }
344
+ .hover\:text-sky-800:hover {
345
+ color: var(--color-sky-800);
346
+ }
347
+ }
348
+ .focus-visible\:ring-2:focus-visible {
349
+ --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
350
+ box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
351
+ }
352
+ .focus-visible\:ring-sky-500\/30:focus-visible {
353
+ --tw-ring-color: color-mix(in srgb, oklch(68.5% 0.169 237.323) 30%, transparent);
354
+ @supports (color: color-mix(in lab, red, red)) {
355
+ --tw-ring-color: color-mix(in oklab, var(--color-sky-500) 30%, transparent);
356
+ }
357
+ }
358
+ .focus-visible\:ring-offset-2:focus-visible {
359
+ --tw-ring-offset-width: 2px;
360
+ --tw-ring-offset-shadow: var(--tw-ring-inset,) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
361
+ }
362
+ .focus-visible\:outline-none:focus-visible {
363
+ --tw-outline-style: none;
364
+ outline-style: none;
365
+ }
366
+ @media (width >= 40rem) {
367
+ .sm\:top-4 {
368
+ top: calc(var(--spacing) * 4);
369
+ }
370
+ .sm\:right-5 {
371
+ right: calc(var(--spacing) * 5);
372
+ }
373
+ .sm\:grid-cols-2 {
374
+ grid-template-columns: repeat(2, minmax(0, 1fr));
375
+ }
376
+ .sm\:px-5 {
377
+ padding-inline: calc(var(--spacing) * 5);
378
+ }
379
+ .sm\:py-4 {
380
+ padding-block: calc(var(--spacing) * 4);
381
+ }
382
+ .sm\:pr-16 {
383
+ padding-right: calc(var(--spacing) * 16);
384
+ }
385
+ .sm\:text-base {
386
+ font-size: var(--text-base);
387
+ line-height: var(--tw-leading, var(--text-base--line-height));
388
+ }
389
+ }
390
+ }
391
+ @property --tw-divide-y-reverse {
392
+ syntax: "*";
393
+ inherits: false;
394
+ initial-value: 0;
395
+ }
396
+ @property --tw-border-style {
397
+ syntax: "*";
398
+ inherits: false;
399
+ initial-value: solid;
400
+ }
401
+ @property --tw-leading {
402
+ syntax: "*";
403
+ inherits: false;
404
+ }
405
+ @property --tw-font-weight {
406
+ syntax: "*";
407
+ inherits: false;
408
+ }
409
+ @property --tw-shadow {
410
+ syntax: "*";
411
+ inherits: false;
412
+ initial-value: 0 0 #0000;
413
+ }
414
+ @property --tw-shadow-color {
415
+ syntax: "*";
416
+ inherits: false;
417
+ }
418
+ @property --tw-shadow-alpha {
419
+ syntax: "<percentage>";
420
+ inherits: false;
421
+ initial-value: 100%;
422
+ }
423
+ @property --tw-inset-shadow {
424
+ syntax: "*";
425
+ inherits: false;
426
+ initial-value: 0 0 #0000;
427
+ }
428
+ @property --tw-inset-shadow-color {
429
+ syntax: "*";
430
+ inherits: false;
431
+ }
432
+ @property --tw-inset-shadow-alpha {
433
+ syntax: "<percentage>";
434
+ inherits: false;
435
+ initial-value: 100%;
436
+ }
437
+ @property --tw-ring-color {
438
+ syntax: "*";
439
+ inherits: false;
440
+ }
441
+ @property --tw-ring-shadow {
442
+ syntax: "*";
443
+ inherits: false;
444
+ initial-value: 0 0 #0000;
445
+ }
446
+ @property --tw-inset-ring-color {
447
+ syntax: "*";
448
+ inherits: false;
449
+ }
450
+ @property --tw-inset-ring-shadow {
451
+ syntax: "*";
452
+ inherits: false;
453
+ initial-value: 0 0 #0000;
454
+ }
455
+ @property --tw-ring-inset {
456
+ syntax: "*";
457
+ inherits: false;
458
+ }
459
+ @property --tw-ring-offset-width {
460
+ syntax: "<length>";
461
+ inherits: false;
462
+ initial-value: 0px;
463
+ }
464
+ @property --tw-ring-offset-color {
465
+ syntax: "*";
466
+ inherits: false;
467
+ initial-value: #fff;
468
+ }
469
+ @property --tw-ring-offset-shadow {
470
+ syntax: "*";
471
+ inherits: false;
472
+ initial-value: 0 0 #0000;
473
+ }
474
+ @layer properties {
475
+ @supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
476
+ *, ::before, ::after, ::backdrop {
477
+ --tw-divide-y-reverse: 0;
478
+ --tw-border-style: solid;
479
+ --tw-leading: initial;
480
+ --tw-font-weight: initial;
481
+ --tw-shadow: 0 0 #0000;
482
+ --tw-shadow-color: initial;
483
+ --tw-shadow-alpha: 100%;
484
+ --tw-inset-shadow: 0 0 #0000;
485
+ --tw-inset-shadow-color: initial;
486
+ --tw-inset-shadow-alpha: 100%;
487
+ --tw-ring-color: initial;
488
+ --tw-ring-shadow: 0 0 #0000;
489
+ --tw-inset-ring-color: initial;
490
+ --tw-inset-ring-shadow: 0 0 #0000;
491
+ --tw-ring-inset: initial;
492
+ --tw-ring-offset-width: 0px;
493
+ --tw-ring-offset-color: #fff;
494
+ --tw-ring-offset-shadow: 0 0 #0000;
495
+ }
496
+ }
497
+ }
@@ -1,75 +1,121 @@
1
1
  module LesliBell
2
- class AnnouncementsController < ApplicationController
3
- before_action :set_announcement, only: %i[ show edit update destroy ]
2
+ class AnnouncementsController < ApplicationController
3
+ prepend_before_action :use_html_for_page_navigation, only: [:index, :show, :new, :edit]
4
+ before_action :load_service
5
+ before_action :load_announcement, only: [:show, :edit, :update, :destroy]
6
+ before_action :load_audience_options, only: [:new, :edit, :create, :update]
7
+ rescue_from ActiveRecord::RecordNotFound do
8
+ if action_name == "dismiss" && request.format.turbo_stream?
9
+ dismissal_error(:not_found)
10
+ else
11
+ respond_with_not_found
12
+ end
13
+ end
4
14
 
5
- # GET /announcements/list
6
- def list
7
- respond_to do |format|
8
- format.html { }
9
- format.json {
10
- respond_with_pagination(AnnouncementService.new(current_user, query).list)
11
- }
15
+ def index
16
+ @announcements = @service.index.result
17
+ respond_with_lesli(json: respond_with_pagination(@announcements))
12
18
  end
13
- end
14
19
 
15
- # GET /announcements
16
- def index
17
- respond_to do |format|
18
- format.html { }
19
- format.json {
20
- respond_with_pagination(AnnouncementService.new(current_user, query).index)
21
- }
20
+ def show
21
+ respond_with_lesli(json: announcement_json)
22
22
  end
23
- end
24
23
 
25
- # GET /announcements/1
26
- def show
27
- end
24
+ def new
25
+ @announcement = Announcement.new
26
+ end
28
27
 
29
- # GET /announcements/new
30
- def new
31
- @announcement = Announcement.new
32
- end
28
+ def edit
29
+ end
33
30
 
34
- # GET /announcements/1/edit
35
- def edit
36
- end
31
+ def create
32
+ @service.create(announcement_params)
33
+ save_response(:new, :created, :created)
34
+ end
37
35
 
38
- # POST /announcements
39
- def create
40
- @announcement = Announcement.new(announcement_params)
36
+ def update
37
+ @service.update(announcement_params)
38
+ save_response(:edit, :updated, :ok)
39
+ end
41
40
 
42
- if @announcement.save
43
- redirect_to @announcement, notice: "Announcement was successfully created."
44
- else
45
- render :new, status: :unprocessable_entity
46
- end
47
- end
41
+ def destroy
42
+ @service.destroy
43
+ success(t("lesli_bell.announcements.deleted"))
44
+ respond_with_lesli(json: { id: @announcement.id }, redirect: announcements_path)
45
+ end
48
46
 
49
- # PATCH/PUT /announcements/1
50
- def update
51
- if @announcement.update(announcement_params)
52
- redirect_to @announcement, notice: "Announcement was successfully updated.", status: :see_other
53
- else
54
- render :edit, status: :unprocessable_entity
55
- end
56
- end
47
+ def dismiss
48
+ dismissal = @service.dismiss(params[:id]).result
49
+ respond_with_lesli(
50
+ turbo: turbo_stream.remove("announcement-#{dismissal.announcement_id}"),
51
+ json: { id: dismissal.announcement_id, dismissed_at: dismissal.created_at },
52
+ redirect: announcements_path
53
+ )
54
+ rescue ActiveRecord::RecordInvalid => exception
55
+ @announcement = exception.record
56
+ respond_with_lesli(
57
+ html: :show, json: { errors: @announcement.errors.to_hash },
58
+ turbo: stream_notification_danger(@announcement.errors.full_messages.to_sentence),
59
+ status: :unprocessable_content
60
+ )
61
+ end
57
62
 
58
- # DELETE /announcements/1
59
- def destroy
60
- @announcement.destroy
61
- redirect_to announcements_url, notice: "Announcement was successfully destroyed.", status: :see_other
62
- end
63
+ private
64
+
65
+ # Turbo preserves its Accept header when following a form's redirect.
66
+ # These actions render complete pages, including Core's HTML banner loader.
67
+ def use_html_for_page_navigation
68
+ request.format = :html if request.get? && request.format.turbo_stream?
69
+ end
70
+
71
+ # A failed close must not replace the current page or remove its banner.
72
+ # Authorization still runs through Core's existing callback.
73
+ def respond_with_forbidden(details = {})
74
+ return super unless action_name == "dismiss" && request.format.turbo_stream?
63
75
 
64
- private
65
- # Use callbacks to share common setup or constraints between actions.
66
- def set_announcement
67
- @announcement = Announcement.find(params[:id])
68
- end
69
-
70
- # Only allow a list of trusted parameters through.
71
- def announcement_params
72
- params.fetch(:announcement, {})
73
- end
74
- end
76
+ dismissal_error(:forbidden)
77
+ end
78
+
79
+ def dismissal_error(status)
80
+ respond_with_lesli(
81
+ turbo: stream_notification_danger(t("lesli_bell.announcements.dismiss_failed")),
82
+ status: status
83
+ )
84
+ end
85
+
86
+ def load_service
87
+ @service = AnnouncementService.new(current_user, query)
88
+ end
89
+
90
+ def load_announcement
91
+ @announcement = @service.show(params[:id]).result
92
+ end
93
+
94
+ def load_audience_options
95
+ @audience_users = current_user.account.users.order(:email).pluck(:email, :id)
96
+ @audience_roles = current_user.account.roles.order(:name).pluck(:name, :id) if defined?(LesliShield)
97
+ end
98
+
99
+ def announcement_json
100
+ @announcement.as_json.merge(user_ids: @announcement.user_ids, role_ids: @announcement.role_ids)
101
+ end
102
+
103
+ def announcement_params
104
+ params.require(:announcement).permit(*AnnouncementService::EDITABLE_ATTRIBUTES, user_ids: [], role_ids: []).to_h
105
+ end
106
+
107
+ def save_response(template, message, status)
108
+ @announcement = @service.result
109
+ unless @service.successful?
110
+ return respond_with_lesli(
111
+ html: template, json: { errors: @announcement.errors.to_hash },
112
+ turbo: turbo_stream.replace("announcement-form", partial: "lesli_bell/announcements/form"),
113
+ status: :unprocessable_content
114
+ )
115
+ end
116
+
117
+ success(t("lesli_bell.announcements.#{message}"))
118
+ respond_with_lesli(json: announcement_json, status: status, redirect: announcement_path(@announcement))
119
+ end
120
+ end
75
121
  end