Add 'type_of' to DisplayAds (#18716)

* Add 'type_of' to DisplayAds

* Try compressing public & approved columns
This commit is contained in:
Joshua Wehner 2022-11-17 10:18:55 +01:00 committed by GitHub
parent 86d64e878e
commit a83a4f4f17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 6 deletions

View file

@ -59,7 +59,7 @@ module Admin
def display_ad_params
params.permit(:organization_id, :body_markdown, :placement_area, :published, :approved, :name, :display_to,
:tag_list)
:tag_list, :type_of)
end
def authorize_admin

View file

@ -14,6 +14,7 @@ class DisplayAd < ApplicationRecord
SIDEBAR_WIDTH = 350
enum display_to: { all: 0, logged_in: 1, logged_out: 2 }, _prefix: true
enum type_of: { in_house: 0, community: 1, external: 2 }
belongs_to :organization, optional: true
has_many :display_ad_events, dependent: :destroy

View file

@ -54,6 +54,28 @@
</fieldset>
</div>
<div class="crayons-field">
<fieldset aria-describedby="section-description" aria-describedby="type-of-description">
<legend class="crayons-field crayons-field__label pl-0">Type</legend>
<p id="display-to-description" class="crayons-field__description mb-2">For internal use</p>
<label class="crayons-field crayons-field--radio mb-2">
<%= radio_button_tag :type_of, "in_house", @display_ad.in_house?, class: "crayons-radio" %>
<div class="crayons-field__label">In-House Ad</div>
</label>
<label class="crayons-field crayons-field--radio mb-2">
<%= radio_button_tag :type_of, "community", @display_ad.community?, class: "crayons-radio" %>
<div class="crayons-field__label">Community</div>
</label>
<label class="crayons-field crayons-field--radio mb-2">
<%= radio_button_tag :type_of, "external", @display_ad.external?, class: "crayons-radio" %>
<div class="crayons-field__label">External advertiser</div>
</label>
</fieldset>
</div>
<div class="crayons-field">
<%= label_tag :published, "Published:", class: "crayons-field__label" %>
<%= select_tag :published, options_for_select([false, true], selected: @display_ad.published), class: "crayons-select" %>

View file

@ -23,8 +23,8 @@
<th scope="col">Name</th>
<th scope="col">Placement Area</th>
<th scope="col">Display to User Group</th>
<th scope="col">Published</th>
<th scope="col">Approved</th>
<th scope="col">Type</th>
<th scope="col">Public?</th>
<th scope="col">Success Rate</th>
</tr>
</thead>
@ -34,8 +34,12 @@
<td><%= link_to display_ad.name, edit_admin_display_ad_path(display_ad) %></td>
<td><%= display_ad.human_readable_placement_area %></td>
<td><%= display_ad.display_to %></td>
<td><%= display_ad.published %></td>
<td><%= display_ad.approved %></td>
<td><%= display_ad.type_of.titleize %></td>
<% if display_ad.published? && display_ad.approved? %>
<td><span class="crayons-icon" role="img" aria-label="Ad is published and approved">✅</span></td>
<% else %>
<td><span class="crayons-icon" role="img" aria-label="Ad is not published or approved">❌</span></td>
<% end %>
<td><%= display_ad.success_rate %></td>
<td><%= link_to "Edit", edit_admin_display_ad_path(display_ad), class: "crayons-btn" %></td>
<td>

View file

@ -0,0 +1,5 @@
class AddTypeToDisplayAds < ActiveRecord::Migration[7.0]
def change
add_column :display_ads, :type_of, :integer, default: 0, null: false
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_10_31_133328) do
ActiveRecord::Schema[7.0].define(version: 2022_11_10_130111) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_stat_statements"
@ -467,6 +467,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_31_133328) do
t.text "processed_html"
t.boolean "published", default: false
t.float "success_rate", default: 0.0
t.integer "type_of", default: 0, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["cached_tag_list"], name: "index_display_ads_on_cached_tag_list", opclass: :gin_trgm_ops, using: :gin
end