Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions app/controllers/announcements/blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def create
return render json: { errors: block.errors.map(&:full_message) }, status: :bad_request
end

render json: { id: block.id, html: block.rendered_html }
render json: { id: block.id, html: block.render }
end

def show
authorize @block, policy_class: Announcement::BlockPolicy

render json: { id: @block.id, html: @block.rendered_html }
render json: { id: @block.id, html: @block.render }
end

def edit
Expand All @@ -38,14 +38,6 @@ def update
render turbo_stream: turbo_stream.replace("block_#{@block.id}", partial: @block.partial, locals: @block.locals)
end

def refresh
authorize @block, policy_class: Announcement::BlockPolicy

@block.refresh!

render html: @block.render
end

private

def set_block
Expand Down
24 changes: 8 additions & 16 deletions app/models/announcement/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand All @@ -23,18 +21,12 @@
#
class Announcement
class Block < ApplicationRecord
self.ignored_columns += ["rendered_html", "rendered_email_html"]

belongs_to :announcement
has_one :event, through: :announcement

before_save { self.parameters ||= {} }
after_create :refresh!

def refresh!
self.rendered_html = render
self.rendered_email_html = render(is_email: true)

save!
end

def render(event: nil, is_email: false)
if event.present? && event != announcement.event
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/donation_goal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/donation_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/hcb_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/top_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/top_merchants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/top_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
14 changes: 6 additions & 8 deletions app/models/announcement/block/top_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Table name: announcement_blocks
#
# id :bigint not null, primary key
# parameters :jsonb
# rendered_email_html :text
# rendered_html :text
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
# id :bigint not null, primary key
# parameters :jsonb
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# announcement_id :bigint not null
#
# Indexes
#
Expand Down
2 changes: 0 additions & 2 deletions app/views/announcements/blocks/_block_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<% unless is_email %>
<div class="block-actions flex gap-2">
<%= pop_icon_to "history", refresh_announcements_block_path(block), data: { turbo_method: :post }, class: "tooltipped", "aria-label": "Refresh this block with the latest data" %>

<% if block.editable? %>
<%= pop_icon_to "edit", edit_announcements_block_path(block), class: "tooltipped", "aria-label": "Edit this block", rel: "modal:open" %>
<% end %>
Expand Down
14 changes: 13 additions & 1 deletion app/views/announcements/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<% page_md %>
<%= render "events/nav", selected: :announcements %>

<% show_blocks_callout = !@announcement.published? && @announcement.blocks.any? %>

<h1 class="heading">
<span class="flex flex-grow items-center"><%= heading %></span>
</h1>
Expand All @@ -20,7 +22,7 @@
<% end %>
<% end %>

<div class="flex justify-between items-center pb-4">
<div class="flex justify-between items-center <%= "pb-4" unless show_blocks_callout %>">
<p class="italic my-0">
<%= @announcement.published? ? "Published" : "Drafted" %> by <%= user_mention @announcement.author %> on <%= (@announcement.draft? ? @announcement.created_at : @announcement.published_at.presence || @announcement.created_at).strftime("%B %e, %Y") %>
</p>
Expand Down Expand Up @@ -51,6 +53,16 @@
</div>
</div>

<% if show_blocks_callout %>
<%= render "callout", type: "info", title: "This announcement contains blocks", footer: :questions do %>
<ul>
<li>Blocks are sections of your announcement that automatically update with the latest data from HCB.</li>
<li>You can change block options by editing the announcement and clicking the blue edit icon in the top-right corner of any block.
<li>Add new blocks by selecting a block from the HCB dropdown menu when editing an announcement.</li>
</ul>
<% end %>
<% end %>

<%= turbo_frame_tag :post_editor do %>
<% if editing %>
<%= render partial: "announcement_form", locals: { announcement: @announcement } %>
Expand Down
6 changes: 1 addition & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,7 @@
end

namespace "announcements" do
resources :blocks, only: [:create, :edit, :update, :show] do
member do
post "refresh"
end
end
resources :blocks, only: [:create, :edit, :update, :show]
end

scope module: "organizer_position_invite" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DropRenderedHtmlFromAnnouncementBlocks < ActiveRecord::Migration[8.0]
def change
safety_assured {
remove_column :announcement_blocks, :rendered_html, :text
remove_column :announcement_blocks, :rendered_email_html, :text
}
end
end
2 changes: 0 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
t.bigint "announcement_id", null: false
t.datetime "created_at", null: false
t.jsonb "parameters"
t.text "rendered_email_html"
t.text "rendered_html"
t.string "type", null: false
t.datetime "updated_at", null: false
t.index ["announcement_id"], name: "index_announcement_blocks_on_announcement_id"
Expand Down