Class: LcpRuby::Metadata::ZoneDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Metadata::ZoneDefinition
- Defined in:
- lib/lcp_ruby/metadata/zone_definition.rb
Constant Summary collapse
- VALID_AREAS =
%w[main tabs sidebar below].freeze
- VALID_WIDGET_TYPES =
%w[kpi_card text rich_text markdown list chart embed workflow_graph approval_status].freeze
- I18N_TEXT_WIDGET_TYPES =
i18n-string widget types — neither depends on a model scope, all require ‘content_key`, none are valid targets for `depends_on` (no data dependency to refresh on).
%w[text rich_text markdown].freeze
- VALID_CHART_TYPES =
%w[line bar column pie donut area].freeze
- PIE_CHART_TYPES =
%w[pie donut].freeze
- VALID_CHART_LEGEND_STRINGS =
%w[auto top bottom left right].freeze
- VALID_CHART_SORTS =
%w[asc desc none value_asc value_desc].freeze
- VALID_FILTERS =
%i[full quick none].freeze
- VALID_RECORD_CLICKS =
%i[navigate dialog none].freeze
- VALID_SUBMIT_REDIRECTS =
%i[self].freeze
- VALID_SELECTIONS =
%i[single].freeze
Instance Attribute Summary collapse
-
#apply_scope_context ⇒ Object
readonly
Returns the value of attribute apply_scope_context.
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#default_scope ⇒ Object
readonly
Returns the value of attribute default_scope.
-
#depends_on ⇒ Object
readonly
Returns the value of attribute depends_on.
-
#eager ⇒ Object
readonly
Returns the value of attribute eager.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#label_key ⇒ Object
readonly
Returns the value of attribute label_key.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#presenter ⇒ Object
readonly
Returns the value of attribute presenter.
-
#raw_apply_scope_context ⇒ Object
readonly
Returns the value of attribute raw_apply_scope_context.
-
#raw_eager ⇒ Object
readonly
Returns the value of attribute raw_eager.
-
#record_click ⇒ Object
readonly
Returns the value of attribute record_click.
-
#record_source_param ⇒ Object
readonly
Returns the value of attribute record_source_param.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#scope_context ⇒ Object
readonly
Returns the value of attribute scope_context.
-
#selection ⇒ Object
readonly
Returns the value of attribute selection.
-
#submit_redirect ⇒ Object
readonly
Returns the value of attribute submit_redirect.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#visible_when ⇒ Object
readonly
Returns the value of attribute visible_when.
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #custom? ⇒ Boolean
-
#depends_on? ⇒ Boolean
depends_on predicates.
- #eager? ⇒ Boolean
- #filterable? ⇒ Boolean
- #filters_full? ⇒ Boolean
- #filters_none? ⇒ Boolean
-
#filters_quick? ⇒ Boolean
Filter predicates.
-
#form_zone? ⇒ Boolean
Form zone predicates.
- #grid_position ⇒ Object
-
#initialize(name:, presenter: nil, area: "main", type: :presenter, widget: nil, position: nil, scope: nil, limit: nil, visible_when: nil, scope_context: nil, label_key: nil, default_scope: nil, width: nil, filters: nil, record_click: nil, submit_redirect: nil, record_source: nil, depends_on: nil, selection: nil, partial: nil, model: nil, eager: nil, apply_scope_context: nil) ⇒ ZoneDefinition
constructor
A new instance of ZoneDefinition.
- #label ⇒ Object
- #presenter_zone? ⇒ Boolean
- #record_click_dialog? ⇒ Boolean
-
#record_click_navigate? ⇒ Boolean
Record click predicates.
- #record_click_none? ⇒ Boolean
-
#record_source? ⇒ Boolean
Record source predicates.
- #record_source_selection? ⇒ Boolean
-
#selection? ⇒ Boolean
Selection predicates.
- #selection_single? ⇒ Boolean
- #submit_redirect_self? ⇒ Boolean
- #widget? ⇒ Boolean
Constructor Details
#initialize(name:, presenter: nil, area: "main", type: :presenter, widget: nil, position: nil, scope: nil, limit: nil, visible_when: nil, scope_context: nil, label_key: nil, default_scope: nil, width: nil, filters: nil, record_click: nil, submit_redirect: nil, record_source: nil, depends_on: nil, selection: nil, partial: nil, model: nil, eager: nil, apply_scope_context: nil) ⇒ ZoneDefinition
Returns a new instance of ZoneDefinition.
27 28 29 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 'lib/lcp_ruby/metadata/zone_definition.rb', line 27 def initialize(name:, presenter: nil, area: "main", type: :presenter, widget: nil, position: nil, scope: nil, limit: nil, visible_when: nil, scope_context: nil, label_key: nil, default_scope: nil, width: nil, filters: nil, record_click: nil, submit_redirect: nil, record_source: nil, depends_on: nil, selection: nil, partial: nil, model: nil, eager: nil, apply_scope_context: nil) @name = name.to_s @presenter = presenter&.to_s @area = (area || "main").to_s @type = (type || :presenter).to_sym @widget = .is_a?(Hash) ? HashUtils.stringify_deep() : nil @position = position.is_a?(Hash) ? HashUtils.stringify_deep(position) : nil @scope = scope&.to_s @limit = limit&.to_i @visible_when = visible_when.is_a?(Hash) ? HashUtils.stringify_deep(visible_when) : nil @scope_context = scope_context.is_a?(Hash) ? HashUtils.stringify_deep(scope_context) : nil @label_key = label_key&.to_s @default_scope = default_scope&.to_s.presence @width = width&.to_i @filters = resolve_filters(filters) @record_click = resolve_record_click(record_click) @submit_redirect = submit_redirect&.to_s&.to_sym.presence @record_source_param = extract_record_source_param(record_source) @depends_on = Array(depends_on).map(&:to_s).presence @selection = resolve_selection(selection) @partial = partial&.to_s @model = model&.to_s.presence @eager = eager == true @apply_scope_context = apply_scope_context.nil? ? true : apply_scope_context == true @raw_eager = eager @raw_apply_scope_context = apply_scope_context validate! end |
Instance Attribute Details
#apply_scope_context ⇒ Object (readonly)
Returns the value of attribute apply_scope_context.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def apply_scope_context @apply_scope_context end |
#area ⇒ Object (readonly)
Returns the value of attribute area.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def area @area end |
#default_scope ⇒ Object (readonly)
Returns the value of attribute default_scope.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def default_scope @default_scope end |
#depends_on ⇒ Object (readonly)
Returns the value of attribute depends_on.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def depends_on @depends_on end |
#eager ⇒ Object (readonly)
Returns the value of attribute eager.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def eager @eager end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def filters @filters end |
#label_key ⇒ Object (readonly)
Returns the value of attribute label_key.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def label_key @label_key end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def limit @limit end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def name @name end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def partial @partial end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def position @position end |
#presenter ⇒ Object (readonly)
Returns the value of attribute presenter.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def presenter @presenter end |
#raw_apply_scope_context ⇒ Object (readonly)
Returns the value of attribute raw_apply_scope_context.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def raw_apply_scope_context @raw_apply_scope_context end |
#raw_eager ⇒ Object (readonly)
Returns the value of attribute raw_eager.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def raw_eager @raw_eager end |
#record_click ⇒ Object (readonly)
Returns the value of attribute record_click.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def record_click @record_click end |
#record_source_param ⇒ Object (readonly)
Returns the value of attribute record_source_param.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def record_source_param @record_source_param end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def scope @scope end |
#scope_context ⇒ Object (readonly)
Returns the value of attribute scope_context.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def scope_context @scope_context end |
#selection ⇒ Object (readonly)
Returns the value of attribute selection.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def selection @selection end |
#submit_redirect ⇒ Object (readonly)
Returns the value of attribute submit_redirect.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def submit_redirect @submit_redirect end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def type @type end |
#visible_when ⇒ Object (readonly)
Returns the value of attribute visible_when.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def visible_when @visible_when end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def @widget end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
21 22 23 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21 def width @width end |
Class Method Details
.from_hash(hash) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 62 def self.from_hash(hash) hash = HashUtils.stringify_deep(hash) new( name: hash["name"], presenter: hash["presenter"], area: hash["area"], type: hash["type"] || :presenter, widget: hash["widget"], position: hash["position"], scope: hash["scope"], limit: hash["limit"], visible_when: hash["visible_when"], scope_context: hash["scope_context"], label_key: hash["label_key"], default_scope: hash["default_scope"], width: hash["width"], filters: hash["filters"], record_click: hash["record_click"], submit_redirect: hash["submit_redirect"], record_source: hash["record_source"], depends_on: hash["depends_on"], selection: hash["selection"], partial: hash["partial"], model: hash["model"], eager: hash["eager"], apply_scope_context: hash["apply_scope_context"] ) end |
Instance Method Details
#custom? ⇒ Boolean
99 100 101 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 99 def custom? @type == :custom end |
#depends_on? ⇒ Boolean
depends_on predicates
173 174 175 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 173 def depends_on? @depends_on.present? end |
#eager? ⇒ Boolean
103 104 105 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 103 def eager? @eager end |
#filterable? ⇒ Boolean
137 138 139 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 137 def filterable? !filters_none? end |
#filters_full? ⇒ Boolean
129 130 131 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 129 def filters_full? @filters == :full end |
#filters_none? ⇒ Boolean
133 134 135 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 133 def filters_none? @filters == :none end |
#filters_quick? ⇒ Boolean
Filter predicates
125 126 127 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 125 def filters_quick? @filters == :quick end |
#form_zone? ⇒ Boolean
Form zone predicates
155 156 157 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 155 def form_zone? @submit_redirect.present? end |
#grid_position ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 115 def grid_position return {} unless @position style = {} style["grid-row"] = "#{@position['row']} / span #{@position['height'] || 1}" if @position["row"] style["grid-column"] = "#{@position['col']} / span #{@position['width'] || 1}" if @position["col"] style end |
#label ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 107 def label if @label_key.present? I18n.t(@label_key, default: @name.humanize) else @name.humanize end end |
#presenter_zone? ⇒ Boolean
95 96 97 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 95 def presenter_zone? @type == :presenter end |
#record_click_dialog? ⇒ Boolean
146 147 148 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 146 def record_click_dialog? @record_click == :dialog end |
#record_click_navigate? ⇒ Boolean
Record click predicates
142 143 144 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 142 def record_click_navigate? @record_click == :navigate end |
#record_click_none? ⇒ Boolean
150 151 152 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 150 def record_click_none? @record_click == :none end |
#record_source? ⇒ Boolean
Record source predicates
164 165 166 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 164 def record_source? @record_source_param.present? end |
#record_source_selection? ⇒ Boolean
168 169 170 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 168 def record_source_selection? @record_source_param == "selected" end |
#selection? ⇒ Boolean
Selection predicates
178 179 180 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 178 def selection? @selection.present? end |
#selection_single? ⇒ Boolean
182 183 184 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 182 def selection_single? @selection == :single end |
#submit_redirect_self? ⇒ Boolean
159 160 161 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 159 def submit_redirect_self? @submit_redirect == :self end |
#widget? ⇒ Boolean
91 92 93 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 91 def @type == :widget end |