diff --git a/app/controllers/admin/communication/websites/localizations_controller.rb b/app/controllers/admin/communication/websites/localizations_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..b71ebabdde774d6410a70b53e0a9a750bc46be4d --- /dev/null +++ b/app/controllers/admin/communication/websites/localizations_controller.rb @@ -0,0 +1,40 @@ +class Admin::Communication::Websites::LocalizationsController < Admin::Communication::Websites::ApplicationController + skip_before_action :load_filters + + before_action :load_localization + + def show + breadcrumb + end + + def update + if @localization.update_and_sync(localization_params) + redirect_to admin_communication_website_localization_path, notice: t('admin.successfully_updated_html', model: Communication::Website::Localization.model_name.human) + else + breadcrumb + render :show, status: :unprocessable_entity + end + end + + protected + + def load_localization + @localization = @website.find_or_create_localization_for(current_website_language) + authorize! :update, @localization + end + + def breadcrumb + super + add_breadcrumb helpers.language_name(current_website_language.iso_code) + add_breadcrumb t('admin.communication.website.localizations.title') + end + + def localization_params + params.require(:communication_website_localization) + .permit( + :name, + :social_email, :social_facebook, :social_github, :social_instagram, :social_linkedin, + :social_mastodon, :social_peertube, :social_tiktok, :social_vimeo, :social_x, :social_youtube + ) + end +end diff --git a/app/helpers/admin/communication/website/localizations_helper.rb b/app/helpers/admin/communication/website/localizations_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..e30177825a91f379fb2dd4352d90b28667cbfa5a --- /dev/null +++ b/app/helpers/admin/communication/website/localizations_helper.rb @@ -0,0 +1,17 @@ +module Admin::Communication::Website::LocalizationsHelper + def localization_input(f, attribute_name, website) + label = Communication::Website.human_attribute_name(attribute_name) + + is_editing_master = f.object.is_a?(Communication::Website) + master_value = website.public_send(attribute_name) + if !is_editing_master && master_value.present? + hint = t('admin.communication.website.localizations.fallback_hint_html', master_value: master_value) + else + hint = nil + end + + f.input attribute_name, + label: label, + hint: hint + end +end \ No newline at end of file diff --git a/app/models/communication/website/localization.rb b/app/models/communication/website/localization.rb index b9523c758dd349e541c264af499c61dd8f63126d..1937d46f7b58e25ddb5d476f6557a89f660c0bce 100644 --- a/app/models/communication/website/localization.rb +++ b/app/models/communication/website/localization.rb @@ -3,18 +3,18 @@ # Table name: communication_website_localizations # # id :uuid not null, primary key -# email :string -# facebook :string -# github :string -# instagram :string -# linkedin :string -# mastodon :string # name :string -# peertube :string -# tiktok :string -# vimeo :string -# x :string -# youtube :string +# social_email :string +# social_facebook :string +# social_github :string +# social_instagram :string +# social_linkedin :string +# social_mastodon :string +# social_peertube :string +# social_tiktok :string +# social_vimeo :string +# social_x :string +# social_youtube :string # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed @@ -40,11 +40,27 @@ class Communication::Website::Localization < ApplicationRecord belongs_to :language + validates :language_id, uniqueness: { scope: :communication_website_id } + before_validation :set_university_id + # Localization is not directly exportable to git + # Whereas the languages config in the dependencies is exportable to git + def exportable_to_git? + false + end + + def dependencies + [website.config_default_languages] + end + + def to_s + name.present? ? "#{name}" : website.to_s + end + private def set_university_id - self.university_id = communication_website.university_id + self.university_id = website.university_id end end diff --git a/app/models/communication/website/with_languages.rb b/app/models/communication/website/with_languages.rb index 0f686e089c463e4412ef12efa1ab9b430c9c0ce9..95591dcdf8c7cb8e6d880729ae74427e35f40e63 100644 --- a/app/models/communication/website/with_languages.rb +++ b/app/models/communication/website/with_languages.rb @@ -11,7 +11,9 @@ module Communication::Website::WithLanguages foreign_key: :communication_website_id, association_foreign_key: :language_id, after_remove: :flag_languages_change - has_many :localizations, dependent: :destroy + has_many :localizations, + foreign_key: :communication_website_id, + dependent: :destroy validates :languages, length: { minimum: 1 } validate :languages_must_include_default_language @@ -35,6 +37,11 @@ module Communication::Website::WithLanguages localization end + def find_or_create_localization_for(language) + return self if language.id == default_language_id + localizations.find_or_create_by(language_id: language.id) + end + protected def languages_must_include_default_language diff --git a/app/services/icon.rb b/app/services/icon.rb index f8a94ca5f33476e99b430d201d4bcf40e890e64e..b09a73897fdd87c7293b7ccbb6464f855755690f 100644 --- a/app/services/icon.rb +++ b/app/services/icon.rb @@ -5,6 +5,7 @@ class Icon COMMUNICATION_EXTRANET = 'fas fa-project-diagram' COMMUNICATION_WEBSITE = 'fas fa-sitemap' COMMUNICATION_WEBSITE_HOME = 'fas fa-home' + COMMUNICATION_WEBSITE_LOCALIZATIONS = 'fas fa-globe' COMMUNICATION_WEBSITE_POST = 'fas fa-newspaper' COMMUNICATION_WEBSITE_PAGE = 'fas fa-file' COMMUNICATION_WEBSITE_PAGES = 'fas fa-sitemap' @@ -60,7 +61,7 @@ class Icon OSUNY_USER = 'fas fa-user' USER = OSUNY_USER - + ADD = 'fas fa-plus' ARROW_RIGHT = 'fas fa-arrow-right' A11Y = 'fas fa-universal-access' diff --git a/app/views/admin/communication/websites/_sidebar.html.erb b/app/views/admin/communication/websites/_sidebar.html.erb index ebd838a964c77d1885ece044b7f398625327ad18..43b53ce044975c590caadad0baa9c646bce69377 100644 --- a/app/views/admin/communication/websites/_sidebar.html.erb +++ b/app/views/admin/communication/websites/_sidebar.html.erb @@ -38,6 +38,13 @@ ability: can?(:read, Communication::Website::Post::Category) } + navigation << { + title: t('admin.communication.website.localizations.title'), + path: admin_communication_website_localization_path(website_id: @website), + icon: Icon::COMMUNICATION_WEBSITE_LOCALIZATIONS, + ability: can?(:read, Communication::Website::Localization) + } if @website.languages.many? + navigation << { title: t('communication.website.analytics'), path: analytics_admin_communication_website_path(@website.id, website_id: nil), diff --git a/app/views/admin/communication/websites/configs/default_languages/static.html.erb b/app/views/admin/communication/websites/configs/default_languages/static.html.erb index acddc20ec56dc6637870f81175ce95c335464808..c85d7645f42e8f4da8f09facb2d2bac587607240 100644 --- a/app/views/admin/communication/websites/configs/default_languages/static.html.erb +++ b/app/views/admin/communication/websites/configs/default_languages/static.html.erb @@ -1,11 +1,37 @@ # DO NOT EDIT THIS FILE BY HAND - IT WILL BE OVERWRITTEN BY OSUNY -<% @website.languages.each do |language| %> +<% +@website.languages.each do |language| + localization = @website.localization_for(language) +%> <%= language.iso_code %>: - title: <%= @website %><%# TODO I18n: Traduire le nom du site %> + title: <%= localization %> contentDir: content/<%= language.iso_code %> languageCode: <%= language.iso_code %> languageName: <%= language.name %> + params: + social: + <%- + [ + :email, + :mastodon, + :peertube, + :x, + :github, + :linkedin, + :youtube, + :vimeo, + :instagram, + :facebook, + :tiktok + ].each do |network| + value = localization.public_send "social_#{network}" + value = @website.public_send "social_#{network}" if value.blank? + next if value.blank? + -%> + <%= network %>: >- + <%= value %> + <%- end -%> permalinks: <% Communication::Website::Permalink.config_in_website(@website, language).each do |key, value| %> <%= key %>: <%= value %> diff --git a/app/views/admin/communication/websites/localizations/show.html.erb b/app/views/admin/communication/websites/localizations/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..7c438b159c0db4f6bc5a52fc29259ec3d4b91b44 --- /dev/null +++ b/app/views/admin/communication/websites/localizations/show.html.erb @@ -0,0 +1,43 @@ +<% content_for :title, "#{t('admin.communication.website.localizations.title')}" %> + +<% content_for :title_right do %> + <%= language_name(current_website_language.iso_code) %> +<% end %> + +<%= render 'admin/communication/websites/sidebar' do %> + <%= simple_form_for [:admin, @localization], as: :communication_website_localization, url: admin_communication_website_localization_path do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + + <%= osuny_panel t('content') do %> + <%= localization_input f, :name, @website %> + <% end %> + + <%= osuny_panel Communication::Website.human_attribute_name('social') do %> + <div class="row"> + <div class="col-lg-6"> + <p><%= t('admin.communication.website.social.free') %></p> + <%= localization_input f, :social_email, @website %> + <%= localization_input f, :social_mastodon, @website %> + <%= localization_input f, :social_peertube, @website %> + </div> + <div class="col-lg-6"> + <p><%= t('admin.communication.website.social.private') %></p> + <%= localization_input f, :social_x, @website %> + <%= localization_input f, :social_github, @website %> + <%= localization_input f, :social_linkedin, @website %> + <%= localization_input f, :social_youtube, @website %> + <%= localization_input f, :social_vimeo, @website %> + <%= localization_input f, :social_instagram, @website %> + <%= localization_input f, :social_facebook, @website %> + <%= localization_input f, :social_tiktok, @website %> + </div> + </div> + <% end %> + + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> + <% end %> + +<% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 7b2d2e04922f916921640173dc4ab6e2940628a8..2f0971b8ade0203dec9395949866c55445643861 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -280,6 +280,9 @@ en: editorial: label: Editorial description: Everything related to content + localizations: + fallback_hint_html: "Leave blank to use the default value: <i>%{master_value}</i>" + title: Internationalization technical: label: Technical description: Everything related to technical settings diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index c54f405afab76963ea787d5dc6596dda7ff13609..099aee1bfb3e23bde05ae36e603c23930ebb4645 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -280,6 +280,9 @@ fr: editorial: label: Éditorial description: Tout ce qui est lié au contenu + localizations: + fallback_hint_html: "Laisser vide pour utiliser la valeur par défaut : <i>%{master_value}</i>" + title: Internationalisation technical: label: Technique description: Tout ce qui est lié aux réglages techniques diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index bb24319d55a16786f58e26fbecde068dc28ae24e..303289d08b65fb3442e4cca0d5d3345bdf993fae 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -41,7 +41,7 @@ namespace :communication do get :children get :static end - end + end resources :authors, controller: '/admin/communication/websites/posts/authors', path: '/:lang/authors', only: [:index, :show] end resources :posts, controller: 'websites/posts', path: '/:lang/posts' do @@ -87,6 +87,7 @@ namespace :communication do end end end + resource :localization, controller: 'websites/localizations', path: '/:lang/localization', only: [:show, :update] end scope "/contents/:about_type/:about_id", as: :contents, controller: 'contents' do get :write diff --git a/db/migrate/20240122144217_rename_social_attributes_in_localizations.rb b/db/migrate/20240122144217_rename_social_attributes_in_localizations.rb new file mode 100644 index 0000000000000000000000000000000000000000..e9178cd76ac5e0418ca7f50ba3dfa9f93a690168 --- /dev/null +++ b/db/migrate/20240122144217_rename_social_attributes_in_localizations.rb @@ -0,0 +1,15 @@ +class RenameSocialAttributesInLocalizations < ActiveRecord::Migration[7.1] + def change + rename_column :communication_website_localizations, :email, :social_email + rename_column :communication_website_localizations, :mastodon, :social_mastodon + rename_column :communication_website_localizations, :peertube, :social_peertube + rename_column :communication_website_localizations, :x, :social_x + rename_column :communication_website_localizations, :github, :social_github + rename_column :communication_website_localizations, :linkedin, :social_linkedin + rename_column :communication_website_localizations, :youtube, :social_youtube + rename_column :communication_website_localizations, :vimeo, :social_vimeo + rename_column :communication_website_localizations, :instagram, :social_instagram + rename_column :communication_website_localizations, :facebook, :social_facebook + rename_column :communication_website_localizations, :tiktok, :social_tiktok + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d3cb5e914379ebb346f1dd2091a9277af8f8655..72fe05620b73cb80eba5d49dcf5193b4cad1ca9e 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_01_22_132556) do +ActiveRecord::Schema[7.1].define(version: 2024_01_22_144217) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -331,17 +331,17 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_22_132556) do t.uuid "language_id", null: false t.uuid "university_id", null: false t.string "name" - t.string "email" - t.string "mastodon" - t.string "peertube" - t.string "x" - t.string "github" - t.string "linkedin" - t.string "youtube" - t.string "vimeo" - t.string "instagram" - t.string "facebook" - t.string "tiktok" + t.string "social_email" + t.string "social_mastodon" + t.string "social_peertube" + t.string "social_x" + t.string "social_github" + t.string "social_linkedin" + t.string "social_youtube" + t.string "social_vimeo" + t.string "social_instagram" + t.string "social_facebook" + t.string "social_tiktok" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["communication_website_id"], name: "idx_on_communication_website_id_ed4630e334"