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
@@ -37,6 +37,12 @@ module LesliBell
37
37
  render :index
38
38
  end
39
39
 
40
+ # PUT /notifications/mark_all_as_read
41
+ def mark_all_as_read
42
+ NotificationService.new(current_user).read_all
43
+ redirect_to notifications_path, status: :see_other
44
+ end
45
+
40
46
  # DELETE /notifications/1
41
47
  def destroy
42
48
  @notification.destroy
@@ -1,4 +1,22 @@
1
1
  module LesliBell
2
- module AnnouncementsHelper
3
- end
2
+ module AnnouncementsHelper
3
+ def announcement_categories
4
+ Announcement.categories.keys.map { |category| [t("lesli_bell.announcements.categories.#{category}"), category] }
5
+ end
6
+
7
+ def announcement_audiences
8
+ Announcement.audiences.keys.map { |audience| [t("lesli_bell.announcements.audiences.#{audience}"), audience] }
9
+ end
10
+
11
+ def announcement_audience_summary(announcement)
12
+ return t("lesli_bell.announcements.audiences.account") if announcement.audience_account?
13
+
14
+ labels = announcement.recipient_users.pluck(:email) + announcement.recipient_roles.pluck(:name)
15
+ labels.presence&.join(", ") || t("lesli_bell.announcements.audience_empty")
16
+ end
17
+
18
+ def announcement_datetime(value)
19
+ value ? l(value, format: :long) : t("lesli_bell.announcements.no_limit")
20
+ end
21
+ end
4
22
  end
@@ -1,6 +1,9 @@
1
1
  module LesliBell
2
2
  class Account < ApplicationRecord
3
- belongs_to :account, class_name: "::Lesli::Account"
3
+ belongs_to :account,
4
+ class_name: "Lesli::Account",
5
+ inverse_of: :bell
6
+ validates :account_id, uniqueness: true
4
7
  has_many :notifications
5
8
  has_many :announcements
6
9
  end
@@ -0,0 +1,20 @@
1
+ module LesliBell
2
+ class Announcement::RoleRecipient < ActiveRecord::Base
3
+ self.table_name = "lesli_bell_announcement_role_recipients"
4
+
5
+ belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :role_recipients
6
+ belongs_to :role, class_name: "Lesli::Role"
7
+ validate :recipient_belongs_to_account
8
+ before_destroy -> { announcement.lock! }
9
+ after_destroy -> { announcement.deactivate_without_recipients! }
10
+
11
+ private
12
+
13
+ def recipient_belongs_to_account
14
+ return unless announcement && role
15
+ return if role.account_id == announcement.account.account_id
16
+
17
+ errors.add(:role, :invalid)
18
+ end
19
+ end
20
+ end
@@ -1,6 +1,9 @@
1
1
  module LesliBell
2
- class Announcement::User < ApplicationRecord
3
- belongs_to :announcement
2
+ # Dismissals are permanent records; do not inherit the soft-delete behavior.
3
+ class Announcement::User < ActiveRecord::Base
4
+ self.table_name = "lesli_bell_announcement_users"
5
+
6
+ belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :dismissals
4
7
  belongs_to :user, class_name: "::Lesli::User"
5
8
  end
6
9
  end
@@ -0,0 +1,20 @@
1
+ module LesliBell
2
+ class Announcement::UserRecipient < ActiveRecord::Base
3
+ self.table_name = "lesli_bell_announcement_user_recipients"
4
+
5
+ belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :user_recipients
6
+ belongs_to :user, class_name: "Lesli::User"
7
+ validate :recipient_belongs_to_account
8
+ before_destroy -> { announcement.lock! }
9
+ after_destroy -> { announcement.deactivate_without_recipients! }
10
+
11
+ private
12
+
13
+ def recipient_belongs_to_account
14
+ return unless announcement && user
15
+ return if user.account_id == announcement.account.account_id
16
+
17
+ errors.add(:user, :invalid)
18
+ end
19
+ end
20
+ end
@@ -1,14 +1,109 @@
1
+ require "uri"
2
+
1
3
  module LesliBell
2
4
  class Announcement < ApplicationRecord
3
5
  belongs_to :account, class_name: "LesliBell::Account"
6
+ # The user is the author, not a recipient of the announcement.
4
7
  belongs_to :user, class_name: "::Lesli::User"
