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 @@ -
- Do or Die - <%= render "entropy/auto_close", model: collection %> -
+<%= turbo_frame_tag @collection, :entropy_configuration do %> +
+ Do or Die + <%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %> +
+<% end %> diff --git a/app/views/collections/edit/_publication.html.erb b/app/views/collections/edit/_publication.html.erb index 72f315b8d..921cd6fe2 100644 --- a/app/views/collections/edit/_publication.html.erb +++ b/app/views/collections/edit/_publication.html.erb @@ -1,54 +1,55 @@ -
- Public link -

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 %> +
+ Public link +

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? %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
+ <% if collection.published? %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> -
- <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> - <%= icon_tag "copy-paste" %> - Copy public link +
+ <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> +
+ <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> + <%= icon_tag "copy-paste" %> + Copy public link + <% end %> +
+
+ Add an optional description to the public page +
+ <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> + <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", + placeholder: "Add a public note about this collection…", + data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> + <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> <% end %>
- Add an optional description to the public page -
- <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> - <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", - placeholder: "Add a public note about this collection…", - data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> - <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> - <% end %> + <% else %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <% else %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
-
- <% end %> -
- + <% end %> +
+<% end %> diff --git a/app/views/collections/edit/_workflows.html.erb b/app/views/collections/edit/_workflows.html.erb index 1b6154415..73d36de66 100644 --- a/app/views/collections/edit/_workflows.html.erb +++ b/app/views/collections/edit/_workflows.html.erb @@ -1,21 +1,23 @@ -Workflows -
Use a Workflow to track progress in this Collection.
-
- <% Workflow.all.each do |workflow| %> -
- <%= button_to collection_workflow_path(collection), method: :patch do %> - <%= hidden_field_tag "collection[workflow_id]", workflow.id %> - <%= workflow.name %> -
    - <% workflow.stages.each do |stage| %> -
  • - - <%= stage.name %> -
  • - <% end %> -
- <% end %> -
- <% end %> -
-

<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>

+<%= turbo_frame_tag @collection, :workflows do %> + Workflows +
Use a Workflow to track progress in this Collection.
+
+ <% Workflow.all.each do |workflow| %> +
+ <%= button_to collection_workflow_path(collection), method: :patch do %> + <%= hidden_field_tag "collection[workflow_id]", workflow.id %> + <%= workflow.name %> +
    + <% workflow.stages.each do |stage| %> +
  • + + <%= stage.name %> +
  • + <% end %> +
+ <% end %> +
+ <% end %> +
+

<%= 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