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, #each, #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
101
102
103
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 101
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
|
#columns_key ⇒ Object
105
106
107
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 105
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_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
|
125
126
127
|
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 125
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
|
#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
|