Skip to content

Commit

Permalink
Refonte des options de bloc (#1850)
Browse files Browse the repository at this point in the history
* infra

* options

* new interfaces

* wip

* done

* refactor

* remove partner

* fix

* page main description

* Temporarily hide new options

* migrate options name in block show partial

* schema

* newline

* pages labels

* double equals

* add future option_year on project template

* public_send

* fix option_categories

* handle option_link in organizations show

* option_link instead of with_link in organizations

* option attributes in template pages

* options in template persons

* remove useless locales

* remove old fix

* space

* fix label future option_image in projects

---------

Co-authored-by: Sébastien Gaya <sebastien.gaya@gmail.com>
Co-authored-by: alexisben <alex@noesya.coop>
  • Loading branch information
3 people committed Jul 12, 2024
1 parent 0ab85ac commit f948fbf
Show file tree
Hide file tree
Showing 43 changed files with 431 additions and 292 deletions.
5 changes: 5 additions & 0 deletions app/helpers/admin/blocks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def block_component_add_element(block, label)
label: label
end

def block_options_static(block)
render 'admin/communication/blocks/options/static',
block: block
end

def block_html_class(block)
html_class = "block block-#{block.template_kind}"
html_class += " block-#{block.template_kind}--#{block.template.layout}" if block.template.respond_to?(:layout)
Expand Down
3 changes: 2 additions & 1 deletion app/models/communication/block/component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Communication::Block::Component::Base

attr_reader :property, :template

def initialize(property, template, options = nil)
def initialize(property, template, options: nil, default: nil)
@property = property.to_s
@template = template
@options = options
@default = default
end

def default_data
Expand Down
8 changes: 7 additions & 1 deletion app/models/communication/block/component/boolean.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class Communication::Block::Component::Boolean < Communication::Block::Component::Base

def default_data
false
@default.nil? ? false
: @default
end

def data
@data.nil? ? default_data
: @data
end

def data=(value)
Expand Down
12 changes: 11 additions & 1 deletion app/models/communication/block/template/agenda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B
has_component :description, :rich_text
has_component :quantity, :number, options: 3
has_component :time, :option, options: AUTHORIZED_SCOPES
has_component :no_event_message, :string

# Deprecated
has_component :show_category, :boolean
has_component :show_summary, :boolean
has_component :show_status, :boolean
has_component :no_event_message, :string
# end

has_component :option_categories, :boolean, default: false
has_component :option_dates, :boolean, default: true
has_component :option_image, :boolean, default: true
has_component :option_subtitle, :boolean, default: true
has_component :option_summary, :boolean, default: true
has_component :option_status, :boolean, default: false

def selected_events
@selected_events ||= send "selected_events_#{mode}"
Expand Down
8 changes: 5 additions & 3 deletions app/models/communication/block/template/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def self.has_layouts(property)
has_component :layout, :layout
end

def self.has_component(property, kind, options: nil)
def self.has_component(property, kind, options: nil, default: nil)
self.components_descriptions ||= []
self.components_descriptions << {
property: property,
kind: kind,
options: options
options: options,
default: default
}
class_eval <<-CODE, __FILE__, __LINE__ + 1
Expand Down Expand Up @@ -104,7 +105,8 @@ def build_component(property)
component_class = "Communication::Block::Component::#{hash[:kind].to_s.classify}".constantize
component_class.new hash[:property],
self,
hash[:options]
options: hash[:options],
default: hash[:default]
end

def check_accessibility
Expand Down
3 changes: 3 additions & 0 deletions app/models/communication/block/template/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Communication::Block::Template::Location < Communication::Block::Template:
:list
]

has_component :option_image, :boolean, default: true
has_component :option_summary, :boolean, default: true

def dependencies
selected_locations
end
Expand Down
9 changes: 8 additions & 1 deletion app/models/communication/block/template/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ class Communication::Block::Template::Organization < Communication::Block::Templ
]
has_component :category_id, :organization_category
has_component :description, :rich_text
has_component :with_link, :boolean
has_component :alphabetical, :boolean

