Class: Tiler::Widget
- Inherits:
-
Object
- Object
- Tiler::Widget
- Defined in:
- lib/tiler/widget.rb
Direct Known Subclasses
Tiler::Widgets::BarChart, Tiler::Widgets::Clock, Tiler::Widgets::Comments, Tiler::Widgets::Iframe, Tiler::Widgets::Image, Tiler::Widgets::LineChart, Tiler::Widgets::List, Tiler::Widgets::Meter, Tiler::Widgets::Metric, Tiler::Widgets::NumberWithDelta, Tiler::Widgets::PieChart, Tiler::Widgets::StatusGrid, Tiler::Widgets::Table, Tiler::Widgets::Text
Class Attribute Summary collapse
-
.col_spans ⇒ Object
Returns the value of attribute col_spans.
-
.default_config ⇒ Object
Returns the value of attribute default_config.
-
.default_size ⇒ Object
Returns the value of attribute default_size.
-
.label ⇒ Object
Returns the value of attribute label.
-
.max_size ⇒ Object
Returns the value of attribute max_size.
-
.min_size ⇒ Object
Returns the value of attribute min_size.
-
.partial ⇒ Object
Returns the value of attribute partial.
-
.query_class ⇒ Object
Returns the value of attribute query_class.
-
.type ⇒ Object
Returns the value of attribute type.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#panel ⇒ Object
readonly
Returns the value of attribute panel.
Class Method Summary collapse
-
.example_config ⇒ Object
An example config object for this widget.
-
.example_payload ⇒ Object
An example payload — one record’s JSON shape — that this widget can render against.
-
.example_preview ⇒ Object
An example data hash matching the shape this widget’s partial expects.
-
.supports_color_config? ⇒ Boolean
Whether this widget’s edit form should expose the per-panel color picker.
-
.supports_palette_config? ⇒ Boolean
Whether this widget’s edit form should expose the multi-color palette picker (array of hex).
Instance Method Summary collapse
- #data ⇒ Object
-
#empty?(data) ⇒ Boolean
Default rule for the global “configure your panel” empty state: - Data-backed widget (query_class set) with no data source and no preview data → empty.
-
#initialize(panel) ⇒ Widget
constructor
A new instance of Widget.
- #label ⇒ Object
- #partial ⇒ Object
- #query_class ⇒ Object
Constructor Details
#initialize(panel) ⇒ Widget
Returns a new instance of Widget.
19 20 21 22 |
# File 'lib/tiler/widget.rb', line 19 def initialize(panel) @panel = panel @config = panel.parsed_config end |
Class Attribute Details
.col_spans ⇒ Object
Returns the value of attribute col_spans.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def col_spans @col_spans end |
.default_config ⇒ Object
Returns the value of attribute default_config.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def default_config @default_config end |
.default_size ⇒ Object
Returns the value of attribute default_size.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def default_size @default_size end |
.label ⇒ Object
Returns the value of attribute label.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def label @label end |
.max_size ⇒ Object
Returns the value of attribute max_size.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def max_size @max_size end |
.min_size ⇒ Object
Returns the value of attribute min_size.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def min_size @min_size end |
.partial ⇒ Object
Returns the value of attribute partial.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def partial @partial end |
.query_class ⇒ Object
Returns the value of attribute query_class.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def query_class @query_class end |
.type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/tiler/widget.rb', line 4 def type @type end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/tiler/widget.rb', line 17 def config @config end |
#panel ⇒ Object (readonly)
Returns the value of attribute panel.
17 18 19 |
# File 'lib/tiler/widget.rb', line 17 def panel @panel end |
Class Method Details
.example_config ⇒ Object
An example config object for this widget. Shown verbatim on the panel edit form so users can copy-paste a working starting point. Default falls back to the class-level default_config; override per widget for richer examples (e.g. specifying value_column / group_by for charts).
66 67 68 |
# File 'lib/tiler/widget.rb', line 66 def self.example_config default_config end |
.example_payload ⇒ Object
An example payload — one record’s JSON shape — that this widget can render against. Used to scaffold sample curl commands on the edit page. Default returns a minimal “ok” which most widgets can render with default config.
74 75 76 |
# File 'lib/tiler/widget.rb', line 74 def self.example_payload { "status" => "ok", "value" => 42, "duration" => 142.3 } end |
.example_preview ⇒ Object
An example data hash matching the shape this widget’s partial expects. Wrapped under ‘…` and shown on the edit form so users can paste it into Config to test the widget without a data source. Return nil for config-only widgets (clock/text/iframe/image) — they render their own placeholders and don’t benefit from preview JSON.
83 84 85 |
# File 'lib/tiler/widget.rb', line 83 def self.example_preview nil end |
.supports_color_config? ⇒ Boolean
Whether this widget’s edit form should expose the per-panel color picker. Charts/meters override this to true; default false hides the picker for widgets that don’t render a colored visualization (clock/text/iframe/image/list/table/comments/status_grid).
91 92 93 |
# File 'lib/tiler/widget.rb', line 91 def self.supports_color_config? false end |
.supports_palette_config? ⇒ Boolean
Whether this widget’s edit form should expose the multi-color palette picker (array of hex). Multi-color charts (bar, pie, line) override to true; default false renders only the single-color picker (or none).
98 99 100 |
# File 'lib/tiler/widget.rb', line 98 def self.supports_palette_config? false end |
Instance Method Details
#data ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tiler/widget.rb', line 24 def data # Static-preview escape hatch: if config carries a `_preview` key, use # that as the widget's data and skip the query entirely. Lets users # paste arbitrary JSON into the Config field to preview a widget # without wiring up a data source. preview = config["_preview"] if preview.present? return preview.is_a?(Hash) ? preview.deep_symbolize_keys : preview end return nil if query_class.nil? query_class.new(panel, config).call end |
#empty?(data) ⇒ Boolean
Default rule for the global “configure your panel” empty state:
- Data-backed widget (query_class set) with no data source and no
preview data → empty.
- Config-only widgets (clock/text/iframe/image: query_class nil)
never trigger this — they render their own placeholders.
Subclasses override for stricter checks (e.g. chart widgets look for empty datasets even when a data source IS attached).
56 57 58 59 60 |
# File 'lib/tiler/widget.rb', line 56 def empty?(data) return false unless self.class.query_class return false if config["_preview"].present? panel.data_source.nil? end |
#label ⇒ Object
41 42 43 |
# File 'lib/tiler/widget.rb', line 41 def label self.class.label end |
#partial ⇒ Object
37 38 39 |
# File 'lib/tiler/widget.rb', line 37 def partial self.class.partial || "tiler/widgets/#{self.class.type}" end |
#query_class ⇒ Object
45 46 47 |
# File 'lib/tiler/widget.rb', line 45 def query_class self.class.query_class end |