Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean headings #2378

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions app/controllers/admin/communication/blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
before_action :redirect_if_block_language_is_incorrect, only: [:edit, :update]

def reorder
# Cette action est très étrange, elle ne met pas en ordre les blocs seuls.
# En fait, elle met en ordre dans le mode "Ecrire le contenu", à la fois les headings et les blocks.
@ids = params[:ids] || []
@index_block = 0
@index_heading = 0
@heading = nil
@ids.values.each do |object|
@object = object
reorder_object
Expand Down Expand Up @@ -150,22 +146,22 @@ def journal_id
rescue
end

def about_path
# Les headings sont toujours affectés à des localisations
l10n = @block.about
# La localisation porte sur un objet, par exemple une University::Person ou un Communication::Website::Post
object_edited = l10n.about
# La formation ou la page concernée
path_method = "admin_#{object_edited.class.base_class.to_s.parameterize.underscore}_path"
path_method_options = {
id: object_edited.id,
lang: l10n.language,
website_id: website_id,
extranet_id: extranet_id,
journal_id: journal_id
}
public_send path_method, **path_method_options
end
def about_path
# Les blocs sont toujours affectés à des localisations
l10n = @block.about
# La localisation porte sur un objet, par exemple une University::Person ou un Communication::Website::Post
object_edited = l10n.about
# La formation ou la page concernée
path_method = "admin_#{object_edited.class.base_class.to_s.parameterize.underscore}_path"
path_method_options = {
id: object_edited.id,
lang: l10n.language,
website_id: website_id,
extranet_id: extranet_id,
journal_id: journal_id
}
public_send path_method, **path_method_options
end

def breadcrumb
short_breadcrumb
Expand Down
2 changes: 0 additions & 2 deletions app/models/ability/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def admin_research
def admin_communication
can :manage, Communication::Block, university_id: @user.university_id
can :create, Communication::Block
can :manage, Communication::Block::Heading, university_id: @user.university_id
can :create, Communication::Block::Heading
can :manage, Communication::Website, university_id: @user.university_id
# Est-ce bien raisonnable de laisser supprimer un site ?
# Le risque de faussse manip est grand.
Expand Down
4 changes: 0 additions & 4 deletions app/models/ability/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ def initialize(user)
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Portfolio::Project::Localization', about_id: managed_portfolio_project_localization_ids
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post::Localization', about_id: managed_post_localization_ids
can :create, Communication::Block
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event::Localization', about_id: managed_agenda_event_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Portfolio::Project::Localization', about_id: managed_portfolio_project_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post::Localization', about_id: managed_post_localization_ids
can :create, Communication::Block::Heading
can :read, Communication::Website, university_id: @user.university_id, id: managed_websites_ids
can :manage, Communication::Website::Post, university_id: @user.university_id, communication_website_id: managed_websites_ids, author_id: @user.person&.id
can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id, communication_website_id: managed_websites_ids, created_by_id: @user.id
Expand Down
5 changes: 0 additions & 5 deletions app/models/ability/program_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ def initialize(user)
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Education::Program::Localization', about_id: managed_program_localization_ids
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: managed_person_localization_ids
can :create, Communication::Block
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event::Localization', about_id: managed_event_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post::Localization', about_id: managed_post_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Education::Program::Localization', about_id: managed_program_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: managed_person_localization_ids
can :create, Communication::Block::Heading
can :read, Communication::Website, university_id: @user.university_id
can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id
can :manage, Communication::Website::Post, university_id: @user.university_id
Expand Down
3 changes: 0 additions & 3 deletions app/models/ability/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ def initialize(user)
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Education::Program::Localization', about_id: managed_program_localization_ids
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: managed_person_localization_ids
can :create, Communication::Block
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Education::Program::Localization', about_id: managed_program_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: managed_person_localization_ids
can :create, Communication::Block::Heading
can [:read, :children], Education::Program, university_id: @user.university_id
can :manage, University::Person, user_id: @user.id
cannot :create, University::Person
Expand Down
10 changes: 0 additions & 10 deletions app/models/ability/website_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ def manage_blocks
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Organization::Localization', about_id: University::Organization::Localization.where(university_id: @user.university_id).pluck(:id)
can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: University::Person::Localization.where(university_id: @user.university_id).pluck(:id)
can :create, Communication::Block
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Category::Localization', about_id: managed_agenda_category_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event::Localization', about_id: managed_agenda_event_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Page::Localization', about_id: managed_page_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Portfolio::Category::Localization', about_id: managed_portfolio_category_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Portfolio::Project::Localization', about_id: managed_portfolio_project_localizations_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post::Category::Localization', about_id: managed_post_category_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post::Localization', about_id: managed_post_localization_ids
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Organization::Localization', about_id: University::Organization::Localization.where(university_id: @user.university_id).pluck(:id)
can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Person::Localization', about_id: University::Person::Localization.where(university_id: @user.university_id).pluck(:id)
can :create, Communication::Block::Heading
end

