diff --git a/app/models/communication/block/template/file.rb b/app/models/communication/block/template/file.rb index b1172690ac667596f1ad5570913d6c3d95480ec8..f998126bc6664f2d7a79af443486d5ed627188db 100644 --- a/app/models/communication/block/template/file.rb +++ b/app/models/communication/block/template/file.rb @@ -1,4 +1,5 @@ class Communication::Block::Template::File < Communication::Block::Template::Base + def build_git_dependencies files.each do |file| add_dependency file.blob @@ -19,4 +20,5 @@ class Communication::Block::Template::File < Communication::Block::Template::Bas blob: find_blob(element, 'file') }.to_dot end + end diff --git a/app/models/communication/block/template/file/file.rb b/app/models/communication/block/template/file/file.rb new file mode 100644 index 0000000000000000000000000000000000000000..107bbc40355d9cc016a37c1f247850078ff53909 --- /dev/null +++ b/app/models/communication/block/template/file/file.rb @@ -0,0 +1,5 @@ +class Communication::Block::Template::File::File < Communication::Block::Template::Base + + has_string :title + +end diff --git a/app/models/communication/block/template/organization_chart.rb b/app/models/communication/block/template/organization_chart.rb index 2788206cdc24127689f90796eedde358d51a5b4f..8b06c00ad4c5a50bc2972e3ec9df324717bbae1b 100644 --- a/app/models/communication/block/template/organization_chart.rb +++ b/app/models/communication/block/template/organization_chart.rb @@ -1,5 +1,29 @@ class Communication::Block::Template::OrganizationChart < Communication::Block::Template::Base - has_elements Communication::Block::Template::OrganizationChart::Person + def build_git_dependencies + add_dependency persons + persons.each do |person| + add_dependency person.active_storage_blobs + end + end + 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 similarity index 85% rename from app/models/communication/block/template/Organization_chart/person.rb rename to app/models/communication/block/template/organization_chart/person.rb index fcfdad2aec13c3126b71d3d8c93d788f868ecca0..687112b22bbbe0c3622c6975481671cd80dc075d 100644 --- a/app/models/communication/block/template/Organization_chart/person.rb +++ b/app/models/communication/block/template/organization_chart/person.rb @@ -1,6 +1,6 @@ class Communication::Block::Template::OrganizationChart::Person < Communication::Block::Template::Base - has_array :person + has_select :person has_string :role end diff --git a/app/views/admin/communication/blocks/templates/files/_edit.html.erb b/app/views/admin/communication/blocks/templates/files/_edit.html.erb index 69cf7d16c80f9e3d970203dfee69a9d88424ea53..4153e497d29f169388a87071811d16e9e933be4c 100644 --- a/app/views/admin/communication/blocks/templates/files/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/files/_edit.html.erb @@ -1,7 +1,6 @@ -<a class="<%= button_classes('mb-4') %>" - v-on:click="data.elements.push({title: '', file: {}})"> - <%= t '.add_file' %> -</a> +<% element = @block.template.default_element %> + +<%= block_component_add_element t('.add_file') %> <draggable :list="data.elements" handle=".dragHandle" class="row"> <div v-for="(element, index) in data.elements" class="col-md-4"> @@ -21,18 +20,8 @@ <div class="card-body"> <div class="d-flex"> <div class="flex-fill"> - <label class="form-label" - :for="'element-' + index + '-title'"><%= t '.title_label' %></label> - <input class="form-control mb-3" - v-model="element.title" - placeholder="<%= t '.title_placeholder' %>" - type="text" - :id="'element-' + index + '-title'" /> + <%= block_component_edit :title, template: element %> - <label class="form-label" - :for="'element-' + index + '-file'"> - <%= t '.file_label' %> - </label> <div v-if="element.file.id"> <p><b>{{ element.file.filename }}</b></p> <a class="btn btn-sm btn-danger mt-2" @@ -42,10 +31,7 @@ </a> </div> <div v-if="!element.file.id"> - <input class="form-control mb-4" - type="file" - @change="onFileImageChange( $event, element, 'file' )" - :id="'element-' + index + '-file'"> + <%= block_component_edit :file, template: element %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/files/_preview.html.erb b/app/views/admin/communication/blocks/templates/files/_preview.html.erb index 48e6bad1ff4411e5e3f139abddedd493eaa25213..51e24752029c892d95944b116d1b8d3a599b854f 100644 --- a/app/views/admin/communication/blocks/templates/files/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/files/_preview.html.erb @@ -1,7 +1,7 @@ <ul> - <% @block.template.files.each do |file| %> +<% @block.template.elements.each do |element| %> <% file.title ||= file.blob.filename if file.blob %> - <% if file.title + <% if file.title title = file.title elsif file.blob title = file.blob.filename @@ -16,4 +16,4 @@ <% end %> </li> <% end %> -</ul> \ No newline at end of file +</ul> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index d45e5773043a05f54508dd3b45144f4eb5d1fc00..dd0198880ec087301ace53cd621bd86e8ee15f1c 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -215,9 +215,12 @@ en: description: A list of downloadable files, mentioning their file size. edit: add_file: Add a file - file_label: File - title_label: Title - title_placeholder: Enter title here + element: + file: + label: File + title: + label: Title + placeholder: Enter title here remove_file: Remove a file gallery: description: A gallery of images, with an accessible description, a text and a credit for each image. diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 73b7cd21fcbe30909716b5e104f27d55a4f0d54d..7fd1777313ec1725ecf9960514c1b9338d867e30 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -221,9 +221,12 @@ fr: description: Une liste de fichiers téléchargeables, présentés avec leur poids. edit: add_file: Ajouter un fichier - file_label: Fichier - title_label: Titre - title_placeholder: Entrer le titre du fichier + element: + file: + label: Fichier + title: + label: Titre + placeholder: Entrer le titre du fichier remove_file: Supprimer le fichier gallery: description: Une galerie d'images, avec pour chaque image une description accessible, un texte et un crédit.