Skip to content

Commit 085cb90

Browse files
standard-editions/ID/featurings
1 parent 075c0f1 commit 085cb90

9 files changed

Lines changed: 64 additions & 6 deletions

File tree

app/controllers/admin/topical_event_featurings_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def index
1717

1818
@topical_event_featurings = @topical_event.topical_event_featurings
1919
@featurable_offsite_links = @topical_event.offsite_links
20+
@featurable_editions = if @topical_event.is_a?(StandardEdition)
21+
@topical_event.topical_event_documents
22+
.page(params[:page])
23+
.per(Admin::EditionFilter::GOVUK_DESIGN_SYSTEM_PER_PAGE)
24+
else
25+
@topical_event.featurable_editions(@tagged_editions)
26+
end
2027
end
2128

2229
def new
@@ -89,6 +96,8 @@ def editions_to_show
8996
else
9097
editions = if @topical_event.respond_to?(:topical_event_documents)
9198
@topical_event.topical_event_documents
99+
.page(params[:page])
100+
.per(Admin::EditionFilter::GOVUK_DESIGN_SYSTEM_PER_PAGE)
92101
else
93102
@topical_event.editions.published
94103
.with_translations
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Edition::OffsiteLinks
2+
extend ActiveSupport::Concern
3+
4+
class Trait < Edition::Traits::Trait
5+
def process_associations_before_save(edition)
6+
@edition.edition_offsite_links.each do |association|
7+
edition.edition_offsite_links.build(association.attributes.except("id"))
8+
end
9+
end
10+
end
11+
12+
included do
13+
has_many :edition_offsite_links, foreign_key: :edition_id, dependent: :destroy
14+
has_many :offsite_links, through: :edition_offsite_links, validate: false
15+
16+
add_trait Trait
17+
end
18+
end

app/models/configurable_document_types/topical_event.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"associations": [
5555
{
5656
"key": "organisations",
57-
"key": "offsite_links",
57+
"key": "offsite_links"
5858
}
5959
],
6060
"settings": {

app/models/edition_offsite_link.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class EditionOffsiteLink < ApplicationRecord
2+
belongs_to :edition
3+
belongs_to :offsite_link, inverse_of: :edition_offsite_links
4+
end

app/models/standard_edition.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ class StandardEdition < Edition
88
include Edition::WorldLocations
99
include Edition::Organisations
1010
include Edition::WorldwideOrganisations
11+
include Edition::OffsiteLinks
1112
include HasBlockContent
1213
include StandardEdition::DefaultLeadImage
1314

1415
validates :configurable_document_type, presence: true, inclusion: { in: -> { ConfigurableDocumentType.all_keys } }
15-
1616
scope :with_news_article_document_type, -> { where(configurable_document_type: ConfigurableDocumentType.where_group("news_article").map(&:key)) }
1717

18+
def name
19+
title
20+
end
21+
1822
def format_name
1923
type_instance.label.downcase
2024
end

app/views/admin/topical_event_featurings/index.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
content: render("admin/shared/featurable_editions",
4343
filter: @filter,
4444
paginator: @tagged_editions,
45-
featurable_editions: @topical_event.featurable_editions(@tagged_editions),
45+
featurable_editions: @featurable_editions,
4646
filter_by: [:title, :type, :author, :organisation],
4747
anchor: "#documents_tab",
4848
filter_action: admin_topical_event_topical_event_featurings_url(@topical_event),
@@ -54,7 +54,7 @@
5454
label: "Non-GOV.UK government links",
5555
content: render("admin/feature_lists/featureable_offsite_links",
5656
model: @topical_event,
57-
featurable_offsite_links: @topical_event.featurable_offsite_links,
57+
featurable_offsite_links: @featurable_offsite_links,
5858
featuring_path: [:new, :admin, @topical_event, :topical_event_featuring],
5959
),
6060
},

config/routes.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })
315315
get :reorder, on: :collection
316316
put :order, on: :collection
317317
get :confirm_destroy, on: :member
318-
end
318+
end
319+
320+
resources :offsite_links do
321+
get :confirm_destroy, on: :member
322+
end
319323

320324
resources :translations, controller: "standard_edition_translations", except: %i[index show create] do
321325
get :confirm_destroy, on: :member
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateEditionOffsiteLinks < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :edition_offsite_links do |t|
4+
t.timestamps
5+
end
6+
7+
add_reference :edition_offsite_links, :edition
8+
add_reference :edition_offsite_links, :offsite_link
9+
end
10+
end

db/schema.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2026_01_07_195134) do
13+
ActiveRecord::Schema[8.0].define(version: 2026_01_09_164506) do
1414
create_table "assets", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
1515
t.string "asset_manager_id", null: false
1616
t.string "variant", null: false
@@ -275,6 +275,15 @@
275275
t.index ["edition_id"], name: "index_edition_links_on_edition_id"
276276
end
277277

278+
create_table "edition_offsite_links", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
279+
t.datetime "created_at", null: false
280+
t.datetime "updated_at", null: false
281+
t.bigint "edition_id"
282+
t.bigint "offsite_link_id"
283+
t.index ["edition_id"], name: "index_edition_offsite_links_on_edition_id"
284+
t.index ["offsite_link_id"], name: "index_edition_offsite_links_on_offsite_link_id"
285+
end
286+
278287
create_table "edition_organisations", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
279288
t.integer "edition_id"
280289
t.integer "organisation_id"

0 commit comments

Comments
 (0)