move up down fixes

This commit is contained in:
Torsten 2023-01-25 17:10:05 +02:00
parent 594f2b5dce
commit 75915b3fe2
4 changed files with 17 additions and 13 deletions

View File

@ -7,19 +7,19 @@ module Merged
fields :id , :index , :section_id fields :id , :index , :section_id
fields :text , :header, :image_name fields :text , :header, :image_name
def move_up
swap_index_with(next_card)
end
def change_name def change_name
pagename = section ? section.page.name : section_id.to_s pagename = section ? section.page.name : section_id.to_s
"#{pagename}:#{header}" "#{pagename}:#{header}"
end end
def move_down def move_up
swap_index_with(previous_card) swap_index_with(previous_card)
end end
def move_down
swap_index_with(next_card)
end
def previous_card def previous_card
section.cards.where(index: index - 1).first section.cards.where(index: index - 1).first
end end

View File

@ -42,11 +42,11 @@ module Merged
end end
def move_up def move_up
swap_index_with(next_section) swap_index_with(previous_section)
end end
def move_down def move_down
swap_index_with(previous_section) swap_index_with(next_section)
end end
def previous_section def previous_section

View File

@ -3,7 +3,8 @@
.text-3xl.font-bold.text-gray-900 .text-3xl.font-bold.text-gray-900
= @section.cards.length = @section.cards.length
Cards Cards
= link_to( "New Card" , merged.new_section_card_path(@section.id) , class: "p-2 border border-gray-200 bg-cyan-100 font-bold rounded-lg hover:bg-sky-100") = link_to( merged.new_section_card_path(@section.id) ) do
%button.button.change New Card
.xl:mx-auto{class: "max-w-[1920px]"} .xl:mx-auto{class: "max-w-[1920px]"}
= render_section( @section ) = render_section( @section )
@ -16,11 +17,11 @@
.p-2 .p-2
=link_to(merged.card_move_path(card.id , dir: :down)) do =link_to(merged.card_move_path(card.id , dir: :down)) do
%svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} %svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"}
%path{:d => "M8.25 6.75L12 3m0 0l3.75 3.75M12 3v18", "stroke-linecap" => "round", "stroke-linejoin" => "round"} %path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.p-2 .p-2
=link_to(merged.card_move_path(card.id , dir: :up)) do =link_to(merged.card_move_path(card.id , dir: :up)) do
%svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} %svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"}
%path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"} %path{:d => "M8.25 6.75L12 3m0 0l3.75 3.75M12 3v18", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.mt-6 .mt-6
.basis-full.mt-3 .basis-full.mt-3
@ -35,7 +36,10 @@
= simple_form_for( card , method: :patch ) do |f| = simple_form_for( card , method: :patch ) do |f|
= f.input :section_id , label: "move to section (on this page)" , include_blank: false , = f.input :section_id , label: "move to section (on this page)" , include_blank: false ,
collection: card_section_select(card) collection: card_section_select(card)
%button.button.change.mt-4{type: :submit} Move .flex.justify-between.mt-4
%button.button.change{type: :submit} Move
= link_to( merged.new_section_card_path(@section.id) ) do
.button.change New Card
.basis-80 .basis-80
-if card.image -if card.image

View File

@ -19,11 +19,11 @@
.p-2 .p-2
=link_to(merged.section_move_path(section.id , dir: :down)) do =link_to(merged.section_move_path(section.id , dir: :down)) do
%svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} %svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"}
%path{:d => "M8.25 6.75L12 3m0 0l3.75 3.75M12 3v18", "stroke-linecap" => "round", "stroke-linejoin" => "round"} %path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.p-2 .p-2
=link_to(merged.section_move_path(section.id , dir: :up)) do =link_to(merged.section_move_path(section.id , dir: :up)) do
%svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} %svg.w-6.h-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"}
%path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"} %path{:d => "M8.25 6.75L12 3m0 0l3.75 3.75M12 3v18", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.basis-full.mt-3 .basis-full.mt-3
Updated at: Updated at:
= distance_of_time_in_words_to_now(section.updated_at) = distance_of_time_in_words_to_now(section.updated_at)