Skip to content
Snippets Groups Projects
Commit 374705d4 authored by alexisben's avatar alexisben
Browse files

Fix conflict

parents 50f869e6 4a53077c
No related branches found
No related tags found
No related merge requests found
Showing
with 111 additions and 67 deletions
app/assets/images/communication/blocks/templates/datatable.jpg

17.6 KiB

app/assets/images/communication/blocks/templates/embed.jpg

17.6 KiB

app/assets/images/communication/blocks/templates/files.jpg

17.6 KiB

app/assets/images/communication/blocks/templates/image.jpg

96.1 KiB

app/assets/images/communication/blocks/templates/video.jpg

17.6 KiB

......@@ -11,10 +11,6 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
end
end
def show
breadcrumb
end
def new
@block.about_type = params[:about_type]
@block.about_id = params[:about_id]
......@@ -23,13 +19,13 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
def edit
breadcrumb
add_breadcrumb t('edit')
end
def create
@block.university = current_university
if @block.save
redirect_to [:edit, :admin, @block], notice: t('admin.successfully_created_html', model: @block.to_s)
redirect_to [:edit, :admin, @block],
notice: t('admin.successfully_created_html', model: @block.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
......@@ -38,7 +34,8 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
def update
if @block.update(block_params)
redirect_to about_path, notice: t('admin.successfully_updated_html', model: @block.to_s)
redirect_to about_path,
notice: t('admin.successfully_updated_html', model: @block.to_s)
else
breadcrumb
add_breadcrumb t('edit')
......@@ -49,7 +46,8 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
def destroy
path = about_path
@block.destroy
redirect_to path, notice: t('admin.successfully_destroyed_html', model: @block.to_s)
redirect_to path,
notice: t('admin.successfully_destroyed_html', model: @block.to_s)
end
protected
......@@ -71,7 +69,7 @@ class Admin::Communication::BlocksController < Admin::Communication::Application
if @block.new_record?
add_breadcrumb t('communication.block.choose_template')
else
add_breadcrumb @block, [:admin, @block]
add_breadcrumb @block
end
end
......
......@@ -32,15 +32,20 @@ class Communication::Block < ApplicationRecord
enum template_kind: {
chapter: 50,
organization_chart: 100,
partners: 200,
image: 51,
gallery: 300,
video: 52,
datatable: 54,
files: 55,
embed: 53,
call_to_action: 900,
testimonials: 400,
posts: 500,
pages: 600,
timeline: 700,
definitions: 800,
call_to_action: 900,
organization_chart: 100,
partners: 200,
posts: 500,
pages: 600,
}
before_save :update_template_images
......
......@@ -37,6 +37,20 @@ class Communication::Block::Template
university.active_storage_blobs.find id
end
def extract_image_alt_and_credit(source, variable)
blob = find_blob source, variable
return if blob.nil?
alt = source["alt"] || source["#{variable}_alt"]
credit = source["credit"] || source["#{variable}_credit"]
text = source["text"] || source["#{variable}_text"]
{
blob: blob,
alt: alt,
credit: credit,
text: text
}.to_dot
end
def data
block.data || {}
end
......
......@@ -23,19 +23,15 @@ class Communication::Block::Template::CallToAction < Communication::Block::Templ
"#{data['button_secondary']}"
end
def image
image_with_alt_and_credit
def url_tertiary
"#{data['url_tertiary']}"
end
protected
def button_tertiary
"#{data['button_tertiary']}"
end
def image_with_alt_and_credit
blob = find_blob data, 'image'
return if blob.nil?
{
blob: blob,
alt: data['image_alt'],
credit: data['image_credit'],
}.to_dot
def image
extract_image_alt_and_credit data, 'image'
end
end
class Communication::Block::Template::Chapter < Communication::Block::Template
def build_git_dependencies
# pas d'images dans summernote, donc rien à déclarer !
add_dependency image&.blob
end
def image
extract_image_alt_and_credit data, 'image'
end
def text
......
class Communication::Block::Template::Datatable < Communication::Block::Template
def build_git_dependencies
end
end
class Communication::Block::Template::Embed < Communication::Block::Template
def build_git_dependencies
end
end
class Communication::Block::Template::File < Communication::Block::Template
def build_git_dependencies
end
end
......@@ -3,26 +3,14 @@ class Communication::Block::Template::Gallery < Communication::Block::Template
add_dependency active_storage_blobs
end
def images_with_data
@images_with_data ||= elements.map { |element| image_with_data(element) }
.compact
def images_with_alt
@images_with_alt ||= elements.map { |element|
extract_image_alt_and_credit element, 'file'
}.compact
end
def active_storage_blobs
@active_storage_blobs ||= images_with_data.map { |hash| hash.blob }
.compact
end
protected
def image_with_data(element)
blob = find_blob element, 'file'
return if blob.nil?
{
blob: blob,
alt: element['alt'],
credit: element['credit'],
text: element['text'],
}.to_dot
end
end
class Communication::Block::Template::Image < Communication::Block::Template
def build_git_dependencies
add_dependency image&.blob
end
def image
extract_image_alt_and_credit data, 'image'
end
def text
"#{data['text']}"
end
end
......@@ -9,33 +9,39 @@ class Communication::Block::Template::Page < Communication::Block::Template
end
def selected_pages
@selected_pages ||= elements.map { |element|
p = page(element['id'])
next if p.nil?
hash_from_page(p, element)
}.compact
# kind could be: selection (default), children
@selected_pages ||= send "selected_pages_#{kind}"
end
def main_page
@main_page ||= page(data['page_id'])
end
def show_description
data['show_description'] || false
def show_descriptions
data['show_descriptions'] || false
end
def show_image
data['show_image'] || false
def show_images
data['show_images'] || false
end
protected
def hash_from_page(page, element)
{
page: page,
show_description: element['show_description'] || false,
show_image: element['show_image'] || false
}.to_dot
def kind
@kind ||= data['kind'] || 'selection'
end
def selected_pages_selection
elements.map { |element|
page element['id']
}.compact
end
def selected_pages_children
return [] unless main_page
main_page.children
.published
.ordered
end
def page(id)
......
......@@ -8,20 +8,23 @@ class Communication::Block::Template::Partner < Communication::Block::Template
end
def partners
@partners ||= elements.map { |element| partner(element) }
.compact
@partners ||= elements.map { |element|
partner(element)
}.compact
end
def active_storage_blobs
@active_storage_blobs ||= partners.map { |partner| partner.blob }
.compact
@active_storage_blobs ||= partners.map { |partner|
partner.blob
}.compact
end
protected
def organizations
@organizations ||= partners.map { |partner| partner.organization }
.compact
@organizations ||= partners.map { |partner|
partner.organization
}.compact
end
def partner(element)
......
......@@ -49,8 +49,9 @@ class Communication::Block::Template::Post < Communication::Block::Template
end
def selected_posts_selection
elements.map { |element| post(element['id']) }
.compact
elements.map { |element|
post(element['id'])
}.compact
end
def post(id)
......
class Communication::Block::Template::Video < Communication::Block::Template
def build_git_dependencies
end
end
......@@ -28,11 +28,10 @@
<% end %>
<td><%= link_to_if can?(:read, block),
block.to_s.truncate(50),
admin_communication_block_path(block) %></td>
edit_admin_communication_block_path(block, website_id: nil) %></td>
<td><%= block.template_kind_i18n %></td>
<td class="text-end">
<div class="btn-group" role="group">
<%= edit_link block %>
<%= destroy_link block %>
</div>
</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment