Make checklist entries sortable by d&d
This commit is contained in:
parent
1e1d80a2c3
commit
7acc0559ae
10 changed files with 98 additions and 20 deletions
|
|
@ -3,13 +3,18 @@
|
|||
|
||||
<div id="<%= dom_id checklist_entry %>" class="hover-row py-1">
|
||||
<div class="d-flex">
|
||||
<div style="width: 56px">
|
||||
<%= button_to tag.i(class: "bi bi-arrow-down"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 #{"pe-3" if is_last } float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position + 1 }} unless is_last %>
|
||||
<%= button_to tag.i(class: "bi bi-arrow-up"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 pe-3 float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position - 1 }} unless is_first %>
|
||||
<i class="bi bi-grip-vertical text-secondary mt-2"></i>
|
||||
<div style="">
|
||||
<% button_to tag.i(class: "bi bi-arrow-down"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 #{"pe-3" if is_last } float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position + 1 }} unless is_last %>
|
||||
<% button_to tag.i(class: "bi bi-arrow-up"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 pe-3 float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position - 1 }} unless is_first %>
|
||||
</div>
|
||||
<div class="d-inline-flex flex-grow-1">
|
||||
<%# checklist_entry.position %>
|
||||
<%= link_to([checklist_entry.position, checklist_entry.check.display_label].join(" "), checklist_entry.check, data: { turbo_frame: "_top" }, class: "flex-grow-1") %>
|
||||
|
||||
<span class="flex-grow-1 mt-2">
|
||||
<%= checklist_entry.check.display_label %>
|
||||
</span>
|
||||
<%= link_to(tag.id(class: "bi bi-search"), checklist_entry.check, data: { turbo_frame: "_top" }, class: "btn btn-link") %>
|
||||
<%= button_to tag.i(class: "bi bi-trash"), checklist_entry_path(checklist_entry), method: :delete, class: "btn btn-link" %>
|
||||
<%= link_to tag.i(class: "bi bi-pencil"), edit_checklist_entry_path(checklist_entry), class: "btn btn-link" %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<div id="<%= dom_id checklist_entry %>">
|
||||
<%= bootstrap_form_with(model: checklist_entry, layout: :horizontal) do |form| %>
|
||||
<%= link_to "Abbrechen", checklist_entry.persisted? ? checklist_entry : checklist_entry.checklist, class: "btn btn-outline-secondary float-end", data: { turbo_frame: "checklist_entries" } %>
|
||||
<%= form.submit class: "btn btn-secondary float-end me-2" %>
|
||||
<%= form.hidden_field :checklist_id %>
|
||||
<%= form.collection_select :check_id, Check.all.order(:name_de), :id, :name_de %>
|
||||
<%= form.collection_select :check_id, Check.all.order(:external_number), :id, :display_label %>
|
||||
<%# form.number_field :position %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
1
app/views/checklist_entries/update.turbo_stream.erb
Normal file
1
app/views/checklist_entries/update.turbo_stream.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
<%== @checklist_entry.checklist.checklist_entries.map { turbo_stream.update _1 }.join %>
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
<h1><i class="bi bi-card-checklist me-2"></i><%= "#{@checklist.name}" %></h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<%= render @checklist %>
|
||||
</div>
|
||||
<div class="col col-md-12">
|
||||
<div class="col col-12 col-lg-8">
|
||||
<div class="mt-3">
|
||||
<%= link_to tag.i(class: "bi bi-plus-lg"), new_checklist_entry_path(checklist_id: @checklist.id), class: "btn btn-primary float-end", data: { turbo_frame: "checklist_entries" } %>
|
||||
<h2>Checks</h2>
|
||||
|
|
@ -14,13 +11,18 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<%= turbo_frame_tag "checklist_entries" do %>
|
||||
<% @checklist.checklist_entries.each do |entry| %>
|
||||
<%= turbo_frame_tag dom_id(entry, :frame) do %>
|
||||
<%= render entry %>
|
||||
<div data-controller="drag">
|
||||
<% @checklist.checklist_entries.each do |entry| %>
|
||||
<%= turbo_frame_tag dom_id(entry, :frame), data: { id: entry.id, "sortable-url": url_for(entry) } do %>
|
||||
<%= render entry %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= tag.i "Es sind keine Checks zugewiesen." if @checklist.empty? %>
|
||||
<% end %>
|
||||
<%= tag.i "Es sind keine Checks zugewiesen." if @checklist.empty? %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-12 col-lg-4">
|
||||
<%= render @checklist %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue