Skip to content
Snippets Groups Projects
Commit 7b1b47ea authored by Arnaud Levy's avatar Arnaud Levy
Browse files

creation wip

parent 887a04e9
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 75 deletions
......@@ -92,7 +92,7 @@ class Communication::Website::Page < ApplicationRecord
git_block_dependencies +
type_git_dependencies
dependencies += [parent] if has_parent?
dependencies.flatten
dependencies.flatten.compact
end
def git_destroy_dependencies(website)
......
......@@ -48,7 +48,7 @@ class Communication::Website::Page::Administrator < Communication::Website::Page
def type_git_dependencies
[
website.config_default_permalinks,
website.website.administrators.map(&:administrator)
website&.administrators&.map(&:administrator)
]
end
end
......@@ -48,7 +48,7 @@ class Communication::Website::Page::Author < Communication::Website::Page
def type_git_dependencies
[
website.config_default_permalinks,
website.website.authors.map(&:author)
website&.authors&.map(&:author)
]
end
end
......@@ -41,6 +41,10 @@
#
class Communication::Website::Page::EducationDiploma < Communication::Website::Page
def is_necessary_for_website?
website.about && website.about&.respond_to(:education_diplomas)
end
def full_width
true
end
......
......@@ -41,6 +41,10 @@
#
class Communication::Website::Page::EducationProgram < Communication::Website::Page
def is_necessary_for_website?
website.about && website.about&.respond_to(:education_programs)
end
def full_width
true
end
......
......@@ -41,6 +41,10 @@
#
class Communication::Website::Page::ResearchPaper < Communication::Website::Page
def is_necessary_for_website?
website.about && website.about&.respond_to(:research_papers)
end
def current_git_path
"#{git_path_prefix}papers/_index.html"
end
......
......@@ -41,6 +41,10 @@
#
class Communication::Website::Page::ResearchVolume < Communication::Website::Page
def is_necessary_for_website?
website.about && website.about&.respond_to(:research_volumes)
end
def current_git_path
"#{git_path_prefix}volumes/_index.html"
end
......
......@@ -48,7 +48,7 @@ class Communication::Website::Page::Researcher < Communication::Website::Page
def type_git_dependencies
[
website.config_default_permalinks,
website.website.researchers.map(&:researcher)
website&.researchers&.map(&:researcher)
]
end
end
......@@ -48,7 +48,7 @@ class Communication::Website::Page::Teacher < Communication::Website::Page
def type_git_dependencies
[
website.config_default_permalinks,
website.website.teachers.map(&:teacher)
website&.teachers&.map(&:teacher)
].flatten
end
end
......@@ -3,7 +3,26 @@ module Communication::Website::Page::WithType
included do
HOME_TYPE = '::Communication::Website::Page::Home'
HOME_TYPE = 'Communication::Website::Page::Home'
TYPES = [
Communication::Website::Page::Home, # Always start with home
Communication::Website::Page::Accessibility,
Communication::Website::Page::Administrator,
Communication::Website::Page::Author,
Communication::Website::Page::CommunicationPost,
Communication::Website::Page::EducationDiploma,
Communication::Website::Page::EducationProgram,
Communication::Website::Page::LegalTerm,
Communication::Website::Page::Organization,
Communication::Website::Page::Person,
Communication::Website::Page::PrivacyPolicy,
Communication::Website::Page::ResearchPaper,
Communication::Website::Page::ResearchVolume,
Communication::Website::Page::Researcher,
Communication::Website::Page::Sitemap,
Communication::Website::Page::Teacher
]
scope :home, -> { where(type: HOME_TYPE) }
end
......
......@@ -61,15 +61,15 @@ module Communication::Website::WithDependencies
end
def administrators
about.administrators
about&.administrators
end
def researchers
about.researchers
about&.researchers
end
def teachers
about.teachers
about&.teachers
end
def people_in_blocks
......
......@@ -2,79 +2,31 @@ module Communication::Website::WithSpecialPages
extend ActiveSupport::Concern
included do
# first level pages with test
SPECIAL_PAGES_WITH_TEST = [
'legal_terms',
'sitemap',
'privacy_policy',
'accessibility',
'communication_posts',
'education_programs',
'education_diplomas',
'research_papers',
'research_volumes',
'organizations'
]
# team pages
SPECIAL_PAGES_FOR_PERSONS = [
'administrators',
'authors',
'researchers',
'teachers'
]
after_create :create_missing_special_pages
after_touch :create_missing_special_pages, :manage_special_pages_publication
def special_page(kind)
pages.where(kind: kind).first
end
def create_missing_special_pages
homepage = create_special_page('home')
SPECIAL_PAGES_WITH_TEST.each do |kind|
create_special_page(kind, homepage.id) if public_send("has_#{kind}?")
end
if has_persons?
persons = create_special_page('persons', homepage.id)
SPECIAL_PAGES_FOR_PERSONS.each do |kind|
create_special_page(kind, persons.id) if public_send("has_#{kind}?")
end
end
end
after_touch :create_missing_special_pages
end
def manage_special_pages_publication
special_pages_keys.each do |kind|
published = public_send("has_#{kind}?")
special_page(kind).update(published: published)
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
end
private
protected
def create_special_page(kind, parent_id = nil)
i18n_key = "communication.website.pages.defaults.#{kind}"
page = pages.where(kind: kind).first_or_initialize(
title: I18n.t("#{i18n_key}.title"),
slug: I18n.t("#{i18n_key}.slug"),
description_short: I18n.t("#{i18n_key}.description_short"),
parent_id: parent_id,
published: true,
university_id: university_id
)
def create_special_page(page_class, parent)
page = page_class.where(website: self, university: university).first_or_initialize
if page.new_record?
# This is a bit brutal, as it might generate several syncs at the same time
page.save_and_sync
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?
end
page
end
def special_pages_keys
@special_pages_keys ||= pages.where.not(kind: nil).pluck(:kind).uniq
end
end
......@@ -10,7 +10,7 @@ namespace :app do
task fix: :environment do
Communication::Website::Page.find_each do |page|
if page.kind
type = "::Communication::Website::Page::#{page.kind.to_s.classify}"
type = "Communication::Website::Page::#{page.kind.to_s.classify}"
page.update_column :type, type
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment