From 307f872baa1096348158d5bc6f4c94dd975a19d0 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 29 Jul 2020 15:31:43 +0100 Subject: [PATCH 01/14] Initial draft on adding custom categories to pages --- app/models/comfy/cms/page_category.rb | 6 ++++++ app/models/comfy/cms/pages_category.rb | 6 ++++++ app/models/comfy/cms/searchable_page.rb | 7 +++++++ 3 files changed, 19 insertions(+) create mode 100644 app/models/comfy/cms/page_category.rb create mode 100644 app/models/comfy/cms/pages_category.rb diff --git a/app/models/comfy/cms/page_category.rb b/app/models/comfy/cms/page_category.rb new file mode 100644 index 000000000..4de35c788 --- /dev/null +++ b/app/models/comfy/cms/page_category.rb @@ -0,0 +1,6 @@ +class Comfy::Cms::PageCategory < ApplicationRecord + self.table_name = 'comfy_cms_page_categories' + + has_many :pages_categories + has_many :pages, through: :pages_categories +end \ No newline at end of file diff --git a/app/models/comfy/cms/pages_category.rb b/app/models/comfy/cms/pages_category.rb new file mode 100644 index 000000000..310446755 --- /dev/null +++ b/app/models/comfy/cms/pages_category.rb @@ -0,0 +1,6 @@ +class Comfy::Cms::PagesCategory < ApplicationRecord + self.table_name = 'comfy_cms_pages_categories' + + belongs_to :page + belongs_to :page_category +end \ No newline at end of file diff --git a/app/models/comfy/cms/searchable_page.rb b/app/models/comfy/cms/searchable_page.rb index 23a8efa09..10f39ce3d 100644 --- a/app/models/comfy/cms/searchable_page.rb +++ b/app/models/comfy/cms/searchable_page.rb @@ -5,6 +5,12 @@ class Comfy::Cms::SearchablePage < Comfy::Cms::Page has_many :translations_for_index, -> { select(:id, :page_id).includes(:fragments_for_index) }, class_name: 'Comfy::Cms::SearchableTranslation', foreign_key: 'page_id' + has_many :pages_categories, foreign_key: 'page_id' + has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' + + has_many :topics, -> { where(group_name: 'topic') }, through: :pages_categories, + class_name: 'Comfy::Cms::PageCategory', source: :page_category + def as_indexed_json self.as_json( only: [:id, :label], @@ -17,6 +23,7 @@ def as_indexed_json include: { fragments_for_index: { only: [:id, :content] } } }, categories: { only: [:id, :label] }, + topics: { only: [:id, :label] }, ancestors: { only: [:id, :label] } } ) From 1f2b5a5e4537c57ef6b511cb9f1d69ba06f106e9 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 29 Jul 2020 15:49:18 +0100 Subject: [PATCH 02/14] Make pages searchable by a given set of categories --- config/search.yml | 5 +++++ lib/modules/search/matcher.rb | 1 + lib/modules/search/templates/mappings.json | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/config/search.yml b/config/search.yml index 711dae922..b4f03ec1e 100644 --- a/config/search.yml +++ b/config/search.yml @@ -116,6 +116,11 @@ filters: path: 'categories' field: 'categories.id' required: true + topic: + type: 'nested' + path: 'topics' + field: 'topics.id' + required: true ancestor: type: 'nested' path: 'ancestors' diff --git a/lib/modules/search/matcher.rb b/lib/modules/search/matcher.rb index c25d07442..8d93ac56a 100644 --- a/lib/modules/search/matcher.rb +++ b/lib/modules/search/matcher.rb @@ -47,6 +47,7 @@ class Search::Matcher ) }, { type: 'nested', path: 'categories', fields: ['categories.label'] }, + { type: 'nested', path: 'topics', fields: ['topics.label'] }, { type: 'nested', path: 'ancestors', fields: ['ancestors.label'] } ] } diff --git a/lib/modules/search/templates/mappings.json b/lib/modules/search/templates/mappings.json index 582c11344..509924967 100644 --- a/lib/modules/search/templates/mappings.json +++ b/lib/modules/search/templates/mappings.json @@ -232,6 +232,17 @@ } } }, + "topics": { + "type": "nested", + "properties": { + "id": { + "type": "integer" + }, + "label": { + "type": "keyword" + } + } + }, "fragments_for_index": { "type": "nested", "properties": { From a7f1c17228c75a5850cad0ce37b9c4313d3422b0 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 29 Jul 2020 17:48:38 +0100 Subject: [PATCH 03/14] Custom categories working on pages form when added in layout --- app/models/comfy/cms/searchable_page.rb | 6 ---- .../initializers/comfortable_mexican_sofa.rb | 1 + config/initializers/comfy_cms_page.rb | 11 ++++++++ config/locales/search/en.yml | 6 +++- lib/cms_tags/categories.rb | 28 +++++++++++++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 config/initializers/comfy_cms_page.rb create mode 100644 lib/cms_tags/categories.rb diff --git a/app/models/comfy/cms/searchable_page.rb b/app/models/comfy/cms/searchable_page.rb index 10f39ce3d..9cdf68a44 100644 --- a/app/models/comfy/cms/searchable_page.rb +++ b/app/models/comfy/cms/searchable_page.rb @@ -5,12 +5,6 @@ class Comfy::Cms::SearchablePage < Comfy::Cms::Page has_many :translations_for_index, -> { select(:id, :page_id).includes(:fragments_for_index) }, class_name: 'Comfy::Cms::SearchableTranslation', foreign_key: 'page_id' - has_many :pages_categories, foreign_key: 'page_id' - has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' - - has_many :topics, -> { where(group_name: 'topic') }, through: :pages_categories, - class_name: 'Comfy::Cms::PageCategory', source: :page_category - def as_indexed_json self.as_json( only: [:id, :label], diff --git a/config/initializers/comfortable_mexican_sofa.rb b/config/initializers/comfortable_mexican_sofa.rb index e4739abeb..7c33b3bb7 100644 --- a/config/initializers/comfortable_mexican_sofa.rb +++ b/config/initializers/comfortable_mexican_sofa.rb @@ -2,6 +2,7 @@ require 'cms_tags/date_not_null' require 'cms_tags/text_custom' +require 'cms_tags/categories' # encoding: utf-8 ComfortableMexicanSofa.configure do |config| diff --git a/config/initializers/comfy_cms_page.rb b/config/initializers/comfy_cms_page.rb new file mode 100644 index 000000000..b124f94d4 --- /dev/null +++ b/config/initializers/comfy_cms_page.rb @@ -0,0 +1,11 @@ +Rails.configuration.to_prepare do + Comfy::Cms::Page.class_eval do + has_many :pages_categories, foreign_key: 'page_id' + has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' + + has_many :topics, -> { where(group_name: 'topic') }, through: :pages_categories, + class_name: 'Comfy::Cms::PageCategory', source: :page_category + + accepts_nested_attributes_for :pages_categories + end +end \ No newline at end of file diff --git a/config/locales/search/en.yml b/config/locales/search/en.yml index cf0aa9fc7..62c318a23 100644 --- a/config/locales/search/en.yml +++ b/config/locales/search/en.yml @@ -40,4 +40,8 @@ en: - all - news-and-stories - resources - - areas \ No newline at end of file + - areas + topics: + wdpa: WDPA + oecm: OECM + pame: PAME \ No newline at end of file diff --git a/lib/cms_tags/categories.rb b/lib/cms_tags/categories.rb new file mode 100644 index 000000000..b27426ec4 --- /dev/null +++ b/lib/cms_tags/categories.rb @@ -0,0 +1,28 @@ +class Categories < ComfortableMexicanSofa::Content::Tag::Fragment + def initialize(context:, params: [], source: nil) + super + @group_name = options['group_name'] + @categories = Comfy::Cms::PageCategory.where(group_name: @group_name) + end + + def form_field(object_name, view, index) + options = { id: form_field_id, class: "form-control" } + + input = view.send(:collection_check_boxes, :page, :page_category_ids, @categories, :id, :label, options) + + yield input + end + + private + + def parse_content(category) + return false if fragment.content.blank? + fragment.content.split(' ').include?(category) + end + +end + +ComfortableMexicanSofa::Content::Renderer.register_tag( + :categories, Categories +) + \ No newline at end of file From b657e6084edd36b8884b3716ccc72a084e6d91bb Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 11:37:27 +0100 Subject: [PATCH 04/14] Add ability to assign categories groups to layouts --- app/models/comfy/cms/layout_category.rb | 7 +++++ app/models/comfy/cms/layouts_category.rb | 6 ++++ app/models/comfy/cms/page_category.rb | 1 + config/initializers/comfy_cms_page.rb | 11 -------- config/initializers/comfy_patching.rb | 36 ++++++++++++++++++++++++ db | 2 +- lib/cms_tags/categories.rb | 12 ++------ 7 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 app/models/comfy/cms/layout_category.rb create mode 100644 app/models/comfy/cms/layouts_category.rb delete mode 100644 config/initializers/comfy_cms_page.rb create mode 100644 config/initializers/comfy_patching.rb diff --git a/app/models/comfy/cms/layout_category.rb b/app/models/comfy/cms/layout_category.rb new file mode 100644 index 000000000..5f8bdd2b5 --- /dev/null +++ b/app/models/comfy/cms/layout_category.rb @@ -0,0 +1,7 @@ +class Comfy::Cms::LayoutCategory < ApplicationRecord + self.table_name = 'comfy_cms_layout_categories' + + has_many :page_categories + has_many :layouts_categories + has_many :layouts, through: :layouts_categories +end \ No newline at end of file diff --git a/app/models/comfy/cms/layouts_category.rb b/app/models/comfy/cms/layouts_category.rb new file mode 100644 index 000000000..77dc7dfe1 --- /dev/null +++ b/app/models/comfy/cms/layouts_category.rb @@ -0,0 +1,6 @@ +class Comfy::Cms::LayoutsCategory < ApplicationRecord + self.table_name = 'comfy_cms_layouts_categories' + + belongs_to :layout + belongs_to :layout_category +end \ No newline at end of file diff --git a/app/models/comfy/cms/page_category.rb b/app/models/comfy/cms/page_category.rb index 4de35c788..6313f88ac 100644 --- a/app/models/comfy/cms/page_category.rb +++ b/app/models/comfy/cms/page_category.rb @@ -1,6 +1,7 @@ class Comfy::Cms::PageCategory < ApplicationRecord self.table_name = 'comfy_cms_page_categories' + belongs_to :layout_category has_many :pages_categories has_many :pages, through: :pages_categories end \ No newline at end of file diff --git a/config/initializers/comfy_cms_page.rb b/config/initializers/comfy_cms_page.rb deleted file mode 100644 index b124f94d4..000000000 --- a/config/initializers/comfy_cms_page.rb +++ /dev/null @@ -1,11 +0,0 @@ -Rails.configuration.to_prepare do - Comfy::Cms::Page.class_eval do - has_many :pages_categories, foreign_key: 'page_id' - has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' - - has_many :topics, -> { where(group_name: 'topic') }, through: :pages_categories, - class_name: 'Comfy::Cms::PageCategory', source: :page_category - - accepts_nested_attributes_for :pages_categories - end -end \ No newline at end of file diff --git a/config/initializers/comfy_patching.rb b/config/initializers/comfy_patching.rb new file mode 100644 index 000000000..da1dae086 --- /dev/null +++ b/config/initializers/comfy_patching.rb @@ -0,0 +1,36 @@ +Rails.configuration.to_prepare do + Comfy::Cms::Page.class_eval do + has_many :pages_categories, foreign_key: 'page_id' + has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' + + has_many :topics, -> { joins(:layout_category).where("comfy_cms_layout_categories.label = 'topic'") }, + through: :pages_categories, class_name: 'Comfy::Cms::PageCategory', source: :page_category + + accepts_nested_attributes_for :pages_categories + end + + Comfy::Cms::Layout.class_eval do + has_many :layouts_categories, foreign_key: 'layout_id' + has_many :layout_categories, through: :layouts_categories, foreign_key: 'layout_id' + + accepts_nested_attributes_for :layouts_categories + + after_save :assign_layout_categories + + def assign_layout_categories + _categories = self.content_tokens.select do |t| + unless t.is_a?(Hash) + false + else + t[:tag_class] == 'categories' + end + end + + _categories.each do |cat| + tag_name = cat[:tag_params].split(',').first + _layout_category = Comfy::Cms::LayoutCategory.find_by(label: tag_name) + Comfy::Cms::LayoutsCategory.find_or_create_by(layout_id: self.id, layout_category_id: _layout_category.id ) + end + end + end +end \ No newline at end of file diff --git a/db b/db index d27b2579b..4b4dc2742 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit d27b2579b2e0a399a157cf4e93c2fa230f78b3fc +Subproject commit 4b4dc2742c23a8267abc9570194d116da52a6e53 diff --git a/lib/cms_tags/categories.rb b/lib/cms_tags/categories.rb index b27426ec4..737a8a79f 100644 --- a/lib/cms_tags/categories.rb +++ b/lib/cms_tags/categories.rb @@ -1,8 +1,8 @@ class Categories < ComfortableMexicanSofa::Content::Tag::Fragment def initialize(context:, params: [], source: nil) super - @group_name = options['group_name'] - @categories = Comfy::Cms::PageCategory.where(group_name: @group_name) + @group_name = params.first + @categories = Comfy::Cms::LayoutCategory.find_by(label: @group_name).page_categories end def form_field(object_name, view, index) @@ -12,14 +12,6 @@ def form_field(object_name, view, index) yield input end - - private - - def parse_content(category) - return false if fragment.content.blank? - fragment.content.split(' ').include?(category) - end - end ComfortableMexicanSofa::Content::Renderer.register_tag( From b28aa4b349851341598a5479a81e0f9ad8d6ce22 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 14:45:06 +0100 Subject: [PATCH 05/14] Add rake task to populate custom categories --- lib/tasks/cms_categories.rake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/tasks/cms_categories.rake diff --git a/lib/tasks/cms_categories.rake b/lib/tasks/cms_categories.rake new file mode 100644 index 000000000..e48449b03 --- /dev/null +++ b/lib/tasks/cms_categories.rake @@ -0,0 +1,15 @@ +namespace :cms_categories do + desc 'Seed database tables with custom categories for the CMS' + task import: :environment do + groups = I18n.t('search')[:custom_categories] + + groups.each do |group_name, categories| + layout_category = Comfy::Cms::LayoutCategory.find_or_create_by(label: group_name.to_s) + categories_names = categories.keys + + categories_names.each do |cat_name| + Comfy::Cms::PageCategory.find_or_create_by(layout_category_id: layout_category.id, label: cat_name) + end + end + end +end \ No newline at end of file From 2493e37d23aaa87536f7cb7bd9593850e9d2c390 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 15:37:28 +0100 Subject: [PATCH 06/14] Add other category group and make sure to delete orphan categories --- app/models/comfy/cms/searchable_page.rb | 1 + config/initializers/comfy_patching.rb | 28 ++++++++++++++++++++-- config/locales/search/en.yml | 14 +++++++---- config/search.yml | 5 ++++ lib/modules/search/templates/mappings.json | 11 +++++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/models/comfy/cms/searchable_page.rb b/app/models/comfy/cms/searchable_page.rb index 9cdf68a44..6e506893d 100644 --- a/app/models/comfy/cms/searchable_page.rb +++ b/app/models/comfy/cms/searchable_page.rb @@ -18,6 +18,7 @@ def as_indexed_json }, categories: { only: [:id, :label] }, topics: { only: [:id, :label] }, + page_types: { only: [:id, :label] }, ancestors: { only: [:id, :label] } } ) diff --git a/config/initializers/comfy_patching.rb b/config/initializers/comfy_patching.rb index da1dae086..94c21f394 100644 --- a/config/initializers/comfy_patching.rb +++ b/config/initializers/comfy_patching.rb @@ -3,7 +3,10 @@ has_many :pages_categories, foreign_key: 'page_id' has_many :page_categories, through: :pages_categories, foreign_key: 'page_id' - has_many :topics, -> { joins(:layout_category).where("comfy_cms_layout_categories.label = 'topic'") }, + has_many :topics, -> { joins(:layout_category).where("comfy_cms_layout_categories.label = 'topics'") }, + through: :pages_categories, class_name: 'Comfy::Cms::PageCategory', source: :page_category + + has_many :page_types, -> { joins(:layout_category).where("comfy_cms_layout_categories.label = 'types'") }, through: :pages_categories, class_name: 'Comfy::Cms::PageCategory', source: :page_category accepts_nested_attributes_for :pages_categories @@ -26,11 +29,32 @@ def assign_layout_categories end end + delete_orphan_categories && return if _categories.blank? + _categories.each do |cat| tag_name = cat[:tag_params].split(',').first _layout_category = Comfy::Cms::LayoutCategory.find_by(label: tag_name) - Comfy::Cms::LayoutsCategory.find_or_create_by(layout_id: self.id, layout_category_id: _layout_category.id ) + Comfy::Cms::LayoutsCategory.find_or_create_by( + layout_id: self.id, + layout_category_id: _layout_category.id + ) end end + + def delete_orphan_categories + layouts_categories = Comfy::Cms::LayoutsCategory.where(layout_id: self.id) + + self.pages.each do |page| + layouts_categories.each do |lc| + pcs_ids = page.page_categories.where(layout_category_id: lc.id).map(&:id) + Comfy::Cms::PagesCategory.where( + page_id: page.id, + page_category_id: pcs_ids + ).destroy_all + end + end + + layout_categories.destroy_all + end end end \ No newline at end of file diff --git a/config/locales/search/en.yml b/config/locales/search/en.yml index 62c318a23..484156445 100644 --- a/config/locales/search/en.yml +++ b/config/locales/search/en.yml @@ -41,7 +41,13 @@ en: - news-and-stories - resources - areas - topics: - wdpa: WDPA - oecm: OECM - pame: PAME \ No newline at end of file + custom_categories: + topics: + wdpa: WDPA + oecm: OECM + pame: PAME + types: + publications: 'Publications' + statistics: 'Statistics' + technical: 'Technical' + training: 'Training' \ No newline at end of file diff --git a/config/search.yml b/config/search.yml index b4f03ec1e..ce0dfea44 100644 --- a/config/search.yml +++ b/config/search.yml @@ -121,6 +121,11 @@ filters: path: 'topics' field: 'topics.id' required: true + page_type: + type: 'nested' + path: 'page_types' + field: 'page_types.id' + required: true ancestor: type: 'nested' path: 'ancestors' diff --git a/lib/modules/search/templates/mappings.json b/lib/modules/search/templates/mappings.json index 509924967..7606fad9b 100644 --- a/lib/modules/search/templates/mappings.json +++ b/lib/modules/search/templates/mappings.json @@ -243,6 +243,17 @@ } } }, + "page_types": { + "type": "nested", + "properties": { + "id": { + "type": "integer" + }, + "label": { + "type": "keyword" + } + } + }, "fragments_for_index": { "type": "nested", "properties": { From b732955d51e3f35dd798360833d2406bda76743d Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 15:38:17 +0100 Subject: [PATCH 07/14] Update db submodule --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index 4b4dc2742..42fafb442 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 4b4dc2742c23a8267abc9570194d116da52a6e53 +Subproject commit 42fafb44293c82ed6137e56c7e8aee47a1a86bf4 From 0305876e7d24c381621c2fedb96c7d07a4714e17 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 16:11:22 +0100 Subject: [PATCH 08/14] Load custom categories on pages for filters --- app/helpers/cms_helper.rb | 25 +++++++++++++++++++++++++ app/views/resources/index.html.erb | 2 ++ 2 files changed, 27 insertions(+) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index e7695bf0c..d23b0bc37 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -88,6 +88,31 @@ def get_filtered_pages pages pages end + def load_categories + return [] unless @cms_page + layouts_categories = Comfy::Cms::LayoutsCategory.where(layout_id: @cms_page.layout_id) + + # TODO This is a workaround to load the custom categories also based on child pages + # in case the categories for the given page are empty. + # This seems to be necessary now because the layout used for the main page + # can be different from the layout used in the child pages + if layouts_categories.blank? + children_layouts = @cms_page.children.map(&:layout_id) + layouts_categories = Comfy::Cms::LayoutsCategory.where(layout_id: children_layouts) + end + + layouts_categories.map do |lc| + name = lc.layout_category.label + page_categories = lc.layout_category.page_categories.map(&:label).map(&:to_sym) + localised_pcs = I18n.t('search')[:custom_categories][name.to_sym].slice(*page_categories) + + { + name: name, + items: localised_pcs + } + end + end + def cta_api @cta_api ||= CallToAction.find_by_css_class('api') end diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index 02b4a47d3..45027e7f1 100644 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -3,6 +3,8 @@

filters

+ + <%= load_categories %>
From 04b5e96ab0087b611d1c1435aab399cfac5400c9 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 30 Jul 2020 17:09:53 +0100 Subject: [PATCH 09/14] Format filters to be used by the FE and BE afterwards --- app/helpers/cms_helper.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index d23b0bc37..11fb7a3d7 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -103,12 +103,21 @@ def load_categories layouts_categories.map do |lc| name = lc.layout_category.label - page_categories = lc.layout_category.page_categories.map(&:label).map(&:to_sym) - localised_pcs = I18n.t('search')[:custom_categories][name.to_sym].slice(*page_categories) + page_categories = lc.layout_category.page_categories + localised_pcs = I18n.t('search')[:custom_categories][name.to_sym] + + items = page_categories.map do |pc| + { + id: pc.id, + name: localised_pcs[pc.label.to_sym] + } + end + # frontend should return the list of selected categories as follows: + # 'group_name' => [category_ids] ; e.g. 'topics' => [1,2,3] { name: name, - items: localised_pcs + items: items } end end From ab312495782e1f94285e3e5855f7dd1d47799ffe Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Thu, 30 Jul 2020 19:04:26 +0100 Subject: [PATCH 10/14] Change layout of categories in the layout file so they are styled correctly --- lib/cms_tags/categories.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cms_tags/categories.rb b/lib/cms_tags/categories.rb index 737a8a79f..d030b541f 100644 --- a/lib/cms_tags/categories.rb +++ b/lib/cms_tags/categories.rb @@ -8,8 +8,13 @@ def initialize(context:, params: [], source: nil) def form_field(object_name, view, index) options = { id: form_field_id, class: "form-control" } - input = view.send(:collection_check_boxes, :page, :page_category_ids, @categories, :id, :label, options) - + input = view.collection_check_boxes(:page, :page_category_ids, @categories, :id, :label, options) do |b| + view.content_tag(:div, class: "form-check form-check-inline") do + view.concat b.check_box(class: "form-check-input") + view.concat b.label(class: "form-check-label") + end + end + yield input end end From 83315974fa7db4e16fe547122f9bf715eed7ff1c Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Thu, 30 Jul 2020 19:11:24 +0100 Subject: [PATCH 11/14] Remove option code that wasn't being applied and isn't required --- lib/cms_tags/categories.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cms_tags/categories.rb b/lib/cms_tags/categories.rb index d030b541f..9af437eaf 100644 --- a/lib/cms_tags/categories.rb +++ b/lib/cms_tags/categories.rb @@ -6,9 +6,7 @@ def initialize(context:, params: [], source: nil) end def form_field(object_name, view, index) - options = { id: form_field_id, class: "form-control" } - - input = view.collection_check_boxes(:page, :page_category_ids, @categories, :id, :label, options) do |b| + input = view.collection_check_boxes(:page, :page_category_ids, @categories, :id, :label) do |b| view.content_tag(:div, class: "form-check form-check-inline") do view.concat b.check_box(class: "form-check-input") view.concat b.label(class: "form-check-label") From 4254e2e077fa855b8d9bd5de51b1a624b1c2e7bf Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 4 Aug 2020 09:16:18 +0100 Subject: [PATCH 12/14] Make name of categories also translatable --- app/helpers/cms_helper.rb | 5 +++-- config/locales/search/en.yml | 18 +++++++++++------- lib/tasks/cms_categories.rake | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 11fb7a3d7..5de2606a2 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -101,10 +101,11 @@ def load_categories layouts_categories = Comfy::Cms::LayoutsCategory.where(layout_id: children_layouts) end + categories_yml = I18n.t('search')[:custom_categories] layouts_categories.map do |lc| - name = lc.layout_category.label + name = categories_yml[lc.layout_category.label.to_sym][:name] page_categories = lc.layout_category.page_categories - localised_pcs = I18n.t('search')[:custom_categories][name.to_sym] + localised_pcs = categories_yml[name.to_sym][:items] items = page_categories.map do |pc| { diff --git a/config/locales/search/en.yml b/config/locales/search/en.yml index 484156445..e4409b8d2 100644 --- a/config/locales/search/en.yml +++ b/config/locales/search/en.yml @@ -43,11 +43,15 @@ en: - areas custom_categories: topics: - wdpa: WDPA - oecm: OECM - pame: PAME + name: 'topics' + items: + wdpa: WDPA + oecm: OECM + pame: PAME types: - publications: 'Publications' - statistics: 'Statistics' - technical: 'Technical' - training: 'Training' \ No newline at end of file + name: 'types' + items: + publications: 'Publications' + statistics: 'Statistics' + technical: 'Technical' + training: 'Training' \ No newline at end of file diff --git a/lib/tasks/cms_categories.rake b/lib/tasks/cms_categories.rake index e48449b03..5b0e7f469 100644 --- a/lib/tasks/cms_categories.rake +++ b/lib/tasks/cms_categories.rake @@ -5,7 +5,7 @@ namespace :cms_categories do groups.each do |group_name, categories| layout_category = Comfy::Cms::LayoutCategory.find_or_create_by(label: group_name.to_s) - categories_names = categories.keys + categories_names = categories[:items].keys categories_names.each do |cat_name| Comfy::Cms::PageCategory.find_or_create_by(layout_category_id: layout_category.id, label: cat_name) From 2033f1d449c3b7ded5f17e5a70b48c93e0846180 Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Tue, 4 Aug 2020 17:54:49 +0100 Subject: [PATCH 13/14] update db --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index 42fafb442..a0e724d57 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 42fafb44293c82ed6137e56c7e8aee47a1a86bf4 +Subproject commit a0e724d577f95b46308b9a5633b0b55826913ba8 From 2b2d5676360a91bd097c862b3314858894afd151 Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Tue, 4 Aug 2020 17:55:45 +0100 Subject: [PATCH 14/14] Fix db conflict --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index a0e724d57..7f970b02d 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit a0e724d577f95b46308b9a5633b0b55826913ba8 +Subproject commit 7f970b02d2eb785833ad9f9be2f31b7925f851ad