Class: AdminSuite::UI::RowDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_suite/ui/dashboard_definition.rb

Overview

DSL used inside row do ... end.

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ RowDSL

Returns a new instance of RowDSL.



32
33
34
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 32

def initialize(row)
  @row = row
end

Instance Method Details

#cards_panel(title, resources: nil, span: nil, **options, &block) ⇒ Object



62
63
64
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 62

def cards_panel(title, resources: nil, span: nil, **options, &block)
  panel(:cards, title, span: span, **options.merge(resources: resources, block: block))
end

#chart_panel(title, data: nil, span: nil, **options, &block) ⇒ Object

type: selects the Chart.js chart type: :bar (default), :line, :area (a line chart rendered with fill), or :doughnut. It flows through **options untouched by this method -- the _chart.html.erb partial is what validates it, falling back to :bar with a logged warning for anything else, so a host typo degrades rather than breaking the dashboard.



57
58
59
60
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 57

def chart_panel(title, data: nil, span: nil, **options, &block)
  data_proc = data.is_a?(Proc) ? data : (block_given? ? block : nil)
  panel(:chart, title, span: span, **options.merge(data: data_proc || data))
end

#health_panel(title, status: nil, metrics: nil, span: nil, **options, &block) ⇒ Object



47
48
49
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 47

def health_panel(title, status: nil, metrics: nil, span: nil, **options, &block)
  panel(:health, title, span: span, **options.merge(status: status, metrics: metrics, block: block))
end

#panel(type, title = nil, span: nil, **options, &block) ⇒ Object



36
37
38
39
40
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 36

def panel(type, title = nil, span: nil, **options, &block)
  options[:span] = span if span
  options[:block] = block if block_given?
  @row.panels << PanelDefinition.new(type: type.to_sym, title: title, options: options)
end

#recent_panel(title, scope: nil, link: nil, span: nil, **options, &block) ⇒ Object



66
67
68
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 66

def recent_panel(title, scope: nil, link: nil, span: nil, **options, &block)
  panel(:recent, title, span: span, **options.merge(scope: scope, link: link, block: block))
end

#stat_panel(title, value = nil, span: nil, **options, &block) ⇒ Object



42
43
44
45
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 42

def stat_panel(title, value = nil, span: nil, **options, &block)
  value_proc = value.is_a?(Proc) ? value : (block_given? ? block : nil)
  panel(:stat, title, span: span, **options.merge(value: value_proc || value))
end

#table_panel(title, rows: nil, columns: nil, span: nil, **options, &block) ⇒ Object



70
71
72
# File 'lib/admin_suite/ui/dashboard_definition.rb', line 70

def table_panel(title, rows: nil, columns: nil, span: nil, **options, &block)
  panel(:table, title, span: span, **options.merge(rows: rows, columns: columns, block: block))
end