From bd47bcdba4b162fe5bb74b86fca4dbdd182c44a8 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 26 Jul 2022 21:23:42 +0200 Subject: [PATCH] better --- .../communication/block/component/time_slot.rb | 16 ++++++++++++++++ app/models/communication/website/with_style.rb | 3 ++- .../components/time_slot/_preview.html.erb | 4 +++- .../blocks/templates/contact/_edit.html.erb | 12 +++++++++--- .../blocks/templates/contact/_preview.html.erb | 16 ++++++++++++++++ .../blocks/templates/programs/_preview.html.erb | 5 +++++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/models/communication/block/component/time_slot.rb b/app/models/communication/block/component/time_slot.rb index 4b1a65555..168dba1ed 100644 --- a/app/models/communication/block/component/time_slot.rb +++ b/app/models/communication/block/component/time_slot.rb @@ -1,5 +1,21 @@ class Communication::Block::Component::TimeSlot < Communication::Block::Component::Base + def from + data['from'] + end + + def to + data['to'] + end + + def present? + from && from != '0' && to && to != '0' + end + + def blank? + !present? + end + def default_data { 'from' => '0', diff --git a/app/models/communication/website/with_style.rb b/app/models/communication/website/with_style.rb index 831c7c4c7..3d5172b77 100644 --- a/app/models/communication/website/with_style.rb +++ b/app/models/communication/website/with_style.rb @@ -2,7 +2,6 @@ module Communication::Website::WithStyle extend ActiveSupport::Concern def preview_style - return '' if url.blank? load_style if style_outdated? style end @@ -14,6 +13,7 @@ module Communication::Website::WithStyle load_style_from url load_style_from "#{url}/fr" if @style.blank? load_style_from "#{url}/en" if @style.blank? + load_style_from "https://example.osuny.org" if @style.blank? substitute_fonts_urls_in_style! self.update_columns style: @style, style_updated_at: Date.today @@ -26,6 +26,7 @@ module Communication::Website::WithStyle css_files.each do |css_url| add_css_url_to_style css_url.to_s end + rescue end def add_css_url_to_style(css_url) diff --git a/app/views/admin/communication/blocks/components/time_slot/_preview.html.erb b/app/views/admin/communication/blocks/components/time_slot/_preview.html.erb index b8c9c330c..3377599ea 100644 --- a/app/views/admin/communication/blocks/components/time_slot/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/time_slot/_preview.html.erb @@ -1 +1,3 @@ -<%= simple_format value %> +<% if component.present? %> + <%= component.from %> → <%= component.to %> +<% end %> diff --git a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb index 1ab0305c4..7ae6dd83c 100644 --- a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb @@ -2,9 +2,15 @@ <div class="col-md-6 col-xl-4"> <h3 class="h4"><%= t '.contacts' %></h3> <%= block_component_edit :name %> - <%= block_component_edit :address %> - <%= block_component_edit :zipcode %> - <%= block_component_edit :city %> + <%= block_component_edit :address, rows: 1 %> + <div class="row"> + <div class="col-md-4"> + <%= block_component_edit :zipcode %> + </div> + <div class="col-md-8"> + <%= block_component_edit :city %> + </div> + </div> <%= block_component_edit :country %> </div> <div class="col-md-6 col-xl-8"> diff --git a/app/views/admin/communication/blocks/templates/contact/_preview.html.erb b/app/views/admin/communication/blocks/templates/contact/_preview.html.erb index e69de29bb..83caa0c2c 100644 --- a/app/views/admin/communication/blocks/templates/contact/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/contact/_preview.html.erb @@ -0,0 +1,16 @@ +<p><%= block_component_preview :name %></p> +<div> + <%= block_component_preview :address %> + <%= block_component_preview :zipcode %> + <%= block_component_preview :city %> + <%= block_component_preview :country %> +</div> +<table class="table"> +<% @block.template.elements.each do |element| %> + <tr> + <td><%= block_component_preview :title, template: element %></td> + <td><%= block_component_preview :time_slot_morning, template: element %></td> + <td><%= block_component_preview :time_slot_afternoon, template: element %></td> + </tr> +<% end %> +</table> \ No newline at end of file diff --git a/app/views/admin/communication/blocks/templates/programs/_preview.html.erb b/app/views/admin/communication/blocks/templates/programs/_preview.html.erb index e69de29bb..b32f9129e 100644 --- a/app/views/admin/communication/blocks/templates/programs/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/programs/_preview.html.erb @@ -0,0 +1,5 @@ +<hr> +<% @block.template.selected_programs.each do |program| %> + <p><%= program %></p> + <hr> +<% end %> \ No newline at end of file -- GitLab