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

Working

parent ce8c179c
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We ...@@ -24,6 +24,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We
end end
old_parent_page.sync_with_git old_parent_page.sync_with_git
parent_page.sync_with_git parent_page.sync_with_git
@website.generate_automatic_menus
end end
def children def children
......
module Communication::Website::Menu::WithAutomatism module Communication::Website::Menu::WithAutomatism
extend ActiveSupport::Concern extend ActiveSupport::Concern
def create_automatic_menu included do
scope :automatic, -> { where(automatic: true) }
end
def generate_automatically
begin
suspend_git_sync
clear_items
create_items
ensure
reactivate_git_sync
end
end end
def stop_automatism! def stop_automatism!
update_column :automatic, false update_column :automatic, false
end end
protected
def suspend_git_sync
# TODO
end
def clear_items
# TODO est-ce bien de ne pas gérer les dépendances avec un destroy? Effet de bord?
items.delete_all
end
def create_items
home = website.pages.root.first
create_items_for_children_of(home)
end
def create_items_for_children_of(page, parent_item = nil)
page.children.ordered.each do |child_page|
next if child_page.default_menu_identifier != identifier
create_item_for(child_page, parent_item)
end
end
def create_item_for(page, parent_item = nil)
item = items.create kind: :page,
about: page,
title: page.title,
position: page.position,
website: website,
university: university,
parent: parent_item
create_items_for_children_of(page, item)
end
def reactivate_git_sync
# TODO
end
end end
\ No newline at end of file
...@@ -48,6 +48,7 @@ class Communication::Website::Page < ApplicationRecord ...@@ -48,6 +48,7 @@ class Communication::Website::Page < ApplicationRecord
include AsDirectObject include AsDirectObject
include Sanitizable include Sanitizable
include WithAccessibility include WithAccessibility
include WithAutomaticMenus
include WithBlobs include WithBlobs
include WithBlocks include WithBlocks
include WithDuplication include WithDuplication
......
...@@ -51,6 +51,10 @@ class Communication::Website::Page::Accessibility < Communication::Website::Page ...@@ -51,6 +51,10 @@ class Communication::Website::Page::Accessibility < Communication::Website::Page
false false
end end
def default_menu_identifier
'legal'
end
def generate_from_template def generate_from_template
generate_declaration generate_declaration
generate_results generate_results
......
...@@ -50,5 +50,9 @@ class Communication::Website::Page::LegalTerm < Communication::Website::Page ...@@ -50,5 +50,9 @@ class Communication::Website::Page::LegalTerm < Communication::Website::Page
def is_listed_among_children? def is_listed_among_children?
false false
end end
def default_menu_identifier
'legal'
end
end end
...@@ -50,5 +50,9 @@ class Communication::Website::Page::PrivacyPolicy < Communication::Website::Page ...@@ -50,5 +50,9 @@ class Communication::Website::Page::PrivacyPolicy < Communication::Website::Page
def is_listed_among_children? def is_listed_among_children?
false false
end end
def default_menu_identifier
'legal'
end
end end
...@@ -67,4 +67,8 @@ class Communication::Website::Page::Sitemap < Communication::Website::Page ...@@ -67,4 +67,8 @@ class Communication::Website::Page::Sitemap < Communication::Website::Page
'sitemap' 'sitemap'
end end
def default_menu_identifier
'legal'
end
end end
module Communication::Website::Page::WithAutomaticMenus
extend ActiveSupport::Concern
included do
after_save :generate_automatic_menus
end
protected
def generate_automatic_menus
website.generate_automatic_menus
end
end
\ No newline at end of file
...@@ -86,6 +86,10 @@ module Communication::Website::Page::WithType ...@@ -86,6 +86,10 @@ module Communication::Website::Page::WithType
nil nil
end end
def default_menu_identifier
'primary'
end
def generate_from_template def generate_from_template
end end
......
...@@ -64,9 +64,13 @@ module Communication::Website::WithMenus ...@@ -64,9 +64,13 @@ module Communication::Website::WithMenus
def initialize_menus def initialize_menus
find_or_create_menu 'primary' find_or_create_menu 'primary'
find_or_create_menu 'social' find_or_create_menu 'social'
find_or_create_menu('legal') do |menu| find_or_create_menu 'legal'
# Only executed after menu creation generate_automatic_menus
fill_legal_menu(menu) end
def generate_automatic_menus
menus.automatic.find_each do |menu|
menu.generate_automatically
end end
end end
...@@ -76,24 +80,6 @@ module Communication::Website::WithMenus ...@@ -76,24 +80,6 @@ module Communication::Website::WithMenus
menu = menus.where(identifier: identifier, university: university, language: default_language).first_or_initialize do |menu| menu = menus.where(identifier: identifier, university: university, language: default_language).first_or_initialize do |menu|
menu.title = I18n.t("communication.website.menus.default_title.#{identifier}") menu.title = I18n.t("communication.website.menus.default_title.#{identifier}")
end end
unless menu.persisted? menu.save unless menu.persisted?
menu.save
yield(menu) if block_given?
end
menu
end
def fill_legal_menu(menu)
[
Communication::Website::Page::LegalTerm,
Communication::Website::Page::PrivacyPolicy,
Communication::Website::Page::Accessibility,
Communication::Website::Page::Sitemap
].each do |page_class|
page = special_page(page_class, language: menu.language)
menu.items.where(kind: 'page', about: page, university: university, website: self).first_or_create do |item|
item.title = page.title
end
end
end end
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