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

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.



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 = 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.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def apply_scope_context
  @apply_scope_context
end

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

#eagerObject (readonly)

Returns the value of attribute eager.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def eager
  @eager
end

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

#limitObject (readonly)

Returns the value of attribute limit.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def limit
  @limit
end

#modelObject (readonly)

Returns the value of attribute model.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def name
  @name
end

#partialObject (readonly)

Returns the value of attribute partial.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def partial
  @partial
end

#positionObject (readonly)

Returns the value of attribute position.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def position
  @position
end

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

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

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

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

#widgetObject (readonly)

Returns the value of attribute widget.



16
17
18
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 16

def widget
  @widget
end

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

Returns:

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

Returns:

  • (Boolean)


168
169
170
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 168

def depends_on?
  @depends_on.present?
end

#eager?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 98

def eager?
  @eager
end

#filterable?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 132

def filterable?
  !filters_none?
end

#filters_full?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 124

def filters_full?
  @filters == :full
end

#filters_none?Boolean

Returns:

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


150
151
152
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 150

def form_zone?
  @submit_redirect.present?
end

#grid_positionObject



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

#labelObject



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

Returns:

  • (Boolean)


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

def presenter_zone?
  @type == :presenter
end

#record_click_dialog?Boolean

Returns:

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

Returns:

  • (Boolean)


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

Returns:

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

Returns:

  • (Boolean)


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

Returns:

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

Returns:

  • (Boolean)


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

def selection?
  @selection.present?
end

#selection_single?Boolean

Returns:

  • (Boolean)


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

def selection_single?
  @selection == :single
end

#submit_redirect_self?Boolean

Returns:

  • (Boolean)


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

def submit_redirect_self?
  @submit_redirect == :self
end

#widget?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/lcp_ruby/metadata/zone_definition.rb', line 86

def widget?
  @type == :widget
end