diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb index d755ae142070e7b7e10ccf33a1dc57e725f5f235..c3e9a0608e1970216cd4292ff9891b91b6d45f21 100644 --- a/app/controllers/admin/communication/website/categories_controller.rb +++ b/app/controllers/admin/communication/website/categories_controller.rb @@ -90,7 +90,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication def category_params params.require(:communication_website_category) .permit( - :website_id, :name, :description, :slug, :parent_id, + :website_id, :name, :description, :text, :slug, :parent_id, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt) .merge(university_id: current_university.id) end diff --git a/app/controllers/admin/communication/website/index_pages_controller.rb b/app/controllers/admin/communication/website/index_pages_controller.rb index 8395ed8d9e13f5d2669ca03290e4a6eaa336967f..3d4bd80fdd16ac03fb0437654edbfa89c92890ef 100644 --- a/app/controllers/admin/communication/website/index_pages_controller.rb +++ b/app/controllers/admin/communication/website/index_pages_controller.rb @@ -5,11 +5,11 @@ class Admin::Communication::Website::IndexPagesController < Admin::Communication def index breadcrumb @kinds = Communication::Website::IndexPage.kinds_global - if @website.about_school? + # if @website.about_school? @kinds += Communication::Website::IndexPage.kinds_school - elsif @website.about_journal? + # elsif @website.about_journal? @kinds += Communication::Website::IndexPage.kinds_journal - end + # end end def edit diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 4bf4541b3d1d91ee381eb469fa0a36d857c75015..7440eaedf4859bba19f61fdd0be3b97867ee8717 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -87,7 +87,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def page_params params.require(:communication_website_page) .permit(:communication_website_id, :title, :breadcrumb_title, - :description, :header_text, :text, :about_type, :about_id, :slug, :published, + :description, :description_short, :header_text, :text, :about_type, :about_id, :slug, :published, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :parent_id, :related_category_id) .merge(university_id: current_university.id) diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index 7574a6220fff395b7f9fbd51816b7f4b0f312031..95bddee72ff187923f2de4cb9e45277b3563da8e 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -57,7 +57,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def post_params params.require(:communication_website_post) .permit( - :university_id, :website_id, :title, :description, :text, + :university_id, :website_id, :title, :description, :description_short, :text, :published, :published_at, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :slug, :pinned, :author_id, category_ids: [] diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index f235303488e854edb39273990f23fab9251a1208..a3ec423b645f1a54f47e99c445f96fdaf9318581 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -28,11 +28,13 @@ class Communication::Website < ApplicationRecord include WithUniversity include WithAbouts include WithConfigs + include WithDependencies include WithGit include WithGitRepository include WithImport include WithIndexPages include WithMenuItems + include WithProgramCategories scope :ordered, -> { order(:name) } @@ -49,45 +51,31 @@ class Communication::Website < ApplicationRecord "data/website.yml" end - def blocks - Communication::Block.where(about_type: 'Communication::Website::Page', about_id: pages) - end - def git_dependencies(website) - dependencies = ( - [self, config_permalinks, config_base_url] + - pages + pages.map(&:active_storage_blobs).flatten + - posts + posts.map(&:active_storage_blobs).flatten + - [index_for(:home)] + index_for(:home).active_storage_blobs + - [index_for(:communication_posts)] + index_for(:communication_posts).active_storage_blobs + - [index_for(:persons)] + index_for(:persons).active_storage_blobs + - [index_for(:authors)] + index_for(:authors).active_storage_blobs + - people_with_facets + people.map(&:active_storage_blobs).flatten + - categories + menus + [about] - ) - - if about.is_a? Education::School - dependencies << index_for(:education_programs) - dependencies += index_for(:education_programs).active_storage_blobs - dependencies += about.programs - dependencies += about.programs.map(&:active_storage_blobs).flatten - dependencies << index_for(:administrators) - dependencies += index_for(:administrators).active_storage_blobs - dependencies << index_for(:teachers) - dependencies += index_for(:teachers).active_storage_blobs - elsif about.is_a? Research::Journal - dependencies << index_for(:research_volumes) - dependencies += index_for(:research_volumes).active_storage_blobs - dependencies += about.volumes - dependencies += about.volumes.map(&:active_storage_blobs).flatten - dependencies << index_for(:research_articles) - dependencies += index_for(:research_articles).active_storage_blobs - dependencies += about.articles - dependencies += about.articles.map(&:active_storage_blobs).flatten - dependencies << index_for(:researchers) - dependencies += index_for(:researchers).active_storage_blobs - end - + dependencies = [self, config_permalinks, config_base_url] + menus + dependencies += pages + pages.map(&:active_storage_blobs).flatten + dependencies += posts + posts.map(&:active_storage_blobs).flatten if has_communication_posts? + dependencies += people_with_facets + people.map(&:active_storage_blobs).flatten if has_people? + dependencies += [categories] if has_communication_categories? + dependencies += about.git_dependencies(website) + dependencies += git_index_pages_dependencies(website) dependencies end + + def git_index_pages_dependencies(website) + # TMP: add index_pages + index_pages_dependencies = [index_for(:home)] + index_for(:home).active_storage_blobs + index_pages_dependencies += [index_for(:communication_posts)] + index_for(:communication_posts).active_storage_blobs if has_communication_posts? + index_pages_dependencies += [index_for(:education_programs)] + index_for(:education_programs).active_storage_blobs if has_education_programs? + index_pages_dependencies += [index_for(:persons)] + index_for(:persons).active_storage_blobs if has_people? + index_pages_dependencies += [index_for(:authors)] + index_for(:authors).active_storage_blobs if has_authors? + index_pages_dependencies += [index_for(:administrators)] + index_for(:administrators).active_storage_blobs if has_administrators? + index_pages_dependencies += [index_for(:teachers)] + index_for(:teachers).active_storage_blobs if has_teachers? + index_pages_dependencies += [index_for(:research_volumes)] + index_for(:research_volumes).active_storage_blobs if has_research_volumes? + index_pages_dependencies += [index_for(:research_articles)] + index_for(:research_articles).active_storage_blobs if has_research_articles? + index_pages_dependencies += [index_for(:researchers)] + index_for(:researchers).active_storage_blobs if has_researchers? + index_pages_dependencies + # END TMP + end + end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 82f9ca9b8e984a18dca8619645fc7a48fb8c89c5..d4a32e3922d7af4d40e265f56439bf078034a8cf 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -11,6 +11,7 @@ # path :string # position :integer # slug :string +# text :text # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed diff --git a/app/models/communication/website/index_page/education_programs.rb b/app/models/communication/website/index_page/education_programs.rb index 99230b5f79d6cce4dfff4e5c8e7c75d0360fd5e2..95dc357e043a235d654d22c7b81a0ce74f048a1a 100644 --- a/app/models/communication/website/index_page/education_programs.rb +++ b/app/models/communication/website/index_page/education_programs.rb @@ -40,7 +40,7 @@ class Communication::Website::IndexPage::EducationPrograms < Communication::Webs end def git_dependencies(website) - [self] + active_storage_blobs + website.about.programs + [self] + active_storage_blobs + website.education_programs end end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index c91a8b7c0e08f6cfc8a3aaf5d517c73135263106..33d813f4ea43fa6b78c67c9cb7633998e7a7ba9e 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -4,12 +4,10 @@ # # id :uuid not null, primary key # about_type :string indexed => [about_id] -# breadcrumb_title :string # description :text +# description_short :text # featured_image_alt :string # github_path :text -# header_text :text -# kind :integer # old_text :text # path :text # position :integer default(0), not null diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 0a2250b06d975d66a7e28c2707aa6cb048ed4e48..72910c15fe2c6f169dfe8886c1f850e1e3e1940d 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -4,6 +4,7 @@ # # id :uuid not null, primary key # description :text +# description_short :text # featured_image_alt :string # github_path :text # old_text :text diff --git a/app/models/communication/website/with_abouts.rb b/app/models/communication/website/with_abouts.rb index 83916b81544fc65b6e2c256bc20e4053ddcff20e..b2871b99cd7a9da0c5f10801288079bfd6f79e97 100644 --- a/app/models/communication/website/with_abouts.rb +++ b/app/models/communication/website/with_abouts.rb @@ -6,26 +6,6 @@ module Communication::Website::WithAbouts polymorphic: true, optional: true - has_many :pages, - foreign_key: :communication_website_id, - dependent: :destroy - - has_many :menus, - class_name: 'Communication::Website::Menu', - foreign_key: :communication_website_id, - dependent: :destroy - - has_many :posts, - foreign_key: :communication_website_id, - dependent: :destroy - - has_many :authors, -> { distinct }, through: :posts - - has_many :categories, - class_name: 'Communication::Website::Category', - foreign_key: :communication_website_id, - dependent: :destroy - def self.about_types [ nil, @@ -35,90 +15,5 @@ module Communication::Website::WithAbouts ] end - after_save_commit :set_programs_categories!, if: -> (website) { website.about_school? } - end - - def about_school? - about_type == 'Education::School' - end - - def about_journal? - about_type == 'Research::Journal' - end - - def about_laboratory? - about_type == 'Research::Laboratory' - end - - def programs - about_school? ? about.programs : Education::Program.none - end - - def research_volumes - about_journal? ? about.volumes : Research::Journal::Volume.none - end - - def research_articles - about_journal? ? about.articles : Research::Journal::Article.none - end - - def people - @people ||= begin - people = authors - if about_school? - people += about.university_people_through_role_involvements - people += about.university_people_through_program_involvements - people += about.university_people_through_program_role_involvements - elsif about_journal? - people += about.people - end - people.uniq.compact - end - end - - def people_with_facets - @people_with_facets ||= begin - people = authors + authors.compact.map(&:author) - if about_school? - people += about.university_people_through_role_involvements - people += about.university_people_through_role_involvements.map(&:administrator) - people += about.university_people_through_program_involvements - people += about.university_people_through_program_involvements.map(&:teacher) - people += about.university_people_through_program_role_involvements - people += about.university_people_through_program_role_involvements.map(&:administrator) - elsif about_journal? - people += about.people - people += about.people.map(&:researcher) - end - people.uniq.compact - end - end - - def set_programs_categories! - programs_root_category = categories.where(is_programs_root: true).first_or_create( - name: 'Offre de formation', - slug: 'offre-de-formation', - is_programs_root: true, - university_id: university.id - ) - set_programs_categories_at_level! programs_root_category, about.programs.root.ordered - rescue - end - - protected - - def set_programs_categories_at_level!(parent_category, programs) - programs.map.with_index do |program, index| - category = categories.where(program_id: program.id).first_or_initialize( - name: program.name, - slug: program.name.parameterize, - university_id: university.id - ) - category.parent = parent_category - category.position = index + 1 - category.save - children = about.programs.where(parent_id: program.id).ordered - set_programs_categories_at_level! category, children - end end end diff --git a/app/models/communication/website/with_dependencies.rb b/app/models/communication/website/with_dependencies.rb new file mode 100644 index 0000000000000000000000000000000000000000..193fb1dd63e4bafde4880e76e7e3db8ff5b1c2aa --- /dev/null +++ b/app/models/communication/website/with_dependencies.rb @@ -0,0 +1,118 @@ +module Communication::Website::WithDependencies + extend ActiveSupport::Concern + + included do + + has_many :pages, + foreign_key: :communication_website_id, + dependent: :destroy + + has_many :menus, + class_name: 'Communication::Website::Menu', + foreign_key: :communication_website_id, + dependent: :destroy + + has_many :posts, + foreign_key: :communication_website_id, + dependent: :destroy + + has_many :authors, -> { distinct }, through: :posts + + has_many :categories, + class_name: 'Communication::Website::Category', + foreign_key: :communication_website_id, + dependent: :destroy + + end + + def blocks + Communication::Block.where(about_type: 'Communication::Website::Page', about_id: pages) + end + + def education_programs + has_education_programs? ? about.published_programs : Education::Program.none + end + + def research_volumes + has_research_volumes? ? about.published_volumes : Research::Journal::Volume.none + end + + def research_articles + has_research_articles? ? about.published_articles : Research::Journal::Article.none + end + + def administrators + about.administrators + end + + def researchers + about.researchers + end + + def teachers + about.teachers + end + + def people + @people ||= begin + people = [] + people += authors if has_authors? + people += teachers if has_teachers? + people += administrators if has_administrators? + people += researchers if has_researchers? + people.uniq.compact + end + end + + def people_with_facets + @people_with_facets ||= begin + people = [] + people += authors + authors.compact.map(&:author) if has_authors? + people += teachers + teachers.map(&:teacher) if has_teachers? + people += administrators + administrators.map(&:administrator) if has_administrators? + people += researchers + researchers.map(&:researcher) if has_researchers? + people.uniq.compact + end + end + + def has_communication_posts? + posts.published.any? + end + + def has_communication_categories? + categories.any? + end + + def has_authors? + authors.compact.any? + end + + def has_people? + has_authors? || has_administrators? || has_researchers? || has_teachers? + end + + def has_administrators? + about && about.has_administrators? + end + + def has_researchers? + about && about.has_researchers? + end + + def has_teachers? + about && about.has_teachers? + end + + def has_education_programs? + about && about.has_education_programs? + end + + def has_research_articles? + about && about.has_research_articles? + end + + def has_research_volumes? + about && about.has_research_volumes? + end + +end diff --git a/app/models/communication/website/with_menu_items.rb b/app/models/communication/website/with_menu_items.rb index b1ee2368be47442a94ab3170c68e083f98fb9e8e..6aefcc20c775a0187eaa31be77acaf452d3d2105 100644 --- a/app/models/communication/website/with_menu_items.rb +++ b/app/models/communication/website/with_menu_items.rb @@ -21,58 +21,58 @@ module Communication::Website::WithMenuItems end def menu_item_kind_programs? - about_school? && programs.any? + has_education_programs? end def menu_item_kind_program? - about_school? && programs.any? + has_education_programs? end def menu_item_kind_news? - posts.published.any? + has_communication_posts? end def menu_item_kind_news_category? - categories.any? + has_communication_categories? end def menu_item_kind_news_article? - menu_item_kind_news? + has_communication_posts? end def menu_item_kind_staff? - true + has_people? end def menu_item_kind_administrators? - people.any? + has_administrators? end def menu_item_kind_authors? - authors.compact.any? + has_authors? end def menu_item_kind_researchers? - about_journal? && about.people.any? + has_researchers? end def menu_item_kind_teachers? - about_school? && about.university_people_through_program_involvements.any? + has_teachers? end def menu_item_kind_research_volumes? - research_volumes.published.any? + has_research_volumes? end def menu_item_kind_research_volume? - menu_item_kind_research_volumes? + has_research_volumes? end def menu_item_kind_research_articles? - research_articles.published.any? + has_research_articles? end def menu_item_kind_research_article? - menu_item_kind_research_articles? + has_research_articles? end end diff --git a/app/models/communication/website/with_program_categories.rb b/app/models/communication/website/with_program_categories.rb new file mode 100644 index 0000000000000000000000000000000000000000..109e5096504ad858ea9f248efba9fd6c2f25a2a3 --- /dev/null +++ b/app/models/communication/website/with_program_categories.rb @@ -0,0 +1,35 @@ +module Communication::Website::WithProgramCategories + extend ActiveSupport::Concern + + included do + after_save_commit :set_programs_categories!, if: -> (website) { website.has_education_programs? } + end + + def set_programs_categories! + programs_root_category = categories.where(is_programs_root: true).first_or_create( + name: 'Offre de formation', + slug: 'offre-de-formation', + is_programs_root: true, + university_id: university.id + ) + set_programs_categories_at_level! programs_root_category, education_programs.root.ordered + rescue + end + + protected + + def set_programs_categories_at_level!(parent_category, programs) + programs.map.with_index do |program, index| + category = categories.where(program_id: program.id).first_or_initialize( + name: program.name, + slug: program.name.parameterize, + university_id: university.id + ) + category.parent = parent_category + category.position = index + 1 + category.save + children = education_programs.where(parent_id: program.id).ordered + set_programs_categories_at_level! category, children + end + end +end \ No newline at end of file diff --git a/app/models/concerns/aboutable.rb b/app/models/concerns/aboutable.rb new file mode 100644 index 0000000000000000000000000000000000000000..c8347a0809fbaa372f4623b09d1d1f7963e8095d --- /dev/null +++ b/app/models/concerns/aboutable.rb @@ -0,0 +1,27 @@ +module Aboutable + extend ActiveSupport::Concern + + def has_administrators? + raise NotImplementedError + end + + def has_researchers? + raise NotImplementedError + end + + def has_teachers? + raise NotImplementedError + end + + def has_education_programs? + raise NotImplementedError + end + + def has_research_articles? + raise NotImplementedError + end + + def has_research_volumes? + raise NotImplementedError + end +end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 9f1f98784c01be3139ad344f4c3f7b20bc94019b..6781044770a9c692b154b3a7d666871120c7883c 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -25,12 +25,19 @@ # class Education::School < ApplicationRecord include WithGit + include Aboutable has_and_belongs_to_many :programs, class_name: 'Education::Program', join_table: 'education_programs_schools', foreign_key: 'education_school_id', association_foreign_key: 'education_program_id' + has_and_belongs_to_many :published_programs, + -> { published }, + class_name: 'Education::Program', + join_table: 'education_programs_schools', + foreign_key: 'education_school_id', + association_foreign_key: 'education_program_id' belongs_to :university has_many :websites, class_name: 'Communication::Website', @@ -52,6 +59,12 @@ class Education::School < ApplicationRecord has_many :university_people_through_program_role_involvements, through: :programs, source: :university_people_through_role_involvements + has_many :university_people_through_published_program_involvements, + through: :published_programs, + source: :university_people_through_involvements + has_many :university_people_through_published_program_role_involvements, + through: :published_programs, + source: :university_people_through_role_involvements validates :name, :address, :city, :zipcode, :country, presence: true @@ -61,14 +74,63 @@ class Education::School < ApplicationRecord "#{name}" end + def researchers + people_ids = ( + university_people_through_published_program_involvements + + university_people_through_role_involvements + + university_people_through_published_program_role_involvements + ).pluck(:id) + university.people.where(id: people_ids, is_researcher: true) + end + + def teachers + people_ids = university_people_through_published_program_involvements.pluck(:id) + university.people.where(id: people_ids, is_teacher: true) + end + + def administrators + people_ids = ( + university_people_through_role_involvements + + university_people_through_published_program_role_involvements + ).pluck(:id) + university.people.where(id: people_ids, is_administration: true) + end + def git_path(website) "data/school.yml" end def git_dependencies(website) - [self] + - university_people_through_role_involvements + - university_people_through_role_involvements.map(&:administrator) + - university_people_through_role_involvements.map(&:active_storage_blobs).flatten + dependencies = [self] + dependencies += published_programs + published_programs.map(&:active_storage_blobs).flatten if has_education_programs? + dependencies += teachers + teachers.map(&:teacher) + teachers.map(&:active_storage_blobs).flatten if has_teachers? + dependencies += researchers + researchers.map(&:researcher) + researchers.map(&:active_storage_blobs).flatten if has_researchers? + dependencies += administrators + administrators.map(&:administrator) + administrators.map(&:active_storage_blobs).flatten if has_administrators? + dependencies + end + + def has_administrators? + university_people_through_role_involvements.any? || + university_people_through_program_role_involvements.any? + end + + def has_researchers? + researchers.any? + end + + def has_teachers? + teachers.any? + end + + def has_education_programs? + published_programs.any? + end + + def has_research_articles? + false + end + + def has_research_volumes? + false end end diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 62c75abdd15fd6a9a73965ec6492230ecd32334d..f888d2538df4fe043fb2ea00f04f34bbbeb95b66 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -21,13 +21,17 @@ # fk_rails_96097d5f10 (university_id => universities.id) # class Research::Journal < ApplicationRecord + include Aboutable include WithUniversity include WithGit has_many :websites, class_name: 'Communication::Website', as: :about, dependent: :nullify has_many :volumes, foreign_key: :research_journal_id, dependent: :destroy + has_many :published_volumes, -> { published }, foreign_key: :research_journal_id, dependent: :destroy has_many :articles, foreign_key: :research_journal_id, dependent: :destroy + has_many :published_articles, -> { published }, foreign_key: :research_journal_id, dependent: :destroy has_many :people, -> { distinct }, through: :articles + has_many :people_through_published_articles, -> { distinct }, through: :published_articles scope :ordered, -> { order(:title) } @@ -35,15 +39,47 @@ class Research::Journal < ApplicationRecord "#{title}" end + def researchers + university.people.where(id: people_through_published_articles.pluck(:id), is_researcher: true) + end + def git_path(website) "data/journal.yml" end def git_dependencies(website) - [self] + articles + volumes + people + people.map(&:researcher) + people.map(&:active_storage_blobs).flatten + dependencies = [self] + dependencies += published_articles + published_articles.map(&:active_storage_blobs).flatten if has_research_articles? + dependencies += published_volumes + published_volumes.map(&:active_storage_blobs).flatten if has_research_volumes? + dependencies += researchers + researchers.map(&:researcher) + researchers.map(&:active_storage_blobs).flatten if has_researchers? + dependencies end def git_destroy_dependencies(website) [self] + articles + volumes end + + def has_administrators? + false + end + + def has_researchers? + researchers.any? + end + + def has_teachers? + false + end + + def has_education_programs? + false + end + + def has_research_articles? + published_articles.published.any? + end + + def has_research_volumes? + published_volumes.published.any? + end end diff --git a/app/models/research/laboratory.rb b/app/models/research/laboratory.rb index 8f64eaed5d33baeb0d39a4b50d48606f0ad181d1..6ec50a9bafb0fc32e3722ab5929faee431181747 100644 --- a/app/models/research/laboratory.rb +++ b/app/models/research/laboratory.rb @@ -22,6 +22,7 @@ # class Research::Laboratory < ApplicationRecord include WithGit + include Aboutable belongs_to :university has_many :websites, @@ -46,4 +47,29 @@ class Research::Laboratory < ApplicationRecord def git_path(website) "data/laboratory.yml" end + + def has_administrators? + false + end + + def has_researchers? + # TODO: Ajouter les researchers quand ils existeront + false + end + + def has_teachers? + false + end + + def has_education_programs? + false + end + + def has_research_articles? + false + end + + def has_research_volumes? + false + end end diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index 5bae307bb23600928b999ab1b3966ac70dc63045..f5fda080ad57e31d179660161ba2567f1bf4b526 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -45,16 +45,6 @@ class University::Person::Administrator < University::Person end def for_website?(website) - is_administration && website.about_school? && ( - website.about - .university_people_through_role_involvements - .find_by(id: id) - .present? || - website.programs - .published - .joins(:involvements_through_roles) - .where(university_person_involvements: { person_id: id }) - .any? - ) + is_administration && website.has_administrators? && website.administrators.pluck(:id).include?(self.id) end end diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb index d2e538f948873d4fb2fbeabe1d316c5ca3a04082..67dda6a6e289d65603bd5184ad345b06e76283db 100644 --- a/app/models/university/person/author.rb +++ b/app/models/university/person/author.rb @@ -45,8 +45,6 @@ class University::Person::Author < University::Person end def for_website?(website) - communication_website_posts.published - .where(communication_website_id: website&.id) - .any? + website.has_authors? && website.authors.pluck(:id).include?(self.id) end end diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb index 5302c9ec61be4b5d805c1784d33a22985ab05c8d..8fffe668f473cf48fa7237a2d68500b78c507ec1 100644 --- a/app/models/university/person/researcher.rb +++ b/app/models/university/person/researcher.rb @@ -45,9 +45,6 @@ class University::Person::Researcher < University::Person end def for_website?(website) - is_researcher && website.about_journal? && website.research_articles - .joins(:people) - .where(university_people: { id: id }) - .any? + is_researcher && website.has_researchers? && website.researchers.pluck(:id).include?(self.id) end end diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index c954e1e89dbdc49986125a48c4b51b1c47489a9d..df1e88803e668e76624ea44562d02825c1e7ccad 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -45,10 +45,6 @@ class University::Person::Teacher < University::Person end def for_website?(website) - is_teacher && website.about_school? && website.programs - .published - .joins(:university_person_involvements) - .where(university_person_involvements: { person_id: id }) - .any? + is_teacher && website.has_teachers? && website.teachers.pluck(:id).include?(self.id) end end diff --git a/app/views/admin/communication/website/categories/_form.html.erb b/app/views/admin/communication/website/categories/_form.html.erb index c0c122f02dbd918b662d6556f3bf1ba7944ec2e0..6fa1142149b0703e0855e2d88ed0451c2912b511 100644 --- a/app/views/admin/communication/website/categories/_form.html.erb +++ b/app/views/admin/communication/website/categories/_form.html.erb @@ -8,6 +8,7 @@ <div class="card-body"> <%= f.input :name %> <%= f.input :description %> + <%= f.input :text, as: :summernote %> </div> </div> </div> diff --git a/app/views/admin/communication/website/categories/show.html.erb b/app/views/admin/communication/website/categories/show.html.erb index 6b2cd098034cb6d3ee3716d4fb66d4d67839c582..a5b6bf332df3c6646881154162e30307ea20b801 100644 --- a/app/views/admin/communication/website/categories/show.html.erb +++ b/app/views/admin/communication/website/categories/show.html.erb @@ -9,7 +9,9 @@ </div> <div class="card-body"> <h3 class="h5"><%= Communication::Website::Category.human_attribute_name('description') %></h3> - <%= sanitize @category.description %> + <p><%= sanitize @category.description %></p> + <h3 class="h5"><%= Communication::Website::Category.human_attribute_name('text') %></h3> + <%= sanitize @category.text %> </div> </div> </div> diff --git a/app/views/admin/communication/website/categories/static.html.erb b/app/views/admin/communication/website/categories/static.html.erb index 500d4021ef6426c6b36bf579f3c623fdae768200..ef0142538858efa7bcea609f9d79077a9f892135 100644 --- a/app/views/admin/communication/website/categories/static.html.erb +++ b/app/views/admin/communication/website/categories/static.html.erb @@ -6,5 +6,7 @@ position: <%= @about.position %> image: "<%= @about.best_featured_image.blob.id %>" image_alt: "<%= @about.featured_image_alt %>" <% end %> +description: > + <%= prepare_text_for_static @about.description %> --- -<%= prepare_html_for_static @about.description, @about.university %> +<%= prepare_html_for_static @about.text, @about.university %> diff --git a/app/views/admin/communication/website/configs/permalinks/static.html.erb b/app/views/admin/communication/website/configs/permalinks/static.html.erb index 8a4a34596645d1c539a9aa48f30a3bbc2a582ed7..bd2143afd03e6b9edf63bc81ba4497ed4e1b08d2 100644 --- a/app/views/admin/communication/website/configs/permalinks/static.html.erb +++ b/app/views/admin/communication/website/configs/permalinks/static.html.erb @@ -1,12 +1,22 @@ +<% if @website.has_communication_posts? %> posts: /<%= @website.index_for(:communication_posts).path %>/:year/:month/:day/:slug/ +<% end %> +<% if @website.has_communication_categories? %> categories: /<%= @website.index_for(:communication_posts).path %>/:slug/ +<% end %> +<% if @website.has_people? %> persons: /<%= @website.index_for(:persons).path %>/:slug/ +<% end %> +<% if @website.has_authors? %> authors: /<%= @website.index_for(:persons).path %>/:slug/<%= @website.index_for(:communication_posts).path %>/ +<% end %> <%# ces paths complémentaires sont nécessairesà Hugo mais on ne les utilise pas %> -<% if @website.about_school? %> +<% if @website.has_administrators? %> administrators: /<%= @website.index_for(:persons).path %>/:slug/roles/ +<% end %> +<% if @website.has_teachers? %> teachers: /<%= @website.index_for(:persons).path %>/:slug/programs/ <% end %> -<% if @website.about_journal? %> +<% if @website.has_researchers? %> researchers: /<%= @website.index_for(:persons).path %>/:slug/articles/ <% end %> diff --git a/app/views/admin/communication/website/menu/items/_form.html.erb b/app/views/admin/communication/website/menu/items/_form.html.erb index 7c72ce057fad651bf3ad45468fa288da2c941f88..fa6d4d31b61f0661fe3a20385060c7ba2bdfd942 100644 --- a/app/views/admin/communication/website/menu/items/_form.html.erb +++ b/app/views/admin/communication/website/menu/items/_form.html.erb @@ -1,43 +1,15 @@ <%= simple_form_for item, url: item.persisted? ? [:admin, item, { menu_id: @menu.id }] : admin_communication_website_menu_items_path(@menu) do |f| %> - <div class="row"> - <div class="col-md-8"> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('content') %></h5> - </div> - <div class="card-body"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('content') %></h5> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-lg-6"> <%= f.input :title %> - <%= f.input :kind, - as: :hidden, - input_html: { - data: { - url: kind_switch_admin_communication_website_menu_items_path - } - } %> - <div class="mb-3"> - <label class="form-label required"> - <%= Communication::Website::Menu::Item.human_attribute_name('kind') %> - <abbr title="required">*</abbr> - </label> - <div class="row"> - <% @website.menu_item_kinds.keys.each do |kind| %> - <div class="col-6 col-lg-4 col-xl-3"> - <div class="card kind" data-kind="<%= kind %>"> - <div class="card-body"> - <p class="text-end mb-0"> - <i class="<%= icon_for "communication.website.menu.item.kind.#{kind}" %> fa-2x"></i><br> - </p> - <p class="mb-0"> - <%= t "enums.communication.website.menu.item.kind.#{kind}" %> - </p> - <a class="stretched-link"></a> - </div> - </div> - </div> - <% end %> - </div> - </div> + </div> + <div class="col-lg-6"> <div data-kind-if="url"> <%= f.input :url, as: :string %> </div> @@ -47,7 +19,7 @@ if item.kind_page? about_collection = collection_tree(@website.pages) elsif item.kind_program? - about_collection = collection_tree(@website.programs) + about_collection = collection_tree(@website.education_programs) elsif item.kind_news_category? about_collection = collection_tree(@website.categories) elsif item.kind_news_article? @@ -61,26 +33,43 @@ about_collection = [] end %> - <%= f.input :about_type, as: :hidden, input_html: { class: 'js-about-type' } %> <%= f.association :about, collection: about_collection, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] }, input_html: { class: 'js-about-id' } %> + <%= f.input :about_type, as: :hidden, input_html: { class: 'js-about-type' } %> </div> </div> </div> - </div> - <div class="col-md-4"> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('metadata') %></h5> - </div> - <div class="card-body"> - <%= f.association :parent, - collection: item.list_of_other_items, - label_method: -> (p) { sanitize p[:label] }, - value_method: -> (p) { p[:id] } %> + <%= f.input :kind, + as: :hidden, + input_html: { + data: { + url: kind_switch_admin_communication_website_menu_items_path + } + } %> + <div> + <label class="form-label required"> + <%= Communication::Website::Menu::Item.human_attribute_name('kind') %> + <abbr title="required">*</abbr> + </label> + <div class="row"> + <% @website.menu_item_kinds.keys.each do |kind| %> + <div class="col-6 col-lg-4 col-xl-3 col-xxl-2"> + <div class="card kind" data-kind="<%= kind %>"> + <div class="card-body"> + <p class="text-end mb-0"> + <i class="<%= icon_for "communication.website.menu.item.kind.#{kind}" %> fa-2x"></i><br> + </p> + <p class="mb-0"> + <%= t "enums.communication.website.menu.item.kind.#{kind}" %> + </p> + <a class="stretched-link"></a> + </div> + </div> + </div> + <% end %> </div> </div> </div> diff --git a/app/views/admin/communication/website/menu/items/kind_switch.js.erb b/app/views/admin/communication/website/menu/items/kind_switch.js.erb index 9632dd52f7a6eda8535dc27f91792aa0541377f2..7e9bfb420c09e7e814587b4562af3a4d1fed7545 100644 --- a/app/views/admin/communication/website/menu/items/kind_switch.js.erb +++ b/app/views/admin/communication/website/menu/items/kind_switch.js.erb @@ -23,7 +23,7 @@ function hideAbout() { <% elsif @kind == 'program' %> <% options = ['<option value="" label=" "></option>'] - collection_tree(@website.programs).each do |page| + collection_tree(@website.education_programs).each do |page| options << "<option value=\"#{page[:id]}\">#{page[:label]}</option>" end %> diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index d5023d588a8a4c63b6929f3cec130513fc8f495e..4f8d6ee580643e3f89cdc08d7fcc8fe22f708f89 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -9,6 +9,7 @@ <%= f.input :title %> <%= f.input :breadcrumb_title %> <%= f.input :description %> + <%= f.input :description_short %> <%= f.input :header_text, as: :summernote, input_html: { diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index bc281edc9eacddd5bafb3ec65cbb54651773ddd3..84b5af9324cba3c022bc6f6ec786ef13a7f97b54 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -10,6 +10,7 @@ </div> <div class="card-body"> <%= render 'admin/application/property/text', object: @page, property: :description %> + <%= render 'admin/application/property/text', object: @page, property: :description_short %> <%= render 'admin/application/property/text', object: @page, property: :text %> </div> </div> diff --git a/app/views/admin/communication/website/pages/static.html.erb b/app/views/admin/communication/website/pages/static.html.erb index 23c3d9aae117fc66c73ccb9fd4ed0f3553834ebc..ac51c4aa5fc7e8b70f42a8b1832b90e4271d7fd6 100644 --- a/app/views/admin/communication/website/pages/static.html.erb +++ b/app/views/admin/communication/website/pages/static.html.erb @@ -12,6 +12,8 @@ category: "<%= @about.related_category.path %>/" <% end %> description: > <%= prepare_text_for_static @about.description %> +description_short: > + <%= prepare_text_for_static @about.description_short %> <%= render 'admin/communication/blocks/static', about: @about %> --- <%= prepare_html_for_static @about.text, @about.university %> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index c82cdb4b22eecf8375735497c3deb1abaee4c3e8..9965c8536f358ceb37f6cf697cdc5d73b43806c3 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -8,6 +8,7 @@ <div class="card-body"> <%= f.input :title %> <%= f.input :description %> + <%= f.input :description_short %> <%= f.input :text, as: :summernote %> </div> </div> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 079d3548b840e3dae8348ed2a04fecfd51c47bf1..ba186de893e773502f618479fb0765eaae02e762 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -9,6 +9,7 @@ </div> <div class="card-body"> <%= render 'admin/application/property/text', object: @post, property: :description %> + <%= render 'admin/application/property/text', object: @post, property: :description_short %> <%= render 'admin/application/property/text', object: @post, property: :text %> <%= render 'admin/application/property/summernote_embeds', object: @post, property: :medias %> <p><%= prepare_text_for_static @post.description %></p> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index b54ff487ee62790ed87d108116179b8d1a1095bc..3beeb6eebd3899da3af1ecccd77ad25866aaa51e 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -57,6 +57,7 @@ en: communication/website/category: children: Children categories description: Description (SEO) + text: Text featured_image: Featured image featured_image_alt: Alt text name: Name @@ -89,6 +90,7 @@ en: related_category: Related category children: Children pages description: Description (SEO) + description_short: Short description featured_image: Featured image featured_image_alt: Alt text parent: Parent page @@ -102,6 +104,7 @@ en: category: Category categories: Categories description: Description (SEO) + description_short: Short description featured_image: Featured image featured_image_alt: Alt text pinned: Pinned? diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 4b69ce1b38f79f771572eb765d0f45a580772e17..de87b635780f15c89f858614129f950bb13ed1be 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -57,6 +57,7 @@ fr: communication/website/category: children: Catégories enfants description: Description (SEO) + text: Texte featured_image: Image à la une featured_image_alt: Texte alternatif name: Nom @@ -89,6 +90,7 @@ fr: breadcrumb_title: Nom affiché dans le fil d'ariane children: Pages enfants description: Description (SEO) + description_short: Description courte featured_image: Image à la une featured_image_alt: Texte alternatif header_text: Texte affiché dans le header @@ -104,6 +106,7 @@ fr: category: Catégorie categories: Catégories description: Description (SEO) + description_short: Description courte featured_image: Image à la une featured_image_alt: Texte alternatif pinned: Mis en avant ? diff --git a/db/migrate/20220401154318_add_description_short_to_page.rb b/db/migrate/20220401154318_add_description_short_to_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..b4c1efc11f613dcec360e2e426cad247b27ea264 --- /dev/null +++ b/db/migrate/20220401154318_add_description_short_to_page.rb @@ -0,0 +1,5 @@ +class AddDescriptionShortToPage < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_pages, :description_short, :text + end +end diff --git a/db/migrate/20220401180504_add_description_short_to_post.rb b/db/migrate/20220401180504_add_description_short_to_post.rb new file mode 100644 index 0000000000000000000000000000000000000000..e302f39b7ea1d0d111e0dfb175535c34064ffbc1 --- /dev/null +++ b/db/migrate/20220401180504_add_description_short_to_post.rb @@ -0,0 +1,5 @@ +class AddDescriptionShortToPost < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_posts, :description_short, :text + end +end diff --git a/db/migrate/20220404140813_add_description_to_category.rb b/db/migrate/20220404140813_add_description_to_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..f6e47636a1ace5fa004aece0bdee95dbb235de6d --- /dev/null +++ b/db/migrate/20220404140813_add_description_to_category.rb @@ -0,0 +1,5 @@ +class AddDescriptionToCategory < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_categories, :text, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 9f3654ae77d2de759df2f2cb65dd2bdb634011dc..e0da33f450ff4cadbf0746f09630000c20ec17e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_04_01_105007) do +ActiveRecord::Schema.define(version: 2022_04_04_140813) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -117,6 +117,7 @@ ActiveRecord::Schema.define(version: 2022_04_01_105007) do t.boolean "is_programs_root", default: false t.string "path" t.string "featured_image_alt" + t.text "text" t.index ["communication_website_id"], name: "idx_communication_website_post_cats_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_categories_on_parent_id" t.index ["program_id"], name: "index_communication_website_categories_on_program_id" @@ -318,9 +319,7 @@ ActiveRecord::Schema.define(version: 2022_04_01_105007) do t.uuid "related_category_id" t.string "featured_image_alt" t.text "text" - t.string "breadcrumb_title" - t.text "header_text" - t.integer "kind" + t.text "description_short" t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" @@ -344,6 +343,7 @@ ActiveRecord::Schema.define(version: 2022_04_01_105007) do t.boolean "pinned", default: false t.string "featured_image_alt" t.text "text" + t.text "description_short" t.index ["author_id"], name: "index_communication_website_posts_on_author_id" t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id" t.index ["university_id"], name: "index_communication_website_posts_on_university_id" diff --git a/docs/api/lheo/formation/cercle-1.md b/docs/api/lheo/formation/cercle-1.md index aa4f1c886e7b1619211d5f2988ab3de7c7be6a65..63162eceb0739bb0cf163beeb75dc91176fedfb0 100644 --- a/docs/api/lheo/formation/cercle-1.md +++ b/docs/api/lheo/formation/cercle-1.md @@ -114,4 +114,8 @@ http://lheo.gouv.fr/2.3/cercle1.html <contact-organisme>...</contact-organisme> <!-- [1,N] --> </organisme-formation-responsable> </formation> -``` \ No newline at end of file +``` + +## Codes (domaine de formation) + +https://www.data.gouv.fr/fr/datasets/repertoire-national-des-certifications-professionnelles-et-repertoire-specifique/ diff --git a/test/fixtures/communication/website/posts.yml b/test/fixtures/communication/website/posts.yml index aa5498d02486b6145071853198c254c3eaeca95c..0bc85c0f7d3a8fd095a209660748ede658f845ff 100644 --- a/test/fixtures/communication/website/posts.yml +++ b/test/fixtures/communication/website/posts.yml @@ -4,6 +4,7 @@ # # id :uuid not null, primary key # description :text +# description_short :text # featured_image_alt :string # github_path :text # old_text :text