From 190ad4538d8182b32b1c0adff6a8d19bfafcc0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Fri, 2 Aug 2024 17:35:42 +0200 Subject: [PATCH 1/9] wip migrations and models (should adapt base models) --- .../website/agenda/category/localization.rb | 8 +-- .../communication/website/agenda/event.rb | 5 ++ .../portfolio/category/localization.rb | 54 +++++++++++++++ .../website/portfolio/project.rb | 5 ++ .../website/portfolio/project/localization.rb | 65 +++++++++++++++++++ ...website_portfolio_project_localizations.rb | 63 ++++++++++++++++++ ...ebsite_portfolio_category_localizations.rb | 63 ++++++++++++++++++ 7 files changed, 259 insertions(+), 4 deletions(-) create mode 100644 app/models/communication/website/portfolio/category/localization.rb create mode 100644 app/models/communication/website/portfolio/project/localization.rb create mode 100644 db/migrate/20240802131238_create_communication_website_portfolio_project_localizations.rb create mode 100644 db/migrate/20240802132626_create_communication_website_portfolio_category_localizations.rb diff --git a/app/models/communication/website/agenda/category/localization.rb b/app/models/communication/website/agenda/category/localization.rb index 50d4677f9..e983f97d1 100644 --- a/app/models/communication/website/agenda/category/localization.rb +++ b/app/models/communication/website/agenda/category/localization.rb @@ -46,7 +46,7 @@ class Communication::Website::Agenda::Category::Localization < ApplicationRecord belongs_to :website, class_name: 'Communication::Website', foreign_key: :communication_website_id - + validates :name, presence: true before_validation :set_communication_website_id @@ -67,15 +67,15 @@ def dependencies def to_s "#{name}" end - + protected def slug_unavailable?(slug) self.class .unscoped .where( - communication_website_id: self.communication_website_id, - language_id: language_id, + communication_website_id: self.communication_website_id, + language_id: language_id, slug: slug ) .where.not(id: self.id) diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index cdcd2133b..a44ca83bd 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -110,6 +110,11 @@ def references abouts_with_agenda_block end + # TODO L10N : to remove + def translate_other_attachments(translation) + translate_attachment(translation, :shared_image) if shared_image.attached? + end + protected def abouts_with_agenda_block diff --git a/app/models/communication/website/portfolio/category/localization.rb b/app/models/communication/website/portfolio/category/localization.rb new file mode 100644 index 000000000..fac0a8700 --- /dev/null +++ b/app/models/communication/website/portfolio/category/localization.rb @@ -0,0 +1,54 @@ +class Communication::Website::Portfolio::Category::Localization < ApplicationRecord + include AsLocalization + include Contentful + include Initials + include Permalinkable # We override slug_unavailable? method + include Sanitizable + include WithBlobs + include WithFeaturedImage + include WithGitFiles + include WithUniversity + + belongs_to :website, + class_name: 'Communication::Website', + foreign_key: :communication_website_id + + validates :name, presence: true + + before_validation :set_communication_website_id + + def git_path(website) + "#{git_path_content_prefix(website)}projects_categories/#{slug}/_index.html" + end + + def template_static + "admin/communication/websites/portfolio/categories/static" + end + + def dependencies + active_storage_blobs + + contents_dependencies + end + + def to_s + "#{name}" + end + + protected + + def slug_unavailable?(slug) + self.class + .unscoped + .where( + communication_website_id: self.communication_website_id, + language_id: language_id, + slug: slug + ) + .where.not(id: self.id) + .exists? + end + + def set_communication_website_id + self.communication_website_id ||= about.communication_website_id + end +end diff --git a/app/models/communication/website/portfolio/project.rb b/app/models/communication/website/portfolio/project.rb index 9825ff2ce..e8256d37f 100644 --- a/app/models/communication/website/portfolio/project.rb +++ b/app/models/communication/website/portfolio/project.rb @@ -105,6 +105,11 @@ def to_s "#{title}" end + # TODO L10N : to remove + def translate_other_attachments(translation) + translate_attachment(translation, :shared_image) if shared_image.attached? + end + protected def check_accessibility diff --git a/app/models/communication/website/portfolio/project/localization.rb b/app/models/communication/website/portfolio/project/localization.rb new file mode 100644 index 000000000..187f1d844 --- /dev/null +++ b/app/models/communication/website/portfolio/project/localization.rb @@ -0,0 +1,65 @@ +class Communication::Website::Portfolio::Project::Localization < ApplicationRecord + include AsLocalization + include Contentful + include Initials + include Permalinkable + include Sanitizable + include Shareable + include WithAccessibility + include WithBlobs + include WithFeaturedImage + include WithGitFiles + include WithUniversity + + validates :title, presence: true + + scope :ordered, -> { order(year: :desc, title: :asc) } + scope :published, -> { where(published: true) } + scope :draft, -> { where(published: false) } + scope :latest, -> { published.order(updated_at: :desc).limit(5) } + + # TODO L10N : To adapt + scope :for_search_term, -> (term) { + where(" + unaccent(communication_website_portfolio_projects.meta_description) ILIKE unaccent(:term) OR + unaccent(communication_website_portfolio_projects.summary) ILIKE unaccent(:term) OR + unaccent(communication_website_portfolio_projects.title) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } + + def git_path(website) + return unless website.id == communication_website_id && published + git_path_content_prefix(website) + git_path_relative + end + + def git_path_relative + "projects/#{year}-#{slug}.html" + end + + def template_static + "admin/communication/websites/portfolio/projects/static" + end + + def dependencies + active_storage_blobs + + contents_dependencies + end + + def to_s + "#{title}" + end + + protected + + def check_accessibility + accessibility_merge_array blocks + end + + def explicit_blob_ids + super.concat [ + featured_image&.blob_id, + shared_image&.blob_id + ] + end + +end diff --git a/db/migrate/20240802131238_create_communication_website_portfolio_project_localizations.rb b/db/migrate/20240802131238_create_communication_website_portfolio_project_localizations.rb new file mode 100644 index 000000000..48293d1cc --- /dev/null +++ b/db/migrate/20240802131238_create_communication_website_portfolio_project_localizations.rb @@ -0,0 +1,63 @@ +class CreateCommunicationWebsitePortfolioProjectLocalizations < ActiveRecord::Migration[7.1] + def up + change_column_null :communication_website_portfolio_projects, :language_id, true + + create_table :communication_website_portfolio_project_localizations, id: :uuid do |t| + t.string :featured_image_alt + t.text :featured_image_credit + t.string :meta_description + t.string :migration_identifier + t.boolean :published, default: false + t.datetime :published_at + t.string :slug + t.text :summary + t.string :title + + t.references :about, foreign_key: { to_table: :communication_website_portfolio_projects }, type: :uuid + t.references :language, foreign_key: true, type: :uuid + t.references :communication_website, foreign_key: true, type: :uuid + t.references :university, foreign_key: true, type: :uuid + + t.timestamps + end + + Communication::Website::Portfolio::Project.find_each do |project| + puts "Migration project #{project.id}" + + about_id = project.original_id || project.id + + l10n = Communication::Website::Portfolio::Project::Localization.create( + featured_image_alt: project.featured_image_alt, + featured_image_credit: project.featured_image_credit, + meta_description: project.meta_description, + published: project.published, + published_at: project.updated_at, # No published_at yet + slug: project.slug, + summary: project.summary, + title: project.title, + about_id: about_id, + + language_id: project.language_id, + communication_website_id: project.communication_website_id, + university_id: project.university_id, + created_at: project.created_at + ) + + project.translate_contents!(l10n) + project.translate_attachment(l10n, :featured_image) + project.translate_other_attachments(l10n) + + project.permalinks.each do |permalink| + new_permalink = permalink.dup + new_permalink.about = l10n + new_permalink.save + end + + l10n.save + end + end + + def down + drop_table :communication_website_portfolio_project_localizations + end +end diff --git a/db/migrate/20240802132626_create_communication_website_portfolio_category_localizations.rb b/db/migrate/20240802132626_create_communication_website_portfolio_category_localizations.rb new file mode 100644 index 000000000..e991f4fb8 --- /dev/null +++ b/db/migrate/20240802132626_create_communication_website_portfolio_category_localizations.rb @@ -0,0 +1,63 @@ +class CreateCommunicationWebsitePortfolioCategoryLocalizations < ActiveRecord::Migration[7.1] + def up + change_column_null :communication_website_portfolio_categories, :language_id, true + + create_table :communication_website_portfolio_category_localizations, id: :uuid do |t| + t.text :featured_image_alt + t.text :featured_image_credit + t.text :meta_description + t.string :name + t.string :path + t.string :published, default: false + t.datetime :published_at + t.string :slug + t.text :summary + + t.references :about, foreign_key: { to_table: :communication_website_portfolio_categories }, type: :uuid + t.references :language, foreign_key: true, type: :uuid + t.references :communication_website, foreign_key: true, type: :uuid + t.references :university, foreign_key: true, type: :uuid + + t.timestamps + end + + Communication::Website::Portfolio::Category.find_each do |category| + puts "Migration category #{category.id}" + + about_id = category.original_id || category.id + + l10n = Communication::Website::Portfolio::Category::Localization.create( + featured_image_alt: category.featured_image_alt, + featured_image_credit: category.featured_image_credit, + meta_description: category.meta_description, + name: category.name, + path: category.path, + published: true, # No published yet + published_at: category.updated_at, # No published_at yet + slug: category.slug, + summary: category.summary, + about_id: about_id, + + language_id: category.language_id, + communication_website_id: category.communication_website_id, + university_id: category.university_id, + created_at: category.created_at + ) + + category.translate_contents!(l10n) + category.translate_attachment(l10n, :featured_image) + + category.permalinks.each do |permalink| + new_permalink = permalink.dup + new_permalink.about = l10n + new_permalink.save + end + + l10n.save + end + end + + def down + drop_table :communication_website_portfolio_category_localizations + end +end From a977f2f368d0c7fe00509c86ffe75569467e76af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 12 Aug 2024 11:47:13 +0200 Subject: [PATCH 2/9] models portfolio --- .../communication/website/agenda/event.rb | 3 +- .../website/portfolio/category.rb | 44 ++++---------- .../portfolio/category/localization.rb | 35 +++++++++++ .../website/portfolio/project.rb | 55 +++++------------- .../website/portfolio/project/localization.rb | 35 +++++++++++ .../program/with_websites_categories.rb | 2 + db/schema.rb | 58 ++++++++++++++++++- 7 files changed, 155 insertions(+), 77 deletions(-) diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index a44ca83bd..93cad365a 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -46,11 +46,9 @@ class Communication::Website::Agenda::Event < ApplicationRecord include AsDirectObject include Contentful # TODO L10N : To remove - include Initials include Sanitizable include Shareable # TODO L10N : To remove include Localizable - include WithAccessibility include WithBlobs # TODO L10N : To remove include WithDuplication include WithFeaturedImage # TODO L10N : To remove @@ -91,6 +89,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord ) .distinct } + # TODO L10N : To adapt scope :for_search_term, -> (term) { where(" unaccent(communication_website_agenda_events.meta_description) ILIKE unaccent(:term) OR diff --git a/app/models/communication/website/portfolio/category.rb b/app/models/communication/website/portfolio/category.rb index 9b8def7f9..43af6db18 100644 --- a/app/models/communication/website/portfolio/category.rb +++ b/app/models/communication/website/portfolio/category.rb @@ -16,7 +16,7 @@ # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed -# language_id :uuid not null, indexed +# language_id :uuid indexed # original_id :uuid indexed # parent_id :uuid indexed # university_id :uuid not null, indexed @@ -40,17 +40,20 @@ class Communication::Website::Portfolio::Category < ApplicationRecord include AsCategory include AsDirectObject - include Contentful - include Initials - include Permalinkable # We override slug_unavailable? method + include Contentful # TODO L10N : To removes include Sanitizable include Localizable - include Pathable # Included after Sluggable to make sure slug is correct before anything - include WithBlobs - include WithFeaturedImage + include WithBlobs # TODO L10N : To removes + include WithFeaturedImage # TODO L10N : To removes include WithMenuItemTarget include WithUniversity + # TODO L10N : remove after migrations + has_many :permalinks, + class_name: "Communication::Website::Permalink", + as: :about, + dependent: :destroy + belongs_to :program, class_name: 'Education::Program', optional: true @@ -60,24 +63,9 @@ class Communication::Website::Portfolio::Category < ApplicationRecord foreign_key: :communication_website_portfolio_category_id, association_foreign_key: :communication_website_portfolio_project_id - validates :name, presence: true - - def to_s - "#{name}" - end - - def git_path(website) - "#{git_path_content_prefix(website)}projects_categories/#{slug}/_index.html" - end - - def template_static - "admin/communication/websites/portfolio/categories/static" - end - def dependencies - active_storage_blobs + - contents_dependencies + - [website.config_default_content_security_policy] + [website.config_default_content_security_policy] + + localizations.in_languages(website.active_language_ids) end def references @@ -86,17 +74,9 @@ def references references end - def siblings - self.class.unscoped.where(parent: parent, university: university, website: website).where.not(id: id) - end - protected def last_ordered_element website.portfolio_categories.where(parent_id: parent_id, language_id: language_id).ordered.last end - - def slug_unavailable?(slug) - self.class.unscoped.where(communication_website_id: self.communication_website_id, language_id: language_id, slug: slug).where.not(id: self.id).exists? - end end diff --git a/app/models/communication/website/portfolio/category/localization.rb b/app/models/communication/website/portfolio/category/localization.rb index fac0a8700..ef0e86f93 100644 --- a/app/models/communication/website/portfolio/category/localization.rb +++ b/app/models/communication/website/portfolio/category/localization.rb @@ -1,3 +1,38 @@ +# == Schema Information +# +# Table name: communication_website_portfolio_category_localizations +# +# id :uuid not null, primary key +# featured_image_alt :text +# featured_image_credit :text +# meta_description :text +# name :string +# path :string +# published :string default("f") +# published_at :datetime +# slug :string +# summary :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed +# communication_website_id :uuid indexed +# language_id :uuid indexed +# university_id :uuid indexed +# +# Indexes +# +# idx_on_about_id_e184bfe637 (about_id) +# idx_on_communication_website_id_9d28ee55e4 (communication_website_id) +# idx_on_language_id_70b50689c4 (language_id) +# idx_on_university_id_66e101bf70 (university_id) +# +# Foreign Keys +# +# fk_rails_6dd917d73a (language_id => languages.id) +# fk_rails_b75b5471d3 (about_id => communication_website_portfolio_categories.id) +# fk_rails_c8c00a26df (communication_website_id => communication_websites.id) +# fk_rails_e84628b736 (university_id => universities.id) +# class Communication::Website::Portfolio::Category::Localization < ApplicationRecord include AsLocalization include Contentful diff --git a/app/models/communication/website/portfolio/project.rb b/app/models/communication/website/portfolio/project.rb index e8256d37f..04847cd6c 100644 --- a/app/models/communication/website/portfolio/project.rb +++ b/app/models/communication/website/portfolio/project.rb @@ -14,7 +14,7 @@ # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed -# language_id :uuid not null, indexed +# language_id :uuid indexed # original_id :uuid indexed # university_id :uuid not null, indexed # @@ -34,26 +34,29 @@ # class Communication::Website::Portfolio::Project < ApplicationRecord include AsDirectObject - include Contentful - include Initials - include Permalinkable + include Contentful # TODO L10N : To removes include Sanitizable - include Shareable + include Shareable # TODO L10N : To remove include Localizable - include WithAccessibility - include WithBlobs + include WithBlobs # TODO L10N : To remove include WithDuplication - include WithFeaturedImage + include WithFeaturedImage # TODO L10N : To remove include WithMenuItemTarget include WithUniversity + # TODO L10N : remove after migrations + has_many :permalinks, + class_name: "Communication::Website::Permalink", + as: :about, + dependent: :destroy + has_and_belongs_to_many :categories, class_name: 'Communication::Website::Portfolio::Category', join_table: :communication_website_portfolio_categories_projects, foreign_key: :communication_website_portfolio_project_id, association_foreign_key: :communication_website_portfolio_category_id - validates :title, :year, presence: true + validates :year, presence: true scope :ordered, -> { order(year: :desc, title: :asc) } scope :published, -> { where(published: true) } @@ -69,6 +72,7 @@ class Communication::Website::Portfolio::Project < ApplicationRecord ) .distinct } + # TODO L10N : To adapt scope :for_search_term, -> (term) { where(" unaccent(communication_website_portfolio_projects.meta_description) ILIKE unaccent(:term) OR @@ -77,23 +81,9 @@ class Communication::Website::Portfolio::Project < ApplicationRecord ", term: "%#{sanitize_sql_like(term)}%") } - def git_path(website) - return unless website.id == communication_website_id && published - git_path_content_prefix(website) + git_path_relative - end - - def git_path_relative - "projects/#{year}-#{slug}.html" - end - - def template_static - "admin/communication/websites/portfolio/projects/static" - end - def dependencies - active_storage_blobs + - contents_dependencies + - [website.config_default_content_security_policy] + [website.config_default_content_security_policy] + + localizations.in_languages(website.active_language_ids) end def references @@ -101,10 +91,6 @@ def references abouts_with_projects_block end - def to_s - "#{title}" - end - # TODO L10N : to remove def translate_other_attachments(translation) translate_attachment(translation, :shared_image) if shared_image.attached? @@ -112,17 +98,6 @@ def translate_other_attachments(translation) protected - def check_accessibility - accessibility_merge_array blocks - end - - def explicit_blob_ids - super.concat [ - featured_image&.blob_id, - shared_image&.blob_id - ] - end - def abouts_with_projects_block website.blocks.projects.collect(&:about) end diff --git a/app/models/communication/website/portfolio/project/localization.rb b/app/models/communication/website/portfolio/project/localization.rb index 187f1d844..242c2492f 100644 --- a/app/models/communication/website/portfolio/project/localization.rb +++ b/app/models/communication/website/portfolio/project/localization.rb @@ -1,3 +1,38 @@ +# == Schema Information +# +# Table name: communication_website_portfolio_project_localizations +# +# id :uuid not null, primary key +# featured_image_alt :string +# featured_image_credit :text +# meta_description :string +# migration_identifier :string +# published :boolean default(FALSE) +# published_at :datetime +# slug :string +# summary :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed +# communication_website_id :uuid indexed +# language_id :uuid indexed +# university_id :uuid indexed +# +# Indexes +# +# idx_on_about_id_a668ef6090 (about_id) +# idx_on_communication_website_id_e653b6273a (communication_website_id) +# idx_on_language_id_25a0c1e472 (language_id) +# idx_on_university_id_f01fc2c686 (university_id) +# +# Foreign Keys +# +# fk_rails_3145135b3c (communication_website_id => communication_websites.id) +# fk_rails_be29689be2 (language_id => languages.id) +# fk_rails_c1a10dcae3 (university_id => universities.id) +# fk_rails_fbc92c5948 (about_id => communication_website_portfolio_projects.id) +# class Communication::Website::Portfolio::Project::Localization < ApplicationRecord include AsLocalization include Contentful diff --git a/app/models/education/program/with_websites_categories.rb b/app/models/education/program/with_websites_categories.rb index 7fe31af9e..53e96f150 100644 --- a/app/models/education/program/with_websites_categories.rb +++ b/app/models/education/program/with_websites_categories.rb @@ -11,6 +11,8 @@ module Education::Program::WithWebsitesCategories has_many :website_agenda_categories, class_name: 'Communication::Website::Agenda::Category', dependent: :destroy + + # TODO : Ajouter les catégories de portfolio end def set_websites_categories diff --git a/db/schema.rb b/db/schema.rb index ab2feaf70..dfbaaaa8e 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_07_31_152544) do +ActiveRecord::Schema[7.1].define(version: 2024_08_02_132626) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -591,7 +591,7 @@ t.integer "position" t.text "summary" t.uuid "communication_website_id", null: false - t.uuid "language_id", null: false + t.uuid "language_id" t.uuid "original_id" t.uuid "parent_id" t.uuid "university_id", null: false @@ -612,6 +612,50 @@ t.index ["communication_website_portfolio_project_id", "communication_website_portfolio_category_id"], name: "idx_on_communication_website_portfolio_project_id_c_8ffd53123b" end + create_table "communication_website_portfolio_category_localizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.text "featured_image_alt" + t.text "featured_image_credit" + t.text "meta_description" + t.string "name" + t.string "path" + t.string "published", default: "f" + t.datetime "published_at" + t.string "slug" + t.text "summary" + t.uuid "about_id" + t.uuid "language_id" + t.uuid "communication_website_id" + t.uuid "university_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["about_id"], name: "idx_on_about_id_e184bfe637" + t.index ["communication_website_id"], name: "idx_on_communication_website_id_9d28ee55e4" + t.index ["language_id"], name: "idx_on_language_id_70b50689c4" + t.index ["university_id"], name: "idx_on_university_id_66e101bf70" + end + + create_table "communication_website_portfolio_project_localizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "featured_image_alt" + t.text "featured_image_credit" + t.string "meta_description" + t.string "migration_identifier" + t.boolean "published", default: false + t.datetime "published_at" + t.string "slug" + t.text "summary" + t.string "title" + t.uuid "about_id" + t.uuid "language_id" + t.uuid "communication_website_id" + t.uuid "university_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["about_id"], name: "idx_on_about_id_a668ef6090" + t.index ["communication_website_id"], name: "idx_on_communication_website_id_e653b6273a" + t.index ["language_id"], name: "idx_on_language_id_25a0c1e472" + t.index ["university_id"], name: "idx_on_university_id_f01fc2c686" + end + create_table "communication_website_portfolio_projects", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.string "slug" @@ -622,7 +666,7 @@ t.boolean "published", default: false t.text "summary" t.uuid "communication_website_id", null: false - t.uuid "language_id", null: false + t.uuid "language_id" t.uuid "original_id" t.uuid "university_id", null: false t.datetime "created_at", null: false @@ -1729,6 +1773,14 @@ add_foreign_key "communication_website_portfolio_categories", "communication_websites" add_foreign_key "communication_website_portfolio_categories", "languages" add_foreign_key "communication_website_portfolio_categories", "universities" + add_foreign_key "communication_website_portfolio_category_localizations", "communication_website_portfolio_categories", column: "about_id" + add_foreign_key "communication_website_portfolio_category_localizations", "communication_websites" + add_foreign_key "communication_website_portfolio_category_localizations", "languages" + add_foreign_key "communication_website_portfolio_category_localizations", "universities" + add_foreign_key "communication_website_portfolio_project_localizations", "communication_website_portfolio_projects", column: "about_id" + add_foreign_key "communication_website_portfolio_project_localizations", "communication_websites" + add_foreign_key "communication_website_portfolio_project_localizations", "languages" + add_foreign_key "communication_website_portfolio_project_localizations", "universities" add_foreign_key "communication_website_portfolio_projects", "communication_website_portfolio_projects", column: "original_id" add_foreign_key "communication_website_portfolio_projects", "communication_websites" add_foreign_key "communication_website_portfolio_projects", "languages" From d361928c66b143808cbe0a3938c854baddcaba04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 12 Aug 2024 17:31:56 +0200 Subject: [PATCH 3/9] portfolio projects --- .../websites/agenda/categories_controller.rb | 11 +--- .../websites/agenda/events_controller.rb | 4 +- .../portfolio/categories_controller.rb | 27 +++++---- .../websites/portfolio/projects_controller.rb | 31 +++++----- .../website/portfolio/category.rb | 13 +++-- .../application/categories/_form.html.erb | 10 +++- .../application/categories/_static.html.erb | 38 +++++++----- .../websites/agenda/events/_form.html.erb | 6 +- .../websites/agenda/events/show.html.erb | 6 +- .../agenda/events/show/_metadata.html.erb | 5 +- .../portfolio/projects/_form.html.erb | 58 ++++++++++--------- .../portfolio/projects/_list.html.erb | 13 +++-- .../websites/portfolio/projects/edit.html.erb | 4 +- .../websites/portfolio/projects/new.html.erb | 2 +- .../websites/portfolio/projects/show.html.erb | 18 +++--- .../projects/show/_metadata.html.erb | 13 +++-- .../portfolio/projects/static.html.erb | 36 +++++++----- config/locales/communication/en.yml | 22 +++---- config/locales/communication/fr.yml | 22 +++---- ...munication_website_portfolio_categories.rb | 5 ++ db/schema.rb | 5 +- 21 files changed, 194 insertions(+), 155 deletions(-) create mode 100644 db/migrate/20240812134035_add_program_id_to_communication_website_portfolio_categories.rb diff --git a/app/controllers/admin/communication/websites/agenda/categories_controller.rb b/app/controllers/admin/communication/websites/agenda/categories_controller.rb index 33a77d0ad..a8f599438 100644 --- a/app/controllers/admin/communication/websites/agenda/categories_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/categories_controller.rb @@ -1,5 +1,5 @@ class Admin::Communication::Websites::Agenda::CategoriesController < Admin::Communication::Websites::Agenda::ApplicationController - load_and_authorize_resource class: 'Communication::Website::Agenda::Category', + load_and_authorize_resource class: 'Communication::Website::Agenda::Category', through: :website, through_association: :agenda_categories @@ -19,11 +19,6 @@ def show breadcrumb end - def static - @about = @category - render_as_plain_text - end - def new breadcrumb end @@ -68,7 +63,7 @@ def categories_class def breadcrumb super - add_breadcrumb Communication::Website::Agenda::Category.model_name.human(count: 2), + add_breadcrumb categories_class.model_name.human(count: 2), admin_communication_website_agenda_categories_path breadcrumb_for @category end @@ -80,7 +75,7 @@ def category_params localizations_attributes: [ :id, :language_id, :name, :meta_description, :summary, :slug, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit ] ) .merge( diff --git a/app/controllers/admin/communication/websites/agenda/events_controller.rb b/app/controllers/admin/communication/websites/agenda/events_controller.rb index 2ab90a1a5..6240fae4d 100644 --- a/app/controllers/admin/communication/websites/agenda/events_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/events_controller.rb @@ -88,7 +88,7 @@ def breadcrumb def categories @website.agenda_categories - .for_language(current_language) + .tmp_original # TODO L10N : Remove tmp_original .ordered end @@ -107,7 +107,7 @@ def event_params category_ids: [], localizations_attributes: [ :id, :title, :subtitle, :meta_description, :summary, :text, - :published, :published_at, :slug, + :published, :published_at, :slug, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, :shared_image, :shared_image_delete, :shared_image_infos, :language_id diff --git a/app/controllers/admin/communication/websites/portfolio/categories_controller.rb b/app/controllers/admin/communication/websites/portfolio/categories_controller.rb index 24f2d2357..e99140f9d 100644 --- a/app/controllers/admin/communication/websites/portfolio/categories_controller.rb +++ b/app/controllers/admin/communication/websites/portfolio/categories_controller.rb @@ -1,13 +1,14 @@ class Admin::Communication::Websites::Portfolio::CategoriesController < Admin::Communication::Websites::Portfolio::ApplicationController - load_and_authorize_resource class: 'Communication::Website::Portfolio::Category', + load_and_authorize_resource class: 'Communication::Website::Portfolio::Category', through: :website, through_association: :portfolio_categories - include Admin::Localizable include Admin::ActAsCategories + include Admin::HasStaticAction + include Admin::Localizable def index - @root_categories = categories.root + @root_categories = categories.root.tmp_original # TODO L10N : To remove @categories_class = categories_class @feature_nav = 'navigation/admin/communication/website/portfolio' breadcrumb @@ -18,11 +19,6 @@ def show breadcrumb end - def static - @about = @category - render_as_plain_text - end - def new breadcrumb end @@ -36,7 +32,7 @@ def create @category.website = @website @category.add_photo_import params[:photo_import] if @category.save_and_sync - redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s) + redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s_in(current_language)) else breadcrumb render :new, status: :unprocessable_entity @@ -46,7 +42,7 @@ def create def update @category.add_photo_import params[:photo_import] if @category.update_and_sync(category_params) - redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s) + redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s_in(current_language)) else breadcrumb add_breadcrumb t('edit') @@ -56,7 +52,7 @@ def update def destroy @category.destroy - redirect_to admin_communication_website_portfolio_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s) + redirect_to admin_communication_website_portfolio_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s_in(current_language)) end protected @@ -75,9 +71,12 @@ def breadcrumb def category_params params.require(:communication_website_portfolio_category) .permit( - :name, :meta_description, :summary, :slug, - :is_taxonomy, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit + :is_taxonomy, :parent_id, + localizations_attributes: [ + :id, :language_id, + :name, :meta_description, :summary, :slug, + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit + ] ) .merge( university_id: current_university.id, diff --git a/app/controllers/admin/communication/websites/portfolio/projects_controller.rb b/app/controllers/admin/communication/websites/portfolio/projects_controller.rb index 0a822d579..41d929b47 100644 --- a/app/controllers/admin/communication/websites/portfolio/projects_controller.rb +++ b/app/controllers/admin/communication/websites/portfolio/projects_controller.rb @@ -2,6 +2,7 @@ class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Com load_and_authorize_resource class: Communication::Website::Portfolio::Project, through: :website + include Admin::HasStaticAction include Admin::Localizable # Allow to override the default load_filters from Admin::Filterable @@ -11,7 +12,7 @@ class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Com has_scope :for_category def index - @projects = apply_scopes(@projects).for_language(current_language) + @projects = apply_scopes(@projects).tmp_original # TODO L10N : To remove .ordered .page(params[:page]) @feature_nav = 'navigation/admin/communication/website/portfolio' @@ -29,11 +30,6 @@ def show breadcrumb end - def static - @about = @project - render_as_plain_text - end - def new @categories = categories breadcrumb @@ -50,7 +46,7 @@ def create @project.add_photo_import params[:photo_import] if @project.save_and_sync redirect_to admin_communication_website_portfolio_project_path(@project), - notice: t('admin.successfully_created_html', model: @project.to_s) + notice: t('admin.successfully_created_html', model: @project.to_s_in(current_language)) else @categories = categories breadcrumb @@ -62,7 +58,7 @@ def update @project.add_photo_import params[:photo_import] if @project.update_and_sync(project_params) redirect_to admin_communication_website_portfolio_project_path(@project), - notice: t('admin.successfully_updated_html', model: @project.to_s) + notice: t('admin.successfully_updated_html', model: @project.to_s_in(current_language)) else @categories = categories breadcrumb @@ -73,13 +69,13 @@ def update def duplicate redirect_to [:admin, @project.duplicate], - notice: t('admin.successfully_duplicated_html', model: @project.to_s) + notice: t('admin.successfully_duplicated_html', model: @project.to_s_in(current_language)) end def destroy @project.destroy redirect_to admin_communication_website_portfolio_projects_url, - notice: t('admin.successfully_destroyed_html', model: @project.to_s) + notice: t('admin.successfully_destroyed_html', model: @project.to_s_in(current_language)) end protected @@ -90,7 +86,7 @@ def breadcrumb def categories @website.portfolio_categories - .for_language(current_language) + .tmp_original # TODO L10N : Remove tmp_original .ordered end @@ -105,10 +101,15 @@ def load_filters def project_params params.require(:communication_website_portfolio_project) .permit( - :title, :meta_description, :summary, :published, :slug, :year, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, - :shared_image, :shared_image_delete, - category_ids: [] + :year, + category_ids: [], + localizations_attributes: [ + :id, :title, :meta_description, :summary, + :published, :published_at, :slug, + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, + :shared_image, :shared_image_delete, :shared_image_infos, + :language_id + ] ) .merge( university_id: current_university.id, diff --git a/app/models/communication/website/portfolio/category.rb b/app/models/communication/website/portfolio/category.rb index 43af6db18..b7f53b673 100644 --- a/app/models/communication/website/portfolio/category.rb +++ b/app/models/communication/website/portfolio/category.rb @@ -19,20 +19,23 @@ # language_id :uuid indexed # original_id :uuid indexed # parent_id :uuid indexed +# program_id :uuid indexed # university_id :uuid not null, indexed # # Indexes # -# idx_on_communication_website_id_8f309901d4 (communication_website_id) -# idx_on_language_id_6e6ffc92a8 (language_id) -# idx_on_original_id_4cbc9f1290 (original_id) -# idx_on_university_id_a07cc0a296 (university_id) -# index_communication_website_portfolio_categories_on_parent_id (parent_id) +# idx_on_communication_website_id_8f309901d4 (communication_website_id) +# idx_on_language_id_6e6ffc92a8 (language_id) +# idx_on_original_id_4cbc9f1290 (original_id) +# idx_on_university_id_a07cc0a296 (university_id) +# index_communication_website_portfolio_categories_on_parent_id (parent_id) +# index_communication_website_portfolio_categories_on_program_id (program_id) # # Foreign Keys # # fk_rails_0f0db1988d (communication_website_id => communication_websites.id) # fk_rails_35d652a63c (parent_id => communication_website_portfolio_categories.id) +# fk_rails_833ff43b27 (program_id => education_programs.id) # fk_rails_c82d8a59f0 (language_id => languages.id) # fk_rails_d21380c33e (original_id => communication_website_portfolio_categories.id) # fk_rails_eed5f4b819 (university_id => universities.id) diff --git a/app/views/admin/application/categories/_form.html.erb b/app/views/admin/application/categories/_form.html.erb index 1d365b2c6..a97679d15 100644 --- a/app/views/admin/application/categories/_form.html.erb +++ b/app/views/admin/application/categories/_form.html.erb @@ -7,7 +7,10 @@ <%= f.association :categories, label_text: false, as: :check_boxes, - collection: taxonomy.descendants %> + collection: osuny_collection( + taxonomy.descendants, + localized: true + ) %> <% end %> <% if categories.root.free.any? %> @@ -16,7 +19,10 @@ <%= f.association :categories, label_text: false, as: :check_boxes, - collection: collection_tree_for_checkboxes(categories.free) %> + collection: osuny_collection_tree( + categories.root.free, + localized: true + ) %> <% end %> diff --git a/app/views/admin/application/categories/_static.html.erb b/app/views/admin/application/categories/_static.html.erb index 7d4f91c8a..c9da477dc 100644 --- a/app/views/admin/application/categories/_static.html.erb +++ b/app/views/admin/application/categories/_static.html.erb @@ -1,34 +1,42 @@ <% -about_categories = about.categories -taxonomies = categories.taxonomies.ordered +about_categories = about.categories.tmp_original # TODO L10N : remove tmp_original +taxonomies = categories.taxonomies.tmp_original.ordered # TODO L10N : remove tmp_original %> <% if about_categories.any? %> <%= key %>: -<% about_categories.ordered.each do |category| %> - - "<%= category.slug %>" +<% +about_categories.ordered.each do |category| + category_l10n = category.localization_for(l10n.language) + next if category_l10n.nil? +%> + - "<%= category_l10n.slug %>" <% end %> -<% - if taxonomies.any? +<% + if taxonomies.any? %> taxonomies: -<% - taxonomies.each do |taxonomy| +<% + taxonomies.each do |taxonomy| + taxonomy_l10n = taxonomy.localization_for(l10n.language) + next if taxonomy_l10n.nil? %> - - name: "<%= prepare_text_for_static taxonomy.to_s %>" - slug: "<%= taxonomy.slug %>" + - name: "<%= prepare_text_for_static taxonomy_l10n.to_s %>" + slug: "<%= taxonomy_l10n.slug %>" categories: <% - about_categories.in_taxonomy(taxonomy).each do |category| - hugo = category.hugo(@website) + about_categories.in_taxonomy(taxonomy).each do |category| + category_l10n = category.localization_for(l10n.language) + next if category_l10n.nil? + hugo = category_l10n.hugo(@website) %> - - name: "<%= prepare_text_for_static category.to_s %>" + - name: "<%= prepare_text_for_static category_l10n.to_s %>" permalink: "<%= hugo.permalink %>" file: "<%= hugo.file %>" path: "<%= hugo.path %>" slug: "<%= hugo.slug %>" -<% +<% end end end -end +end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/agenda/events/_form.html.erb b/app/views/admin/communication/websites/agenda/events/_form.html.erb index 2bae9c5ec..e0f17ba56 100644 --- a/app/views/admin/communication/websites/agenda/events/_form.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_form.html.erb @@ -56,13 +56,13 @@ f: lf, source: '#communication_website_agenda_event_localizations_attributes_0_title' %> <% end %> - <%= render 'admin/application/featured_image/edit', f: lf, about: @l10n %> - <%= render 'admin/application/shared_image/edit', f: lf, about: @l10n %> + <%= render 'admin/application/featured_image/edit', f: lf, about: l10n %> + <%= render 'admin/application/shared_image/edit', f: lf, about: l10n %> <% content_for :action_bar_left do %> - <%= render 'admin/application/l10n/libre_translate_button', l10n: @l10n %> + <%= render 'admin/application/l10n/libre_translate_button', l10n: l10n %> <% end %> <% content_for :action_bar_right do %> 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 b4088a02e..ebfd63e0f 100644 --- a/app/views/admin/communication/websites/agenda/events/show.html.erb +++ b/app/views/admin/communication/websites/agenda/events/show.html.erb @@ -22,11 +22,11 @@ <%= render 'admin/communication/websites/agenda/events/show/metadata' %>
- <%= render 'admin/application/summary/show', about: @event, small: true %> - <%= render 'admin/application/meta_description/show', about: @event %> + <%= render 'admin/application/summary/show', about: @l10n, small: true %> + <%= render 'admin/application/meta_description/show', about: @l10n %>
-<%= render 'admin/communication/blocks/content/editor', about: @event %> +<%= render 'admin/communication/blocks/content/editor', about: @l10n %> <% content_for :action_bar_left do %> <%= destroy_link @event %> 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 61d526096..319010f3d 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 @@ -2,9 +2,10 @@ <%= @l10n.published ? Communication::Website::Agenda::Event.human_attribute_name(:published) : t('admin.communication.website.agenda.events.draft') %> <% if @event.categories.any? %> + <% category_names = @event.categories.map { |category| category.to_s_in(current_language) } %> <%= t( - 'admin.communication.website.posts.in', - categories: @event.categories.collect(&:to_s).join(', ') + 'admin.communication.website.posts.in', + categories: category_names.join(', ') ) %> <% end %> <%= render 'admin/application/permalinks/redirects', about: @l10n %> diff --git a/app/views/admin/communication/websites/portfolio/projects/_form.html.erb b/app/views/admin/communication/websites/portfolio/projects/_form.html.erb index 6acf3999e..9e380a925 100644 --- a/app/views/admin/communication/websites/portfolio/projects/_form.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/_form.html.erb @@ -1,34 +1,38 @@ <%= simple_form_for [:admin, project] do |f| %> - <%= f.error_notification %> - <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + <%= f.simple_fields_for :localizations, l10n do |lf| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> -
-
- <%= osuny_panel t('content') do %> - <%= f.input :title %> - <%= render 'admin/application/summary/form', f: f, about: project %> - <% end %> - <%= render 'admin/application/categories/form', f: f, categories: @categories %> - <%= render 'admin/application/meta_description/form', f: f, about: project %> -
-
- <%= osuny_panel t('metadata') do %> - <%= f.input :published if can? :publish, project %> - <%= f.input :year %> - <%= render "admin/application/slug/form", - f: f, - source: '#communication_website_portfolio_project_title' %> - <% end %> - <%= render 'admin/application/featured_image/edit', about: project, f: f %> - <%= render 'admin/application/shared_image/edit', about: project, f: f %> + <%= lf.hidden_field :language_id, value: current_language.id %> + +
+
+ <%= osuny_panel t('content') do %> + <%= lf.input :title %> + <%= render 'admin/application/summary/form', f: lf, about: l10n %> + <% end %> + <%= render 'admin/application/categories/form', f: f, categories: @categories %> + <%= render 'admin/application/meta_description/form', f: lf, about: l10n %> +
+
+ <%= osuny_panel t('metadata') do %> + <%= lf.input :published if can? :publish, project %> + <%= f.input :year %> + <%= render "admin/application/slug/form", + f: lf, + source: '#communication_website_portfolio_project_localizations_attributes_0_title' %> + <% end %> + <%= render 'admin/application/featured_image/edit', about: l10n, f: lf %> + <%= render 'admin/application/shared_image/edit', about: l10n, f: lf %> +
-
- <% content_for :action_bar_left do %> - <%= render 'admin/application/i18n/translate_button', about: project %> - <% end %> + <% content_for :action_bar_left do %> + <%= render 'admin/application/l10n/libre_translate_button', l10n: l10n %> + <% end %> - <% content_for :action_bar_right do %> - <%= submit f %> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> <% end %> <% end %> 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 b75d27515..0962ac2cf 100644 --- a/app/views/admin/communication/websites/portfolio/projects/_list.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/_list.html.erb @@ -8,12 +8,15 @@ small ||= false <% projects.each do |project| %>
- <%= osuny_thumbnail project %> + <%= osuny_thumbnail_localized project %>
- <%= 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' %> + <%= osuny_published_localized project unless small %> + <%= osuny_link_localized project, + admin_communication_website_portfolio_project_path( + website_id: project.website.id, + id: project.id + ), + classes: "stretched-link" %>
<%= render 'admin/communication/blocks/content/editor', about: @l10n %> <% if @events.total_count > 0 %> - <%= osuny_panel Communication::Website::Agenda::Event.model_name.human(count: 2), - subtitle: "#{@events.total_count} #{Communication::Website::Agenda::Event.model_name.human(count: @events.total_count).downcase }" do %> + <% + title = Communication::Website::Agenda::Event.model_name.human(count: 2) + subtitle = "#{@projects.total_count} #{Communication::Website::Agenda::Event.model_name.human(count: @events.total_count).downcase }" + %> + <%= osuny_panel title, subtitle: subtitle do %> <%= render 'admin/communication/websites/agenda/events/list', events: @events, hide_category: true %> <%= paginate @events %> <% end %> diff --git a/app/views/admin/communication/websites/agenda/categories/static.html.erb b/app/views/admin/communication/websites/agenda/categories/static.html.erb index 6550c6d11..afa085646 100644 --- a/app/views/admin/communication/websites/agenda/categories/static.html.erb +++ b/app/views/admin/communication/websites/agenda/categories/static.html.erb @@ -2,13 +2,12 @@ category = @l10n.about %>--- <%= render 'admin/application/static/title', about: @l10n %> -<%= render 'admin/application/static/permalink', - about: @l10n %> +<%= render 'admin/application/static/permalink', about: @l10n %> <%= render 'admin/application/static/breadcrumbs', about: @l10n %> -<%= render 'admin/application/static/design', +<%= render 'admin/application/static/design', about: category, l10n: @l10n, - full_width: true, + full_width: true, toc_offcanvas: true %> position: <%= category.position %> <%= render 'admin/application/l10n/static', about: @l10n %> diff --git a/app/views/admin/communication/websites/portfolio/categories/_form.html.erb b/app/views/admin/communication/websites/portfolio/categories/_form.html.erb index e6426d949..24c8c5016 100644 --- a/app/views/admin/communication/websites/portfolio/categories/_form.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/_form.html.erb @@ -1,26 +1,30 @@ <%= simple_form_for [:admin, category] do |f| %> - <%= f.error_notification %> - <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + <%= f.simple_fields_for :localizations, l10n do |lf| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> -
-
- <%= osuny_panel t('content') do %> - <%= f.input :name %> - <%= render 'admin/application/summary/form', f: f, about: category %> - <% end %> - <%= render 'admin/application/meta_description/form', f: f, about: category %> -
-
- <%= osuny_panel t('metadata') do %> - <%= render "admin/application/slug/form", - f: f, - source: '#communication_website_portfolio_category_name' %> - <%= f.input :is_taxonomy, label: t('admin.categories.is_taxonomy') if category.possible_taxonomy? %> - <% end %> - <%= render 'admin/application/featured_image/edit', about: category, f: f %> + <%= lf.hidden_field :language_id, value: current_language.id %> + +
+
+ <%= osuny_panel t('content') do %> + <%= lf.input :name %> + <%= render 'admin/application/summary/form', f: lf, about: l10n %> + <% end %> + <%= render 'admin/application/meta_description/form', f: lf, about: l10n %> +
+
+ <%= osuny_panel t('metadata') do %> + <%= render "admin/application/slug/form", + f: lf, + source: '#communication_website_portfolio_category_localizations_attributes_0_name' %> + <%= f.input :is_taxonomy, label: t('admin.categories.is_taxonomy') if category.possible_taxonomy? %> + <% end %> + <%= render 'admin/application/featured_image/edit', f: lf, about: l10n %> +
-
- <% content_for :action_bar_right do %> - <%= submit f %> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> <% end %> <% end %> diff --git a/app/views/admin/communication/websites/portfolio/categories/_panel.html.erb b/app/views/admin/communication/websites/portfolio/categories/_panel.html.erb index 69a2b832a..92db92b13 100644 --- a/app/views/admin/communication/websites/portfolio/categories/_panel.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/_panel.html.erb @@ -1,7 +1,7 @@ <% if can?(:create, Communication::Website::Portfolio::Category) %> - <% + <% title = Communication::Website::Portfolio::Category.model_name.human(count: 2) - action = create_link Communication::Website::Portfolio::Category + action = create_link Communication::Website::Portfolio::Category %> <%= osuny_panel title, action: action do %> <%= render 'admin/communication/websites/portfolio/categories/list', categories: categories %> diff --git a/app/views/admin/communication/websites/portfolio/categories/edit.html.erb b/app/views/admin/communication/websites/portfolio/categories/edit.html.erb index 123bc888b..967d23fd0 100644 --- a/app/views/admin/communication/websites/portfolio/categories/edit.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/edit.html.erb @@ -1,3 +1,2 @@ -<% content_for :title, @category %> - -<%= render 'form', category: @category %> +<% content_for :title, @l10n %> +<%= render 'form', category: @category, l10n: @l10n %> diff --git a/app/views/admin/communication/websites/portfolio/categories/new.html.erb b/app/views/admin/communication/websites/portfolio/categories/new.html.erb index 074fa4398..efc9131aa 100644 --- a/app/views/admin/communication/websites/portfolio/categories/new.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/new.html.erb @@ -1,3 +1,2 @@ -<% content_for :title, Communication::Website::Post::Category.model_name.human %> - -<%= render 'form', category: @category %> +<% content_for :title, Communication::Website::Portfolio::Category.model_name.human %> +<%= render 'form', category: @category, l10n: @l10n %> 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 5016a2fcb..3b8d1fd60 100644 --- a/app/views/admin/communication/websites/portfolio/categories/show.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/show.html.erb @@ -1,16 +1,16 @@ -<% content_for :title, @category %> +<% content_for :title, @l10n %>
- <%= render 'admin/application/summary/show', about: @category %> - <%= render 'admin/application/i18n/widget', about: @category %> + <%= render 'admin/application/summary/show', about: @l10n %> + <%= render 'admin/application/i18n/widget', about: @category, l10n: @l10n %>
- <%= render 'admin/application/featured_image/show', about: @category %> - <%= render 'admin/application/meta_description/show', about: @category %> + <%= render 'admin/application/featured_image/show', about: @l10n %> + <%= render 'admin/application/meta_description/show', about: @l10n %>
-<%= render 'admin/communication/blocks/content/editor', about: @category %> +<%= render 'admin/communication/blocks/content/editor', about: @l10n %> <% if @projects.total_count > 0 %> <% title = Communication::Website::Portfolio::Project.model_name.human(count: 2) diff --git a/app/views/admin/communication/websites/portfolio/categories/static.html.erb b/app/views/admin/communication/websites/portfolio/categories/static.html.erb index c7238dd4c..afa085646 100644 --- a/app/views/admin/communication/websites/portfolio/categories/static.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/static.html.erb @@ -1,14 +1,18 @@ ---- -<%= render 'admin/application/static/title' %> -<%= render 'admin/application/static/permalink' %> -<%= render 'admin/application/static/breadcrumbs' %> +<% +category = @l10n.about +%>--- +<%= render 'admin/application/static/title', about: @l10n %> +<%= render 'admin/application/static/permalink', about: @l10n %> +<%= render 'admin/application/static/breadcrumbs', about: @l10n %> <%= render 'admin/application/static/design', + about: category, + l10n: @l10n, full_width: true, toc_offcanvas: true %> -position: <%= @about.position %> -<%= render 'admin/application/i18n/static' %> -<%= render 'admin/application/featured_image/static' %> -<%= render 'admin/application/meta_description/static' %> -<%= render 'admin/application/summary/static' %> -<%= render 'admin/communication/blocks/content/static', about: @about %> +position: <%= category.position %> +<%= render 'admin/application/l10n/static', about: @l10n %> +<%= render 'admin/application/featured_image/static', about: @l10n %> +<%= render 'admin/application/meta_description/static', about: @l10n %> +<%= render 'admin/application/summary/static', about: @l10n %> +<%= render 'admin/communication/blocks/content/static', about: @l10n %> --- From 7a1c2dbef21e72a16fb18084a2003bf40db9d3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 12 Aug 2024 17:45:18 +0200 Subject: [PATCH 5/9] permalink mapping --- app/models/communication/website/permalink/with_mapping.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/communication/website/permalink/with_mapping.rb b/app/models/communication/website/permalink/with_mapping.rb index 4fe5ee2e0..8035c47f6 100644 --- a/app/models/communication/website/permalink/with_mapping.rb +++ b/app/models/communication/website/permalink/with_mapping.rb @@ -33,8 +33,8 @@ module Communication::Website::Permalink::WithMapping "Communication::Website::Agenda::Event::Localization" => Communication::Website::Permalink::Agenda::Event, "Communication::Website::Agenda::Category::Localization" => Communication::Website::Permalink::Agenda::Category, "Communication::Website::Page::Localization" => Communication::Website::Permalink::Page, - # "Communication::Website::Portfolio::Project::Localization" => Communication::Website::Permalink::Portfolio::Project, - # "Communication::Website::Portfolio::Category::Localization" => Communication::Website::Permalink::Portfolio::Category, + "Communication::Website::Portfolio::Project::Localization" => Communication::Website::Permalink::Portfolio::Project, + "Communication::Website::Portfolio::Category::Localization" => Communication::Website::Permalink::Portfolio::Category, "Communication::Website::Post::Localization" => Communication::Website::Permalink::Post, "Communication::Website::Post::Category::Localization" => Communication::Website::Permalink::Category, # "Education::Diploma::Localization" => Communication::Website::Permalink::Diploma, From 4121029cdd0858b91819b6c26f2a0e15a1c021e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 19 Aug 2024 11:58:04 +0200 Subject: [PATCH 6/9] fix --- .../communication/websites/portfolio/categories/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3b8d1fd60..837e6f8b0 100644 --- a/app/views/admin/communication/websites/portfolio/categories/show.html.erb +++ b/app/views/admin/communication/websites/portfolio/categories/show.html.erb @@ -3,7 +3,7 @@
<%= render 'admin/application/summary/show', about: @l10n %> - <%= render 'admin/application/i18n/widget', about: @category, l10n: @l10n %> + <%= render 'admin/application/l10n/widget', about: @category, l10n: @l10n %>
<%= render 'admin/application/featured_image/show', about: @l10n %> From 239450f5b2464d388318f0ae53241c7f7500fd93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 19 Aug 2024 12:13:05 +0200 Subject: [PATCH 7/9] fix --- .../communication/website/portfolio/project/localization.rb | 4 ++++ .../communication/websites/portfolio/projects/static.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/communication/website/portfolio/project/localization.rb b/app/models/communication/website/portfolio/project/localization.rb index 242c2492f..d8750dda0 100644 --- a/app/models/communication/website/portfolio/project/localization.rb +++ b/app/models/communication/website/portfolio/project/localization.rb @@ -46,6 +46,10 @@ class Communication::Website::Portfolio::Project::Localization < ApplicationReco include WithGitFiles include WithUniversity + belongs_to :website, + class_name: 'Communication::Website', + foreign_key: :communication_website_id + validates :title, presence: true scope :ordered, -> { order(year: :desc, title: :asc) } diff --git a/app/views/admin/communication/websites/portfolio/projects/static.html.erb b/app/views/admin/communication/websites/portfolio/projects/static.html.erb index 58269e873..b0379d0b5 100644 --- a/app/views/admin/communication/websites/portfolio/projects/static.html.erb +++ b/app/views/admin/communication/websites/portfolio/projects/static.html.erb @@ -10,7 +10,7 @@ project = @l10n.about toc_offcanvas: false, about: project, l10n: @l10n %> -<%= render 'admin/application/i18n/static', about: @l10n %> +<%= render 'admin/application/l10n/static', about: @l10n %> <%= render 'admin/application/featured_image/static', about: @l10n %> <%= render 'admin/application/shared_image/static', about: @l10n %> <%= render 'admin/application/meta_description/static', about: @l10n %> From 509f97d3691a5ce6f775f76540ebeafacbf1f3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 19 Aug 2024 13:50:03 +0200 Subject: [PATCH 8/9] website id on project localization --- .../communication/website/agenda/event/localization.rb | 4 ++-- .../communication/website/portfolio/project/localization.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/communication/website/agenda/event/localization.rb b/app/models/communication/website/agenda/event/localization.rb index a67c153fd..4c1586f16 100644 --- a/app/models/communication/website/agenda/event/localization.rb +++ b/app/models/communication/website/agenda/event/localization.rb @@ -57,14 +57,14 @@ class Communication::Website::Agenda::Event::Localization < ApplicationRecord alias :event :about - delegate :archive?, + delegate :archive?, :from_day, :from_hour, :to_day, :to_hour, :time_zone, to: :event has_summernote :text - + validates :title, presence: true before_validation :set_communication_website_id diff --git a/app/models/communication/website/portfolio/project/localization.rb b/app/models/communication/website/portfolio/project/localization.rb index d8750dda0..9fd724382 100644 --- a/app/models/communication/website/portfolio/project/localization.rb +++ b/app/models/communication/website/portfolio/project/localization.rb @@ -52,6 +52,8 @@ class Communication::Website::Portfolio::Project::Localization < ApplicationReco validates :title, presence: true + before_validation :set_communication_website_id + scope :ordered, -> { order(year: :desc, title: :asc) } scope :published, -> { where(published: true) } scope :draft, -> { where(published: false) } @@ -101,4 +103,8 @@ def explicit_blob_ids ] end + def set_communication_website_id + self.communication_website_id ||= about.communication_website_id + end + end From 2e2de58b133187a13160176646be877c31841136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Mon, 19 Aug 2024 14:07:10 +0200 Subject: [PATCH 9/9] fix --- app/models/communication/website/portfolio/category.rb | 6 +++--- app/models/communication/website/portfolio/project.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/communication/website/portfolio/category.rb b/app/models/communication/website/portfolio/category.rb index b7f53b673..457e0eae6 100644 --- a/app/models/communication/website/portfolio/category.rb +++ b/app/models/communication/website/portfolio/category.rb @@ -43,11 +43,11 @@ class Communication::Website::Portfolio::Category < ApplicationRecord include AsCategory include AsDirectObject - include Contentful # TODO L10N : To removes + include Contentful # TODO L10N : To remove include Sanitizable include Localizable - include WithBlobs # TODO L10N : To removes - include WithFeaturedImage # TODO L10N : To removes + include WithBlobs # TODO L10N : To remove + include WithFeaturedImage # TODO L10N : To remove include WithMenuItemTarget include WithUniversity diff --git a/app/models/communication/website/portfolio/project.rb b/app/models/communication/website/portfolio/project.rb index 04847cd6c..c248108af 100644 --- a/app/models/communication/website/portfolio/project.rb +++ b/app/models/communication/website/portfolio/project.rb @@ -34,7 +34,7 @@ # class Communication::Website::Portfolio::Project < ApplicationRecord include AsDirectObject - include Contentful # TODO L10N : To removes + include Contentful # TODO L10N : To remove include Sanitizable include Shareable # TODO L10N : To remove include Localizable