-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1032 from alphagov/add-content-item-links-rules-s…
…ubgroups Add content item links rules subgroups
- Loading branch information
Showing
26 changed files
with
728 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
module ContentItem | ||
module LinksOut | ||
def links_out_supergroups | ||
@links_out_supergroups ||= fetch_links_out_supergroups | ||
end | ||
|
||
def links_out_subgroups | ||
@links_out_subgroups ||= fetch_links_out_subgroups | ||
end | ||
|
||
private | ||
|
||
def fetch_links_out_supergroups | ||
links_out.map { |link| link["supergroup"] }.uniq | ||
end | ||
|
||
def fetch_links_out_subgroups | ||
subgroups = [] | ||
links_out.each do |link| | ||
if link["type"] == "content_purpose_subgroup" | ||
subgroups << link["title"] | ||
end | ||
end | ||
subgroups.uniq | ||
end | ||
|
||
def links_out | ||
@links_out ||= fetch_links_out | ||
end | ||
|
||
def fetch_links_out | ||
document_type_link_rule = DocumentTypeLinkRule.new(content_item) | ||
return document_type_link_rule.links if document_type_link_rule.any? | ||
subgroup_link_rule = SubgroupLinkRule.new(content_item) | ||
return subgroup_link_rule.links if subgroup_link_rule.any? | ||
SupergroupLinkRule.new(content_item).links | ||
end | ||
|
||
class LinkRule | ||
def initialize(content_item) | ||
@content_item = content_item | ||
@rules = load_rules | ||
@links = fetch_links | ||
end | ||
|
||
def any? | ||
!@links.nil? | ||
end | ||
|
||
def links | ||
@links || [] | ||
end | ||
|
||
private | ||
|
||
def fetch_links | ||
if @content_item.dig(rule_level) && | ||
@rules[rule_level] && | ||
@rules[rule_level].dig(@content_item[rule_level]) | ||
@rules[rule_level][@content_item[rule_level]] | ||
end | ||
end | ||
|
||
def load_rules | ||
Rails.configuration.taxonomy_navigation_links_out | ||
end | ||
|
||
def rule_level | ||
NotImplementedError | ||
end | ||
end | ||
|
||
class DocumentTypeLinkRule < LinkRule | ||
def initialize(content_item) | ||
super | ||
end | ||
|
||
private | ||
|
||
def rule_level | ||
'document_type' | ||
end | ||
end | ||
|
||
class SubgroupLinkRule < LinkRule | ||
def initialize(content_item) | ||
super | ||
end | ||
|
||
private | ||
|
||
def rule_level | ||
'content_purpose_subgroup' | ||
end | ||
end | ||
|
||
class SupergroupLinkRule < LinkRule | ||
def initialize(content_item) | ||
super | ||
end | ||
|
||
private | ||
|
||
def rule_level | ||
'content_purpose_supergroup' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
module Supergroups | ||
class GuidanceAndRegulation < Supergroup | ||
def initialize(current_path, taxon_ids) | ||
@current_path = current_path | ||
@taxon_ids = taxon_ids | ||
@content = fetch_content | ||
def initialize(current_path, taxon_ids, filters) | ||
super(current_path, taxon_ids, filters, MostPopularContent) | ||
end | ||
|
||
def tagged_content | ||
format_document_data(@content, include_timestamp: false) | ||
end | ||
|
||
private | ||
|
||
def fetch_content | ||
return [] unless @taxon_ids.any? | ||
MostPopularContent.fetch(content_ids: @taxon_ids, current_path: @current_path, filter_content_purpose_supergroup: "guidance_and_regulation") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,7 @@ | ||
module Supergroups | ||
class PolicyAndEngagement < Supergroup | ||
def initialize(current_path, taxon_ids) | ||
@current_path = current_path | ||
@taxon_ids = taxon_ids | ||
@content = fetch_content | ||
end | ||
|
||
def tagged_content | ||
format_document_data(@content) | ||
end | ||
|
||
private | ||
|
||
def fetch_content | ||
return [] unless @taxon_ids.any? | ||
MostRecentContent.fetch(content_ids: @taxon_ids, current_path: @current_path, filter_content_purpose_supergroup: "policy_and_engagement") | ||
def initialize(current_path, taxon_ids, filters) | ||
super(current_path, taxon_ids, filters, MostRecentContent) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,7 @@ | ||
module Supergroups | ||
class Transparency < Supergroup | ||
def initialize(current_path, taxon_ids) | ||
@current_path = current_path | ||
@taxon_ids = taxon_ids | ||
@content = fetch_content | ||
end | ||
|
||
def tagged_content | ||
format_document_data(@content) | ||
end | ||
|
||
private | ||
|
||
def fetch_content | ||
return [] unless @taxon_ids.any? | ||
MostRecentContent.fetch(content_ids: @taxon_ids, current_path: @current_path, filter_content_purpose_supergroup: "transparency") | ||
def initialize(current_path, taxon_ids, filters) | ||
super(current_path, taxon_ids, filters, MostRecentContent) | ||
end | ||
end | ||
end |
Oops, something went wrong.