From 2855eee02474ed8da2b4c894baa78160fc435e2d Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Thu, 16 Dec 2021 17:18:07 +0100 Subject: [PATCH] wip --- app/models/communication/website/category.rb | 1 + app/models/communication/website/page.rb | 11 +++++------ app/models/communication/website/post.rb | 1 + app/models/concerns/with_menu_item_target.rb | 11 +++++++++++ app/models/education/program.rb | 1 + .../admin/communication/website/menus/_form.html.erb | 6 +++++- 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 app/models/concerns/with_menu_item_target.rb diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 1b08ce315..b0c4b39a1 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -32,6 +32,7 @@ # class Communication::Website::Category < ApplicationRecord include WithGithubFiles + include WithMenuItemTarget include WithSlug include WithTree diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 20f0e94f9..f9b54aa15 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -39,15 +39,13 @@ class Communication::Website::Page < ApplicationRecord include Communication::Website::WithMedia include WithGithubFiles + include WithMenuItemTarget include WithSlug include WithTree has_rich_text :text has_one_attached_deletable :featured_image - has_one :imported_page, - class_name: 'Communication::Website::Imported::Page', - dependent: :destroy belongs_to :university belongs_to :website, foreign_key: :communication_website_id @@ -57,13 +55,14 @@ class Communication::Website::Page < ApplicationRecord belongs_to :parent, class_name: 'Communication::Website::Page', optional: true + has_one :imported_page, + class_name: 'Communication::Website::Imported::Page', + dependent: :nullify has_many :children, class_name: 'Communication::Website::Page', foreign_key: :parent_id, dependent: :nullify - has_one :imported_page, - class_name: 'Communication::Website::Imported::Page', - dependent: :nullify + validates :title, presence: true validates :slug, uniqueness: { scope: :communication_website_id } diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index e5e54b9a8..b0fff7941 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -31,6 +31,7 @@ class Communication::Website::Post < ApplicationRecord include Communication::Website::WithMedia include WithGithubFiles + include WithMenuItemTarget include WithSlug has_rich_text :text diff --git a/app/models/concerns/with_menu_item_target.rb b/app/models/concerns/with_menu_item_target.rb new file mode 100644 index 000000000..cd5ed55e8 --- /dev/null +++ b/app/models/concerns/with_menu_item_target.rb @@ -0,0 +1,11 @@ +module WithMenuItemTarget + extend ActiveSupport::Concern + + included do + has_many :menu_items, + as: :about, + class_name: 'Communication::Website::Menu::Item', + dependent: :destroy + + end +end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index a74327634..6cef3f3d8 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -28,6 +28,7 @@ # class Education::Program < ApplicationRecord include WithGithubFiles + include WithMenuItemTarget include WithTree attr_accessor :skip_websites_categories_callback diff --git a/app/views/admin/communication/website/menus/_form.html.erb b/app/views/admin/communication/website/menus/_form.html.erb index d8e33611a..df77eedc3 100644 --- a/app/views/admin/communication/website/menus/_form.html.erb +++ b/app/views/admin/communication/website/menus/_form.html.erb @@ -16,7 +16,11 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :identifier if can?(:create, menu) %> + <%= f.input :identifier, + input_html: menu.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#communication_website_menu_title' } + } if can?(:create, menu) %> </div> </div> </div> -- GitLab