From 26e5e6ae9ecdd4efc56f5bb172ce35a1f7408f39 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 25 Sep 2025 16:12:17 +0200 Subject: [PATCH] Render a collection resource (WIP) --- .../columns/not_nows_controller.rb | 7 ++++ .../collections/columns/streams_controller.rb | 7 ++++ .../collections/columns_controller.rb | 14 +++++++ app/controllers/collections_controller.rb | 4 ++ app/models/card/postponable.rb | 5 ++- app/models/card/triageable.rb | 12 +++++- app/views/cards/display/_preview.html.erb | 4 +- app/views/collections/columns/_list.html.erb | 1 + .../columns/not_nows/show.html.erb | 15 ++++++++ app/views/collections/columns/show.html.erb | 14 +++++++ .../collections/columns/streams/show.html.erb | 14 +++++++ app/views/collections/show.html.erb | 38 +++++++++++++++++++ app/views/collections/show/_closed.html.erb | 0 app/views/collections/show/_column.html.erb | 10 +++++ app/views/collections/show/_columns.html.erb | 20 ++++++++++ app/views/collections/show/_not_now.html.erb | 9 +++++ app/views/collections/show/_stream.html.erb | 18 +++++++++ config/routes.rb | 7 ++++ 18 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 app/controllers/collections/columns/not_nows_controller.rb create mode 100644 app/controllers/collections/columns/streams_controller.rb create mode 100644 app/controllers/collections/columns_controller.rb create mode 100644 app/views/collections/columns/_list.html.erb create mode 100644 app/views/collections/columns/not_nows/show.html.erb create mode 100644 app/views/collections/columns/show.html.erb create mode 100644 app/views/collections/columns/streams/show.html.erb create mode 100644 app/views/collections/show.html.erb create mode 100644 app/views/collections/show/_closed.html.erb create mode 100644 app/views/collections/show/_column.html.erb create mode 100644 app/views/collections/show/_columns.html.erb create mode 100644 app/views/collections/show/_not_now.html.erb create mode 100644 app/views/collections/show/_stream.html.erb diff --git a/app/controllers/collections/columns/not_nows_controller.rb b/app/controllers/collections/columns/not_nows_controller.rb new file mode 100644 index 000000000..0b5658322 --- /dev/null +++ b/app/controllers/collections/columns/not_nows_controller.rb @@ -0,0 +1,7 @@ +class Collections::Columns::NotNowsController < ApplicationController + include CollectionScoped + + def show + set_page_and_extract_portion_from @collection.cards.postponed.reverse_chronologically + end +end diff --git a/app/controllers/collections/columns/streams_controller.rb b/app/controllers/collections/columns/streams_controller.rb new file mode 100644 index 000000000..e5b9dbb6b --- /dev/null +++ b/app/controllers/collections/columns/streams_controller.rb @@ -0,0 +1,7 @@ +class Collections::Columns::StreamsController < ApplicationController + include CollectionScoped + + def show + set_page_and_extract_portion_from @collection.cards.untriaged.reverse_chronologically + end +end diff --git a/app/controllers/collections/columns_controller.rb b/app/controllers/collections/columns_controller.rb new file mode 100644 index 000000000..f69a8b80b --- /dev/null +++ b/app/controllers/collections/columns_controller.rb @@ -0,0 +1,14 @@ +class Collections::ColumnsController < ApplicationController + include CollectionScoped + + before_action :set_column + + def show + set_page_and_extract_portion_from @column.cards.active.reverse_chronologically + end + + private + def set_column + @column = @collection.columns.find(params[:id]) + end +end diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 7cf673339..60d358857 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -7,6 +7,10 @@ class CollectionsController < ApplicationController @collection = Collection.new end + def show + set_page_and_extract_portion_from @collection.cards.untriaged.reverse_chronologically + end + def create @collection = Collection.create! collection_params.with_defaults(all_access: true) redirect_to cards_path(collection_ids: [ @collection ]) diff --git a/app/models/card/postponable.rb b/app/models/card/postponable.rb index eca9a0809..6877a06f7 100644 --- a/app/models/card/postponable.rb +++ b/app/models/card/postponable.rb @@ -4,8 +4,8 @@ module Card::Postponable included do has_one :not_now, dependent: :destroy, class_name: "Card::NotNow" - scope :not_now, -> { joins(:not_now) } - scope :active, -> { where.missing(:not_now) } + scope :postponed, -> { open.joins(:not_now) } + scope :active, -> { open.where.missing(:not_now) } end def postponed? @@ -19,6 +19,7 @@ module Card::Postponable def postpone unless postponed? transaction do + update!(column: nil) reopen activity_spike&.destroy create_not_now! diff --git a/app/models/card/triageable.rb b/app/models/card/triageable.rb index 5a297b7c9..694845298 100644 --- a/app/models/card/triageable.rb +++ b/app/models/card/triageable.rb @@ -4,7 +4,15 @@ module Card::Triageable included do belongs_to :column, optional: true - scope :untriaged, -> { where.missing(:column) } - scope :triaged, -> { joins(:column) } + scope :untriaged, -> { active.where.missing(:column) } + scope :triaged, -> { active.joins(:column) } + end + + def triaged? + active? && column.present? + end + + def untriaged? + !triaged? end end diff --git a/app/views/cards/display/_preview.html.erb b/app/views/cards/display/_preview.html.erb index cd5573773..034201131 100644 --- a/app/views/cards/display/_preview.html.erb +++ b/app/views/cards/display/_preview.html.erb @@ -8,9 +8,9 @@ <%= render "cards/display/preview/steps", card: card %> <%= icon_tag "attachment", class: "card__attachments-indicator translucent txt-x-small" if card.has_attachments? %> - <% if card.staged? && card.doing? %> + <% if card.triaged? %> - <%= card.stage.name %> + <%= card.column.name %> <% end %> diff --git a/app/views/collections/columns/_list.html.erb b/app/views/collections/columns/_list.html.erb new file mode 100644 index 000000000..acd87a9b0 --- /dev/null +++ b/app/views/collections/columns/_list.html.erb @@ -0,0 +1 @@ +<%= render partial: "cards/display/preview", collection: cards, as: :card, locals: { draggable: draggable }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %> diff --git a/app/views/collections/columns/not_nows/show.html.erb b/app/views/collections/columns/not_nows/show.html.erb new file mode 100644 index 000000000..ab257f527 --- /dev/null +++ b/app/views/collections/columns/not_nows/show.html.erb @@ -0,0 +1,15 @@ +<%= turbo_frame_tag :not_now_column do %> + + <% if @page.used? %> + <%= render "collections/columns/list", cards: @page.records, draggable: true %> + + <% unless @page.last? %> +
+
+ <% end %> + <% else %> +
+

