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 list chart embed workflow_graph approval_status].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.
22 23 24 25 26 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 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 22 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.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def apply_scope_context @apply_scope_context end |
#area ⇒ Object (readonly)
Returns the value of attribute area.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def area @area end |
#default_scope ⇒ Object (readonly)
Returns the value of attribute default_scope.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def default_scope @default_scope end |
#depends_on ⇒ Object (readonly)
Returns the value of attribute depends_on.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def depends_on @depends_on end |
#eager ⇒ Object (readonly)
Returns the value of attribute eager.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def eager @eager end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def filters @filters end |
#label_key ⇒ Object (readonly)
Returns the value of attribute label_key.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def label_key @label_key end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def limit @limit end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def name @name end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def partial @partial end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def position @position end |
#presenter ⇒ Object (readonly)
Returns the value of attribute presenter.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def presenter @presenter end |
#raw_apply_scope_context ⇒ Object (readonly)
Returns the value of attribute raw_apply_scope_context.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def raw_apply_scope_context @raw_apply_scope_context end |
#raw_eager ⇒ Object (readonly)
Returns the value of attribute raw_eager.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def raw_eager @raw_eager end |
#record_click ⇒ Object (readonly)
Returns the value of attribute record_click.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def record_click @record_click end |
#record_source_param ⇒ Object (readonly)
Returns the value of attribute record_source_param.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def record_source_param @record_source_param end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def scope @scope end |
#scope_context ⇒ Object (readonly)
Returns the value of attribute scope_context.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def scope_context @scope_context end |
#selection ⇒ Object (readonly)
Returns the value of attribute selection.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def selection @selection end |
#submit_redirect ⇒ Object (readonly)
Returns the value of attribute submit_redirect.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def submit_redirect @submit_redirect end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def type @type end |
#visible_when ⇒ Object (readonly)
Returns the value of attribute visible_when.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def visible_when @visible_when end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def @widget end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
16 17 18 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16 def width @width end |
Class Method Details
.from_hash(hash) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 57 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
94 95 96 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 94 def custom? @type == :custom end |
#depends_on? ⇒ Boolean
depends_on predicates
168 169 170 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 168 def depends_on? @depends_on.present? end |
#eager? ⇒ Boolean
98 99 100 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 98 def eager? @eager end |
#filterable? ⇒ Boolean
132 133 134 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 132 def filterable? !filters_none? end |
#filters_full? ⇒ Boolean
124 125 126 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 124 def filters_full? @filters == :full end |
#filters_none? ⇒ Boolean
128 129 130 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 128 def filters_none? @filters == :none end |
#filters_quick? ⇒ Boolean
Filter predicates
120 121 122 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 120 def filters_quick? @filters == :quick end |
#form_zone? ⇒ Boolean
Form zone predicates
150 151 152 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 150 def form_zone? @submit_redirect.present? end |
#grid_position ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 110 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
102 103 104 105 106 107 108 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 102 def label if @label_key.present? I18n.t(@label_key, default: @name.humanize) else @name.humanize end end |
#presenter_zone? ⇒ Boolean
90 91 92 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 90 def presenter_zone? @type == :presenter end |
#record_click_dialog? ⇒ Boolean
141 142 143 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 141 def record_click_dialog? @record_click == :dialog end |
#record_click_navigate? ⇒ Boolean
Record click predicates
137 138 139 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 137 def record_click_navigate? @record_click == :navigate end |
#record_click_none? ⇒ Boolean
145 146 147 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 145 def record_click_none? @record_click == :none end |
#record_source? ⇒ Boolean
Record source predicates
159 160 161 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 159 def record_source? @record_source_param.present? end |
#record_source_selection? ⇒ Boolean
163 164 165 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 163 def record_source_selection? @record_source_param == "selected" end |
#selection? ⇒ Boolean
Selection predicates
173 174 175 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 173 def selection? @selection.present? end |
#selection_single? ⇒ Boolean
177 178 179 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 177 def selection_single? @selection == :single end |
#submit_redirect_self? ⇒ Boolean
154 155 156 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 154 def submit_redirect_self? @submit_redirect == :self end |
#widget? ⇒ Boolean
86 87 88 |
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 86 def @type == :widget end |