From 355308c97aac1e000b9244e7f7648f001834ffdd Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Wed, 16 Oct 2024 12:03:49 +0200 Subject: [PATCH 1/4] Orderable --- .../admin/administration/locations_controller.rb | 2 +- app/controllers/admin/education/diplomas_controller.rb | 1 + app/controllers/admin/education/schools_controller.rb | 2 +- app/models/communication/block.rb | 2 +- app/models/communication/block/heading.rb | 2 +- app/models/communication/website/agenda/category.rb | 2 +- app/models/communication/website/menu/item.rb | 2 +- app/models/communication/website/page.rb | 4 ++-- app/models/communication/website/post/category.rb | 4 ++-- app/models/concerns/as_category.rb | 2 +- app/models/concerns/{with_position.rb => orderable.rb} | 2 +- app/models/education/diploma.rb | 6 ++++-- app/models/education/program.rb | 4 ++-- app/models/research/journal/paper.rb | 2 +- app/models/research/laboratory/axis.rb | 2 +- app/models/university/organization/category.rb | 2 +- app/models/university/person/category.rb | 2 +- app/models/university/person/involvement.rb | 2 +- app/models/university/person/localization.rb | 2 +- app/models/university/role.rb | 2 +- app/views/admin/administration/locations/static.html.erb | 2 +- app/views/admin/education/diplomas/_list.html.erb | 6 ++++-- config/routes/admin/education.rb | 3 +++ .../20241016094257_add_position_to_education_diplomas.rb | 5 +++++ db/schema.rb | 9 +++++---- 25 files changed, 44 insertions(+), 30 deletions(-) rename app/models/concerns/{with_position.rb => orderable.rb} (95%) create mode 100644 db/migrate/20241016094257_add_position_to_education_diplomas.rb diff --git a/app/controllers/admin/administration/locations_controller.rb b/app/controllers/admin/administration/locations_controller.rb index c017e319f..01628c7ff 100644 --- a/app/controllers/admin/administration/locations_controller.rb +++ b/app/controllers/admin/administration/locations_controller.rb @@ -27,7 +27,7 @@ def edit end def create - @location.language_id = current_language.id + @l10n.language_id = current_language.id if @location.save redirect_to [:admin, @location], notice: t('admin.successfully_created_html', model: @location.to_s_in(current_language)) diff --git a/app/controllers/admin/education/diplomas_controller.rb b/app/controllers/admin/education/diplomas_controller.rb index 9f12d51f3..e4391fc9d 100644 --- a/app/controllers/admin/education/diplomas_controller.rb +++ b/app/controllers/admin/education/diplomas_controller.rb @@ -4,6 +4,7 @@ class Admin::Education::DiplomasController < Admin::Education::ApplicationContro include Admin::HasStaticAction include Admin::Localizable + include Admin::Reorderable def index @diplomas = @diplomas.ordered diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb index 2cc29781c..58436424e 100644 --- a/app/controllers/admin/education/schools_controller.rb +++ b/app/controllers/admin/education/schools_controller.rb @@ -29,7 +29,7 @@ def edit end def create - @school.language_id = current_language.id + @l10n.language_id = current_language.id if @school.save redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s_in(current_language)) else diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 6d11a0fb3..f53d7462b 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -33,10 +33,10 @@ # class Communication::Block < ApplicationRecord include AsIndirectObject + include Orderable include WithAccessibility include WithHeadingRanks include WithHtmlClass - include WithPosition include WithTemplate include WithUniversity include Sanitizable diff --git a/app/models/communication/block/heading.rb b/app/models/communication/block/heading.rb index 6b5b82e99..282c388ad 100644 --- a/app/models/communication/block/heading.rb +++ b/app/models/communication/block/heading.rb @@ -29,9 +29,9 @@ # class Communication::Block::Heading < ApplicationRecord include AsIndirectObject + include Orderable include Sanitizable include Sluggable - include WithPosition include WithUniversity belongs_to :university diff --git a/app/models/communication/website/agenda/category.rb b/app/models/communication/website/agenda/category.rb index dd6d03a98..31e685e47 100644 --- a/app/models/communication/website/agenda/category.rb +++ b/app/models/communication/website/agenda/category.rb @@ -29,9 +29,9 @@ class Communication::Website::Agenda::Category < ApplicationRecord include AsDirectObject include Localizable + include Orderable include Sanitizable include WithMenuItemTarget - include WithPosition include WithTree include WithUniversity diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index 5fdd71a54..beada2893 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -33,8 +33,8 @@ # class Communication::Website::Menu::Item < ApplicationRecord include Initials + include Orderable include Sanitizable - include WithPosition include WithTree include WithUniversity diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 7df77afe0..e731bdcab 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -35,12 +35,12 @@ class Communication::Website::Page < ApplicationRecord include AsDirectObject include Duplicable include Filterable - include Sanitizable include Localizable + include Orderable # Scope :ordered must override WithPublication + include Sanitizable include WithAutomaticMenus include WithMenuItemTarget include WithSpecialPage # WithSpecialPage can set default publication status, so must be included before WithPublication - include WithPosition # Scope :ordered must override WithPublication include WithTree include WithUniversity diff --git a/app/models/communication/website/post/category.rb b/app/models/communication/website/post/category.rb index c6273744f..ec43b625f 100644 --- a/app/models/communication/website/post/category.rb +++ b/app/models/communication/website/post/category.rb @@ -28,10 +28,10 @@ # class Communication::Website::Post::Category < ApplicationRecord include AsDirectObject - include Sanitizable include Localizable + include Orderable + include Sanitizable include WithMenuItemTarget - include WithPosition include WithTree include WithUniversity diff --git a/app/models/concerns/as_category.rb b/app/models/concerns/as_category.rb index 120f5afdb..2c7445f76 100644 --- a/app/models/concerns/as_category.rb +++ b/app/models/concerns/as_category.rb @@ -2,7 +2,7 @@ module AsCategory extend ActiveSupport::Concern included do - include WithPosition + include Orderable include WithTree belongs_to :parent, diff --git a/app/models/concerns/with_position.rb b/app/models/concerns/orderable.rb similarity index 95% rename from app/models/concerns/with_position.rb rename to app/models/concerns/orderable.rb index cf9a3559c..26c495fca 100644 --- a/app/models/concerns/with_position.rb +++ b/app/models/concerns/orderable.rb @@ -1,4 +1,4 @@ -module WithPosition +module Orderable extend ActiveSupport::Concern included do diff --git a/app/models/education/diploma.rb b/app/models/education/diploma.rb index c0a2477a6..42318405d 100644 --- a/app/models/education/diploma.rb +++ b/app/models/education/diploma.rb @@ -6,6 +6,7 @@ # certification :string # ects :integer # level :integer default("not_applicable") +# position :integer default(0) # created_at :datetime not null # updated_at :datetime not null # university_id :uuid not null, indexed @@ -22,8 +23,9 @@ class Education::Diploma < ApplicationRecord CERTIFICATIONS_DIRECTORY = "app/assets/images/education/diplomas/certifications" include AsIndirectObject - include Sanitizable include Localizable + include Orderable + include Sanitizable include WithUniversity enum level: { @@ -43,7 +45,7 @@ class Education::Diploma < ApplicationRecord validates :certification, inclusion: { in: -> { certifications } }, allow_blank: true - scope :ordered, -> (language = nil) { order(:level) } + scope :ordered, -> (language = nil) { order(:position, :level) } def self.certifications Dir.children(CERTIFICATIONS_DIRECTORY).map { |filename| diff --git a/app/models/education/program.rb b/app/models/education/program.rb index d8d0aa009..d9a632188 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -31,13 +31,13 @@ class Education::Program < ApplicationRecord include AsIndirectObject include Filterable include Localizable + include Orderable include Sanitizable include WebsitesLinkable include WithAlumni include WithDiploma include WithLocations include WithMenuItemTarget - include WithPosition include WithSchools include WithTeam include WithTree @@ -60,7 +60,7 @@ class Education::Program < ApplicationRecord before_destroy :move_children - # can't use LocalizableOrderByNameScope because scope ordered is already defined by WithPosition + # can't use LocalizableOrderByNameScope because scope ordered is already defined by Orderable scope :ordered_by_name, -> (language) { localization_name_select = <<-SQL COALESCE( diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index b6ebc87dd..22becea4f 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -36,8 +36,8 @@ class Research::Journal::Paper < ApplicationRecord include AsIndirectObject include Localizable + include Orderable include Sanitizable - include WithPosition include WithUniversity belongs_to :journal, diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb index 4e120c9c5..abcd62e63 100644 --- a/app/models/research/laboratory/axis.rb +++ b/app/models/research/laboratory/axis.rb @@ -22,9 +22,9 @@ class Research::Laboratory::Axis < ApplicationRecord include Localizable include LocalizableOrderByNameScope + include Orderable include Sanitizable include WithUniversity - include WithPosition belongs_to :laboratory, foreign_key: :research_laboratory_id diff --git a/app/models/university/organization/category.rb b/app/models/university/organization/category.rb index 4b402e133..0a74f2b2e 100644 --- a/app/models/university/organization/category.rb +++ b/app/models/university/organization/category.rb @@ -22,7 +22,7 @@ class University::Organization::Category < ApplicationRecord include AsIndirectObject include Localizable - include WithPosition + include Orderable include WithTree include WithUniversity diff --git a/app/models/university/person/category.rb b/app/models/university/person/category.rb index 5802b3497..beca2b937 100644 --- a/app/models/university/person/category.rb +++ b/app/models/university/person/category.rb @@ -22,7 +22,7 @@ class University::Person::Category < ApplicationRecord include AsIndirectObject include Localizable - include WithPosition + include Orderable include WithTree include WithUniversity diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index 0104bc80b..1b9640659 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -25,7 +25,7 @@ # class University::Person::Involvement < ApplicationRecord include Localizable - include WithPosition + include Orderable include WithUniversity enum kind: { diff --git a/app/models/university/person/localization.rb b/app/models/university/person/localization.rb index f16255ca4..1d2e978a2 100644 --- a/app/models/university/person/localization.rb +++ b/app/models/university/person/localization.rb @@ -3,7 +3,7 @@ # Table name: university_person_localizations # # id :uuid not null, primary key -# biography :string +# biography :text # first_name :string # last_name :string # linkedin :string diff --git a/app/models/university/role.rb b/app/models/university/role.rb index a9404a424..45aa24cfa 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -21,7 +21,7 @@ # class University::Role < ApplicationRecord include Localizable - include WithPosition + include Orderable include WithUniversity # Can be an Education::School or an Education::Program diff --git a/app/views/admin/administration/locations/static.html.erb b/app/views/admin/administration/locations/static.html.erb index a30ea7e9c..d6999a047 100644 --- a/app/views/admin/administration/locations/static.html.erb +++ b/app/views/admin/administration/locations/static.html.erb @@ -34,7 +34,7 @@ location.programs.each do |program| <% end %> diplomas: <% -location.diplomas.each do |diploma| +location.diplomas.ordered.each do |diploma| diploma_l10n = diploma.best_localization_for(language) programs = location.education_programs.where(diploma: diploma).root.ordered next if programs.empty? diff --git a/app/views/admin/education/diplomas/_list.html.erb b/app/views/admin/education/diplomas/_list.html.erb index c7b02415c..8ab7c4fc0 100644 --- a/app/views/admin/education/diplomas/_list.html.erb +++ b/app/views/admin/education/diplomas/_list.html.erb @@ -1,6 +1,8 @@ -
+
<% diplomas.ordered.each do |diploma| %> -
+
<%= osuny_thumbnail_localized diploma %>
diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index 4dda51f8a..834d9cf4e 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -2,6 +2,9 @@ resources :academic_years resources :cohorts, only: [:index, :show] resources :diplomas do + collection do + post :reorder + end member do get :static end diff --git a/db/migrate/20241016094257_add_position_to_education_diplomas.rb b/db/migrate/20241016094257_add_position_to_education_diplomas.rb new file mode 100644 index 000000000..15e28af16 --- /dev/null +++ b/db/migrate/20241016094257_add_position_to_education_diplomas.rb @@ -0,0 +1,5 @@ +class AddPositionToEducationDiplomas < ActiveRecord::Migration[7.1] + def change + add_column :education_diplomas, :position, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index d7b4bd239..b174304b5 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[7.1].define(version: 2024_10_03_134739) do +ActiveRecord::Schema[7.1].define(version: 2024_10_16_094257) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -354,7 +354,7 @@ t.boolean "feature_jobs", default: false t.text "sass" t.text "css" - t.uuid "default_language_id" + t.uuid "default_language_id", null: false t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["default_language_id"], name: "index_communication_extranets_on_default_language_id" t.index ["university_id"], name: "index_communication_extranets_on_university_id" @@ -569,7 +569,7 @@ t.boolean "header_cta" t.string "header_cta_label" t.string "header_cta_url" - t.string "header_text" + t.text "header_text" t.string "meta_description" t.string "migration_identifier" t.boolean "published" @@ -913,6 +913,7 @@ t.datetime "updated_at", null: false t.integer "ects" t.string "certification" + t.integer "position", default: 0 t.index ["university_id"], name: "index_education_diplomas_on_university_id" end @@ -1686,7 +1687,7 @@ end create_table "university_person_localizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "biography" + t.text "biography" t.string "first_name" t.string "last_name" t.string "linkedin" From 10efc55681ca682f9e930733896268cf8c1a9622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Wed, 16 Oct 2024 12:07:53 +0200 Subject: [PATCH 2/4] Update app/models/communication/website/page.rb --- app/models/communication/website/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index e731bdcab..783c522c0 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -36,7 +36,7 @@ class Communication::Website::Page < ApplicationRecord include Duplicable include Filterable include Localizable - include Orderable # Scope :ordered must override WithPublication + include Orderable include Sanitizable include WithAutomaticMenus include WithMenuItemTarget From 0aa95118b5053566a33ade69e5350fdc127df65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Wed, 16 Oct 2024 12:08:16 +0200 Subject: [PATCH 3/4] Update app/controllers/admin/education/schools_controller.rb --- app/controllers/admin/education/schools_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb index 58436424e..0f944aa1b 100644 --- a/app/controllers/admin/education/schools_controller.rb +++ b/app/controllers/admin/education/schools_controller.rb @@ -29,7 +29,6 @@ def edit end def create - @l10n.language_id = current_language.id if @school.save redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s_in(current_language)) else From 891499713b827437b6cf0c08ddd9474959e8dddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Wed, 16 Oct 2024 12:08:20 +0200 Subject: [PATCH 4/4] Update app/controllers/admin/administration/locations_controller.rb --- app/controllers/admin/administration/locations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/administration/locations_controller.rb b/app/controllers/admin/administration/locations_controller.rb index 01628c7ff..bbf1df49f 100644 --- a/app/controllers/admin/administration/locations_controller.rb +++ b/app/controllers/admin/administration/locations_controller.rb @@ -27,7 +27,6 @@ def edit end def create - @l10n.language_id = current_language.id if @location.save redirect_to [:admin, @location], notice: t('admin.successfully_created_html', model: @location.to_s_in(current_language))