diff --git a/app/controllers/collections/entropy_configurations_controller.rb b/app/controllers/collections/entropy_configurations_controller.rb new file mode 100644 index 000000000..98a2b1b0f --- /dev/null +++ b/app/controllers/collections/entropy_configurations_controller.rb @@ -0,0 +1,14 @@ +class Collections::EntropyConfigurationsController < ApplicationController + include CollectionScoped + + def update + @collection.entropy_configuration.update!(entropy_configuration_params) + + render turbo_stream: turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }) + end + + private + def entropy_configuration_params + params.expect(collection: [ :auto_close_period, :auto_reconsider_period ]) + end +end diff --git a/app/controllers/collections/publications_controller.rb b/app/controllers/collections/publications_controller.rb index feb5ae4b7..2ded7eda2 100644 --- a/app/controllers/collections/publications_controller.rb +++ b/app/controllers/collections/publications_controller.rb @@ -3,11 +3,12 @@ class Collections::PublicationsController < ApplicationController def create @collection.publish - redirect_to edit_collection_path(@collection) + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end def destroy @collection.unpublish - redirect_to edit_collection_path(@collection) + @collection.reload + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end end diff --git a/app/controllers/collections/workflows_controller.rb b/app/controllers/collections/workflows_controller.rb index 28b691f11..fd503473c 100644 --- a/app/controllers/collections/workflows_controller.rb +++ b/app/controllers/collections/workflows_controller.rb @@ -5,7 +5,7 @@ class Collections::WorkflowsController < ApplicationController def update @collection.update! workflow: @workflow - redirect_to cards_path(collection_ids: [ @collection ]) + render turbo_stream: turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection }) end private diff --git a/app/views/collections/edit/_auto_close.html.erb b/app/views/collections/edit/_auto_close.html.erb index d222fd5e8..79125016d 100644 --- a/app/views/collections/edit/_auto_close.html.erb +++ b/app/views/collections/edit/_auto_close.html.erb @@ -1,4 +1,6 @@ -
Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.
+<%= turbo_frame_tag @collection, :publication do %> +Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.
- <% if collection.published? %> -<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>
+<%= turbo_frame_tag @collection, :workflows do %> + Workflows +<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 985122b47..f4cf895d6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ Rails.application.routes.draw do resource :workflow, only: :update resource :involvement resource :publication + resource :entropy_configuration end resources :cards diff --git a/test/controllers/collections/entropy_configurations_controller_test.rb b/test/controllers/collections/entropy_configurations_controller_test.rb new file mode 100644 index 000000000..b96c3b198 --- /dev/null +++ b/test/controllers/collections/entropy_configurations_controller_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +class Collections::EntropyConfigurationsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + @collection = collections(:writebook) + end + + test "update" do + put collection_entropy_configuration_path(@collection), params: { collection: { auto_close_period: 1.day, auto_reconsider_period: 2.days } } + + assert_equal 1.day, @collection.entropy_configuration.reload.auto_close_period + assert_equal 2.days, @collection.entropy_configuration.reload.auto_reconsider_period + + assert_turbo_stream action: :replace, target: dom_id(@collection, :entropy_configuration) + end +end diff --git a/test/controllers/collections/publications_controller_test.rb b/test/controllers/collections/publications_controller_test.rb index 2bd9ec1dc..da24c22da 100644 --- a/test/controllers/collections/publications_controller_test.rb +++ b/test/controllers/collections/publications_controller_test.rb @@ -13,7 +13,7 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest post collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end test "unpublish a collection" do @@ -24,6 +24,6 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest delete collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end end diff --git a/test/controllers/collections/workflows_controller_test.rb b/test/controllers/collections/workflows_controller_test.rb index 8fb0e8dce..e4e739720 100644 --- a/test/controllers/collections/workflows_controller_test.rb +++ b/test/controllers/collections/workflows_controller_test.rb @@ -10,7 +10,7 @@ class Collections::WorkflowsControllerTest < ActionDispatch::IntegrationTest patch collection_workflow_path(collection), params: { collection: { workflow_id: workflows(:on_call).id } } - assert_redirected_to cards_path(collection_ids: [ collection.id ]) + assert_turbo_stream action: :replace, target: dom_id(collection, :workflows) assert_equal workflows(:on_call), collection.reload.workflow end end