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

menu filtered

parent f3496abc
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ GEM
execjs (~> 2)
aws-eventstream (1.2.0)
aws-partitions (1.549.0)
aws-sdk-core (3.125.4)
aws-sdk-core (3.125.5)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
......@@ -88,7 +88,7 @@ GEM
aws-sdk-kms (1.53.0)
aws-sdk-core (~> 3, >= 3.125.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.111.1)
aws-sdk-s3 (1.111.2)
aws-sdk-core (~> 3, >= 3.125.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
......@@ -126,7 +126,7 @@ GEM
countries (4.2.1)
i18n_data (~> 0.15.0)
sixarm_ruby_unaccent (~> 1.1)
country_select (6.1.0)
country_select (6.1.1)
countries (~> 4.2)
sort_alphabetical (~> 1.1)
crass (1.0.6)
......@@ -263,7 +263,7 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.7.1)
minitest (5.15.0)
msgpack (1.4.2)
msgpack (1.4.3)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
......
......@@ -37,6 +37,7 @@ class Communication::Website < ApplicationRecord
include WithGitRepository
include WithHome
include WithImport
include WithMenuItems
belongs_to :university
......@@ -50,10 +51,6 @@ class Communication::Website < ApplicationRecord
"data/website.yml"
end
def menu_item_kinds
Communication::Website::Menu::Item.kinds_for_website(self)
end
def git_dependencies(website)
dependencies = (
[self] +
......
......@@ -32,9 +32,6 @@
# fk_rails_... (website_id => communication_websites.id)
#
class Communication::Website::Menu::Item < ApplicationRecord
KINDS_FOR_SCHOOL = ['programs', 'program', 'administrators', 'teachers']
KINDS_FOR_JOURNAL = ['researchers', 'research_volumes', 'research_volume', 'research_articles', 'research_article']
include WithTree
include WithPosition
......@@ -45,10 +42,10 @@ class Communication::Website::Menu::Item < ApplicationRecord
belongs_to :menu, class_name: 'Communication::Website::Menu'
belongs_to :parent, class_name: 'Communication::Website::Menu::Item', optional: true
belongs_to :about, polymorphic: true, optional: true
has_many :children,
class_name: 'Communication::Website::Menu::Item',
foreign_key: :parent_id,
dependent: :destroy
has_many :children,
class_name: 'Communication::Website::Menu::Item',
foreign_key: :parent_id,
dependent: :destroy
enum kind: {
blank: 0,
......@@ -75,58 +72,48 @@ class Communication::Website::Menu::Item < ApplicationRecord
after_commit :sync_menu
def self.kinds_for_website(website)
whitelisted_kinds = self.kinds.dup
KINDS_FOR_SCHOOL.each { |school_kind|
whitelisted_kinds.delete(school_kind)
} unless website.about_school?
KINDS_FOR_JOURNAL.each { |journal_kind|
whitelisted_kinds.delete(journal_kind)
} unless website.about_journal?
whitelisted_kinds
end
def to_s
"#{title}"
end
def static_target
target = nil
active = website.send "menu_item_kind_#{kind}?"
return nil unless active
published = about&.published && about&.published_at
case self.kind
when 'blank'
target = ''
when 'url'
target = url
when 'page'
target = about.path if about&.published
when 'programs'
target = "/#{website.static_pathname_programs}" if website.programs.any?
target = "/#{website.static_pathname_programs}"
when 'program'
target = "/#{website.static_pathname_programs}#{about.path}" if website.about_school?
target = "/#{website.static_pathname_programs}#{about.path}"
when 'news'
target = "/#{website.static_pathname_posts}" if website.posts.published.any?
target = "/#{website.static_pathname_posts}"
when 'news_article'
target = "/#{website.static_pathname_posts}#{about.path}" if about&.published_at
target = "/#{website.static_pathname_posts}#{about.path}" if published
when 'staff'
target = "/#{website.static_pathname_staff}" if website.people.any?
target = "/#{website.static_pathname_staff}"
when 'administrators'
target = "/#{website.static_pathname_administrators}" if website.university_people_through_administrators.any?
target = "/#{website.static_pathname_administrators}"
when 'authors'
target = "/#{website.static_pathname_authors}" if website.authors.compact.any?
target = "/#{website.static_pathname_authors}"
when 'researchers'
target = "/#{website.static_pathname_researchers}" if website.research_articles.collect(&:researchers).flatten.any?
target = "/#{website.static_pathname_researchers}"
when 'teachers'
target = "/#{website.static_pathname_teachers}" if website.programs.collect(&:university_people_through_teachers).flatten.any?
target = "/#{website.static_pathname_teachers}"
when 'research_volumes'
target = "/#{website.static_pathname_research_volumes}" if website.research_volumes.published.any?
target = "/#{website.static_pathname_research_volumes}"
when 'research_volume'
target = "/#{website.static_pathname_research_volumes}#{about.path}" if about&.published_at
target = "/#{website.static_pathname_research_volumes}#{about.path}" if published
when 'research_articles'
target = "/#{website.static_pathname_research_articles}" if website.research_articles.published.any?
target = "/#{website.static_pathname_research_articles}"
when 'research_article'
target = "/#{website.static_pathname_research_articles}#{about.path}" if about&.published_at
when 'blank'
target = ''
target = "/#{website.static_pathname_research_articles}#{about.path}" if published
else
target = about&.path
end
......
......@@ -27,7 +27,12 @@ module Communication::Website::WithAbouts
dependent: :destroy
def self.about_types
[nil, Education::School.name, Research::Laboratory.name, Research::Journal.name]
[
nil,
Education::School.name,
Research::Laboratory.name,
Research::Journal.name
]
end
after_save_commit :set_programs_categories!, if: -> (website) { website.about_school? }
......@@ -66,8 +71,8 @@ module Communication::Website::WithAbouts
people += about.university_people_through_administrators
people += about.university_people_through_administrators.map(&:administrator)
elsif about_journal?
people += research_articles.collect(&:researchers).flatten
people += research_articles.collect(&:researchers).flatten.map(&:researcher)
people += research_articles.collect(&:persons).flatten
people += research_articles.collect(&:persons).flatten.map(&:researcher)
end
people.uniq.compact
end
......
module Communication::Website::WithMenuItems
extend ActiveSupport::Concern
def menu_item_kinds
Communication::Website::Menu::Item.kinds.reject do |key, value|
active = send "menu_item_kind_#{key}?"
!active
end
end
def menu_item_kind_blank?
true
end
def menu_item_kind_url?
true
end
def menu_item_kind_page?
pages.any?
end
def menu_item_kind_programs?
about_school? && programs.any?
end
def menu_item_kind_program?
about_school? && programs.any?
end
def menu_item_kind_news?
posts.published.any?
end
def menu_item_kind_news_category?
categories.any?
end
def menu_item_kind_news_article?
menu_item_kind_news?
end
def menu_item_kind_staff?
authors.any?
end
def menu_item_kind_administrators?
people.any?
end
def menu_item_kind_authors?
authors.compact.any?
end
def menu_item_kind_researchers?
research_articles.collect(&:persons).flatten.any?
end
def menu_item_kind_teachers?
programs.collect(&:university_people_through_teachers).flatten.any?
end
def menu_item_kind_research_volumes?
research_volumes.published.any?
end
def menu_item_kind_research_volume?
menu_item_kind_research_volumes?
end
def menu_item_kind_research_articles?
research_articles.published.any?
end
def menu_item_kind_research_article?
menu_item_kind_research_articles?
end
end
......@@ -30,7 +30,6 @@
</div>
</div>
<% end %>
</div>
<div class="<%= 'd-none' unless item.url? %> js-url-field">
<%= f.input :url, as: :string %>
......
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