Add label to cards

Also removes unused fields related to buttons and alignment
This commit is contained in:
rgarcia
2018-05-24 18:38:32 +02:00
committed by decabeza
parent eaebf349df
commit ad181b0e10
10 changed files with 44 additions and 29 deletions

View File

@@ -39,7 +39,7 @@ class Admin::Widget::CardsController < Admin::BaseController
private private
def card_params def card_params
params.require(:widget_card).permit(:title, :description, :link_text, :link_url, params.require(:widget_card).permit(:label, :title, :description, :link_text, :link_url,
:button_text, :button_url, :alignment, :header, :button_text, :button_url, :alignment, :header,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end end

View File

@@ -1,5 +1,8 @@
<tr id="<%= dom_id(card) %>" class="card"> <tr id="<%= dom_id(card) %>" class="card">
<td><%= card.title %></td> <td>
<%= card.label %><br>
<%= card.title %>
</td>
<td><%= card.description %></td> <td><%= card.description %></td>
<td> <td>
<%= card.link_text %><br> <%= card.link_text %><br>

View File

@@ -1,4 +1,8 @@
<%= form_for [:admin, @card] do |f| %> <%= form_for [:admin, @card] do |f| %>
<div class="small-12 medium-6">
<%= f.text_field :label %>
</div>
<%= f.text_field :title %> <%= f.text_field :title %>
<%= f.text_area :description, rows: 5 %> <%= f.text_area :description, rows: 5 %>

View File

@@ -5,7 +5,7 @@
<%= image_tag(card.image_url(:large), alt: card.image.title) %> <%= image_tag(card.image_url(:large), alt: card.image.title) %>
<% end %> <% end %>
<figcaption> <figcaption>
<span>LABEL</span><br> <span><%= card.label %></span><br>
<h3><%= card.title %></h3> <h3><%= card.title %></h3>
</figcaption> </figcaption>
</figure> </figure>

View File

@@ -246,6 +246,7 @@ en:
from: From from: From
body: Email content body: Email content
widget/card: widget/card:
label: Label
title: Title title: Title
description: Description description: Description
link_text: Link text link_text: Link text

View File

@@ -242,6 +242,7 @@ es:
from: Enviado por from: Enviado por
body: Contenido del email body: Contenido del email
widget/card: widget/card:
label: Etiqueta
title: Título title: Título
description: Descripción description: Descripción
link_text: Texto del enlace link_text: Texto del enlace

View File

@@ -5,10 +5,8 @@ class CreateWidgetCards < ActiveRecord::Migration
t.text :description t.text :description
t.string :link_text t.string :link_text
t.string :link_url t.string :link_url
t.string :button_text t.string :label
t.string :button_url
t.boolean :header, default: false t.boolean :header, default: false
t.string :alignment
t.timestamps null: false t.timestamps null: false
end end
end end

View File

@@ -1231,10 +1231,8 @@ ActiveRecord::Schema.define(version: 20180519132715) do
t.text "description" t.text "description"
t.string "link_text" t.string "link_text"
t.string "link_url" t.string "link_url"
t.string "button_text" t.string "label"
t.string "button_url"
t.boolean "header", default: false t.boolean "header", default: false
t.string "alignment"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end

View File

@@ -76,33 +76,37 @@ feature 'Homepage' do
end end
scenario "Cards" do scenario "Cards" do
card1 = create(:widget_card, title: "Card text", card1 = create(:widget_card, label: "Card1 label",
description: "Card description", title: "Card1 text",
link_text: "Link text", description: "Card1 description",
link_url: "consul.dev") link_text: "Link1 text",
link_url: "consul1.dev")
card2 = create(:widget_card, title: "Card text2", card2 = create(:widget_card, label: "Card2 label",
description: "Card description2", title: "Card2 text",
link_text: "Link text2", description: "Card2 description",
link_url: "consul.dev2") link_text: "Link2 text",
link_url: "consul2.dev")
visit root_path visit root_path
expect(page).to have_css(".card", count: 2) expect(page).to have_css(".card", count: 2)
within("#widget_card_#{card1.id}") do within("#widget_card_#{card1.id}") do
expect(page).to have_content("Card text") expect(page).to have_content("Card1 label")
expect(page).to have_content("Card description") expect(page).to have_content("Card1 text")
expect(page).to have_content("Link text") expect(page).to have_content("Card1 description")
expect(page).to have_link(href: "consul.dev") expect(page).to have_content("Link1 text")
expect(page).to have_link(href: "consul1.dev")
expect(page).to have_css("img[alt='#{card1.image.title}']") expect(page).to have_css("img[alt='#{card1.image.title}']")
end end
within("#widget_card_#{card2.id}") do within("#widget_card_#{card2.id}") do
expect(page).to have_content("Card text2") expect(page).to have_content("Card2 label")
expect(page).to have_content("Card description2") expect(page).to have_content("Card2 text")
expect(page).to have_content("Link text2") expect(page).to have_content("Card2 description")
expect(page).to have_link(href: "consul.dev2") expect(page).to have_content("Link2 text")
expect(page).to have_link(href: "consul2.dev")
expect(page).to have_css("img[alt='#{card2.image.title}']") expect(page).to have_css("img[alt='#{card2.image.title}']")
end end
end end

View File

@@ -11,6 +11,7 @@ feature 'Cards' do
visit admin_homepage_path visit admin_homepage_path
click_link "Create card" click_link "Create card"
fill_in "widget_card_label", with: "Card label"
fill_in "widget_card_title", with: "Card text" fill_in "widget_card_title", with: "Card text"
fill_in "widget_card_description", with: "Card description" fill_in "widget_card_description", with: "Card description"
fill_in "widget_card_link_text", with: "Link text" fill_in "widget_card_link_text", with: "Link text"
@@ -23,6 +24,7 @@ feature 'Cards' do
card = Widget::Card.last card = Widget::Card.last
within("#widget_card_#{card.id}") do within("#widget_card_#{card.id}") do
expect(page).to have_content "Card label"
expect(page).to have_content "Card text" expect(page).to have_content "Card text"
expect(page).to have_content "Card description" expect(page).to have_content "Card description"
expect(page).to have_content "Link text" expect(page).to have_content "Link text"
@@ -57,6 +59,7 @@ feature 'Cards' do
click_link "Edit" click_link "Edit"
end end
fill_in "widget_card_label", with: "Card label updated"
fill_in "widget_card_title", with: "Card text updated" fill_in "widget_card_title", with: "Card text updated"
fill_in "widget_card_description", with: "Card description updated" fill_in "widget_card_description", with: "Card description updated"
fill_in "widget_card_link_text", with: "Link text updated" fill_in "widget_card_link_text", with: "Link text updated"
@@ -67,6 +70,7 @@ feature 'Cards' do
expect(page).to have_css(".card", count: 1) expect(page).to have_css(".card", count: 1)
within("#widget_card_#{Widget::Card.last.id}") do within("#widget_card_#{Widget::Card.last.id}") do
expect(page).to have_content "Card label updated"
expect(page).to have_content "Card text updated" expect(page).to have_content "Card text updated"
expect(page).to have_content "Card description updated" expect(page).to have_content "Card description updated"
expect(page).to have_content "Link text updated" expect(page).to have_content "Link text updated"
@@ -95,8 +99,9 @@ feature 'Cards' do
visit admin_homepage_path visit admin_homepage_path
click_link "Create header" click_link "Create header"
fill_in "widget_card_title", with: "Card text" fill_in "widget_card_label", with: "Header label"
fill_in "widget_card_description", with: "Card description" fill_in "widget_card_title", with: "Header text"
fill_in "widget_card_description", with: "Header description"
fill_in "widget_card_link_text", with: "Link text" fill_in "widget_card_link_text", with: "Link text"
fill_in "widget_card_link_url", with: "consul.dev" fill_in "widget_card_link_url", with: "consul.dev"
click_button "Create header" click_button "Create header"
@@ -105,8 +110,9 @@ feature 'Cards' do
within("#header") do within("#header") do
expect(page).to have_css(".card", count: 1) expect(page).to have_css(".card", count: 1)
expect(page).to have_content "Card text" expect(page).to have_content "Header label"
expect(page).to have_content "Card description" expect(page).to have_content "Header text"
expect(page).to have_content "Header description"
expect(page).to have_content "Link text" expect(page).to have_content "Link text"
expect(page).to have_content "consul.dev" expect(page).to have_content "consul.dev"
end end