From b9cd8c4d7f26091849172072e785859d2debf10c Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 10 Oct 2023 14:44:47 +0200 Subject: [PATCH] Default image --- Gemfile.lock | 8 ++++---- .../admin/communication/websites_controller.rb | 2 +- app/models/communication/website.rb | 6 +++++- app/views/admin/communication/websites/_form.html.erb | 8 ++++++++ app/views/admin/communication/websites/static.html.erb | 4 ++++ config/locales/communication/en.yml | 2 ++ config/locales/communication/fr.yml | 2 ++ db/schema.rb | 5 ++--- 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 54c0680c8..9705bb5e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -161,9 +161,9 @@ GEM csl (~> 2.0) cocoon (1.2.15) concurrent-ruby (1.2.2) - countries (5.6.0) + countries (5.7.0) unaccent (~> 0.3) - country_select (8.0.2) + country_select (8.0.3) countries (~> 5.0) crack (0.4.5) rexml @@ -353,7 +353,7 @@ GEM nesty (1.0.2) net-http (0.3.2) uri - net-imap (0.4.0) + net-imap (0.4.1) date net-protocol net-pop (0.1.2) @@ -461,7 +461,7 @@ GEM nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) rotp (6.3.0) - ruby-saml (1.15.0) + ruby-saml (1.16.0) nokogiri (>= 1.13.10) rexml ruby-vips (2.1.4) diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 36d1774ab..4d931dc92 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -73,7 +73,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites: :name, :url, :repository, :about_type, :about_id, :in_production, :git_provider, :git_endpoint, :git_branch, :plausible_url, :feature_posts, :feature_agenda, - :deuxfleurs_hosting, + :deuxfleurs_hosting, :default_image, :default_image_delete, :social_mastodon, :social_x, :social_linkedin, :social_youtube, :social_vimeo, :social_peertube, :social_instagram, :social_facebook, :social_tiktok, :social_email, :social_github, :deployment_status_badge, :autoupdate_theme, language_ids: [] ] diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 0942ac751..0886d3dfc 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -77,6 +77,9 @@ class Communication::Website < ApplicationRecord gitlab: 1 } + has_one_attached_deletable :default_image + validates :default_image, size: { less_than: 5.megabytes } + before_validation :sanitize_fields scope :ordered, -> { order(:name) } @@ -114,7 +117,8 @@ class Communication::Website < ApplicationRecord events.where(language_id: language_ids) + categories.where(language_id: language_ids) + menus.where(language_id: language_ids) + - [about] + [about] + + [default_image&.blob] end def website diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 412b5a445..57989105b 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -35,6 +35,14 @@ label_method: lambda { |l| language_name(l.iso_code) }, input_html: (@website.persisted? ? { disabled: true } : { class: "js-default-language" }) %> <% end %> + <%= osuny_panel Communication::Website.human_attribute_name('appearance') do %> + <%= f.input :default_image, + as: :single_deletable_file, + direct_upload: true, + hint: '5 Mo max, .jpg, .jpeg, .png, .svg', + input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + preview: true %> + <% end %> </div> </div> <div class="row"> diff --git a/app/views/admin/communication/websites/static.html.erb b/app/views/admin/communication/websites/static.html.erb index 6ed5c1d2f..e7fe00d08 100644 --- a/app/views/admin/communication/websites/static.html.erb +++ b/app/views/admin/communication/websites/static.html.erb @@ -1,5 +1,9 @@ title: > <%= @about.to_s %> +<% if @website.default_image.attached? %> +default_image: + id: <%= @website.default_image.blob&.id %> +<% end %> external_domains: <% @website.external_domains.each do |domain| %> - "<%= domain %>" diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 6cd50c56b..ef0bef5bd 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -130,9 +130,11 @@ en: about_Research::Journal: Journal website about_Research::Laboratory: Laboratory website about_type: About + appearance: Appearance autoupdate_theme: Automatically update Osuny theme access_token: Access token created_at: Creation + default_image: Default image default_language: Default language deployment_status_badge: Deployment status badge deuxfleurs_hosting: Hébergement avec Deuxfleurs diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index a61369e14..e08fad43b 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -130,9 +130,11 @@ fr: about_Research::Journal: Site de revue scientifique about_Research::Laboratory: Site de laboratoire about_type: Type de site + appearance: Apparence autoupdate_theme: Mise à jour automatique du thème Osuny access_token: Jeton d'accès created_at: Création + default_image: Image par défaut default_language: Langue par défaut deployment_status_badge: Badge de statut du déploiement deuxfleurs_hosting: Hébergement avec Deuxfleurs diff --git a/db/schema.rb b/db/schema.rb index cb3e15ec4..eb300673c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -106,8 +106,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do 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" @@ -229,7 +229,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do t.text "home_sentence" t.text "sass" t.text "css" - t.boolean "allow_experiences_modification", default: true t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end @@ -390,7 +389,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_06_145950) do 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 -- GitLab