Skip to content

Commit 7866c74

Browse files
Merge pull request #2294 from NCCE/2956-move-primary-computing-glossary-to-strapi
Move primary computing glossary page to Strapi
2 parents 2134dd3 + 94db3f8 commit 7866c74

File tree

17 files changed

+320
-14
lines changed

17 files changed

+320
-14
lines changed

.env.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ STRAPI_GRAPHQL_URL="http://strapi.teachcomputing.rpfdev.com/graphql"
8080
STRAPI_CONNECTION_TYPE="graphql"
8181
STRAPI_TEST_SCHEMA_PATH="spec/support/cms/providers/strapi/schema.json"
8282

83-
NODE_OPTIONS=--openssl-legacy-provider
83+
NODE_OPTIONS=--openssl-legacy-provider
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class Cms::PrimaryGlossaryTableComponent < ViewComponent::Base
4+
def initialize(title:)
5+
@title = title
6+
@records = begin
7+
Cms::Collections::PrimaryGlossaryTableItems.all_records
8+
rescue ActiveRecord::RecordNotFound
9+
[]
10+
end
11+
end
12+
13+
def render?
14+
@records.any?
15+
end
16+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%= render GovGridRowComponent.new(additional_classes: "primary-glossary-table", padding: {top: 0, bottom: 0}) do |row| %>
2+
<%= row.with_column("full") do %>
3+
<% if @title %>
4+
<h2 class="govuk-heading-m" id="glossary"><%= @title %></h2>
5+
<% end %>
6+
<table class="govuk-table govuk-!-margin-bottom-0">
7+
<thead class="govuk-table__head">
8+
<tr>
9+
<th class="govuk-table__header">Term</th>
10+
<th class="govuk-table__header">Key Stage</th>
11+
<th class="govuk-table__header">Definition</th>
12+
</tr>
13+
</thead>
14+
<tbody class="govuk-table__body">
15+
<% @records.each do |record| %>
16+
<tr class="govuk-table__row">
17+
<td class="govuk-table__cell"><%= record.term.value %></td>
18+
<td class="govuk-table__cell"><%= record.key_stage.value %></td>
19+
<td class="govuk-table__cell"><%= render Cms::RichTextBlockComponent.new(blocks: record.definition.blocks) %></td>
20+
</tr>
21+
<% end %>
22+
</tbody>
23+
</table>
24+
<% end %>
25+
<% end %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.primary-glossary-table {
2+
.govuk-table {
3+
border-collapse: collapse;
4+
5+
th, td {
6+
border: 1px solid black;
7+
padding: 10px;
8+
}
9+
10+
.govuk-table__header {
11+
color: $white;
12+
background-color: $purple;
13+
text-wrap: nowrap;
14+
text-align: center;
15+
}
16+
17+
.govuk-table__cell {
18+
padding-right: 10px;
19+
}
20+
}
21+
}

app/jobs/searchable_page_indexing_job.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@ class SearchablePageIndexingJob < ApplicationJob
55
def perform
66
now = DateTime.now
77
SearchablePages::CmsBlog.delete_all
8-
page = 1
9-
per_page = 100
10-
loop do
11-
blog_search_records = Cms::Collections::Blog.all(page, per_page) # Strapi Graphql has a max limit of 100
12-
if blog_search_records.resources.any?
13-
SearchablePages::CmsBlog.insert_all(blog_search_records.resources.map { |blog| blog.to_search_record(now) })
14-
end
15-
break if (page * per_page) > blog_search_records.total_records
16-
page += 1
8+
9+
all_blogs = Cms::Collections::Blog.all_records
10+
11+
if all_blogs.any?
12+
SearchablePages::CmsBlog.insert_all(all_blogs.map { |blog| blog.to_search_record(now) })
1713
end
1814

1915
SearchablePages::CmsWebPage.delete_all
20-
page_search_records = Cms::Collections::WebPage.all(1, 100)
21-
if page_search_records.resources.any?
22-
SearchablePages::CmsWebPage.insert_all(page_search_records.resources.map { |page| page.to_search_record(now) })
16+
page_search_records = Cms::Collections::WebPage.all_records
17+
if page_search_records.any?
18+
SearchablePages::CmsWebPage.insert_all(page_search_records.map { |page| page.to_search_record(now) })
2319
end
2420
enrichment_pages = Cms::Collections::EnrichmentPage.all(1, 10)
2521
if enrichment_pages.resources.any?
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Cms
2+
module Collections
3+
class PrimaryGlossaryTableItems < Resource
4+
def self.is_collection = true
5+
6+
def self.resource_key
7+
"primary-computing-glossary-table"
8+
end
9+
10+
def self.graphql_key
11+
"primaryComputingGlossaryTables"
12+
end
13+
14+
def self.collection_attribute_mappings
15+
[
16+
{model: Cms::Models::TextField, key: :term},
17+
{model: Cms::Models::TextField, key: :keyStage},
18+
{model: Cms::Models::TextBlock, key: :definition}
19+
]
20+
end
21+
22+
def self.resource_attribute_mappings
23+
[
24+
{model: Cms::Models::TextField, key: :term},
25+
{model: Cms::Models::TextField, key: :keyStage},
26+
{model: Cms::Models::TextBlock, key: :definition}
27+
]
28+
end
29+
end
30+
end
31+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Cms
2+
module DynamicComponents
3+
class PrimaryGlossaryTable
4+
attr_accessor :title
5+
6+
def initialize(title:)
7+
@title = title
8+
end
9+
10+
def render
11+
PrimaryGlossaryTableComponent.new(title:)
12+
end
13+
end
14+
end
15+
end

app/services/cms/providers/strapi/factories/blocks_factory.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def self.generate_component(component_name, strapi_data)
4343
to_icon_row(strapi_data)
4444
when "two-column-video-section"
4545
to_two_column_video_section(strapi_data)
46+
when "primary-glossary-table"
47+
DynamicComponents::PrimaryGlossaryTable.new(title: strapi_data[:title])
4648
end
4749
end
4850

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
module DynamicComponents
6+
class PrimaryGlossaryTable < StrapiMock
7+
strapi_component "blocks.primary-glossary-table"
8+
9+
attribute(:title) { Faker::Lorem.sentence }
10+
end
11+
end
12+
end
13+
end
14+
end
15+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Cms
2+
module Providers
3+
module Strapi
4+
module Mocks
5+
class PrimaryGlossaryTableItems < StrapiMock
6+
attribute(:term) { Faker::Lorem.word }
7+
attribute(:keyStage) { Faker::Lorem.word }
8+
attribute(:definition) { RichBlocks.generate_data }
9+
end
10+
end
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)