From 6fd69ea5a8da31a76fe4e24e60e083a73cc3763d Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 13 Jun 2024 16:31:52 +0200 Subject: [PATCH 001/349] wip person --- .../communication/websites/lang_switch.js | 2 +- .../university/application_controller.rb | 12 ++++++++++ .../admin/university/people_controller.rb | 5 ++-- .../concerns/admin/translatable.rb | 6 ++--- app/models/concerns/translatable.rb | 18 +++++++++++++- app/models/university.rb | 4 +--- app/models/university/with_languages.rb | 24 +++++++++++++++++++ .../application/_language_switcher.html.erb | 17 +++++++++++++ .../admin/application/i18n/_widget.html.erb | 3 +-- .../websites/_language_switcher.html.erb | 2 +- .../admin/university/people/_list.html.erb | 2 +- .../admin/university/people/index.html.erb | 4 ++++ config/routes/admin/university.rb | 2 +- 13 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 app/models/university/with_languages.rb create mode 100644 app/views/admin/application/_language_switcher.html.erb diff --git a/app/assets/javascripts/admin/communication/websites/lang_switch.js b/app/assets/javascripts/admin/communication/websites/lang_switch.js index 390243899d..2547d147af 100644 --- a/app/assets/javascripts/admin/communication/websites/lang_switch.js +++ b/app/assets/javascripts/admin/communication/websites/lang_switch.js @@ -1,7 +1,7 @@ window.osuny.communication.websites.langSwitch = { init: function () { 'use strict'; - this.select = document.querySelector('#js-website-lang-switch'); + this.select = document.querySelector('#js-lang-switch'); if (this.select) { this.select.addEventListener('change', this.onChange.bind(this)); } diff --git a/app/controllers/admin/university/application_controller.rb b/app/controllers/admin/university/application_controller.rb index 67e9473db6..aff28176a5 100644 --- a/app/controllers/admin/university/application_controller.rb +++ b/app/controllers/admin/university/application_controller.rb @@ -6,4 +6,16 @@ def breadcrumb super add_breadcrumb University.model_name.human, admin_university_root_path if current_university.is_really_a_university end + + def default_url_options + options = {} + options[:lang] = current_language.iso_code + options + end + + def current_language + @current_language ||= current_university.best_language_for(params[:lang]) + end + helper_method :current_language + end diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 09cb51bb0c..8f0f7f02b6 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -3,6 +3,7 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro through: :current_university, through_association: :people + include Admin::Translatable has_scope :for_search_term has_scope :for_category @@ -10,14 +11,14 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro def index @people = apply_scopes(@people) - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .ordered respond_to do |format| format.html { @people = @people.page(params[:page]).per(24) @categories = current_university.person_categories - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .ordered .page(params[:categories_page]) breadcrumb diff --git a/app/controllers/concerns/admin/translatable.rb b/app/controllers/concerns/admin/translatable.rb index 1d7b6e9cce..7598338334 100644 --- a/app/controllers/concerns/admin/translatable.rb +++ b/app/controllers/concerns/admin/translatable.rb @@ -7,13 +7,11 @@ module Admin::Translatable protected - # If we don't have a website, it will not work - def check_or_redirect_translatable_resource # Early return if language is correct - return if resource.language_id == current_website_language.id + return if resource.language_id == current_language.id # Look up for translation or translate (with blocks and all) from resource - translation = resource.find_or_translate!(current_website_language) + translation = resource.find_or_translate!(current_language) # Redirect to the translation redirect_to_translation(translation) end diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index 82568cd3d6..2fcdd3d172 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -15,6 +15,22 @@ module Translatable # has to be before_destroy because of the foreign key constraints before_destroy :destroy_or_nullify_translations + + + # on cherche les objets pour cette langue (original ou pas) + les objets originaux dans une autre langue s'il n'en existe pas de traduction + scope :in_closest_language_id, -> (language_id) { + # Records with correct language (Original or Translation) + # OR Records originals which does not have any translation matching the language + for_language_id(language_id).or( + where(original_id: nil) + .where.not(language_id: language_id) + .where( + "NOT EXISTS (SELECT 1 FROM #{table_name} AS translations WHERE translations.original_id = #{table_name}.id AND translations.language_id = ?)", + language_id + ) + ) + } + scope :for_language, -> (language) { for_language_id(language.id) } # The for_language_id scope can be used when you have the ID without needing to load the Language itself scope :for_language_id, -> (language_id) { where(language_id: language_id) } @@ -23,7 +39,7 @@ module Translatable def available_languages @available_languages ||= begin - languages = is_direct_object? ? website.languages : Language.all + languages = is_direct_object? ? website.languages : university.languages languages.ordered end end diff --git a/app/models/university.rb b/app/models/university.rb index ae745ac38c..13eedf2f12 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -47,6 +47,7 @@ class University < ApplicationRecord include WithEducation include WithIdentifier include WithInvoice + include WithLanguages include WithPeopleAndOrganizations include WithResearch include WithSso @@ -59,8 +60,6 @@ class University < ApplicationRecord has_many :active_storage_blobs, class_name: 'ActiveStorage::Blob' has_many :imports, dependent: :destroy has_many :apps, dependent: :destroy - belongs_to :default_language, class_name: "Language" - has_and_belongs_to_many :languages validates_presence_of :name validates :sms_sender_name, presence: true, length: { maximum: 11 } @@ -74,7 +73,6 @@ class University < ApplicationRecord scope :for_real_university, -> (status) { where(is_really_a_university: status) } scope :for_contribution, -> (status) { status == 'true' ? contributing : not_contributing } scope :for_university_kind, -> (status) { where(private: status == 'private') } - scope :for_language, -> (language) { joins(:languages).where(languages: { id: language } ) } def self.parts [ diff --git a/app/models/university/with_languages.rb b/app/models/university/with_languages.rb new file mode 100644 index 0000000000..8556fbcc31 --- /dev/null +++ b/app/models/university/with_languages.rb @@ -0,0 +1,24 @@ +module University::WithLanguages + extend ActiveSupport::Concern + + included do + + belongs_to :default_language, class_name: "Language" + has_and_belongs_to_many :languages + + scope :for_language, -> (language) { joins(:languages).where(languages: { id: language } ) } + + end + + def best_language_for(iso_code) + # if iso_code provided check if university contains current language + # else fallback to the default university language. + if iso_code.present? + languages.find_by!(iso_code: iso_code) + else + default_language + end + end + + +end diff --git a/app/views/admin/application/_language_switcher.html.erb b/app/views/admin/application/_language_switcher.html.erb new file mode 100644 index 0000000000..77d8738663 --- /dev/null +++ b/app/views/admin/application/_language_switcher.html.erb @@ -0,0 +1,17 @@ +<% if current_university.languages.many? %> + <% + languages_options = current_university.languages.ordered.map { |language| + [ + language_name(language.iso_code), + url_for(request.params.merge(lang: language.iso_code)) + ] + } + selected_option = url_for(request.params.merge(lang: current_language.iso_code)) + %> + + <%= select_tag nil, + options_for_select(languages_options, selected_option), + class: "form-control form-select", + id: "js-lang-switch" %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/application/i18n/_widget.html.erb b/app/views/admin/application/i18n/_widget.html.erb index 2db7736739..920a7b1c02 100644 --- a/app/views/admin/application/i18n/_widget.html.erb +++ b/app/views/admin/application/i18n/_widget.html.erb @@ -3,8 +3,7 @@ small ||= false %> <% if about.available_languages.many? %> <% - route_args = about.is_direct_object? ? [:admin, about.becomes(about.class.base_class)] - : [:show_in_language, :admin, about.becomes(about.class.base_class)] + route_args =[:admin, about.becomes(about.class.base_class)] %> <%= osuny_panel t('internationalization.label'), small: small do %>
    diff --git a/app/views/admin/communication/websites/_language_switcher.html.erb b/app/views/admin/communication/websites/_language_switcher.html.erb index 298e9e4e96..e0af86dedf 100644 --- a/app/views/admin/communication/websites/_language_switcher.html.erb +++ b/app/views/admin/communication/websites/_language_switcher.html.erb @@ -13,7 +13,7 @@ <%= select_tag nil, options_for_select(languages_options, selected_option), class: "form-control form-select my-5", - id: "js-website-lang-switch" %> + id: "js-lang-switch" %> <% end %> \ No newline at end of file diff --git a/app/views/admin/university/people/_list.html.erb b/app/views/admin/university/people/_list.html.erb index d3789b2a0b..84593e7730 100644 --- a/app/views/admin/university/people/_list.html.erb +++ b/app/views/admin/university/people/_list.html.erb @@ -1,7 +1,7 @@
    <% people.each do |person| %>
    -
    +
    <%= osuny_thumbnail person, large: true %>
    diff --git a/app/views/admin/university/people/index.html.erb b/app/views/admin/university/people/index.html.erb index b00d8e74e2..10f11011d4 100644 --- a/app/views/admin/university/people/index.html.erb +++ b/app/views/admin/university/people/index.html.erb @@ -37,3 +37,7 @@ subtitle = t('admin.elements', count: @categories.total_count) request.params.merge(format: "xlsx"), class: button_classes %> <% end %> + +<% content_for :action_bar_right do %> + <%= render 'language_switcher' %> +<% end %> diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index 212782074a..f1c956a861 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -23,7 +23,7 @@ resources :imports, only: [:index, :show, :new, :create] end end - resources :people do + resources :people, path: '/:lang/people' do collection do get :search, defaults: { format: 'json' } resources :categories, controller: 'people/categories', as: 'person_categories' do From bafa153958e98e8de02e2802a350ed249d1e01d4 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 13 Jun 2024 16:52:14 +0200 Subject: [PATCH 002/349] rename current_website_language as current_language --- .../websites/agenda/categories_controller.rb | 2 +- .../websites/agenda/events_controller.rb | 8 ++++---- .../communication/websites/application_controller.rb | 8 ++++---- .../websites/localizations_controller.rb | 2 +- .../admin/communication/websites/menus_controller.rb | 4 ++-- .../admin/communication/websites/pages_controller.rb | 8 ++++---- .../websites/portfolio/categories_controller.rb | 2 +- .../websites/portfolio/projects_controller.rb | 8 ++++---- .../websites/posts/categories_controller.rb | 2 +- .../websites/posts/curations_controller.rb | 2 +- .../admin/communication/websites/posts_controller.rb | 10 +++++----- .../admin/communication/websites_controller.rb | 10 +++++----- .../admin/university/people_controller.rb | 12 ------------ app/controllers/concerns/admin/categorizable.rb | 2 +- app/views/admin/application/i18n/_inline.html.erb | 5 +---- .../websites/_language_switcher.html.erb | 2 +- .../websites/menus/items/_form.html.erb | 6 +++--- .../websites/menus/items/kind_switch.js.erb | 6 +++--- .../communication/websites/pages/_form.html.erb | 2 +- .../communication/websites/posts/_form.html.erb | 2 +- .../websites/posts/categories/_form.html.erb | 2 +- .../admin/dashboard/_really_a_university.html.erb | 2 +- config/navigation/admin_navigation.rb | 2 +- config/routes/admin/university.rb | 1 - 24 files changed, 47 insertions(+), 63 deletions(-) diff --git a/app/controllers/admin/communication/websites/agenda/categories_controller.rb b/app/controllers/admin/communication/websites/agenda/categories_controller.rb index 8aad641c09..d780e91234 100644 --- a/app/controllers/admin/communication/websites/agenda/categories_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/categories_controller.rb @@ -80,7 +80,7 @@ def category_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end diff --git a/app/controllers/admin/communication/websites/agenda/events_controller.rb b/app/controllers/admin/communication/websites/agenda/events_controller.rb index c03dcf57e8..5ee256ca03 100644 --- a/app/controllers/admin/communication/websites/agenda/events_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/events_controller.rb @@ -11,7 +11,7 @@ class Admin::Communication::Websites::Agenda::EventsController < Admin::Communic has_scope :for_category def index - @events = apply_scopes(@events).for_language(current_website_language) + @events = apply_scopes(@events).for_language(current_language) .ordered_desc .page(params[:page]) @feature_nav = 'navigation/admin/communication/website/agenda' @@ -92,7 +92,7 @@ def breadcrumb def categories @website.agenda_categories - .for_language(current_website_language) + .for_language(current_language) .ordered end @@ -100,7 +100,7 @@ def load_filters @filters = ::Filters::Admin::Communication::Websites::Agenda::Events.new( current_user, @website, - current_website_language + current_language ).list end @@ -115,7 +115,7 @@ def event_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end \ No newline at end of file diff --git a/app/controllers/admin/communication/websites/application_controller.rb b/app/controllers/admin/communication/websites/application_controller.rb index c7e88ce9a2..92ac1136a3 100644 --- a/app/controllers/admin/communication/websites/application_controller.rb +++ b/app/controllers/admin/communication/websites/application_controller.rb @@ -6,10 +6,10 @@ class Admin::Communication::Websites::ApplicationController < Admin::Communicati protected - def current_website_language - @current_website_language ||= @website.best_language_for(params[:lang]) + def current_language + @current_language ||= @website.best_language_for(params[:lang]) end - helper_method :current_website_language + helper_method :current_language def current_subnav_context 'navigation/admin/communication/website' if @website && @website.persisted? @@ -25,7 +25,7 @@ def default_url_options options = {} if @website.present? options[:website_id] = @website.id - options[:lang] = current_website_language.iso_code + options[:lang] = current_language.iso_code end options end diff --git a/app/controllers/admin/communication/websites/localizations_controller.rb b/app/controllers/admin/communication/websites/localizations_controller.rb index e99a932f2d..2330f5c848 100644 --- a/app/controllers/admin/communication/websites/localizations_controller.rb +++ b/app/controllers/admin/communication/websites/localizations_controller.rb @@ -22,7 +22,7 @@ def set_feature_nav end def load_localization - @localization = @website.find_or_create_localization_for(current_website_language) + @localization = @website.find_or_create_localization_for(current_language) authorize! :update, @localization end diff --git a/app/controllers/admin/communication/websites/menus_controller.rb b/app/controllers/admin/communication/websites/menus_controller.rb index 93991c1a1f..78a35a3394 100644 --- a/app/controllers/admin/communication/websites/menus_controller.rb +++ b/app/controllers/admin/communication/websites/menus_controller.rb @@ -4,7 +4,7 @@ class Admin::Communication::Websites::MenusController < Admin::Communication::We include Admin::Translatable def index - @menus = @menus.for_language(current_website_language).ordered + @menus = @menus.for_language(current_language).ordered breadcrumb end @@ -68,7 +68,7 @@ def menu_params .permit(:title, :identifier) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index 4331b558cd..8e79a04a6d 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -9,15 +9,15 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We has_scope :for_full_width def index - @homepage = @website.special_page(Communication::Website::Page::Home, language: current_website_language) + @homepage = @website.special_page(Communication::Website::Page::Home, language: current_language) @first_level_pages = @homepage.children.ordered - @pages = @website.pages.for_language(current_website_language) + @pages = @website.pages.for_language(current_language) breadcrumb end def index_list @filters = ::Filters::Admin::Communication::Websites::Pages.new(current_user).list - @pages = apply_scopes(@pages).for_language(current_website_language) + @pages = apply_scopes(@pages).for_language(current_language) .ordered_by_title .page(params[:page]) breadcrumb @@ -159,7 +159,7 @@ def page_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end diff --git a/app/controllers/admin/communication/websites/portfolio/categories_controller.rb b/app/controllers/admin/communication/websites/portfolio/categories_controller.rb index 45e1930b65..0d157c574e 100644 --- a/app/controllers/admin/communication/websites/portfolio/categories_controller.rb +++ b/app/controllers/admin/communication/websites/portfolio/categories_controller.rb @@ -80,7 +80,7 @@ def category_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end diff --git a/app/controllers/admin/communication/websites/portfolio/projects_controller.rb b/app/controllers/admin/communication/websites/portfolio/projects_controller.rb index 1bbd82208f..1b744cc41a 100644 --- a/app/controllers/admin/communication/websites/portfolio/projects_controller.rb +++ b/app/controllers/admin/communication/websites/portfolio/projects_controller.rb @@ -11,7 +11,7 @@ class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Com has_scope :for_category def index - @projects = apply_scopes(@projects).for_language(current_website_language) + @projects = apply_scopes(@projects).for_language(current_language) .ordered .page(params[:page]) @feature_nav = 'navigation/admin/communication/website/portfolio' @@ -90,7 +90,7 @@ def breadcrumb def categories @website.portfolio_categories - .for_language(current_website_language) + .for_language(current_language) .ordered end @@ -98,7 +98,7 @@ def load_filters @filters = ::Filters::Admin::Communication::Websites::Portfolio::Projects.new( current_user, @website, - current_website_language + current_language ).list end @@ -112,7 +112,7 @@ def project_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end \ No newline at end of file diff --git a/app/controllers/admin/communication/websites/posts/categories_controller.rb b/app/controllers/admin/communication/websites/posts/categories_controller.rb index 0660ea646c..b1611e930a 100644 --- a/app/controllers/admin/communication/websites/posts/categories_controller.rb +++ b/app/controllers/admin/communication/websites/posts/categories_controller.rb @@ -85,7 +85,7 @@ def category_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end end diff --git a/app/controllers/admin/communication/websites/posts/curations_controller.rb b/app/controllers/admin/communication/websites/posts/curations_controller.rb index dca73a2856..e94d6d2a86 100644 --- a/app/controllers/admin/communication/websites/posts/curations_controller.rb +++ b/app/controllers/admin/communication/websites/posts/curations_controller.rb @@ -4,7 +4,7 @@ def new end def create - @curator = Importers::Curator.new @website, current_user, current_website_language, curation_params[:url] + @curator = Importers::Curator.new @website, current_user, current_language, curation_params[:url] if @curator.valid? redirect_to [:admin, @curator.post], notice: t('admin.successfully_created_html', model: @curator.post.to_s) diff --git a/app/controllers/admin/communication/websites/posts_controller.rb b/app/controllers/admin/communication/websites/posts_controller.rb index 4f7a4194d1..f83bc4751e 100644 --- a/app/controllers/admin/communication/websites/posts_controller.rb +++ b/app/controllers/admin/communication/websites/posts_controller.rb @@ -13,7 +13,7 @@ class Admin::Communication::Websites::PostsController < Admin::Communication::We has_scope :for_pinned def index - @posts = apply_scopes(@posts).for_language(current_website_language) + @posts = apply_scopes(@posts).for_language(current_language) .ordered .page(params[:page]) @feature_nav = 'navigation/admin/communication/website/posts' @@ -57,7 +57,7 @@ def new @categories = categories @post.website = @website if current_user.person.present? - @post.author_id = current_user.person.find_or_translate!(current_website_language).id + @post.author_id = current_user.person.find_or_translate!(current_language).id end breadcrumb end @@ -122,7 +122,7 @@ def post_params ) .merge( university_id: current_university.id, - language_id: current_website_language.id + language_id: current_language.id ) end @@ -130,13 +130,13 @@ def load_filters @filters = ::Filters::Admin::Communication::Website::Posts.new( current_user, @website, - current_website_language + current_language ).list end def categories @website.post_categories - .for_language(current_website_language) + .for_language(current_language) .ordered end end diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 06c163eb9c..4858d0dd9b 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -26,13 +26,13 @@ def production end def show - @all_pages = @website.pages.accessible_by(current_ability).for_language(current_website_language) + @all_pages = @website.pages.accessible_by(current_ability).for_language(current_language) @pages = @all_pages.latest - @all_posts = @website.posts.accessible_by(current_ability).for_language(current_website_language) + @all_posts = @website.posts.accessible_by(current_ability).for_language(current_language) @posts = @all_posts.latest - @all_events = @website.events.accessible_by(current_ability).for_language(current_website_language) + @all_events = @website.events.accessible_by(current_ability).for_language(current_language) @events = @all_events.latest - @all_projects = @website.projects.accessible_by(current_ability).for_language(current_website_language) + @all_projects = @website.projects.accessible_by(current_ability).for_language(current_language) @projects = @all_projects.latest breadcrumb end @@ -103,7 +103,7 @@ def website_params def default_url_options options = {} - options[:lang] = current_website_language.iso_code if @website&.persisted? + options[:lang] = current_language.iso_code if @website&.persisted? options end end diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 8f0f7f02b6..0c109956fc 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -49,18 +49,6 @@ def show breadcrumb end - def in_language - language = Language.find_by!(iso_code: params[:lang]) - translation = @person.find_or_translate!(language) - if translation.newly_translated - # There's an attribute accessor named "newly_translated" that we set to true - # when we just created the translation. We use it to redirect to the form instead of the show. - redirect_to [:edit, :admin, translation.becomes(translation.class.base_class)] - else - redirect_to [:admin, translation.becomes(translation.class.base_class)] - end - end - def static @about = @person @website = @person.websites&.first diff --git a/app/controllers/concerns/admin/categorizable.rb b/app/controllers/concerns/admin/categorizable.rb index c8e9d3173a..116523b4d9 100644 --- a/app/controllers/concerns/admin/categorizable.rb +++ b/app/controllers/concerns/admin/categorizable.rb @@ -29,7 +29,7 @@ def children def categories categories_class.where(communication_website_id: @website.id) - .for_language(current_website_language) + .for_language(current_language) .ordered end diff --git a/app/views/admin/application/i18n/_inline.html.erb b/app/views/admin/application/i18n/_inline.html.erb index 4c5b3bc773..7371a1d500 100644 --- a/app/views/admin/application/i18n/_inline.html.erb +++ b/app/views/admin/application/i18n/_inline.html.erb @@ -1,10 +1,7 @@ <% if about.available_languages.many? %> <%= t('admin.i18n.in', lang: language_name(about.language.iso_code).downcase) %> - <% - route_args = about.is_direct_object? ? [:admin, about.becomes(about.class.base_class)] - : [:show_in_language, :admin, about.becomes(about.class.base_class)] - %> + <% route_args = [:admin, about.becomes(about.class.base_class)] %> <% links = about.available_languages.map { |language| next if language.id == about.language_id diff --git a/app/views/admin/communication/websites/_language_switcher.html.erb b/app/views/admin/communication/websites/_language_switcher.html.erb index e0af86dedf..9985f49e80 100644 --- a/app/views/admin/communication/websites/_language_switcher.html.erb +++ b/app/views/admin/communication/websites/_language_switcher.html.erb @@ -6,7 +6,7 @@ url_for(request.params.merge(lang: language.iso_code)) ] } - selected_option = url_for(request.params.merge(lang: current_website_language.iso_code)) + selected_option = url_for(request.params.merge(lang: current_language.iso_code)) %>
    diff --git a/app/views/admin/communication/websites/menus/items/_form.html.erb b/app/views/admin/communication/websites/menus/items/_form.html.erb index 0a1d769dc6..6a643428f9 100644 --- a/app/views/admin/communication/websites/menus/items/_form.html.erb +++ b/app/views/admin/communication/websites/menus/items/_form.html.erb @@ -48,15 +48,15 @@ <% if item.has_about? if item.kind_page? - about_collection = collection_tree @website.pages.for_language(current_website_language) + about_collection = collection_tree @website.pages.for_language(current_language) elsif item.kind_diploma? about_collection = collection @website.education_diplomas elsif item.kind_program? about_collection = collection_tree @website.education_programs elsif item.kind_category? - about_collection = collection_tree @website.post_categories.for_language(current_website_language) + about_collection = collection_tree @website.post_categories.for_language(current_language) elsif item.kind_post? - about_collection = collection @website.posts.for_language(current_website_language) + about_collection = collection @website.posts.for_language(current_language) elsif item.kind_volume? about_collection = collection @website.research_volumes elsif item.kind_paper? diff --git a/app/views/admin/communication/websites/menus/items/kind_switch.js.erb b/app/views/admin/communication/websites/menus/items/kind_switch.js.erb index 5984531f6f..00a614cc41 100644 --- a/app/views/admin/communication/websites/menus/items/kind_switch.js.erb +++ b/app/views/admin/communication/websites/menus/items/kind_switch.js.erb @@ -15,7 +15,7 @@ function hideAbout() { <% elsif @kind == 'page' %> <% options = [''] - collection_tree(@website.pages.for_language(current_website_language)).each do |page| + collection_tree(@website.pages.for_language(current_language)).each do |page| options << "" end %> @@ -40,7 +40,7 @@ function hideAbout() { <% elsif @kind == 'category' %> <% options = [''] - collection_tree(@website.post_categories.for_language(current_website_language)).each do |category| + collection_tree(@website.post_categories.for_language(current_language)).each do |category| options << "" end %> @@ -48,7 +48,7 @@ function hideAbout() { <% elsif @kind == 'post' %> <% options = [''] - @website.posts.for_language(current_website_language).ordered.each do |post| + @website.posts.for_language(current_language).ordered.each do |post| options << "" end %> diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb index f189a9be24..65f1c638de 100644 --- a/app/views/admin/communication/websites/pages/_form.html.erb +++ b/app/views/admin/communication/websites/pages/_form.html.erb @@ -32,7 +32,7 @@ url = page.new_record? ? admin_communication_website_pages_path f: f, source: '#communication_website_page_title' unless page.is_home? %> <%= f.association :parent, - collection: collection_tree(@website.pages.for_language(current_website_language), page), + collection: collection_tree(@website.pages.for_language(current_language), page), include_blank: false, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } unless page.is_home? %> diff --git a/app/views/admin/communication/websites/posts/_form.html.erb b/app/views/admin/communication/websites/posts/_form.html.erb index d22fa3bde7..f249cf75fb 100644 --- a/app/views/admin/communication/websites/posts/_form.html.erb +++ b/app/views/admin/communication/websites/posts/_form.html.erb @@ -37,7 +37,7 @@ <%= f.input :published_at, html5: true, as: :date %> <% end %> <%= f.association :author, - collection: current_university.people.for_language(current_website_language).ordered, + collection: current_university.people.for_language(current_language).ordered, label_method: :to_s_alphabetical %> <%= render "admin/application/slug/form", f: f, diff --git a/app/views/admin/communication/websites/posts/categories/_form.html.erb b/app/views/admin/communication/websites/posts/categories/_form.html.erb index 43782ce292..eb7d16ce2e 100644 --- a/app/views/admin/communication/websites/posts/categories/_form.html.erb +++ b/app/views/admin/communication/websites/posts/categories/_form.html.erb @@ -16,7 +16,7 @@ f: f, source: '#communication_website_post_category_name' %> <%= f.association :parent, - collection: collection_tree(@website.post_categories.for_language(current_website_language), category), + collection: collection_tree(@website.post_categories.for_language(current_language), category), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <% end %> diff --git a/app/views/admin/dashboard/_really_a_university.html.erb b/app/views/admin/dashboard/_really_a_university.html.erb index 686703a1ae..99c91ad88a 100644 --- a/app/views/admin/dashboard/_really_a_university.html.erb +++ b/app/views/admin/dashboard/_really_a_university.html.erb @@ -32,7 +32,7 @@ <% next unless can? :read, part.first class_name = part.first - path = send part.last + path = send part.last, lang: current_language.iso_code title = class_name.model_name.human(count: 2) %>
  1. diff --git a/config/navigation/admin_navigation.rb b/config/navigation/admin_navigation.rb index b95fff7419..57f8f49c4d 100644 --- a/config/navigation/admin_navigation.rb +++ b/config/navigation/admin_navigation.rb @@ -9,7 +9,7 @@ def load_from_parts class_name, primary class_name = part.first identifier = class_name.to_s.to_sym label = class_name.model_name.human(count: 2) - path = send part.last + path = send part.last, lang: current_language.iso_code icon = Icon.icon_for class_name primary.item identifier, label, path, { icon: icon } if can?(:read, class_name) end diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index f1c956a861..a3f4dbb549 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -35,7 +35,6 @@ end member do get :static - get "/translations/:lang" => "people#in_language", as: :show_in_language get 'experiences' => 'people/experiences#edit' patch 'experiences' => 'people/experiences#update' end From 897bf8e2c7323fa7e4f5c98a8eac0677af6a2d62 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 13 Jun 2024 16:56:53 +0200 Subject: [PATCH 003/349] adjust websites --- .../admin/communication/websites/application_controller.rb | 6 +++++- app/views/admin/communication/websites/_form.html.erb | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/communication/websites/application_controller.rb b/app/controllers/admin/communication/websites/application_controller.rb index 92ac1136a3..d2ad3accc8 100644 --- a/app/controllers/admin/communication/websites/application_controller.rb +++ b/app/controllers/admin/communication/websites/application_controller.rb @@ -7,7 +7,11 @@ class Admin::Communication::Websites::ApplicationController < Admin::Communicati protected def current_language - @current_language ||= @website.best_language_for(params[:lang]) + if @website + @current_language ||= @website.best_language_for(params[:lang]) + else + super + end end helper_method :current_language diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index df58a36d94..53f1a1962e 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -29,6 +29,7 @@
    <%= f.association :languages, as: :check_boxes, + collection: current_university.languages, required: true, wrapper_html: { class: "js-languages" }, label_method: lambda { |l| language_name(l.iso_code) } %> From 24f8f61ae2e7a0acdfff6f9b642d08b4382852a9 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 13 Jun 2024 17:35:54 +0200 Subject: [PATCH 004/349] add hint to prevent disconnect used language --- app/models/university.rb | 1 + app/views/server/universities/_form.html.erb | 3 ++- config/locales/university/en.yml | 2 ++ config/locales/university/fr.yml | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/university.rb b/app/models/university.rb index 13eedf2f12..c79da6be7c 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -114,4 +114,5 @@ def sanitize_fields def destroy_remaining_blobs active_storage_blobs.delete_all end + end diff --git a/app/views/server/universities/_form.html.erb b/app/views/server/universities/_form.html.erb index e827d5bebf..212cf12ead 100644 --- a/app/views/server/universities/_form.html.erb +++ b/app/views/server/universities/_form.html.erb @@ -39,7 +39,8 @@ as: :check_boxes, required: true, wrapper_html: { class: "js-languages" }, - label_method: lambda { |l| language_name(l.iso_code) } %> + label_method: lambda { |l| language_name(l.iso_code) }, + hint: t('simple_form.hints.university.languages', used_languages: Language.where(id: university.websites.map(&:language_ids).flatten.uniq).ordered.map(&:name).join(', ')) %>
    <%= f.association :default_language, diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index 22f9935e71..ac0fedbef3 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -11,6 +11,7 @@ en: is_really_a_university: Is really a university identifier: Identifier invoice_date: Contribution date + languages: Languages logo: Logo name: Name private: Private @@ -181,6 +182,7 @@ en: hints: university: is_really_a_university: Uncheck this to hide the 5 realms. + languages: "Those languages are currently used on websites: %{used_languages}" sms_sender_name: "11 characters max. Only alphanumeric chars ([A-Z][a-z][0-9])." sso_button_label: "Default: Sign in via SSO" university_organization: diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index f5183d5f20..f81e269b2d 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -11,6 +11,7 @@ fr: is_really_a_university: Réellement une université identifier: Identifiant invoice_date: Date de contribution + languages: Langues logo: Logo name: Nom private: Etablissement privé @@ -181,6 +182,7 @@ fr: hints: university: is_really_a_university: Décocher cette case masque les 5 royaumes. + languages: "Ces langues sont actuellement utilisées sans les sites web : %{used_languages}" sms_sender_name: "11 caractères maximum. Que des caractères alphadécimaux ([A-Z][a-z][0-9])." sso_button_label: "Par défaut : Se connecter en SSO" university_organization: From fd4384fdd8ce419a84b33d15f160c7472a294b77 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Fri, 14 Jun 2024 10:58:41 +0200 Subject: [PATCH 005/349] nice --- app/assets/stylesheets/admin/components/card.sass | 10 +++++++++- app/helpers/admin/osuny_helper.rb | 4 ++-- app/models/concerns/translatable.rb | 10 ++++++++-- app/views/admin/application/i18n/_widget.html.erb | 13 ++++++++++--- .../websites/agenda/events/_list.html.erb | 2 +- .../communication/websites/pages/_list.html.erb | 2 +- .../websites/pages/_treebranch.html.erb | 2 +- .../websites/portfolio/projects/_list.html.erb | 2 +- .../communication/websites/posts/_list.html.erb | 2 +- .../admin/university/organizations/_list.html.erb | 1 + app/views/admin/university/people/_list.html.erb | 6 +++--- .../admin/university/people/_main_infos.html.erb | 2 +- app/views/admin/university/people/index.html.erb | 5 ++++- 13 files changed, 43 insertions(+), 18 deletions(-) diff --git a/app/assets/stylesheets/admin/components/card.sass b/app/assets/stylesheets/admin/components/card.sass index ce5b120a92..7b8b61be2d 100644 --- a/app/assets/stylesheets/admin/components/card.sass +++ b/app/assets/stylesheets/admin/components/card.sass @@ -4,6 +4,14 @@ margin-bottom: $spacing1 overflow: hidden transition: box-shadow 0.3s ease-in-out + // In the people and organizations + > .osuny__published + margin-right: 0 + position: absolute + right: pxToRem(10) + top: pxToRem(10) + &--false + border: 1px solid $color-border &--horizontal align-items: center flex-direction: row @@ -30,4 +38,4 @@ background: $color-accent border-color: $color-accent &, p, label - color: $color-background \ No newline at end of file + color: $color-background diff --git a/app/helpers/admin/osuny_helper.rb b/app/helpers/admin/osuny_helper.rb index 7d36fd64d8..ec1210013d 100644 --- a/app/helpers/admin/osuny_helper.rb +++ b/app/helpers/admin/osuny_helper.rb @@ -34,8 +34,8 @@ def osuny_thumbnail(object, large: false, cropped: true) } end - def osuny_published(object) - raw "" + def osuny_published(state) + raw "" end end \ No newline at end of file diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index 2fcdd3d172..af1ec70b11 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -15,8 +15,6 @@ module Translatable # has to be before_destroy because of the foreign key constraints before_destroy :destroy_or_nullify_translations - - # on cherche les objets pour cette langue (original ou pas) + les objets originaux dans une autre langue s'il n'en existe pas de traduction scope :in_closest_language_id, -> (language_id) { # Records with correct language (Original or Translation) @@ -72,6 +70,14 @@ def is_a_translation? self.original.present? end + def is_in_language?(l) + language.id == l.id + end + + def exists_in_language?(l) + translation_for(l).present? + end + def original_with_translations original_object.translations + [original_object] end diff --git a/app/views/admin/application/i18n/_widget.html.erb b/app/views/admin/application/i18n/_widget.html.erb index 920a7b1c02..92dc4ef317 100644 --- a/app/views/admin/application/i18n/_widget.html.erb +++ b/app/views/admin/application/i18n/_widget.html.erb @@ -6,14 +6,21 @@ small ||= false route_args =[:admin, about.becomes(about.class.base_class)] %> <%= osuny_panel t('internationalization.label'), small: small do %> -
      +
        <% about.available_languages.each do |language| %> <% label = language_name(language.iso_code) current = language.id == about.language_id %> -
      • <%= link_to_unless current, label, [*route_args, lang: language.iso_code] %>
      • +
      • + <%= osuny_published about.exists_in_language?(language) %> + <%= link_to_unless current, label, [*route_args, lang: language.iso_code] %> + <% if current %> + + <% end %> +
      • <% end %> -
    + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/agenda/events/_list.html.erb b/app/views/admin/communication/websites/agenda/events/_list.html.erb index 20cf0800e0..460557870c 100644 --- a/app/views/admin/communication/websites/agenda/events/_list.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_list.html.erb @@ -10,7 +10,7 @@ small ||= false
    <%= osuny_thumbnail event %>
    - <%= osuny_published event unless small %> + <%= osuny_published event.published? unless small %> <%= link_to event, admin_communication_website_agenda_event_path(website_id: event.website.id, id: event.id), class: "stretched-link text-black" %> diff --git a/app/views/admin/communication/websites/pages/_list.html.erb b/app/views/admin/communication/websites/pages/_list.html.erb index f9c4a007ff..b8583ef1cd 100644 --- a/app/views/admin/communication/websites/pages/_list.html.erb +++ b/app/views/admin/communication/websites/pages/_list.html.erb @@ -7,7 +7,7 @@ small ||= false
    <%= osuny_thumbnail page %>
    - <%= osuny_published page %> + <%= osuny_published page.published? %> <%= link_to page, admin_communication_website_page_path(website_id: page.website.id, id: page.id), class: "stretched-link text-black" %> diff --git a/app/views/admin/communication/websites/pages/_treebranch.html.erb b/app/views/admin/communication/websites/pages/_treebranch.html.erb index 7ebedd398f..9f1f43393c 100644 --- a/app/views/admin/communication/websites/pages/_treebranch.html.erb +++ b/app/views/admin/communication/websites/pages/_treebranch.html.erb @@ -13,7 +13,7 @@ <% end %>
    - <%= osuny_published page %> + <%= osuny_published page.published? %> <%= link_to page, admin_communication_website_page_path(page), class: 'text-black' %> <% if page.children.any? %> (<%= page.children.count %>) diff --git a/app/views/admin/communication/websites/portfolio/projects/_list.html.erb b/app/views/admin/communication/websites/portfolio/projects/_list.html.erb index ca9e9a1510..b75d27515c 100644 --- a/app/views/admin/communication/websites/portfolio/projects/_list.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/_list.html.erb @@ -10,7 +10,7 @@ small ||= false
    <%= osuny_thumbnail project %>
    - <%= osuny_published project unless small %> + <%= osuny_published project.published? unless small %> <%= link_to project, admin_communication_website_portfolio_project_path(website_id: project.website.id, id: project.id), class: 'stretched-link text-black' %> diff --git a/app/views/admin/communication/websites/posts/_list.html.erb b/app/views/admin/communication/websites/posts/_list.html.erb index e834daea73..9abc37dbbe 100644 --- a/app/views/admin/communication/websites/posts/_list.html.erb +++ b/app/views/admin/communication/websites/posts/_list.html.erb @@ -36,7 +36,7 @@ end
    <%= osuny_thumbnail post %>
    - <%= osuny_published post unless small %> + <%= osuny_published post.published? unless small %> <%= link_to post, admin_communication_website_post_path(website_id: post.website.id, id: post.id), class: "stretched-link #{ post.published? ? 'text-black' : 'text-muted' }" %> diff --git a/app/views/admin/university/organizations/_list.html.erb b/app/views/admin/university/organizations/_list.html.erb index bc314e3bf7..674ea2ea50 100644 --- a/app/views/admin/university/organizations/_list.html.erb +++ b/app/views/admin/university/organizations/_list.html.erb @@ -2,6 +2,7 @@ <% organizations.each do |organization| %>
    + <%= osuny_published organization.is_in_language?(current_language) %> <%= osuny_thumbnail organization, large: true, cropped: false %> diff --git a/app/views/admin/university/people/_list.html.erb b/app/views/admin/university/people/_list.html.erb index 84593e7730..a653514369 100644 --- a/app/views/admin/university/people/_list.html.erb +++ b/app/views/admin/university/people/_list.html.erb @@ -1,9 +1,9 @@
    <% people.each do |person| %>
    -
    - <%= osuny_thumbnail person, - large: true %> +
    + <%= osuny_published person.is_in_language?(current_language) %> + <%= osuny_thumbnail person, large: true %>

    <%= link_to person, admin_university_person_path(person), diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb index b05d20decf..5ca68c7f23 100644 --- a/app/views/admin/university/people/_main_infos.html.erb +++ b/app/views/admin/university/people/_main_infos.html.erb @@ -1,4 +1,4 @@ -

    +
    <%= osuny_panel t('activerecord.attributes.university/person.picture'), small: true do %> diff --git a/app/views/admin/university/people/index.html.erb b/app/views/admin/university/people/index.html.erb index 9341a19a2f..3dfe62b806 100644 --- a/app/views/admin/university/people/index.html.erb +++ b/app/views/admin/university/people/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, "#{University::Person.model_name.human(count: 2)}" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= t('admin.elements', count: @people.total_count) %>

    <%= render 'filters', current_path: admin_university_people_path, filters: @filters if @filters.any? %> <%= render 'admin/university/people/list', people: @people %> @@ -18,6 +22,5 @@ <% end %> <% content_for :action_bar_right do %> - <%= render 'language_switcher' %> <%= create_link University::Person %> <% end %> From 4b5b09e3ef575f50df9a03a0d2df93630c7f2044 Mon Sep 17 00:00:00 2001 From: pabois Date: Fri, 14 Jun 2024 12:33:47 +0200 Subject: [PATCH 006/349] creation of person --- app/controllers/admin/university/people_controller.rb | 5 ++--- app/views/admin/university/people/_form.html.erb | 11 ++++++++++- config/locales/university/en.yml | 2 ++ config/locales/university/fr.yml | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index d2a1b819be..03c61f4d12 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -54,7 +54,7 @@ def static end def new - @person.language_id = current_university.default_language_id + @person.language_id = current_language.id breadcrumb end @@ -64,7 +64,6 @@ def edit end def create - @person.language_id = current_university.default_language_id if @person.save redirect_to admin_university_person_path(@person), notice: t('admin.successfully_created_html', model: @person.to_s) @@ -102,7 +101,7 @@ def breadcrumb def person_params params.require(:university_person).permit( - :slug, :first_name, :last_name, :email, :email_visibility, :gender, :birthdate, + :slug, :language_id, :first_name, :last_name, :email, :email_visibility, :gender, :birthdate, :phone_mobile, :phone_mobile_visibility, :phone_professional, :phone_professional_visibility, :phone_personal, :phone_personal_visibility, :address, :zipcode, :city, :country, :address_visibility, :meta_description, :summary, diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index ddbb461c6b..ecb9a06412 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -130,9 +130,18 @@ <%= render "admin/application/slug/form", f: f, source: '#university_person_first_name, #university_person_last_name' %> + <% unless person.persisted? %> + <% if current_university.languages.many? %> + <%= f.association :language, + collection: current_university.languages.ordered, + include_blank: false %> + <% else %> + <%= f.input :language_id, as: :hidden, wrapper: false %> + <% end %> + <% end %> <%= f.association :user, collection: current_university.users.ordered if can?(:manage, User) %> <% - categories = current_university.person_categories.for_language_id(person.language_id) + categories = current_university.person_categories.in_closest_language_id(current_language.id) if categories.any? %> <%= f.association :categories, diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index ac0fedbef3..d802208742 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -89,6 +89,7 @@ en: is_author: Author is_researcher: Researcher is_teacher: Teacher + language: Language last_name: Last name linkedin: LinkedIn URL linkedin_visibility: LinkedIn URL visibility @@ -203,6 +204,7 @@ en: is_author: "Writes posts for websites." is_researcher: "Writes papers for journals." is_teacher: "Teaches in Schools." + language: This is the language used for the different fields, not the language that the person speaks. linkedin: "Example: https://www.linkedin.com/in/osuny" mastodon: "Example: @osuny" personal_data_visibility: "Private: only visible in admin. Restricted: visible in the extranets. Public: visible in the websites." diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index f81e269b2d..1dacb36a44 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -89,6 +89,7 @@ fr: is_author: Auteur·rice is_researcher: Chercheur·e is_teacher: Enseignant·e + language: Langue last_name: Nom de famille linkedin: LinkedIn (URL) linkedin_visibility: Visibilité de l'URL LinkedIn @@ -203,6 +204,7 @@ fr: is_author: "Écrit des articles pour les sites." is_researcher: "Écrit des papiers dans des revues scientifiques." is_teacher: "Enseigne dans des formations." + language: Il s'agit de la langue utilisée dans les différents champs, pas de la langue que la personne parle. linkedin: "Exemple : https://www.linkedin.com/in/osuny" mastodon: "Exemple: @osuny" personal_data_visibility: "Privé : visible uniquement en admin. Restreint : visible sur les extranets. Public : visible sur les sites web." From 864cf868949ce8f5ad3cbf0c0c12707395347ed2 Mon Sep 17 00:00:00 2001 From: pabois Date: Fri, 14 Jun 2024 14:44:39 +0200 Subject: [PATCH 007/349] people categories --- .../university/people/categories_controller.rb | 17 ++++------------- .../admin/university/people_controller.rb | 4 ++-- .../admin/university/people/_form.html.erb | 9 --------- .../university/people/categories/index.html.erb | 4 ++++ config/locales/university/en.yml | 2 -- config/locales/university/fr.yml | 2 -- config/routes/admin/university.rb | 1 - 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/app/controllers/admin/university/people/categories_controller.rb b/app/controllers/admin/university/people/categories_controller.rb index 962b5af8e7..e155714f45 100644 --- a/app/controllers/admin/university/people/categories_controller.rb +++ b/app/controllers/admin/university/people/categories_controller.rb @@ -4,9 +4,12 @@ class Admin::University::People::CategoriesController < Admin::University::Appli through_association: :person_categories include Admin::Categorizable + include Admin::Translatable def index @root_categories = categories.root + .in_closest_language_id(current_language.id) + .ordered @categories_class = categories_class @feature_nav = 'navigation/admin/university/people' breadcrumb @@ -17,18 +20,6 @@ def show breadcrumb end - def in_language - language = Language.find_by!(iso_code: params[:lang]) - translation = @category.find_or_translate!(language) - if translation.newly_translated - # There's an attribute accessor named "newly_translated" that we set to true - # when we just created the translation. We use it to redirect to the form instead of the show. - redirect_to [:edit, :admin, translation.becomes(translation.class.base_class)] - else - redirect_to [:admin, translation.becomes(translation.class.base_class)] - end - end - def static @about = @category @website = @category.websites&.first @@ -45,7 +36,7 @@ def edit end def create - @category.language_id = current_university.default_language_id + @category.language_id = current_language.id if @category.save redirect_to admin_university_person_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s) diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 03c61f4d12..22f541660b 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -54,7 +54,6 @@ def static end def new - @person.language_id = current_language.id breadcrumb end @@ -64,6 +63,7 @@ def edit end def create + @person.language_id = current_language.id if @person.save redirect_to admin_university_person_path(@person), notice: t('admin.successfully_created_html', model: @person.to_s) @@ -101,7 +101,7 @@ def breadcrumb def person_params params.require(:university_person).permit( - :slug, :language_id, :first_name, :last_name, :email, :email_visibility, :gender, :birthdate, + :slug, :first_name, :last_name, :email, :email_visibility, :gender, :birthdate, :phone_mobile, :phone_mobile_visibility, :phone_professional, :phone_professional_visibility, :phone_personal, :phone_personal_visibility, :address, :zipcode, :city, :country, :address_visibility, :meta_description, :summary, diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index ecb9a06412..12a427a657 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -130,15 +130,6 @@ <%= render "admin/application/slug/form", f: f, source: '#university_person_first_name, #university_person_last_name' %> - <% unless person.persisted? %> - <% if current_university.languages.many? %> - <%= f.association :language, - collection: current_university.languages.ordered, - include_blank: false %> - <% else %> - <%= f.input :language_id, as: :hidden, wrapper: false %> - <% end %> - <% end %> <%= f.association :user, collection: current_university.users.ordered if can?(:manage, User) %> <% categories = current_university.person_categories.in_closest_language_id(current_language.id) diff --git a/app/views/admin/university/people/categories/index.html.erb b/app/views/admin/university/people/categories/index.html.erb index fe22ddf519..9f522733ea 100644 --- a/app/views/admin/university/people/categories/index.html.erb +++ b/app/views/admin/university/people/categories/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Person::Category.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index d802208742..ac0fedbef3 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -89,7 +89,6 @@ en: is_author: Author is_researcher: Researcher is_teacher: Teacher - language: Language last_name: Last name linkedin: LinkedIn URL linkedin_visibility: LinkedIn URL visibility @@ -204,7 +203,6 @@ en: is_author: "Writes posts for websites." is_researcher: "Writes papers for journals." is_teacher: "Teaches in Schools." - language: This is the language used for the different fields, not the language that the person speaks. linkedin: "Example: https://www.linkedin.com/in/osuny" mastodon: "Example: @osuny" personal_data_visibility: "Private: only visible in admin. Restricted: visible in the extranets. Public: visible in the websites." diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index 1dacb36a44..f81e269b2d 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -89,7 +89,6 @@ fr: is_author: Auteur·rice is_researcher: Chercheur·e is_teacher: Enseignant·e - language: Langue last_name: Nom de famille linkedin: LinkedIn (URL) linkedin_visibility: Visibilité de l'URL LinkedIn @@ -204,7 +203,6 @@ fr: is_author: "Écrit des articles pour les sites." is_researcher: "Écrit des papiers dans des revues scientifiques." is_teacher: "Enseigne dans des formations." - language: Il s'agit de la langue utilisée dans les différents champs, pas de la langue que la personne parle. linkedin: "Exemple : https://www.linkedin.com/in/osuny" mastodon: "Exemple: @osuny" personal_data_visibility: "Privé : visible uniquement en admin. Restreint : visible sur les extranets. Public : visible sur les sites web." diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index 7ef5318162..52e35a6c62 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -33,7 +33,6 @@ member do get :children get :static - get "/translations/:lang" => "people/categories#in_language", as: :show_in_language end end end From 1fb95188b21a8c011e4ef01deec3a718d975edfe Mon Sep 17 00:00:00 2001 From: pabois Date: Fri, 14 Jun 2024 16:00:33 +0200 Subject: [PATCH 008/349] orga multilingues --- .../organizations/categories_controller.rb | 17 +++-------- .../university/organizations_controller.rb | 29 +++++-------------- .../admin/university/people_controller.rb | 7 +++-- .../university/organizations/_form.html.erb | 7 +++-- .../organizations/categories/index.html.erb | 4 +++ .../university/organizations/index.html.erb | 4 +++ .../admin/university/people/_form.html.erb | 7 +++-- config/routes/admin/university.rb | 4 +-- 8 files changed, 34 insertions(+), 45 deletions(-) diff --git a/app/controllers/admin/university/organizations/categories_controller.rb b/app/controllers/admin/university/organizations/categories_controller.rb index d9ac5e3767..1038526909 100644 --- a/app/controllers/admin/university/organizations/categories_controller.rb +++ b/app/controllers/admin/university/organizations/categories_controller.rb @@ -4,9 +4,12 @@ class Admin::University::Organizations::CategoriesController < Admin::University through_association: :organization_categories include Admin::Categorizable + include Admin::Translatable def index @root_categories = categories.root + .in_closest_language_id(current_language.id) + .ordered @categories_class = categories_class @feature_nav = 'navigation/admin/university/organizations' breadcrumb @@ -17,18 +20,6 @@ def show breadcrumb end - def in_language - language = Language.find_by!(iso_code: params[:lang]) - translation = @category.find_or_translate!(language) - if translation.newly_translated - # There's an attribute accessor named "newly_translated" that we set to true - # when we just created the translation. We use it to redirect to the form instead of the show. - redirect_to [:edit, :admin, translation.becomes(translation.class.base_class)] - else - redirect_to [:admin, translation.becomes(translation.class.base_class)] - end - end - def static @about = @category @website = @category.websites&.first @@ -45,7 +36,7 @@ def edit end def create - @category.language_id = current_university.default_language_id + @category.language_id = current_language.id if @category.save redirect_to admin_university_organization_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s) diff --git a/app/controllers/admin/university/organizations_controller.rb b/app/controllers/admin/university/organizations_controller.rb index cb565c84e8..f89f6e45db 100644 --- a/app/controllers/admin/university/organizations_controller.rb +++ b/app/controllers/admin/university/organizations_controller.rb @@ -3,13 +3,15 @@ class Admin::University::OrganizationsController < Admin::University::Applicatio through: :current_university, through_association: :organizations + include Admin::Translatable + has_scope :for_search_term has_scope :for_category has_scope :for_kind def index @organizations = apply_scopes(@organizations) - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .ordered @feature_nav = 'navigation/admin/university/organizations' @@ -28,32 +30,16 @@ def index def search @term = params[:term].to_s - language = Language.find_by(iso_code: params[:lang]) @organizations = current_university.organizations - .search_by_siren_or_name(@term) - .ordered - @organizations = @organizations.joins(:language) - .where(languages: { - iso_code: language.iso_code - }) if language.present? + .in_closest_language_id(current_language.id) + .search_by_siren_or_name(@term) + .ordered end def show breadcrumb end - def in_language - language = Language.find_by!(iso_code: params[:lang]) - translation = @organization.find_or_translate!(language) - if translation.newly_translated - # There's an attribute accessor named "newly_translated" that we set to true - # when we just created the translation. We use it to redirect to the form instead of the show. - redirect_to [:edit, :admin, translation.becomes(translation.class.base_class)] - else - redirect_to [:admin, translation.becomes(translation.class.base_class)] - end - end - def static @about = @organization @website = @organization.websites&.first @@ -61,7 +47,6 @@ def static end def new - @organization.language_id = current_university.default_language_id breadcrumb end @@ -71,7 +56,7 @@ def edit end def create - @organization.language_id = current_university.default_language_id + @organization.language_id = current_language.id if @organization.save redirect_to admin_university_organization_path(@organization), notice: t('admin.successfully_created_html', model: @organization.to_s) diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 22f541660b..62982531c7 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -30,9 +30,10 @@ def index def search @term = params[:term].to_s - language = Language.find_by(iso_code: params[:lang]) - @people = current_university.people.for_search_term(@term).ordered - @people = @people.joins(:language).where(languages: { iso_code: language.iso_code }) if language.present? + @people = current_university.people + .in_closest_language_id(current_language.id) + .for_search_term(@term) + .ordered end def show diff --git a/app/views/admin/university/organizations/_form.html.erb b/app/views/admin/university/organizations/_form.html.erb index ab8a52ab76..ee76f7e74d 100644 --- a/app/views/admin/university/organizations/_form.html.erb +++ b/app/views/admin/university/organizations/_form.html.erb @@ -78,12 +78,15 @@ source: '#university_organization_name' %> <%= f.input :active %> <% - categories = current_university.organization_categories.for_language_id(organization.language_id) + categories = current_university.organization_categories + .in_closest_language_id(current_language.id) + .root + .ordered if categories.any? %> <%= f.association :categories, as: :check_boxes, - collection: categories %> + collection: collection_tree_for_checkboxes(categories) %> <% end %> <% end %> <%= osuny_panel University::Organization.human_attribute_name('logos') do %> diff --git a/app/views/admin/university/organizations/categories/index.html.erb b/app/views/admin/university/organizations/categories/index.html.erb index 1c2bc665be..41cabb1cdf 100644 --- a/app/views/admin/university/organizations/categories/index.html.erb +++ b/app/views/admin/university/organizations/categories/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Organization::Category.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> diff --git a/app/views/admin/university/organizations/index.html.erb b/app/views/admin/university/organizations/index.html.erb index 1f159edd18..e6b37c770c 100644 --- a/app/views/admin/university/organizations/index.html.erb +++ b/app/views/admin/university/organizations/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Organization.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= t('admin.elements', count: @organizations.total_count) %>

    <%= render 'filters', current_path: admin_university_organizations_path, filters: @filters if @filters.any? %> <%= render 'admin/university/organizations/list', organizations: @organizations %> diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index 12a427a657..1815d34ecf 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -132,12 +132,15 @@ source: '#university_person_first_name, #university_person_last_name' %> <%= f.association :user, collection: current_university.users.ordered if can?(:manage, User) %> <% - categories = current_university.person_categories.in_closest_language_id(current_language.id) + categories = current_university.person_categories + .in_closest_language_id(current_language.id) + .root + .ordered if categories.any? %> <%= f.association :categories, as: :check_boxes, - collection: categories %> + collection: collection_tree_for_checkboxes(categories) %> <% end %> <% end %> <%= osuny_panel University::Person.human_attribute_name('picture') do %> diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index 52e35a6c62..c87a68ce93 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -43,7 +43,7 @@ end end - resources :organizations do + resources :organizations, path: '/:lang/organizations' do collection do get :search, defaults: { format: 'json' } resources :categories, controller: 'organizations/categories', as: 'organization_categories' do @@ -53,13 +53,11 @@ member do get :children get :static - get "/translations/:lang" => "organizations/categories#in_language", as: :show_in_language end end end member do get :static - get "/translations/:lang" => "organizations#in_language", as: :show_in_language end end root to: 'dashboard#index' From 339fcd3479da4eb4ae7780e8a9d1c1c8054b6c37 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Fri, 14 Jun 2024 16:34:38 +0200 Subject: [PATCH 009/349] switchers --- .../categories/_treebranch.html.erb | 1 + .../application/favorites/_widget.html.erb | 15 ++-- .../websites/_language_switcher.html.erb | 12 +-- .../websites/agenda/categories/index.html.erb | 6 +- .../websites/agenda/categories/show.html.erb | 4 + .../websites/agenda/events/index.html.erb | 6 +- .../websites/agenda/events/show.html.erb | 4 + .../websites/localizations/show.html.erb | 4 +- .../websites/menus/index.html.erb | 14 ++-- .../websites/menus/items/edit.html.erb | 4 + .../websites/menus/items/new.html.erb | 4 + .../websites/menus/items/show.html.erb | 18 ++--- .../websites/menus/show.html.erb | 30 ++++---- .../websites/pages/index.html.erb | 74 ++++++++++--------- .../websites/pages/index_list.html.erb | 53 ++++++------- .../websites/pages/show.html.erb | 4 + .../portfolio/categories/index.html.erb | 6 +- .../portfolio/categories/show.html.erb | 4 + .../portfolio/projects/index.html.erb | 6 +- .../websites/portfolio/projects/show.html.erb | 4 + .../websites/posts/authors/index.html.erb | 6 +- .../websites/posts/authors/show.html.erb | 4 + .../websites/posts/categories/index.html.erb | 6 +- .../websites/posts/categories/show.html.erb | 6 +- .../websites/posts/index.html.erb | 7 +- .../websites/posts/show.html.erb | 6 +- .../communication/websites/show.html.erb | 26 ++++--- .../organizations/categories/index.html.erb | 4 + .../university/organizations/index.html.erb | 4 + .../university/organizations/show.html.erb | 1 + 30 files changed, 204 insertions(+), 139 deletions(-) diff --git a/app/views/admin/application/categories/_treebranch.html.erb b/app/views/admin/application/categories/_treebranch.html.erb index 5e237e5b4e..645725d00e 100644 --- a/app/views/admin/application/categories/_treebranch.html.erb +++ b/app/views/admin/application/categories/_treebranch.html.erb @@ -36,6 +36,7 @@ categories_class_path = categories_class.to_s.parameterize.underscore <%= osuny_thumbnail category %> <% end %>
    + <%= osuny_published category.is_in_language?(current_language) %> <%= link_to category, show_path, class: 'text-black' %> <% if category.children.any? %> (<%= category.children.count %>) diff --git a/app/views/admin/application/favorites/_widget.html.erb b/app/views/admin/application/favorites/_widget.html.erb index 727d4b3ae7..d32aae6d8f 100644 --- a/app/views/admin/application/favorites/_widget.html.erb +++ b/app/views/admin/application/favorites/_widget.html.erb @@ -1,22 +1,23 @@ -
    + <% if current_user.favorite?(about)%> <%= link_to admin_favorite_path( operation: :remove, about_id: about.id, about_type: about.class.polymorphic_name - ), method: :put do %> - <%= t 'user.favorites.remove' %> + ), + method: :put, + title: t('user.favorites.remove') do %> <% end %> - <% else %> <%= link_to admin_favorite_path( operation: :add, about_id: about.id, about_type: about.class.polymorphic_name - ), method: :put do %> - <%= t 'user.favorites.add' %> + ), + method: :put, + title: t('user.favorites.add') do %> <% end %> <% end %> -
    \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/communication/websites/_language_switcher.html.erb b/app/views/admin/communication/websites/_language_switcher.html.erb index 9985f49e80..b2041c6cc2 100644 --- a/app/views/admin/communication/websites/_language_switcher.html.erb +++ b/app/views/admin/communication/websites/_language_switcher.html.erb @@ -8,12 +8,8 @@ } selected_option = url_for(request.params.merge(lang: current_language.iso_code)) %> -
    -
    - <%= select_tag nil, - options_for_select(languages_options, selected_option), - class: "form-control form-select my-5", - id: "js-lang-switch" %> -
    -
    + <%= select_tag nil, + options_for_select(languages_options, selected_option), + class: "form-control form-select my-5", + id: "js-lang-switch" %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/agenda/categories/index.html.erb b/app/views/admin/communication/websites/agenda/categories/index.html.erb index 4f8fdd6d3c..dfc51092eb 100644 --- a/app/views/admin/communication/websites/agenda/categories/index.html.erb +++ b/app/views/admin/communication/websites/agenda/categories/index.html.erb @@ -1,11 +1,13 @@ <% content_for :title, "#{Communication::Website::Agenda::Category.model_name.human(count: 2)} (#{@categories.count})" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= create_link Communication::Website::Agenda::Category %> <% end %> diff --git a/app/views/admin/communication/websites/agenda/categories/show.html.erb b/app/views/admin/communication/websites/agenda/categories/show.html.erb index 8918deb443..0173e8b3d8 100644 --- a/app/views/admin/communication/websites/agenda/categories/show.html.erb +++ b/app/views/admin/communication/websites/agenda/categories/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @category %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    <%= render 'admin/application/summary/show', about: @category %> diff --git a/app/views/admin/communication/websites/agenda/events/index.html.erb b/app/views/admin/communication/websites/agenda/events/index.html.erb index 20b2580823..ed6b75d9a3 100644 --- a/app/views/admin/communication/websites/agenda/events/index.html.erb +++ b/app/views/admin/communication/websites/agenda/events/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, Communication::Website::Agenda::Event.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= @events.total_count %> <%= Communication::Website::Agenda::Event.model_name.human(count: @events.total_count).downcase %> @@ -9,8 +13,6 @@ <%= render 'admin/communication/websites/agenda/events/list', events: @events %> <%= paginate @events %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= create_link Communication::Website::Agenda::Event %> <% end %> diff --git a/app/views/admin/communication/websites/agenda/events/show.html.erb b/app/views/admin/communication/websites/agenda/events/show.html.erb index 5da93939f4..1f302537db 100644 --- a/app/views/admin/communication/websites/agenda/events/show.html.erb +++ b/app/views/admin/communication/websites/agenda/events/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @event %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= osuny_panel Communication::Website::Agenda::Event.human_attribute_name(:title), small: true do %> diff --git a/app/views/admin/communication/websites/localizations/show.html.erb b/app/views/admin/communication/websites/localizations/show.html.erb index 10241ae5a8..4a5a0914c8 100644 --- a/app/views/admin/communication/websites/localizations/show.html.erb +++ b/app/views/admin/communication/websites/localizations/show.html.erb @@ -1,6 +1,8 @@ <% content_for :title, "#{t('admin.communication.website.localizations.title')}" %> -<%= render 'admin/communication/websites/language_switcher' %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> <%= simple_form_for [:admin, @localization], as: :communication_website_localization, url: admin_communication_website_localization_path do |f| %> <%= f.error_notification %> diff --git a/app/views/admin/communication/websites/menus/index.html.erb b/app/views/admin/communication/websites/menus/index.html.erb index ddbe771152..30335db825 100644 --- a/app/views/admin/communication/websites/menus/index.html.erb +++ b/app/views/admin/communication/websites/menus/index.html.erb @@ -1,13 +1,15 @@ <% content_for :title, Communication::Website::Menu.model_name.human(count: 2) %> <% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + +

    <%= @menus.count %> <%= Communication::Website::Menu.model_name.human(count: @menus.count).downcase %> -<% end %> +

    +<%= render 'admin/communication/websites/menus/list', menus: @menus %> -<%= osuny_panel Communication::Website::Menu.model_name.human(count: 2), - action: create_link(Communication::Website::Menu) do %> - <%= render 'admin/communication/websites/menus/list', menus: @menus %> +<% content_for :action_bar_right do %> + <%= create_link Communication::Website::Menu %> <% end %> - -<%= render 'admin/communication/websites/language_switcher' %> diff --git a/app/views/admin/communication/websites/menus/items/edit.html.erb b/app/views/admin/communication/websites/menus/items/edit.html.erb index 5bcb312388..4a83f13567 100644 --- a/app/views/admin/communication/websites/menus/items/edit.html.erb +++ b/app/views/admin/communication/websites/menus/items/edit.html.erb @@ -1,3 +1,7 @@ <% content_for :title, @item %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'form', item: @item %> diff --git a/app/views/admin/communication/websites/menus/items/new.html.erb b/app/views/admin/communication/websites/menus/items/new.html.erb index 6f5acfa832..8d5395c2ee 100644 --- a/app/views/admin/communication/websites/menus/items/new.html.erb +++ b/app/views/admin/communication/websites/menus/items/new.html.erb @@ -1,3 +1,7 @@ <% content_for :title, Communication::Website::Menu::Item.model_name.human %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'form', item: @item %> diff --git a/app/views/admin/communication/websites/menus/items/show.html.erb b/app/views/admin/communication/websites/menus/items/show.html.erb index d6c48f2f13..e3de80a8f1 100644 --- a/app/views/admin/communication/websites/menus/items/show.html.erb +++ b/app/views/admin/communication/websites/menus/items/show.html.erb @@ -1,15 +1,12 @@ <% content_for :title, @item %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    - <% - action = link_to t('create'), - new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id, parent_id: @item.id), - class: button_classes if can?(:create, Communication::Website::Menu::Item) - %> - <%= osuny_panel Communication::Website::Menu::Item.human_attribute_name('children'), action: action do %> - <%= render 'admin/communication/websites/menus/items/list', items: @children, item: @item if @children.any? %> - <% end %> + <%= render 'admin/communication/websites/menus/items/list', items: @children, item: @item if @children.any? %>
    <%= osuny_panel t('metadata') do %> @@ -26,8 +23,6 @@
    -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_left do %> <%= link_to t('delete'), admin_communication_website_menu_item_path(website_id: @item.website.id, menu_id: @item.menu.id, id: @item.id), @@ -40,4 +35,7 @@ <%= link_to t('edit'), edit_admin_communication_website_menu_item_path(@item, website_id: @website, menu_id: @menu.id), class: button_classes %> + <%= link_to t('create'), + new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id, parent_id: @item.id), + class: button_classes if can?(:create, Communication::Website::Menu::Item) %> <% end %> diff --git a/app/views/admin/communication/websites/menus/show.html.erb b/app/views/admin/communication/websites/menus/show.html.erb index aa8d097dc1..ec3e8509be 100644 --- a/app/views/admin/communication/websites/menus/show.html.erb +++ b/app/views/admin/communication/websites/menus/show.html.erb @@ -1,22 +1,19 @@ <% content_for :title, @menu %> -<% -action = '' -action += link_to t('create'), - new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), - class: button_classes if can?(:create, Communication::Website::Menu::Item) %> -<%= osuny_panel Communication::Website::Menu::Item.model_name.human(count: 2), action: action do %> - <% if @menu.automatic %> -
    - - <%= Communication::Website::Menu.human_attribute_name('automatic') %> - -

    <%= sanitize t('communication.website.menus.automatic') %>

    -
    - <% end %> - <%= render 'admin/communication/websites/menus/items/list', items: @root_items if @items.any? %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> <% end %> +<% if @menu.automatic %> +
    + + <%= Communication::Website::Menu.human_attribute_name('automatic') %> + +

    <%= sanitize t('communication.website.menus.automatic') %>

    +
    +<% end %> +<%= render 'admin/communication/websites/menus/items/list', items: @root_items if @items.any? %> + <% content_for :action_bar_left do %> <%= destroy_link @menu %> <%= static_link static_admin_communication_website_menu_path(@menu) %> @@ -24,4 +21,7 @@ action += link_to t('create'), <% content_for :action_bar_right do %> <%= edit_link @menu %> + <%= link_to t('create'), + new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), + class: button_classes if can?(:create, Communication::Website::Menu::Item) %> <% end %> diff --git a/app/views/admin/communication/websites/pages/index.html.erb b/app/views/admin/communication/websites/pages/index.html.erb index 50b46f3251..15894d8a25 100644 --- a/app/views/admin/communication/websites/pages/index.html.erb +++ b/app/views/admin/communication/websites/pages/index.html.erb @@ -1,43 +1,45 @@ <% content_for :title, t('admin.communication.website.subnav.structure') %> <% content_for :title_right do %> - <%= @pages.size %> - <%= Communication::Website::Page.model_name.human(count: @pages.size).downcase %> + <%= render 'language_switcher' %> <% end %> -<%= osuny_panel t('admin.communication.website.pages.structure'), - action: create_link(Communication::Website::Page) do %> - -
      -
    • -
      - <%= osuny_thumbnail @homepage %> -
      - <%= link_to @homepage, admin_communication_website_page_path(@homepage), class: 'text-black' %> -
      +

      + <%= @pages.size %> + <%= Communication::Website::Page.model_name.human(count: @pages.size).downcase %> +

      + +
        +
      • +
        + <%= osuny_thumbnail @homepage %> +
        + <%= link_to @homepage, admin_communication_website_page_path(@homepage), class: 'text-black' %>
        -
          - <%= render 'treebranch', pages: @first_level_pages %> -
        -
      • -
      -<% end %> +
      +
        + <%= render 'treebranch', pages: @first_level_pages %> +
      +
    • +
    -<%= render 'admin/communication/websites/language_switcher' %> +<% content_for :action_bar_right do %> + <%= create_link Communication::Website::Page %> +<% end %> diff --git a/app/views/admin/communication/websites/pages/index_list.html.erb b/app/views/admin/communication/websites/pages/index_list.html.erb index 578804532b..af6ee0ccda 100644 --- a/app/views/admin/communication/websites/pages/index_list.html.erb +++ b/app/views/admin/communication/websites/pages/index_list.html.erb @@ -1,32 +1,35 @@ <% content_for :title, t('admin.communication.website.pages.structure') %> <% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + +

    <%= @pages.total_count %> <%= Communication::Website::Page.model_name.human(count: @pages.total_count).downcase %> -<% end %> +

    -<%= osuny_panel t('admin.communication.website.pages.structure'), - action: create_link(Communication::Website::Page) do %> - -
    -

     

    <%# Hack idiot pour le bon affichage des filtres %> - <%= render 'filters', current_path: list_admin_communication_website_pages_path, filters: @filters %> - <%= render 'admin/communication/websites/pages/list', pages: @pages %> - <%= paginate @pages %> -
    -<% end %> + +
    +

     

    <%# Hack idiot pour le bon affichage des filtres %> + <%= render 'filters', current_path: list_admin_communication_website_pages_path, filters: @filters %> + <%= render 'admin/communication/websites/pages/list', pages: @pages %> + <%= paginate @pages %> +
    -<%= render 'admin/communication/websites/language_switcher' %> +<% content_for :action_bar_right do %> + <%= create_link Communication::Website::Page %> +<% end %> diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index da85dbf426..fa90bc39d7 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @page %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    <%= osuny_panel Communication::Website::Page.human_attribute_name(:title), small: true do %> diff --git a/app/views/admin/communication/websites/portfolio/categories/index.html.erb b/app/views/admin/communication/websites/portfolio/categories/index.html.erb index f09b12893c..544a5d2161 100644 --- a/app/views/admin/communication/websites/portfolio/categories/index.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/index.html.erb @@ -1,11 +1,13 @@ <% content_for :title, "#{Communication::Website::Portfolio::Category.model_name.human(count: 2)} (#{@categories.count})" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= create_link Communication::Website::Portfolio::Category %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/portfolio/categories/show.html.erb b/app/views/admin/communication/websites/portfolio/categories/show.html.erb index 5016a2fcb0..9a72207c4e 100644 --- a/app/views/admin/communication/websites/portfolio/categories/show.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @category %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    <%= render 'admin/application/summary/show', about: @category %> diff --git a/app/views/admin/communication/websites/portfolio/projects/index.html.erb b/app/views/admin/communication/websites/portfolio/projects/index.html.erb index de7b4b1ee2..f19e8362c6 100644 --- a/app/views/admin/communication/websites/portfolio/projects/index.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, Communication::Website::Portfolio::Project.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= @projects.total_count %> <%= Communication::Website::Portfolio::Project.model_name.human(count: @projects.total_count).downcase %> @@ -8,8 +12,6 @@ <%= render 'admin/communication/websites/portfolio/projects/list', projects: @projects %> <%= paginate @projects %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= create_link Communication::Website::Portfolio::Project %> <% end %> diff --git a/app/views/admin/communication/websites/portfolio/projects/show.html.erb b/app/views/admin/communication/websites/portfolio/projects/show.html.erb index 713d93ea22..004350114b 100644 --- a/app/views/admin/communication/websites/portfolio/projects/show.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @project %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= osuny_panel Communication::Website::Portfolio::Project.human_attribute_name(:title), small: true do %> diff --git a/app/views/admin/communication/websites/posts/authors/index.html.erb b/app/views/admin/communication/websites/posts/authors/index.html.erb index be0d30dfc9..8047d50b62 100644 --- a/app/views/admin/communication/websites/posts/authors/index.html.erb +++ b/app/views/admin/communication/websites/posts/authors/index.html.erb @@ -1,11 +1,13 @@ <% content_for :title, "#{t('communication.authors', count: 2)} (#{@authors.total_count})" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'filters', current_path: admin_communication_website_post_authors_path, filters: @filters if @filters.any? %> <%= render 'admin/communication/websites/posts/authors/list', authors: @authors %> <%= paginate @authors %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= link_to t('communication.manage_authors'), admin_university_people_path, class: button_classes if can?(:read, University::Person) %> <% end %> diff --git a/app/views/admin/communication/websites/posts/authors/show.html.erb b/app/views/admin/communication/websites/posts/authors/show.html.erb index 628301b24a..ff4453401a 100644 --- a/app/views/admin/communication/websites/posts/authors/show.html.erb +++ b/app/views/admin/communication/websites/posts/authors/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @author %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/university/people/main_infos', person: @author %> <% if @posts.any? %> diff --git a/app/views/admin/communication/websites/posts/categories/index.html.erb b/app/views/admin/communication/websites/posts/categories/index.html.erb index fabd2ff239..a85950acb4 100644 --- a/app/views/admin/communication/websites/posts/categories/index.html.erb +++ b/app/views/admin/communication/websites/posts/categories/index.html.erb @@ -1,11 +1,13 @@ <% content_for :title, "#{Communication::Website::Post::Category.model_name.human(count: 2)} (#{@categories.count})" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_right do %> <%= create_link Communication::Website::Post::Category %> <% end %> diff --git a/app/views/admin/communication/websites/posts/categories/show.html.erb b/app/views/admin/communication/websites/posts/categories/show.html.erb index b0c21a0b5a..d51fe48698 100644 --- a/app/views/admin/communication/websites/posts/categories/show.html.erb +++ b/app/views/admin/communication/websites/posts/categories/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @category %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    <%= render 'admin/application/summary/show', about: @category %> @@ -43,8 +47,6 @@ <% end %> <% end %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_left do %> <%= destroy_link @category %> <%= static_link static_admin_communication_website_post_category_path(@category) %> diff --git a/app/views/admin/communication/websites/posts/index.html.erb b/app/views/admin/communication/websites/posts/index.html.erb index 557c5a11f1..b29e37504f 100644 --- a/app/views/admin/communication/websites/posts/index.html.erb +++ b/app/views/admin/communication/websites/posts/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, "#{Communication::Website::Post.model_name.human(count: 2)}" %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= @posts.total_count %> <%= Communication::Website::Post.model_name.human(count: @posts.total_count).downcase %> @@ -31,9 +35,6 @@ <% end %>

    -<%= render 'admin/communication/websites/language_switcher' %> - - <% content_for :action_bar_left do %> <%= link_to t('communication.website.posts.new_curation'), new_admin_communication_website_post_curation_path(website_id: @website.id), diff --git a/app/views/admin/communication/websites/posts/show.html.erb b/app/views/admin/communication/websites/posts/show.html.erb index 3539d28a76..502c70f0d5 100644 --- a/app/views/admin/communication/websites/posts/show.html.erb +++ b/app/views/admin/communication/websites/posts/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @post %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +
    <%= osuny_panel Communication::Website::Post.human_attribute_name(:title), small: true do %> @@ -25,8 +29,6 @@
    <%= render 'admin/communication/blocks/content/editor', about: @post %> -<%= render 'admin/communication/websites/language_switcher' %> - <% content_for :action_bar_left do %> <%= destroy_link @post %> <%= duplicate_link @post %> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index b7d4430cba..325bd0320e 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -1,16 +1,20 @@ <% content_for :title, @website %> -<% content_for :title_right do %> - <% unless @website.url.blank? %> - <%= link_to @website.url, @website.url, target: :_blank %>
    - <% end %> - <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %> - <% if @website.about %> - (<%= link_to_if can?(:read, @website.about), - @website.about, - [:admin, @website.about] unless @website.about.nil? %>) - <% end %> +<% content_for :title_left do %> <%= render 'admin/application/favorites/widget', about: @website %> + <%= link_to @website.url, @website.url, target: :_blank unless @website.url.blank? %> +
    + <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %> + <% if @website.about %> + (<%= link_to_if can?(:read, @website.about), + @website.about, + [:admin, @website.about] unless @website.about.nil? %>) + <% end %> +
    +<% end %> + +<% content_for :title_right do %> + <%= render 'language_switcher' %> <% end %> <% @@ -40,8 +44,6 @@ number_of_panels = 0
    -<%= render 'admin/communication/websites/language_switcher' %> - <%= image_tag @website.deployment_status_badge, alt: '' if @website.deployment_status_badge.present? %> <% content_for :action_bar_left do %> diff --git a/app/views/admin/university/organizations/categories/index.html.erb b/app/views/admin/university/organizations/categories/index.html.erb index 1c2bc665be..41cabb1cdf 100644 --- a/app/views/admin/university/organizations/categories/index.html.erb +++ b/app/views/admin/university/organizations/categories/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Organization::Category.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/application/categories/list', root_categories: @root_categories, categories_class: @categories_class %> diff --git a/app/views/admin/university/organizations/index.html.erb b/app/views/admin/university/organizations/index.html.erb index 1f159edd18..e6b37c770c 100644 --- a/app/views/admin/university/organizations/index.html.erb +++ b/app/views/admin/university/organizations/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Organization.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> +

    <%= t('admin.elements', count: @organizations.total_count) %>

    <%= render 'filters', current_path: admin_university_organizations_path, filters: @filters if @filters.any? %> <%= render 'admin/university/organizations/list', organizations: @organizations %> diff --git a/app/views/admin/university/organizations/show.html.erb b/app/views/admin/university/organizations/show.html.erb index 0b70bb3bc2..a318ec193c 100644 --- a/app/views/admin/university/organizations/show.html.erb +++ b/app/views/admin/university/organizations/show.html.erb @@ -1,4 +1,5 @@ <% content_for :title, @organization %> +
    <%= render 'admin/application/summary/show', about: @organization %> From aa3269d646d11b6fb86c5e523436b690bacf30b2 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Fri, 14 Jun 2024 16:52:25 +0200 Subject: [PATCH 010/349] widgets --- .../websites/agenda/events/show/_metadata.html.erb | 3 +-- .../admin/communication/websites/menus/items/show.html.erb | 4 ---- app/views/admin/communication/websites/pages/show.html.erb | 4 ---- .../communication/websites/pages/show/_metadata.html.erb | 6 ++---- .../websites/portfolio/projects/show/_metadata.html.erb | 2 +- .../communication/websites/posts/categories/show.html.erb | 4 ---- app/views/admin/communication/websites/posts/show.html.erb | 4 ---- .../communication/websites/posts/show/_metadata.html.erb | 6 ++---- 8 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/views/admin/communication/websites/agenda/events/show/_metadata.html.erb b/app/views/admin/communication/websites/agenda/events/show/_metadata.html.erb index da72152d5a..92c854bbeb 100644 --- a/app/views/admin/communication/websites/agenda/events/show/_metadata.html.erb +++ b/app/views/admin/communication/websites/agenda/events/show/_metadata.html.erb @@ -1,8 +1,6 @@ <%= osuny_panel t('metadata'), small: true do %> <%= @event.published ? Communication::Website::Agenda::Event.human_attribute_name(:published) : t('admin.communication.website.agenda.events.draft') %> - - <%= render 'admin/application/i18n/inline', about: @event %> <% if @event.categories.any? %> <%= t( 'admin.communication.website.posts.in', @@ -11,3 +9,4 @@ <% end %> <%= render 'admin/application/permalinks/redirects', about: @event %> <% end %> +<%= render 'admin/application/i18n/widget', about: @event, small: true %> diff --git a/app/views/admin/communication/websites/menus/items/show.html.erb b/app/views/admin/communication/websites/menus/items/show.html.erb index e3de80a8f1..361f37fe45 100644 --- a/app/views/admin/communication/websites/menus/items/show.html.erb +++ b/app/views/admin/communication/websites/menus/items/show.html.erb @@ -1,9 +1,5 @@ <% content_for :title, @item %> -<% content_for :title_right do %> - <%= render 'language_switcher' %> -<% end %> -
    <%= render 'admin/communication/websites/menus/items/list', items: @children, item: @item if @children.any? %> diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index fa90bc39d7..da85dbf426 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -1,9 +1,5 @@ <% content_for :title, @page %> -<% content_for :title_right do %> - <%= render 'language_switcher' %> -<% end %> -
    <%= osuny_panel Communication::Website::Page.human_attribute_name(:title), small: true do %> diff --git a/app/views/admin/communication/websites/pages/show/_metadata.html.erb b/app/views/admin/communication/websites/pages/show/_metadata.html.erb index f9ace3254b..17fa20ed55 100644 --- a/app/views/admin/communication/websites/pages/show/_metadata.html.erb +++ b/app/views/admin/communication/websites/pages/show/_metadata.html.erb @@ -10,8 +10,6 @@ <%= @page.published ? t('admin.communication.website.pages.published') : t('admin.communication.website.pages.draft') %> - <%= render 'admin/application/i18n/inline', about: @page %> - <%= t('admin.communication.website.pages.in_full_width') if @page.full_width %> <% if @page.parent && !@page.parent.is_home? %> @@ -34,7 +32,7 @@ }.join(', ') %> <% end %> -

    - +

    <%= render 'admin/application/permalinks/redirects', about: @page %> <% end %> +<%= render 'admin/application/i18n/widget', about: @page, small: true %> diff --git a/app/views/admin/communication/websites/portfolio/projects/show/_metadata.html.erb b/app/views/admin/communication/websites/portfolio/projects/show/_metadata.html.erb index 54bb65fff1..083cfe6cda 100644 --- a/app/views/admin/communication/websites/portfolio/projects/show/_metadata.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/show/_metadata.html.erb @@ -2,7 +2,6 @@ <%= @project.published ? Communication::Website::Agenda::Event.human_attribute_name(:published) : t('admin.communication.website.agenda.projects.draft') %> - <%= render 'admin/application/i18n/inline', about: @project %> <% if @project.categories.any? %> <%= t( 'admin.communication.website.posts.in', @@ -11,3 +10,4 @@ <% end %> <%= render 'admin/application/permalinks/redirects', about: @project %> <% end %> +<%= render 'admin/application/i18n/widget', about: @project, small: true %> diff --git a/app/views/admin/communication/websites/posts/categories/show.html.erb b/app/views/admin/communication/websites/posts/categories/show.html.erb index d51fe48698..5bb7fbc3c9 100644 --- a/app/views/admin/communication/websites/posts/categories/show.html.erb +++ b/app/views/admin/communication/websites/posts/categories/show.html.erb @@ -1,9 +1,5 @@ <% content_for :title, @category %> -<% content_for :title_right do %> - <%= render 'language_switcher' %> -<% end %> -
    <%= render 'admin/application/summary/show', about: @category %> diff --git a/app/views/admin/communication/websites/posts/show.html.erb b/app/views/admin/communication/websites/posts/show.html.erb index 502c70f0d5..78c436082f 100644 --- a/app/views/admin/communication/websites/posts/show.html.erb +++ b/app/views/admin/communication/websites/posts/show.html.erb @@ -1,9 +1,5 @@ <% content_for :title, @post %> -<% content_for :title_right do %> - <%= render 'language_switcher' %> -<% end %> -
    <%= osuny_panel Communication::Website::Post.human_attribute_name(:title), small: true do %> diff --git a/app/views/admin/communication/websites/posts/show/_metadata.html.erb b/app/views/admin/communication/websites/posts/show/_metadata.html.erb index 3f4a523704..f5ab63f024 100644 --- a/app/views/admin/communication/websites/posts/show/_metadata.html.erb +++ b/app/views/admin/communication/websites/posts/show/_metadata.html.erb @@ -9,13 +9,11 @@ <%= t('admin.communication.website.posts.by', author: @post.author) if @post.author %> - <%= render 'admin/application/i18n/inline', about: @post %> - <% if @post.categories.any? %> <% categories = @post.categories.collect(&:to_s).join(', ') %> <%= t('admin.communication.website.posts.in', categories: categories) %> <% end %>

    - <%= render 'admin/application/permalinks/redirects', about: @post %> -<% end %> \ No newline at end of file +<% end %> +<%= render 'admin/application/i18n/widget', about: @post, small: true %> \ No newline at end of file From 9b6a4a91e119a47bd60eca4e77ad913a44e97f17 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 11:23:07 +0200 Subject: [PATCH 011/349] post authors & blocks for people and orgas --- app/models/communication/block/component/organization.rb | 8 +++++++- .../block/component/organization_category.rb | 8 +++++++- app/models/communication/block/component/person.rb | 8 +++++++- .../communication/block/component/person_category.rb | 8 +++++++- app/models/communication/website/post.rb | 8 +++++++- .../blocks/components/organization/_edit.html.erb | 4 ++-- .../components/organization_category/_edit.html.erb | 5 ++++- .../communication/blocks/components/person/_edit.html.erb | 4 +++- .../blocks/components/person_category/_edit.html.erb | 5 ++++- .../admin/communication/websites/posts/_form.html.erb | 2 +- 10 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/models/communication/block/component/organization.rb b/app/models/communication/block/component/organization.rb index e0bdfce273..5f188662ed 100644 --- a/app/models/communication/block/component/organization.rb +++ b/app/models/communication/block/component/organization.rb @@ -1,5 +1,11 @@ class Communication::Block::Component::Organization < Communication::Block::Component::Base + def data=(value) + super(value) + # Calling translate! will make sure that the organization's language matches the block's language. + translate! + end + def organization template.block .university @@ -12,7 +18,7 @@ def dependencies end def translate! - return unless organization.present? + return unless organization.present? && organization.language_id != template.language.id @data = organization.find_or_translate!(template.language).id end diff --git a/app/models/communication/block/component/organization_category.rb b/app/models/communication/block/component/organization_category.rb index de8fccf4e3..883d9458f2 100644 --- a/app/models/communication/block/component/organization_category.rb +++ b/app/models/communication/block/component/organization_category.rb @@ -1,5 +1,11 @@ class Communication::Block::Component::OrganizationCategory < Communication::Block::Component::Base + def data=(value) + super(value) + # Calling translate! will make sure that the category's language matches the block's language. + translate! + end + def categories university.organization_categories end @@ -13,7 +19,7 @@ def dependencies end def translate! - return unless category.present? + return unless category.present? && category.language_id != template.language.id @data = category.find_or_translate!(template.language).id end diff --git a/app/models/communication/block/component/person.rb b/app/models/communication/block/component/person.rb index 635ceabb8c..7320db9001 100644 --- a/app/models/communication/block/component/person.rb +++ b/app/models/communication/block/component/person.rb @@ -1,5 +1,11 @@ class Communication::Block::Component::Person < Communication::Block::Component::Base + def data=(value) + super(value) + # Calling translate! will make sure that the person's language matches the block's language. + translate! + end + def person template.block .university @@ -12,7 +18,7 @@ def dependencies end def translate! - return unless person.present? + return unless person.present? && person.language_id != template.language.id @data = person.find_or_translate!(template.language).id end diff --git a/app/models/communication/block/component/person_category.rb b/app/models/communication/block/component/person_category.rb index 088aa5dc29..66d5d26a30 100644 --- a/app/models/communication/block/component/person_category.rb +++ b/app/models/communication/block/component/person_category.rb @@ -1,5 +1,11 @@ class Communication::Block::Component::PersonCategory < Communication::Block::Component::Base + def data=(value) + super(value) + # Calling translate! will make sure that the category's language matches the block's language. + translate! + end + def categories university.person_categories end @@ -13,7 +19,7 @@ def dependencies end def translate! - return unless category.present? + return unless category.present? && category.language_id != template.language.id @data = category.find_or_translate!(template.language).id end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 88cc75b523..485d3e17fc 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,7 +68,7 @@ class Communication::Website::Post < ApplicationRecord validates :title, presence: true - before_validation :set_published_at + before_validation :set_published_at, :ensure_authors_are_in_correct_language after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id? scope :published, -> { @@ -175,6 +175,12 @@ def inherited_blob_ids [best_featured_image&.blob_id] end + def ensure_authors_are_in_correct_language + return unless author.present? && author.language_id != language_id + author_in_correct_language = author.find_or_translate!(language) + self.author_id = author_in_correct_language.id + end + def update_authors_statuses! old_author = University::Person.find_by(id: author_id_before_last_save) if old_author && old_author.communication_website_posts.none? diff --git a/app/views/admin/communication/blocks/components/organization/_edit.html.erb b/app/views/admin/communication/blocks/components/organization/_edit.html.erb index 3d2a0a7e23..79e8572ef2 100644 --- a/app/views/admin/communication/blocks/components/organization/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/organization/_edit.html.erb @@ -1,6 +1,6 @@ <% organizations = current_university.organizations - .for_language(block.language) - .ordered %> + .in_closest_language_id(block.language.id) + .ordered %> <% unless label.blank? %>
    <% content_for :action_bar_right do %> diff --git a/app/views/admin/administration/locations/index.html.erb b/app/views/admin/administration/locations/index.html.erb index 880744fed1..ba1aaa512a 100644 --- a/app/views/admin/administration/locations/index.html.erb +++ b/app/views/admin/administration/locations/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, Administration::Location.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/administration/locations/list', locations: @locations %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/administration/locations/show.html.erb b/app/views/admin/administration/locations/show.html.erb index 70cf7eccf7..436b424180 100644 --- a/app/views/admin/administration/locations/show.html.erb +++ b/app/views/admin/administration/locations/show.html.erb @@ -81,6 +81,8 @@ <% end %>
    +<%= render 'admin/application/i18n/widget', about: @location, small: true %> + <%= render 'admin/communication/blocks/content/editor', about: @location %> <%= render 'admin/application/connections/list', about: @location %> diff --git a/app/views/admin/education/diplomas/index.html.erb b/app/views/admin/education/diplomas/index.html.erb index 98c19f66ff..acfe2c624b 100644 --- a/app/views/admin/education/diplomas/index.html.erb +++ b/app/views/admin/education/diplomas/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, Education::Diploma.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/education/diplomas/list', diplomas: @diplomas %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/education/diplomas/show.html.erb b/app/views/admin/education/diplomas/show.html.erb index d520bc6470..c8e9cb0c7d 100644 --- a/app/views/admin/education/diplomas/show.html.erb +++ b/app/views/admin/education/diplomas/show.html.erb @@ -50,6 +50,8 @@
    +<%= render 'admin/application/i18n/widget', about: @diploma, small: true %> + <% content_for :action_bar_left do %> <%= destroy_link @diploma %> <%= static_link static_admin_education_diploma_path(@diploma) %> diff --git a/app/views/admin/education/programs/index.html.erb b/app/views/admin/education/programs/index.html.erb index cca9c40bca..b3da256c83 100644 --- a/app/views/admin/education/programs/index.html.erb +++ b/app/views/admin/education/programs/index.html.erb @@ -4,6 +4,10 @@ current_path: admin_education_programs_path, filters: @filters if @filters.any? %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'admin/education/programs/list', programs: @programs %> <%= paginate @programs %> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index b280c7e39c..20f8b4bbfa 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -21,6 +21,10 @@ <%= osuny_separator %> <%= render 'admin/application/a11y/widget', about: @program, horizontal: true %> +<%= osuny_separator %> +<%= render 'admin/application/i18n/widget', about: @program, small: true %> + + <%= osuny_separator %>
    diff --git a/app/views/admin/education/teachers/_involvement_fields.html.erb b/app/views/admin/education/teachers/_involvement_fields.html.erb index 0419b3e642..0fc7ce2ae2 100644 --- a/app/views/admin/education/teachers/_involvement_fields.html.erb +++ b/app/views/admin/education/teachers/_involvement_fields.html.erb @@ -6,7 +6,11 @@
    <%= f.hidden_field :target_type, value: "Education::Program" %> <%= f.association :target, - collection: collection_tree(current_university.education_programs), + collection: collection_tree( + current_university.education_programs + .in_closest_language_id(current_language.id) + .ordered + ), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] }, label: false, diff --git a/app/views/admin/education/teachers/index.html.erb b/app/views/admin/education/teachers/index.html.erb index 637b185d43..bbe35c163b 100644 --- a/app/views/admin/education/teachers/index.html.erb +++ b/app/views/admin/education/teachers/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, University::Person::Teacher.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'filters', current_path: admin_education_teachers_path, filters: @filters if @filters.any? %> <%= render 'admin/education/teachers/list', teachers: @teachers %> diff --git a/config/routes/admin/administration.rb b/config/routes/admin/administration.rb index e4dd1801df..693207f79e 100644 --- a/config/routes/admin/administration.rb +++ b/config/routes/admin/administration.rb @@ -1,5 +1,5 @@ namespace :administration do - resources :locations do + resources :locations, path: '/:lang/locations' do member do get :static end diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index e8faefb744..c4c1200aca 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -1,6 +1,6 @@ namespace :education do - resources :teachers, only: [:index, :show, :edit, :update] - resources :schools do + resources :teachers, only: [:index, :show, :edit, :update], path: '/:lang/teachers' + resources :schools, path: '/:lang/schools' do resources :roles, controller: 'schools/roles' do resources :people, controller: 'schools/roles/people', only: [:destroy] do post :reorder, on: :collection @@ -10,7 +10,7 @@ end end end - resources :programs do + resources :programs, path: '/:lang/programs' do resources :roles, controller: 'programs/roles' do resources :people, controller: 'programs/role/people', only: [:destroy] do post :reorder, on: :collection @@ -36,7 +36,7 @@ end resources :academic_years resources :cohorts, only: [:index, :show] - resources :diplomas do + resources :diplomas, path: '/:lang/diplomas' do member do get :static end From a56bd4ace3ba16d99fce2ef3be2013702afef6bb Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 15:32:16 +0200 Subject: [PATCH 013/349] i18n for schools --- .../admin/education/schools_controller.rb | 8 +++++++- app/models/communication/website/post.rb | 4 ++-- app/models/education/school.rb | 7 +++++++ .../communication/websites/posts/_form.html.erb | 4 +++- app/views/admin/education/schools/index.html.erb | 4 ++++ app/views/admin/education/schools/show.html.erb | 2 ++ ...124925_add_i18n_infos_to_education_schools.rb | 16 ++++++++++++++++ db/schema.rb | 8 +++++++- 8 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20240617124925_add_i18n_infos_to_education_schools.rb diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb index de2fc555c1..9e428fe5da 100644 --- a/app/controllers/admin/education/schools_controller.rb +++ b/app/controllers/admin/education/schools_controller.rb @@ -3,11 +3,16 @@ class Admin::Education::SchoolsController < Admin::Education::ApplicationControl through: :current_university, through_association: :education_schools + include Admin::Translatable + has_scope :for_search_term has_scope :for_program def index - @schools = apply_scopes(@schools).ordered.page(params[:page]) + @schools = apply_scopes(@schools) + .in_closest_language_id(current_language.id) + .ordered + .page(params[:page]) breadcrumb end @@ -27,6 +32,7 @@ def edit def create @school.university = current_university + @school.language_id = current_language.id if @school.save redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s) else diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 485d3e17fc..2f20db7391 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,7 +68,7 @@ class Communication::Website::Post < ApplicationRecord validates :title, presence: true - before_validation :set_published_at, :ensure_authors_are_in_correct_language + before_validation :set_published_at, :ensure_author_is_in_correct_language after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id? scope :published, -> { @@ -175,7 +175,7 @@ def inherited_blob_ids [best_featured_image&.blob_id] end - def ensure_authors_are_in_correct_language + def ensure_author_is_in_correct_language return unless author.present? && author.language_id != language_id author_in_correct_language = author.find_or_translate!(language) self.author_id = author_in_correct_language.id diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 1c5de7eb0d..f9268fa37e 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -14,19 +14,26 @@ # zipcode :string # created_at :datetime not null # updated_at :datetime not null +# language_id :uuid indexed +# original_id :uuid indexed # university_id :uuid not null, indexed # # Indexes # +# index_education_schools_on_language_id (language_id) +# index_education_schools_on_original_id (original_id) # index_education_schools_on_university_id (university_id) # # Foreign Keys # +# fk_rails_84e48509e8 (language_id => languages.id) +# fk_rails_cba5631cc9 (original_id => education_schools.id) # fk_rails_e01b37a3ad (university_id => universities.id) # class Education::School < ApplicationRecord include AsIndirectObject include Sanitizable + include Translatable include WebsitesLinkable include WithAlumni include WithBlobs diff --git a/app/views/admin/communication/websites/posts/_form.html.erb b/app/views/admin/communication/websites/posts/_form.html.erb index 6bb1e261cf..ad005046e2 100644 --- a/app/views/admin/communication/websites/posts/_form.html.erb +++ b/app/views/admin/communication/websites/posts/_form.html.erb @@ -37,7 +37,9 @@ <%= f.input :published_at, html5: true, as: :date %> <% end %> <%= f.association :author, - collection: current_university.people.in_closest_language_id(current_language.id).ordered, + collection: current_university.people + .in_closest_language_id(current_language.id) + .ordered, label_method: :to_s_alphabetical %> <%= render "admin/application/slug/form", f: f, diff --git a/app/views/admin/education/schools/index.html.erb b/app/views/admin/education/schools/index.html.erb index ef244cfbc1..c4f650f073 100644 --- a/app/views/admin/education/schools/index.html.erb +++ b/app/views/admin/education/schools/index.html.erb @@ -1,5 +1,9 @@ <% content_for :title, Education::School.model_name.human(count: 2) %> +<% content_for :title_right do %> + <%= render 'language_switcher' %> +<% end %> + <%= render 'filters', current_path: admin_education_schools_path, filters: @filters if @filters.any? %>
    diff --git a/app/views/admin/education/schools/show.html.erb b/app/views/admin/education/schools/show.html.erb index 6f4961a690..8b679a14eb 100644 --- a/app/views/admin/education/schools/show.html.erb +++ b/app/views/admin/education/schools/show.html.erb @@ -61,6 +61,8 @@
    +<%= render 'admin/application/i18n/widget', about: @school, small: true %> + <%= render 'admin/education/schools/show/roles', roles: @roles %> <% content_for :action_bar_left do %> diff --git a/db/migrate/20240617124925_add_i18n_infos_to_education_schools.rb b/db/migrate/20240617124925_add_i18n_infos_to_education_schools.rb new file mode 100644 index 0000000000..22961fdf7f --- /dev/null +++ b/db/migrate/20240617124925_add_i18n_infos_to_education_schools.rb @@ -0,0 +1,16 @@ +class AddI18nInfosToEducationSchools < ActiveRecord::Migration[7.1] + def up + add_reference :education_schools, :language, foreign_key: true, type: :uuid + add_reference :education_schools, :original, foreign_key: {to_table: :education_schools}, type: :uuid + + Education::School.reset_column_information + University.all.find_each do |university| + university.schools.update_all(language_id: university.default_language_id) + end + end + + def down + remove_reference :education_schools, :language + remove_reference :education_schools, :original + end +end diff --git a/db/schema.rb b/db/schema.rb index 05ba4c099d..745ee84a08 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_06_13_120944) do +ActiveRecord::Schema[7.1].define(version: 2024_06_17_124925) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -840,6 +840,10 @@ t.datetime "updated_at", null: false t.string "phone" t.string "url" + t.uuid "language_id" + t.uuid "original_id" + t.index ["language_id"], name: "index_education_schools_on_language_id" + t.index ["original_id"], name: "index_education_schools_on_original_id" t.index ["university_id"], name: "index_education_schools_on_university_id" end @@ -1532,6 +1536,8 @@ add_foreign_key "education_programs", "education_programs", column: "parent_id" add_foreign_key "education_programs", "languages" add_foreign_key "education_programs", "universities" + add_foreign_key "education_schools", "education_schools", column: "original_id" + add_foreign_key "education_schools", "languages" add_foreign_key "education_schools", "universities" add_foreign_key "emergency_messages", "universities" add_foreign_key "imports", "universities" From 518bc22323d5588074312a944f2af4079443f408 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 16:22:50 +0200 Subject: [PATCH 014/349] wip schools --- .../education/programs/roles_controller.rb | 2 +- .../admin/education/schools/roles_controller.rb | 2 +- app/models/education/school.rb | 16 ++++++++++++++++ app/models/university/person/involvement.rb | 10 +++++----- app/models/university/role.rb | 17 +++++++++++++++++ .../admin/education/schools/_form.html.erb | 6 +++++- 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/education/programs/roles_controller.rb b/app/controllers/admin/education/programs/roles_controller.rb index fa6a9d1228..10704279cb 100644 --- a/app/controllers/admin/education/programs/roles_controller.rb +++ b/app/controllers/admin/education/programs/roles_controller.rb @@ -71,7 +71,7 @@ def model def load_administration_people @administration_people = current_university.people - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .administration .accessible_by(current_ability) .ordered diff --git a/app/controllers/admin/education/schools/roles_controller.rb b/app/controllers/admin/education/schools/roles_controller.rb index cff87cbf66..e797bdb2cf 100644 --- a/app/controllers/admin/education/schools/roles_controller.rb +++ b/app/controllers/admin/education/schools/roles_controller.rb @@ -71,7 +71,7 @@ def model def load_administration_people @administration_people = current_university.people - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .administration .accessible_by(current_ability) .ordered diff --git a/app/models/education/school.rb b/app/models/education/school.rb index f9268fa37e..31acf504d4 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -55,6 +55,8 @@ class Education::School < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true validates :logo, size: { less_than: 1.megabytes } + before_validation :ensure_programs_are_in_correct_language + scope :ordered, -> { order(:name) } scope :for_search_term, -> (term) { where(" @@ -106,4 +108,18 @@ def explicit_blob_ids logo&.blob_id ] end + + def ensure_programs_are_in_correct_language + correct_program_ids = [] + programs.each do |program| + if program.language_id == language_id + program_in_correct_language = program + else + program_in_correct_language = program.find_or_translate!(language) + end + correct_program_ids << program_in_correct_language.id + end + self.program_ids = correct_program_ids + end + end diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index c0785c3569..0ac0a74d63 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -38,7 +38,7 @@ class University::Person::Involvement < ApplicationRecord validates :target_id, uniqueness: { scope: [:person_id, :target_type] } before_validation :set_kind, :set_university_id, on: :create - before_validation :ensure_target_is_in_correct_language + before_validation :ensure_person_is_in_correct_language after_commit :sync_with_git @@ -77,9 +77,9 @@ def set_university_id self.university_id = self.person.university_id end - def ensure_target_is_in_correct_language - return unless target.language_id != person.language_id - target_in_correct_language = target.find_or_translate!(person.language) - self.target_id = target_in_correct_language.id + def ensure_person_is_in_correct_language + return unless person.language_id != target.language_id + person_in_correct_language = person.find_or_translate!(target.language) + self.person_id = person_in_correct_language.id end end diff --git a/app/models/university/role.rb b/app/models/university/role.rb index f631de2527..9cbba2c61c 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -29,8 +29,12 @@ class University::Role < ApplicationRecord has_many :involvements, class_name: 'University::Person::Involvement', as: :target, dependent: :destroy, inverse_of: :target has_many :people, through: :involvements + delegate :language_id, :language, to: :target + accepts_nested_attributes_for :involvements, reject_if: :all_blank, allow_destroy: true + before_validation :ensure_people_are_in_correct_language + def to_s "#{description}" end @@ -44,4 +48,17 @@ def sync_with_git def last_ordered_element self.class.unscoped.where(university_id: university_id, target: target).ordered.last end + + def ensure_people_are_in_correct_language + correct_people_ids = [] + people.each do |person| + if person.language_id == target.language_id + person_in_correct_language = person + else + person_in_correct_language = person.find_or_translate!(target.language) + end + correct_people_ids << person_in_correct_language.id + end + self.person_ids = correct_people_ids + end end diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb index 1ec5198c75..62bb6e4897 100644 --- a/app/views/admin/education/schools/_form.html.erb +++ b/app/views/admin/education/schools/_form.html.erb @@ -29,7 +29,11 @@ <%= osuny_panel Education::Program.model_name.human(count: 2) do %> <%= f.association :programs, as: :check_boxes, - collection: collection_tree(current_university.education_programs), + collection: collection_tree( + current_university.education_programs + .in_closest_language_id(current_language.id) + .ordered + ), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <% end %> From d063d80e87b8b2185bfce876691e2a96554de1a1 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 16:47:32 +0200 Subject: [PATCH 015/349] remove unused i18n for journal children --- .../administration/locations_controller.rb | 4 +- .../communication/extranets_controller.rb | 4 +- .../communication/websites_controller.rb | 7 +- .../education/academic_years_controller.rb | 4 +- .../admin/education/diplomas_controller.rb | 4 +- .../admin/education/programs_controller.rb | 35 +++++----- .../admin/education/schools_controller.rb | 4 +- .../alumni/cohorts/imports_controller.rb | 4 +- .../organizations/imports_controller.rb | 4 +- .../people/experiences/imports_controller.rb | 4 +- .../university/people/imports_controller.rb | 4 +- .../extranet/experiences_controller.rb | 4 +- app/models/research/journal/paper.rb | 7 -- app/models/research/journal/paper/kind.rb | 10 --- app/models/research/journal/volume.rb | 7 -- app/models/university/person/involvement.rb | 15 +++-- ..._i18n_info_to_research_journal_children.rb | 8 +++ db/schema.rb | 66 ++++++++----------- 18 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb diff --git a/app/controllers/admin/administration/locations_controller.rb b/app/controllers/admin/administration/locations_controller.rb index 83010927be..19776e98e1 100644 --- a/app/controllers/admin/administration/locations_controller.rb +++ b/app/controllers/admin/administration/locations_controller.rb @@ -30,7 +30,6 @@ def edit end def create - @location.university = current_university @location.language_id = current_language.id if @location.save redirect_to [:admin, @location], @@ -74,5 +73,8 @@ def location_params :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, school_ids: [], program_ids: [] ) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index 4a4eef04e4..37b6f12cc4 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -25,7 +25,6 @@ def edit end def create - @extranet.university = current_university if @extranet.save redirect_to [:admin, @extranet], notice: t('admin.successfully_created_html', model: @extranet.to_s) else @@ -68,5 +67,8 @@ def extranet_params end params.require(:communication_extranet) .permit(allowed_params) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 4858d0dd9b..d7df9dc817 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -52,7 +52,6 @@ def edit end def create - @website.university = current_university if @website.save_and_sync redirect_to [:admin, @website], notice: t('admin.successfully_created_html', model: @website.to_s) else @@ -98,7 +97,11 @@ def website_params attribute_names << :access_token unless params[:communication_website][:access_token].blank? # For now, default language can't be changed, too many implications, especially around special pages. attribute_names << :default_language_id unless @website&.persisted? - params.require(:communication_website).permit(*attribute_names) + params.require(:communication_website) + .permit(*attribute_names) + .merge( + university_id: current_university.id + ) end def default_url_options diff --git a/app/controllers/admin/education/academic_years_controller.rb b/app/controllers/admin/education/academic_years_controller.rb index 91346203a9..643a65df76 100644 --- a/app/controllers/admin/education/academic_years_controller.rb +++ b/app/controllers/admin/education/academic_years_controller.rb @@ -20,7 +20,6 @@ def edit end def create - @academic_year.university = current_university if @academic_year.save redirect_to [:admin, @academic_year], notice: t('admin.successfully_created_html', model: @academic_year.to_s) @@ -56,5 +55,8 @@ def breadcrumb def academic_year_params params.require(:education_academic_year) .permit(:year) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/education/diplomas_controller.rb b/app/controllers/admin/education/diplomas_controller.rb index 64b43b24e1..a565cf07a0 100644 --- a/app/controllers/admin/education/diplomas_controller.rb +++ b/app/controllers/admin/education/diplomas_controller.rb @@ -31,7 +31,6 @@ def edit end def create - @diploma.university = current_university @diploma.language_id = current_language.id if @diploma.save redirect_to [:admin, @diploma], @@ -70,5 +69,8 @@ def breadcrumb def diploma_params params.require(:education_diploma) .permit(:name, :slug, :short_name, :summary, :level, :ects, :duration) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index c41db10b4d..df04845f58 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -80,7 +80,6 @@ def edit end def create - @program.university = current_university @program.language_id = current_language.id @program.add_photo_import params[:photo_import] if @program.save @@ -116,21 +115,25 @@ def breadcrumb end def program_params - params.require(:education_program).permit( - :name, :short_name, :slug, :url, :bodyclass, - :meta_description, :summary, :published, - :capacity, :continuing, :initial, :apprenticeship, - :qualiopi_certified, :qualiopi_text, - :logo, :logo_delete, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, - :shared_image, :shared_image_delete, - :prerequisites, :objectives, :presentation, :registration, :pedagogy, :content, :registration_url, - :evaluation, :accessibility, :contacts, :opportunities, :results, :other, :main_information, - :pricing, :pricing_apprenticeship, :pricing_continuing, :pricing_initial, :duration, - :downloadable_summary, :downloadable_summary_delete, - :parent_id, :diploma_id, school_ids: [], - university_person_involvements_attributes: [:id, :person_id, :description, :position, :_destroy] - ) + params.require(:education_program) + .permit( + :name, :short_name, :slug, :url, :bodyclass, + :meta_description, :summary, :published, + :capacity, :continuing, :initial, :apprenticeship, + :qualiopi_certified, :qualiopi_text, + :logo, :logo_delete, + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, + :shared_image, :shared_image_delete, + :prerequisites, :objectives, :presentation, :registration, :pedagogy, :content, :registration_url, + :evaluation, :accessibility, :contacts, :opportunities, :results, :other, :main_information, + :pricing, :pricing_apprenticeship, :pricing_continuing, :pricing_initial, :duration, + :downloadable_summary, :downloadable_summary_delete, + :parent_id, :diploma_id, school_ids: [], + university_person_involvements_attributes: [:id, :person_id, :description, :position, :_destroy] + ) + .merge( + university_id: current_university.id + ) end def load_teacher_people diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb index 9e428fe5da..2b69f97ae4 100644 --- a/app/controllers/admin/education/schools_controller.rb +++ b/app/controllers/admin/education/schools_controller.rb @@ -31,7 +31,6 @@ def edit end def create - @school.university = current_university @school.language_id = current_language.id if @school.save redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s) @@ -67,5 +66,8 @@ def breadcrumb def school_params params.require(:education_school) .permit(:university_id, :name, :address, :zipcode, :city, :country, :url, :phone, :logo, :logo_delete, program_ids: []) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/university/alumni/cohorts/imports_controller.rb b/app/controllers/admin/university/alumni/cohorts/imports_controller.rb index 54aeb2536b..dcc96c5ab7 100644 --- a/app/controllers/admin/university/alumni/cohorts/imports_controller.rb +++ b/app/controllers/admin/university/alumni/cohorts/imports_controller.rb @@ -21,7 +21,6 @@ def new def create @import.kind = :alumni_cohorts - @import.university = current_university @import.user = current_user if @import.save redirect_to admin_university_alumni_cohorts_import_path(@import), @@ -48,5 +47,8 @@ def breadcrumb def import_params params.require(:import) .permit(:file) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/university/organizations/imports_controller.rb b/app/controllers/admin/university/organizations/imports_controller.rb index 31b2f8b3eb..c103c194f6 100644 --- a/app/controllers/admin/university/organizations/imports_controller.rb +++ b/app/controllers/admin/university/organizations/imports_controller.rb @@ -21,7 +21,6 @@ def new def create @import.kind = :organizations - @import.university = current_university @import.user = current_user if @import.save redirect_to admin_university_organizations_import_path(@import), @@ -48,5 +47,8 @@ def breadcrumb def import_params params.require(:import) .permit(:file) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/university/people/experiences/imports_controller.rb b/app/controllers/admin/university/people/experiences/imports_controller.rb index 663b26c9bc..b3a7921f0b 100644 --- a/app/controllers/admin/university/people/experiences/imports_controller.rb +++ b/app/controllers/admin/university/people/experiences/imports_controller.rb @@ -21,7 +21,6 @@ def new def create @import.kind = :people_experiences - @import.university = current_university @import.user = current_user if @import.save redirect_to admin_university_people_experiences_import_path(@import), @@ -48,5 +47,8 @@ def breadcrumb def import_params params.require(:import) .permit(:file) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/admin/university/people/imports_controller.rb b/app/controllers/admin/university/people/imports_controller.rb index 1fb35d64cd..4f038dfca1 100644 --- a/app/controllers/admin/university/people/imports_controller.rb +++ b/app/controllers/admin/university/people/imports_controller.rb @@ -21,7 +21,6 @@ def new def create @import.kind = :people - @import.university = current_university @import.user = current_user if @import.save redirect_to admin_university_people_import_path(@import), @@ -48,5 +47,8 @@ def breadcrumb def import_params params.require(:import) .permit(:file) + .merge( + university_id: current_university.id + ) end end diff --git a/app/controllers/extranet/experiences_controller.rb b/app/controllers/extranet/experiences_controller.rb index 9a297799d5..16f0da0510 100644 --- a/app/controllers/extranet/experiences_controller.rb +++ b/app/controllers/extranet/experiences_controller.rb @@ -11,7 +11,6 @@ def edit def create @experience = current_user.experiences.new(experience_params) - @experience.university = current_university if @experience.save redirect_to account_path, notice: t('admin.successfully_created_html', model: @experience.organization.to_s) @@ -46,6 +45,9 @@ def load_experience def experience_params params.require(:university_person_experience) .permit(:description, :from_year, :to_year, :organization_id, :organization_name) + .merge( + university_id: current_university.id + ) end def breadcrumb diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index c1d5ab305a..9c03c6cb8a 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -21,7 +21,6 @@ # created_at :datetime not null # updated_at :datetime not null # kind_id :uuid indexed -# language_id :uuid not null, indexed # research_journal_id :uuid not null, indexed # research_journal_volume_id :uuid indexed # university_id :uuid not null, indexed @@ -30,7 +29,6 @@ # Indexes # # index_research_journal_papers_on_kind_id (kind_id) -# index_research_journal_papers_on_language_id (language_id) # index_research_journal_papers_on_research_journal_id (research_journal_id) # index_research_journal_papers_on_research_journal_volume_id (research_journal_volume_id) # index_research_journal_papers_on_slug (slug) @@ -40,7 +38,6 @@ # Foreign Keys # # fk_rails_05213f4f24 (research_journal_id => research_journals.id) -# fk_rails_0da55970b1 (language_id => languages.id) # fk_rails_22f161a6a7 (research_journal_volume_id => research_journal_volumes.id) # fk_rails_2713063b85 (updated_by_id => users.id) # fk_rails_935541e014 (university_id => universities.id) @@ -63,7 +60,6 @@ class Research::Journal::Paper < ApplicationRecord has_summernote :text has_one_attached :pdf - belongs_to :language belongs_to :journal, foreign_key: :research_journal_id belongs_to :volume, @@ -83,9 +79,6 @@ class Research::Journal::Paper < ApplicationRecord scope :ordered, -> { order(published_at: :desc) } scope :ordered_by_position, -> { order(:position) } - scope :for_language, -> (language) { for_language_id(language.id) } - # The for_language_id scope can be used when you have the ID without needing to load the Language itself - scope :for_language_id, -> (language_id) { where(language_id: language_id) } def git_path(website) "#{git_path_content_prefix(website)}papers/#{static_path}.html" if published? diff --git a/app/models/research/journal/paper/kind.rb b/app/models/research/journal/paper/kind.rb index afe5014282..7386cfe9c7 100644 --- a/app/models/research/journal/paper/kind.rb +++ b/app/models/research/journal/paper/kind.rb @@ -8,24 +8,18 @@ # created_at :datetime not null # updated_at :datetime not null # journal_id :uuid not null, indexed -# language_id :uuid not null, indexed -# original_id :uuid indexed # university_id :uuid not null, indexed # # Indexes # # index_research_journal_paper_kinds_on_journal_id (journal_id) -# index_research_journal_paper_kinds_on_language_id (language_id) -# index_research_journal_paper_kinds_on_original_id (original_id) # index_research_journal_paper_kinds_on_slug (slug) # index_research_journal_paper_kinds_on_university_id (university_id) # # Foreign Keys # -# fk_rails_4ee2e9e2d4 (original_id => research_journal_paper_kinds.id) # fk_rails_57217513c3 (journal_id => research_journals.id) # fk_rails_8e6f992b9d (university_id => universities.id) -# fk_rails_fa47741536 (language_id => languages.id) # class Research::Journal::Paper::Kind < ApplicationRecord include AsIndirectObject @@ -34,16 +28,12 @@ class Research::Journal::Paper::Kind < ApplicationRecord include WithGitFiles include WithUniversity - belongs_to :language belongs_to :journal, class_name: 'Research::Journal' has_many :papers validates :title, presence: true scope :ordered, -> { order(:title) } - scope :for_language, -> (language) { for_language_id(language.id) } - # The for_language_id scope can be used when you have the ID without needing to load the Language itself - scope :for_language_id, -> (language_id) { where(language_id: language_id) } def to_s "#{title}" diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 0cf4112376..06fbf1531c 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -16,20 +16,17 @@ # title :string # created_at :datetime not null # updated_at :datetime not null -# language_id :uuid not null, indexed # research_journal_id :uuid not null, indexed # university_id :uuid not null, indexed # # Indexes # -# index_research_journal_volumes_on_language_id (language_id) # index_research_journal_volumes_on_research_journal_id (research_journal_id) # index_research_journal_volumes_on_slug (slug) # index_research_journal_volumes_on_university_id (university_id) # # Foreign Keys # -# fk_rails_4f1170147a (language_id => languages.id) # fk_rails_814e97604b (research_journal_id => research_journals.id) # fk_rails_c83d5e9068 (university_id => universities.id) # @@ -46,7 +43,6 @@ class Research::Journal::Volume < ApplicationRecord has_summernote :text - belongs_to :language belongs_to :journal, foreign_key: :research_journal_id has_many :papers, @@ -59,9 +55,6 @@ class Research::Journal::Volume < ApplicationRecord validates :title, presence: true scope :ordered, -> { order(published_at: :desc, number: :desc) } - scope :for_language, -> (language) { for_language_id(language.id) } - # The for_language_id scope can be used when you have the ID without needing to load the Language itself - scope :for_language_id, -> (language_id) { where(language_id: language_id) } def git_path(website) "#{git_path_content_prefix(website)}volumes#{path}/_index.html" if published_at diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index 0ac0a74d63..21e8bf9988 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -38,7 +38,7 @@ class University::Person::Involvement < ApplicationRecord validates :target_id, uniqueness: { scope: [:person_id, :target_type] } before_validation :set_kind, :set_university_id, on: :create - before_validation :ensure_person_is_in_correct_language + before_validation :ensure_connexion_is_in_correct_language after_commit :sync_with_git @@ -77,9 +77,16 @@ def set_university_id self.university_id = self.person.university_id end - def ensure_person_is_in_correct_language + def ensure_connexion_is_in_correct_language + # Si on passe par un rôle, on veut s'assurer que la personne connectée soit de la même langue que le target + # Si on passe par autre chose (connexion directe) on veut au contraire s'assurer que c'est le target qui a la même langue que la personne return unless person.language_id != target.language_id - person_in_correct_language = person.find_or_translate!(target.language) - self.person_id = person_in_correct_language.id + if target.is_a?(University::Role) + person_in_correct_language = person.find_or_translate!(target.language) + self.person_id = person_in_correct_language.id + else + target_in_correct_language = target.find_or_translate!(person.language) + self.target_id = target_in_correct_language.id + end end end diff --git a/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb b/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb new file mode 100644 index 0000000000..5210ad1385 --- /dev/null +++ b/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb @@ -0,0 +1,8 @@ +class RemoveUnusedI18nInfoToResearchJournalChildren < ActiveRecord::Migration[7.1] + def change + remove_column :research_journal_volumes, :language_id + remove_column :research_journal_papers, :language_id + remove_column :research_journal_paper_kinds, :language_id + remove_column :research_journal_paper_kinds, :original_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 2a98693100..ceaca5a271 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_17_124925) do +ActiveRecord::Schema[7.1].define(version: 2024_06_17_144345) do # These are extensions that must be enabled in order to support this database - enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" @@ -120,7 +119,7 @@ t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -148,8 +147,8 @@ t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.uuid "communication_website_id" + t.uuid "heading_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -157,7 +156,7 @@ t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "about_type" @@ -169,7 +168,7 @@ t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -181,7 +180,7 @@ t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -193,7 +192,7 @@ t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -209,7 +208,7 @@ t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -221,7 +220,7 @@ t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -301,7 +300,7 @@ t.index ["university_id"], name: "index_communication_website_agenda_categories_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -345,7 +344,7 @@ t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -689,15 +688,16 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" + t.datetime "run_at", precision: nil + t.datetime "locked_at", precision: nil + t.datetime "failed_at", precision: nil t.string "locked_by" t.string "queue" - t.string "signature" - t.text "args" t.datetime "created_at" t.datetime "updated_at" + t.string "signature" + t.text "args" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| @@ -847,7 +847,7 @@ t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -969,7 +969,7 @@ t.index ["university_id", "language_id"], name: "index_languages_universities_on_university_id_and_language_id" end - create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -995,18 +995,14 @@ t.index ["university_person_id", "research_hal_author_id"], name: "hal_author_person" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" t.string "slug" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.uuid "language_id", null: false - t.uuid "original_id" t.index ["journal_id"], name: "index_research_journal_paper_kinds_on_journal_id" - t.index ["language_id"], name: "index_research_journal_paper_kinds_on_language_id" - t.index ["original_id"], name: "index_research_journal_paper_kinds_on_original_id" t.index ["slug"], name: "index_research_journal_paper_kinds_on_slug" t.index ["university_id"], name: "index_research_journal_paper_kinds_on_university_id" end @@ -1034,9 +1030,7 @@ t.date "accepted_at" t.string "doi" t.text "authors_list" - t.uuid "language_id", null: false t.index ["kind_id"], name: "index_research_journal_papers_on_kind_id" - t.index ["language_id"], name: "index_research_journal_papers_on_language_id" t.index ["research_journal_id"], name: "index_research_journal_papers_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_papers_on_research_journal_volume_id" t.index ["slug"], name: "index_research_journal_papers_on_slug" @@ -1067,8 +1061,6 @@ t.text "text" t.text "featured_image_credit" t.text "summary" - t.uuid "language_id", null: false - t.index ["language_id"], name: "index_research_journal_volumes_on_language_id" t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id" t.index ["slug"], name: "index_research_journal_volumes_on_slug" t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" @@ -1122,7 +1114,7 @@ t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "hal_docid" t.jsonb "data" t.string "title" @@ -1200,7 +1192,7 @@ t.index ["name"], name: "index_universities_on_name", opclass: :gin_trgm_ops, using: :gin end - create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -1211,7 +1203,7 @@ t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1263,7 +1255,7 @@ t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" @@ -1321,14 +1313,14 @@ t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1385,7 +1377,7 @@ t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -1542,11 +1534,8 @@ add_foreign_key "emergency_messages", "universities" add_foreign_key "imports", "universities" add_foreign_key "imports", "users" - add_foreign_key "research_journal_paper_kinds", "languages" - add_foreign_key "research_journal_paper_kinds", "research_journal_paper_kinds", column: "original_id" add_foreign_key "research_journal_paper_kinds", "research_journals", column: "journal_id" add_foreign_key "research_journal_paper_kinds", "universities" - add_foreign_key "research_journal_papers", "languages" add_foreign_key "research_journal_papers", "research_journal_paper_kinds", column: "kind_id" add_foreign_key "research_journal_papers", "research_journal_volumes" add_foreign_key "research_journal_papers", "research_journals" @@ -1554,7 +1543,6 @@ add_foreign_key "research_journal_papers", "users", column: "updated_by_id" add_foreign_key "research_journal_papers_researchers", "research_journal_papers", column: "paper_id" add_foreign_key "research_journal_papers_researchers", "university_people", column: "researcher_id" - add_foreign_key "research_journal_volumes", "languages" add_foreign_key "research_journal_volumes", "research_journals" add_foreign_key "research_journal_volumes", "universities" add_foreign_key "research_journals", "languages" From ea662ca7c697a55736b4652ff6cfe07ce7213ca2 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 17:20:56 +0200 Subject: [PATCH 016/349] connexions --- .../research/journals/papers/kinds_controller.rb | 8 ++++---- .../admin/research/journals/papers_controller.rb | 5 +---- .../admin/research/journals/volumes_controller.rb | 7 ++----- app/models/research/journal/paper.rb | 15 +++++++++++++++ app/views/admin/application/i18n/_form.html.erb | 2 +- .../admin/research/journals/papers/_form.html.erb | 4 ++-- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/research/journals/papers/kinds_controller.rb b/app/controllers/admin/research/journals/papers/kinds_controller.rb index fa9a8bb632..bc8da3c70c 100644 --- a/app/controllers/admin/research/journals/papers/kinds_controller.rb +++ b/app/controllers/admin/research/journals/papers/kinds_controller.rb @@ -34,9 +34,7 @@ def edit def create @kind.assign_attributes( - journal: @journal, - university: current_university, - language_id: @journal.language_id + journal: @journal ) if @kind.save redirect_to admin_research_journal_kind_path(@kind), notice: t('admin.successfully_created_html', model: @paper_kind.to_s) @@ -71,6 +69,8 @@ def breadcrumb end def kind_params - params.require(:research_journal_paper_kind).permit(:title, :slug) + params.require(:research_journal_paper_kind) + .permit(:title, :slug) + .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/research/journals/papers_controller.rb b/app/controllers/admin/research/journals/papers_controller.rb index fb9733d3eb..7f8ea94203 100644 --- a/app/controllers/admin/research/journals/papers_controller.rb +++ b/app/controllers/admin/research/journals/papers_controller.rb @@ -4,8 +4,7 @@ class Admin::Research::Journals::PapersController < Admin::Research::Journals::A include Admin::Reorderable def index - @papers = @papers.for_language_id(@journal.language_id) - .ordered + @papers = @papers.ordered .page(params[:page]) breadcrumb end @@ -36,8 +35,6 @@ def edit def create @paper.assign_attributes( journal: @journal, - university: current_university, - language_id: @journal.language_id, updated_by: current_user ) if @paper.save diff --git a/app/controllers/admin/research/journals/volumes_controller.rb b/app/controllers/admin/research/journals/volumes_controller.rb index 349fe114be..44104bf2d5 100644 --- a/app/controllers/admin/research/journals/volumes_controller.rb +++ b/app/controllers/admin/research/journals/volumes_controller.rb @@ -2,8 +2,7 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals:: load_and_authorize_resource class: Research::Journal::Volume, through: :journal def index - @volumes = @volumes.for_language_id(@journal.language_id) - .ordered + @volumes = @volumes.ordered .page(params[:page]) breadcrumb end @@ -35,9 +34,7 @@ def edit def create @volume.add_photo_import params[:photo_import] @volume.assign_attributes( - journal: @journal, - university: current_university, - language_id: @journal.language_id + journal: @journal ) if @volume.save redirect_to admin_research_journal_volume_path(@volume), notice: t('admin.successfully_created_html', model: @volume.to_s) diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index 9c03c6cb8a..29bee717f7 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -77,6 +77,8 @@ class Research::Journal::Paper < ApplicationRecord validates :title, presence: true + before_validation :ensure_people_are_in_correct_language + scope :ordered, -> { order(published_at: :desc) } scope :ordered_by_position, -> { order(:position) } @@ -150,4 +152,17 @@ def last_ordered_element def explicit_blob_ids super.concat [pdf&.blob_id] end + + def ensure_people_are_in_correct_language + correct_person_ids = [] + people.each do |person| + if person.language_id == journal.language_id + person_in_correct_language = person + else + person_in_correct_language = person.find_or_translate!(journal.language) + end + correct_person_ids << person_in_correct_language.id + end + self.person_ids = correct_person_ids + end end diff --git a/app/views/admin/application/i18n/_form.html.erb b/app/views/admin/application/i18n/_form.html.erb index 025683b8ac..4805a945e6 100644 --- a/app/views/admin/application/i18n/_form.html.erb +++ b/app/views/admin/application/i18n/_form.html.erb @@ -1,4 +1,4 @@ <%= f.association :language, include_blank: false, - collection: Language.available_for_interface, + collection: current_university.languages.ordered, label_method: lambda { |l| t("languages.#{l.iso_code.to_s}") } %> diff --git a/app/views/admin/research/journals/papers/_form.html.erb b/app/views/admin/research/journals/papers/_form.html.erb index 2efc16d31f..0eb77a496c 100644 --- a/app/views/admin/research/journals/papers/_form.html.erb +++ b/app/views/admin/research/journals/papers/_form.html.erb @@ -27,7 +27,7 @@ <%= render "admin/application/slug/form", f: f, source: '#research_journal_paper_title' %> - <%= f.association :volume, collection: @journal.volumes, label: Research::Journal::Volume.model_name.human %> + <%= f.association :volume, collection: @journal.volumes.ordered, label: Research::Journal::Volume.model_name.human %> <%= f.input :published %> <%= f.input :published_at, html5: true, as: :date %> <%= f.input :accepted_at, html5: true, as: :date %> @@ -35,7 +35,7 @@ <%= f.input :keywords, as: :text, input_html: { rows: 2 } %> <%= f.association :people, collection: current_university.people - .for_language_id(current_university.default_language_id) + .in_closest_language_id(@journal.language_id) .researchers .ordered, as: :check_boxes %> From ce1a8676332864d04b01b90b38465150b964d917 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 17 Jun 2024 17:56:04 +0200 Subject: [PATCH 017/349] connexions between i18n models --- app/models/administration/location.rb | 15 ++++++++++++++- .../admin/administration/locations/_form.html.erb | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/administration/location.rb b/app/models/administration/location.rb index c3736660d5..44c44b4374 100644 --- a/app/models/administration/location.rb +++ b/app/models/administration/location.rb @@ -71,7 +71,7 @@ class Administration::Location < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true - before_validation :ensure_programs_are_in_correct_language + before_validation :ensure_programs_are_in_correct_language, :ensure_schools_are_in_correct_language def to_s "#{name}" @@ -148,4 +148,17 @@ def ensure_programs_are_in_correct_language end self.program_ids = correct_program_ids end + + def ensure_schools_are_in_correct_language + correct_school_ids = [] + schools.each do |school| + if school.language_id == language_id + school_in_correct_language = school + else + school_in_correct_language = school.find_or_translate!(language) + end + correct_school_ids << school_in_correct_language.id + end + self.school_ids = correct_school_ids + end end diff --git a/app/views/admin/administration/locations/_form.html.erb b/app/views/admin/administration/locations/_form.html.erb index 8cf970ff95..6eaa16b857 100644 --- a/app/views/admin/administration/locations/_form.html.erb +++ b/app/views/admin/administration/locations/_form.html.erb @@ -37,6 +37,7 @@ collection: collection_tree( current_university.education_programs .in_closest_language_id(location.language_id) + .ordered ), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> @@ -45,6 +46,7 @@ <%= f.association :schools, as: :check_boxes, collection: current_university.education_schools + .in_closest_language_id(location.language_id) .ordered %>
    From 9d6011968434b7ea44e560290799c34e081be132 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Tue, 18 Jun 2024 14:27:31 +0200 Subject: [PATCH 018/349] migration --- db/schema.rb | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 02fecfda00..f914e42878 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,8 +10,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_17_144345) do +ActiveRecord::Schema[7.1].define(version: 2024_06_17_190729) do # These are extensions that must be enabled in order to support this database + enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" @@ -119,7 +120,7 @@ t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -148,8 +149,8 @@ t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "communication_website_id" t.uuid "heading_id" + t.uuid "communication_website_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -157,7 +158,7 @@ t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "about_type" @@ -169,7 +170,7 @@ t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -181,7 +182,7 @@ t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -193,7 +194,7 @@ t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -209,7 +210,7 @@ t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -221,7 +222,7 @@ t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -301,7 +302,7 @@ t.index ["university_id"], name: "index_communication_website_agenda_categories_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -346,7 +347,7 @@ t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -690,16 +691,15 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at", precision: nil - t.datetime "locked_at", precision: nil - t.datetime "failed_at", precision: nil + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" t.string "locked_by" t.string "queue" - t.datetime "created_at" - t.datetime "updated_at" t.string "signature" t.text "args" - t.index ["priority", "run_at"], name: "delayed_jobs_priority" + t.datetime "created_at" + t.datetime "updated_at" end create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| @@ -849,7 +849,7 @@ t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -971,7 +971,7 @@ t.index ["university_id", "language_id"], name: "index_languages_universities_on_university_id_and_language_id" end - create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -997,7 +997,7 @@ t.index ["university_person_id", "research_hal_author_id"], name: "hal_author_person" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" @@ -1116,7 +1116,7 @@ t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "hal_docid" t.jsonb "data" t.string "title" @@ -1194,7 +1194,7 @@ t.index ["name"], name: "index_universities_on_name", opclass: :gin_trgm_ops, using: :gin end - create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -1205,7 +1205,7 @@ t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1257,7 +1257,7 @@ t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" @@ -1315,14 +1315,14 @@ t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1379,7 +1379,7 @@ t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false From 826422884d244e497a6be1ea220cebe80e59096b Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Wed, 19 Jun 2024 07:08:04 +0200 Subject: [PATCH 019/349] reversible --- ...emove_unused_i18n_info_to_research_journal_children.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb b/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb index 5210ad1385..21b90f5427 100644 --- a/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb +++ b/db/migrate/20240617144345_remove_unused_i18n_info_to_research_journal_children.rb @@ -1,8 +1,8 @@ class RemoveUnusedI18nInfoToResearchJournalChildren < ActiveRecord::Migration[7.1] def change - remove_column :research_journal_volumes, :language_id - remove_column :research_journal_papers, :language_id - remove_column :research_journal_paper_kinds, :language_id - remove_column :research_journal_paper_kinds, :original_id + remove_column :research_journal_volumes, :language_id, :uuid + remove_column :research_journal_papers, :language_id, :uuid + remove_column :research_journal_paper_kinds, :language_id, :uuid + remove_column :research_journal_paper_kinds, :original_id, :uuid end end From b386007b88626213908fec8ccb0e0a7495cf47f4 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 20 Jun 2024 12:45:19 +0200 Subject: [PATCH 020/349] wip connexions integrity --- app/models/administration/location.rb | 29 ++--------- app/models/communication/website/post.rb | 8 ++- .../concerns/relations_language_integrity.rb | 29 +++++++++++ app/models/concerns/translatable.rb | 21 ++++++++ app/models/education/program.rb | 10 ++++ app/models/education/school.rb | 15 ++---- app/models/research/journal/paper.rb | 16 ++---- app/models/university/person/involvement.rb | 4 +- app/models/university/role.rb | 17 ++---- .../admin/education/programs/_form.html.erb | 30 +++++++---- db/schema.rb | 52 +++++++++---------- 11 files changed, 126 insertions(+), 105 deletions(-) create mode 100644 app/models/concerns/relations_language_integrity.rb diff --git a/app/models/administration/location.rb b/app/models/administration/location.rb index 44c44b4374..6fe8ab5553 100644 --- a/app/models/administration/location.rb +++ b/app/models/administration/location.rb @@ -71,7 +71,7 @@ class Administration::Location < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true - before_validation :ensure_programs_are_in_correct_language, :ensure_schools_are_in_correct_language + before_validation :ensure_connected_elements_are_in_correct_language def to_s "#{name}" @@ -136,29 +136,8 @@ def has_administration_locations? private - def ensure_programs_are_in_correct_language - correct_program_ids = [] - programs.each do |program| - if program.language_id == language_id - program_in_correct_language = program - else - program_in_correct_language = program.find_or_translate!(language) - end - correct_program_ids << program_in_correct_language.id - end - self.program_ids = correct_program_ids - end - - def ensure_schools_are_in_correct_language - correct_school_ids = [] - schools.each do |school| - if school.language_id == language_id - school_in_correct_language = school - else - school_in_correct_language = school.find_or_translate!(language) - end - correct_school_ids << school_in_correct_language.id - end - self.school_ids = correct_school_ids + def ensure_connected_elements_are_in_correct_language + ensure_multiple_connections_are_in_correct_language(programs, :program_ids) + ensure_multiple_connections_are_in_correct_language(schools, :school_ids) end end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 2f20db7391..fd0e96eca5 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,7 +68,7 @@ class Communication::Website::Post < ApplicationRecord validates :title, presence: true - before_validation :set_published_at, :ensure_author_is_in_correct_language + before_validation :set_published_at, :ensure_connected_elements_are_in_correct_language after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id? scope :published, -> { @@ -175,10 +175,8 @@ def inherited_blob_ids [best_featured_image&.blob_id] end - def ensure_author_is_in_correct_language - return unless author.present? && author.language_id != language_id - author_in_correct_language = author.find_or_translate!(language) - self.author_id = author_in_correct_language.id + def ensure_connected_elements_are_in_correct_language + ensure_single_connection_is_in_correct_language(author, :author_id) end def update_authors_statuses! diff --git a/app/models/concerns/relations_language_integrity.rb b/app/models/concerns/relations_language_integrity.rb new file mode 100644 index 0000000000..4c32f9a94b --- /dev/null +++ b/app/models/concerns/relations_language_integrity.rb @@ -0,0 +1,29 @@ +module RelationsLanguageIntegrity + extend ActiveSupport::Concern + + protected + + def ensure_connected_elements_are_in_correct_language + raise NotImplementedError + end + + def ensure_single_connection_is_in_correct_language(element, property_name, compared_language = language) + return unless element.present? && element.language_id != compared_language.id + element_in_correct_language = element.find_or_translate!(compared_language) + public_send("#{property_name}=", element_in_correct_language.id) + end + + def ensure_multiple_connections_are_in_correct_language(elements, property_name, compared_language = language) + correct_elements_ids = [] + elements.each do |element| + if element.language_id == compared_language.id + element_in_correct_language = element + else + element_in_correct_language = element.find_or_translate!(compared_language) + end + correct_elements_ids << element_in_correct_language.id + end + public_send("#{property_name}=", correct_elements_ids) + end + +end \ No newline at end of file diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index af1ec70b11..dea39bb1e1 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -1,6 +1,8 @@ module Translatable extend ActiveSupport::Concern + include RelationsLanguageIntegrity + included do attr_accessor :newly_translated @@ -154,4 +156,23 @@ def destroy_or_nullify_translations end end + def ensure_single_connection_is_in_correct_language(element, property_name, compared_language = language) + return unless element.present? && element.language_id != compared_language.id + element_in_correct_language = element.find_or_translate!(compared_language) + public_send("#{property_name}=", element_in_correct_language.id) + end + + def ensure_multiple_connections_are_in_correct_language(elements, property_name, compared_language = language) + correct_elements_ids = [] + elements.each do |element| + if element.language_id == compared_language.id + element_in_correct_language = element + else + element_in_correct_language = element.find_or_translate!(compared_language) + end + correct_elements_ids << element_in_correct_language.id + end + public_send("#{property_name}=", correct_elements_ids) + end + end \ No newline at end of file diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 936d1740ab..bb68205c44 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -118,6 +118,8 @@ class Education::Program < ApplicationRecord has_one_attached_deletable :downloadable_summary has_one_attached_deletable :logo + before_validation :ensure_connected_elements_are_in_correct_language + before_destroy :move_children validates_presence_of :name @@ -242,4 +244,12 @@ def inherited_blob_ids def move_children children.update(parent_id: parent_id) end + + def ensure_connected_elements_are_in_correct_language + ensure_single_connection_is_in_correct_language(parent, :parent_id) + ensure_single_connection_is_in_correct_language(diploma, :diploma_id) + ensure_multiple_connections_are_in_correct_language(schools, :school_ids) + end + + end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 31acf504d4..b9b43ef6a1 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -55,7 +55,7 @@ class Education::School < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true validates :logo, size: { less_than: 1.megabytes } - before_validation :ensure_programs_are_in_correct_language + before_validation :ensure_connected_elements_are_in_correct_language scope :ordered, -> { order(:name) } scope :for_search_term, -> (term) { @@ -109,17 +109,8 @@ def explicit_blob_ids ] end - def ensure_programs_are_in_correct_language - correct_program_ids = [] - programs.each do |program| - if program.language_id == language_id - program_in_correct_language = program - else - program_in_correct_language = program.find_or_translate!(language) - end - correct_program_ids << program_in_correct_language.id - end - self.program_ids = correct_program_ids + def ensure_connected_elements_are_in_correct_language + ensure_multiple_connections_are_in_correct_language(programs, :program_ids) end end diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index 29bee717f7..4a57a5d741 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -47,6 +47,7 @@ class Research::Journal::Paper < ApplicationRecord include AsIndirectObject include Contentful include Permalinkable + include RelationsLanguageIntegrity include Sanitizable include Sluggable include WithBlobs @@ -77,7 +78,7 @@ class Research::Journal::Paper < ApplicationRecord validates :title, presence: true - before_validation :ensure_people_are_in_correct_language + before_validation :ensure_connected_elements_are_in_correct_language scope :ordered, -> { order(published_at: :desc) } scope :ordered_by_position, -> { order(:position) } @@ -153,16 +154,7 @@ def explicit_blob_ids super.concat [pdf&.blob_id] end - def ensure_people_are_in_correct_language - correct_person_ids = [] - people.each do |person| - if person.language_id == journal.language_id - person_in_correct_language = person - else - person_in_correct_language = person.find_or_translate!(journal.language) - end - correct_person_ids << person_in_correct_language.id - end - self.person_ids = correct_person_ids + def ensure_connected_elements_are_in_correct_language + ensure_multiple_connections_are_in_correct_language(people, :person_ids, journal.language) end end diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index 21e8bf9988..e0811898f6 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -38,7 +38,7 @@ class University::Person::Involvement < ApplicationRecord validates :target_id, uniqueness: { scope: [:person_id, :target_type] } before_validation :set_kind, :set_university_id, on: :create - before_validation :ensure_connexion_is_in_correct_language + before_validation :ensure_connected_elements_are_in_correct_language after_commit :sync_with_git @@ -77,7 +77,7 @@ def set_university_id self.university_id = self.person.university_id end - def ensure_connexion_is_in_correct_language + def ensure_connected_elements_are_in_correct_language # Si on passe par un rôle, on veut s'assurer que la personne connectée soit de la même langue que le target # Si on passe par autre chose (connexion directe) on veut au contraire s'assurer que c'est le target qui a la même langue que la personne return unless person.language_id != target.language_id diff --git a/app/models/university/role.rb b/app/models/university/role.rb index 9cbba2c61c..5ae67f433a 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -21,6 +21,7 @@ # fk_rails_8e52293a38 (university_id => universities.id) # class University::Role < ApplicationRecord + include RelationsLanguageIntegrity include Sanitizable include WithUniversity include WithPosition @@ -33,7 +34,7 @@ class University::Role < ApplicationRecord accepts_nested_attributes_for :involvements, reject_if: :all_blank, allow_destroy: true - before_validation :ensure_people_are_in_correct_language + before_validation :ensure_connected_elements_are_in_correct_language def to_s "#{description}" @@ -49,16 +50,8 @@ def last_ordered_element self.class.unscoped.where(university_id: university_id, target: target).ordered.last end - def ensure_people_are_in_correct_language - correct_people_ids = [] - people.each do |person| - if person.language_id == target.language_id - person_in_correct_language = person - else - person_in_correct_language = person.find_or_translate!(target.language) - end - correct_people_ids << person_in_correct_language.id - end - self.person_ids = correct_people_ids + def ensure_connected_elements_are_in_correct_language + ensure_multiple_connections_are_in_correct_language(people, :person_ids, target.language) end + end diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index 863b83e0f6..ddff43d893 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -17,10 +17,14 @@
    <%= f.association :diploma, - collection: current_university.diplomas.ordered %> + collection: current_university.diplomas + .in_closest_language_id(program.language_id) + .ordered %> <%= f.association :schools, as: :check_boxes, - collection: current_university.education_schools.ordered %> + collection: current_university.education_schools + .in_closest_language_id(program.language_id) + .ordered %>
    <%= f.input :url %> @@ -72,14 +76,14 @@
    <%= link_to_add_association t('add'), - f, - :university_person_involvements, - class: button_classes, - partial: 'admin/education/programs/involvement_fields', - data: { - 'association-insertion-method': 'append', - 'association-insertion-node': '#involvements', - } %> + f, + :university_person_involvements, + class: button_classes, + partial: 'admin/education/programs/involvement_fields', + data: { + 'association-insertion-method': 'append', + 'association-insertion-node': '#involvements', + } %>
    @@ -168,7 +172,11 @@ f: f, source: '#education_program_name' %> <%= f.association :parent, - collection: collection_tree(current_university.education_programs, program), + collection: collection_tree( + current_university.education_programs + .in_closest_language_id(program.language_id) + .ordered, + program), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <%= f.input :bodyclass %> diff --git a/db/schema.rb b/db/schema.rb index f914e42878..12cf242082 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_17_190729) do # These are extensions that must be enabled in order to support this database - enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" @@ -120,7 +119,7 @@ t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -149,8 +148,8 @@ t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.uuid "communication_website_id" + t.uuid "heading_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -158,7 +157,7 @@ t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "about_type" @@ -170,7 +169,7 @@ t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -182,7 +181,7 @@ t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -194,7 +193,7 @@ t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -210,7 +209,7 @@ t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -222,7 +221,7 @@ t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -302,7 +301,7 @@ t.index ["university_id"], name: "index_communication_website_agenda_categories_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -347,7 +346,7 @@ t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -691,15 +690,16 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" + t.datetime "run_at", precision: nil + t.datetime "locked_at", precision: nil + t.datetime "failed_at", precision: nil t.string "locked_by" t.string "queue" - t.string "signature" - t.text "args" t.datetime "created_at" t.datetime "updated_at" + t.string "signature" + t.text "args" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| @@ -849,7 +849,7 @@ t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -971,7 +971,7 @@ t.index ["university_id", "language_id"], name: "index_languages_universities_on_university_id_and_language_id" end - create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -997,7 +997,7 @@ t.index ["university_person_id", "research_hal_author_id"], name: "hal_author_person" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" @@ -1116,7 +1116,7 @@ t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "hal_docid" t.jsonb "data" t.string "title" @@ -1194,7 +1194,7 @@ t.index ["name"], name: "index_universities_on_name", opclass: :gin_trgm_ops, using: :gin end - create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -1205,7 +1205,7 @@ t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1257,7 +1257,7 @@ t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" @@ -1315,14 +1315,14 @@ t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1379,7 +1379,7 @@ t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false From 7503175d50b208a043d1c2849df1367c37717c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 20 Jun 2024 12:48:36 +0200 Subject: [PATCH 021/349] translatable_collection_tree --- app/helpers/admin/application_helper.rb | 9 +++++++++ app/models/concerns/with_tree.rb | 16 ++++++++++++++++ app/views/admin/education/schools/_form.html.erb | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index 6c45f759f8..e91ad6a929 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -153,6 +153,15 @@ def collection_tree(list, except = nil) collection end + def translatable_collection_tree(list, language, except = nil) + collection = [] + list.in_closest_language_id(language.id).root.ordered.each do |object| + collection.concat(object.self_and_translatable_children(language, 0)) + end + collection = collection.reject { |o| o[:id] == except.id } unless except.nil? + collection + end + def collection_tree_for_checkboxes(list, except = nil) collection = collection_tree(list, except) collection.map { |object| diff --git a/app/models/concerns/with_tree.rb b/app/models/concerns/with_tree.rb index ab53e6ef23..9cd0db8642 100644 --- a/app/models/concerns/with_tree.rb +++ b/app/models/concerns/with_tree.rb @@ -45,6 +45,22 @@ def self_and_children(level) elements end + def self_and_translatable_children(language, level, parent_id = nil) + elements = [] + label = "   " * level + self.to_s + elements << { label: label, id: self.id, parent_id: parent_id } + parent_ids = [original_object.id] + original_object.translation_ids - [id] + # We query other translations' children which are originals, meaning created in their language first, and then in the closest language + indirect_children = self.class.unscoped + .where(parent_id: parent_ids, original_id: nil) + .in_closest_language_id(language.id) + children_in_closest_language = children.or(indirect_children) + children_in_closest_language.ordered.each do |child| + elements.concat(child.self_and_translatable_children(language, level + 1, child.id)) + end + elements + end + end diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb index 1ec5198c75..f0e0c6abd2 100644 --- a/app/views/admin/education/schools/_form.html.erb +++ b/app/views/admin/education/schools/_form.html.erb @@ -18,7 +18,7 @@
    <%= f.input :country, input_html: { class: 'form-select' } %> <%= f.input :url %> - <%= f.input :logo, + <%= f.input :logo, as: :single_deletable_file, input_html: { accept: default_images_formats_accepted }, preview: 200, @@ -29,7 +29,7 @@ <%= osuny_panel Education::Program.model_name.human(count: 2) do %> <%= f.association :programs, as: :check_boxes, - collection: collection_tree(current_university.education_programs), + collection: translatable_collection_tree(current_university.education_programs, current_language), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <% end %> From 993649bc9ddbc59e580dc2fa956ed29cd8572691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Thu, 20 Jun 2024 12:50:31 +0200 Subject: [PATCH 022/349] schema --- db/schema.rb | 114 +++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 12cf242082..f7d56f29ba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,7 +17,7 @@ enable_extension "plpgsql" enable_extension "unaccent" - create_table "action_text_rich_texts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.text "body" t.string "record_type", null: false @@ -27,7 +27,7 @@ t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true end - create_table "active_storage_attachments", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false t.uuid "record_id", null: false @@ -37,7 +37,7 @@ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end - create_table "active_storage_blobs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_blobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "key", null: false t.string "filename", null: false t.string "content_type" @@ -51,7 +51,7 @@ t.index ["university_id"], name: "index_active_storage_blobs_on_university_id" end - create_table "active_storage_variant_records", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_variant_records", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "blob_id", null: false t.string "variation_digest", null: false t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true @@ -97,7 +97,7 @@ t.index ["education_school_id", "administration_location_id"], name: "index_location_school" end - create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number" t.text "name" t.text "description" @@ -105,7 +105,7 @@ t.datetime "updated_at", null: false end - create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "criterion_id", null: false t.integer "number" t.text "name" @@ -119,7 +119,7 @@ t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -137,7 +137,7 @@ t.index ["university_id"], name: "index_communication_block_headings_on_university_id" end - create_table "communication_blocks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_blocks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type" t.uuid "about_id" @@ -148,8 +148,8 @@ t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "communication_website_id" t.uuid "heading_id" + t.uuid "communication_website_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -157,7 +157,7 @@ t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "about_type" @@ -169,7 +169,7 @@ t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -181,7 +181,7 @@ t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -193,7 +193,7 @@ t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -209,7 +209,7 @@ t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -221,7 +221,7 @@ t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -243,7 +243,7 @@ t.index ["university_id"], name: "index_communication_extranet_posts_on_university_id" end - create_table "communication_extranets", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "host" @@ -301,7 +301,7 @@ t.index ["university_id"], name: "index_communication_website_agenda_categories_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -346,7 +346,7 @@ t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -381,7 +381,7 @@ t.index ["university_id"], name: "index_communication_website_git_file_orphans_on_university_id" end - create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_git_files", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false t.uuid "about_id", null: false @@ -416,7 +416,7 @@ t.index ["university_id"], name: "index_communication_website_localizations_on_university_id" end - create_table "communication_website_menu_items", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menu_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.uuid "menu_id", null: false @@ -436,7 +436,7 @@ t.index ["website_id"], name: "index_communication_website_menu_items_on_website_id" end - create_table "communication_website_menus", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menus", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -452,7 +452,7 @@ t.index ["university_id"], name: "index_communication_website_menus_on_university_id" end - create_table "communication_website_pages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -466,10 +466,10 @@ t.boolean "published", default: false t.string "featured_image_alt" t.text "text" - t.text "summary" t.string "breadcrumb_title" t.text "header_text" t.integer "kind" + t.text "summary" t.string "bodyclass" t.uuid "language_id", null: false t.text "featured_image_credit" @@ -489,7 +489,7 @@ t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -555,7 +555,7 @@ t.index ["university_id"], name: "idx_on_university_id_ac2f4a0bfc" end - create_table "communication_website_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "name" @@ -582,7 +582,7 @@ t.index ["university_id"], name: "index_communication_website_post_categories_on_university_id" end - create_table "communication_website_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -623,7 +623,7 @@ t.index ["communication_website_showcase_tag_id", "communication_website_id"], name: "index_showcase_tag_website" end - create_table "communication_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "url" @@ -702,7 +702,7 @@ t.index ["priority", "run_at"], name: "delayed_jobs_priority" end - create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_academic_years", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.integer "year" t.datetime "created_at", null: false @@ -717,7 +717,7 @@ t.index ["university_person_id", "education_academic_year_id"], name: "index_person_academic_year" end - create_table "education_cohorts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_cohorts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "program_id", null: false t.uuid "academic_year_id", null: false @@ -738,7 +738,7 @@ t.index ["university_person_id", "education_cohort_id"], name: "index_person_cohort" end - create_table "education_diplomas", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_diplomas", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "short_name" t.integer "level", default: 0 @@ -757,7 +757,7 @@ t.index ["university_id"], name: "index_education_diplomas_on_university_id" end - create_table "education_programs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_programs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.integer "capacity" @@ -829,7 +829,7 @@ t.index ["education_program_id", "user_id"], name: "index_education_programs_users_on_program_id_and_user_id" end - create_table "education_schools", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -849,7 +849,7 @@ t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -944,7 +944,7 @@ t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)" end - create_table "imports", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" t.integer "kind" @@ -957,7 +957,7 @@ t.index ["user_id"], name: "index_imports_on_user_id" end - create_table "languages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" t.datetime "created_at", null: false @@ -971,7 +971,7 @@ t.index ["university_id", "language_id"], name: "index_languages_universities_on_university_id_and_language_id" end - create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -997,7 +997,7 @@ t.index ["university_person_id", "research_hal_author_id"], name: "hal_author_person" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" @@ -1009,7 +1009,7 @@ t.index ["university_id"], name: "index_research_journal_paper_kinds_on_university_id" end - create_table "research_journal_papers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_papers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.datetime "published_at", precision: nil t.uuid "university_id", null: false @@ -1047,7 +1047,7 @@ t.index ["researcher_id"], name: "index_research_journal_papers_researchers_on_researcher_id" end - create_table "research_journal_volumes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_journal_id", null: false t.string "title" @@ -1068,7 +1068,7 @@ t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end - create_table "research_journals", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journals", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "title" t.text "meta_description" @@ -1081,7 +1081,7 @@ t.index ["university_id"], name: "index_research_journals_on_university_id" end - create_table "research_laboratories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -1102,7 +1102,7 @@ t.index ["university_person_id", "research_laboratory_id"], name: "laboratory_person" end - create_table "research_laboratory_axes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratory_axes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.string "name" @@ -1116,7 +1116,7 @@ t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "hal_docid" t.jsonb "data" t.string "title" @@ -1147,7 +1147,7 @@ t.index ["university_person_id", "research_publication_id"], name: "index_publication_person" end - create_table "research_theses", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_theses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.uuid "author_id", null: false @@ -1165,7 +1165,7 @@ t.index ["university_id"], name: "index_research_theses_on_university_id" end - create_table "universities", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "identifier" t.string "address" @@ -1194,7 +1194,7 @@ t.index ["name"], name: "index_universities_on_name", opclass: :gin_trgm_ops, using: :gin end - create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -1205,7 +1205,7 @@ t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1221,7 +1221,7 @@ t.index ["university_id"], name: "index_university_organization_categories_on_university_id" end - create_table "university_organizations", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "long_name" @@ -1257,14 +1257,14 @@ t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" t.index ["organization_id"], name: "index_university_organizations_categories_on_organization_id" end - create_table "university_people", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "user_id" t.string "last_name" @@ -1315,14 +1315,14 @@ t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1338,7 +1338,7 @@ t.index ["university_id"], name: "index_university_person_categories_on_university_id" end - create_table "university_person_experiences", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_experiences", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.uuid "organization_id", null: false @@ -1352,7 +1352,7 @@ t.index ["university_id"], name: "index_university_person_experiences_on_university_id" end - create_table "university_person_involvements", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_involvements", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.integer "kind" @@ -1367,7 +1367,7 @@ t.index ["university_id"], name: "index_university_person_involvements_on_university_id" end - create_table "university_roles", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_roles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "target_type" t.uuid "target_id" @@ -1379,7 +1379,7 @@ t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -1389,7 +1389,7 @@ t.index ["user_id"], name: "index_user_favorites_on_user_id" end - create_table "users", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "first_name" t.string "last_name" From 91f899745447370eb07fa3fcd0ee5d79fc749a0d Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 20 Jun 2024 15:27:48 +0200 Subject: [PATCH 023/349] wip connected relations translated --- app/controllers/admin/education/programs_controller.rb | 2 +- app/models/university/person/involvement.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index df04845f58..83aac9459e 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -138,7 +138,7 @@ def program_params def load_teacher_people @teacher_people = current_university.people - .for_language_id(current_university.default_language_id) + .in_closest_language_id(current_language.id) .teachers .accessible_by(current_ability) .ordered diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index e0811898f6..0e555f4a78 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -81,7 +81,7 @@ def ensure_connected_elements_are_in_correct_language # Si on passe par un rôle, on veut s'assurer que la personne connectée soit de la même langue que le target # Si on passe par autre chose (connexion directe) on veut au contraire s'assurer que c'est le target qui a la même langue que la personne return unless person.language_id != target.language_id - if target.is_a?(University::Role) + if target.is_a?(University::Role) || target.is_a?(Education::Program) person_in_correct_language = person.find_or_translate!(target.language) self.person_id = person_in_correct_language.id else From d0614edfe3a3a37d7ec6c050af19c02ef609f5f2 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 20 Jun 2024 15:36:17 +0200 Subject: [PATCH 024/349] correct translate for programs & locations --- app/models/administration/location.rb | 11 +++++++++++ app/models/education/program.rb | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/administration/location.rb b/app/models/administration/location.rb index 6fe8ab5553..b28b600286 100644 --- a/app/models/administration/location.rb +++ b/app/models/administration/location.rb @@ -136,6 +136,17 @@ def has_administration_locations? private + def translate_additional_data!(translation) + programs.each do |program| + translated_program = program.find_or_translate!(translation.language) + translation.programs << translated_program + end + schools.each do |school| + translated_school = school.find_or_translate!(translation.language) + translation.schools << translated_school + end + end + def ensure_connected_elements_are_in_correct_language ensure_multiple_connections_are_in_correct_language(programs, :program_ids) ensure_multiple_connections_are_in_correct_language(schools, :school_ids) diff --git a/app/models/education/program.rb b/app/models/education/program.rb index bb68205c44..ca64826ca4 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -245,6 +245,15 @@ def move_children children.update(parent_id: parent_id) end + def translate_additional_data!(translation) + translation.update(parent_id: parent.find_or_translate!(translation.language).id) if parent_id.present? + translation.update(diploma_id: diploma.find_or_translate!(translation.language).id) if diploma_id.present? + schools.each do |school| + translated_school = school.find_or_translate!(translation.language) + translation.schools << translated_school + end + end + def ensure_connected_elements_are_in_correct_language ensure_single_connection_is_in_correct_language(parent, :parent_id) ensure_single_connection_is_in_correct_language(diploma, :diploma_id) From b62758e893e1d3fc130ce7b7a326250088da2d30 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 20 Jun 2024 16:03:00 +0200 Subject: [PATCH 025/349] rename old current_language as current_interface_language --- app/controllers/application_controller/with_locale.rb | 6 +++--- app/models/language.rb | 4 ++++ app/views/admin/communication/blocks/edit.html.erb | 2 +- .../websites/connections/_direct_source.html.erb | 4 ++-- app/views/admin/research/publications/_form.html.erb | 3 ++- app/views/application/_summernote_localization.html.erb | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller/with_locale.rb b/app/controllers/application_controller/with_locale.rb index 91322f474a..508463b976 100644 --- a/app/controllers/application_controller/with_locale.rb +++ b/app/controllers/application_controller/with_locale.rb @@ -4,12 +4,12 @@ module ApplicationController::WithLocale included do around_action :switch_locale - helper_method :current_language + helper_method :current_interface_language end - def current_language - @current_language ||= Language.find_by(iso_code: I18n.locale.to_s) + def current_interface_language + @current_interface_language ||= Language.find_by(iso_code: I18n.locale.to_s) end protected diff --git a/app/models/language.rb b/app/models/language.rb index bd636b1cc9..1da1ea983f 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -39,4 +39,8 @@ def supported_by_libretranslate? def to_s "#{name}" end + + def to_param + iso_code + end end diff --git a/app/views/admin/communication/blocks/edit.html.erb b/app/views/admin/communication/blocks/edit.html.erb index 61ef357eb9..95d9ecbc51 100644 --- a/app/views/admin/communication/blocks/edit.html.erb +++ b/app/views/admin/communication/blocks/edit.html.erb @@ -166,7 +166,7 @@ }; $(element).summernote({ - lang: '<%= current_language.summernote_locale unless current_language.summernote_locale.blank? %>', + lang: '<%= current_interface_language.summernote_locale unless current_interface_language.summernote_locale.blank? %>', toolbar: window.SUMMERNOTE_CONFIGS[config].toolbar, // Dependent of app/assets/javascripts/admin/plugins/summernote.js followingToolbar: true, disableDragAndDrop: true, diff --git a/app/views/admin/communication/websites/connections/_direct_source.html.erb b/app/views/admin/communication/websites/connections/_direct_source.html.erb index 474e659f2a..89a946d236 100644 --- a/app/views/admin/communication/websites/connections/_direct_source.html.erb +++ b/app/views/admin/communication/websites/connections/_direct_source.html.erb @@ -3,9 +3,9 @@ source_name = source.to_s begin case type when 'Communication::Website::Page' - source_link = admin_communication_website_page_path(website_id: source.website.id, id: source.id, lang: current_language) + source_link = admin_communication_website_page_path(website_id: source.website.id, id: source.id, lang: source.language) when 'Communication::Website::Post' - source_link = admin_communication_website_post_path(website_id: source.website.id, id: source.id, lang: current_language) + source_link = admin_communication_website_post_path(website_id: source.website.id, id: source.id, lang: source.language) else source_link = url_for [:admin, source] end diff --git a/app/views/admin/research/publications/_form.html.erb b/app/views/admin/research/publications/_form.html.erb index 0abce16d44..6248d6f101 100644 --- a/app/views/admin/research/publications/_form.html.erb +++ b/app/views/admin/research/publications/_form.html.erb @@ -18,11 +18,12 @@ <%= f.input :doi %> <%= f.input :journal_title %> <%= f.input :open_access %> + <%# TODO: ce devrait être la current_language, pas l'interface_language %> <%= f.association :researchers, as: :check_boxes, collection: current_university.university_people .researchers - .for_language(current_language) + .for_language(current_interface_language) .ordered %>
    diff --git a/app/views/application/_summernote_localization.html.erb b/app/views/application/_summernote_localization.html.erb index 0fb23463ed..f677bd1b07 100644 --- a/app/views/application/_summernote_localization.html.erb +++ b/app/views/application/_summernote_localization.html.erb @@ -1,3 +1,3 @@ -<% unless current_language.summernote_locale.blank? %> - +<% unless current_interface_language.summernote_locale.blank? %> + <% end %> From 1953d2cf7a5fc02540b11d17df38e07df6bcd3e9 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Mon, 24 Jun 2024 11:41:09 +0200 Subject: [PATCH 026/349] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Gaya Co-authored-by: Pierre-André Boissinot --- app/models/administration/location.rb | 30 ++----- .../concerns/relations_language_integrity.rb | 5 ++ app/models/concerns/translatable.rb | 74 +++++++++------- db/schema.rb | 86 +++++++++---------- 4 files changed, 101 insertions(+), 94 deletions(-) diff --git a/app/models/administration/location.rb b/app/models/administration/location.rb index b28b600286..30dc6d4f3c 100644 --- a/app/models/administration/location.rb +++ b/app/models/administration/location.rb @@ -71,8 +71,6 @@ class Administration::Location < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true - before_validation :ensure_connected_elements_are_in_correct_language - def to_s "#{name}" end @@ -84,8 +82,14 @@ def git_path(website) def dependencies active_storage_blobs + contents_dependencies + - programs + - schools + translatable_dependencies + end + + def translatable_dependencies_with_relations + [ + { relation: :programs, list: programs }, + { relation: :schools, list: schools } + ] end def references @@ -133,22 +137,4 @@ def has_administration_locations? # Un site (location) n'a pas de site (location) dépendant false end - - private - - def translate_additional_data!(translation) - programs.each do |program| - translated_program = program.find_or_translate!(translation.language) - translation.programs << translated_program - end - schools.each do |school| - translated_school = school.find_or_translate!(translation.language) - translation.schools << translated_school - end - end - - def ensure_connected_elements_are_in_correct_language - ensure_multiple_connections_are_in_correct_language(programs, :program_ids) - ensure_multiple_connections_are_in_correct_language(schools, :school_ids) - end end diff --git a/app/models/concerns/relations_language_integrity.rb b/app/models/concerns/relations_language_integrity.rb index 4c32f9a94b..34521d3bef 100644 --- a/app/models/concerns/relations_language_integrity.rb +++ b/app/models/concerns/relations_language_integrity.rb @@ -1,6 +1,11 @@ module RelationsLanguageIntegrity extend ActiveSupport::Concern + included do + before_validation :ensure_connected_elements_are_in_correct_language + end + + protected def ensure_connected_elements_are_in_correct_language diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index dea39bb1e1..626dc43f50 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -1,8 +1,6 @@ module Translatable extend ActiveSupport::Concern - include RelationsLanguageIntegrity - included do attr_accessor :newly_translated @@ -14,6 +12,8 @@ module Translatable class_name: base_class.to_s, foreign_key: :original_id + before_validation :ensure_translatable_dependencies_are_in_correct_language + # has to be before_destroy because of the foreign key constraints before_destroy :destroy_or_nullify_translations @@ -37,6 +37,16 @@ module Translatable end + # This is supposed to be overwritten in model + # Declare dependencies and their relations with the object + # [ + # { relation: :programs, list: programs }, + # { relation: :author, object: author } + # ] + def translatable_dependencies_with_relations + [] + end + def available_languages @available_languages ||= begin languages = is_direct_object? ? website.languages : university.languages @@ -108,13 +118,21 @@ def translate!(language) translation.save # Handle headings & blocks if object has any translate_contents!(translation) if respond_to?(:contents) - translate_additional_data!(translation) + # Handle dependencies (programs, author, schools...) + translate_dependencies!(translation) translation end protected + def translatable_dependencies + translatable_dependencies_with_relations.map { |hash| + hash.has_key?(:list) ? hash[:list] + : [hash[:object]] + }.flatten + end + def translate_parent!(language) return nil if parent_id.nil? parent.find_or_translate!(language) @@ -141,38 +159,36 @@ def translate_attachment(translation, attachment_name) # Missing attachment end - def translate_additional_data!(translation) - # Overridable method to handle custom cases - end - - def destroy_or_nullify_translations - # Translatable is included in either Direct or Indirect Objects - # If object is direct we do not want to remove the translations - # If object is indirect we remove the translations - if is_direct_object? - translations.update_all(original_id: nil) - else - translations.destroy_all + def translate_dependencies!(translation) + translatable_dependencies_with_relations.each do |hash| + # Single or multiple: programs, author + relation_name = hash[:relation] + # Array of objects or single object + association = association_in_correct_language(hash, translation.language) + translation.public_send("#{relation_name}=", association) end end - def ensure_single_connection_is_in_correct_language(element, property_name, compared_language = language) - return unless element.present? && element.language_id != compared_language.id - element_in_correct_language = element.find_or_translate!(compared_language) - public_send("#{property_name}=", element_in_correct_language.id) + def ensure_translatable_dependencies_are_in_correct_language + translate_dependencies!(self) end - def ensure_multiple_connections_are_in_correct_language(elements, property_name, compared_language = language) - correct_elements_ids = [] - elements.each do |element| - if element.language_id == compared_language.id - element_in_correct_language = element - else - element_in_correct_language = element.find_or_translate!(compared_language) - end - correct_elements_ids << element_in_correct_language.id + def association_in_correct_language(hash, language) + if hash.has_key?(:list) + # association is an array (has_many, habtm, ...) + hash[:list].map { |object| object.find_or_translate!(language) } + else + # association is an object (has_one, belongs_to) + hash[:object].find_or_translate!(language) end - public_send("#{property_name}=", correct_elements_ids) + end + + # Translatable is included in either Direct or Indirect Objects + # If object is direct we do not want to remove the translations + # If object is indirect we remove the translations + def destroy_or_nullify_translations + is_direct_object? ? translations.update_all(original_id: nil) + : translations.destroy_all end end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index f7d56f29ba..f914e42878 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,12 +12,13 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_17_190729) do # These are extensions that must be enabled in order to support this database + enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" enable_extension "unaccent" - create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "action_text_rich_texts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.text "body" t.string "record_type", null: false @@ -27,7 +28,7 @@ t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true end - create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_attachments", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false t.uuid "record_id", null: false @@ -37,7 +38,7 @@ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end - create_table "active_storage_blobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_blobs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "key", null: false t.string "filename", null: false t.string "content_type" @@ -51,7 +52,7 @@ t.index ["university_id"], name: "index_active_storage_blobs_on_university_id" end - create_table "active_storage_variant_records", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_variant_records", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "blob_id", null: false t.string "variation_digest", null: false t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true @@ -97,7 +98,7 @@ t.index ["education_school_id", "administration_location_id"], name: "index_location_school" end - create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.integer "number" t.text "name" t.text "description" @@ -105,7 +106,7 @@ t.datetime "updated_at", null: false end - create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "criterion_id", null: false t.integer "number" t.text "name" @@ -137,7 +138,7 @@ t.index ["university_id"], name: "index_communication_block_headings_on_university_id" end - create_table "communication_blocks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_blocks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type" t.uuid "about_id" @@ -243,7 +244,7 @@ t.index ["university_id"], name: "index_communication_extranet_posts_on_university_id" end - create_table "communication_extranets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranets", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "host" @@ -381,7 +382,7 @@ t.index ["university_id"], name: "index_communication_website_git_file_orphans_on_university_id" end - create_table "communication_website_git_files", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false t.uuid "about_id", null: false @@ -416,7 +417,7 @@ t.index ["university_id"], name: "index_communication_website_localizations_on_university_id" end - create_table "communication_website_menu_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menu_items", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.uuid "menu_id", null: false @@ -436,7 +437,7 @@ t.index ["website_id"], name: "index_communication_website_menu_items_on_website_id" end - create_table "communication_website_menus", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menus", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -452,7 +453,7 @@ t.index ["university_id"], name: "index_communication_website_menus_on_university_id" end - create_table "communication_website_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_pages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -466,10 +467,10 @@ t.boolean "published", default: false t.string "featured_image_alt" t.text "text" + t.text "summary" t.string "breadcrumb_title" t.text "header_text" t.integer "kind" - t.text "summary" t.string "bodyclass" t.uuid "language_id", null: false t.text "featured_image_credit" @@ -489,7 +490,7 @@ t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -555,7 +556,7 @@ t.index ["university_id"], name: "idx_on_university_id_ac2f4a0bfc" end - create_table "communication_website_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "name" @@ -582,7 +583,7 @@ t.index ["university_id"], name: "index_communication_website_post_categories_on_university_id" end - create_table "communication_website_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -623,7 +624,7 @@ t.index ["communication_website_showcase_tag_id", "communication_website_id"], name: "index_showcase_tag_website" end - create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "url" @@ -690,19 +691,18 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at", precision: nil - t.datetime "locked_at", precision: nil - t.datetime "failed_at", precision: nil + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" t.string "locked_by" t.string "queue" - t.datetime "created_at" - t.datetime "updated_at" t.string "signature" t.text "args" - t.index ["priority", "run_at"], name: "delayed_jobs_priority" + t.datetime "created_at" + t.datetime "updated_at" end - create_table "education_academic_years", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.integer "year" t.datetime "created_at", null: false @@ -717,7 +717,7 @@ t.index ["university_person_id", "education_academic_year_id"], name: "index_person_academic_year" end - create_table "education_cohorts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "education_cohorts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "program_id", null: false t.uuid "academic_year_id", null: false @@ -738,7 +738,7 @@ t.index ["university_person_id", "education_cohort_id"], name: "index_person_cohort" end - create_table "education_diplomas", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "education_diplomas", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "short_name" t.integer "level", default: 0 @@ -757,7 +757,7 @@ t.index ["university_id"], name: "index_education_diplomas_on_university_id" end - create_table "education_programs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "education_programs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.integer "capacity" @@ -829,7 +829,7 @@ t.index ["education_program_id", "user_id"], name: "index_education_programs_users_on_program_id_and_user_id" end - create_table "education_schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "education_schools", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -944,7 +944,7 @@ t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)" end - create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "imports", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" t.integer "kind" @@ -957,7 +957,7 @@ t.index ["user_id"], name: "index_imports_on_user_id" end - create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "languages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" t.datetime "created_at", null: false @@ -1009,7 +1009,7 @@ t.index ["university_id"], name: "index_research_journal_paper_kinds_on_university_id" end - create_table "research_journal_papers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_papers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.datetime "published_at", precision: nil t.uuid "university_id", null: false @@ -1047,7 +1047,7 @@ t.index ["researcher_id"], name: "index_research_journal_papers_researchers_on_researcher_id" end - create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_volumes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_journal_id", null: false t.string "title" @@ -1068,7 +1068,7 @@ t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end - create_table "research_journals", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journals", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "title" t.text "meta_description" @@ -1081,7 +1081,7 @@ t.index ["university_id"], name: "index_research_journals_on_university_id" end - create_table "research_laboratories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -1102,7 +1102,7 @@ t.index ["university_person_id", "research_laboratory_id"], name: "laboratory_person" end - create_table "research_laboratory_axes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratory_axes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.string "name" @@ -1147,7 +1147,7 @@ t.index ["university_person_id", "research_publication_id"], name: "index_publication_person" end - create_table "research_theses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_theses", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.uuid "author_id", null: false @@ -1165,7 +1165,7 @@ t.index ["university_id"], name: "index_research_theses_on_university_id" end - create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "universities", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "identifier" t.string "address" @@ -1221,7 +1221,7 @@ t.index ["university_id"], name: "index_university_organization_categories_on_university_id" end - create_table "university_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "long_name" @@ -1264,7 +1264,7 @@ t.index ["organization_id"], name: "index_university_organizations_categories_on_organization_id" end - create_table "university_people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "user_id" t.string "last_name" @@ -1338,7 +1338,7 @@ t.index ["university_id"], name: "index_university_person_categories_on_university_id" end - create_table "university_person_experiences", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_experiences", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.uuid "organization_id", null: false @@ -1352,7 +1352,7 @@ t.index ["university_id"], name: "index_university_person_experiences_on_university_id" end - create_table "university_person_involvements", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_involvements", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.integer "kind" @@ -1367,7 +1367,7 @@ t.index ["university_id"], name: "index_university_person_involvements_on_university_id" end - create_table "university_roles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_roles", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "target_type" t.uuid "target_id" @@ -1389,7 +1389,7 @@ t.index ["user_id"], name: "index_user_favorites_on_user_id" end - create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "users", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "first_name" t.string "last_name" From 06fc87a6ec0a1dee1635181525ee955b4eb5f925 Mon Sep 17 00:00:00 2001 From: pabois Date: Mon, 24 Jun 2024 14:12:50 +0200 Subject: [PATCH 027/349] wip nettoyage --- app/models/administration/location.rb | 5 ++-- app/models/communication/website/menu.rb | 6 ++--- app/models/communication/website/post.rb | 22 +++++++--------- app/models/concerns/translatable.rb | 28 ++++++++++----------- app/models/education/program.rb | 26 ++++++------------- app/models/education/school.rb | 13 +++++----- app/models/university/organization.rb | 12 +++++---- app/models/university/person.rb | 12 +++++---- app/models/university/person/involvement.rb | 13 ++++------ app/models/university/role.rb | 1 + 10 files changed, 62 insertions(+), 76 deletions(-) diff --git a/app/models/administration/location.rb b/app/models/administration/location.rb index 30dc6d4f3c..3005db5ec0 100644 --- a/app/models/administration/location.rb +++ b/app/models/administration/location.rb @@ -82,10 +82,11 @@ def git_path(website) def dependencies active_storage_blobs + contents_dependencies + - translatable_dependencies + programs + + schools end - def translatable_dependencies_with_relations + def translatable_relations [ { relation: :programs, list: programs }, { relation: :schools, list: schools } diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index 212ba9e088..926f147857 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -57,7 +57,8 @@ def template_static "admin/communication/websites/menus/static" end - def translate_additional_data!(translation) + # Override from Translatable + def translate_relations!(translation) items.root.ordered.each { |item| translate_menu_item!(item, translation) } end @@ -66,9 +67,6 @@ def translate_menu_item!(item, menu_translation, parent_translation = nil) item_translation.menu = menu_translation item_translation.parent = parent_translation - # TODO : I18n - # For now, only pages, posts, categories are handled. - # We need to translate programs, diplomas, volumes and papers set_item_translation_attributes(item_translation, item, menu_translation) # If no translation and no children to translate, translation won't be save, as about is nil and kind requires one. diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index fd0e96eca5..5f56bf83ae 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,7 +68,7 @@ class Communication::Website::Post < ApplicationRecord validates :title, presence: true - before_validation :set_published_at, :ensure_connected_elements_are_in_correct_language + before_validation :set_published_at after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id? scope :published, -> { @@ -126,6 +126,13 @@ def dependencies [website.config_default_content_security_policy] end + def translatable_relations + [ + { relation: :categories, list: categories }, + { relation: :author, object: author } + ] + end + def references menus + abouts_with_post_block @@ -139,6 +146,7 @@ def url "#{Static.remove_trailing_slash website.url}#{Static.clean_path current_permalink_in_website(website).path}" end + # FIXME : Should disappear after language check in before_validation def translated_author @translated_author ||= author.find_or_translate!(language) end @@ -175,10 +183,6 @@ def inherited_blob_ids [best_featured_image&.blob_id] end - def ensure_connected_elements_are_in_correct_language - ensure_single_connection_is_in_correct_language(author, :author_id) - end - def update_authors_statuses! old_author = University::Person.find_by(id: author_id_before_last_save) if old_author && old_author.communication_website_posts.none? @@ -187,14 +191,6 @@ def update_authors_statuses! author.update(is_author: true) if author_id end - def translate_additional_data!(translation) - categories.each do |category| - translated_category = category.find_or_translate!(translation.language) - translation.categories << translated_category - end - translation.update(author_id: author.find_or_translate!(translation.language).id) if author_id.present? - end - def abouts_with_post_block website.blocks.posts.collect(&:about) # Potentiel gain de performance (25%) diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index 626dc43f50..1ab20fa7e4 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -12,7 +12,7 @@ module Translatable class_name: base_class.to_s, foreign_key: :original_id - before_validation :ensure_translatable_dependencies_are_in_correct_language + before_validation :ensure_translatable_relations_are_in_correct_language # has to be before_destroy because of the foreign key constraints before_destroy :destroy_or_nullify_translations @@ -43,7 +43,7 @@ module Translatable # { relation: :programs, list: programs }, # { relation: :author, object: author } # ] - def translatable_dependencies_with_relations + def translatable_relations [] end @@ -115,24 +115,18 @@ def translate!(language) translation.parent_id = translate_parent!(language)&.id if respond_to?(:parent_id) # Handle featured image if object has one translate_attachment(translation, :featured_image) if respond_to?(:featured_image) && featured_image.attached? + translate_other_attachments(translation) + # Handle relations (programs, author, schools...) + translate_relations!(translation) translation.save # Handle headings & blocks if object has any translate_contents!(translation) if respond_to?(:contents) - # Handle dependencies (programs, author, schools...) - translate_dependencies!(translation) translation end protected - def translatable_dependencies - translatable_dependencies_with_relations.map { |hash| - hash.has_key?(:list) ? hash[:list] - : [hash[:object]] - }.flatten - end - def translate_parent!(language) return nil if parent_id.nil? parent.find_or_translate!(language) @@ -159,8 +153,12 @@ def translate_attachment(translation, attachment_name) # Missing attachment end - def translate_dependencies!(translation) - translatable_dependencies_with_relations.each do |hash| + # can be overwritten in model + def translate_other_attachments(translation) + end + + def translate_relations!(translation) + translatable_relations.each do |hash| # Single or multiple: programs, author relation_name = hash[:relation] # Array of objects or single object @@ -169,8 +167,8 @@ def translate_dependencies!(translation) end end - def ensure_translatable_dependencies_are_in_correct_language - translate_dependencies!(self) + def ensure_translatable_relations_are_in_correct_language + translate_relations!(self) end def association_in_correct_language(hash, language) diff --git a/app/models/education/program.rb b/app/models/education/program.rb index ca64826ca4..f77cea6329 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -118,8 +118,6 @@ class Education::Program < ApplicationRecord has_one_attached_deletable :downloadable_summary has_one_attached_deletable :logo - before_validation :ensure_connected_elements_are_in_correct_language - before_destroy :move_children validates_presence_of :name @@ -175,6 +173,14 @@ def dependencies [diploma] end + def translatable_relations + [ + { relation: :parent, object: parent }, + { relation: :diploma, object: diploma }, + { relation: :schools, list: schools } + ] + end + def references references = schools + siblings + descendants references << parent if parent.present? @@ -244,21 +250,5 @@ def inherited_blob_ids def move_children children.update(parent_id: parent_id) end - - def translate_additional_data!(translation) - translation.update(parent_id: parent.find_or_translate!(translation.language).id) if parent_id.present? - translation.update(diploma_id: diploma.find_or_translate!(translation.language).id) if diploma_id.present? - schools.each do |school| - translated_school = school.find_or_translate!(translation.language) - translation.schools << translated_school - end - end - - def ensure_connected_elements_are_in_correct_language - ensure_single_connection_is_in_correct_language(parent, :parent_id) - ensure_single_connection_is_in_correct_language(diploma, :diploma_id) - ensure_multiple_connections_are_in_correct_language(schools, :school_ids) - end - end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index b9b43ef6a1..0896a00686 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -55,8 +55,6 @@ class Education::School < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true validates :logo, size: { less_than: 1.megabytes } - before_validation :ensure_connected_elements_are_in_correct_language - scope :ordered, -> { order(:name) } scope :for_search_term, -> (term) { where(" @@ -83,12 +81,19 @@ def git_path(website) def dependencies active_storage_blobs + programs + + # As diplomas are here through programs, and diploma being a program's dependency, it this necessary? diplomas + locations + administrators.map(&:administrator) + researchers.map(&:researcher) end + def translatable_relations + [ + { relation: :programs, list: programs } + ] + end + ##################### # WebsitesLinkable methods ##################### @@ -108,9 +113,5 @@ def explicit_blob_ids logo&.blob_id ] end - - def ensure_connected_elements_are_in_correct_language - ensure_multiple_connections_are_in_correct_language(programs, :program_ids) - end end diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index 4f1fb46c00..7d84087f8a 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -124,6 +124,12 @@ def dependencies blocks end + def translatable_relations + [ + { relation: :categories, list: categories } + ] + end + def git_path(website) "#{git_path_content_prefix(website)}organizations/#{slug}.html" if for_website?(website) end @@ -134,13 +140,9 @@ def to_s protected - def translate_additional_data!(translation) + def translate_other_attachments(translation) translate_attachment(translation, :logo) if logo.attached? translate_attachment(translation, :logo_on_dark_background) if logo_on_dark_background.attached? - categories.each do |category| - translated_category = category.find_or_translate!(translation.language) - translation.categories << translated_category - end end def backlinks_blocks(website) diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 51d1127e44..116fe768ed 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -215,6 +215,12 @@ def dependencies active_storage_blobs end + def translatable_relations + [ + { relation: :categories, list: categories } + ] + end + def references [administrator, author, researcher, teacher] end @@ -266,11 +272,7 @@ def prepare_name self.name = to_s end - def translate_additional_data!(translation) + def translate_other_attachments(translation) translate_attachment(translation, :picture) if picture.attached? - categories.each do |category| - translated_category = category.find_or_translate!(translation.language) - translation.categories << translated_category - end end end diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index 0e555f4a78..e4647adbc2 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -32,6 +32,7 @@ class University::Person::Involvement < ApplicationRecord enum kind: { administrator: 10, researcher: 20, teacher: 30 } belongs_to :person, class_name: 'University::Person' + # Can be an Education::Program, a Research::Laboratory, or a University::Role (attached to Programs or Schools) belongs_to :target, polymorphic: true validates :person_id, uniqueness: { scope: [:target_id, :target_type] } @@ -68,7 +69,7 @@ def set_kind self.kind = :teacher when "Research::Laboratory" self.kind = :researcher - else + else # University::Role (attached to Programs or Schools) self.kind = :administrator end end @@ -81,12 +82,8 @@ def ensure_connected_elements_are_in_correct_language # Si on passe par un rôle, on veut s'assurer que la personne connectée soit de la même langue que le target # Si on passe par autre chose (connexion directe) on veut au contraire s'assurer que c'est le target qui a la même langue que la personne return unless person.language_id != target.language_id - if target.is_a?(University::Role) || target.is_a?(Education::Program) - person_in_correct_language = person.find_or_translate!(target.language) - self.person_id = person_in_correct_language.id - else - target_in_correct_language = target.find_or_translate!(person.language) - self.target_id = target_in_correct_language.id - end + person_in_correct_language = person.find_or_translate!(target.language) + self.person_id = person_in_correct_language.id + end end diff --git a/app/models/university/role.rb b/app/models/university/role.rb index 5ae67f433a..b69717d55e 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -26,6 +26,7 @@ class University::Role < ApplicationRecord include WithUniversity include WithPosition + # Can be an Education::School or an Education::Program belongs_to :target, polymorphic: true, optional: true has_many :involvements, class_name: 'University::Person::Involvement', as: :target, dependent: :destroy, inverse_of: :target has_many :people, through: :involvements From 23a74e91a9599d80f9884acafb3ca736533291a1 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 27 Jun 2024 11:53:48 +0200 Subject: [PATCH 028/349] add translatable to roles --- .../education/programs/roles_controller.rb | 2 +- .../education/schools/roles_controller.rb | 2 +- app/models/concerns/translatable.rb | 4 +- app/models/education/program.rb | 4 +- app/models/university/role.rb | 22 ++++--- .../20240627082422_add_i18n_infos_to_roles.rb | 16 +++++ db/schema.rb | 60 ++++++++++--------- 7 files changed, 69 insertions(+), 41 deletions(-) create mode 100644 db/migrate/20240627082422_add_i18n_infos_to_roles.rb diff --git a/app/controllers/admin/education/programs/roles_controller.rb b/app/controllers/admin/education/programs/roles_controller.rb index 10704279cb..7219d82df1 100644 --- a/app/controllers/admin/education/programs/roles_controller.rb +++ b/app/controllers/admin/education/programs/roles_controller.rb @@ -62,7 +62,7 @@ def breadcrumb def role_params params.require(:university_role) .permit(:description, involvements_attributes: [:id, :person_id, :position, :_destroy]) - .merge(target: @program, university_id: current_university.id) + .merge(target: @program, language_id: @program.language_id, university_id: current_university.id) end def model diff --git a/app/controllers/admin/education/schools/roles_controller.rb b/app/controllers/admin/education/schools/roles_controller.rb index e797bdb2cf..b2c91887e4 100644 --- a/app/controllers/admin/education/schools/roles_controller.rb +++ b/app/controllers/admin/education/schools/roles_controller.rb @@ -62,7 +62,7 @@ def breadcrumb def role_params params.require(:university_role) .permit(:description, involvements_attributes: [:id, :person_id, :position, :_destroy]) - .merge(target: @school, university_id: @school.university_id) + .merge(target: @school, language_id: @school.language_id, university_id: @school.university_id) end def model diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index 1ab20fa7e4..286665a83b 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -176,8 +176,8 @@ def association_in_correct_language(hash, language) # association is an array (has_many, habtm, ...) hash[:list].map { |object| object.find_or_translate!(language) } else - # association is an object (has_one, belongs_to) - hash[:object].find_or_translate!(language) + # association can be an object (has_one, belongs_to) + hash[:object].find_or_translate!(language) if hash[:object].present? end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index f77cea6329..7db8c5d69f 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -177,7 +177,9 @@ def translatable_relations [ { relation: :parent, object: parent }, { relation: :diploma, object: diploma }, - { relation: :schools, list: schools } + { relation: :schools, list: schools }, + { relation: :university_roles, list: university_roles } + # TODO: Add direct involvements when translatable ] end diff --git a/app/models/university/role.rb b/app/models/university/role.rb index b69717d55e..7726d587e4 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -8,21 +8,27 @@ # target_type :string indexed => [target_id] # created_at :datetime not null # updated_at :datetime not null +# language_id :uuid indexed +# original_id :uuid indexed # target_id :uuid indexed => [target_type] # university_id :uuid not null, indexed # # Indexes # +# index_university_roles_on_language_id (language_id) +# index_university_roles_on_original_id (original_id) # index_university_roles_on_target (target_type,target_id) # index_university_roles_on_university_id (university_id) # # Foreign Keys # # fk_rails_8e52293a38 (university_id => universities.id) +# fk_rails_961921e9ca (original_id => university_roles.id) +# fk_rails_caf681fd5c (language_id => languages.id) # class University::Role < ApplicationRecord - include RelationsLanguageIntegrity include Sanitizable + include Translatable include WithUniversity include WithPosition @@ -31,11 +37,13 @@ class University::Role < ApplicationRecord has_many :involvements, class_name: 'University::Person::Involvement', as: :target, dependent: :destroy, inverse_of: :target has_many :people, through: :involvements - delegate :language_id, :language, to: :target - accepts_nested_attributes_for :involvements, reject_if: :all_blank, allow_destroy: true - - before_validation :ensure_connected_elements_are_in_correct_language + + # def translatable_relations + # [ + # { relation: :programs, list: programs } + # ] + # end def to_s "#{description}" @@ -50,9 +58,5 @@ def sync_with_git def last_ordered_element self.class.unscoped.where(university_id: university_id, target: target).ordered.last end - - def ensure_connected_elements_are_in_correct_language - ensure_multiple_connections_are_in_correct_language(people, :person_ids, target.language) - end end diff --git a/db/migrate/20240627082422_add_i18n_infos_to_roles.rb b/db/migrate/20240627082422_add_i18n_infos_to_roles.rb new file mode 100644 index 0000000000..74519d10bc --- /dev/null +++ b/db/migrate/20240627082422_add_i18n_infos_to_roles.rb @@ -0,0 +1,16 @@ +class AddI18nInfosToRoles < ActiveRecord::Migration[7.1] + def up + add_reference :university_roles, :language, foreign_key: true, type: :uuid + add_reference :university_roles, :original, foreign_key: {to_table: :university_roles}, type: :uuid + + University::Role.reset_column_information + University::Role.all.each do |role| + role.update(language_id: role.target.language_id) + end + end + + def down + remove_reference :university_roles, :original + remove_reference :university_roles, :language + end +end diff --git a/db/schema.rb b/db/schema.rb index f914e42878..b11f6b3379 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_17_190729) do +ActiveRecord::Schema[7.1].define(version: 2024_06_27_082422) do # These are extensions that must be enabled in order to support this database - enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" @@ -120,7 +119,7 @@ t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end - create_table "communication_block_headings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_block_headings", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -149,8 +148,8 @@ t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.uuid "communication_website_id" + t.uuid "heading_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -158,7 +157,7 @@ t.index ["university_id"], name: "index_communication_blocks_on_university_id" end - create_table "communication_extranet_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "extranet_id", null: false t.string "about_type" @@ -170,7 +169,7 @@ t.index ["university_id"], name: "index_communication_extranet_connections_on_university_id" end - create_table "communication_extranet_document_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -182,7 +181,7 @@ t.index ["university_id"], name: "extranet_document_categories_universities" end - create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_document_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "extranet_id", null: false t.uuid "university_id", null: false t.string "name" @@ -194,7 +193,7 @@ t.index ["university_id"], name: "extranet_document_kinds_universities" end - create_table "communication_extranet_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_documents", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.uuid "extranet_id", null: false @@ -210,7 +209,7 @@ t.index ["university_id"], name: "index_communication_extranet_documents_on_university_id" end - create_table "communication_extranet_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "slug" t.uuid "extranet_id", null: false @@ -222,7 +221,7 @@ t.index ["university_id"], name: "index_communication_extranet_post_categories_on_university_id" end - create_table "communication_extranet_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranet_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.boolean "published", default: false t.datetime "published_at" @@ -302,7 +301,7 @@ t.index ["university_id"], name: "index_communication_website_agenda_categories_on_university_id" end - create_table "communication_website_agenda_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_agenda_events", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.text "summary" t.uuid "university_id", null: false @@ -347,7 +346,7 @@ t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_connections", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "indirect_object_type", null: false @@ -691,15 +690,16 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" + t.datetime "run_at", precision: nil + t.datetime "locked_at", precision: nil + t.datetime "failed_at", precision: nil t.string "locked_by" t.string "queue" - t.string "signature" - t.text "args" t.datetime "created_at" t.datetime "updated_at" + t.string "signature" + t.text "args" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| @@ -849,7 +849,7 @@ t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "emergency_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "emergency_messages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id" t.string "name" t.string "role" @@ -971,7 +971,7 @@ t.index ["university_id", "language_id"], name: "index_languages_universities_on_university_id_and_language_id" end - create_table "research_hal_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_hal_authors", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "docid" t.string "form_identifier" t.string "person_identifier" @@ -997,7 +997,7 @@ t.index ["university_person_id", "research_hal_author_id"], name: "hal_author_person" end - create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "journal_id", null: false t.string "title" @@ -1116,7 +1116,7 @@ t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end - create_table "research_publications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "research_publications", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "hal_docid" t.jsonb "data" t.string "title" @@ -1194,7 +1194,7 @@ t.index ["name"], name: "index_universities_on_name", opclass: :gin_trgm_ops, using: :gin end - create_table "university_apps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_apps", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "token" @@ -1205,7 +1205,7 @@ t.index ["university_id"], name: "index_university_apps_on_university_id" end - create_table "university_organization_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organization_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1257,7 +1257,7 @@ t.index ["university_id"], name: "index_university_organizations_on_university_id" end - create_table "university_organizations_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "organization_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_organizations_categories_on_category_id" @@ -1315,14 +1315,14 @@ t.index ["user_id"], name: "index_university_people_on_user_id" end - create_table "university_people_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "person_id", null: false t.uuid "category_id", null: false t.index ["category_id"], name: "index_university_people_categories_on_category_id" t.index ["person_id"], name: "index_university_people_categories_on_person_id" end - create_table "university_person_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1375,11 +1375,15 @@ t.integer "position" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.uuid "language_id" + t.uuid "original_id" + t.index ["language_id"], name: "index_university_roles_on_language_id" + t.index ["original_id"], name: "index_university_roles_on_original_id" t.index ["target_type", "target_id"], name: "index_university_roles_on_target" t.index ["university_id"], name: "index_university_roles_on_university_id" end - create_table "user_favorites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "user_favorites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "user_id", null: false t.string "about_type", null: false t.uuid "about_id", null: false @@ -1582,7 +1586,9 @@ add_foreign_key "university_person_experiences", "university_people", column: "person_id" add_foreign_key "university_person_involvements", "universities" add_foreign_key "university_person_involvements", "university_people", column: "person_id" + add_foreign_key "university_roles", "languages" add_foreign_key "university_roles", "universities" + add_foreign_key "university_roles", "university_roles", column: "original_id" add_foreign_key "user_favorites", "users" add_foreign_key "users", "languages" add_foreign_key "users", "universities" From 90b98a79a4dc8e147054a73657560f3d96f71e4b Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 27 Jun 2024 15:37:46 +0200 Subject: [PATCH 029/349] involvements i18n --- .../education/programs/roles_controller.rb | 3 +- .../admin/education/programs_controller.rb | 2 +- app/models/concerns/translatable.rb | 5 ++-- app/models/education/program.rb | 4 +-- app/models/education/school.rb | 3 +- app/models/university/person/involvement.rb | 28 +++++++++---------- app/models/university/role.rb | 10 +++---- .../programs/_involvement_fields.html.erb | 2 ++ .../roles/_involvement_fields.html.erb | 7 ++--- .../20240627082422_add_i18n_infos_to_roles.rb | 2 +- ...27095534_add_i18n_infos_to_involvements.rb | 22 +++++++++++++++ db/schema.rb | 8 +++++- 12 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20240627095534_add_i18n_infos_to_involvements.rb diff --git a/app/controllers/admin/education/programs/roles_controller.rb b/app/controllers/admin/education/programs/roles_controller.rb index 7219d82df1..dffde1f3eb 100644 --- a/app/controllers/admin/education/programs/roles_controller.rb +++ b/app/controllers/admin/education/programs/roles_controller.rb @@ -37,6 +37,7 @@ def update if @role.update(role_params) redirect_to admin_education_program_role_path(@role), notice: t('admin.successfully_updated_html', model: @role.to_s) else + byebug breadcrumb render :edit, status: :unprocessable_entity add_breadcrumb t('edit') @@ -61,7 +62,7 @@ def breadcrumb def role_params params.require(:university_role) - .permit(:description, involvements_attributes: [:id, :person_id, :position, :_destroy]) + .permit(:description, involvements_attributes: [:id, :person_id, :language_id, :university_id, :position, :_destroy]) .merge(target: @program, language_id: @program.language_id, university_id: current_university.id) end diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index 83aac9459e..59a919fcb5 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -129,7 +129,7 @@ def program_params :pricing, :pricing_apprenticeship, :pricing_continuing, :pricing_initial, :duration, :downloadable_summary, :downloadable_summary_delete, :parent_id, :diploma_id, school_ids: [], - university_person_involvements_attributes: [:id, :person_id, :description, :position, :_destroy] + university_person_involvements_attributes: [:id, :person_id, :language_id, :university_id, :description, :position, :_destroy] ) .merge( university_id: current_university.id diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb index 286665a83b..4bc84e74f1 100644 --- a/app/models/concerns/translatable.rb +++ b/app/models/concerns/translatable.rb @@ -185,8 +185,9 @@ def association_in_correct_language(hash, language) # If object is direct we do not want to remove the translations # If object is indirect we remove the translations def destroy_or_nullify_translations - is_direct_object? ? translations.update_all(original_id: nil) - : translations.destroy_all + # TODO: remove ? + # is_direct_object? ? translations.update_all(original_id: nil) + # : translations.destroy_all end end \ No newline at end of file diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 7db8c5d69f..b5f1298584 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -178,8 +178,8 @@ def translatable_relations { relation: :parent, object: parent }, { relation: :diploma, object: diploma }, { relation: :schools, list: schools }, - { relation: :university_roles, list: university_roles } - # TODO: Add direct involvements when translatable + { relation: :university_roles, list: university_roles }, + { relation: :university_person_involvements, list: university_person_involvements } ] end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 0896a00686..e7c3d7f8a4 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -90,7 +90,8 @@ def dependencies def translatable_relations [ - { relation: :programs, list: programs } + { relation: :programs, list: programs }, + { relation: :university_roles, list: university_roles } ] end diff --git a/app/models/university/person/involvement.rb b/app/models/university/person/involvement.rb index e4647adbc2..fffc13152f 100644 --- a/app/models/university/person/involvement.rb +++ b/app/models/university/person/involvement.rb @@ -9,23 +9,30 @@ # target_type :string not null, indexed => [target_id] # created_at :datetime not null # updated_at :datetime not null +# language_id :uuid indexed +# original_id :uuid indexed # person_id :uuid not null, indexed # target_id :uuid not null, indexed => [target_type] # university_id :uuid not null, indexed # # Indexes # +# index_university_person_involvements_on_language_id (language_id) +# index_university_person_involvements_on_original_id (original_id) # index_university_person_involvements_on_person_id (person_id) # index_university_person_involvements_on_target (target_type,target_id) # index_university_person_involvements_on_university_id (university_id) # # Foreign Keys # +# fk_rails_0e1e65ddb0 (original_id => university_person_involvements.id) +# fk_rails_3df2a6f2d9 (language_id => languages.id) # fk_rails_407e2a671c (person_id => university_people.id) # fk_rails_5c704f6338 (university_id => universities.id) # class University::Person::Involvement < ApplicationRecord include Sanitizable + include Translatable include WithUniversity include WithPosition @@ -38,8 +45,7 @@ class University::Person::Involvement < ApplicationRecord validates :person_id, uniqueness: { scope: [:target_id, :target_type] } validates :target_id, uniqueness: { scope: [:person_id, :target_type] } - before_validation :set_kind, :set_university_id, on: :create - before_validation :ensure_connected_elements_are_in_correct_language + before_validation :set_kind, on: :create after_commit :sync_with_git @@ -49,6 +55,12 @@ class University::Person::Involvement < ApplicationRecord } scope :ordered_by_date, -> { order(:created_at) } + def translatable_relations + [ + { relation: :person, object: person } + ] + end + def to_s "#{person}" end @@ -74,16 +86,4 @@ def set_kind end end - def set_university_id - self.university_id = self.person.university_id - end - - def ensure_connected_elements_are_in_correct_language - # Si on passe par un rôle, on veut s'assurer que la personne connectée soit de la même langue que le target - # Si on passe par autre chose (connexion directe) on veut au contraire s'assurer que c'est le target qui a la même langue que la personne - return unless person.language_id != target.language_id - person_in_correct_language = person.find_or_translate!(target.language) - self.person_id = person_in_correct_language.id - - end end diff --git a/app/models/university/role.rb b/app/models/university/role.rb index 7726d587e4..36a3f0aa21 100644 --- a/app/models/university/role.rb +++ b/app/models/university/role.rb @@ -39,11 +39,11 @@ class University::Role < ApplicationRecord accepts_nested_attributes_for :involvements, reject_if: :all_blank, allow_destroy: true - # def translatable_relations - # [ - # { relation: :programs, list: programs } - # ] - # end + def translatable_relations + [ + { relation: :involvements, list: involvements } + ] + end def to_s "#{description}" diff --git a/app/views/admin/education/programs/_involvement_fields.html.erb b/app/views/admin/education/programs/_involvement_fields.html.erb index 53b196e684..fca30d64e1 100644 --- a/app/views/admin/education/programs/_involvement_fields.html.erb +++ b/app/views/admin/education/programs/_involvement_fields.html.erb @@ -21,5 +21,7 @@ class: 'btn btn-sm btn-danger' %>
    + <%= f.hidden_field :university_id, value: current_university.id %> + <%= f.hidden_field :language_id, value: current_language.id %> <%= f.hidden_field :id if include_id %>
    diff --git a/app/views/admin/education/programs/roles/_involvement_fields.html.erb b/app/views/admin/education/programs/roles/_involvement_fields.html.erb index a787c7f681..165d1dff65 100644 --- a/app/views/admin/education/programs/roles/_involvement_fields.html.erb +++ b/app/views/admin/education/programs/roles/_involvement_fields.html.erb @@ -11,10 +11,9 @@ <%= link_to_remove_association "".html_safe, f, class: 'btn btn-sm text-danger' %> -
    - <%= link_to_remove_association "".html_safe, - f, - class: 'text-danger' %> <%= f.hidden_field :position, data: { 'sortable-input': '' } %> + <%= f.hidden_field :university_id, value: current_university.id %> + <%= f.hidden_field :language_id, value: current_language.id %> <%= f.hidden_field :id if include_id %> +
    diff --git a/db/migrate/20240627082422_add_i18n_infos_to_roles.rb b/db/migrate/20240627082422_add_i18n_infos_to_roles.rb index 74519d10bc..2400443981 100644 --- a/db/migrate/20240627082422_add_i18n_infos_to_roles.rb +++ b/db/migrate/20240627082422_add_i18n_infos_to_roles.rb @@ -5,7 +5,7 @@ def up University::Role.reset_column_information University::Role.all.each do |role| - role.update(language_id: role.target.language_id) + role.update_column(:language_id, role.target.language_id) end end diff --git a/db/migrate/20240627095534_add_i18n_infos_to_involvements.rb b/db/migrate/20240627095534_add_i18n_infos_to_involvements.rb new file mode 100644 index 0000000000..862f3ef664 --- /dev/null +++ b/db/migrate/20240627095534_add_i18n_infos_to_involvements.rb @@ -0,0 +1,22 @@ +class AddI18nInfosToInvolvements < ActiveRecord::Migration[7.1] + def up + add_reference :university_person_involvements, :language, foreign_key: true, type: :uuid + add_reference :university_person_involvements, :original, foreign_key: {to_table: :university_person_involvements}, type: :uuid + + University::Person::Involvement.reset_column_information + University::Person::Involvement.all.find_each do |involvement| + if involvement.target_type == 'Research::Laboratory' + # atm laboratory has no language + language_id = involvement.user.language_id + else + language_id = involvement.target.language_id + end + involvement.update_column(:language_id, language_id) + end + end + + def down + remove_reference :university_person_involvements, :original + remove_reference :university_person_involvements, :language + end +end diff --git a/db/schema.rb b/db/schema.rb index b11f6b3379..75dc380b86 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_06_27_082422) do +ActiveRecord::Schema[7.1].define(version: 2024_06_27_095534) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -1362,6 +1362,10 @@ t.integer "position" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.uuid "language_id" + t.uuid "original_id" + t.index ["language_id"], name: "index_university_person_involvements_on_language_id" + t.index ["original_id"], name: "index_university_person_involvements_on_original_id" t.index ["person_id"], name: "index_university_person_involvements_on_person_id" t.index ["target_type", "target_id"], name: "index_university_person_involvements_on_target" t.index ["university_id"], name: "index_university_person_involvements_on_university_id" @@ -1584,8 +1588,10 @@ add_foreign_key "university_person_experiences", "universities" add_foreign_key "university_person_experiences", "university_organizations", column: "organization_id" add_foreign_key "university_person_experiences", "university_people", column: "person_id" + add_foreign_key "university_person_involvements", "languages" add_foreign_key "university_person_involvements", "universities" add_foreign_key "university_person_involvements", "university_people", column: "person_id" + add_foreign_key "university_person_involvements", "university_person_involvements", column: "original_id" add_foreign_key "university_roles", "languages" add_foreign_key "university_roles", "universities" add_foreign_key "university_roles", "university_roles", column: "original_id" From 8c7efaa9887b7e89521f3431e776fab068a254d7 Mon Sep 17 00:00:00 2001 From: pabois Date: Thu, 27 Jun 2024 17:27:26 +0200 Subject: [PATCH 030/349] routes & languages switch --- .../admin/application_controller.rb | 2 +- .../websites/application_controller.rb | 7 ++--- .../communication/websites_controller.rb | 5 ---- app/controllers/admin/dashboard_controller.rb | 6 ++++ .../programs/application_controller.rb | 3 +- .../schools/application_controller.rb | 3 +- .../journals/application_controller.rb | 7 ++--- .../laboratories/application_controller.rb | 7 ++--- .../administration/locations/index.html.erb | 4 --- .../application/_language_switcher.html.erb | 6 ++-- .../application/components/_nav.html.erb | 4 +++ .../blocks/content/_editor.html.erb | 4 +-- .../photo_imports/_selector.html.erb | 4 +-- .../websites/_language_switcher.html.erb | 15 ---------- .../websites/agenda/categories/index.html.erb | 4 --- .../websites/agenda/categories/show.html.erb | 4 --- .../websites/agenda/events/index.html.erb | 4 --- .../websites/agenda/events/show.html.erb | 4 --- .../websites/connections/index.html.erb | 4 +-- .../websites/git_analysis/index.html.erb | 2 +- .../websites/localizations/show.html.erb | 4 --- .../websites/menus/index.html.erb | 4 --- .../websites/menus/items/edit.html.erb | 4 --- .../websites/menus/items/new.html.erb | 4 --- .../websites/menus/show.html.erb | 4 --- .../websites/pages/index.html.erb | 4 --- .../websites/pages/index_list.html.erb | 4 --- .../show/special_pages/_organization.html.erb | 2 +- .../portfolio/categories/index.html.erb | 4 --- .../portfolio/categories/show.html.erb | 4 --- .../portfolio/projects/index.html.erb | 4 --- .../websites/portfolio/projects/show.html.erb | 4 --- .../websites/posts/authors/index.html.erb | 4 --- .../websites/posts/authors/show.html.erb | 4 --- .../websites/posts/categories/index.html.erb | 4 --- .../websites/posts/index.html.erb | 4 --- .../communication/websites/show.html.erb | 4 --- .../admin/education/diplomas/index.html.erb | 4 --- .../admin/education/programs/index.html.erb | 4 --- .../admin/education/schools/index.html.erb | 4 --- .../admin/education/teachers/index.html.erb | 4 --- .../organizations/categories/index.html.erb | 4 --- .../university/organizations/index.html.erb | 4 --- .../people/categories/index.html.erb | 4 --- .../admin/university/people/index.html.erb | 4 --- config/routes.rb | 28 +++++++++++-------- config/routes/admin/administration.rb | 2 +- config/routes/admin/communication.rb | 16 +++++------ config/routes/admin/education.rb | 8 +++--- config/routes/admin/university.rb | 4 +-- 50 files changed, 64 insertions(+), 191 deletions(-) delete mode 100644 app/views/admin/communication/websites/_language_switcher.html.erb diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 82a4c8579c..854b4d52b5 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -40,7 +40,7 @@ def load_block_copy_cookie def default_url_options options = {} - options[:lang] = current_language.iso_code + options[:lang] = current_language options end diff --git a/app/controllers/admin/communication/websites/application_controller.rb b/app/controllers/admin/communication/websites/application_controller.rb index c858990c5c..917eb9706c 100644 --- a/app/controllers/admin/communication/websites/application_controller.rb +++ b/app/controllers/admin/communication/websites/application_controller.rb @@ -27,11 +27,8 @@ def breadcrumb end def default_url_options - options = {} - if @website.present? - options[:website_id] = @website.id - options[:lang] = current_language.iso_code - end + options = super + options[:website_id] = @website.id if @website&.persisted? options end end diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index d7df9dc817..59e1a23c0c 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -104,9 +104,4 @@ def website_params ) end - def default_url_options - options = {} - options[:lang] = current_language.iso_code if @website&.persisted? - options - end end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index dd170122f3..6edfbed00e 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -7,4 +7,10 @@ def index @namespaces << Administration if feature_administration? breadcrumb end + + # called from /admin without any language specified + def redirect_to_default_language + redirect_to admin_root_path(lang: current_university.default_language) + end + end diff --git a/app/controllers/admin/education/programs/application_controller.rb b/app/controllers/admin/education/programs/application_controller.rb index a2fec9f930..5d5b5e9b93 100644 --- a/app/controllers/admin/education/programs/application_controller.rb +++ b/app/controllers/admin/education/programs/application_controller.rb @@ -12,8 +12,7 @@ def breadcrumb end def default_url_options - options = {} - options[:lang] = current_language.iso_code + options = super options[:program_id] = params[:program_id] if params.has_key? :program_id options end diff --git a/app/controllers/admin/education/schools/application_controller.rb b/app/controllers/admin/education/schools/application_controller.rb index 145a5d3062..d26872b293 100644 --- a/app/controllers/admin/education/schools/application_controller.rb +++ b/app/controllers/admin/education/schools/application_controller.rb @@ -12,8 +12,7 @@ def breadcrumb end def default_url_options - options = {} - options[:lang] = current_language.iso_code + options = super options[:school_id] = params[:school_id] if params.has_key? :school_id options end diff --git a/app/controllers/admin/research/journals/application_controller.rb b/app/controllers/admin/research/journals/application_controller.rb index 8f7759e154..e70e732f2f 100644 --- a/app/controllers/admin/research/journals/application_controller.rb +++ b/app/controllers/admin/research/journals/application_controller.rb @@ -18,9 +18,8 @@ def breadcrumb end def default_url_options - return {} unless params.has_key? :journal_id - { - journal_id: params[:journal_id] - } + options = super + options[:journal_id] = params[:journal_id] if params.has_key? :journal_id + options end end diff --git a/app/controllers/admin/research/laboratories/application_controller.rb b/app/controllers/admin/research/laboratories/application_controller.rb index 6907007fce..66ba4cd620 100644 --- a/app/controllers/admin/research/laboratories/application_controller.rb +++ b/app/controllers/admin/research/laboratories/application_controller.rb @@ -17,9 +17,8 @@ def breadcrumb end def default_url_options - return {} unless params.has_key? :laboratory_id - { - laboratory_id: params[:laboratory_id] - } + options = super + options[:laboratory_id] = params[:laboratory_id] if params.has_key? :laboratory_id + options end end diff --git a/app/views/admin/administration/locations/index.html.erb b/app/views/admin/administration/locations/index.html.erb index ba1aaa512a..880744fed1 100644 --- a/app/views/admin/administration/locations/index.html.erb +++ b/app/views/admin/administration/locations/index.html.erb @@ -1,9 +1,5 @@ <% content_for :title, Administration::Location.model_name.human(count: 2) %> -<% content_for :title_right do %> - <%= render 'language_switcher' %> -<% end %> - <%= render 'admin/administration/locations/list', locations: @locations %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/application/_language_switcher.html.erb b/app/views/admin/application/_language_switcher.html.erb index 77d8738663..967a36c013 100644 --- a/app/views/admin/application/_language_switcher.html.erb +++ b/app/views/admin/application/_language_switcher.html.erb @@ -1,6 +1,8 @@ -<% if current_university.languages.many? %> +<% languages = (@website && @website.persisted?) ? @website.languages : current_university.languages %> + +<% if languages.many? %> <% - languages_options = current_university.languages.ordered.map { |language| + languages_options = languages.ordered.map { |language| [ language_name(language.iso_code), url_for(request.params.merge(lang: language.iso_code)) diff --git a/app/views/admin/application/components/_nav.html.erb b/app/views/admin/application/components/_nav.html.erb index cc0dfe3f94..9b98ae8930 100644 --- a/app/views/admin/application/components/_nav.html.erb +++ b/app/views/admin/application/components/_nav.html.erb @@ -1,11 +1,15 @@ <% context ||= 'navigation/admin' %> +
  2. diff --git a/app/views/server/websites/_list.html.erb b/app/views/server/websites/_list.html.erb index 8747456783..be3a132320 100644 --- a/app/views/server/websites/_list.html.erb +++ b/app/views/server/websites/_list.html.erb @@ -23,7 +23,7 @@ [:server, website.university] %> <%= link_to t('server_admin.websites.admin'), - admin_communication_website_url(website, host: website.university.url), + admin_communication_website_url(website, host: website.university.url, lang: website.default_language), target: :_blank, class: 'action' %> <%= link_to Communication::Website.human_attribute_name('url'), diff --git a/db/schema.rb b/db/schema.rb index 645d35a66b..bc6f3a0203 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,13 +12,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_27_095534) do # These are extensions that must be enabled in order to support this database - enable_extension "pg_stat_statements" enable_extension "pg_trgm" enable_extension "pgcrypto" enable_extension "plpgsql" enable_extension "unaccent" - create_table "action_text_rich_texts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.text "body" t.string "record_type", null: false @@ -28,7 +27,7 @@ t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true end - create_table "active_storage_attachments", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false t.uuid "record_id", null: false @@ -38,7 +37,7 @@ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end - create_table "active_storage_blobs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_blobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "key", null: false t.string "filename", null: false t.string "content_type" @@ -52,7 +51,7 @@ t.index ["university_id"], name: "index_active_storage_blobs_on_university_id" end - create_table "active_storage_variant_records", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "active_storage_variant_records", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "blob_id", null: false t.string "variation_digest", null: false t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true @@ -98,7 +97,7 @@ t.index ["education_school_id", "administration_location_id"], name: "index_location_school" end - create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number" t.text "name" t.text "description" @@ -106,7 +105,7 @@ t.datetime "updated_at", null: false end - create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "criterion_id", null: false t.integer "number" t.text "name" @@ -138,7 +137,7 @@ t.index ["university_id"], name: "index_communication_block_headings_on_university_id" end - create_table "communication_blocks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_blocks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "about_type" t.uuid "about_id" @@ -244,7 +243,7 @@ t.index ["university_id"], name: "index_communication_extranet_posts_on_university_id" end - create_table "communication_extranets", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_extranets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.uuid "university_id", null: false t.string "host" @@ -382,7 +381,7 @@ t.index ["university_id"], name: "index_communication_website_git_file_orphans_on_university_id" end - create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_git_files", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false t.uuid "about_id", null: false @@ -417,7 +416,7 @@ t.index ["university_id"], name: "index_communication_website_localizations_on_university_id" end - create_table "communication_website_menu_items", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menu_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.uuid "menu_id", null: false @@ -437,7 +436,7 @@ t.index ["website_id"], name: "index_communication_website_menu_items_on_website_id" end - create_table "communication_website_menus", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_menus", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -453,7 +452,7 @@ t.index ["university_id"], name: "index_communication_website_menus_on_university_id" end - create_table "communication_website_pages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -467,10 +466,10 @@ t.boolean "published", default: false t.string "featured_image_alt" t.text "text" - t.text "summary" t.string "breadcrumb_title" t.text "header_text" t.integer "kind" + t.text "summary" t.string "bodyclass" t.uuid "language_id", null: false t.text "featured_image_credit" @@ -490,7 +489,7 @@ t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false @@ -556,7 +555,7 @@ t.index ["university_id"], name: "idx_on_university_id_ac2f4a0bfc" end - create_table "communication_website_post_categories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_post_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "name" @@ -583,7 +582,7 @@ t.index ["university_id"], name: "index_communication_website_post_categories_on_university_id" end - create_table "communication_website_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false t.string "title" @@ -624,7 +623,7 @@ t.index ["communication_website_showcase_tag_id", "communication_website_id"], name: "index_showcase_tag_website" end - create_table "communication_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "url" @@ -667,8 +666,6 @@ t.datetime "git_files_analysed_at" t.boolean "highlighted_in_showcase", default: false t.uuid "locked_by_job_id" - t.string "deuxfleurs_access_key_id" - t.string "deuxfleurs_secret_access_key" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["default_language_id"], name: "index_communication_websites_on_default_language_id" t.index ["name"], name: "index_communication_websites_on_name", opclass: :gin_trgm_ops, using: :gin @@ -693,18 +690,19 @@ t.integer "attempts", default: 0, null: false t.text "handler", null: false t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" + t.datetime "run_at", precision: nil + t.datetime "locked_at", precision: nil + t.datetime "failed_at", precision: nil t.string "locked_by" t.string "queue" - t.string "signature" - t.text "args" t.datetime "created_at" t.datetime "updated_at" + t.string "signature" + t.text "args" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" end - create_table "education_academic_years", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_academic_years", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.integer "year" t.datetime "created_at", null: false @@ -719,7 +717,7 @@ t.index ["university_person_id", "education_academic_year_id"], name: "index_person_academic_year" end - create_table "education_cohorts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_cohorts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "program_id", null: false t.uuid "academic_year_id", null: false @@ -740,7 +738,7 @@ t.index ["university_person_id", "education_cohort_id"], name: "index_person_cohort" end - create_table "education_diplomas", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_diplomas", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "short_name" t.integer "level", default: 0 @@ -759,7 +757,7 @@ t.index ["university_id"], name: "index_education_diplomas_on_university_id" end - create_table "education_programs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_programs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.integer "capacity" @@ -831,7 +829,7 @@ t.index ["education_program_id", "user_id"], name: "index_education_programs_users_on_program_id_and_user_id" end - create_table "education_schools", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "education_schools", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -946,7 +944,7 @@ t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)" end - create_table "imports", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" t.integer "kind" @@ -959,7 +957,7 @@ t.index ["user_id"], name: "index_imports_on_user_id" end - create_table "languages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" t.datetime "created_at", null: false @@ -1011,7 +1009,7 @@ t.index ["university_id"], name: "index_research_journal_paper_kinds_on_university_id" end - create_table "research_journal_papers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_papers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.datetime "published_at", precision: nil t.uuid "university_id", null: false @@ -1049,7 +1047,7 @@ t.index ["researcher_id"], name: "index_research_journal_papers_researchers_on_researcher_id" end - create_table "research_journal_volumes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_journal_id", null: false t.string "title" @@ -1070,7 +1068,7 @@ t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end - create_table "research_journals", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_journals", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "title" t.text "meta_description" @@ -1083,7 +1081,7 @@ t.index ["university_id"], name: "index_research_journals_on_university_id" end - create_table "research_laboratories", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "address" @@ -1104,7 +1102,7 @@ t.index ["university_person_id", "research_laboratory_id"], name: "laboratory_person" end - create_table "research_laboratory_axes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_laboratory_axes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.string "name" @@ -1149,7 +1147,7 @@ t.index ["university_person_id", "research_publication_id"], name: "index_publication_person" end - create_table "research_theses", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "research_theses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "research_laboratory_id", null: false t.uuid "author_id", null: false @@ -1167,7 +1165,7 @@ t.index ["university_id"], name: "index_research_theses_on_university_id" end - create_table "universities", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "identifier" t.string "address" @@ -1223,7 +1221,7 @@ t.index ["university_id"], name: "index_university_organization_categories_on_university_id" end - create_table "university_organizations", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" t.string "long_name" @@ -1266,7 +1264,7 @@ t.index ["organization_id"], name: "index_university_organizations_categories_on_organization_id" end - create_table "university_people", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "user_id" t.string "last_name" @@ -1340,7 +1338,7 @@ t.index ["university_id"], name: "index_university_person_categories_on_university_id" end - create_table "university_person_experiences", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_experiences", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.uuid "organization_id", null: false @@ -1354,7 +1352,7 @@ t.index ["university_id"], name: "index_university_person_experiences_on_university_id" end - create_table "university_person_involvements", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_person_involvements", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "person_id", null: false t.integer "kind" @@ -1373,7 +1371,7 @@ t.index ["university_id"], name: "index_university_person_involvements_on_university_id" end - create_table "university_roles", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "university_roles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "target_type" t.uuid "target_id" @@ -1399,7 +1397,7 @@ t.index ["user_id"], name: "index_user_favorites_on_user_id" end - create_table "users", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "first_name" t.string "last_name" From 8d3c6956409e9c4666c3b6f0d94821342e297a91 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Fri, 28 Jun 2024 13:23:23 +0200 Subject: [PATCH 033/349] wip --- Gemfile | 1 + Gemfile.lock | 82 +++++------ .../admin/communication/websites/init.js | 1 - .../communication/websites/lang_switch.js | 26 ---- .../admin/design-system/layout.sass | 1 + .../stylesheets/admin/design-system/nav.sass | 78 ++++++---- .../users/registrations_controller.rb | 2 +- .../osuny/simple_navigation_renderer.rb | 2 +- .../application/_language_switcher.html.erb | 19 --- .../application/components/_nav.html.erb | 133 ++++++++++-------- config/initializers/lucide_rails.rb | 3 + .../navigation/admin_directory_navigation.rb | 18 +++ config/navigation/admin_navigation.rb | 6 - 13 files changed, 189 insertions(+), 183 deletions(-) delete mode 100644 app/assets/javascripts/admin/communication/websites/lang_switch.js delete mode 100644 app/views/admin/application/_language_switcher.html.erb create mode 100644 config/initializers/lucide_rails.rb create mode 100644 config/navigation/admin_directory_navigation.rb diff --git a/Gemfile b/Gemfile index 182817fc56..8ea35f2a19 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ gem "kamifusen"#, path: "../kamifusen" gem "kaminari" gem "leaflet-rails" gem "libretranslate"#, path: "../libretranslate" +gem "lucide-rails" gem "mini_magick" gem "observer", "~> 0.1.2" gem "octokit" diff --git a/Gemfile.lock b/Gemfile.lock index 5449eeddf2..6e920d83b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/noesya/good_job.git - revision: 70e6a44874fe38681814fafaed5b9e75de4f2f90 + revision: f7391eed85757b8e0ee05df33cd5c62bbff4b72e specs: good_job (3.29.3) activejob (>= 6.0.0) @@ -125,8 +125,8 @@ GEM add_to_calendar (0.4.0) tzinfo (>= 1.1, < 3) tzinfo-data (~> 1.2020) - addressable (2.8.6) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) angularjs-rails (1.8.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) @@ -134,17 +134,17 @@ GEM autoprefixer-rails (10.4.16.0) execjs (~> 2) aws-eventstream (1.3.0) - aws-partitions (1.940.0) - aws-sdk-core (3.197.0) + aws-partitions (1.948.0) + aws-sdk-core (3.199.0) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.83.0) - aws-sdk-core (~> 3, >= 3.197.0) + aws-sdk-kms (1.87.0) + aws-sdk-core (~> 3, >= 3.199.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.152.0) - aws-sdk-core (~> 3, >= 3.197.0) + aws-sdk-s3 (1.154.0) + aws-sdk-core (~> 3, >= 3.199.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.8) aws-sigv4 (1.8.0) @@ -163,7 +163,7 @@ GEM rails (>= 3.1) breadcrumbs_on_rails (4.1.0) railties (>= 5.0) - bugsnag (6.27.0) + bugsnag (6.27.1) concurrent-ruby (~> 1.0) builder (3.3.0) byebug (11.1.3) @@ -182,7 +182,7 @@ GEM marcel (~> 1.0) nokogiri (~> 1.10, >= 1.10.4) rubyzip (>= 1.3.0, < 3) - caxlsx_rails (0.6.3) + caxlsx_rails (0.6.4) actionpack (>= 3.1) caxlsx (>= 3.0) citeproc (1.0.10) @@ -191,7 +191,7 @@ GEM citeproc (~> 1.0, >= 1.0.9) csl (~> 2.0) cocoon (1.2.15) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.3) connection_pool (2.4.1) countries (6.0.1) unaccent (~> 0.3) @@ -227,7 +227,7 @@ GEM encryptor (3.0.0) enum_help (0.0.19) activesupport (>= 3.0.0) - erubi (1.12.0) + erubi (1.13.0) et-orbi (1.2.11) tzinfo ethon (0.16.0) @@ -236,7 +236,7 @@ GEM faceted_search (3.6.2) font-awesome-sass rails (>= 5.2.0) - faraday (2.9.1) + faraday (2.9.2) faraday-net_http (>= 2.0, < 3.2) faraday-cookie_jar (0.0.7) faraday (>= 0.8.0) @@ -257,9 +257,7 @@ GEM faraday-retry (2.2.1) faraday (~> 2.0) fastimage (2.3.1) - ffi (1.17.0-arm64-darwin) ffi (1.17.0-x86_64-darwin) - ffi (1.17.0-x86_64-linux-gnu) figaro (1.2.0) thor (>= 0.14.0, < 2) font-awesome-sass (6.5.2) @@ -285,18 +283,12 @@ GEM geocoder (1.8.3) base64 (>= 0.1.0) csv (>= 3.0.0) - gitlab (4.19.0) + gitlab (5.0.0) httparty (~> 0.20) terminal-table (>= 1.5.1) globalid (1.2.1) activesupport (>= 6.1) - google-protobuf (4.27.1-arm64-darwin) - bigdecimal - rake (>= 13) - google-protobuf (4.27.1-x86_64-darwin) - bigdecimal - rake (>= 13) - google-protobuf (4.27.1-x86_64-linux) + google-protobuf (4.27.2-x86_64-darwin) bigdecimal rake (>= 13) hal_openscience (0.1.0) @@ -327,7 +319,7 @@ GEM mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) io-console (0.7.2) - irb (1.13.1) + irb (1.13.2) rdoc (>= 4.0.0) reline (>= 0.4.2) jbuilder (2.12.0) @@ -339,7 +331,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.7.2) - jwt (2.8.1) + jwt (2.8.2) base64 kamifusen (1.11.2) image_processing @@ -369,6 +361,8 @@ GEM loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) + lucide-rails (0.4.0) + railties (>= 4.1.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap @@ -388,9 +382,9 @@ GEM fastimage (~> 2.2) nesty (~> 1.0) nokogiri (~> 1.13) - mini_magick (4.12.0) + mini_magick (4.13.1) mini_mime (1.1.5) - minitest (5.23.1) + minitest (5.24.0) msgpack (1.7.2) multi_xml (0.7.1) bigdecimal (~> 3.1) @@ -401,7 +395,7 @@ GEM nesty (1.0.2) net-http (0.4.1) uri - net-imap (0.4.12) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) @@ -411,11 +405,7 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.3) - nokogiri (1.16.5-arm64-darwin) - racc (~> 1.4) - nokogiri (1.16.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.16.5-x86_64-linux) + nokogiri (1.16.6-x86_64-darwin) racc (~> 1.4) oauth2 (2.0.9) faraday (>= 0.17.3, < 3.0) @@ -425,8 +415,7 @@ GEM snaky_hash (~> 2.0) version_gem (~> 1.1) observer (0.1.2) - octokit (8.1.0) - base64 + octokit (9.1.0) faraday (>= 1, < 3) sawyer (~> 0.9) omniauth (2.1.2) @@ -454,12 +443,12 @@ GEM popper_js (2.11.8) psych (5.1.2) stringio - public_suffix (5.0.5) + public_suffix (6.0.0) puma (6.4.2) nio4r (~> 2.0) raabro (1.4.0) racc (1.8.0) - rack (3.0.11) + rack (3.1.4) rack-mini-profiler (2.3.4) rack (>= 1.2.0) rack-protection (4.0.0) @@ -518,15 +507,15 @@ GEM redis-client (0.22.2) connection_pool regexp_parser (2.9.2) - reline (0.5.8) + reline (0.5.9) io-console (~> 0.5) requests (1.0.2) require_all (3.0.0) responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.8) - strscan (>= 3.0.9) + rexml (3.3.1) + strscan roo (2.10.1) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) @@ -537,7 +526,7 @@ GEM ruby-vips (2.2.1) ffi (~> 1.12) rubyzip (2.3.2) - sanitize (6.1.0) + sanitize (6.1.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) sassc (2.4.0) @@ -590,7 +579,7 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - stringio (3.1.0) + stringio (3.1.1) strscan (3.1.0) sugar-high (0.7.3) sweetloader (0.1.6) @@ -599,7 +588,7 @@ GEM terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.3.1) - tilt (2.3.0) + tilt (2.4.0) time (0.3.0) date timeout (0.4.1) @@ -640,13 +629,11 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.15) + zeitwerk (2.6.16) zlib (2.1.1) PLATFORMS - arm64-darwin-23 x86_64-darwin-23 - x86_64-linux DEPENDENCIES active_storage_validations (~> 1) @@ -696,6 +683,7 @@ DEPENDENCIES leaflet-rails libretranslate listen (~> 3.3) + lucide-rails mini_magick observer (~> 0.1.2) octokit diff --git a/app/assets/javascripts/admin/communication/websites/init.js b/app/assets/javascripts/admin/communication/websites/init.js index f3887d3758..11ddf46160 100644 --- a/app/assets/javascripts/admin/communication/websites/init.js +++ b/app/assets/javascripts/admin/communication/websites/init.js @@ -1,5 +1,4 @@ //= require_self -//= require ./lang_switch //= require ./menu_items window.osuny.communication.websites = {}; diff --git a/app/assets/javascripts/admin/communication/websites/lang_switch.js b/app/assets/javascripts/admin/communication/websites/lang_switch.js deleted file mode 100644 index 2547d147af..0000000000 --- a/app/assets/javascripts/admin/communication/websites/lang_switch.js +++ /dev/null @@ -1,26 +0,0 @@ -window.osuny.communication.websites.langSwitch = { - init: function () { - 'use strict'; - this.select = document.querySelector('#js-lang-switch'); - if (this.select) { - this.select.addEventListener('change', this.onChange.bind(this)); - } - }, - - onChange: function () { - 'use strict'; - document.location.href = this.select.selectedOptions[0].value; - }, - - invoke: function () { - 'use strict'; - return { - init: this.init.bind(this) - }; - } -}.invoke(); - -window.addEventListener('DOMContentLoaded', function () { - 'use strict'; - window.osuny.communication.websites.langSwitch.init(); -}); diff --git a/app/assets/stylesheets/admin/design-system/layout.sass b/app/assets/stylesheets/admin/design-system/layout.sass index 6676575282..fd3eccb9f9 100644 --- a/app/assets/stylesheets/admin/design-system/layout.sass +++ b/app/assets/stylesheets/admin/design-system/layout.sass @@ -4,6 +4,7 @@ body .container-fluid padding-left: var(--bs-gutter-x) padding-right: var(--bs-gutter-x) + max-width: 1800px @media (min-width: 768px) #{--bs-gutter-x}: 4rem diff --git a/app/assets/stylesheets/admin/design-system/nav.sass b/app/assets/stylesheets/admin/design-system/nav.sass index 0df6c74a65..0f640baf82 100644 --- a/app/assets/stylesheets/admin/design-system/nav.sass +++ b/app/assets/stylesheets/admin/design-system/nav.sass @@ -1,42 +1,66 @@ .navbar - button - color: white - .bi - font-size: 26px - vertical-align: middle - .navbar-brand - img - width: 100px - .btn-open - margin-right: -10px -#menu + .btn + color: $gray-300 + &:hover + background: $gray-800 + +.popin-menu background: black - bottom: 0 - color: white - left: 0 + border-radius: var(--bs-border-radius) + color: $color-white + font-family: $font-family-sans-serif !important + margin: 0.5rem overflow-y: scroll - padding-bottom: 30px - position: fixed - right: 0 - top: 0 + padding: 1rem + position: absolute z-index: 1000 + a + color: $color-white + &:hover + color: $gray-100 + hr + color: $gray-500 + margin-left: -1rem + margin-right: -1rem .image border-radius: 100% margin-bottom: 20px width: 100px + ul + list-style-type: none + padding: 0 + li + padding-bottom: 5px + span + opacity: 0.2 .menu-content - margin-top: 50px position: relative + .section + color: $gray-500 + font-size: pxToRem(16) + margin-bottom: 0.5rem + text-transform: uppercase + &#menu-main + min-width: 90% + &#menu-profile, + &#menu-language + right: 0 + &#menu-language ul - list-style-type: none - padding: 0 + margin-bottom: 0 li - padding-bottom: 5px - span - opacity: 0.2 - a - color: white - text-decoration: none + list-style: none + a + color: $color-white + &.active + color: $gray-500 + &#menu-profile + min-width: 300px + .profile + &__name + margin-bottom: 0 + &__email + color: $gray-500 .commands backdrop-filter: blur(6px) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 9581173cf2..d9b11dfa43 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -8,7 +8,7 @@ class Users::RegistrationsController < Devise::RegistrationsController def edit add_breadcrumb t('admin.dashboard'), :admin_root_path if can? :read, @user - add_breadcrumb User.model_name.human(count: 2), admin_users_path + # add_breadcrumb User.model_name.human(count: 2), admin_users_path add_breadcrumb @user, [:admin, @user] add_breadcrumb t('edit') else diff --git a/app/services/osuny/simple_navigation_renderer.rb b/app/services/osuny/simple_navigation_renderer.rb index b1dcd9275a..425eeb2c4b 100644 --- a/app/services/osuny/simple_navigation_renderer.rb +++ b/app/services/osuny/simple_navigation_renderer.rb @@ -1,5 +1,5 @@ class Osuny::SimpleNavigationRenderer < SimpleNavigation::Renderer::Base - OPEN = "
    " + OPEN = "
    " CLOSE = "
    " attr_accessor :content, :index, :item diff --git a/app/views/admin/application/_language_switcher.html.erb b/app/views/admin/application/_language_switcher.html.erb deleted file mode 100644 index 967a36c013..0000000000 --- a/app/views/admin/application/_language_switcher.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% languages = (@website && @website.persisted?) ? @website.languages : current_university.languages %> - -<% if languages.many? %> - <% - languages_options = languages.ordered.map { |language| - [ - language_name(language.iso_code), - url_for(request.params.merge(lang: language.iso_code)) - ] - } - selected_option = url_for(request.params.merge(lang: current_language.iso_code)) - %> - - <%= select_tag nil, - options_for_select(languages_options, selected_option), - class: "form-control form-select", - id: "js-lang-switch" %> - -<% end %> \ No newline at end of file diff --git a/app/views/admin/application/components/_nav.html.erb b/app/views/admin/application/components/_nav.html.erb index dec58faabd..9ff56e83da 100644 --- a/app/views/admin/application/components/_nav.html.erb +++ b/app/views/admin/application/components/_nav.html.erb @@ -1,67 +1,90 @@ <% context ||= 'navigation/admin' +languages = (@website && @website.persisted?) ? @website.languages.ordered + : current_university.languages.ordered %> - -