Untie statuses from the project directly (tie to workflows)
This commit is contained in:
@@ -11,7 +11,7 @@ class TasksController < ApplicationController
|
||||
Task.all
|
||||
end
|
||||
|
||||
@tasks = @tasks.includes(:status, :workflow, project: :task_statuses)
|
||||
@tasks = @tasks.includes(:status, :project, workflow: :task_statuses)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
@@ -7,8 +7,8 @@ class Project < ApplicationRecord
|
||||
validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z][a-z0-9]{1,}\z/ }
|
||||
|
||||
has_many :tasks, dependent: :restrict_with_exception
|
||||
has_many :task_statuses, dependent: :destroy
|
||||
has_many :workflows, dependent: :destroy
|
||||
has_many :task_statuses, through: :workflows
|
||||
|
||||
has_rich_text :description
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TaskStatus < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :workflow
|
||||
has_one :project, through: :workflow
|
||||
|
||||
enum :category, { backlog: 100, analysis: 1000, development: 20_000, fulfillment: 60_000 }
|
||||
|
||||
validates :name, presence: true, uniqueness: { scope: :project }
|
||||
validates :name, presence: true, uniqueness: { scope: :workflow }
|
||||
validates :category, presence: true
|
||||
validate :associations_should_have_same_project
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ class Workflow < ApplicationRecord
|
||||
belongs_to :project
|
||||
|
||||
has_many :tasks, dependent: :restrict_with_exception
|
||||
has_many :statuses, class_name: 'TaskStatus', dependent: :restrict_with_error
|
||||
has_many :task_statuses, dependent: :restrict_with_error
|
||||
|
||||
enum :icon, { task: 'task', warning: 'warning' }, default: 'task', scopes: false
|
||||
enum :color, { blue: 'blue', gray: 'gray', yellow: 'yellow', red: 'red' }, default: 'gray', scopes: false
|
||||
|
||||
@@ -17,16 +17,15 @@ module Tasks
|
||||
view_context.render(
|
||||
partial: 'tasks/status_selector',
|
||||
locals: { task: @task, id: dom_id, with_form: @with_form,
|
||||
project_task_statuses:,
|
||||
workflow_task_statuses:,
|
||||
task_status_badge: ->(status) { task_status_badge(status, view_context) }}
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def project_task_statuses
|
||||
# TODO: refactor because it causes N+1 (task statuses loaded separately)
|
||||
@task.project.task_statuses.default_order
|
||||
def workflow_task_statuses
|
||||
@task.workflow.task_statuses.sort_by { |e| [e.category, e.name] }
|
||||
end
|
||||
|
||||
def task_status_badge(status, view_context)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
details.dropdown.task-status-selector id=id data-controller="tasks--status-selector"
|
||||
summary= task_status_badge[task.status]
|
||||
ul
|
||||
- project_task_statuses.each do |status|
|
||||
- workflow_task_statuses.each do |status|
|
||||
li
|
||||
a href="#" data-status-id="#{status.id}" data-action="tasks--status-selector#changeStatus:prevent" = task_status_badge[status]
|
||||
- if with_form
|
||||
|
||||
Reference in New Issue
Block a user