end
1 change: 0 additions & 1 deletion app/models/communication/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class Communication::Block < ApplicationRecord
after_save :touch_about#, :touch_targets # FIXME

scope :published, -> { where(published: true) }
scope :without_heading, -> { where(heading: nil) }

# When we set data from json, we pass it to the template.
# The json we save is first sanitized and prepared by the template.
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/block/with_heading_ranks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Communication::Block::WithHeadingRanks
DEFAULT_HEADING_LEVEL = 2 # h1 is the page title

def heading_rank_self
title.present? ? heading_rank_base : false
title.present? ? heading_rank_base : DEFAULT_HEADING_LEVEL
end

def heading_rank_children
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/website/page/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def git_path_relative
end

def show_toc?
about.try(:show_toc?) || headings.many?
about.try(:show_toc?) || blocks.template_title.many?
end

def to_s
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/as_localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def localize_in!(language)
# Blocks need an about, so we save before localizing blocks
l10n.save

# Handle headings & blocks if object has any
# Handle blocks if object has any
localize_contents!(l10n) if respond_to?(:contents)
l10n
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def blocks
end

def import_blocks
heading = nil
blocks.each do |b|
migration_identifier = b[:migration_identifier]
template_kind = b[:template_kind]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
json.contents about.contents do |block_or_heading|
if block_or_heading.is_a? Communication::Block
json.partial! 'admin/communication/blocks/static', block: block_or_heading
else
# TODO
end
json.contents about.contents do |block|
json.partial! 'admin/communication/blocks/static', block: block
end
4 changes: 1 addition & 3 deletions config/locales/communication/contents/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ en:
close: Close block edition
title: Block edition
empty: This block is empty and will not appear
headings:
add: Add a title
templates:
agenda:
description: A list of upcoming events.
Expand Down Expand Up @@ -717,7 +715,7 @@ en:
description: In “Organize structure” mode, you see only a small preview of each block. This is the ideal mode to organize long documents.
tab: Organize structure
write:
description: In “Write content” mode, you can move blocks and headings anywhere you like, independently of each other. For example, you can move a heading higher up in the document without it taking its blocks with it.
description: In “Write content” mode, you can move blocks anywhere you like, independently of each other. For example, you can move a title higher up in the document without it taking its blocks with it.
tab: Write content
enums:
communication:
Expand Down
2 changes: 0 additions & 2 deletions config/locales/communication/contents/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ fr:
close: Fermer l'édition du bloc
title: Édition de bloc
empty: Ce bloc est vide et n'apparaitra pas
headings:
add: Ajouter un titre
templates:
agenda:
description: Une liste d'événements à venir.
Expand Down
2 changes: 0 additions & 2 deletions config/locales/communication/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ en:
published: Published?
template: Kind of block
title: Name (optional)
communication/block/heading:
title: Title
communication/extranet:
about: About
about_: Independent extranet
Expand Down
2 changes: 0 additions & 2 deletions config/locales/communication/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ fr:
published: Publié ?
template: Type de bloc
title: Nom (facultatif)
communication/block/heading:
title: Titre
communication/extranet:
about: Sujet de l'extranet
about_: Extranet indépendant
Expand Down
2 changes: 1 addition & 1 deletion config/locales/education/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ en:
categories:
root_name: Programs
publication: Publication
submenu: "You are currently in the program summary. For simplicity, each program is broken down into several pages. These pages can be accessed via the menu at the top of the page, and correspond to the headings on the websites. For greater convenience, this summary page shows the menu hereafter."
submenu: "You are currently in the program summary. For simplicity, each program is broken down into several pages. These pages can be accessed via the menu at the top of the page, and correspond to the titles on the websites. For greater convenience, this summary page shows the menu hereafter."
teacher:
no_teaching: No teaching
show_person_html: This page only shows teaching assignments.<br>If you wish to view or modify the person's details, click on the link below.
Expand Down
5 changes: 0 additions & 5 deletions config/routes/admin/communication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@
end
resources :blocks, controller: 'blocks', except: [:index] do
collection do
resources :headings, controller: 'blocks/headings', except: [:index, :show] do
collection do
post :reorder
end
end
post :reorder
end
member do
Expand Down
Loading