From 75d9ce0b82c6cc92b1f401af2ae0318065391551 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Thu, 12 Jun 2025 11:59:09 -0500 Subject: [PATCH 1/3] Add multiple cards quickly --- app/assets/stylesheets/card-perma.css | 1 + app/controllers/cards_controller.rb | 5 +++++ app/views/cards/container/footer/_draft.html.erb | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/card-perma.css b/app/assets/stylesheets/card-perma.css index 47f4c4c8c..f61b22806 100644 --- a/app/assets/stylesheets/card-perma.css +++ b/app/assets/stylesheets/card-perma.css @@ -175,6 +175,7 @@ .btn--reversed { --btn-background: var(--color-canvas); --btn-color: var(--card-color); + --btn-border-color: var(--color-container); } } diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 8a8b4fb05..660cd7513 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -15,6 +15,11 @@ class CardsController < ApplicationController end def create + if params[:publish_current] + @card = Card.find(params[:publish_current]) + @card.publish + flash[:notice] = "Card added" + end card = @collection.cards.create! redirect_to card end diff --git a/app/views/cards/container/footer/_draft.html.erb b/app/views/cards/container/footer/_draft.html.erb index f46e08b41..2e58b978b 100644 --- a/app/views/cards/container/footer/_draft.html.erb +++ b/app/views/cards/container/footer/_draft.html.erb @@ -1,4 +1,5 @@
<%= button_to "Create card", card_publish_path(card), class: "btn" %> - <%= button_to "Save as draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %> + <%= button_to "Create and add another", collection_cards_path(card.collection, publish_current: card.id), method: :post, class: "btn btn--reversed", form: { data: { turbo: false } } %> + <%= button_to "Save as a draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %>
From 31c851aa5b8a21be5985844cdb7655d0738e65c3 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 13 Jun 2025 08:55:30 +0200 Subject: [PATCH 2/3] Use the same controller for publishing cards and for publishing and adding another --- app/controllers/cards/publishes_controller.rb | 8 +++++++- app/controllers/cards_controller.rb | 5 ----- app/views/cards/container/footer/_draft.html.erb | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/cards/publishes_controller.rb b/app/controllers/cards/publishes_controller.rb index f7ac6590c..cd24ffdeb 100644 --- a/app/controllers/cards/publishes_controller.rb +++ b/app/controllers/cards/publishes_controller.rb @@ -3,6 +3,12 @@ class Cards::PublishesController < ApplicationController def create @card.publish - redirect_to @card + + redirect_to add_another_param? ? @collection.cards.create! : @card end + + private + def add_another_param? + params[:creation_type] == "add_another" + end end diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 660cd7513..8a8b4fb05 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -15,11 +15,6 @@ class CardsController < ApplicationController end def create - if params[:publish_current] - @card = Card.find(params[:publish_current]) - @card.publish - flash[:notice] = "Card added" - end card = @collection.cards.create! redirect_to card end diff --git a/app/views/cards/container/footer/_draft.html.erb b/app/views/cards/container/footer/_draft.html.erb index 2e58b978b..7b3dff00a 100644 --- a/app/views/cards/container/footer/_draft.html.erb +++ b/app/views/cards/container/footer/_draft.html.erb @@ -1,5 +1,5 @@
- <%= button_to "Create card", card_publish_path(card), class: "btn" %> - <%= button_to "Create and add another", collection_cards_path(card.collection, publish_current: card.id), method: :post, class: "btn btn--reversed", form: { data: { turbo: false } } %> + <%= button_to "Create card", card_publish_path(card), name: "creation_type", value: "add", class: "btn" %> + <%= button_to "Create and add another", card_publish_path(card), method: :post, class: "btn btn--reversed", name: "creation_type", value: "add_another", form: { data: { turbo: false } } %> <%= button_to "Save as a draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %>
From 9dc221f0b2f3d3cec73578b05a8e32902154865e Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 13 Jun 2025 08:58:06 +0200 Subject: [PATCH 3/3] Add test --- test/controllers/cards/publishes_controller_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/controllers/cards/publishes_controller_test.rb b/test/controllers/cards/publishes_controller_test.rb index c9df4d0aa..e5a99c51c 100644 --- a/test/controllers/cards/publishes_controller_test.rb +++ b/test/controllers/cards/publishes_controller_test.rb @@ -15,4 +15,17 @@ class Cards::PublishesControllerTest < ActionDispatch::IntegrationTest assert_redirected_to card end + + test "create and add another" do + card = cards(:logo) + card.drafted! + + assert_changes -> { card.reload.published? }, from: false, to: true do + assert_difference -> { Card.creating.count }, +1 do + post card_publish_path(card, creation_type: "add_another") + end + end + + assert_redirected_to Card.creating.last + end end