Class: Admin::TrashController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::TrashController
- Includes:
- AuditLoggable
- Defined in:
- lib/generators/ruby_cms/templates/controllers/admin/trash_controller.rb
Constant Summary collapse
- DISCARDABLE =
Models we expose in the trash UI. Each must
include Discard::Model. { "visitor_errors" => "VisitorError", "content_blocks" => "ContentBlock", "redirects" => "Redirect" }.freeze
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /admin/trash/:model/:id.
- #index ⇒ Object
-
#restore ⇒ Object
POST /admin/trash/:model/:id/restore.
Instance Method Details
#destroy ⇒ Object
DELETE /admin/trash/:model/:id
44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/trash_controller.rb', line 44 def destroy record = locate_record return redirect_to(admin_trash_path, alert: "Niet gevonden.") unless record label = "#{record.class.name}##{record.id}" record.destroy audit!(:trashed_item_purged, target: label, summary: "Purged #{label}", meta: { id: record.id }) redirect_to admin_trash_path, notice: "Permanent verwijderd." end |
#index ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/trash_controller.rb', line 20 def index @groups = DISCARDABLE.filter_map do |slug, class_name| klass = class_name.safe_constantize next unless klass&.respond_to?(:discarded) items = klass.discarded.order(discarded_at: :desc).limit(50) next if items.empty? { slug: slug, klass: klass, label: class_name.titleize, items: items } end @total = @groups.sum { |g| g[:items].size } end |
#restore ⇒ Object
POST /admin/trash/:model/:id/restore
34 35 36 37 38 39 40 41 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/trash_controller.rb', line 34 def restore record = locate_record return redirect_to(admin_trash_path, alert: "Niet gevonden.") unless record record.undiscard audit!(:trashed_item_restored, target: record, summary: "Restored #{record.class.name}##{record.id}") redirect_to admin_trash_path, notice: "Hersteld." end |