diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 7bc72d2642f2c13da7f17cafded8f770c0f20996..8387ebf6c4d0c824531d0783723ccdd32ea2f70f 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -81,7 +81,13 @@ class Communication::Website < ApplicationRecord end def git_dependencies(website) - dependencies = [self, config_default_languages, config_default_permalinks, config_development_config, config_production_config] + menus + dependencies = [ + self, + config_default_languages, + config_default_permalinks, + config_development_config, + config_production_config + ] + menus dependencies += pages + pages.includes(parent: { featured_image_attachment: :blob }, featured_image_attachment: :blob).map(&:active_storage_blobs).flatten dependencies += posts + posts.includes(featured_image_attachment: :blob).map(&:active_storage_blobs).flatten dependencies += people_with_facets + people.map(&:active_storage_blobs).flatten diff --git a/app/models/communication/website/page/accessibility.rb b/app/models/communication/website/page/accessibility.rb index aa0ec83cb50c573f29b9ef51bb93c4acce0ac531..de2b0ff1289b02e7d2c710bc28ab8edcad868b0e 100644 --- a/app/models/communication/website/page/accessibility.rb +++ b/app/models/communication/website/page/accessibility.rb @@ -44,4 +44,8 @@ class Communication::Website::Page::Accessibility < Communication::Website::Page def draftable? false end + + def default_position + 90 + end end diff --git a/app/models/communication/website/page/administrator.rb b/app/models/communication/website/page/administrator.rb index b6f74915331a972ecd91d6b2cae26b610ba5bb60..f95cba0c9745b05beb56737265b86364ce7440de 100644 --- a/app/models/communication/website/page/administrator.rb +++ b/app/models/communication/website/page/administrator.rb @@ -42,7 +42,7 @@ class Communication::Website::Page::Administrator < Communication::Website::Page def is_necessary_for_website? - website.about && website.about&.respond_to(:administrators) + website.about && website.about&.respond_to?(:administrators) end def current_git_path @@ -55,4 +55,10 @@ class Communication::Website::Page::Administrator < Communication::Website::Page website&.administrators&.map(&:administrator) ] end + + protected + + def default_parent + website.persons_page + end end diff --git a/app/models/communication/website/page/author.rb b/app/models/communication/website/page/author.rb index 5e7cda9b79ae6ada45eee93ebb90a02819efb110..32d0e5e87959c4767d67a567f70d2d6843c7d2ff 100644 --- a/app/models/communication/website/page/author.rb +++ b/app/models/communication/website/page/author.rb @@ -51,4 +51,10 @@ class Communication::Website::Page::Author < Communication::Website::Page website&.authors&.map(&:author) ] end + + protected + + def default_parent + website.persons_page + end end diff --git a/app/models/communication/website/page/communication_post.rb b/app/models/communication/website/page/communication_post.rb index 7b36eb47e27c36e6edae6de8b8345fa9b90669b9..a51c0d532fceca095f1e4a77fdea50ac8aa3123f 100644 --- a/app/models/communication/website/page/communication_post.rb +++ b/app/models/communication/website/page/communication_post.rb @@ -53,6 +53,10 @@ class Communication::Website::Page::CommunicationPost < Communication::Website:: false end + def default_position + 1 + end + def current_git_path "#{git_path_prefix}posts/_index.html" end diff --git a/app/models/communication/website/page/education_diploma.rb b/app/models/communication/website/page/education_diploma.rb index b864ec7c549337edfc9dc23814567c6b3c1f9eda..58252b81d8935f6a0c9bee7e2162485ecc48ea78 100644 --- a/app/models/communication/website/page/education_diploma.rb +++ b/app/models/communication/website/page/education_diploma.rb @@ -42,7 +42,7 @@ class Communication::Website::Page::EducationDiploma < Communication::Website::Page def is_necessary_for_website? - website.about && website.about&.respond_to(:education_diplomas) + website.about && website.about&.respond_to?(:education_diplomas) end def full_width @@ -57,6 +57,10 @@ class Communication::Website::Page::EducationDiploma < Communication::Website::P false end + def default_position + 10 + end + def current_git_path "#{git_path_prefix}diplomas/_index.html" end diff --git a/app/models/communication/website/page/education_program.rb b/app/models/communication/website/page/education_program.rb index 1f9334d375839283c04fce42fd4f4f73b5e359b4..4b23782b8188ca305b1dcb7b4eb679133e447bac 100644 --- a/app/models/communication/website/page/education_program.rb +++ b/app/models/communication/website/page/education_program.rb @@ -42,7 +42,7 @@ class Communication::Website::Page::EducationProgram < Communication::Website::Page def is_necessary_for_website? - website.about && website.about&.respond_to(:education_programs) + website.about && website.about&.respond_to?(:programs) end def full_width @@ -57,6 +57,10 @@ class Communication::Website::Page::EducationProgram < Communication::Website::P false end + def default_position + 11 + end + def current_git_path "#{git_path_prefix}programs/_index.html" end diff --git a/app/models/communication/website/page/home.rb b/app/models/communication/website/page/home.rb index 05d09454154c449ed73cfd0635c4dc2853a109f6..6929b9089516e3a552dd614645160f8b33161183 100644 --- a/app/models/communication/website/page/home.rb +++ b/app/models/communication/website/page/home.rb @@ -59,6 +59,10 @@ class Communication::Website::Page::Home < Communication::Website::Page protected + def default_parent + nil + end + def set_slug self.slug = '' end diff --git a/app/models/communication/website/page/legal_term.rb b/app/models/communication/website/page/legal_term.rb index 5d3668c13a3f6296dd19d4946a43b38ed778fcb6..9d2e0fd373f37145c994fa9533f4eec16a98572b 100644 --- a/app/models/communication/website/page/legal_term.rb +++ b/app/models/communication/website/page/legal_term.rb @@ -44,4 +44,8 @@ class Communication::Website::Page::LegalTerm < Communication::Website::Page def draftable? false end + + def default_position + 91 + end end diff --git a/app/models/communication/website/page/organization.rb b/app/models/communication/website/page/organization.rb index f31d856ce6bc11c0aea625fd22476bf9022d1247..9333f74023ce73ac2beef959e909ff8454bdb813 100644 --- a/app/models/communication/website/page/organization.rb +++ b/app/models/communication/website/page/organization.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::Organization < Communication::Website::Page + def default_position + 31 + end + def current_git_path "#{git_path_prefix}organizations/_index.html" end diff --git a/app/models/communication/website/page/person.rb b/app/models/communication/website/page/person.rb index 6572ece248ddb99f3ab0e5624391b9a23c453299..e5b4fdf6e829cc41ba4c626f29e917bfdc5e50d1 100644 --- a/app/models/communication/website/page/person.rb +++ b/app/models/communication/website/page/person.rb @@ -41,6 +41,10 @@ # class Communication::Website::Page::Person < Communication::Website::Page + def default_position + 30 + end + def current_git_path "#{git_path_prefix}persons/_index.html" end diff --git a/app/models/communication/website/page/privacy_policy.rb b/app/models/communication/website/page/privacy_policy.rb index d3fe6738bee27f48cfaee74779fbebf54a9d3f93..ffe368fe14c54f01572f488373de4f11c26351ec 100644 --- a/app/models/communication/website/page/privacy_policy.rb +++ b/app/models/communication/website/page/privacy_policy.rb @@ -41,4 +41,7 @@ # class Communication::Website::Page::PrivacyPolicy < Communication::Website::Page + def default_position + 92 + end end diff --git a/app/models/communication/website/page/research_paper.rb b/app/models/communication/website/page/research_paper.rb index 1497d4cfa46814006a31e2a59be77284205f6242..5633ca32567fb41a1b6d3fc178bf8b9297342f04 100644 --- a/app/models/communication/website/page/research_paper.rb +++ b/app/models/communication/website/page/research_paper.rb @@ -41,8 +41,12 @@ # class Communication::Website::Page::ResearchPaper < Communication::Website::Page + def default_position + 41 + end + def is_necessary_for_website? - website.about && website.about&.respond_to(:research_papers) + website.about && website.about&.respond_to?(:papers) end def current_git_path diff --git a/app/models/communication/website/page/research_volume.rb b/app/models/communication/website/page/research_volume.rb index 3aca8617bd8cf3c76eefdb0689e5de56998de9d3..1119b006091eb68b2907f1bdf0400678520d3d23 100644 --- a/app/models/communication/website/page/research_volume.rb +++ b/app/models/communication/website/page/research_volume.rb @@ -41,8 +41,12 @@ # class Communication::Website::Page::ResearchVolume < Communication::Website::Page + def default_position + 40 + end + def is_necessary_for_website? - website.about && website.about&.respond_to(:research_volumes) + website.about && website.about&.respond_to?(:volumes) end def current_git_path diff --git a/app/models/communication/website/page/researcher.rb b/app/models/communication/website/page/researcher.rb index b255ede9cae16c1c22655a75b07fe804a2b7ed0d..04dcb239cec41967ef4ed5ebe0553f669b69bad3 100644 --- a/app/models/communication/website/page/researcher.rb +++ b/app/models/communication/website/page/researcher.rb @@ -42,7 +42,7 @@ class Communication::Website::Page::Researcher < Communication::Website::Page def is_necessary_for_website? - website.about && website.about&.respond_to(:researchers) + website.about && website.about&.respond_to?(:researchers) end def current_git_path @@ -55,4 +55,10 @@ class Communication::Website::Page::Researcher < Communication::Website::Page website&.researchers&.map(&:researcher) ] end + + protected + + def default_parent + website.persons_page + end end diff --git a/app/models/communication/website/page/sitemap.rb b/app/models/communication/website/page/sitemap.rb index 659b213ae2b12d5f799d3ee0ac9a94a250e76af4..0ccb3c9f5f9eecdf4ce866fd2a76125a89df35e2 100644 --- a/app/models/communication/website/page/sitemap.rb +++ b/app/models/communication/website/page/sitemap.rb @@ -52,4 +52,8 @@ class Communication::Website::Page::Sitemap < Communication::Website::Page def editable_width? false end + + def default_position + 93 + end end diff --git a/app/models/communication/website/page/teacher.rb b/app/models/communication/website/page/teacher.rb index 24ab34bbf5d7732fbde97f20fc4a77f9104291c6..dc11b628ec6bab83d2a3492f92052ce29987bed1 100644 --- a/app/models/communication/website/page/teacher.rb +++ b/app/models/communication/website/page/teacher.rb @@ -42,7 +42,7 @@ class Communication::Website::Page::Teacher < Communication::Website::Page def is_necessary_for_website? - website.about && website.about&.respond_to(:teachers) + website.about && website.about&.respond_to?(:teachers) end def current_git_path @@ -55,4 +55,10 @@ class Communication::Website::Page::Teacher < Communication::Website::Page website&.teachers&.map(&:teacher) ].flatten end + + protected + + def default_parent + website.persons_page + end end diff --git a/app/models/communication/website/page/with_type.rb b/app/models/communication/website/page/with_type.rb index a2ef3eaee71f906b8c7b34cc71f25b0b63e26bef..300eef28e4fdd9975fc202c8404f3655789acf8f 100644 --- a/app/models/communication/website/page/with_type.rb +++ b/app/models/communication/website/page/with_type.rb @@ -3,7 +3,8 @@ module Communication::Website::Page::WithType included do - HOME_TYPE = 'Communication::Website::Page::Home' + TYPE_HOME = 'Communication::Website::Page::Home' + TYPE_PERSONS = 'Communication::Website::Page::Person' TYPES = [ Communication::Website::Page::Home, # Always start with home @@ -24,7 +25,11 @@ module Communication::Website::Page::WithType Communication::Website::Page::Teacher ] - scope :home, -> { where(type: HOME_TYPE) } + scope :home, -> { where(type: TYPE_HOME) } + scope :persons, -> { where(type: TYPE_PERSONS) } + + after_initialize :initialize_page + after_create :positionize_page end # Communication::Website::Page::CommunicationPosts -> communication_posts @@ -34,7 +39,7 @@ module Communication::Website::Page::WithType end def is_home? - type == HOME_TYPE + type == TYPE_HOME end def is_special_page? @@ -71,7 +76,31 @@ module Communication::Website::Page::WithType is_regular_page? end + protected + + def default_parent + website.home_page + end + + def default_position + nil + end + def type_git_dependencies [] end + + def initialize_page + i18n_key = "communication.website.pages.defaults.#{type_key}" + self.title = I18n.t("#{i18n_key}.title") + self.slug = I18n.t("#{i18n_key}.slug") + self.parent = default_parent + self.full_width = full_width_by_default? + self.published = published_by_default? + end + + def positionize_page + return if is_regular_page? + self.update_column :position, default_position if default_position + end end \ No newline at end of file diff --git a/app/models/communication/website/with_special_pages.rb b/app/models/communication/website/with_special_pages.rb index b64c850512cc4a2d0d2ccc5e9fdebe289db12f3b..2b2f973a2fdf05ba2138ee294cee33d0d813c535 100644 --- a/app/models/communication/website/with_special_pages.rb +++ b/app/models/communication/website/with_special_pages.rb @@ -3,30 +3,24 @@ module Communication::Website::WithSpecialPages included do after_create :create_missing_special_pages + after_save :create_missing_special_pages after_touch :create_missing_special_pages end - def create_missing_special_pages - home = nil - special_pages = Communication::Website::Page::TYPES.each do |page_class| - page = create_special_page page_class, home - home = page if home.nil? - end + def home_page + pages.home.first end - protected + def persons_page + pages.persons.first + end - def create_special_page(page_class, parent) - page = page_class.where(website: self, university: university).first_or_initialize - if page.new_record? - i18n_key = "communication.website.pages.defaults.#{page.type_key}" - page.title = I18n.t("#{i18n_key}.title") - page.slug = I18n.t("#{i18n_key}.slug") - page.parent = parent - page.full_width = page.full_width_by_default? - page.published = page.published_by_default? - page.save_and_sync if page.is_necessary_for_website? + def create_missing_special_pages + Communication::Website::Page::TYPES.each do |page_class| + page = page_class.where(website: self, university: university).first_or_initialize + next if page.persisted? # No resave + next unless page.is_necessary_for_website? # No useless pages + page.save_and_sync end - page end end