Class: ActiveAdmin::Favorites::ViewLens::Layout
- Inherits:
-
Object
- Object
- ActiveAdmin::Favorites::ViewLens::Layout
- Defined in:
- app/models/active_admin/favorites/view_lens/layout.rb
Constant Summary collapse
- VERSION =
1
Instance Attribute Summary collapse
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
Class Method Summary collapse
Instance Method Summary collapse
- #hidden_action_item?(action_name) ⇒ Boolean
- #hidden_action_items ⇒ Object
- #hidden_column?(column_id) ⇒ Boolean
- #hidden_columns ⇒ Object
- #hidden_filter?(filter_id) ⇒ Boolean
- #hidden_filters ⇒ Object
- #hidden_panel?(panel_id) ⇒ Boolean
- #hidden_panels ⇒ Object
- #hidden_show_row?(row_id) ⇒ Boolean
- #hidden_show_rows ⇒ Object
-
#initialize(raw_layout) ⇒ Layout
constructor
A new instance of Layout.
- #merge(other) ⇒ Object
Constructor Details
#initialize(raw_layout) ⇒ Layout
Returns a new instance of Layout.
28 29 30 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 28 def initialize(raw_layout) @layout = self.class.normalize(raw_layout) end |
Instance Attribute Details
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
32 33 34 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 32 def layout @layout end |
Class Method Details
.empty ⇒ Object
24 25 26 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 24 def self.empty new({}) end |
.normalize(raw_layout) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 9 def self.normalize(raw_layout) layout = raw_layout.is_a?(Hash) ? raw_layout.deep_stringify_keys : {} hidden = layout.fetch("hidden", {}) { "version" => layout.fetch("version", VERSION), "hidden" => { "columns" => Array(hidden["columns"]).map(&:to_s), "filters" => Array(hidden["filters"]).map(&:to_s), "action_items" => Array(hidden["action_items"]).map(&:to_s), "panels" => Array(hidden["panels"]).map(&:to_s), "show_rows" => Array(hidden["show_rows"]).map(&:to_s) } } end |
Instance Method Details
#hidden_action_item?(action_name) ⇒ Boolean
62 63 64 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 62 def hidden_action_item?(action_name) action_name.present? && hidden_action_items.include?(action_name.to_s) end |
#hidden_action_items ⇒ Object
42 43 44 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 42 def hidden_action_items @layout.dig("hidden", "action_items") end |
#hidden_column?(column_id) ⇒ Boolean
54 55 56 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 54 def hidden_column?(column_id) column_id.present? && hidden_columns.include?(column_id.to_s) end |
#hidden_columns ⇒ Object
34 35 36 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 34 def hidden_columns @layout.dig("hidden", "columns") end |
#hidden_filter?(filter_id) ⇒ Boolean
58 59 60 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 58 def hidden_filter?(filter_id) filter_id.present? && hidden_filters.include?(filter_id.to_s) end |
#hidden_filters ⇒ Object
38 39 40 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 38 def hidden_filters @layout.dig("hidden", "filters") end |
#hidden_panel?(panel_id) ⇒ Boolean
66 67 68 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 66 def hidden_panel?(panel_id) panel_id.present? && hidden_panels.include?(panel_id.to_s) end |
#hidden_panels ⇒ Object
46 47 48 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 46 def hidden_panels @layout.dig("hidden", "panels") end |
#hidden_show_row?(row_id) ⇒ Boolean
70 71 72 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 70 def hidden_show_row?(row_id) row_id.present? && hidden_show_rows.include?(row_id.to_s) end |
#hidden_show_rows ⇒ Object
50 51 52 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 50 def hidden_show_rows @layout.dig("hidden", "show_rows") end |
#merge(other) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/models/active_admin/favorites/view_lens/layout.rb', line 74 def merge(other) return self if other.blank? other_layout = self.class.normalize(other.layout || other) merged_hidden = layout.fetch("hidden", {}).merge(other_layout.fetch("hidden", {})) do |_key, left, right| (left + right).uniq end self.class.new("version" => VERSION, "hidden" => merged_hidden) end |