Module: Avo::ApplicationHelper

Instance Method Summary collapse

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #resource_grid, #resource_show_path, #resource_table

Instance Method Details

#a_button(**args, &block) ⇒ Object



18
19
20
21
22
# File 'app/helpers/avo/application_helper.rb', line 18

def a_button(**args, &block)
  render Avo::ButtonComponent.new(is_link: false, **args) do
    capture(&block) if block.present?
  end
end


24
25
26
27
28
# File 'app/helpers/avo/application_helper.rb', line 24

def a_link(path = nil, **args, &block)
  render Avo::ButtonComponent.new(path, is_link: true, **args) do
    capture(&block) if block.present?
  end
end

#button_classes(extra_classes = nil, color: nil, variant: nil, size: :md, active: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/avo/application_helper.rb', line 30

def button_classes(extra_classes = nil, color: nil, variant: nil, size: :md, active: false)
  classes = "inline-flex flex-grow-0 items-center text-sm font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 rounded transform transition duration-100 active:translate-x-px active:translate-y-px cursor-pointer disabled:cursor-not-allowed #{extra_classes}"

  if color.present?
    if variant.present? && (variant.to_sym == :outlined)
      classes += " bg-white border"

      classes += " hover:border-#{color}-700 border-#{color}-500 text-#{color}-600 hover:text-#{color}-700 disabled:border-gray-300 disabled:text-gray-600"
    else
      classes += " text-white bg-#{color}-500 hover:bg-#{color}-600 disabled:bg-#{color}-300"
    end
  else
    classes += " text-gray-700 bg-white hover:bg-gray-100 disabled:bg-gray-300"
  end

  size = size.present? ? size.to_sym : :md
  classes += case size
  when :xs
    " p-2 py-1"
  when :sm
    " py-1 px-4"
  when :md
    " py-2 px-4"
  when :xl
    " py-3 px-4"
  else
    " p-4"
  end

  classes
end

#card_classesObject



91
92
93
# File 'app/helpers/avo/application_helper.rb', line 91

def card_classes
  "bg-white rounded shadow-panel"
end

#chart_color(index) ⇒ Object



140
141
142
# File 'app/helpers/avo/application_helper.rb', line 140

def chart_color(index)
  Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length]
end

#decode_filter_params(encoded_params) ⇒ Object



113
114
115
# File 'app/helpers/avo/application_helper.rb', line 113

def decode_filter_params(encoded_params)
  Avo::Filters::BaseFilter.decode_filters(encoded_params)
end

#empty_state(**args) ⇒ Object



14
15
16
# File 'app/helpers/avo/application_helper.rb', line 14

def empty_state(**args)
  render Avo::EmptyStateComponent.new(**args)
end

#encode_filter_params(filter_params) ⇒ Object



117
118
119
# File 'app/helpers/avo/application_helper.rb', line 117

def encode_filter_params(filter_params)
  Avo::Filters::BaseFilter.encode_filters(filter_params)
end

#frame_id(resource) ⇒ Object



136
137
138
# File 'app/helpers/avo/application_helper.rb', line 136

def frame_id(resource)
  ["frame", resource.model_name.singular, resource.record_param].compact.join("-")
end

#get_model_class(model) ⇒ Object



95
96
97
98
99
100
101
# File 'app/helpers/avo/application_helper.rb', line 95

def get_model_class(model)
  if model.instance_of?(Class)
    model
  else
    model.class
  end
end

#input_classes(extra_classes = "", has_error: false) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/avo/application_helper.rb', line 73

def input_classes(extra_classes = "", has_error: false)
  classes = "appearance-none inline-flex bg-gray-25 disabled:cursor-not-allowed text-gray-600 disabled:opacity-50 rounded py-2 px-3 leading-tight border focus:border-gray-600 focus-visible:ring-0 focus:text-gray-700 placeholder:text-gray-300"

  classes += if has_error
    " border-red-600"
  else
    " border-gray-200"
  end

  classes += " #{extra_classes}"

  classes
end

#mount_pathObject



109
110
111
# File 'app/helpers/avo/application_helper.rb', line 109

def mount_path
  Avo::Engine.routes.find_script_name(params.permit!.to_h.symbolize_keys)
end

#number_to_social(number, start_at: 10_000) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/helpers/avo/application_helper.rb', line 121

def number_to_social(number, start_at: 10_000)
  return number_with_delimiter(number) if number < start_at

  number_to_human(number,
    precision: 1,
    significant: false,
    round_mode: :down,
    format: "%n%u",
    units: {
      thousand: "K",
      million: "M",
      billion: "B"
    })
end

#render_license_warning(title: "", message: "", icon: "exclamation") ⇒ Object



6
7
8
9
10
11
12
# File 'app/helpers/avo/application_helper.rb', line 6

def render_license_warning(title: "", message: "", icon: "exclamation")
  render partial: "avo/sidebar/license_warning", locals: {
    title: title,
    message: message,
    icon: icon
  }
end

#root_path_without_urlObject



103
104
105
106
107
# File 'app/helpers/avo/application_helper.rb', line 103

def root_path_without_url
  "#{Avo.configuration.prefix_path}#{mount_path}"
rescue
  Avo.configuration.root_path
end

#svg(file_name, **args) ⇒ Object

Use inline_svg gem but with our own finder implementation.



63
64
65
66
67
68
69
70
71
# File 'app/helpers/avo/application_helper.rb', line 63

def svg(file_name, **args)
  return if file_name.blank?

  file_name = "#{file_name}.svg" unless file_name.end_with? ".svg"

  with_asset_finder(::Avo::SvgFinder) do
    inline_svg file_name, **args
  end
end

#white_panel_classesObject



87
88
89
# File 'app/helpers/avo/application_helper.rb', line 87

def white_panel_classes
  "bg-white rounded shadow-md"
end