From a70dfa84a96748a6e7c72c50816615fb1d643c2f Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 17 Jun 2022 18:34:18 +0200 Subject: [PATCH] conventional elements --- .../block/template/call_to_action.rb | 3 +- .../call_to_action/{button.rb => element.rb} | 2 +- .../communication/block/template/datatable.rb | 2 +- .../block/template/datatable/element.rb | 5 ++ .../block/template/datatable/row.rb | 5 -- .../block/template/definition.rb | 2 +- .../block/template/definition/definition.rb | 4 -- .../block/template/definition/element.rb | 4 ++ .../communication/block/template/embed.rb | 2 + .../communication/block/template/file.rb | 21 +------- .../template/file/{file.rb => element.rb} | 3 +- .../communication/block/template/gallery.rb | 2 +- .../template/gallery/{image.rb => element.rb} | 2 +- .../communication/block/template/image.rb | 2 + .../block/template/key_figure.rb | 2 +- .../key_figure/{figure.rb => element.rb} | 2 +- .../block/template/organization_chart.rb | 2 +- .../{person.rb => element.rb} | 2 +- .../communication/block/template/partner.rb | 48 +------------------ .../communication/block/template/post.rb | 2 +- .../block/template/post/element.rb | 5 ++ .../communication/block/template/post/item.rb | 5 -- .../block/template/testimonial.rb | 2 +- .../{testimonial.rb => element.rb} | 2 +- .../communication/block/template/timeline.rb | 2 +- .../block/template/timeline/element.rb | 6 +++ .../block/template/timeline/timeline.rb | 6 --- 27 files changed, 43 insertions(+), 102 deletions(-) rename app/models/communication/block/template/call_to_action/{button.rb => element.rb} (52%) create mode 100644 app/models/communication/block/template/datatable/element.rb delete mode 100644 app/models/communication/block/template/datatable/row.rb delete mode 100644 app/models/communication/block/template/definition/definition.rb create mode 100644 app/models/communication/block/template/definition/element.rb rename app/models/communication/block/template/file/{file.rb => element.rb} (60%) rename app/models/communication/block/template/gallery/{image.rb => element.rb} (77%) rename app/models/communication/block/template/key_figure/{figure.rb => element.rb} (52%) rename app/models/communication/block/template/organization_chart/{person.rb => element.rb} (51%) create mode 100644 app/models/communication/block/template/post/element.rb delete mode 100644 app/models/communication/block/template/post/item.rb rename app/models/communication/block/template/testimonial/{testimonial.rb => element.rb} (55%) create mode 100644 app/models/communication/block/template/timeline/element.rb delete mode 100644 app/models/communication/block/template/timeline/timeline.rb diff --git a/app/models/communication/block/template/call_to_action.rb b/app/models/communication/block/template/call_to_action.rb index a16e87e65..b29315d66 100644 --- a/app/models/communication/block/template/call_to_action.rb +++ b/app/models/communication/block/template/call_to_action.rb @@ -1,11 +1,12 @@ class Communication::Block::Template::CallToAction < Communication::Block::Template::Base + has_elements has_component :text, :rich_text has_component :image, :image has_component :alt, :string has_component :credit, :rich_text - has_elements Communication::Block::Template::CallToAction::Button + protected def check_accessibility super diff --git a/app/models/communication/block/template/call_to_action/button.rb b/app/models/communication/block/template/call_to_action/element.rb similarity index 52% rename from app/models/communication/block/template/call_to_action/button.rb rename to app/models/communication/block/template/call_to_action/element.rb index bfb78c82e..91db73134 100644 --- a/app/models/communication/block/template/call_to_action/button.rb +++ b/app/models/communication/block/template/call_to_action/element.rb @@ -1,4 +1,4 @@ -class Communication::Block::Template::CallToAction::Button < Communication::Block::Template::Base +class Communication::Block::Template::CallToAction::Element < Communication::Block::Template::Base has_component :title, :string has_component :url, :string diff --git a/app/models/communication/block/template/datatable.rb b/app/models/communication/block/template/datatable.rb index f40d97f26..a6f3d5ec3 100644 --- a/app/models/communication/block/template/datatable.rb +++ b/app/models/communication/block/template/datatable.rb @@ -1,6 +1,6 @@ class Communication::Block::Template::Datatable < Communication::Block::Template::Base - has_elements Communication::Block::Template::Datatable::Row + has_elements has_component :columns, :array has_component :caption, :text diff --git a/app/models/communication/block/template/datatable/element.rb b/app/models/communication/block/template/datatable/element.rb new file mode 100644 index 000000000..d6d786a73 --- /dev/null +++ b/app/models/communication/block/template/datatable/element.rb @@ -0,0 +1,5 @@ +class Communication::Block::Template::Datatable::Element < Communication::Block::Template::Base + + has_component :cells, :array + +end diff --git a/app/models/communication/block/template/datatable/row.rb b/app/models/communication/block/template/datatable/row.rb deleted file mode 100644 index 6563744ec..000000000 --- a/app/models/communication/block/template/datatable/row.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Communication::Block::Template::Datatable::Row < Communication::Block::Template::Base - - has_component :cells, :array - -end diff --git a/app/models/communication/block/template/definition.rb b/app/models/communication/block/template/definition.rb index 24239084f..5b444b404 100644 --- a/app/models/communication/block/template/definition.rb +++ b/app/models/communication/block/template/definition.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::Definition < Communication::Block::Template::Base - has_elements Communication::Block::Template::Definition::Definition + has_elements end diff --git a/app/models/communication/block/template/definition/definition.rb b/app/models/communication/block/template/definition/definition.rb deleted file mode 100644 index 350a8b3e4..000000000 --- a/app/models/communication/block/template/definition/definition.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Communication::Block::Template::Definition::Definition < Communication::Block::Template::Base - has_component :title, :string - has_component :description, :text -end diff --git a/app/models/communication/block/template/definition/element.rb b/app/models/communication/block/template/definition/element.rb new file mode 100644 index 000000000..4372d6b95 --- /dev/null +++ b/app/models/communication/block/template/definition/element.rb @@ -0,0 +1,4 @@ +class Communication::Block::Template::Definition::Element < Communication::Block::Template::Base + has_component :title, :string + has_component :description, :text +end diff --git a/app/models/communication/block/template/embed.rb b/app/models/communication/block/template/embed.rb index 8f48cc8f3..e71ed4a89 100644 --- a/app/models/communication/block/template/embed.rb +++ b/app/models/communication/block/template/embed.rb @@ -4,6 +4,8 @@ class Communication::Block::Template::Embed < Communication::Block::Template::Ba has_component :iframe_title, :string has_component :transcription, :text + protected + def check_accessibility super accessibility_error 'accessibility.blocks.templates.embed.title_missing' if iframe_title.blank? diff --git a/app/models/communication/block/template/file.rb b/app/models/communication/block/template/file.rb index f998126bc..44322dc71 100644 --- a/app/models/communication/block/template/file.rb +++ b/app/models/communication/block/template/file.rb @@ -1,24 +1,5 @@ class Communication::Block::Template::File < Communication::Block::Template::Base - def build_git_dependencies - files.each do |file| - add_dependency file.blob - end - end - - def files - @files ||= elements.map { |element| - file(element) - }.compact - end - - protected - - def file(element) - { - title: element['title'], - blob: find_blob(element, 'file') - }.to_dot - end + has_elements end diff --git a/app/models/communication/block/template/file/file.rb b/app/models/communication/block/template/file/element.rb similarity index 60% rename from app/models/communication/block/template/file/file.rb rename to app/models/communication/block/template/file/element.rb index 107bbc403..7c14df5ac 100644 --- a/app/models/communication/block/template/file/file.rb +++ b/app/models/communication/block/template/file/element.rb @@ -1,5 +1,6 @@ class Communication::Block::Template::File::File < Communication::Block::Template::Base - has_string :title + has_component :title, :string + has_component :file, :file end diff --git a/app/models/communication/block/template/gallery.rb b/app/models/communication/block/template/gallery.rb index 0fef23ebf..572169bcc 100644 --- a/app/models/communication/block/template/gallery.rb +++ b/app/models/communication/block/template/gallery.rb @@ -1,6 +1,6 @@ class Communication::Block::Template::Gallery < Communication::Block::Template::Base + has_elements has_layouts [:grid, :carousel] - has_elements Communication::Block::Template::Gallery::Image end diff --git a/app/models/communication/block/template/gallery/image.rb b/app/models/communication/block/template/gallery/element.rb similarity index 77% rename from app/models/communication/block/template/gallery/image.rb rename to app/models/communication/block/template/gallery/element.rb index 2761a441b..ada521ad4 100644 --- a/app/models/communication/block/template/gallery/image.rb +++ b/app/models/communication/block/template/gallery/element.rb @@ -1,4 +1,4 @@ -class Communication::Block::Template::Gallery::Image < Communication::Block::Template::Base +class Communication::Block::Template::Gallery::Element < Communication::Block::Template::Base has_component :image, :image has_component :alt, :string has_component :credit, :rich_text diff --git a/app/models/communication/block/template/image.rb b/app/models/communication/block/template/image.rb index ea534a890..fa80f4866 100644 --- a/app/models/communication/block/template/image.rb +++ b/app/models/communication/block/template/image.rb @@ -5,6 +5,8 @@ class Communication::Block::Template::Image < Communication::Block::Template::Ba has_component :credit, :rich_text has_component :text, :text + protected + def check_accessibility super accessibility_warning 'accessibility.commons.alt.empty' if image_component.blob && alt.blank? diff --git a/app/models/communication/block/template/key_figure.rb b/app/models/communication/block/template/key_figure.rb index 14b92d39d..a7baeb675 100644 --- a/app/models/communication/block/template/key_figure.rb +++ b/app/models/communication/block/template/key_figure.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::KeyFigure < Communication::Block::Template::Base - has_elements Communication::Block::Template::KeyFigure::Figure + has_elements end diff --git a/app/models/communication/block/template/key_figure/figure.rb b/app/models/communication/block/template/key_figure/element.rb similarity index 52% rename from app/models/communication/block/template/key_figure/figure.rb rename to app/models/communication/block/template/key_figure/element.rb index 24c22f2ba..d7409a874 100644 --- a/app/models/communication/block/template/key_figure/figure.rb +++ b/app/models/communication/block/template/key_figure/element.rb @@ -1,4 +1,4 @@ -class Communication::Block::Template::KeyFigure::Figure < Communication::Block::Template::Base +class Communication::Block::Template::KeyFigure::Element < Communication::Block::Template::Base has_component :number, :number has_component :unit, :string diff --git a/app/models/communication/block/template/organization_chart.rb b/app/models/communication/block/template/organization_chart.rb index 2788206cd..42901e89c 100644 --- a/app/models/communication/block/template/organization_chart.rb +++ b/app/models/communication/block/template/organization_chart.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::OrganizationChart < Communication::Block::Template::Base - has_elements Communication::Block::Template::OrganizationChart::Person + has_elements end diff --git a/app/models/communication/block/template/organization_chart/person.rb b/app/models/communication/block/template/organization_chart/element.rb similarity index 51% rename from app/models/communication/block/template/organization_chart/person.rb rename to app/models/communication/block/template/organization_chart/element.rb index 265a20f80..962ce80e4 100644 --- a/app/models/communication/block/template/organization_chart/person.rb +++ b/app/models/communication/block/template/organization_chart/element.rb @@ -1,4 +1,4 @@ -class Communication::Block::Template::OrganizationChart::Person < Communication::Block::Template::Base +class Communication::Block::Template::OrganizationChart::Element < Communication::Block::Template::Base has_component :id, :person has_component :role, :string diff --git a/app/models/communication/block/template/partner.rb b/app/models/communication/block/template/partner.rb index 6d3b2d286..1644b17ae 100644 --- a/app/models/communication/block/template/partner.rb +++ b/app/models/communication/block/template/partner.rb @@ -1,51 +1,5 @@ class Communication::Block::Template::Partner < Communication::Block::Template::Base - has_elements Communication::Block::Template::Partner::Element + has_elements - - # def build_git_dependencies - # add_dependency active_storage_blobs - # add_dependency organizations - # organizations.each do |organization| - # add_dependency organization.active_storage_blobs - # end - # end - # - # def partners - # @partners ||= elements.map { |element| - # partner(element) - # }.compact - # end - - # def active_storage_blobs - # @active_storage_blobs ||= partners.map { |partner| - # partner.blob - # }.compact - # end - - # protected - - # def organizations - # @organizations ||= partners.map { |partner| - # partner.organization - # }.compact - # end - # - # def partner(element) - # # Init to have easy tests in the views and dependencies - # element['organization'] = nil - # element['blob'] = nil - # if element['id'] - # organization = university.organizations.find_by id: element['id'] - # if organization - # element['organization'] = organization - # element['name'] = organization.to_s - # element['url'] = organization.url - # element['blob'] = organization.logo&.blob - # end - # else - # element['blob'] = find_blob element, 'logo' - # end - # element.to_dot - # end end diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index 4b916b574..92b771aec 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -1,6 +1,6 @@ class Communication::Block::Template::Post < Communication::Block::Template::Base - has_elements Communication::Block::Template::Post::Item + has_elements has_component :mode, :option, options: [:all, :category, :selection] has_component :posts_quantity, :number, options: 3 has_component :category_id, :category diff --git a/app/models/communication/block/template/post/element.rb b/app/models/communication/block/template/post/element.rb new file mode 100644 index 000000000..acc20d9dd --- /dev/null +++ b/app/models/communication/block/template/post/element.rb @@ -0,0 +1,5 @@ +class Communication::Block::Template::Post::Element < Communication::Block::Template::Base + + has_component :id, :post + +end diff --git a/app/models/communication/block/template/post/item.rb b/app/models/communication/block/template/post/item.rb deleted file mode 100644 index be25c4cfb..000000000 --- a/app/models/communication/block/template/post/item.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Communication::Block::Template::Post::Item < Communication::Block::Template::Base - - has_component :id, :post - -end diff --git a/app/models/communication/block/template/testimonial.rb b/app/models/communication/block/template/testimonial.rb index 70e9d7026..89a595b7a 100644 --- a/app/models/communication/block/template/testimonial.rb +++ b/app/models/communication/block/template/testimonial.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::Testimonial < Communication::Block::Template::Base - has_elements Communication::Block::Template::Testimonial::Testimonial + has_elements end diff --git a/app/models/communication/block/template/testimonial/testimonial.rb b/app/models/communication/block/template/testimonial/element.rb similarity index 55% rename from app/models/communication/block/template/testimonial/testimonial.rb rename to app/models/communication/block/template/testimonial/element.rb index 6750491ed..2a6d88653 100644 --- a/app/models/communication/block/template/testimonial/testimonial.rb +++ b/app/models/communication/block/template/testimonial/element.rb @@ -1,4 +1,4 @@ -class Communication::Block::Template::Testimonial::Testimonial < Communication::Block::Template::Base +class Communication::Block::Template::Testimonial::Element < Communication::Block::Template::Base has_component :text, :text has_component :author, :string diff --git a/app/models/communication/block/template/timeline.rb b/app/models/communication/block/template/timeline.rb index 03c0f668c..aa5759594 100644 --- a/app/models/communication/block/template/timeline.rb +++ b/app/models/communication/block/template/timeline.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::Timeline < Communication::Block::Template::Base - has_elements Communication::Block::Template::Timeline::Timeline + has_elements end diff --git a/app/models/communication/block/template/timeline/element.rb b/app/models/communication/block/template/timeline/element.rb new file mode 100644 index 000000000..a928b630f --- /dev/null +++ b/app/models/communication/block/template/timeline/element.rb @@ -0,0 +1,6 @@ +class Communication::Block::Template::Timeline::Element < Communication::Block::Template::Base + + has_component :title, :string + has_component :text, :text + +end diff --git a/app/models/communication/block/template/timeline/timeline.rb b/app/models/communication/block/template/timeline/timeline.rb deleted file mode 100644 index f1d0faae8..000000000 --- a/app/models/communication/block/template/timeline/timeline.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Communication::Block::Template::Timeline::Timeline < Communication::Block::Template::Base - - has_component :title, :string - has_component :text, :text - -end -- GitLab