Class: LcpRuby::Metadata::ZoneDefinition

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 = widget.is_a?(Hash) ? HashUtils.stringify_deep(widget) : 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_contextObject (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

#areaObject (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_scopeObject (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_onObject (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

#eagerObject (readonly)

Returns the value of attribute eager.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def eager
  @eager
end

#filtersObject (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_keyObject (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

#limitObject (readonly)

Returns the value of attribute limit.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def limit
  @limit
end

#modelObject (readonly)

Returns the value of attribute model.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def name
  @name
end

#partialObject (readonly)

Returns the value of attribute partial.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def partial
  @partial
end

#positionObject (readonly)

Returns the value of attribute position.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def position
  @position
end

#presenterObject (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_contextObject (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_eagerObject (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_clickObject (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_paramObject (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

#scopeObject (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_contextObject (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

#selectionObject (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_redirectObject (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

#typeObject (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_whenObject (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

#widgetObject (readonly)

Returns the value of attribute widget.



21
22
23
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 21

def widget
  @widget
end

#widthObject (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

Returns:

  • (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

Returns:

  • (Boolean)


173
174
175
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 173

def depends_on?
  @depends_on.present?
end

#eager?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 103

def eager?
  @eager
end

#filterable?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 137

def filterable?
  !filters_none?
end

#filters_full?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 129

def filters_full?
  @filters == :full
end

#filters_none?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


155
156
157
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 155

def form_zone?
  @submit_redirect.present?
end

#grid_positionObject



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

#labelObject



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

Returns:

  • (Boolean)


95
96
97
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 95

def presenter_zone?
  @type == :presenter
end

#record_click_dialog?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (Boolean)


178
179
180
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 178

def selection?
  @selection.present?
end

#selection_single?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 182

def selection_single?
  @selection == :single
end

#submit_redirect_self?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 159

def submit_redirect_self?
  @submit_redirect == :self
end

#widget?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 91

def widget?
  @type == :widget
end