diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index d4bb7ed163d2e42d696776656648b484f81be6e8..f4065516d9eed0ce612ae301c0a26ffede1ab3ae 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -91,7 +91,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We :communication_website_id, :title, :breadcrumb_title, :bodyclass, :description, :description_short, :header_text, :text, :slug, :published, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, - :parent_id, :related_category_id, :language_id + :parent_id, :language_id ) .merge(university_id: current_university.id) end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 0a8959ca643a67e935023e428b42be5b06c5141b..bdb083c2a5a3d96131a7e4348950e2e3fae3a2db 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -23,7 +23,6 @@ # communication_website_id :uuid not null, indexed # language_id :uuid indexed # parent_id :uuid indexed -# related_category_id :uuid indexed # university_id :uuid not null, indexed # # Indexes @@ -31,14 +30,12 @@ # index_communication_website_pages_on_communication_website_id (communication_website_id) # index_communication_website_pages_on_language_id (language_id) # index_communication_website_pages_on_parent_id (parent_id) -# index_communication_website_pages_on_related_category_id (related_category_id) # index_communication_website_pages_on_university_id (university_id) # # Foreign Keys # # fk_rails_1a42003f06 (parent_id => communication_website_pages.id) # fk_rails_280107c62b (communication_website_id => communication_websites.id) -# fk_rails_47b37cf8b2 (related_category_id => communication_website_categories.id) # fk_rails_d208d15a73 (university_id => universities.id) # @@ -58,9 +55,6 @@ class Communication::Website::Page < ApplicationRecord belongs_to :website, foreign_key: :communication_website_id - belongs_to :related_category, - class_name: 'Communication::Website::Category', - optional: true belongs_to :parent, class_name: 'Communication::Website::Page', optional: true diff --git a/app/models/education/cohort.rb b/app/models/education/cohort.rb index 11ac56052a85bb334ac2b6d433b2ae6e591193f1..fff2ec382e6c82e454bc387c07b2b21a8c207ed6 100644 --- a/app/models/education/cohort.rb +++ b/app/models/education/cohort.rb @@ -40,7 +40,6 @@ class Education::Cohort < ApplicationRecord validates_associated :academic_year, :program validates :year, presence: true - # before_validation :set_university_id, on: :create scope :ordered, -> { includes(:academic_year).order('education_academic_years.year DESC') @@ -58,9 +57,4 @@ class Education::Cohort < ApplicationRecord self.academic_year = Education::AcademicYear.where(university_id: university_id, year: val).first_or_create end - private - - # def set_university_id - # self.university_id = self.program.university_id - # end end diff --git a/app/models/education/program/with_alumni.rb b/app/models/education/program/with_alumni.rb index 475572935cce3f68fb1c79b283f528288c7156f8..5ec4ec189feef1b050135611246a74bf5741ad06 100644 --- a/app/models/education/program/with_alumni.rb +++ b/app/models/education/program/with_alumni.rb @@ -21,25 +21,25 @@ module Education::Program::WithAlumni source: :organization alias_attribute :university_person_alumni_organizations, :alumni_organizations - # TODO: Find a fix for wrong table name on WHERE clause + # Dénormalisation des alumni pour le faceted search + has_and_belongs_to_many :university_people, + class_name: 'University::Person', + foreign_key: 'education_program_id', + association_foreign_key: 'university_person_id' + + # NOTE: Find a fix for wrong table name on WHERE clause # SELECT "education_academic_years".* # FROM "education_academic_years" # INNER JOIN "education_cohorts" # ON "education_academic_years"."id" = "education_cohorts"."academic_year_id" # WHERE "cohorts"."program_id" = '<uuid>' # - # has_many :academic_years, -> { distinct }, + # has_many :academic_years, # class_name: 'Education::AcademicYear', - # through: :cohorts, - # source: :academic_year + # through: :education_cohorts, + # source: :education_academic_year # alias_attribute :education_academic_years, :academic_years - # Dénormalisation des alumni pour le faceted search - has_and_belongs_to_many :university_people, - class_name: 'University::Person', - foreign_key: 'education_program_id', - association_foreign_key: 'university_person_id' - def academic_years Education::AcademicYear.where(id: cohorts.pluck(:academic_year_id)) end diff --git a/app/models/education/school/with_alumni.rb b/app/models/education/school/with_alumni.rb index a234267c35ea0eeeca54642dafa75b2bdf73810a..d36438ec05756ae5e51969ffc9161f8b5fdc9fc1 100644 --- a/app/models/education/school/with_alumni.rb +++ b/app/models/education/school/with_alumni.rb @@ -19,14 +19,16 @@ module Education::School::WithAlumni source: :organization alias_attribute :university_person_alumni_organizations, :alumni_organizations - has_many :academic_years, -> { distinct }, - class_name: 'Education::AcademicYear', - through: :programs - alias_attribute :education_academic_years, :academic_years - has_many :cohorts, -> { distinct }, class_name: 'Education::Cohort', through: :programs alias_attribute :education_cohorts, :cohorts + + has_many :academic_years, -> { distinct }, + class_name: 'Education::AcademicYear', + through: :cohorts, + source: :academic_year + alias_attribute :education_academic_years, :academic_years + end end diff --git a/app/views/admin/communication/blocks/templates/posts/_edit.html.erb b/app/views/admin/communication/blocks/templates/posts/_edit.html.erb index fc343bc2c34e1cadd52935c0af4062365ee271d2..10ca5a411f43b85195d18e23ff85af77871d0c98 100644 --- a/app/views/admin/communication/blocks/templates/posts/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_edit.html.erb @@ -1,3 +1,5 @@ +<% categories = collection_tree(@block.about&.website.categories) %> + <div class="row mb-1"> <div class="col-md-6"> @@ -31,8 +33,8 @@ <select id="category_id" class="form-select select" v-model="data.category_id"> - <% @block.about&.website.categories.ordered.each_with_index do |category, index| %> - <option value="<%= category.id %>"><%= category %></option> + <% categories.each_with_index do |category, index| %> + <option value="<%= category[:id] %>"><%= category[:label].html_safe %></option> <% end %> </select> </div> diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb index f2c2e2064d48a4c30dd882dee5e062f3024306ca..00d096e51246a0b8869a5c9227360a2c4327b5e4 100644 --- a/app/views/admin/communication/websites/pages/_form.html.erb +++ b/app/views/admin/communication/websites/pages/_form.html.erb @@ -14,10 +14,6 @@ <%= f.input :description_short, input_html: { value: page.description_short&.gsub('&', '&') } %> <%= f.input :header_text, as: :string %> <%= f.input :text, as: :summernote if page.text&.to_plain_text.present? %> - <%= f.association :related_category, - collection: collection_tree(@website.categories), - label_method: ->(p) { sanitize p[:label] }, - value_method: ->(p) { p[:id] } if @website.categories.any? && page.is_regular_page? %> </div> </div> <div class="card"> diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index c8f5773399a9b98cad09e4fec5cc5c75e7cb8395..6241359b1420110801295f4bd3e022a2c6f063e0 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -71,15 +71,6 @@ </p> <% end %> - <% if @page.related_category %> - <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('related_category') %></h3> - <p><%= link_to_if can?(:read, @page.related_category), - @page.related_category, - admin_communication_website_category_path( - website_id: @website.id, - id: @page.related_category.id - ) %></p> - <% end %> <% if @page.children.any? %> <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('children') %></h3> <ul class="list-unstyled mb-0"> diff --git a/app/views/admin/communication/websites/pages/static.html.erb b/app/views/admin/communication/websites/pages/static.html.erb index 710adbec98809df944bb1167c0338bbfc653c45f..8812dd9cf9187dad7c1f1988842661a05b0d41ca 100644 --- a/app/views/admin/communication/websites/pages/static.html.erb +++ b/app/views/admin/communication/websites/pages/static.html.erb @@ -12,15 +12,12 @@ children: - <%= child.path %> <% end %> <% end %> -<% if @about.related_category %> -category: "<%= @about.related_category.path %>" -<% end %> description: > <%= prepare_text_for_static @about.description %> description_short: > <%= prepare_text_for_static @about.description_short %> header_text: >- - <%= @about.header_text %> + <%= prepare_html_for_static @about.header_text, @website.university %> legacy_text: > <%= prepare_html_for_static @about.text, @about.university %> <%= render 'admin/communication/blocks/static', about: @about %> diff --git a/db/migrate/20220519100506_remove_pages_related_category_id.rb b/db/migrate/20220519100506_remove_pages_related_category_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..c23410315056f374b4af40bf7245475ab6ca9746 --- /dev/null +++ b/db/migrate/20220519100506_remove_pages_related_category_id.rb @@ -0,0 +1,5 @@ +class RemovePagesRelatedCategoryId < ActiveRecord::Migration[6.1] + def change + remove_column :communication_website_pages, :related_category_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 931135610066d1d6eea271bcebf5a84074972d96..be781469c4836c52797c1bfb4adfbe20732871e4 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_05_16_095044) do +ActiveRecord::Schema.define(version: 2022_05_19_100506) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -300,7 +300,6 @@ ActiveRecord::Schema.define(version: 2022_05_16_095044) do t.datetime "updated_at", precision: 6, null: false t.boolean "published", default: false t.text "github_path" - t.uuid "related_category_id" t.string "featured_image_alt" t.text "text" t.text "description_short" @@ -313,7 +312,6 @@ ActiveRecord::Schema.define(version: 2022_05_16_095044) do t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_pages_on_language_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" - t.index ["related_category_id"], name: "index_communication_website_pages_on_related_category_id" t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end @@ -828,7 +826,6 @@ ActiveRecord::Schema.define(version: 2022_05_16_095044) do add_foreign_key "communication_website_menu_items", "universities" add_foreign_key "communication_website_menus", "communication_websites" add_foreign_key "communication_website_menus", "universities" - add_foreign_key "communication_website_pages", "communication_website_categories", column: "related_category_id" add_foreign_key "communication_website_pages", "communication_website_pages", column: "parent_id" add_foreign_key "communication_website_pages", "communication_websites" add_foreign_key "communication_website_pages", "universities"