diff --git a/app/models/communication/block/component/base.rb b/app/models/communication/block/component/base.rb index 4c65e7f07c07670aeee6c03038a8d788c91c6497..798e61e84c515baeb5cfc90984ece2ae4ac6b852 100644 --- a/app/models/communication/block/component/base.rb +++ b/app/models/communication/block/component/base.rb @@ -32,4 +32,8 @@ class Communication::Block::Component::Base def active_storage_blobs [] end + + def website + template.block.about&.website + end end diff --git a/app/models/communication/block/component/category.rb b/app/models/communication/block/component/category.rb index 1336a6d4ce61e68b1d98bc1db1952bef87a993ba..e11cd06a510ad83d50f96e73123fceada132d6c0 100644 --- a/app/models/communication/block/component/category.rb +++ b/app/models/communication/block/component/category.rb @@ -1,12 +1,16 @@ class Communication::Block::Component::Category < Communication::Block::Component::Base def category - return unless template.block.about&.website - template.block - .about - .website - .categories - .find_by(id: data) + return unless website + website.categories.find_by(id: data) end + def git_dependencies + active_storage_blobs + + [category] + end + + def active_storage_blobs + category&.active_storage_blobs || [] + end end diff --git a/app/models/communication/block/component/person.rb b/app/models/communication/block/component/person.rb new file mode 100644 index 0000000000000000000000000000000000000000..f15ddb44e81d5c29fcda98053e4b3e0001bd89ca --- /dev/null +++ b/app/models/communication/block/component/person.rb @@ -0,0 +1,7 @@ +class Communication::Block::Component::Person < Communication::Block::Component::Base + + def person + template.block.university.people.find_by(id: data) + end + +end diff --git a/app/models/communication/block/component/post.rb b/app/models/communication/block/component/post.rb index 964d25384df35ed975870dbfcefeda7852a8187c..0a653a7eaf991a0a89a29e5021cdbbee2006668b 100644 --- a/app/models/communication/block/component/post.rb +++ b/app/models/communication/block/component/post.rb @@ -1,11 +1,17 @@ class Communication::Block::Component::Post < Communication::Block::Component::Base def post - return if data.blank? - block.about&.website - .posts - .published - .find_by(id: data) + return unless website + website.posts.published.find_by(id: data) + end + + def git_dependencies + active_storage_blobs + + [post, post.author, post.author.author] + end + + def active_storage_blobs + post&.author&.active_storage_blobs || [] end end diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index d830701e2a0489dfb7f584e94dbd0bb86f8204b7..1cd430c1defafc2c16f5a97fbf3e1bcbb144e044 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -96,6 +96,7 @@ class Communication::Block::Template::Base elements.each do |element| add_dependency element.git_dependencies end + add_custom_git_dependencies @git_dependencies.uniq! end @git_dependencies @@ -166,6 +167,9 @@ class Communication::Block::Template::Base !self.class.element_class.nil? end + def add_custom_git_dependencies + end + def add_dependency(dependency) if dependency.is_a? Array @git_dependencies += dependency diff --git a/app/models/communication/block/template/organization_chart.rb b/app/models/communication/block/template/organization_chart.rb index 8b06c00ad4c5a50bc2972e3ec9df324717bbae1b..2788206cdc24127689f90796eedde358d51a5b4f 100644 --- a/app/models/communication/block/template/organization_chart.rb +++ b/app/models/communication/block/template/organization_chart.rb @@ -1,29 +1,5 @@ class Communication::Block::Template::OrganizationChart < Communication::Block::Template::Base - def build_git_dependencies - add_dependency persons - persons.each do |person| - add_dependency person.active_storage_blobs - end - end + has_elements Communication::Block::Template::OrganizationChart::Person - def persons_with_role - @persons_with_role ||= elements.map { |element| person_with_role(element) } - .compact - end - - protected - - def persons - @persons ||= persons_with_role.map { |hash| hash[:person] } - end - - def person_with_role(element) - person = block.university.people.find_by id: element['id'] - return if person.nil? - { - person: person, - role: element['role'] - }.to_dot - end end diff --git a/app/models/communication/block/template/organization_chart/person.rb b/app/models/communication/block/template/organization_chart/person.rb index 687112b22bbbe0c3622c6975481671cd80dc075d..265a20f8034690d06bb922cd1a6436dc1700f42f 100644 --- a/app/models/communication/block/template/organization_chart/person.rb +++ b/app/models/communication/block/template/organization_chart/person.rb @@ -1,6 +1,9 @@ class Communication::Block::Template::OrganizationChart::Person < Communication::Block::Template::Base - has_select :person - has_string :role + has_component :id, :person + has_component :role, :string + def person + id_component.person + end end diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index 32d5f9b9649ed8331bb9e946a6b3cbc02232f29d..4b916b574bc5ef600d29093cdd909e65af61fcfa 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -5,10 +5,9 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas has_component :posts_quantity, :number, options: 3 has_component :category_id, :category - def build_git_dependencies - add_dependency category unless category.nil? - add_dependency selected_posts + def add_custom_git_dependencies selected_posts.each do |post| + add_dependency post add_dependency post.active_storage_blobs if post.author.present? add_dependency [post.author, post.author.author] diff --git a/app/views/admin/communication/blocks/components/category/_static.html.erb b/app/views/admin/communication/blocks/components/category/_static.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a871dde97f687b000c6124e9bf75784cdd148d18 100644 --- a/app/views/admin/communication/blocks/components/category/_static.html.erb +++ b/app/views/admin/communication/blocks/components/category/_static.html.erb @@ -0,0 +1 @@ +<%= indentation %><%= '- ' if list %><%= property %>: <%= value %> diff --git a/app/views/admin/communication/blocks/components/person/_edit.html.erb b/app/views/admin/communication/blocks/components/person/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..679a74a4382d3530e09c1e8decc367a591f7b4e0 --- /dev/null +++ b/app/views/admin/communication/blocks/components/person/_edit.html.erb @@ -0,0 +1,19 @@ +<% +people = current_university.people.ordered +%> +<label class="form-label" + :for="<%= dom_id.html_safe %>"> + <%= label %> +</label> +<select :id="<%= dom_id.html_safe %>" + class="form-select select mb-3" + v-model="<%= model %>.<%= property %>"> + <% if placeholder %> + <option value="" disabled><%= placeholder %></option> + <% end %> + <% people.each do |person| %> + <option value="<%= person.id %>"> + <%= person.last_name %>, <%= person.first_name %> + </option> + <% end %> +</select> diff --git a/app/views/admin/communication/blocks/components/person/_preview.html.erb b/app/views/admin/communication/blocks/components/person/_preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c6c01864d09367e1dcb7a8c76029632aec899b7b --- /dev/null +++ b/app/views/admin/communication/blocks/components/person/_preview.html.erb @@ -0,0 +1 @@ +<%= component.person.to_s %> diff --git a/app/views/admin/communication/blocks/components/person/_static.html.erb b/app/views/admin/communication/blocks/components/person/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a871dde97f687b000c6124e9bf75784cdd148d18 --- /dev/null +++ b/app/views/admin/communication/blocks/components/person/_static.html.erb @@ -0,0 +1 @@ +<%= indentation %><%= '- ' if list %><%= property %>: <%= value %> diff --git a/app/views/admin/communication/blocks/components/post/_static.html.erb b/app/views/admin/communication/blocks/components/post/_static.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a871dde97f687b000c6124e9bf75784cdd148d18 100644 --- a/app/views/admin/communication/blocks/components/post/_static.html.erb +++ b/app/views/admin/communication/blocks/components/post/_static.html.erb @@ -0,0 +1 @@ +<%= indentation %><%= '- ' if list %><%= property %>: <%= value %> diff --git a/app/views/admin/communication/blocks/templates/organization_chart/_edit.html.erb b/app/views/admin/communication/blocks/templates/organization_chart/_edit.html.erb index 92589f172f189f884c6a2ad7598b5e35b98776d5..a4925d7246972152572cc98cb5fd97c8c275a4f4 100644 --- a/app/views/admin/communication/blocks/templates/organization_chart/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/organization_chart/_edit.html.erb @@ -1,4 +1,3 @@ -<% element = @block.template.default_element %> <%= block_component_add_element t('.add_person') %> <draggable :list="data.elements" class="list-group" handle=".dragHandle"> @@ -10,21 +9,12 @@ </a> </div> <div class="flex-fill"> - <div class="row"> + <div class="row mb-n2"> <div class="col-md-6"> - <label class="form-label visually-hidden" - :for="'person-' + index + '-name'"><%= t '.person_label' %></label> - <select :id="'person-' + index + '-name'" - class="form-select select" - v-model="person.id"> - <option value="" disabled><%= t '.person_placeholder' %></option> - <% current_university.people.ordered.each_with_index do |person, index| %> - <option value="<%= person.id %>"><%= person.last_name %>, <%= person.first_name %></option> - <% end %> - </select> + <%= block_component_edit :id, template: @element %> </div> <div class="col-md-6"> - <%= block_component_edit :role, template: element %> + <%= block_component_edit :role, template: @element %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/organization_chart/_preview.html.erb b/app/views/admin/communication/blocks/templates/organization_chart/_preview.html.erb index 1ba8ba5a07ea9f15432677b2ab1db74cf3521431..08c110324918ce581c646538efb9861b4299e09d 100644 --- a/app/views/admin/communication/blocks/templates/organization_chart/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/organization_chart/_preview.html.erb @@ -1,5 +1,7 @@ -<% @block.template.persons_with_role.each do |person_with_role| - person = person_with_role.person %> +<% @block.template.elements.each do |element| + person = element.person + next if person.nil? + %> <article class="card"> <div class="card-body"> <% if person.best_picture.attached? %> @@ -9,7 +11,7 @@ </div> <% end %> <h3 class="card-title h5"><%= link_to person, [:admin, person] %></h3> - <p class="mb-0"><%= person_with_role.role %></p> + <p class="mb-0"><%= element.role %></p> </div> </article> <% end %> diff --git a/app/views/admin/communication/blocks/templates/organization_chart/_static.html.erb b/app/views/admin/communication/blocks/templates/organization_chart/_static.html.erb index 95c784ff68ace980e99b7ea580936961906298c3..6ed1e765f9fb862745a1c2b28702a75aec9cb613 100644 --- a/app/views/admin/communication/blocks/templates/organization_chart/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/organization_chart/_static.html.erb @@ -1,7 +1,5 @@ -<% -block.template.persons_with_role.each do |person_with_role| - person = person_with_role.person %> - - slug: "<%= person.slug %>" - role: >- - <%= prepare_text_for_static person_with_role.role, 5 %> +<% block.template.elements.each do |element| %> +<% next unless element.person %> +<%= block_component_static :id, template: element, depth: 4, list: true %> +<%= block_component_static :role, template: element, depth: 5 %> <% end %> diff --git a/app/views/admin/communication/blocks/templates/posts/_static.html.erb b/app/views/admin/communication/blocks/templates/posts/_static.html.erb index 7523029450a1e5ca3d893481bcf733d8f8c9b293..69055c1981cac86b047e7796cf5c426483b6da12 100644 --- a/app/views/admin/communication/blocks/templates/posts/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_static.html.erb @@ -3,5 +3,5 @@ <% end %> posts: <% block.template.selected_posts.each do |post| %> - - <%= post.static_path %> + - "<%= post.static_path %>" <% end %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 30132f5fb59488ab9d7129c71500cd86a0186c4f..30aa26e4f57137e07a3c51398e9bf7f3443c1a64 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -276,7 +276,7 @@ fr: edit: add_person: Ajouter une personne element: - person: + id: label: Personne placeholder: Choisir la personne role: