diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb index 4cc7c2cda7acb2abdd1b40c9429cb92945d33847..c112b51d5a28f27c5982be8b23ebfa01cb73beba 100644 --- a/app/controllers/admin/research/journal/articles_controller.rb +++ b/app/controllers/admin/research/journal/articles_controller.rb @@ -60,7 +60,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A def article_params params.require(:research_journal_article) - .permit(:title, :slug, :text, :published, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, researcher_ids: []) + .permit(:title, :slug, :text, :published, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, person_ids: []) .merge(university_id: current_university.id) end end diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index 7e6e6749448677a8dafd7953d4f5ff4a53e32da9..23c54a029f65943d85ee1c644187db99ccd81370 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -34,6 +34,7 @@ class Communication::Website::Menu::Item < ApplicationRecord include WithTree include WithPosition + include WithTargets attr_accessor :skip_publication_callback @@ -80,42 +81,10 @@ class Communication::Website::Menu::Item < ApplicationRecord target = nil active = website.send "menu_item_kind_#{kind}?" return nil unless active - case self.kind - when 'blank' - target = '' - when 'url' - target = url - when 'page' - target = about.path if about&.published - when 'programs' - target = "/#{website.structure.education_programs_path}" - when 'program' - target = "/#{website.structure.education_programs_path}#{about.path}" - when 'news' - target = "/#{website.structure.communication_posts_path}" - when 'news_article' - target = "/#{website.structure.communication_posts_path}#{about.path}" if about&.published && about&.published_at - when 'staff' - target = "/#{website.structure.persons_path}" - when 'administrators' - target = "/#{website.structure.administrators_path}" - when 'authors' - target = "/#{website.structure.authors_path}" - when 'researchers' - target = "/#{website.structure.researchers_path}" - when 'teachers' - target = "/#{website.structure.teachers_path}" - when 'research_volumes' - target = "/#{website.structure.research_volumes_path}" - when 'research_volume' - target = "/#{website.structure.research_volumes_path}#{about.path}" if about&.published && about&.published_at - when 'research_articles' - target = "/#{website.structure.research_articles_path}" - when 'research_article' - target = "/#{website.structure.research_articles_path}#{about.path}" if about&.published && about&.published_at - else - target = about&.path - end + # Les méthodes target_for_ sont définies dans le concern WithTarget + method = "target_for_#{kind}" + target = respond_to?(method) ? send(method) + : about&.path return nil if target.nil? target.end_with?('/') ? target : "#{target}/" @@ -141,9 +110,12 @@ class Communication::Website::Menu::Item < ApplicationRecord end def has_about? - kind_page? || kind_program? || - kind_news_category? || kind_news_article? || - kind_research_volume? || kind_research_article? + kind_page? || + kind_program? || + kind_news_category? || + kind_news_article? || + kind_research_volume? || + kind_research_article? end def sync_menu diff --git a/app/models/communication/website/menu/item/with_targets.rb b/app/models/communication/website/menu/item/with_targets.rb new file mode 100644 index 0000000000000000000000000000000000000000..8ca3adea79206e9ada0ac1a97a43c577532d462a --- /dev/null +++ b/app/models/communication/website/menu/item/with_targets.rb @@ -0,0 +1,74 @@ +module Communication::Website::Menu::Item::WithTargets + extend ActiveSupport::Concern + + protected + + def target_for_blank + '' + end + + def target_for_url + url + end + + def target_for_page + about.path if about&.published + end + + def target_for_programs + "/#{website.structure.education_programs_path}" + end + + def target_for_program + "/#{website.structure.education_programs_path}#{about.path}" + end + + def target_for_news + "/#{website.structure.communication_posts_path}" + end + + def target_for_news_article + "/#{website.structure.communication_posts_path}#{about.path}" if about&.published && about&.published_at + end + + def target_for_news_category + # TODO use communication_categories_path + "/#{website.structure.communication_posts_path}/categories#{about.path}" if about + end + + def target_for_staff + "/#{website.structure.persons_path}" + end + + def target_for_administrators + "/#{website.structure.administrators_path}" + end + + def target_for_authors + "/#{website.structure.authors_path}" + end + + def target_for_researchers + "/#{website.structure.researchers_path}" + end + + def target_for_teachers + "/#{website.structure.teachers_path}" + end + + def target_for_research_volumes + "/#{website.structure.research_volumes_path}" + end + + def target_for_research_volume + "/#{website.structure.research_volumes_path}#{about.path}" if about&.published && about&.published_at + end + + def target_for_research_articles + "/#{website.structure.research_articles_path}" + end + + def target_for_research_article + "/#{website.structure.research_articles_path}#{about.path}" if about&.published && about&.published_at + end +end diff --git a/app/views/admin/research/journal/articles/static.html.erb b/app/views/admin/research/journal/articles/static.html.erb index c889f93a8b1d729f37b2c0f999cae5f38b4dbab0..9388ad4911a90d2c3f0a3eea0cf4db7609a0a412 100644 --- a/app/views/admin/research/journal/articles/static.html.erb +++ b/app/views/admin/research/journal/articles/static.html.erb @@ -1,5 +1,6 @@ --- title: "<%= @article.title %>" +slug: "<%= @article.slug %>" description: > <%= prepare_text_for_static @article.abstract %> <% if @article.volume && @article.volume.path %>