Allow saving a position when create a widget card

We are ensuring that only position field is rendered only on
non-header cards.

Note that we have 3 sections that use widget cards:
- Homepage (cards and header cards)
- Custompages (only have cards)
- Sdg Homepage (cards and header cards)
This commit is contained in:
taitus
2023-10-27 10:53:16 +02:00
parent 9dd10cac19
commit 6059aab674
8 changed files with 29 additions and 9 deletions

View File

@@ -45,7 +45,7 @@ module Admin::Widget::CardsActions
def allowed_params
[
:link_url, :button_text, :button_url, :alignment, :header, :columns,
:link_url, :button_text, :button_url, :alignment, :header, :columns, :order,
translation_params(Widget::Card),
image_attributes: image_attributes
]

View File

@@ -31,12 +31,12 @@
<div class="row">
<% unless card.header_or_sdg_header? %>
<div class="column">
<%= f.label :columns %>
<p class="help-text"><%= t("admin.site_customization.pages.cards.columns_help") %></p>
<div class="small-12 medium-4 large-2">
<%= f.select :columns, (1..12), label: false %>
</div>
<div class="small-12 medium-6 column">
<%= f.select :columns, (1..12), hint: t("admin.site_customization.pages.cards.columns_help") %>
</div>
<div class="small-12 medium-6 column">
<%= f.number_field :order, min: 1, hint: t("admin.site_customization.pages.cards.order_help") %>
</div>
<% end %>
</div>

View File

@@ -488,6 +488,7 @@ en:
link_text: Link text
link_url: Link URL
columns: Number of columns
order: Position
widget/card/translation:
label: Label (optional)
title: Title

View File

@@ -1648,6 +1648,7 @@ en:
create_card: Create card
no_cards: There are no cards.
columns_help: "Width of the card in number of columns. On mobile screens it's always a width of 100%."
order_help: "You can enter the position where this card will be shown."
create:
notice: "Card created successfully!"
update:

View File

@@ -488,6 +488,7 @@ es:
link_text: Texto del enlace
link_url: URL del enlace
columns: Número de columnas
order: Posición
widget/card/translation:
label: Etiqueta (opcional)
title: Título

View File

@@ -1648,6 +1648,7 @@ es:
create_card: Crear tarjeta
no_cards: No hay tarjetas.
columns_help: "Ancho de la tarjeta en número de columnas. En pantallas móviles siempre es un ancho del 100%."
order_help: "Puedes introducir la posición en la que se mostrará esta tarjeta."
create:
notice: "¡Tarjeta creada con éxito!"
update:

View File

@@ -11,7 +11,8 @@ describe "Cards", :admin do
fill_in "Title", with: "Card text"
fill_in "Description", with: "Card description"
fill_in "Link text", with: "Link text"
fill_in "widget_card_link_url", with: "consul.dev"
fill_in "Link URL", with: "consul.dev"
fill_in "Position", with: "12"
attach_image_to_card
click_button "Create card"
@@ -25,6 +26,7 @@ describe "Cards", :admin do
expect(page).to have_content "Card description"
expect(page).to have_content "Link text"
expect(page).to have_content "consul.dev"
expect(page).to have_css "td", exact_text: "12"
expect(page).to have_link "Show image", title: "clippy.jpg"
end
end
@@ -87,7 +89,8 @@ describe "Cards", :admin do
fill_in "Link text", with: "Link text updated"
end
fill_in "widget_card_link_url", with: "consul.dev updated"
fill_in "Link URL", with: "consul.dev updated"
fill_in "Position", with: "2"
click_button "Save card"
expect(page).to have_content "Card updated successfully"
@@ -101,6 +104,7 @@ describe "Cards", :admin do
expect(page).to have_content "Card description updated"
expect(page).to have_content "Link text updated"
expect(page).to have_content "consul.dev updated"
expect(page).to have_css "td", exact_text: "2"
end
end
end
@@ -125,6 +129,8 @@ describe "Cards", :admin do
visit admin_homepage_path
click_link "Create header"
expect(page).not_to have_field "Position"
fill_in "Label (optional)", with: "Header label"
fill_in "Title", with: "Header text"
fill_in "Description", with: "Header description"
@@ -174,10 +180,13 @@ describe "Cards", :admin do
fill_in "Title", with: "Card for a custom page"
fill_in "Link URL", with: "/any_path"
fill_in "Position", with: "12"
click_button "Create card"
expect(page).to have_current_path admin_site_customization_page_widget_cards_path(custom_page)
expect(page).to have_content "Card for a custom page"
expect(page).to have_content "12"
expect(page).to have_css "th", exact_text: "Position"
end
scenario "Show" do
@@ -239,12 +248,14 @@ describe "Cards", :admin do
within(".translatable-fields") do
fill_in "Title", with: "Updated title"
end
fill_in "Position", with: "2"
click_button "Save card"
expect(page).to have_current_path admin_site_customization_page_widget_cards_path(custom_page)
expect(page).to have_content "Updated title"
expect(page).not_to have_content "Original title"
expect(page).to have_css "td", exact_text: "2"
end
scenario "Destroy" do

View File

@@ -22,13 +22,17 @@ describe "SDG homepage configuration" do
click_link "Create planning card"
expect(page).to have_field "Number of columns"
expect(page).to have_field "Position"
within(".translatable-fields") { fill_in "Title", with: "My planning card" }
fill_in "Link URL", with: "/any_path"
fill_in "Position", with: "2"
click_button "Create card"
within(".planning-cards") do
expect(page).to have_content "My planning card"
expect(page).to have_css "th", exact_text: "Position"
expect(page).to have_css "td", exact_text: "2"
end
within(".sensitization-cards") do
@@ -57,6 +61,7 @@ describe "SDG homepage configuration" do
click_link "Create header"
expect(page).not_to have_field "Number of columns"
expect(page).not_to have_field "Position"
within(".translatable-fields") { fill_in "Title", with: "My header" }
fill_in "Link URL", with: "/any_path"