Class: RivetCms::TrashController

Inherits:
ApplicationController show all
Includes:
InertiaProps
Defined in:
app/controllers/rivet_cms/trash_controller.rb

Overview

One place to find everything trashed, so recovering does not depend on remembering which content type something belonged to. Entries of removed types are represented by their type below: restoring the type brings its entries back with it.

Instance Method Summary collapse

Instance Method Details

#showObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/rivet_cms/trash_controller.rb', line 11

def show
  scope = trashed_entries
  if params[:type].present?
    scope = scope.joins(:content_type).where(rivet_cms_content_types: { slug: params[:type] })
  end
  scope = scope.search(params[:q]) if params[:q].present?
  page = scope.includes(:content_type, :draft_revision).order(deleted_at: :desc).page(params[:page]).per(25)
  entries = permitted_documents(page)
  titles = document_titles(entries)

  render inertia: "Trash/Show", props: {
    documents: entries.map { |document|
      document_list_props(document, titles).merge(
        content_type_name: document.content_type.name,
        trashed_at: document.deleted_at.iso8601,
        paths: {
          restore: restore_content_type_document_path(document.content_type, document),
          purge: purge_content_type_document_path(document.content_type, document)
        }
      )
    },
    q: params[:q].presence,
    type: params[:type].presence,
    # Filter options come from what is actually trashed, like media kinds
    types: filter_types,
    pagination: { page: page.current_page, total_pages: page.total_pages },
    content_types: removed_content_types
  }
end