Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Show the ancestor trail and the sub-task section on every ticket

Guido Boyke20bab73737aa
diff --git a/app/helpers/ticket_columns_helper.rb b/app/helpers/ticket_columns_helper.rb
index c8588f5..a88034a 100644
--- a/app/helpers/ticket_columns_helper.rb
+++ b/app/helpers/ticket_columns_helper.rb
@@ -153,9 +153,10 @@ module TicketColumnsHelper
safe_join([render(NeoTimeShareBarComponent.new(shares: totals[:shares])), label], ' ')
end
when 'subtask_count'
- # A ticket without sub-tickets shows nothing, and so does every sub-ticket
- # (one level deep, Ticket#parent_is_top_level): "0/0" in most rows would
- # be the column of placeholders the note at the top rules out.
+ # A ticket without sub-tickets shows nothing: "0/0" in most rows would be
+ # the column of placeholders the note at the top rules out. Sub-tickets
+ # nest to any depth, so a sub-ticket with sub-tickets of its own shows
+ # its numbers. Every row counts its DIRECT children only.
counts = ticket_subtask_counts(ticket)
return empty_cell unless counts[:total].positive?
diff --git a/app/views/organisations/tickets/_subtasks_section.html.erb b/app/views/organisations/tickets/_subtasks_section.html.erb
index d2dd72b..620bba1 100644
--- a/app/views/organisations/tickets/_subtasks_section.html.erb
+++ b/app/views/organisations/tickets/_subtasks_section.html.erb
@@ -1,4 +1,5 @@
-<%# Sub-tasks section — top-level tickets only (rendered from _ticket_content_for_frame).
+<%# Sub-tasks section — on every ticket, a sub-task too, since sub-tasks nest to any depth
+ (rendered from _timeline_frame_content). Lists the DIRECT children only.
Two states:
- EMPTY (no children): just a compact, right-aligned "+ Unteraufgabe hinzufügen" affordance
below the ticket header — no heading, no hint, minimal footprint. The first add replaces the
diff --git a/app/views/organisations/tickets/_ticket_breadcrumbs.html.erb b/app/views/organisations/tickets/_ticket_breadcrumbs.html.erb
new file mode 100644
index 0000000..9456ae8
--- /dev/null
+++ b/app/views/organisations/tickets/_ticket_breadcrumbs.html.erb
@@ -0,0 +1,23 @@
+<%# The trail of a sub-task: every ticket above it, root first, each a link to
+ the list with that ticket open (the target of the old "part of" pill), then
+ the ticket's own number, not a link. Sub-tasks nest to any depth, so the
+ whole chain shows and wraps on a narrow screen; nothing is collapsed.
+ One query for the chain (Tickets::Ancestry). Rendered by the header for a
+ ticket with a parent; needs ticket, project and current_organisation, which
+ the header has on the page and in its turbo streams alike. %>
+<% ancestors = Tickets::Ancestry.call(ticket: ticket) %>
+<nav aria-label="<%= t('views.organisations.tickets.shared.subtasks.breadcrumbs_label') %>">
+ <ol class="flex flex-wrap items-center gap-1 text-xs text-cream-700">
+ <% ancestors.each do |ancestor| %>
+ <li class="inline-flex items-center gap-1">
+ <%= link_to "##{ancestor.number}",
+ organisation_project_tickets_path(current_organisation, project, ticket_id: ancestor.id),
+ class: "inline-flex h-6 items-center rounded-full border border-cream-300 px-2 font-mono tabular-nums hover:bg-cream-100" %>
+ <span class="text-cream-500" aria-hidden="true">›</span>
+ </li>
+ <% end %>
+ <li class="inline-flex items-center">
+ <span class="inline-flex h-6 items-center px-1 font-mono tabular-nums text-cream-900" aria-current="page">#<%= ticket.number %></span>
+ </li>
+ </ol>
+</nav>
diff --git a/app/views/organisations/tickets/_ticket_header_show.html.erb b/app/views/organisations/tickets/_ticket_header_show.html.erb
index ccb128b..7bd2f2c 100644
--- a/app/views/organisations/tickets/_ticket_header_show.html.erb
+++ b/app/views/organisations/tickets/_ticket_header_show.html.erb
@@ -116,13 +116,10 @@
<%= ticket.title %>
<% end %>
</h2>
- <%# Sub-task backlink — neutral pill (not a status/action colour), links to the parent. %>
+ <%# Where a sub-task sits in its tree: every ticket above it, then its own number. %>
<% if ticket.parent_id.present? %>
- <%= link_to organisation_project_tickets_path(current_organisation, project, ticket_id: ticket.parent_id),
- class: "inline-flex h-6 w-fit items-center gap-1 rounded-full border border-cream-300 px-2 text-xs text-cream-700 hover:bg-cream-100" do %>
- <i class="bi bi-arrow-return-right text-[11px]"></i>
- <%= t('views.organisations.tickets.shared.subtasks.part_of', number: ticket.parent.number) %>
- <% end %>
+ <%= render 'organisations/tickets/ticket_breadcrumbs',
+ ticket: ticket, project: project, current_organisation: current_organisation %>
<% end %>
</div>
diff --git a/app/views/organisations/tickets/_timeline_frame_content.html.erb b/app/views/organisations/tickets/_timeline_frame_content.html.erb
index 30881a8..d8445a7 100644
--- a/app/views/organisations/tickets/_timeline_frame_content.html.erb
+++ b/app/views/organisations/tickets/_timeline_frame_content.html.erb
@@ -72,18 +72,17 @@
<% end %>
<%# The sub-tasks row toggles the SECTION below this line, not a
timeline sort - below a divider and outside the state word on
- purpose. Top-level tickets only; a child never shows the section. %>
- <% if ticket.parent_id.nil? %>
- <div class="my-1 border-t border-cream-200"></div>
- <button type="button" class="<%= row_classes %>" aria-pressed="false"
- data-action="click->timeline-filter#toggleSubtasks"
- data-timeline-filter-target="subtasksToggleButton">
- <%# invisible: the sub-tasks row starts OFF, unlike the three sorts. %>
- <i class="bi bi-check-lg invisible text-green-700" aria-hidden="true"></i>
- <%= t('views.organisations.tickets.shared.subtasks.heading') %>
- <span class="ml-auto font-mono text-[11px] text-cream-500"><%= ticket.children.count %></span>
- </button>
- <% end %>
+ purpose. Every ticket has it, a sub-task too: sub-tasks nest to
+ any depth. %>
+ <div class="my-1 border-t border-cream-200"></div>
+ <button type="button" class="<%= row_classes %>" aria-pressed="false"
+ data-action="click->timeline-filter#toggleSubtasks"
+ data-timeline-filter-target="subtasksToggleButton">
+ <%# invisible: the sub-tasks row starts OFF, unlike the three sorts. %>
+ <i class="bi bi-check-lg invisible text-green-700" aria-hidden="true"></i>
+ <%= t('views.organisations.tickets.shared.subtasks.heading') %>
+ <span class="ml-auto font-mono text-[11px] text-cream-500"><%= ticket.children.count %></span>
+ </button>
</div>
</div>
</div>
@@ -204,12 +203,11 @@
row (user 03.09.), default off, rendered hidden so nothing flashes
before the controller connects. Its own turbo streams keep working here:
they address #subtasks-<id> by id, and the quick-add answers with
- streams, which take precedence over the enclosing frame. %>
-<% if ticket.parent_id.nil? %>
- <div data-timeline-filter-target="subtasks" style="display: none;">
- <%= render 'organisations/tickets/subtasks_section', ticket: ticket %>
- </div>
-<% end %>
+ streams, which take precedence over the enclosing frame. On every
+ ticket, a sub-task too: its quick-add makes a sub-task one level down. %>
+<div data-timeline-filter-target="subtasks" style="display: none;">
+ <%= render 'organisations/tickets/subtasks_section', ticket: ticket %>
+</div>
<%= render 'organisations/tickets/timeline_items',
timeline_items: timeline_items,
diff --git a/config/locales/views/tickets.de.yml b/config/locales/views/tickets.de.yml
index 2e92483..cbdc4ff 100644
--- a/config/locales/views/tickets.de.yml
+++ b/config/locales/views/tickets.de.yml
@@ -245,7 +245,7 @@ de:
heading: Unteraufgaben
progress: "%{done} von %{total} erledigt"
add_placeholder: Unteraufgabe hinzufügen …
- part_of: 'Teil von #%{number}'
+ breadcrumbs_label: Übergeordnete Aufgaben
relations:
heading: Beziehungen
add: Verknüpfen
diff --git a/config/locales/views/tickets.en.yml b/config/locales/views/tickets.en.yml
index 1680341..c7ac1a2 100644
--- a/config/locales/views/tickets.en.yml
+++ b/config/locales/views/tickets.en.yml
@@ -245,7 +245,7 @@ en:
heading: Sub-tasks
progress: "%{done} of %{total} done"
add_placeholder: Add a sub-task …
- part_of: 'Part of #%{number}'
+ breadcrumbs_label: Parent tasks
relations:
heading: Relations
add: Link
diff --git a/spec/requests/organisations/tickets_subtasks_quick_add_spec.rb b/spec/requests/organisations/tickets_subtasks_quick_add_spec.rb
index faa7e41..68c30b8 100644
--- a/spec/requests/organisations/tickets_subtasks_quick_add_spec.rb
+++ b/spec/requests/organisations/tickets_subtasks_quick_add_spec.rb
@@ -69,6 +69,50 @@ RSpec.describe 'Tickets sub-tasks quick-add', type: :request do
expect(response.body).to match(/<details[^>]*\bopen\b/)
end
+ # Sub-tasks nest to any depth: the quick-add on a sub-task makes a grandchild, and the list's
+ # Subs cell of that sub-task (its own row, not the root's) gets the new count.
+ context 'on a sub-task' do
+ let(:sub_task) do
+ ActsAsTenant.current_tenant = organisation
+ create(:ticket, project: project, creator: user, parent: parent)
+ end
+
+ before do
+ ViewConfiguration.create!(user: user, project: project, view_type: 'tickets',
+ table_columns: %w[number title subtask_count],
+ list_columns: { 'cells' => [], 'metadata' => [] },
+ header_columns: %w[assignees])
+ end
+
+ def stream_text(target)
+ Nokogiri::HTML(response.body).css('turbo-stream').find { |node| node['targets'] == target }&.text&.strip
+ end
+
+ it 'creates a grandchild below the sub-task' do
+ expect do
+ post organisation_project_ticket_subtasks_path(organisation, project, sub_task),
+ params: { title: 'Enkel' }, as: :turbo_stream
+ end.to change { children_of(sub_task).size }.by(1)
+
+ expect(response).to have_http_status(:ok)
+ grandchild = children_of(sub_task).last
+ expect(grandchild.title).to eq('Enkel')
+ expect(grandchild.parent_id).to eq(sub_task.id)
+ expect(response.body).to include("subtask-quick-add-#{sub_task.id}")
+ end
+
+ it "redraws the sub-task's own Subs cell and item, not the root's" do
+ post organisation_project_ticket_subtasks_path(organisation, project, sub_task),
+ params: { title: 'Enkel' }, as: :turbo_stream
+
+ expect(response).to have_http_status(:ok)
+ expect(stream_text("tr[data-ticket-id='#{sub_task.id}'] td[data-column='subtask_count']")).to eq('0/1')
+ expect(stream_text("tr[data-ticket-id='#{sub_task.id}'] .ticket-meta__item[data-meta-column='subtask_count']"))
+ .to eq('Subs 0/1')
+ expect(stream_text("tr[data-ticket-id='#{parent.id}'] td[data-column='subtask_count']")).to be_nil
+ end
+ end
+
it 'rejects a blank title: no child, inline error, 422' do
expect do
post organisation_project_ticket_subtasks_path(organisation, project, parent),
diff --git a/spec/requests/organisations/tickets_subtasks_render_spec.rb b/spec/requests/organisations/tickets_subtasks_render_spec.rb
index 65419ee..627c320 100644
--- a/spec/requests/organisations/tickets_subtasks_render_spec.rb
+++ b/spec/requests/organisations/tickets_subtasks_render_spec.rb
@@ -2,11 +2,13 @@
require 'rails_helper'
-# Renders the sub-tasks UI: section + progress on the parent, compact quick-add on a
-# childless top-level ticket, and the parent backlink on a child. The SECTION lives
-# INSIDE the lazy timeline frame since the T3 follow-up (03.09., ticket detail
-# redesign) — the show body only carries the frame's src, so section assertions go
-# against the frame's own endpoint; header assertions (backlink badge) stay on show.
+# Renders the sub-tasks UI: section + progress on a ticket with children, compact
+# quick-add on a childless one, and the trail of ancestors on a sub-task. Sub-tasks
+# nest to any depth, so every ticket, a sub-task too, carries the section. The
+# SECTION lives INSIDE the lazy timeline frame since the T3 follow-up (03.09., ticket
+# detail redesign) - the show body only carries the frame's src, so section
+# assertions go against the frame's own endpoint; header assertions (the trail)
+# stay on show.
RSpec.describe 'Tickets sub-tasks (detail rendering)', type: :request do
let(:organisation) { create(:organisation) }
let(:user) { create(:user) }
@@ -67,14 +69,66 @@ RSpec.describe 'Tickets sub-tasks (detail rendering)', type: :request do
expect(body).not_to include('Zerlege diese Aufgabe in kleinere Schritte.')
end
- it 'shows the parent backlink badge on a child ticket' do
+ def breadcrumbs(body = response.body)
+ Nokogiri::HTML(body).at_css(
+ "nav[aria-label='#{I18n.t('views.organisations.tickets.shared.subtasks.breadcrumbs_label')}']"
+ )
+ end
+
+ it 'shows the parent number as a link in the trail of a child, and no old pill' do
parent = create(:ticket, project: project, creator: user)
child = create(:ticket, project: project, creator: user, parent: parent)
get detail_path(child)
- expect(response.body).to include("Teil von ##{parent.number}")
- expect(response.body).to include('bi-arrow-return-right')
+ expect(response).to have_http_status(:ok)
+ nav = breadcrumbs
+ expect(nav).to be_present
+ link = nav.at_css('ol li a')
+ expect(link.text.strip).to eq("##{parent.number}")
+ expect(link['href']).to eq(organisation_project_tickets_path(organisation, project, ticket_id: parent.id))
+ expect(response.body).not_to include('Teil von')
+ end
+
+ it 'shows the whole chain of a great-grandchild, root first, its own number last and not a link' do
+ root = create(:ticket, project: project, creator: user)
+ child = create(:ticket, project: project, creator: user, parent: root)
+ grandchild = create(:ticket, project: project, creator: user, parent: child)
+ great = create(:ticket, project: project, creator: user, parent: grandchild)
+
+ get detail_path(great)
+
+ expect(response).to have_http_status(:ok)
+ items = breadcrumbs.css('ol > li')
+ expect(items.map { |li| li.text.gsub(/\s+/, ' ').strip.delete_suffix('›').strip })
+ .to eq([root, child, grandchild, great].map { |t| "##{t.number}" })
+ expect(items[0..2].map { |li| li.at_css('a')['href'] })
+ .to eq([root, child, grandchild].map { |t| organisation_project_tickets_path(organisation, project, ticket_id: t.id) })
+ expect(items.last.at_css('a')).to be_nil
+ expect(items.last.at_css('[aria-current="page"]').text.strip).to eq("##{great.number}")
+ # The separator is decoration, not a word a screen reader reads out.
+ expect(breadcrumbs.css('[aria-hidden="true"]').map { |n| n.text.strip }).to eq(%w[› › ›])
+ end
+
+ it 'looks the ancestors up in one query, however deep the ticket sits' do
+ root = create(:ticket, project: project, creator: user)
+ child = create(:ticket, project: project, creator: user, parent: root)
+ grandchild = create(:ticket, project: project, creator: user, parent: child)
+ great = create(:ticket, project: project, creator: user, parent: grandchild)
+
+ statements = capture_sql { get detail_path(great) }
+
+ expect(response).to have_http_status(:ok)
+ expect(statements.grep(/WITH RECURSIVE ancestors/).size).to eq(1)
+ end
+
+ it 'shows no trail on a top-level ticket' do
+ lone = create(:ticket, project: project, creator: user)
+
+ get detail_path(lone)
+
+ expect(response).to have_http_status(:ok)
+ expect(breadcrumbs).to be_nil
end
it 'renders the inline quick-add form posting to this parent subtasks endpoint' do
@@ -109,12 +163,16 @@ RSpec.describe 'Tickets sub-tasks (detail rendering)', type: :request do
expect(body).not_to include('subtasks-details')
end
- it 'does not show the sub-tasks section on a child ticket' do
+ it 'shows the sub-tasks section and its quick-add on a child ticket too' do
parent = create(:ticket, project: project, creator: user)
child = create(:ticket, project: project, creator: user, parent: parent)
- # Asserted against the frame endpoint — the surface that WOULD render the
- # section if the parent_id gate were missing; the show body never carries it.
- expect(subtasks_body(child)).not_to include("subtasks-#{child.id}")
+ body = subtasks_body(child)
+
+ expect(response).to have_http_status(:ok)
+ expect(body).to include("subtasks-#{child.id}")
+ expect(body).to include("subtask-quick-add-#{child.id}")
+ expect(body).to include(organisation_project_ticket_subtasks_path(organisation, project, child))
+ expect(body).to include('data-timeline-filter-target="subtasksToggleButton"')
end
end
diff --git a/spec/requests/ticket_subtask_count_column_spec.rb b/spec/requests/ticket_subtask_count_column_spec.rb
index cd32984..b1b5ad4 100644
--- a/spec/requests/ticket_subtask_count_column_spec.rb
+++ b/spec/requests/ticket_subtask_count_column_spec.rb
@@ -3,9 +3,10 @@
require 'rails_helper'
# The "Subs" column, seen from the list that renders it. The cache spec proves
-# the numbers; this proves the wiring: the cell shows "done/total", stays empty
-# for a ticket without sub-tickets and for the sub-tickets themselves, the page
-# preloads, and the single-row re-render after a save still counts.
+# the numbers; this proves the wiring: the cell shows "done/total" of a ticket's
+# DIRECT sub-tickets, also on a sub-ticket with sub-tickets of its own, stays
+# empty for a ticket without any, the page preloads, and the single-row
+# re-render after a save still counts.
RSpec.describe 'Ticket table: sub-ticket column', type: :request do
let(:organisation) { create(:organisation) }
let(:user) { ActsAsTenant.with_tenant(organisation) { create(:user) } }
@@ -64,6 +65,25 @@ RSpec.describe 'Ticket table: sub-ticket column', type: :request do
expect(cells.sort).to eq(['', '', '', '1/3'])
end
+ # Sub-tasks nest to any depth. Each row counts its direct children: the
+ # grandchild is the sub-ticket's, not the root's.
+ it "shows a sub-ticket's own children and leaves them out of the root's count" do
+ sub = child('Offen')
+ create(:ticket, project: project, creator: user, parent: sub, custom_attributes: { 'status' => 'Erledigt' })
+ create(:ticket, project: project, creator: user, parent: sub, custom_attributes: { 'status' => 'Offen' })
+ child('Erledigt')
+
+ get_index
+ expect(response).to have_http_status(:ok)
+ by_row = Nokogiri::HTML(response.body).css('tr[data-ticket-id]').to_h do |row|
+ [row['data-ticket-id'], row.at_css('td.subtask_count-column')&.text&.strip]
+ end
+ expect(by_row[parent.id]).to eq('1/2')
+ expect(by_row[sub.id]).to eq('1/2')
+ # The other sub-ticket and both grandchildren have no children: empty.
+ expect(by_row.values.sort).to eq(['', '', '', '1/2', '1/2'])
+ end
+
it 'explains the number in the cell title' do
child('Erledigt')
@@ -261,18 +281,17 @@ RSpec.describe 'Ticket table: sub-ticket column', type: :request do
expect(parent_cell).to eq('1/1')
end
- it 'redraws the old parent too when a ticket moves to another one' do
+ # A saved ticket keeps its parent (Ticket#parent_unchanged): an edit that names
+ # another parent changes nothing, so no row has a new count to show.
+ it 'keeps the parent when an edit names another one, and the other stays empty' do
new_parent = create(:ticket, project: project, creator: user)
sub = child('Offen')
patch organisation_project_ticket_path(organisation, project, sub),
params: { ticket: { title: sub.title, parent_id: new_parent.id } }, headers: stream_headers
- expect(response).to have_http_status(:ok)
- expect(parent_cell(of: new_parent)).to eq('0/1')
- # The old parent has no sub-tickets left: its cell and item are emptied.
- expect(parent_cell(of: parent)).to eq('')
- expect(parent_meta(of: parent)).to eq('')
+ expect(sub.reload.parent_id).to eq(parent.id)
+ expect(parent_cell(of: new_parent).to_s).to eq('')
end
# Finding 2 of the second review: the unread dot on the parent's number