From 6e871e9ebb29d63f3d908b46dfd707c38b39551d Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 11 Nov 2026 20:31:02 -0500 Subject: [PATCH] Documents: collections (and Uncollected) collapse, closed by default, with document counts Co-Authored-By: Claude Opus 5.5 --- app/views/documents/index.html.erb | 28 ++++++++++++------- docs/guide/documents.md | 2 +- test/integration/document_bulk_upload_test.rb | 12 ++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 82d495c..4acdea1 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -12,11 +12,14 @@ <% end %>
<% @collections.each do |col| %> -
-
-
-

<%= "★ " if col.starred? %><%= col.name %>

- <% if col.description.present? %>

<%= col.description %>

<% end %> +
+ +
+ +
+

<%= "★ " if col.starred? %><%= col.name %> (<%= col.documents.size %>)

+ <% if col.description.present? %>

<%= col.description %>

<% end %> +
<%= visibility_badge(col.visibility) %> @@ -25,16 +28,21 @@ <%= link_to "Edit", edit_aircraft_document_collection_path(@aircraft, col), class: "btn-secondary btn-sm" %> <% end %>
-
+ <% if col.documents.any? %>
    <% col.documents.sort_by(&:name).each do |doc| %><%= render "documents/doc_row", doc: doc, aircraft: @aircraft %><% end %>
<% else %><%= empty_state "Empty collection." %><% end %> -
+ <% end %> <% if @uncollected.any? %> -
-

Uncollected

+
+ +
+ +

Uncollected (<%= @uncollected.size %>)

+
+
    <% @uncollected.each do |doc| %><%= render "documents/doc_row", doc: doc, aircraft: @aircraft %><% end %>
-
+ <% end %>
diff --git a/docs/guide/documents.md b/docs/guide/documents.md index 5016f34..6d54fd9 100644 --- a/docs/guide/documents.md +++ b/docs/guide/documents.md @@ -4,7 +4,7 @@ The **Documents** tab keeps scans and files: registration, airworthiness certifi - **+ Upload Document**: a name, type, collection, description, and one or more files (images, PDFs or text). Each file is a page in the viewer. - **Bulk upload**: many files at once. Each becomes its own document named after the file; files with the same name are combined, in order, as pages of one document. -- **+ Collection** groups documents (for example *Engine logbook* or *Annual 2026*). +- **+ Collection** groups documents (for example *Engine logbook* or *Annual 2026*). Collections start collapsed, showing how many documents they hold; click one to open it. ## Expiry diff --git a/test/integration/document_bulk_upload_test.rb b/test/integration/document_bulk_upload_test.rb index 60e1490..07d0316 100644 --- a/test/integration/document_bulk_upload_test.rb +++ b/test/integration/document_bulk_upload_test.rb @@ -15,6 +15,18 @@ class DocumentBulkUploadTest < ActionDispatch::IntegrationTest ActiveStorage::Blob.create_and_upload!(io: StringIO.new("bytes"), filename: name, content_type: type) end + test "collections are collapsed on the documents page, with their document count" do + sign_in @owner + @a.document_collections.create!(name: "Engine logbook").documents.create!(aircraft: @a, name: "Scan", doc_type: "LOG") + @a.documents.create!(name: "Loose receipt", doc_type: "INVOICE") + get aircraft_documents_path(@a) + assert_select "details.document-collection", 2 + assert_select "details.document-collection[open]", 0 # collapsed until clicked + assert_select "details.document-collection summary h2", text: /Engine logbook\s*\(1\)/ + assert_select "details.document-collection summary h2", text: /Uncollected\s*\(1\)/ + assert_select "details.document-collection a", text: "Scan" # still in the page, just closed + end + test "owner sees the bulk page; pilots and outsiders can't use it" do sign_in @owner get aircraft_documents_path(@a)