Files
fizzy/app/controllers/cards_controller.rb
T
Jason Zimdars 04f9a0f83a Merge branch 'main' into add-card-description
* main: (33 commits)
  Run beamer accessories in production only
  Less noisy logging in production
  Inline perma to container partial
  Use card replacement for card updates too
  Extract helper method to keep partial at a uniform level of abstraction
  Remove duplicated conditional
  Style
  Note that we dont want to keep reloading these frames
  I like this even better
  Suffix qualifier is unnnecessary
  Group partials for container
  Match domain language
  Fix trailing space
  Use card rerendering instead of redirects
  Better name
  Stick with domain language
  Fix tests
  Rerender instead of redirect
  Style
  Extract partials that can be rerendered
  ...
2025-04-17 16:40:23 -05:00

59 lines
1.6 KiB
Ruby

require "ostruct"
class CardsController < ApplicationController
include CollectionScoped, FilterScoped
skip_before_action :set_collection, only: :index
before_action :set_card, only: %i[ show edit update destroy ]
PAGE_SIZE = 50
def index
@considering = page_and_filter_for @filter.with(engagement_status: "considering", indexed_by: "latest"), per_page: PAGE_SIZE
@doing = page_and_filter_for @filter.with(engagement_status: "doing", indexed_by: "latest"), per_page: PAGE_SIZE
@closed = page_and_filter_for(@filter.with(indexed_by: "closed"), per_page: PAGE_SIZE) { |cards| cards.recently_closed_first }
end
def create
card = @collection.cards.create!
redirect_to card
end
def show
end
def edit
end
def update
@card.update! card_params
render_card_replacement
end
def destroy
@card.destroy!
redirect_to cards_path(collection_ids: [ @card.collection ]), notice: ("Card deleted" unless @card.creating?)
end
private
def set_card
@card = @collection.cards.find 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 card_params
params.expect(card: [ :status, :title, :description, :image, tag_ids: [] ])
end
def render_card_replacement
render turbo_stream: turbo_stream.replace([ @card, :card_container ], partial: "cards/container", locals: { card: @card.reload })
end
end