fix remove image for card and section

This commit is contained in:
Torsten 2023-01-02 22:52:01 +02:00
parent 42ff77b70c
commit 693d121c0f
6 changed files with 56 additions and 13 deletions

View File

@ -8,8 +8,9 @@ module Merged
def set_image
@card.image_id = params[:image_id].to_i
@card.save
redirect_to section_cards_url(@card.section.id) , notice: "Image selected: #{@card.image.name}"
@card.edit_save(current_member.email)
message = @card.image ? "#{@card.image.name} selected" : "Image removed"
redirect_to section_cards_url(@card.section.id) , notice: message
end
def move

View File

@ -34,7 +34,8 @@ module Merged
def set_image
@section.image_id = params[:image_id].to_i
@section.edit_save(current_member.email)
redirect_to section_url(@section.id) , notice: "Image selected: #{@section.image.name}"
message = @section.image ? "#{@section.image.name} selected" : "Image removed"
redirect_to section_url(@section.id) , notice: message
end
def set_template

View File

@ -21,7 +21,7 @@
= form_tag( merged.card_path(card.id) , {method: :delete } ) do
=submit_button( "Delete" , true)
.p-4
%h3.mt-4.text-lg.font-bold Image
%h3.mt-4.text-lg.font-bold.image_button Image
= yellow_button("Change Image" , merged.images_path(card_id: card.id) )
= red_button("Remove image", merged.card_set_image_path( card.id , image: "") )
.basis-full.mt-3
@ -42,7 +42,7 @@
= card.image.aspect_ratio
= image_for( card )
-else
%h3.mt-4.text-lg.font-bold No Image
%h3.mt-4.text-lg.font-bold No image
.basis-72.grow
%h3.mt-4.text-lg.font-bold Fields
= form_tag( merged.card_path(card.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do

View File

@ -19,14 +19,21 @@
Updated by:
= @section.updated_by
.basis-96
%h3.mt-4.text-lg.font-bold Image
-if( @section.image.blank? )
%p No image
.basis-96.image
= link_to(merged.images_path(section_id: @section.id)) do
-if @section.image
%h3.mt-4.text-lg.font-bold Image #{@section.image.name}
.flex.align-center.justify-between.mb-4
.text-lg.font-bold.mt-2.mx-2
= @section.image.size.to_s + "k"
%strong.inline-block.rounded.bg-yellow-200.px-3.py-1.text-md.font-medium
= @section.image.aspect_ratio
= image_for( @section )
-else
= image_for( @section , "my-3")
= yellow_button("Change Image", merged.images_path(section_id: @section.id))
= red_button( "Remove image", merged.section_set_image_path( @section.id , image: ""))
%h3.mt-4.text-lg.font-bold No Image
.flex
.mt-3= yellow_button("Change Image", merged.images_path(section_id: @section.id))
.mt-3= red_button( "Remove image", merged.section_set_image_path( @section.id , image: "")) if( @section.image )
.basis-80.grow.content_update
= section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do

View File

@ -25,4 +25,20 @@ class CardsTest < ActionDispatch::IntegrationTest
find_button("Update").click
end
end
class CardsWriteTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers # Rails >= 5
include Merged::Cleanup
def test_remove_image
visit "merged/sections/11/cards"
find_button("Remove image", match: :first).click
assert_equal 200 , page.status_code
end
def test_remove_image_force
visit "merged/cards/6/set_image?image=''"
assert_text page , "No image"
end
end
end

View File

@ -33,4 +33,22 @@ class SectionsTest < ActionDispatch::IntegrationTest
find_button("Update").click
end
end
class SectionsWriteTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers # Rails >= 5
include Merged::Cleanup
def test_remove_image
visit "merged/sections/31"
within(".image") do
click_button("Remove image")
end
assert_equal 200 , page.status_code
end
def test_remove_image_force
visit "merged/sections/31/set_image?image=''"
assert_text page , "No Image"
end
end
end