diff --git a/app/helpers/workflows_helper.rb b/app/helpers/workflows_helper.rb index 21b697531..f60e9d7f8 100644 --- a/app/helpers/workflows_helper.rb +++ b/app/helpers/workflows_helper.rb @@ -12,4 +12,24 @@ module WorkflowsHelper def stage_color(stage) stage.color.presence || Card::DEFAULT_COLOR end + + def dependent_collections_sentence(workflow) + if workflow.collections.many? + "It will be removed from #{ workflow.collections.count } collections that are using it." + elsif workflow.collections.one? + "It will be removed from the only collection using it." + else + "It's not being used in any collections." + end + end + + def workflow_switch_confirmation_message(workflow, collection) + if workflow == collection.workflow + "Stop using #{workflow.name}? Cards you're working on will lose their current stage." + elsif collection.workflow.present? + "Switch to #{workflow.name}? This will return all cards you're working on to the first stage." + else + nil + end + end end diff --git a/app/models/workflow.rb b/app/models/workflow.rb index 54d82d6ff..f385c5dd0 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -4,7 +4,8 @@ class Workflow < ApplicationRecord { name: "In progress", color: "var(--color-card-3)" } ] - has_many :stages, dependent: :delete_all + has_many :stages, dependent: :destroy + has_many :collections, dependent: :nullify after_create_commit :create_default_stages diff --git a/app/models/workflow/stage.rb b/app/models/workflow/stage.rb index 8966d0000..4eb08828d 100644 --- a/app/models/workflow/stage.rb +++ b/app/models/workflow/stage.rb @@ -1,6 +1,8 @@ class Workflow::Stage < ApplicationRecord belongs_to :workflow, touch: true + has_many :cards, dependent: :nullify + before_validation :assign_random_color, on: :create private diff --git a/app/views/collections/edit/_workflows.html.erb b/app/views/collections/edit/_workflows.html.erb index 180b6a4c6..3460c4f35 100644 --- a/app/views/collections/edit/_workflows.html.erb +++ b/app/views/collections/edit/_workflows.html.erb @@ -7,7 +7,10 @@
<% Workflow.all.each do |workflow| %>
- <%= button_to collection_workflow_path(collection), method: :patch, aria: { label: workflow == collection.workflow ? "Stop using this workflow" : "Use this workflow" } do %> + <% confirmation_message = workflow_switch_confirmation_message(workflow, collection) %> + <%= button_to collection_workflow_path(collection), method: :patch, + aria: { label: workflow == collection.workflow ? "Stop using this workflow" : "Use this workflow" }, + data: confirmation_message ? { turbo_confirm: confirmation_message } : {} do %> <%= hidden_field_tag "collection[workflow_id]", workflow == collection.workflow ? "" : workflow.id %> <%= workflow.name %>
<% end %>
+ <%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link", data: { turbo_frame: "_top" } %> <% end %> diff --git a/app/views/workflows/_workflow.html.erb b/app/views/workflows/_workflow.html.erb index 3c19658ed..bdce1d13d 100644 --- a/app/views/workflows/_workflow.html.erb +++ b/app/views/workflows/_workflow.html.erb @@ -1,10 +1,17 @@ <%= turbo_frame_tag workflow do %> -
-
+
+
<%= turbo_frame_tag dom_id(workflow, :header) do %> <%= link_to edit_workflow_path(workflow) do %>

<%= workflow.name %>

<% end %> + + <%= button_to workflow_path(workflow), method: :delete, class: "btn txt-small borderless txt-subtle", + data: { turbo_frame: "_top", turbo_confirm: "Are you sure you want to delete this Workflow? #{ dependent_collections_sentence(workflow) }" }, + form: { class: "flex-item-justify-end" } do %> + <%= icon_tag "trash" %> + Delete <%= workflow.name %> + <% end %> <% end %>
diff --git a/app/views/workflows/edit.html.erb b/app/views/workflows/edit.html.erb index b8405698b..a7efd1558 100644 --- a/app/views/workflows/edit.html.erb +++ b/app/views/workflows/edit.html.erb @@ -2,7 +2,8 @@
<%= form_with model: @workflow, url: workflow_path(@workflow), id: dom_id(@workflow, :form), class: "full-width", data: { controller: "form" } do |form| %>