# Deprecated
has_component :with_link, :boolean
# end

has_component :option_link, :boolean, default: true
has_component :option_logo, :boolean, default: true
has_component :option_summary, :boolean, default: false

def elements
if alphabetical
Expand Down
7 changes: 7 additions & 0 deletions app/models/communication/block/template/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ class Communication::Block::Template::Page < Communication::Block::Template::Bas
has_component :mode, :option, options: [:selection, :children]
has_component :text, :rich_text
has_component :page_id, :page

# Deprecated
has_component :show_main_description, :boolean
has_component :show_description, :boolean
has_component :show_image, :boolean
# end

has_component :option_image, :boolean, default: true
has_component :option_main_summary, :boolean, default: true
has_component :option_summary, :boolean, default: true

def page
page_id_component.page
Expand Down
9 changes: 8 additions & 1 deletion app/models/communication/block/template/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ class Communication::Block::Template::Person < Communication::Block::Template::B
]
has_component :category_id, :person_category
has_component :description, :rich_text
has_component :alphabetical, :boolean

# Deprecated
has_component :with_link, :boolean
has_component :with_photo, :boolean
has_component :alphabetical, :boolean
# end

has_component :option_image, :boolean, default: true
has_component :option_summary, :boolean, default: true
has_component :option_link, :boolean, default: true

def elements
if alphabetical
Expand Down
10 changes: 10 additions & 0 deletions app/models/communication/block/template/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas
]
has_component :posts_quantity, :number, options: 3
has_component :category_id, :post_category

# Deprecated
has_component :hide_image, :boolean
has_component :hide_summary, :boolean
has_component :hide_category, :boolean
has_component :hide_author, :boolean
has_component :hide_date, :boolean
# end

has_component :option_author, :boolean, default: false
has_component :option_categories, :boolean, default: false
has_component :option_date, :boolean, default: false
has_component :option_image, :boolean, default: true
has_component :option_reading_time, :boolean, default: false
has_component :option_summary, :boolean, default: true

def category
category_id_component.category
Expand Down
4 changes: 4 additions & 0 deletions app/models/communication/block/template/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class Communication::Block::Template::Program < Communication::Block::Template::
has_elements
has_layouts [:list, :grid]

has_component :option_diploma, :boolean, default: true
has_component :option_image, :boolean, default: false
has_component :option_summary, :boolean, default: false

def dependencies
selected_programs
end
Expand Down
9 changes: 7 additions & 2 deletions app/models/communication/block/template/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ class Communication::Block::Template::Project < Communication::Block::Template::
:large
]
has_component :mode, :option, options: [
:all,
:category,
:all,
:category,
:selection,
:categories
]
has_component :projects_quantity, :number, options: 3
has_component :category_id, :project_category

has_component :option_categories, :boolean, default: true
has_component :option_image, :boolean, default: true
has_component :option_summary, :boolean, default: false
has_component :option_year, :boolean, default: true

def category
category_id_component.category
end
Expand Down
13 changes: 13 additions & 0 deletions app/models/communication/block/with_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Communication::Block::WithTemplate
extend ActiveSupport::Concern

included do
OPTION_PREFIX = 'option_'.freeze

# Used to purge images when unattaching them
# template_blobs would be a better name, because there are files
has_many_attached :template_images
Expand All @@ -17,6 +19,17 @@ def template_reset!
@template = nil
end

def options
options = {}
template.components_descriptions.map do |desc|
property = desc[:property].to_s
next unless property.start_with?(OPTION_PREFIX)
property_without_prefix = property.remove(OPTION_PREFIX)
options[property_without_prefix] = template.public_send(property)
end
options
end

protected