Drag cards here

+
+ <% end %> +<% end %> diff --git a/app/views/collections/columns/show.html.erb b/app/views/collections/columns/show.html.erb new file mode 100644 index 000000000..4545fa2d6 --- /dev/null +++ b/app/views/collections/columns/show.html.erb @@ -0,0 +1,14 @@ +<%= turbo_frame_tag dom_id(@column, :cards) do %> + <% if @page.used? %> + <%= render "collections/columns/list", cards: @page.records, draggable: true %> + + <% unless @page.last? %> +
+
+ <% end %> + <% else %> +
+

Drag cards here

+
+ <% end %> +<% end %> diff --git a/app/views/collections/columns/streams/show.html.erb b/app/views/collections/columns/streams/show.html.erb new file mode 100644 index 000000000..4631ccb50 --- /dev/null +++ b/app/views/collections/columns/streams/show.html.erb @@ -0,0 +1,14 @@ +<%= turbo_frame_tag :stream_column do %> + <% if @page.used? %> + <%= render "collections/columns/list", cards: @page.records, draggable: true %> + + <% unless @page.last? %> +
+
+ <% end %> + <% else %> +
+

Drag cards here

+
+ <% end %> +<% end %> diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb new file mode 100644 index 000000000..0f60d814f --- /dev/null +++ b/app/views/collections/show.html.erb @@ -0,0 +1,38 @@ +<% @page_title = @collection.name %> +<% turbo_exempts_page_from_cache %> + +<% content_for :head do %> + <%= tag.meta property: "og:title", content: @page_title %> + <%= tag.meta property: "og:description", content: Account.sole.name %> + <%= tag.meta property: "og:url", content: collection_url(@collection) %> +<% end %> + +<% content_for :header do %> +
+ <%= render "cards/webhooks", collection: @collection if Current.user.admin? %> +
+ +

+ <%= @collection.name %> +

+ +
+ <%= render "cards/collection_settings", collection: @collection %> +
+<% end %> + +<%= render "filters/settings", user_filtering: @user_filtering %> + +<%= tag.div data: { + controller: "drag-and-drop", + drag_and_drop_dragged_item_class: "drag-and-drop__dragged-item", + drag_and_drop_hover_container_class: "drag-and-drop__hover-container", + drag_and_drop_url_value: cards_drops_path(**@filter.as_params), + action: " + dragstart->drag-and-drop#dragStart + dragover->drag-and-drop#dragOver + drop->drag-and-drop#drop + dragend->drag-and-drop#dragEnd" } do %> + + <%= render "collections/show/columns", page: @page, collection: @collection %> +<% end %> diff --git a/app/views/collections/show/_closed.html.erb b/app/views/collections/show/_closed.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/collections/show/_column.html.erb b/app/views/collections/show/_column.html.erb new file mode 100644 index 000000000..cab5ddad3 --- /dev/null +++ b/app/views/collections/show/_column.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/collections/show/_columns.html.erb b/app/views/collections/show/_columns.html.erb new file mode 100644 index 000000000..0a1a67136 --- /dev/null +++ b/app/views/collections/show/_columns.html.erb @@ -0,0 +1,20 @@ + <%= turbo_frame_tag :card_columns do %> +
+ +
+ <%= render "collections/show/not_now", collection: collection %> +
+ + <%= render "collections/show/stream", page: page %> + +
+ <%= render partial: "collections/show/column", collection: collection.columns, cached: true %> + <%= render "collections/show/closed", collection: collection %> + + +
+
+ <% end %> diff --git a/app/views/collections/show/_not_now.html.erb b/app/views/collections/show/_not_now.html.erb new file mode 100644 index 000000000..3b4e9f0b0 --- /dev/null +++ b/app/views/collections/show/_not_now.html.erb @@ -0,0 +1,9 @@ + diff --git a/app/views/collections/show/_stream.html.erb b/app/views/collections/show/_stream.html.erb new file mode 100644 index 000000000..70c6970bc --- /dev/null +++ b/app/views/collections/show/_stream.html.erb @@ -0,0 +1,18 @@ +
+
+ + <% if page.used? %> + <%= render "collections/columns/list", cards: @page.records, draggable: true %> + + <% unless page.last? %> +
+
+ <% end %> + <% else %> +
+

Drag cards here

+
+ <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index e22b6173d..f457a0381 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,13 @@ Rails.application.routes.draw do resource :involvement resource :publication resource :entropy_configuration + + namespace :columns do + resource :not_now + resource :stream + end + + resources :columns end resources :cards, only: %i[ create ]