Class: ActiveScaffold::DataStructures::ActionColumns
- Inherits:
-
Set
- Object
- Set
- ActiveScaffold::DataStructures::ActionColumns
show all
- Includes:
- Configurable
- Defined in:
- lib/active_scaffold/data_structures/action_columns.rb
Overview
A set of columns. These structures can be nested for organization.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#configure, #method_missing, #respond_to_missing?
Methods inherited from Set
#add, #empty?, #exclude, #find_by_name, #find_by_names, #initialize, #initialize_dup, #set_values
Instance Attribute Details
this lets us refer back to the action responsible for this link, if it exists. the immediate need here is to get the crud_type so we can dynamically filter columns from the set.
8
9
10
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 8
def action
@action
end
|
#collapsed ⇒ Object
Whether this column set is collapsed by default in contexts where collapsing is supported
35
36
37
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 35
def collapsed
@collapsed
end
|
12
13
14
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 12
def label
as_(@label) if @label
end
|
Instance Method Details
#==(other) ⇒ Object
this is so that array.delete and array.include?, etc., will work by column name
25
26
27
28
29
30
31
32
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 25
def ==(other) if other.class == self.class
label == other.label
else
@label.to_s == other.to_s
end
end
|
#action_name ⇒ Object
126
127
128
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 126
def action_name
@action.user_settings_key
end
|
#add_subgroup(label, &proc) ⇒ Object
nests a subgroup in the column set
38
39
40
41
42
43
44
45
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 38
def add_subgroup(label, &proc)
columns = ActiveScaffold::DataStructures::ActionColumns.new
columns.label = label
columns.action = action
columns.configure(&proc)
exclude columns.collect_columns
add columns
end
|
#collect_visible(options = {}, &proc) ⇒ Object
110
111
112
113
114
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 110
def collect_visible(options = {}, &proc)
ActiveSupport::Deprecation.warn "use visible_columns#{"(#{options.inspect})" if options.present?}#{'.map(&proc)' if proc}"
columns = visible_columns(options)
proc ? columns.map(&proc) : columns
end
|
#columns_key ⇒ Object
130
131
132
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 130
def columns_key
"#{@action.core.model_id.to_s.underscore}-#{action_name}"
end
|
#constraint_columns=(columns) ⇒ Object
#css_class ⇒ Object
20
21
22
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 20
def css_class
@label.to_s.underscore.gsub(/[^-_0-9a-zA-Z]/, '-')
end
|
#each(options = nil, &proc) ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 101
def each(options = nil, &proc)
if options
ActiveSupport::Deprecation.warn 'use each_column'
each_column(options, &proc)
else
super(&proc)
end
end
|
#each_column(options = {}, &proc) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 70
def each_column(options = {}, &proc)
columns = options[:core_columns] || action.core.columns
self.unauthorized_columns = []
options[:for] ||= columns.active_record_class
each do |item|
if item.is_a? ActiveScaffold::DataStructures::ActionColumns
if options[:flatten]
item.each_column(options, &proc)
elsif !options[:skip_groups]
yield item
end
else
next if skip_column?(item, options)
yield columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, columns.active_record_class)
end
end
end
|
#include?(item) ⇒ Boolean
47
48
49
50
51
52
53
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 47
def include?(item)
@set.each do |c|
return true if !c.is_a?(Symbol) && c.include?(item)
return true if c == item.to_sym
end
false
end
|
150
151
152
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 150
def length
((@set - constraint_columns) - unauthorized_columns).length
end
|
16
17
18
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 16
def name
@label.to_s.underscore
end
|
116
117
118
119
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 116
def names
ActiveSupport::Deprecation.warn 'use visible_columns.map(&:name)'
visible_columns(flatten: true).map(&:name)
end
|
#names_without_auth_check ⇒ Object
121
122
123
124
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 121
def names_without_auth_check
ActiveSupport::Deprecation.warn 'use to_a'
to_a
end
|
#skip_column?(column_name, options) ⇒ Boolean
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 59
def skip_column?(column_name, options)
return true if constraint_columns.include?(column_name.to_sym)
unless options[:for].authorized_for?(action: options[:action], crud_type: options[:crud_type] || action&.crud_type || :read, column: column_name)
unauthorized_columns << column_name.to_sym
return true
end
false
end
|
55
56
57
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 55
def to_a
Array(@set)
end
|
#unauthorized_columns ⇒ Object
#unauthorized_columns=(columns) ⇒ Object
#visible_columns(options = {}) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 89
def visible_columns(options = {})
columns = []
each_column(options) do |column|
columns << column
end
columns
end
|
#visible_columns_names(options = {}) ⇒ Object
97
98
99
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 97
def visible_columns_names(options = {})
visible_columns(options.reverse_merge(flatten: true)).map(&:name)
end
|