5
- has_many :users #, class_name: "::Lesli::User"
8
+ has_many :dismissals, class_name: "LesliBell::Announcement::User", inverse_of: :announcement
9
+
10
+ has_many :user_recipients, class_name: "LesliBell::Announcement::UserRecipient", inverse_of: :announcement
11
+ has_many :role_recipients, class_name: "LesliBell::Announcement::RoleRecipient", inverse_of: :announcement
12
+ has_many :recipient_users, through: :user_recipients, source: :user
13
+ has_many :recipient_roles, through: :role_recipients, source: :role
14
+
15
+ enum :audience, { account: "account", specific: "specific" }, prefix: true, default: :account, validate: true
16
+
17
+ # Submitted IDs remain available to the form when validation fails.
18
+ attr_writer :user_ids, :role_ids
19
+ attr_accessor :allow_empty_audience
6
20
 
7
21
  enum :category, {
8
22
  :info => 'info',
9
23
  :danger => 'danger',
10
24
  :warning => 'warning',
11
25
  :success => 'success'
12
- }
26
+ }, default: :info, validate: true
27
+
28
+ attribute :active, :boolean, default: true
29
+ attribute :can_be_closed, :boolean, default: true
30
+
31
+ normalizes :name, :message, with: ->(value) { value.strip }
32
+ normalizes :path, :url, with: ->(value) { value.strip.presence }
33
+
34
+ validates :name, :message, presence: true
35
+ validates :active, :can_be_closed, inclusion: { in: [true, false] }
36
+ validates :end_at, comparison: { greater_than: :start_at },
37
+ if: -> { start_at.present? && end_at.present? }
38
+
39
+ # Match request.path exactly: no host, query string, fragment, or wildcard.
40
+ validates :path, format: { with: %r{\A/(?!/)[^?#\\\s*]*\z} }, allow_nil: true
41
+ validate :url_is_a_supported_destination
42
+ validate :audience_is_valid
43
+ validate :publication_dates_are_valid
44
+
45
+ def user_ids
46
+ @user_ids || user_recipients.pluck(:user_id)
47
+ end
48
+
49
+ def role_ids
50
+ @role_ids || role_recipients.pluck(:role_id)
51
+ end
52
+
53
+ def clear_audience_selection
54
+ @user_ids = @role_ids = nil
55
+ self.allow_empty_audience = false
56
+ end
57
+
58
+ # Keep a specific audience specific even after its final recipient is removed.
59
+ def deactivate_without_recipients!
60
+ return unless audience_specific?
61
+ return if user_recipients.exists? || role_recipients.exists?
62
+
63
+ # An empty specific audience is intentionally retained but cannot be published.
64
+ # Skip the recipient-presence validation when disabling it.
65
+ update_columns(active: false, updated_at: Time.current)
66
+ end
67
+
68
+ private
69
+
70
+ # Rails casts malformed datetime input to nil; distinguish it from an empty field.
71
+ def publication_dates_are_valid
72
+ [:start_at, :end_at].each do |attribute|
73
+ if public_send("#{attribute}_before_type_cast").present? && public_send(attribute).nil?
74
+ errors.add(attribute, :invalid)
75
+ end
76
+ end
77
+ end
78
+
79
+ def audience_is_valid
80
+ if audience_specific? && user_ids.empty? && role_ids.empty? && !allow_empty_audience
81
+ errors.add(:base, I18n.t("lesli_bell.announcements.audience_required"))
82
+ end
83
+
84
+ core_account = account&.account
85
+ return unless core_account
86
+
87
+ valid_users = core_account.users.where(id: user_ids).pluck(:id).map(&:to_s)
88
+ unless (user_ids.map(&:to_s) - valid_users).empty?
89
+ errors.add(:base, I18n.t("lesli_bell.announcements.invalid_users"))
90
+ end
91
+
92
+ valid_roles = defined?(LesliShield) ? core_account.roles.where(id: role_ids).pluck(:id).map(&:to_s) : []
93
+ unless (role_ids.map(&:to_s) - valid_roles).empty?
94
+ errors.add(:base, I18n.t("lesli_bell.announcements.invalid_roles"))
95
+ end
96
+ end
97
+
98
+ def url_is_a_supported_destination
99
+ return if url.nil?
100
+
101
+ destination = URI.parse(url)
102
+ internal_path = destination.relative? && url.start_with?("/") && !url.start_with?("//")
103
+ web_url = destination.is_a?(URI::HTTP) && destination.host.present?
104
+ errors.add(:url, :invalid) unless internal_path || web_url
105
+ rescue URI::InvalidURIError
106
+ errors.add(:url, :invalid)
107
+ end
13
108
  end
14
109
  end
@@ -1,84 +1,131 @@
1
1
  module LesliBell
2
2
  class AnnouncementService < Lesli::ApplicationLesliService
3
+ EDITABLE_ATTRIBUTES = %i[name message category active start_at end_at path url can_be_closed audience].freeze
4
+
5
+ # Banner selection is independent of administrative pagination.
6
+ # Compare both date boundaries against the same instant.
7
+ def list(path: nil)
8
+ now = Time.current
9
+ dismissed_ids = Announcement::User.where(user: current_user).select(:announcement_id)
10
+
11
+ visible = announcements.where(audience: :account)
12
+ user_matches = Announcement::UserRecipient.where(user_id: current_user.id).select(:announcement_id)
13
+ visible = visible.or(announcements.where(audience: :specific, id: user_matches))
14
+ if defined?(LesliShield)
15
+ memberships = LesliShield::User::Role.where(user: current_user).select(:role_id)
16
+ role_ids = current_user.account.roles.where(id: memberships).select(:id)
17
+ role_matches = Announcement::RoleRecipient.where(role_id: role_ids).select(:announcement_id)
18
+ visible = visible.or(announcements.where(audience: :specific, id: role_matches))
19
+ end
20
+
21
+ visible
22
+ .where(active: true, path: [nil, path.presence])
23
+ .where("start_at IS NULL OR start_at <= ?", now)
24
+ .where("end_at IS NULL OR end_at > ?", now)
25
+ .where.not(id: dismissed_ids)
26
+ .order(:created_at, :id)
27
+ end
3
28
 
4
- def list
5
-
6
- # NOTE: the query must be created in this specific order, if not ActiveRecord creates weird sql
7
- # due the OR statement we are usign to get the announcements with a path
8
-
9
- # Get all the announcements for the current user
10
- announcements = current_user.account.bell.announcements
11
-
12
- # joining to the announcement_users table, to see if the users already mark the announcement as read
13
- announcements = announcements.left_joins(:users)
14
-
15
- # get the announcements without a specific path (global announcements)
16
- announcements = announcements.where(path: nil)
17
-
18
- # get the announcements with a specific path (to show only in a specific page)
19
- #announcements = announcements.or(Announcement.where("path = ?", filters[:base_path])) if params.dig(:f, :base_path)
20
-
21
- # get the announcements with a start date greater than or equal to current date and with expiration date less or equal than current date
22
- # announcements = announcements.where("start_at <= '#{Date.now.end_of_day}' or start_at is NULL")
23
- # .where("cloud_bell_announcements.end_at >= '#{LC::Date.now.beginning_of_day}' or end_at is NULL")
24
-
25
- # get the announcements that are not marked as read by the user
26
- announcements = announcements.where(users: { id: nil })
27
-
28
- announcements.select(
29
- :id,
30
- :name,
31
- :category,
32
- :message,
33
- :can_be_closed,
34
- :start_at,
35
- :end_at,
36
- :path
37
- ).page(query[:pagination][:page])
38
- .per(query[:pagination][:perPage])
39
- .order(:start_at)
29
+ def index
30
+ pagination = query.fetch(:pagination, {})
31
+ response(announcements.order(:created_at, :id)
32
+ .page(pagination[:page]).per(pagination[:perPage]))
40
33
  end
41
34
 
42
- def index
35
+ def show(id)
36
+ response(announcements.find(id))
37
+ end
43
38
 
44
- # work with all notifications
45
- announcements = current_user.account.bell
46
- .announcements
47
- .order(:start_at)
39
+ alias_method :find, :show
48
40
 
49
- # add pagination
50
- announcements
51
- .page(query[:pagination][:page])
52
- .per(query[:pagination][:perPage])
53
- .order(:updated_at)
41
+ def create(attributes)
42
+ announcement = announcements.build(editable_attributes(attributes))
43
+ announcement.user = current_user
44
+ persist(announcement, attributes)
54
45
  end
55
46
 
56
- def create(
57
- announcements_params,
58
- send_to_role_ids:nil,
59
- send_to_user_ids:nil,
60
- send_to_user_emails:nil
61
- )
47
+ def update(attributes)
48
+ persist(resource, attributes)
49
+ end
62
50
 
63
- users = []
51
+ def destroy
52
+ resource.destroy!
53
+ response(resource)
54
+ end
64
55
 
65
- unless Announcement.categories.key?(announcements_params[:category])
66
- announcements_params[:category] = :info
56
+ def dismiss(id)
57
+ announcement = announcements.find(id)
58
+ unless announcement.can_be_closed?
59
+ announcement.errors.add(:base, I18n.t("lesli_bell.announcements.cannot_dismiss"))
60
+ raise ActiveRecord::RecordInvalid.new(announcement)
67
61
  end
68
62
 
69
- announcements_params[:user_id] = current_user.id
63
+ # The unique index makes repeated requests return the same dismissal,
64
+ # preserving the original created_at even when requests overlap.
65
+ self.resource = announcement.dismissals.create_or_find_by!(user: current_user)
66
+ self
67
+ end
70
68
 
71
- announcement = current_user.account.bell.announcements.create!(announcements_params)
69
+ private
72
70
 
73
- self.resource = announcement
71
+ def announcements
72
+ current_user.account.bell.announcements
73
+ end
74
74
 
75
- self
76
- end
75
+ # Ownership comes from the authenticated context, including direct service calls.
76
+ def editable_attributes(attributes)
77
+ attributes.to_h.symbolize_keys.slice(*EDITABLE_ATTRIBUTES)
78
+ end
77
79
 
78
- def read id
79
- noti = current_user.account.bell.notifications.where(:id => id, :user => current_user)
80
- noti.update(:status => :read)
81
- self
80
+ def persist(announcement, attributes)
81
+ attributes = attributes.to_h.symbolize_keys
82
+ Announcement.transaction do
83
+ # Serialize recipient replacement with other edits and dismissals of recipients.
84
+ announcement.lock! if announcement.persisted?
85
+ announcement.assign_attributes(editable_attributes(attributes))
86
+ assign_audience(announcement, attributes)
87
+ announcement.save!
88
+ # Add both kinds before removing either, including user-to-role replacements.
89
+ add_recipients(announcement.user_recipients, :user_id, announcement.user_ids)
90
+ add_recipients(announcement.role_recipients, :role_id, announcement.role_ids)
91
+ announcement.user_recipients.where.not(user_id: announcement.user_ids).each(&:destroy!)
92
+ announcement.role_recipients.where.not(role_id: announcement.role_ids).each(&:destroy!)
93
+ announcement.clear_audience_selection
94
+ end
95
+ response(announcement)
96
+ rescue ActiveRecord::RecordInvalid => exception
97
+ if exception.record != announcement
98
+ announcement.errors.add(:base, exception.record.errors.full_messages.to_sentence)
99
+ end
100
+ error(announcement.errors.full_messages.to_sentence)
101
+ response(announcement)
102
+ end
103
+
104
+ def assign_audience(announcement, attributes)
105
+ [:user_ids, :role_ids].each do |key|
106
+ next unless attributes.key?(key)
107
+
108
+ announcement.public_send("#{key}=", Array(attributes[key]).reject(&:blank?).map(&:to_s).uniq)
109
+ end
110
+
111
+ has_recipients = announcement.user_ids.any? || announcement.role_ids.any?
112
+ if attributes[:audience].to_s == "account"
113
+ announcement.user_ids = []
114
+ announcement.role_ids = []
115
+ elsif has_recipients && !attributes.key?(:audience)
116
+ announcement.audience = :specific
117
+ elsif announcement.audience_specific? && !has_recipients && !attributes.key?(:audience)
118
+ # An API caller can explicitly empty the audience, but never publish it to everyone.
119
+ announcement.active = false
120
+ announcement.allow_empty_audience = true
121
+ end
122
+ end
123
+
124
+ def add_recipients(association, foreign_key, ids)
125
+ existing_ids = association.pluck(foreign_key).map(&:to_s)
126
+ (ids.map(&:to_s) - existing_ids).each do |id|
127
+ association.create!(foreign_key => id)
128
+ end
82
129
  end
83
130
  end
84
131
  end
@@ -78,5 +78,13 @@ module LesliBell
78
78
  noti.update(:status => :read)
79
79
  self
80
80
  end
81
+
82
+ def read_all
83
+ current_user.account.bell.notifications
84
+ .where(user: current_user, status: ["created", "sent", nil])
85
+ .update_all(status: "read", updated_at: Time.current)
86
+
87
+ self
88
+ end
81
89
  end
82
90
  end
@@ -0,0 +1,34 @@
1
+ <div id="announcement-form">
2
+ <%= form_with model: @announcement, scope: :announcement, builder: LesliView::Forms::Builder,
3
+ url: @announcement.persisted? ? announcement_path(@announcement) : announcements_path,
4
+ data: { turbo_frame: "_top" } do |form| %>
5
+ <%= form.fieldset do %>
6
+ <% if @announcement.errors.any? %>
7
+ <div role="alert"><%= form.field_control_builder(message_text: @announcement.errors.full_messages.to_sentence, category: :danger) %></div>
8
+ <% end %>
9
+ <%= form.field_control(:name, label: t("lesli_bell.announcements.name"), required: true) %>
10
+ <%= form.field_control_textarea(:message, label: t("lesli_bell.announcements.message"), required: true, rows: 4) %>
11
+ <%= form.field_control_select(:category, announcement_categories, label: t("lesli_bell.announcements.category"), humanize: false) %>
12
+ <%= form.field_control_select(:audience, announcement_audiences,
13
+ label: t("lesli_bell.announcements.audience"), humanize: false,
14
+ message: t("lesli_bell.announcements.audience_hint")) %>
15
+ <%= form.field_control_select(:user_ids, @audience_users,
16
+ label: t("lesli_bell.announcements.recipient_users"), humanize: false,
17
+ html_options: { multiple: true, size: 5 }) %>
18
+ <% if @audience_roles %>
19
+ <%= form.field_control_select(:role_ids, @audience_roles,
20
+ label: t("lesli_bell.announcements.recipient_roles"), humanize: false,
21
+ html_options: { multiple: true, size: 5 }) %>
22
+ <% end %>
23
+ <%= form.field_control_checkbox(:active, label: t("lesli_bell.announcements.active")) %>
24
+ <% [:start_at, :end_at].each do |field| %>
25
+ <%= form.field_control(field, label: t("lesli_bell.announcements.#{field}"), type: "datetime-local",
26
+ value: @announcement.public_send(field)&.strftime("%Y-%m-%dT%H:%M:%S"), step: 1) %>
27
+ <% end %>
28
+ <%= form.field_control(:path, label: t("lesli_bell.announcements.path"), message: t("lesli_bell.announcements.path_hint")) %>
29
+ <%= form.field_control(:url, label: t("lesli_bell.announcements.url"), message: t("lesli_bell.announcements.url_hint")) %>
30
+ <%= form.field_control_checkbox(:can_be_closed, label: t("lesli_bell.announcements.can_be_closed")) %>
31
+ <%= form.field_control_submit(t("lesli_bell.announcements.save")) %>
32
+ <% end %>
33
+ <% end %>
34
+ </div>
@@ -1,10 +1,6 @@
1
- <h1>Editing announcement</h1>
2
-
3
- <%= render "form", announcement: @announcement %>
4
-
5
- <br>
6
-
7
- <div>
8
- <%= link_to "Show this announcement", @announcement %> |
9
- <%= link_to "Back to announcements", announcements_path %>
10
- </div>
1
+ <%= render LesliView::Layout::Container.new("announcements-edit") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_bell.announcements.edit")) do %>
3
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
4
+ <% end %>
5
+ <%= render "form" %>
6
+ <% end %>
@@ -1,33 +1,25 @@
1
- <%#
2
-
3
- Lesli
4
-
5
- Copyright (c) 2023, Lesli Technologies, S. A.
6
-
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see http://www.gnu.org/licenses/.
19
-
20
- Lesli · Ruby on Rails SaaS Development Framework.
21
-
22
- Made with ♥ by LesliTech
23
- Building a better future, one line of code at a time.
24
-
25
- @contact hello@lesli.tech
26
- @website https://www.lesli.tech
27
- @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
-
29
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
- %>
32
-
33
- <router-view></router-view>
1
+ <%= render LesliView::Layout::Container.new("announcements-index") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_bell.announcements.title")) do %>
3
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.new"), url: new_announcement_path, icon: "add") %>
4
+ <% end %>
5
+ <%= render LesliView::Elements::Table.new(
6
+ columns: %w[name category publication start_at end_at].map { |field| { field: field, label: t("lesli_bell.announcements.#{field}") } },
7
+ records: @announcements.map { |announcement| {
8
+ id: announcement.id, name: announcement.name,
9
+ category: t("lesli_bell.announcements.categories.#{announcement.category}"),
10
+ publication: t("lesli_bell.announcements.#{announcement.active? ? 'active' : 'inactive'}"),
11
+ start_at: announcement_datetime(announcement.start_at),
12
+ end_at: announcement_datetime(announcement.end_at)
13
+ } },
14
+ link: ->(announcement) { announcement_path(announcement.fetch(:id)) },
15
+ empty: t("lesli_bell.announcements.empty")
16
+ ) %>
17
+ <nav class="mt-6 flex gap-3" aria-label="<%= t('lesli_bell.announcements.pagination') %>">
18
+ <% if @announcements.prev_page %>
19
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.previous"), url: announcements_path(page: @announcements.prev_page, perPage: @announcements.limit_value), solid: false) %>
20
+ <% end %>
21
+ <% if @announcements.next_page %>
22
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.next"), url: announcements_path(page: @announcements.next_page, perPage: @announcements.limit_value), solid: false) %>
23
+ <% end %>
24
+ </nav>
25
+ <% end %>
@@ -1,9 +1,6 @@
1
- <h1>New announcement</h1>
2
-
3
- <%= render "form", announcement: @announcement %>
4
-
5
- <br>
6
-
7
- <div>
8
- <%= link_to "Back to announcements", announcements_path %>
9
- </div>
1
+ <%= render LesliView::Layout::Container.new("announcements-new") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_bell.announcements.new")) do %>
3
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
4
+ <% end %>
5
+ <%= render "form" %>
6
+ <% end %>
@@ -1,10 +1,27 @@
1
- <p style="color: green"><%= notice %></p>
2
-
3
- <%= render @announcement %>
4
-
5
- <div>
6
- <%= link_to "Edit this announcement", edit_announcement_path(@announcement) %> |
7
- <%= link_to "Back to announcements", announcements_path %>
8
-
9
- <%= button_to "Destroy this announcement", @announcement, method: :delete %>
10
- </div>
1
+ <%= render LesliView::Layout::Container.new("announcements-show") do %>
2
+ <%= render LesliView::Components::Header.new(@announcement.name) do %>
3
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
4
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.edit"), url: edit_announcement_path(@announcement), icon: "edit") %>
5
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.delete"), url: announcement_path(@announcement), method: :delete,
6
+ data: { turbo_confirm: t("lesli_bell.announcements.confirm_delete") }, icon: "delete", danger: true, solid: false) %>
7
+ <% end %>
8
+ <% if @announcement.errors.any? %>
9
+ <p role="alert"><%= @announcement.errors.full_messages.to_sentence %></p>
10
+ <% end %>
11
+ <p class="mb-6 whitespace-pre-wrap break-words"><%= @announcement.message %></p>
12
+ <dl class="grid gap-4 sm:grid-cols-2">
13
+ <% {
14
+ audience: announcement_audience_summary(@announcement),
15
+ category: t("lesli_bell.announcements.categories.#{@announcement.category}"),
16
+ publication: t("lesli_bell.announcements.#{@announcement.active? ? 'active' : 'inactive'}"),
17
+ start_at: announcement_datetime(@announcement.start_at), end_at: announcement_datetime(@announcement.end_at),
18
+ path: @announcement.path || t("lesli_bell.announcements.all_pages"),
19
+ can_be_closed: t("lesli_bell.announcements.#{@announcement.can_be_closed? ? 'yes' : 'no'}")
20
+ }.each do |field, value| %>
21
+ <div><dt class="font-medium"><%= t("lesli_bell.announcements.#{field}") %></dt><dd><%= value %></dd></div>
22
+ <% end %>
23
+ </dl>
24
+ <% if @announcement.url.present? %>
25
+ <%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.open_link"), url: @announcement.url, solid: false) %>
26
+ <% end %>
27
+ <% end %>
@@ -30,4 +30,4 @@ Building a better future, one line of code at a time.
30
30
  // ·
31
31
  %>
32
32
 
33
- <%= render("/lesli/shared/dashboards/show") %>
33
+ <%= render(template:"lesli/shared/dashboards/show") %>