- <%= form.text_field :name, required: true, autofocus: true, class: "input full-width", style: "--input-padding: 0.2em 0.5em;", data: { action: "keydown.esc@document->form#cancel" } %> + <%= form.text_field :name, required: true, autofocus: true, class: "input full-width", + style: "--input-padding: 0.2em 0.5em;", data: { action: "keydown.esc@document->form#cancel focus->form#select" } %>

<%= link_to "Cancel", workflow_path(@workflow), data: { form_target: "cancel", turbo_frame: dom_id(@workflow) }, hidden: true %> <% end %> @@ -16,10 +17,5 @@ <%= icon_tag "remove-med" %> Cancel <% end %> - - <%= button_to workflow_path(@workflow), method: :delete, class: "btn txt-small btn--negative", data: { turbo_frame: :workflows, turbo_confirm: "Are you sure you want to delete this workflow?" } do %> - <%= icon_tag "minus" %> - Delete <%= @workflow.name %> - <% end %>
<% end %> diff --git a/app/views/workflows/index.html.erb b/app/views/workflows/index.html.erb index 5f0717262..60e8723b6 100644 --- a/app/views/workflows/index.html.erb +++ b/app/views/workflows/index.html.erb @@ -11,8 +11,20 @@
<% end %> -<%= turbo_frame_tag :workflows do %> -
+
+ <% if @workflows.any? %> <%= render partial: "workflows/workflow", collection: @workflows %> -
-<% end %> + <% else %> +
+

+ Workflows are for organizing Cards you're working on into stages. +

+

+ <%= link_to new_workflow_path, class: "btn btn--link" do %> + <%= icon_tag "add" %> + Create a new workflow + <% end %> +

+
+ <% end %> +
diff --git a/app/views/workflows/new.html.erb b/app/views/workflows/new.html.erb index 0009e46a4..cec65033f 100644 --- a/app/views/workflows/new.html.erb +++ b/app/views/workflows/new.html.erb @@ -1,19 +1,20 @@ -<% @page_title = "Create a new Workflow" %> +<% @page_title = "Workflows" %> <% content_for :header do %> <%= render "filters/menu", user_filtering: @user_filtering %>

<%= @page_title %>

<% end %> -<%= turbo_frame_tag :workflows do %> -
+
+
<%= form_with model: @workflow, url: workflows_path, data: { controller: "form" } do |form| %> - <%= form.text_field :name, required: true, autofocus: true, class: "input txt-large", placeholder: "Name your Workflow…", data: { action: "keydown.esc@document->form#cancel" } %> - <%= form.button type: :submit, class: "btn btn--reversed center margin-block-start txt-large" do %> - <%= icon_tag "check" %> - Create Workflow +

+ <%= form.text_field :name, required: true, autofocus: true, class: "input", placeholder: "Name your Workflow…", data: { action: "keydown.esc@document->form#cancel" } %> +

+ <%= form.button type: :submit, class: "btn btn--reversed center margin-block-start txt-medium" do %> + Create Workflow <% end %> - <%= link_to "Go back", workflows_path, data: { form_target: "cancel", turbo_frame: "_top" }, hidden: true %> + <%= link_to "Go back", workflows_path, data: { form_target: "cancel" }, hidden: true %> <% end %> -
-<% end %> + +
diff --git a/app/views/workflows/stages/edit.html.erb b/app/views/workflows/stages/edit.html.erb index b1da71b60..10aa78514 100644 --- a/app/views/workflows/stages/edit.html.erb +++ b/app/views/workflows/stages/edit.html.erb @@ -1,6 +1,7 @@ <%= turbo_frame_tag @stage do %> <%= form_with model: @stage, url: workflow_stage_path(@stage.workflow, @stage), id: dom_id(@stage, :form), class: "full-width", data: { controller: "form" } do |form| %> - <%= form.text_field :name, required: true, autofocus: true, class: "input full-width", data: { action: "keydown.esc@document->form#cancel" } %> + <%= form.text_field :name, required: true, autofocus: true, class: "input full-width", + data: { action: "keydown.esc@document->form#cancel focus->form#select" } %> <%= link_to "Cancel", workflow_path(@workflow), data: { form_target: "cancel", turbo_frame: dom_id(@workflow) }, hidden: true %> <% end %>