def template_class
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/communication/blocks/options/_static.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
options:
<% block.options.each do |key, value| %>
<%= key %>: <%= value %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<div class="row pure__row--small">
<div class="row pure__row--small mb-5">
<div class="col-xl-6">
<%= block_component_edit block, :description %>
</div>
<div class="col-xl-6" v-if="data.mode !== 'categories'">
<%= osuny_label t('admin.communication.blocks.display_options.title') %>
<%#= block_component_edit block, :option_image, label: Communication::Website::Agenda::Event.human_attribute_name(:featured_image) %>
<%#= block_component_edit block, :option_subtitle, label: Communication::Website::Agenda::Event.human_attribute_name(:subtitle) %>
<%= block_component_edit block, :option_summary, label: t('admin.summary.label') %>
<%#= block_component_edit block, :option_dates, label: Communication::Website::Agenda::Event.human_attribute_name(:dates) %>
<%= block_component_edit block, :option_categories, label: Communication::Website::Agenda::Event.human_attribute_name(:categories) %>
<%= block_component_edit block, :option_status, label: Communication::Website::Agenda::Event.human_attribute_name(:status) %>
</div>
</div>

<div class="row pure__row--small">
Expand Down Expand Up @@ -51,14 +60,5 @@
</div>
</draggable>
</div>

<div class="row pure__row--small">
<div class="col-xl-6">
<%= osuny_label t('admin.communication.blocks.templates.agenda.edit.show.label') %>
<%= block_component_edit block, :show_summary %>
<%= block_component_edit block, :show_category %>
<%= block_component_edit block, :show_status %>
<%= block_component_edit block, :no_event_message %>
</div>
</div>
<%= block_component_edit block, :no_event_message %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<% end %>
</div>
<% end %>
<% if event.status.present? && block.template.show_status %>
<% if event.status.present? && block.template.option_status %>
<p class="event-status">
<% if event.status == "current" %>
<%= t 'admin.communication.blocks.templates.agenda.time.options.current' %>
Expand All @@ -60,7 +60,7 @@
</p>
<% end %>
<% if block.template.show_summary && event.summary.present? %>
<% if block.template.option_summary && event.summary.present? %>
<div class="event-description">
<p itemprop="description">
<%= event.summary %>
Expand All @@ -71,7 +71,7 @@
</div>
<% end %>
<% if event.categories.present? && block.template.show_category%>
<% if event.categories.present? && block.template.option_categories %>
<p class="event-categories">
<% event.categories.each do |category| %>
<span><%= link_to category, category.current_permalink_url_in_website(@website) %></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= block_component_static block, :mode %>
<%= block_options_static block %>
<%= block_component_static block, :layout %>
<%= block_component_static block, :description %>
<%= block_component_static block, :no_event_message %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="block-content">
<%= render 'admin/communication/blocks/partials/top', block: block %>
<% if block.template.layout === "carousel" %>
<% if block.template.layout == "carousel" %>
<% if !block.template.elements.one? %>
<div class="splide" role="group" data-splide='{"arrows":true,"pagination":false,"autoWidth":true,"autoplay":false}'>
<div class="splide__track">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<%= block_component_edit block, :layout %>

<!--
<div class="mb-5">
<%= osuny_label t('admin.communication.blocks.display_options.title') %>
<%= block_component_edit block, :option_image, label: Administration::Location.human_attribute_name(:image) %>
<%= block_component_edit block, :option_summary, label: t('admin.summary.label') %>
</div>
-->

<%= block_component_add_element block, t('.add') %>
<draggable :list="data.elements" handle=".dragHandle" class="mb-3">
<div v-for="(element, index) in data.elements" class="d-flex draggable-item">
<div>
Expand All @@ -19,4 +28,6 @@
</div>
</div>
</draggable>
<%= block_component_add_element block, t('.add') %>
<div v-show="data.elements.length > 2">
<%= block_component_add_element block, t('.add') %>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= block_options_static block %>
locations:
<% block.template.elements.each do |element| %>
<% next unless element.location %>
Expand Down
Loading

0 comments on commit f948fbf

Please sign in to comment.