Class: RailsBase::Admin::IndexTile
- Inherits:
-
Object
- Object
- RailsBase::Admin::IndexTile
- Includes:
- RailsBase::AdminHelper
- Defined in:
- lib/rails_base/admin/index_tile.rb
Constant Summary collapse
- MODIFY_TYPES =
[ RISKY = { type: :risky }, TOGGLE = { type: :toggle, expects: { on: 'String', off: 'String' } }, SELECTOR = { type: :selector, expects: { selector: 'Proc' } }, TEXT = { type: :text, expects: { partial: 'String' } }, BUTTON = { type: :button, expects: { url: 'Proc', method: 'Symbol', color: 'String' } }, PLAIN = { type: :plain }, ]
- VALID_METHODS =
[:get, :post, :delete, :patch, :put]
Constants included from RailsBase::AdminHelper
RailsBase::AdminHelper::SECOND_MODAL_MAPPING, RailsBase::AdminHelper::SESSION_REASON_BASE, RailsBase::AdminHelper::SESSION_REASON_KEY
Instance Attribute Summary collapse
-
#col_name ⇒ Object
Returns the value of attribute col_name.
-
#color ⇒ Object
Returns the value of attribute color.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#disabled_msg ⇒ Object
Returns the value of attribute disabled_msg.
-
#insert ⇒ Object
Returns the value of attribute insert.
-
#link ⇒ Object
Returns the value of attribute link.
-
#method ⇒ Object
Returns the value of attribute method.
-
#min_width ⇒ Object
Returns the value of attribute min_width.
-
#name ⇒ Object
Returns the value of attribute name.
-
#off ⇒ Object
Returns the value of attribute off.
-
#on ⇒ Object
Returns the value of attribute on.
-
#partial ⇒ Object
Returns the value of attribute partial.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.add(instance) ⇒ Object
type: Symbol => values: MODIFY_TYPES.map{|s| s} => what: This is the type of index self will be.
- .defaults ⇒ Object
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(type:, name:, value:, col_name:, disabled: nil, disabled_msg: nil, insert: nil, on: nil, off: nil, selector: [], partial: nil, url: nil, min_width: nil, method: nil, color: 'warning') ⇒ IndexTile
constructor
A new instance of IndexTile.
- #is_button? ⇒ Boolean
- #is_risky? ⇒ Boolean
- #is_selector? ⇒ Boolean
- #is_text? ⇒ Boolean
- #is_toggle? ⇒ Boolean
Methods included from RailsBase::AdminHelper
#accurate_admin_user, #admin_user, #array_for_proc, #filtered_classes, #fullsized_paginated_count, #paginante_class_names, #paginate_admin_can_next?, #paginate_admin_can_prev?, #paginate_admin_history_range, #paginate_admin_what_page, #paginate_can_view_page?, #paginate_diff_id?, #paginate_get_admins_array, #paginate_get_users_array, #paginated_records, #parse_mfa_to_obj, #session_reason, #users_for_proc
Constructor Details
#initialize(type:, name:, value:, col_name:, disabled: nil, disabled_msg: nil, insert: nil, on: nil, off: nil, selector: [], partial: nil, url: nil, min_width: nil, method: nil, color: 'warning') ⇒ IndexTile
Returns a new instance of IndexTile.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rails_base/admin/index_tile.rb', line 87 def initialize(type:, name:, value:, col_name:, disabled: nil, disabled_msg: nil, insert: nil, on: nil, off: nil, selector: [], partial: nil, url: nil, min_width: nil, method: nil, color: 'warning') @type = type @name = name @value = value @col_name = col_name @insert = insert.is_a?(Integer) ? insert : -1 @on = on @off = off @partial = partial @min_width = min_width&.to_i rescue nil @disabled = disabled @disabled_msg = disabled_msg @selector = selector @method = method @url = url @color = color validate! validate_expects! validate_risky! validate_method! validate_disabled! validate_disabled_msg! end |
Instance Attribute Details
#col_name ⇒ Object
Returns the value of attribute col_name.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def col_name @col_name end |
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def color @color end |
#disabled ⇒ Object
Returns the value of attribute disabled.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def disabled @disabled end |
#disabled_msg ⇒ Object
Returns the value of attribute disabled_msg.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def disabled_msg @disabled_msg end |
#insert ⇒ Object
Returns the value of attribute insert.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def insert @insert end |
#link ⇒ Object
Returns the value of attribute link.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def link @link end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def method @method end |
#min_width ⇒ Object
Returns the value of attribute min_width.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def min_width @min_width end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def name @name end |
#off ⇒ Object
Returns the value of attribute off.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def off @off end |
#on ⇒ Object
Returns the value of attribute on.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def on @on end |
#partial ⇒ Object
Returns the value of attribute partial.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def partial @partial end |
#selector ⇒ Object
Returns the value of attribute selector.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def selector @selector end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def url @url end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/rails_base/admin/index_tile.rb', line 6 def value @value end |
Class Method Details
.add(instance) ⇒ Object
type: Symbol
> values: MODIFY_TYPES.map{|s| s}
> what: This is the type of index self will be
name: Symbol
> values: <Anything>
> what: Used as the ‘id` for html. when risky, expected it is a key in RailsBase::AdminController::SECOND_MODAL_MAPPING
value: Proc
> values: Proc that takes a user as an argument ex: ->(current_user) { user.full_name }
> what: Value returned from proc will be value displayed table grid
display: Proc
> values: Proc that takes a user as an argument ex: ->(current_user) { user.full_name }
> what: Boolean returned from proc will allow the element to be changeable
col_name: String
> values: Short String
> what: Value for the Column header
insert: Integer
> values: Expected to be an integer
> what: Column number in the admin view index table
on: String
> values: 1 word for a toggle switch
> what: When toggle is on, this is displayed
off: String
> values: 1 word for a toggle switch
> what: When toggle is off, this is displayed
partial: String
> values: Path to partial
> what: Partial that will get loaded. At present, only for TEXT type
url: Proc
> values: Given a user, Proc that dynamically assigns url based on the user
> what: ->(user) { Rails.application.url_routes.root_path }
min_width: Integer
> values: nil || > 0
> what: Min width for the given table column. When nil passed, none will be set
method: Symbol
> values: [:get, :post, :delete, :patch, :put]
> what: Min width for the given table column. When nil passed, none will be set. Used for Button
method: String
> values: [:get, :post, :delete, :patch, :put]
> what: Min width for the given table column. When nil passed, none will be set. Used for Button
selector: Array
> values: [:get, :post, :delete, :patch, :put]
> what: Min width for the given table column. When nil passed, none will be set. Used for Button
selected: String
> values: [:get, :post, :delete, :patch, :put]
> what: Min width for the given table column. When nil passed, none will be set. Used for Button
78 79 80 81 |
# File 'lib/rails_base/admin/index_tile.rb', line 78 def self.add(instance) @default ||= [] @default.insert(instance.insert, instance) end |
.defaults ⇒ Object
83 84 85 |
# File 'lib/rails_base/admin/index_tile.rb', line 83 def self.defaults @default end |
Instance Method Details
#description ⇒ Object
112 113 114 |
# File 'lib/rails_base/admin/index_tile.rb', line 112 def description "#{type} for #{name}" end |
#is_button? ⇒ Boolean
132 133 134 |
# File 'lib/rails_base/admin/index_tile.rb', line 132 def type == BUTTON[:type] end |
#is_risky? ⇒ Boolean
124 125 126 |
# File 'lib/rails_base/admin/index_tile.rb', line 124 def is_risky? type == RISKY[:type] end |
#is_selector? ⇒ Boolean
120 121 122 |
# File 'lib/rails_base/admin/index_tile.rb', line 120 def is_selector? type == SELECTOR[:type] end |
#is_text? ⇒ Boolean
128 129 130 |
# File 'lib/rails_base/admin/index_tile.rb', line 128 def is_text? type == TEXT[:type] end |
#is_toggle? ⇒ Boolean
116 117 118 |
# File 'lib/rails_base/admin/index_tile.rb', line 116 def is_toggle? type == TOGGLE[:type] end |