diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index adfa4394c..8a8b4fb05 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -41,14 +41,6 @@ class CardsController < ApplicationController end private - def page_and_filter_for_closed_cards - if @filter.indexed_by.stalled? - page_and_filter_for(@filter, per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } - else - page_and_filter_for(@filter.with(indexed_by: "closed"), per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } - end - end - def set_card @card = @collection.cards.find params[:id] end @@ -61,6 +53,14 @@ class CardsController < ApplicationController filter: filter end + def page_and_filter_for_closed_cards + if @filter.indexed_by.stalled? + page_and_filter_for(@filter, per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } + else + page_and_filter_for(@filter.with(indexed_by: "closed"), per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } + end + end + def card_params params.expect(card: [ :status, :title, :description, :image, tag_ids: [] ]) end diff --git a/app/controllers/public/collections_controller.rb b/app/controllers/public/collections_controller.rb new file mode 100644 index 000000000..91926a0e4 --- /dev/null +++ b/app/controllers/public/collections_controller.rb @@ -0,0 +1,38 @@ +class Public::CollectionsController < ApplicationController + allow_unauthenticated_access only: :show + + before_action :set_collection + + layout "public" + + PAGE_SIZE = 50 + + def show + @filter = Current.user.filters.build + + @considering = page_and_filter_for @filter.with(engagement_status: "considering"), per_page: PAGE_SIZE + @doing = page_and_filter_for @filter.with(engagement_status: "doing"), per_page: PAGE_SIZE + @closed = page_and_filter_for_closed_cards + end + + private + def set_collection + @collection = Collection.find_by_published_key(params[:id]) + end + + def page_and_filter_for(filter, per_page: nil) + cards = block_given? ? yield(filter.cards) : filter.cards + + OpenStruct.new \ + page: GearedPagination::Recordset.new(cards, per_page:).page(1), + filter: filter + end + + def page_and_filter_for_closed_cards + if @filter.indexed_by.stalled? + page_and_filter_for(@filter, per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } + else + page_and_filter_for(@filter.with(indexed_by: "closed"), per_page: PAGE_SIZE) { |cards| cards.recently_closed_first } + end + end +end diff --git a/app/models/collection/publishable.rb b/app/models/collection/publishable.rb index 373ca4a21..cee1b6e11 100644 --- a/app/models/collection/publishable.rb +++ b/app/models/collection/publishable.rb @@ -6,6 +6,12 @@ module Collection::Publishable scope :published, ->{ joins(:publication) } end + class_methods do + def find_by_published_key(key) + Collection::Publication.find_by!(key: key).collection + end + end + def published? publication.present? end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b667bfb47..03b4727c2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,29 +1,6 @@ -
- <%= page_title_tag %> - - - - - - - <%= csrf_meta_tags %> - <%= csp_meta_tag %> - <%= tag.meta name: "current-user-id", content: Current.user.id if Current.user %> - - <% turbo_refreshes_with method: :morph, scroll: :preserve %> - - <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> - <%= javascript_importmap_tags %> - - <%= yield :head %> - - - - - - + <%= render "layouts/shared/head" %>