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

Program > Portfolio category + related categories #2339

Merged
merged 26 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
98ad481
add is_taxonomy to blog and agenda categories + set portfolio program…
SebouChu Oct 17, 2024
947ec4c
program related_categories
SebouChu Oct 17, 2024
2c8c76e
fix tests
SebouChu Oct 17, 2024
20c459e
category slug with ancestors
SebouChu Oct 17, 2024
f324fb2
harmonize taxonomies
SebouChu Oct 18, 2024
301a932
add as localized tree to program category l10ns
SebouChu Oct 18, 2024
7700f63
harmonisation !
SebouChu Oct 18, 2024
4af1c8b
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 18, 2024
13aa3b7
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 21, 2024
53e074e
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 21, 2024
64e506b
Merge branch 'main' into program-portfolio-categories
SebouChu Oct 28, 2024
f15b696
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 29, 2024
558690a
is_taxonomy
arnaudlevy Oct 29, 2024
9b82b69
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 29, 2024
052fd57
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 30, 2024
47911c9
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 31, 2024
b0516da
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 31, 2024
f94a17e
Merge branch 'main' into program-portfolio-categories
arnaudlevy Oct 31, 2024
9ec009c
Merge branch 'main' into program-portfolio-categories
SebouChu Oct 31, 2024
f462e8f
Merge branch 'main' into program-portfolio-categories
SebouChu Oct 31, 2024
e08e370
wip is_taxonomy in person and orga categories
SebouChu Oct 31, 2024
19b3d2b
static categories in orga and people
SebouChu Oct 31, 2024
461303c
fix permalink and git path + hugo_slug
SebouChu Oct 31, 2024
b515121
fix
SebouChu Oct 31, 2024
9352102
static versions
SebouChu Oct 31, 2024
e997244
Merge branch 'main' into program-portfolio-categories
SebouChu Oct 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def breadcrumb
def category_params
params.require(:communication_website_agenda_category)
.permit(
:parent_id,
:is_taxonomy, :parent_id,
localizations_attributes: [
:id, :language_id,
:name, :meta_description, :summary, :slug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def breadcrumb
end

def categories
@website.agenda_categories
.ordered
@website.agenda_categories.ordered
end

def event_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def breadcrumb
def category_params
params.require(:communication_website_post_category)
.permit(
:parent_id,
:is_taxonomy, :parent_id,
localizations_attributes: [
:id, :name, :meta_description, :summary, :slug,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit,
Expand Down
11 changes: 2 additions & 9 deletions app/models/communication/website/agenda/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :uuid not null, primary key
# is_programs_root :boolean default(FALSE)
# is_taxonomy :boolean default(FALSE)
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
Expand All @@ -27,24 +28,16 @@
# fk_rails_7b5ad84dda (communication_website_id => communication_websites.id)
#
class Communication::Website::Agenda::Category < ApplicationRecord
include AsCategory
include AsDirectObject
include Localizable
include Orderable
include Sanitizable
include WithMenuItemTarget
include WithTree
include WithUniversity

belongs_to :parent,
class_name: 'Communication::Website::Agenda::Category',
optional: true
belongs_to :program,
class_name: 'Education::Program',
optional: true
has_many :children,
class_name: 'Communication::Website::Agenda::Category',
foreign_key: :parent_id,
dependent: :destroy
has_and_belongs_to_many :events,
class_name: 'Communication::Website::Agenda::Event',
join_table: :communication_website_agenda_events_categories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class Communication::Website::Agenda::Category::Localization < ApplicationRecord
before_validation :set_communication_website_id, on: :create

def git_path(website)
"#{git_path_content_prefix(website)}events_categories/#{slug}/_index.html"
prefix = git_path_content_prefix(website)
slugs = slug_with_ancestors_slugs(separator: '-')
"#{prefix}events_categories/#{slugs}/_index.html"
end

def template_static
Expand Down Expand Up @@ -94,4 +96,9 @@ def inherited_blob_ids
def set_communication_website_id
self.communication_website_id ||= about.communication_website_id
end

# TODO : Pertinent ?
def hugo_slug_in_website(website)
slug_with_ancestors_slugs(separator: '-')
end
end
2 changes: 1 addition & 1 deletion app/models/communication/website/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def to_s
end

def git_path(website)
"data/menus/#{language.iso_code}/#{identifier}.yml"
"data/menus/#{language.iso_code}/#{identifier}.yml" if website.active_language_ids.include?(language_id)
end

def template_static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def published?

def substitutions
{
slug: about.slug
slug: about.slug_with_ancestors_slugs
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def published?

def substitutions
{
slug: about.slug
slug: about.slug_with_ancestors_slugs
}
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/communication/website/portfolio/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def references
[parent]
end

def siblings
self.class.unscoped.where(parent: parent, university: university, website: website).where.not(id: id)
end

protected

def last_ordered_element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class Communication::Website::Portfolio::Category::Localization < ApplicationRec
before_validation :set_communication_website_id, on: :create

def git_path(website)
"#{git_path_content_prefix(website)}projects_categories/#{slug}/_index.html"
prefix = git_path_content_prefix(website)
slugs = slug_with_ancestors_slugs(separator: '-')
"#{prefix}projects_categories/#{slugs}/_index.html"
end

def template_static
Expand Down Expand Up @@ -85,4 +87,9 @@ def slug_unavailable?(slug)
def set_communication_website_id
self.communication_website_id ||= about.communication_website_id
end

# TODO : Pertinent ?
def hugo_slug_in_website(website)
slug_with_ancestors_slugs(separator: '-')
end
end
11 changes: 2 additions & 9 deletions app/models/communication/website/post/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :uuid not null, primary key
# is_programs_root :boolean default(FALSE)
# is_taxonomy :boolean default(FALSE)
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
Expand All @@ -27,24 +28,16 @@
# fk_rails_e58348b119 (program_id => education_programs.id)
#
class Communication::Website::Post::Category < ApplicationRecord
include AsCategory
include AsDirectObject
include Localizable
include Orderable
include Sanitizable
include WithMenuItemTarget
include WithTree
include WithUniversity

belongs_to :parent,
class_name: 'Communication::Website::Post::Category',
optional: true
belongs_to :program,
class_name: 'Education::Program',
optional: true
has_many :children,
class_name: 'Communication::Website::Post::Category',
foreign_key: :parent_id,
dependent: :destroy
has_and_belongs_to_many :posts,
class_name: 'Communication::Website::Post',
join_table: :communication_website_categories_posts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ def inherited_blob_ids
def set_communication_website_id
self.communication_website_id ||= about.communication_website_id
end

# TODO : Pertinent ?
def hugo_slug_in_website(website)
slug_with_ancestors_slugs(separator: '-')
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def set_programs_categories
end

def set_programs_categories_safely
[post_categories, agenda_categories].each do |objects|
[post_categories, agenda_categories, portfolio_categories].each do |objects|
programs_root_category = set_programs_categories_root_for!(objects)
set_programs_categories_at_level_for! objects, programs_root_category, education_programs.root.ordered
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/education/program/category/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#
class Education::Program::Category::Localization < ApplicationRecord
include AsLocalization
include AsLocalizedTree
include Contentful
include Initials
include Permalinkable
Expand All @@ -49,4 +50,11 @@ def dependencies
def to_s
"#{name}"
end

protected

# TODO : Pertinent ?
def hugo_slug_in_website(website)
slug_with_ancestors_slugs(separator: '-')
end
end
20 changes: 15 additions & 5 deletions app/models/education/program/with_websites_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ module Education::Program::WithWebsitesCategories
included do
after_save_commit :set_websites_categories

has_many :website_post_categories,
class_name: 'Communication::Website::Post::Category',
dependent: :destroy

has_many :website_agenda_categories,
class_name: 'Communication::Website::Agenda::Category',
dependent: :destroy

# TODO : Ajouter les catégories de portfolio
has_many :website_portfolio_categories,
class_name: 'Communication::Website::Portfolio::Category',
dependent: :destroy

has_many :website_post_categories,
class_name: 'Communication::Website::Post::Category',
dependent: :destroy
end

def set_websites_categories
websites.each { |website| website.set_programs_categories }
end

def website_category_l10ns_for(website, language)
categories = {}
categories[:agenda] = website_agenda_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories[:blog] = website_post_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories[:portfolio] = website_portfolio_categories.find_by(communication_website_id: website.id)&.localization_for(language)
categories.compact
end
end
4 changes: 2 additions & 2 deletions app/views/admin/application/categories/_static.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ about_categories.ordered.each do |category|
category_l10n = category.localization_for(l10n.language)
next if category_l10n.nil?
%>
- "<%= category_l10n.slug %>"
- "<%= category_l10n.slug_with_ancestors_slugs(separator: '-') %>"
SebouChu marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
<%
if taxonomies.any?
Expand All @@ -21,7 +21,7 @@ taxonomies:
next if taxonomy_l10n.nil?
%>
- name: "<%= prepare_text_for_static taxonomy_l10n.to_s %>"
slug: "<%= taxonomy_l10n.slug %>"
slug: "<%= taxonomy_l10n.slug_with_ancestors_slugs(separator: '-') %>"
categories:
<%
about_categories.in_taxonomy(taxonomy).each do |category|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
except: category,
localized: true
) %>
<%= 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 %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if @about.categories.any? %>
events_categories:
<% @about.agenda_categories.each do |category| %>
- "<%= category.slug_with_ancestors_slugs %>"
- "<%= category.slug_with_ancestors_slugs(separator: '-') %>"
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
category = @l10n.about
%>---
<%= render 'admin/application/static/title', about: @l10n %>
<%= render 'admin/application/static/permalink', about: @l10n %>
<%= render 'admin/application/static/permalink',
about: @l10n,
forced_slug: @l10n.slug_with_ancestors_slugs(separator: '-') %>
<%= render 'admin/application/static/breadcrumbs', about: @l10n %>
<%= render 'admin/application/static/design',
about: category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@
include_blank: false,
selected: f.object.time_zone || @website.default_time_zone %>
<% end %>
<% if @categories.any? %>
<%= osuny_panel t('activerecord.attributes.communication/website/agenda/event.categories') do %>
<%= f.association :categories,
label_text: false,
as: :check_boxes,
collection: osuny_collection_tree(
@website.agenda_categories.root,
localized: true
) %>
<% end %>
<% end %>

<%= render 'admin/application/categories/form', f: f, categories: @categories %>
<%= render 'admin/application/meta_description/form', f: lf, about: l10n %>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ weight: <%= event.distance_in_days %>
<%= render 'admin/application/shared_image/static', about: @l10n %>
<%= render 'admin/application/meta_description/static', about: @l10n %>
<%= render 'admin/application/summary/static', about: @l10n %>
<% if @l10n.categories.any? %>
events_categories:
<% @l10n.categories.each do |category| %>
- "<%= category.slug %>"
<% end %>
<% end %>
<%= render 'admin/application/categories/static',
about: event,
l10n: @l10n,
categories: @website.agenda_categories,
key: :events_categories %>
<%= render 'admin/communication/contents/static', about: @l10n %>
---
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if @about.categories.any? %>
projects_categories:
<% @about.portfolio_categories.each do |category| %>
- "<%= category.slug_with_ancestors_slugs %>"
- "<%= category.slug_with_ancestors_slugs(separator: '-') %>"
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
category = @l10n.about
%>---
<%= render 'admin/application/static/title', about: @l10n %>
<%= render 'admin/application/static/permalink', about: @l10n %>
<%= render 'admin/application/static/permalink',
about: @l10n,
forced_slug: @l10n.slug_with_ancestors_slugs(separator: '-') %>
<%= render 'admin/application/static/breadcrumbs', about: @l10n %>
<%= render 'admin/application/static/design',
about: category,
Expand Down
16 changes: 1 addition & 15 deletions app/views/admin/communication/websites/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@
<%= render 'admin/application/summary/form', f: lf, about: l10n %>
<%= lf.input :text, as: :summernote if strip_tags(l10n.text).present? %>
<% end %>
<% if @categories.any? %>
<div class="row pure__row--small">
<div class="col-md-6">
<%= osuny_panel t('activerecord.attributes.communication/website/post.categories') do %>
<%= f.association :categories,
label_text: false,
as: :check_boxes,
collection: osuny_collection_tree(
@categories.root,
localized: true
) %>
<% end %>
</div>
</div>
<% end %>
<%= render 'admin/application/categories/form', f: f, categories: @categories %>
<%= render 'admin/application/meta_description/form', f: lf, about: l10n %>
</div>
<div class="col-md-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
except: category,
localized: true
) %>
<%= 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 %>
</div>
Expand Down
Loading
Loading