diff --git a/app/controllers/admin/communication/websites/agenda/events_controller.rb b/app/controllers/admin/communication/websites/agenda/events_controller.rb index a78ff1a9104db908706f2a990e533add4627c9d0..04326f9179071756aa5d8b281ea995b14baf561c 100644 --- a/app/controllers/admin/communication/websites/agenda/events_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/events_controller.rb @@ -2,8 +2,11 @@ class Admin::Communication::Websites::Agenda::EventsController < Admin::Communic load_and_authorize_resource class: Communication::Website::Agenda::Event, through: :website + before_action :load_categories, only: [:new, :edit] + def index @events = apply_scopes(@events).for_language(current_website_language).ordered.page params[:page] + @root_categories = @website.categories.for_language(current_website_language).root.ordered breadcrumb end @@ -80,7 +83,8 @@ class Admin::Communication::Websites::Agenda::EventsController < Admin::Communic .permit( :title, :meta_description, :summary, :published, :slug, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, - :from_day, :from_hour, :to_day, :to_hour + :from_day, :from_hour, :to_day, :to_hour, + category_ids: [] ) .merge( university_id: current_university.id, diff --git a/app/controllers/admin/communication/websites/application_controller.rb b/app/controllers/admin/communication/websites/application_controller.rb index f5111244d3ac6ba18697d14938e0ae8550d29ae3..44cb83f3ed2c2eef73f4185b2bc21cb43e77278b 100644 --- a/app/controllers/admin/communication/websites/application_controller.rb +++ b/app/controllers/admin/communication/websites/application_controller.rb @@ -25,4 +25,8 @@ class Admin::Communication::Websites::ApplicationController < Admin::Communicati end options end + + def load_categories + @categories = @website.categories.for_language(current_website_language) + end end diff --git a/app/controllers/admin/communication/websites/posts_controller.rb b/app/controllers/admin/communication/websites/posts_controller.rb index e16f48cec4ea647086c794a928ac865985138ce8..ba642280dc0210fe67caccdc57a9c5391c058b8f 100644 --- a/app/controllers/admin/communication/websites/posts_controller.rb +++ b/app/controllers/admin/communication/websites/posts_controller.rb @@ -129,8 +129,4 @@ class Admin::Communication::Websites::PostsController < Admin::Communication::We def load_filters @filters = ::Filters::Admin::Communication::Website::Posts.new(current_user, @website).list end - - def load_categories - @categories = @website.categories.for_language(current_website_language) - end end diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index 67c710dae7813e905b2a1ad8fc390a12db7f832c..c96700f8f2a2a9f4e355d4cb32db221b81b216fd 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -58,6 +58,12 @@ class Communication::Website::Agenda::Event < ApplicationRecord class_name: 'Communication::Website::Agenda::Event', optional: true + has_and_belongs_to_many :categories, + class_name: 'Communication::Website::Category', + join_table: :communication_website_agenda_events_categories, + foreign_key: :communication_website_agenda_event_id, + association_foreign_key: :communication_website_category_id + scope :ordered_desc, -> { order(from_day: :desc, from_hour: :desc) } scope :ordered_asc, -> { order(:from_day, :from_hour) } scope :ordered, -> { ordered_asc } diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 17afdc07c9fa9f4cbdd33c3304558091d5b051a7..64e565c1a07225c47fb4c6ef7b3d037114c138d8 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -70,6 +70,11 @@ class Communication::Website::Category < ApplicationRecord join_table: :communication_website_categories_posts, foreign_key: :communication_website_category_id, association_foreign_key: :communication_website_post_id + has_and_belongs_to_many :events, + class_name: 'Communication::Website::Agenda::Event', + join_table: :communication_website_agenda_events_categories, + foreign_key: :communication_website_category_id, + association_foreign_key: :communication_website_agenda_event_id validates :name, presence: true 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 576ba9c86683bd85324da3d3050d4f6146daa576..380a0448c60302f90b35b9922771bcbe6990b97f 100644 --- a/app/views/admin/communication/websites/agenda/events/_form.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_form.html.erb @@ -26,7 +26,17 @@ </div> </div> <% end %> + <% if @categories.any? %> + <%= osuny_panel t('activerecord.attributes.communication/website/post.categories') do %> + <%= f.association :categories, + label_text: false, + as: :check_boxes, + collection: collection_tree_for_checkboxes(@categories) %> + <% end %> + <% end %> + <%= render 'admin/application/meta_description/form', f: f, about: event %> + </div> <div class="col-md-4"> <%= osuny_panel t('metadata') do %> 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 98cdcba2140109d1816777ed041a26dd124a47ba..038ea46d1de8b342ef19d7fde97a7579a9baf041 100644 --- a/app/views/admin/communication/websites/agenda/events/_list.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_list.html.erb @@ -7,18 +7,19 @@ <tr> <th class="ps-0" style="min-width: 250px"><%= Communication::Website::Agenda::Event.human_attribute_name('title') %></th> <th><%= Communication::Website::Agenda::Event.human_attribute_name('dates') %></th> + <th><%= Communication::Website::Agenda::Event.human_attribute_name('categories') %></th> <th><%= Communication::Website::Agenda::Event.human_attribute_name('featured_image') %></th> </tr> </thead> <tbody> <% events.each do |event| %> - <tr class="<% 'draft' unless event.published? %>"> - <td class="ps-0"> + <tr class="<%= 'draft' unless event.published? %>"> + <td> <%= link_to event, - admin_communication_website_agenda_event_path(website_id: event.website.id, id: event.id), - class: "#{'draft' unless event.published?}" %> + admin_communication_website_agenda_event_path(website_id: event.website.id, id: event.id) %> </td> <td class="small"><%= render 'admin/communication/websites/agenda/events/dates', event: event %></td> + <td class="small"><%= render 'admin/communication/websites/categories/inline', about: event %></td> <td> <%= kamifusen_tag event.featured_image, width: 100 if event.featured_image.attached? %> </td> 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 92fd9962628ccbe23741f26bf10e925457d52372..9f75cfd7752fe64edbe929dd7ac3968eb886c1ef 100644 --- a/app/views/admin/communication/websites/agenda/events/index.html.erb +++ b/app/views/admin/communication/websites/agenda/events/index.html.erb @@ -15,4 +15,7 @@ <%= render 'admin/communication/websites/agenda/events/list', events: @events %> <%= paginate @events, theme: 'bootstrap-5' %> <% end %> + + <%= render 'admin/communication/websites/categories/panel', root_categories: @root_categories %> <% 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 3bd2fded9ad281eaf2eb25d37abff5c6a187a704..b613966a781f70d74e446a90e02dd1bb009cb348 100644 --- a/app/views/admin/communication/websites/agenda/events/show.html.erb +++ b/app/views/admin/communication/websites/agenda/events/show.html.erb @@ -17,12 +17,7 @@ <hr class="mb-5"> <div class="row"> <div class="col-lg-4"> - <div class="mb-4"> - <%= osuny_label t('metadata') %><br> - <% # TODO i18n après Violenn %> - <%= @event.published ? 'Publié' : 'Brouillon' %> - <%= render 'admin/application/i18n/inline', about: @event %> - </div> + <%= render 'admin/communication/websites/agenda/events/show/metadata' %> </div> <div class="col-lg-8"> <%= render 'admin/application/summary/show', about: @event, small: true %> 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 new file mode 100644 index 0000000000000000000000000000000000000000..f597b0a7f916e6b39f477fc18ad849fc40fde639 --- /dev/null +++ b/app/views/admin/communication/websites/agenda/events/show/_metadata.html.erb @@ -0,0 +1,15 @@ +<div class="mb-4"> + <%= osuny_label t('metadata') %><br> + + <%= @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', + categories: @event.categories.collect(&:to_s).join(', ') + ) %> + <% end %> +</div> diff --git a/app/views/admin/communication/websites/agenda/events/static.html.erb b/app/views/admin/communication/websites/agenda/events/static.html.erb index 9e83a432b2ee92ada11d4c303e668f8f92799aa1..137d6f1c0969e1a3345ee5757b031cafd8b0febf 100644 --- a/app/views/admin/communication/websites/agenda/events/static.html.erb +++ b/app/views/admin/communication/websites/agenda/events/static.html.erb @@ -11,5 +11,6 @@ weight: <%= @about.distance_in_days %> <%= render 'admin/application/featured_image/static' %> <%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/summary/static' %> +<%= render 'admin/communication/websites/categories/static_about' %> <%= render 'admin/communication/blocks/content/static', about: @about %> --- diff --git a/app/views/admin/communication/websites/categories/_inline.html.erb b/app/views/admin/communication/websites/categories/_inline.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2594e1625ab871a8974d25a9d1c8b26d85bb95f8 --- /dev/null +++ b/app/views/admin/communication/websites/categories/_inline.html.erb @@ -0,0 +1,5 @@ +<ul class="list-unstyled mb-0"> + <% about.categories.each do |category| %> + <li><%= category %></li> + <% end %> +</ul> diff --git a/app/views/admin/communication/websites/categories/_panel.html.erb b/app/views/admin/communication/websites/categories/_panel.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a289c6377985411a8ed68e34681b831e3bc2caa4 --- /dev/null +++ b/app/views/admin/communication/websites/categories/_panel.html.erb @@ -0,0 +1,10 @@ +<% if can?(:create, Communication::Website::Category) || (root_categories.any? && can?(:edit, root_categories.first)) %> + <% action = create_link Communication::Website::Category %> + <%= osuny_panel Communication::Website::Category.model_name.human(count: 2), action: action do %> + <ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container" + data-id="" + data-sort-url="<%= reorder_admin_communication_website_categories_path %>"> + <%= render 'admin/communication/websites/categories/treebranch', categories: root_categories %> + </ul> + <% end %> +<% end %> diff --git a/app/views/admin/communication/websites/categories/_static_about.html.erb b/app/views/admin/communication/websites/categories/_static_about.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..1f6b4ec4cf088b671178dff7da896604e6725073 --- /dev/null +++ b/app/views/admin/communication/websites/categories/_static_about.html.erb @@ -0,0 +1,6 @@ +<% if @about.categories.any? %> +categories: + <% @about.categories.each do |category| %> + - "<%= category.slug_with_ancestors_slugs %>" + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/posts/_list.html.erb b/app/views/admin/communication/websites/posts/_list.html.erb index 5f04b74e9690327440a3de82ada2c87a115bb08a..1c99eaa857320641ccca663ab5f352735ed0749d 100644 --- a/app/views/admin/communication/websites/posts/_list.html.erb +++ b/app/views/admin/communication/websites/posts/_list.html.erb @@ -42,13 +42,7 @@ selectable ||= false <% if !hide_author && post.author %> <%= post.author %><br> <% end %> - <% unless hide_category %> - <ul class="list-unstyled mb-0"> - <% post.categories.each do |category| %> - <li><%= category %></li> - <% end %> - </ul> - <% end %> + <%= render 'admin/communication/websites/categories/inline', about: post unless hide_category %> <% if post.pinned %> <%= Communication::Website::Post.human_attribute_name('pinned') %> <% end %> diff --git a/app/views/admin/communication/websites/posts/index.html.erb b/app/views/admin/communication/websites/posts/index.html.erb index acf2195ffddafa27a2d5ea288f2b931d6ecaa524..18e9992fb2b98cc5f2196c501f75eff9a8550bf9 100644 --- a/app/views/admin/communication/websites/posts/index.html.erb +++ b/app/views/admin/communication/websites/posts/index.html.erb @@ -39,16 +39,7 @@ <% end %> </div> <% end %> - <% if can?(:create, Communication::Website::Category) || (@root_categories.any? && can?(:edit, @root_categories.first)) %> - <% action = create_link Communication::Website::Category %> - <%= osuny_panel Communication::Website::Category.model_name.human(count: 2), action: action do %> - <ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container" - data-id="" - data-sort-url="<%= reorder_admin_communication_website_categories_path %>"> - <%= render 'admin/communication/websites/categories/treebranch', categories: @root_categories %> - </ul> - <% end %> - <% end %> + <%= render 'admin/communication/websites/categories/panel', root_categories: @root_categories %> <% if @authors.any? %> <%= osuny_panel t('communication.authors', count: 2) do %> <%= render 'admin/communication/websites/authors/list', authors: @authors %> diff --git a/app/views/admin/communication/websites/posts/static.html.erb b/app/views/admin/communication/websites/posts/static.html.erb index 0c17c1a6a04ea6d446c9363a908100bc67cc4bac..52d468a4a70e2debaf13e84e52519160c7ede004 100644 --- a/app/views/admin/communication/websites/posts/static.html.erb +++ b/app/views/admin/communication/websites/posts/static.html.erb @@ -13,12 +13,7 @@ weight: 1 authors: - "<%= @about.translated_author.slug %>" <% end %> -<% if @about.categories.any? %> -categories: - <% @about.categories.each do |category| %> - - "<%= category.slug_with_ancestors_slugs %>" - <% end %> -<% end %> +<%= render 'admin/communication/websites/categories/static_about' %> <%= render 'admin/application/i18n/static' %> <%= render 'admin/application/featured_image/static' %> <%= render 'admin/application/meta_description/static' %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index db409f6584315aaba48c5a2955137cce3bc045a9..91b22d9e970e9c92b322544a42447a72bcd0ff8b 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -165,6 +165,7 @@ en: url: URL university: University communication/website/agenda/event: + categories: Categories dates: Dates featured_image: Featured image from_day: From day @@ -256,6 +257,7 @@ en: website: agenda: events: + draft: Draft none: No event yet default_image: "The default image will be used on pages and posts that do not have an image, if the theme is set to display images in all cases. It is also the default sharing image." editorial: diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index fb95a9c825d57aef5136a7c75cc6d777fc92eaaa..21c29c120b212b15012dd0d80c698928a80bba0e 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -165,6 +165,7 @@ fr: university: Université url: URL communication/website/agenda/event: + categories: Catégories dates: Dates featured_image: Image à la une from_day: Jour de début @@ -257,6 +258,7 @@ fr: agenda: events: none: Pas encore d'événements + draft: Brouillon default_image: "L'image par défaut sera utilisée dans les pages et actualités qui n'ont pas d'image, si le thème est paramétré pour afficher des images dans tous les cas. C'est aussi l'image de partage par défaut." editorial: label: Éditorial diff --git a/db/migrate/20231031102713_join_categories_to_events.rb b/db/migrate/20231031102713_join_categories_to_events.rb new file mode 100644 index 0000000000000000000000000000000000000000..20f7786c5ce0cb98222865c2bea80d4653838c37 --- /dev/null +++ b/db/migrate/20231031102713_join_categories_to_events.rb @@ -0,0 +1,11 @@ +class JoinCategoriesToEvents < ActiveRecord::Migration[7.1] + def change + + create_table "communication_website_agenda_events_categories", id: false, force: :cascade do |t| + t.uuid "communication_website_agenda_event_id", null: false + t.uuid "communication_website_category_id", null: false + t.index ["communication_website_category_id", "communication_website_agenda_event_id"], name: "category_event" + t.index ["communication_website_agenda_event_id", "communication_website_category_id"], name: "event_category" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 659e0ae397ed6501c52e9dedbd3b6089c4283ee7..2eebca15a2d0413cf1aa3baca787bd93c0e72b16 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: 2023_10_18_182341) do +ActiveRecord::Schema[7.1].define(version: 2023_10_31_102713) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -260,6 +260,13 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_18_182341) do t.index ["university_id"], name: "index_communication_website_agenda_events_on_university_id" end + create_table "communication_website_agenda_events_categories", id: false, force: :cascade do |t| + t.uuid "communication_website_agenda_event_id", null: false + t.uuid "communication_website_category_id", null: false + t.index ["communication_website_agenda_event_id", "communication_website_category_id"], name: "event_category" + t.index ["communication_website_category_id", "communication_website_agenda_event_id"], name: "category_event" + end + create_table "communication_website_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