diff --git a/app/models/communication/block/component/array.rb b/app/models/communication/block/component/array.rb new file mode 100644 index 0000000000000000000000000000000000000000..019d1d0bb1987678ec015c0ab7dc2ee1487ff0df --- /dev/null +++ b/app/models/communication/block/component/array.rb @@ -0,0 +1,7 @@ +class Communication::Block::Component::Array < Communication::Block::Component::Base + + def default_data + [""] + end + +end diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index 05e735af7ce0f8e09cf70a1e5a732bef03a402e9..d03104ab97e4303cbde309dd2fda4d8eda78cc9c 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -29,6 +29,10 @@ class Communication::Block::Template::Base has_component property, :number end + def self.has_array(property) + has_component property, :array + end + def self.has_layouts(list) self.layouts = list has_component :layout, :layout diff --git a/app/models/communication/block/template/datatable.rb b/app/models/communication/block/template/datatable.rb index 579750d21f832a353b510161d432c324569914fe..d055a3da428beead7f1fa318d6922f70c5779a5f 100644 --- a/app/models/communication/block/template/datatable.rb +++ b/app/models/communication/block/template/datatable.rb @@ -1,4 +1,7 @@ class Communication::Block::Template::Datatable < Communication::Block::Template::Base - def build_git_dependencies - end + + has_array :columns + has_elements Communication::Block::Template::Datatable::Row + has_text :caption + end diff --git a/app/models/communication/block/template/datatable/row.rb b/app/models/communication/block/template/datatable/row.rb new file mode 100644 index 0000000000000000000000000000000000000000..67650ab89e3513c14e328ea4cea5dce576f56694 --- /dev/null +++ b/app/models/communication/block/template/datatable/row.rb @@ -0,0 +1,5 @@ +class Communication::Block::Template::Datatable::Row < Communication::Block::Template::Base + + has_array :cells + +end diff --git a/app/views/admin/communication/blocks/templates/datatable/_edit.html.erb b/app/views/admin/communication/blocks/templates/datatable/_edit.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6fc978ae4e48e4cc7db11d802b8ba0f599c40420 100644 --- a/app/views/admin/communication/blocks/templates/datatable/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/datatable/_edit.html.erb @@ -0,0 +1,69 @@ + + +<a class="<%= button_classes('mb-4 me-2') %>" + v-on:click="data.columns.pop(); data.elements.forEach(row => row.cells.pop());"> + Supprimer la dernière colonne +</a> + + +<div class="table-responsive mb-5"> + <table class="table table-striped table-hover"> + <thead> + <tr> + <td></td> + <td v-for="(column, index) in data.columns"> + <input + type="text" + v-model="data.columns[index]"> + <a class="btn btn-sm btn-danger ms-2" + v-on:click="data.columns.splice(index, 1); data.elements.forEach(row => row.cells.splice(index, 1));"> + <i class="fas fa-times"></i> + </a> + </td> + <td> + <a class="<%= button_classes("btn-sm") %>" + v-on:click="data.columns.push('')"> + <i class="fas fa-plus"></i> colonne + </a> + </td> + </tr> + </thead> + <tbody> + <draggable :list="data.elements" handle=".dragHandle"> + <tr v-for="(row, index) in data.elements"> + <td> + <a class="btn p-0 dragHandle"> + <i class="fa fa-bars handle"></i> + </a> + </td> + <td v-for="(column, columnIndex) in data.columns"> + <input + type="text" + v-model="row.cells[columnIndex]"> + </td> + <td> + <a class="btn btn-sm btn-danger" + v-on:click="data.elements.splice(index, 1);"> + <i class="fas fa-times"></i> + </a> + </td> + </tr> + </draggable> + </tbody> + </table> + <a class="<%= button_classes('btn-sm') %>" + v-on:click="data.elements.push({cells: []})"> + <i class="fas fa-plus"></i> ligne + </a> +</div> + + +<%= block_component_edit :caption, + label: "Transcription textuelle", + placeholder: "Écrivez-ici la transcription textuelle du tableau" %> + + +<%#= block_component_add_element "Ajouter une ligne" %> +<%# Comportement non attendu dans ce context %> + + diff --git a/app/views/admin/communication/blocks/templates/datatable/_preview.html.erb b/app/views/admin/communication/blocks/templates/datatable/_preview.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..86862043d97ec8231b43d9341d5ecefbf177a34e 100644 --- a/app/views/admin/communication/blocks/templates/datatable/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/datatable/_preview.html.erb @@ -0,0 +1,24 @@ +<div class="table-responsive"> + <table class="table"> + <thead> + <tr> + <% @block.template.columns.each do |column| %> + <td> + <%= column %> + </td> + <% end %> + </tr> + </thead> + <tbody> + <% @block.template.elements.each do |row| %> + <tr> + <% row.cells.each do |cell| %> + <td><%= cell %></td> + <% end %> + </tr> + <% end %> + </tbody> + </table> +</div> + +<%= block_component_preview :caption %> diff --git a/app/views/admin/communication/blocks/templates/datatable/_static.html.erb b/app/views/admin/communication/blocks/templates/datatable/_static.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a6147ad309d88721ca4f977cd00a3341c4e2dfa1 100644 --- a/app/views/admin/communication/blocks/templates/datatable/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/datatable/_static.html.erb @@ -0,0 +1,11 @@ + headers: +<% block.template.columns.each do |column| %> + - <%= column %> +<% end %> + rows: +<% block.template.elements.each do |element| %> +<% if element.cells.count > 0 %> + - ["<%= element.cells.join('", "').html_safe %>"] +<% end %> +<% end %> +<%= block_component_static :caption %> diff --git a/db/schema.rb b/db/schema.rb index 2b98e8d52f46d5b3a3882cf3ba22c24d00a3c7bb..45ca2a5032878221c9861fbfaf7fbb8b57ad814a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -502,23 +502,6 @@ ActiveRecord::Schema.define(version: 2022_05_30_094714) do t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "title" - t.text "description" - t.string "address" - t.string "zipcode" - t.string "city" - t.string "country" - t.string "website" - t.string "phone" - t.string "mail" - t.boolean "active" - t.string "sirene" - t.integer "kind" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - end - create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" @@ -713,8 +696,8 @@ ActiveRecord::Schema.define(version: 2022_05_30_094714) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.string "name" t.boolean "is_author" + t.string "name" t.integer "gender" t.date "birthdate" t.string "phone_professional"