Module: FlexiAdmin::Components::Helpers::ResourceHelper

Instance Method Summary collapse

Instance Method Details

#autocomplete_path(action:, fields:, parent: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 6

def autocomplete_path(action:, fields:, parent: nil)
  payload = {
    ac_action: action,
    ac_path: resource__path,
    fa_parent: parent&.gid_param,
    ac_fields: fields
  }
  main_app.send("autocomplete_admin_#{scope_plural}_path", params: payload)
end

#bulk_action_path(scope, **params) ⇒ Object



29
30
31
32
33
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 29

def bulk_action_path(scope, **params)
  raise 'Scope is not defined' if scope.blank?

  main_app.send("bulk_action_admin_#{scope}_path", params:)
end

#datalist_path(action:, fields:, parent: nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 16

def datalist_path(action:, fields:, parent: nil)
  payload = {
    ac_action: action,
    ac_fields: fields
  }

  main_app.send("datalist_admin_#{scope_plural}_path", params: payload)
end

#edit_resource_path(resource, **params) ⇒ Object



25
26
27
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 25

def edit_resource_path(resource, **params)
  main_app.send("edit_admin_#{scope_singular}_path", resource, params:)
end

#paginate(resource, per_page: 10) ⇒ Object



68
69
70
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 68

def paginate(resource, per_page: 10)
  resource.paginate(page: params[:page], per_page:)
end

#resource__pathObject



39
40
41
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 39

def resource__path
  "admin_#{scope_singular}_path"
end

#resource_input_nameObject



47
48
49
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 47

def resource_input_name
  "#{scope_singular}_id"
end

#resource_path(resource, **params) ⇒ Object



35
36
37
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 35

def resource_path(resource, **params)
  main_app.send("admin_#{scope_singular}_path", resource, params:)
end

#resources_path(**params) ⇒ Object



43
44
45
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 43

def resources_path(**params)
  main_app.send("admin_#{scope_plural}_path", params:)
end

#scopeObject



59
60
61
62
63
64
65
66
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 59

def scope
  @scope ||= begin
    return context.scope if defined?(context)
    return resource.model_name.try(:plural) if defined?(resource)

    raise 'Scope is not defined'
  end
end

#scope_pluralObject



51
52
53
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 51

def scope_plural
  scope.gsub('/', '_')
end

#scope_singularObject



55
56
57
# File 'lib/flexi_admin/components/helpers/resource_helper.rb', line 55

def scope_singular
  scope.singularize
end