Class: Para::Admin::CrudResourcesController

Inherits:
ResourcesController show all
Includes:
ResourceControllerConcerns, SearchHelper, TagHelper
Defined in:
app/controllers/para/admin/crud_resources_controller.rb

Instance Method Summary collapse

Methods included from TagHelper

#add_button_for, #icon_link_to, #listing_for, #table_for

Methods included from SearchHelper

#distinct_search_results, #filtered?, #fulltext_search_param_for, #searchable_attributes

Methods inherited from ResourcesController

#create, #destroy, #edit, #new, #order, #tree, #update

Methods included from Helpers::AttributesMappings

#attributes_mappings_for

Methods included from ModelHelper

#attribute_field_mappings_for, #excerpt_value_for, #field_for, #field_value_for, #model_field_mappings, #relation_klass_for, #value_for

Methods inherited from BaseController

#current_ability, #current_admin

Methods included from BaseHelper

#find_partial_for, #find_relation_name_for, #flash_message, #registered_components_options, #resource_title_for, #template_path_lookup

Methods included from Helpers::ResourceName

#resource_name

Methods inherited from Para::ApplicationController

#admin?

Instance Method Details

#cloneObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/para/admin/crud_resources_controller.rb', line 35

def clone
  new_resource = resource.deep_clone!
  new_resource.save!

  if new_resource.save
    component_resource = Para::ComponentResource.where(
      resource: resource
    ).first

    if component_resource
      Para::ComponentResource.create! do |record|
        record.resource = new_resource
        record.component = component_resource.component
      end
    end

    flash_message(:success, new_resource)
    redirect_to @component.relation_path(new_resource, action: :edit), status: 303
  else
    flash_message(:error, new_resource)
    render after_form_submit_path, status: 422
  end
end

#indexObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/para/admin/crud_resources_controller.rb', line 19

def index
  @q = @component.resources.ransack(params[:q])
  @resources = distinct_search_results(@q).page(params[:page]).per(params[:per_page])

  # Sort collection for orderable and trees
  @resources = if @resources.respond_to?(:ordered)
                 @resources.ordered
               else
                 @resources.order(created_at: :desc)
               end

  return unless turbo_frame_request?

  listing_for(@resources)
end