active_scaffold_config_list 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +69 -3
- data/app/views/active_scaffold_overrides/_list.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_named_views.html.erb +10 -13
- data/app/views/active_scaffold_overrides/_show_config_list_form.html.erb +13 -15
- data/app/views/active_scaffold_overrides/_show_config_list_form_body.html.erb +60 -49
- data/app/views/active_scaffold_overrides/show_config_list_form.html.erb +1 -1
- data/lib/active_scaffold/actions/config_list.rb +9 -2
- data/lib/active_scaffold/config/config_list.rb +17 -2
- data/lib/active_scaffold/data_structures/named_view.rb +6 -0
- data/lib/active_scaffold/helpers/config_list_helpers.rb +33 -12
- data/lib/active_scaffold_config_list/version.rb +1 -1
- data/lib/active_scaffold_config_list.rb +12 -1
- metadata +6 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd4aa6db1cf82232099715da904d5927b2b8a91d578745e58cdfac14fced1f8e
|
|
4
|
+
data.tar.gz: a789114e4b22710b30eb90df83a544f2861c188013f158e9aa51bb4edd468ee2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d8f89d0344fd9cef930a2b670bb5c2c77f42e80d3636b188cb4370cac1319097bc50b91e3cde4581f316b3414b0f04c8832f69dc30183deac8a3c33426a35c0
|
|
7
|
+
data.tar.gz: cc9420929d95e2503b7732816f8cdffaf5adfbb8a43f810fd59735b1c1670da125c20e46f5353de83ca5eb42824be83239144172bd13fa2fb4e51e3dbf4d11c3
|
data/README.md
CHANGED
|
@@ -41,7 +41,7 @@ It's possible to define named views, with a set of columns, so users can switch
|
|
|
41
41
|
conf.config_list.add_view :simple, [:number, :status]
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Although it's possible to use a block too, to change other view settings, such as label, sorting and
|
|
44
|
+
Although it's possible to use a block too, to change other view settings, such as label, sorting, security method and the partial used to render the list. If the label is set, it can be a string, or a symbol to be localized, and the name is used in the URL parameters. When using a block, the columns can be defined in the view instead of the `add_view` call:
|
|
45
45
|
|
|
46
46
|
```rb
|
|
47
47
|
conf.config_list.add_view :simple do |view|
|
|
@@ -49,11 +49,20 @@ conf.config_list.add_view :simple do |view|
|
|
|
49
49
|
view.columns = [:number, :status]
|
|
50
50
|
view.sorting = {number: :desc}
|
|
51
51
|
view.security_method = :simple_view_authorized?
|
|
52
|
+
view.view = 'compact_list'
|
|
52
53
|
end
|
|
53
54
|
```
|
|
54
55
|
|
|
56
|
+
When `view` is set, the named view renders that partial instead of ActiveScaffold's default list partial. The custom partial can use the same assigns and helpers as the normal list.
|
|
57
|
+
|
|
55
58
|
The columns defined in the view are not required to be in the `conf.list.columns`, so it's possible to add views including columns that are not available in the normal config list.
|
|
56
59
|
|
|
60
|
+
Set `tooltip` to add a title to the view in the selector:
|
|
61
|
+
|
|
62
|
+
```rb
|
|
63
|
+
view.tooltip = 'PTO and HR policy'
|
|
64
|
+
```
|
|
65
|
+
|
|
57
66
|
The security method is a controller method used to check if the view is available for the user, it must return true when the view is allowed:
|
|
58
67
|
|
|
59
68
|
```rb
|
|
@@ -64,7 +73,7 @@ end
|
|
|
64
73
|
|
|
65
74
|
When a named view is selected, the configure action link is not rendered.
|
|
66
75
|
|
|
67
|
-
The view selector is displayed in the title header, and it's rendered as a menu of links, displaying the selected view, and the list of available views on hover. The selector can be changed to a list of radio buttons or select field with `conf.config_list.named_views_selector`,per controller, or it can be changed globally in `ActiveScaffold.defaults`:
|
|
76
|
+
The view selector is displayed in the title header, and it's rendered as a menu of links, displaying the selected view, and the list of available views on hover. The selector can be changed to a list of radio buttons or select field with `conf.config_list.named_views_selector`, per controller, or it can be changed globally in `ActiveScaffold.defaults`:
|
|
68
77
|
|
|
69
78
|
```rb
|
|
70
79
|
conf.config_list.named_views_selector = :radio # use radio buttons
|
|
@@ -72,6 +81,20 @@ conf.config_list.named_views_selector = :select # use select field
|
|
|
72
81
|
conf.config_list.named_views_selector = :links # use a menu of links (default)
|
|
73
82
|
```
|
|
74
83
|
|
|
84
|
+
A named view can be selected by default when the request does not contain `config_list_view`:
|
|
85
|
+
|
|
86
|
+
```rb
|
|
87
|
+
conf.config_list.default_view = 'Calendar'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
An explicit empty `config_list_view` still selects the ordinary, unnamed list view. For a request-dependent default, set the parameter in a controller callback before ActiveScaffold processes the index action instead of using this static setting.
|
|
91
|
+
|
|
92
|
+
The unnamed choice, shown as "Default" in the selector, is included unless `unnamed_view_security_method` is configured. It is the configurable list that uses saved/session columns or `config_list.default_columns`; it is separate from the named view selected by `default_view`. The method runs on the controller and must return true to include the unnamed choice. This controls selector visibility; applications must still enforce authorization for the underlying list action.
|
|
93
|
+
|
|
94
|
+
```rb
|
|
95
|
+
conf.config_list.unnamed_view_security_method = :unnamed_list_view_authorized?
|
|
96
|
+
```
|
|
97
|
+
|
|
75
98
|
The position of the views selector can be changed with `conf.config_list.named_views_position`, setting it to `:center` (default, between the title and actions), `:left` (next to the title) or `:right` (at the right of the actions). Although the position of the `div.config-list-views` doesn't change, it just adds a class (center, right or left) and use CSS of flexbox layout to change the position (changing `flex-grow` and `order`). It can be changed per controller or globally in `ActiveScaffold.defaults`:
|
|
76
99
|
|
|
77
100
|
```rb
|
|
@@ -80,6 +103,49 @@ conf.config_list.named_views_position = :left
|
|
|
80
103
|
conf.config_list.named_views_position = :right
|
|
81
104
|
```
|
|
82
105
|
|
|
106
|
+
The selector and configuration form expose their markup through ActiveScaffold's UI registry. Elements rendered with `as_element` have a default tag that applications may replace with `ActiveScaffold.set_element_tag`. Attribute-only entries are applied to tags produced by Rails helpers such as `form_tag`, `select_tag`, or `radio_button_tag`.
|
|
107
|
+
|
|
108
|
+
Named-view selector elements:
|
|
109
|
+
|
|
110
|
+
| UI element | Rendered control | Purpose |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| `config_list_views` | `<div>` | Outer container when the selector is `:links`; it receives `config-list-views` and the configured position class. |
|
|
113
|
+
| `config_list_views_form` | `<form>` attributes | Outer form when the selector is `:radio` or `:select`; use it for layout or behavior classes such as `no-autofocus`. |
|
|
114
|
+
| `config_list_view_selected` | `<div>` | Currently selected view displayed by the links selector. |
|
|
115
|
+
| `config_list_views_list` | `<ul>` | Dropdown list containing the links-selector choices. |
|
|
116
|
+
| `config_list_view_item` | `<li>` | One links-selector choice; the current choice also receives `selected`. |
|
|
117
|
+
| `config_list_view_link` | `<a>` attributes | Remote link that selects a view; its `title` contains the named-view tooltip. |
|
|
118
|
+
| `config_list_view_select` | `<select>` attributes | Select control used by the `:select` selector. |
|
|
119
|
+
| `config_list_view_option` | `<option>` attributes | One option in the select selector; its `title` contains the named-view tooltip. |
|
|
120
|
+
| `config_list_view_label` | `<label>` | Label wrapping a radio and its text; its `title` contains the named-view tooltip. |
|
|
121
|
+
| `config_list_view_radio` | `<input type="radio">` attributes | Radio control used by the `:radio` selector. |
|
|
122
|
+
|
|
123
|
+
For example:
|
|
124
|
+
|
|
125
|
+
```rb
|
|
126
|
+
ActiveScaffold.add_element_attributes(:config_list_view_label, class: 'label text-sm')
|
|
127
|
+
ActiveScaffold.add_element_attributes(:config_list_view_radio, class: 'radio radio-xs')
|
|
128
|
+
ActiveScaffold.add_element_attributes(:config_list_view_link, class: 'link')
|
|
129
|
+
ActiveScaffold.add_element_attributes(:config_list_view_select, class: 'select select-sm')
|
|
130
|
+
ActiveScaffold.add_element_attributes(:config_list_views_form, class: 'no-autofocus')
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Configuration-form elements:
|
|
134
|
+
|
|
135
|
+
| UI element | Rendered control | Purpose |
|
|
136
|
+
| --- | --- | --- |
|
|
137
|
+
| `config_list_columns` | `<ul>` attributes | Checkbox-list container used to select and order visible columns. |
|
|
138
|
+
| `config_list_column` | `<li>` attributes | One entry in the columns checkbox list; it receives `sortable`. |
|
|
139
|
+
| `config_list_sorting` | `<ol>` | Container for the configurable sorting levels. |
|
|
140
|
+
| `config_list_sorting_item` | `<li>` | One sorting level containing its column and direction controls. |
|
|
141
|
+
| `config_list_sorting_column` | `<select>` attributes | Column selector for one sorting level; it receives `column`. |
|
|
142
|
+
| `config_list_sorting_order` | `<select>` attributes | Ascending/descending selector for one sorting level; it receives `order`. |
|
|
143
|
+
| `config_list_view_name` | `<input type="text">` attributes | Name field used to save or rename a view; core ActiveScaffold text-input attributes are also applied. |
|
|
144
|
+
| `config_list_view_rename` | `<label>` | Rename option wrapper; it receives the `rename-view` class required by the JavaScript behavior. |
|
|
145
|
+
| `config_list_view_rename_checkbox` | `<input type="checkbox">` attributes | Checkbox inside the rename option. |
|
|
146
|
+
| `config_list_view_global` | `<label>` | Global-view option wrapper; it receives the `global-view` class required by the JavaScript behavior. |
|
|
147
|
+
| `config_list_view_global_checkbox` | `<input type="checkbox">` attributes | Checkbox choosing whether a saved view is global. |
|
|
148
|
+
|
|
83
149
|
## Saving to DB
|
|
84
150
|
|
|
85
151
|
The configuration data can be saved on the DB. Define a model to store the list configuration, it must have a config_list
|
|
@@ -291,4 +357,4 @@ def config_list_views(controller_id, controller_name)
|
|
|
291
357
|
end
|
|
292
358
|
```
|
|
293
359
|
|
|
294
|
-
It's possible to user other column names than `view_name` and `slug`, just ensure the values are set from `attributes[:view_name]` and `attributes[:slug]`, and use the right column names in the queries.
|
|
360
|
+
It's possible to user other column names than `view_name` and `slug`, just ensure the values are set from `attributes[:view_name]` and `attributes[:slug]`, and use the right column names in the queries.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render named_view&.view || :super %>
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
%>
|
|
12
|
-
<%= send(method, arg, attributes) do %>
|
|
13
|
-
<%= active_scaffold_named_view_selector %>
|
|
1
|
+
<% selector_class = "config-list-views #{active_scaffold_config.config_list.named_views_position}" %>
|
|
2
|
+
<% if active_scaffold_config.config_list.named_views_selector == :links %>
|
|
3
|
+
<%= as_element :config_list_views, class: selector_class do %>
|
|
4
|
+
<%= active_scaffold_named_view_selector %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% else %>
|
|
7
|
+
<% attributes = as_element_attributes(:config_list_views_form, class: selector_class, remote: true, method: :get) %>
|
|
8
|
+
<%= form_tag params_for(action: :index, config_list_view: nil), attributes do %>
|
|
9
|
+
<%= active_scaffold_named_view_selector %>
|
|
10
|
+
<% end %>
|
|
14
11
|
<% end %>
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
<% url_options = params_for(action: :config_list) -%>
|
|
2
|
-
<%=
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
</p>
|
|
16
|
-
</form>
|
|
2
|
+
<%= render partial: 'base_form', locals: {form_action: :config_list,
|
|
3
|
+
method: :post,
|
|
4
|
+
url_options: url_options,
|
|
5
|
+
body_partial: 'show_config_list_form_body',
|
|
6
|
+
multipart: false,
|
|
7
|
+
persistent: false,
|
|
8
|
+
field_descriptions: :show,
|
|
9
|
+
cancel_link: true,
|
|
10
|
+
cancel_text: params[:config_list_view].present? ? :delete : :reset,
|
|
11
|
+
cancel_attrs: {data: {refresh: true, method: :post}},
|
|
12
|
+
cancel_url: url_for(url_options.merge(config_list: '')),
|
|
13
|
+
headline: active_scaffold_config.config_list.label} %>
|
|
14
|
+
|
|
@@ -1,58 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
<%= as_element :fields_container, class: 'form' do %>
|
|
2
2
|
<% if config_list_columns? %>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
4
|
+
<%
|
|
5
|
+
columns_options = as_element_attributes(
|
|
6
|
+
:config_list_columns,
|
|
7
|
+
name: 'config_list',
|
|
8
|
+
id: "#{element_form_id(action: :config_list)}-columns",
|
|
9
|
+
class: ('sortable-container' unless active_scaffold_config.config_list.draggable)
|
|
10
|
+
).to_h
|
|
11
|
+
content = active_scaffold_checkbox_list(
|
|
12
|
+
nil,
|
|
13
|
+
config_list_columns,
|
|
14
|
+
config_list_params || config_list_columns.map(&:last),
|
|
15
|
+
columns_options,
|
|
16
|
+
ui_options: {
|
|
17
|
+
draggable_lists: active_scaffold_config.config_list.draggable,
|
|
18
|
+
item_options: as_element_attributes(:config_list_column, class: 'sortable').to_h
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
%>
|
|
22
|
+
<%= form_attribute_html(nil, as_(:columns), content, nil, {}) %>
|
|
23
|
+
<% end %>
|
|
19
24
|
<% end %>
|
|
25
|
+
|
|
20
26
|
<% if config_list_sorting? %>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<%
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
%>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
28
|
+
<% content = capture do %>
|
|
29
|
+
<%= as_element :config_list_sorting do %>
|
|
30
|
+
<%
|
|
31
|
+
columns_options = list_columns.select(&:sortable?).map { |c| [c.label, c.name] }
|
|
32
|
+
order_options = ['asc', 'desc'].map { |v| [as_(v), v] }
|
|
33
|
+
selected = config_list_sorting || []
|
|
34
|
+
3.times do |i|
|
|
35
|
+
%>
|
|
36
|
+
<%= as_element :config_list_sorting_item do %>
|
|
37
|
+
<%= select_tag "config_list_sorting[#{i}][]", options_for_select(columns_options, selected: selected[i]&.first), as_element_attributes(:config_list_sorting_column, include_blank: as_(:_select_), class: 'column') %>
|
|
38
|
+
<%= select_tag "config_list_sorting[#{i}][]", options_for_select(order_options, selected: selected[i]&.last), as_element_attributes(:config_list_sorting_order, include_blank: as_(:_select_), class: 'order') %>
|
|
39
|
+
<% end %>
|
|
40
|
+
<% end %>
|
|
41
|
+
<% end %>
|
|
42
|
+
<% end %>
|
|
43
|
+
<%= form_attribute_html(nil, as_(:default_sorting), content, nil, {}) %>
|
|
44
|
+
<% end %>
|
|
35
45
|
<% end %>
|
|
36
46
|
|
|
37
47
|
<% if config_list_save_named_views? %>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</label>
|
|
48
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
49
|
+
<% content = capture do %>
|
|
50
|
+
<% name_options = active_scaffold_input_text_options(required: @config_list_view_name.present?) %>
|
|
51
|
+
<%= text_field_tag "config_list_view_name", @config_list_view_name.to_s, as_element_attributes(:config_list_view_name, **name_options) %>
|
|
52
|
+
<% if @config_list_view_name.present? %>
|
|
53
|
+
<%= as_element :config_list_view_rename, class: 'rename-view', style: 'display: none;' do %>
|
|
54
|
+
<%= check_box_tag 'config_list_old_view_name', params[:config_list_view], false, **as_element_attributes(:config_list_view_rename_checkbox, id: nil).to_h %>
|
|
55
|
+
<%= as_ :rename_view, view_name: @config_list_view_name %>
|
|
47
56
|
<% end %>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
<% end %>
|
|
58
|
+
<% if config_list_global_views? %>
|
|
59
|
+
<%= as_element :config_list_view_global, class: 'global-view', style: ('display: none;' if @config_list_view_name.blank?) do %>
|
|
60
|
+
<%= hidden_field_tag 'global_view', @global_view ? '1' : '' %>
|
|
61
|
+
<%= check_box_tag 'global_view', '1', @global_view, **as_element_attributes(:config_list_view_global_checkbox, id: nil, disabled: true).to_h %>
|
|
62
|
+
<%= as_ :global_view %>
|
|
54
63
|
<% end %>
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
<% end %>
|
|
65
|
+
<% end %>
|
|
66
|
+
<%= form_attribute_html(nil, as_(:view_name), content, nil, {}) %>
|
|
67
|
+
<% end %>
|
|
57
68
|
<% end %>
|
|
58
|
-
|
|
69
|
+
<% end %>
|
|
@@ -2,7 +2,7 @@ module ActiveScaffold::Actions
|
|
|
2
2
|
module ConfigList
|
|
3
3
|
|
|
4
4
|
def self.included(base)
|
|
5
|
-
base.before_action :set_default_sorting, :change_view, only: [:index]
|
|
5
|
+
base.before_action :set_default_view, :set_default_sorting, :change_view, only: [:index]
|
|
6
6
|
base.before_action :config_list_authorized_filter, only: [:show_config_list, :config_list]
|
|
7
7
|
base.helper_method :config_list_params, :config_list_sorting, :config_list_named_views
|
|
8
8
|
end
|
|
@@ -23,6 +23,13 @@ module ActiveScaffold::Actions
|
|
|
23
23
|
|
|
24
24
|
protected
|
|
25
25
|
|
|
26
|
+
def set_default_view
|
|
27
|
+
return unless params[:config_list_view].nil?
|
|
28
|
+
|
|
29
|
+
default_view = active_scaffold_config.config_list.default_view
|
|
30
|
+
params[:config_list_view] = default_view.to_s if default_view.present?
|
|
31
|
+
end
|
|
32
|
+
|
|
26
33
|
def change_view
|
|
27
34
|
active_scaffold_config.list.refresh_with_header = true if params[:config_list_view]
|
|
28
35
|
end
|
|
@@ -251,7 +258,7 @@ module ActiveScaffold::Actions
|
|
|
251
258
|
end
|
|
252
259
|
|
|
253
260
|
def named_view
|
|
254
|
-
return unless params[:config_list_view].present?
|
|
261
|
+
return @named_view unless params[:config_list_view].present?
|
|
255
262
|
|
|
256
263
|
@named_view ||= active_scaffold_config.config_list.named_views.find { |v| v.name == params[:config_list_view] }
|
|
257
264
|
end
|
|
@@ -9,6 +9,8 @@ module ActiveScaffold::Config
|
|
|
9
9
|
@draggable = self.class.draggable
|
|
10
10
|
@named_views_position = self.class.named_views_position
|
|
11
11
|
@named_views_selector = self.class.named_views_selector
|
|
12
|
+
@default_view = self.class.default_view
|
|
13
|
+
@unnamed_view_security_method = self.class.unnamed_view_security_method
|
|
12
14
|
@global_views = self.class.global_views
|
|
13
15
|
@named_views = []
|
|
14
16
|
end
|
|
@@ -44,6 +46,12 @@ module ActiveScaffold::Config
|
|
|
44
46
|
cattr_accessor :named_views_selector
|
|
45
47
|
@@named_views_selector = :links
|
|
46
48
|
|
|
49
|
+
# named view selected when config_list_view is not present in the request
|
|
50
|
+
cattr_accessor :default_view
|
|
51
|
+
|
|
52
|
+
# method used to check whether the unnamed, configurable list view is available
|
|
53
|
+
cattr_accessor :unnamed_view_security_method
|
|
54
|
+
|
|
47
55
|
# if saving global views is allowed, or named views are always saved for the current user only
|
|
48
56
|
cattr_accessor :global_views
|
|
49
57
|
|
|
@@ -83,6 +91,12 @@ module ActiveScaffold::Config
|
|
|
83
91
|
# the type of selector for named views, :links, :select or :radio
|
|
84
92
|
attr_accessor :named_views_selector
|
|
85
93
|
|
|
94
|
+
# named view selected when config_list_view is not present in the request
|
|
95
|
+
attr_accessor :default_view
|
|
96
|
+
|
|
97
|
+
# method used to check whether the unnamed, configurable list view is available
|
|
98
|
+
attr_accessor :unnamed_view_security_method
|
|
99
|
+
|
|
86
100
|
# if saving global views is allowed, or named views are always saved for the current user only
|
|
87
101
|
attr_accessor :global_views
|
|
88
102
|
|
|
@@ -106,7 +120,8 @@ module ActiveScaffold::Config
|
|
|
106
120
|
view = ::ActiveScaffold::DataStructures::NamedView.new(name, self)
|
|
107
121
|
view.columns = columns if columns
|
|
108
122
|
yield view if block_given?
|
|
109
|
-
|
|
123
|
+
view.columns ||= [] if view.view
|
|
124
|
+
raise ArgumentError, "no columns defined for view '#{name}'" if view.view.blank? && view.columns.empty?
|
|
110
125
|
|
|
111
126
|
@named_views << view
|
|
112
127
|
view
|
|
@@ -114,7 +129,7 @@ module ActiveScaffold::Config
|
|
|
114
129
|
|
|
115
130
|
UserSettings.class_eval do
|
|
116
131
|
user_attr :default_columns, :save_to_user, :named_views_method, :draggable,
|
|
117
|
-
:named_views_position, :named_views_selector, :global_views
|
|
132
|
+
:named_views_position, :named_views_selector, :default_view, :unnamed_view_security_method, :global_views
|
|
118
133
|
|
|
119
134
|
def label
|
|
120
135
|
@conf.label(core: core)
|
|
@@ -17,6 +17,12 @@ module ActiveScaffold::DataStructures
|
|
|
17
17
|
# default sorting used with this view instead of default
|
|
18
18
|
attr_accessor :sorting
|
|
19
19
|
|
|
20
|
+
# custom partial used to render the list for this view
|
|
21
|
+
attr_accessor :view
|
|
22
|
+
|
|
23
|
+
# additional information displayed as a title in the view selector
|
|
24
|
+
attr_accessor :tooltip
|
|
25
|
+
|
|
20
26
|
def initialize(name, action)
|
|
21
27
|
@name = name.to_s
|
|
22
28
|
@action = action
|
|
@@ -9,6 +9,14 @@ module ActiveScaffold
|
|
|
9
9
|
true
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def ignore_param_for_nested?(key)
|
|
13
|
+
super || key == :config_list_view
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def named_view
|
|
17
|
+
controller.send(:named_view) if active_scaffold_config.actions.include?(:config_list)
|
|
18
|
+
end
|
|
19
|
+
|
|
12
20
|
def config_list_save_named_views?
|
|
13
21
|
active_scaffold_config.config_list.named_views_method.present?
|
|
14
22
|
end
|
|
@@ -44,18 +52,24 @@ module ActiveScaffold
|
|
|
44
52
|
def named_views_from_config
|
|
45
53
|
active_scaffold_config.config_list.named_views.filter_map do |view|
|
|
46
54
|
next if view.security_method && !controller.send(view.security_method)
|
|
47
|
-
[view.label, view.name]
|
|
55
|
+
[view.label, view.name, view.tooltip]
|
|
48
56
|
end
|
|
49
57
|
end
|
|
50
58
|
|
|
59
|
+
def config_list_unnamed_view?
|
|
60
|
+
security_method = active_scaffold_config.config_list.unnamed_view_security_method
|
|
61
|
+
security_method.nil? || controller.send(security_method)
|
|
62
|
+
end
|
|
63
|
+
|
|
51
64
|
def active_scaffold_named_view_selector
|
|
52
65
|
named_views = user_named_views + named_views_from_config
|
|
53
66
|
return unless named_views.any?
|
|
54
67
|
|
|
55
|
-
named_views.unshift [as_(:default_view), '']
|
|
68
|
+
named_views.unshift [as_(:default_view), ''] if config_list_unnamed_view?
|
|
56
69
|
html = config_list_view_options(named_views, params[:config_list_view].to_s)
|
|
57
70
|
if active_scaffold_config.config_list.named_views_selector == :select
|
|
58
|
-
|
|
71
|
+
select_options = as_element_attributes(:config_list_view_select, id: nil)
|
|
72
|
+
html = select_tag('config_list_view', html, select_options)
|
|
59
73
|
end
|
|
60
74
|
html
|
|
61
75
|
end
|
|
@@ -65,22 +79,29 @@ module ActiveScaffold
|
|
|
65
79
|
when :links
|
|
66
80
|
url = url_for(params_for(action: :index, config_list_view: '--VIEW--'))
|
|
67
81
|
view = nil
|
|
68
|
-
links = named_views.map do |
|
|
82
|
+
links = named_views.map do |label, name, tooltip|
|
|
69
83
|
name ||= label
|
|
70
|
-
|
|
84
|
+
link_options = as_element_attributes(:config_list_view_link, remote: true, title: tooltip)
|
|
85
|
+
link = link_to(label, url.sub('--VIEW--', ERB::Util.unwrapped_html_escape(name)), link_options)
|
|
71
86
|
view = label if name == selected
|
|
72
|
-
|
|
87
|
+
as_element :config_list_view_item, link, class: ('selected' if name == selected)
|
|
73
88
|
end
|
|
74
|
-
|
|
89
|
+
as_element(:config_list_view_selected, view || as_(:default_view), class: 'selected-view') +
|
|
90
|
+
as_element(:config_list_views_list, safe_join(links), class: 'views')
|
|
75
91
|
|
|
76
92
|
when :select
|
|
77
|
-
|
|
93
|
+
options = named_views.map do |label, name, tooltip|
|
|
94
|
+
option_attributes = as_element_attributes(:config_list_view_option, title: tooltip).to_h.compact
|
|
95
|
+
[label, name || label, option_attributes]
|
|
96
|
+
end
|
|
97
|
+
options_for_select(options, selected)
|
|
78
98
|
|
|
79
99
|
when :radio
|
|
80
|
-
buttons = named_views.map do |
|
|
100
|
+
buttons = named_views.map do |label, name, tooltip|
|
|
81
101
|
name ||= label
|
|
82
|
-
|
|
83
|
-
|
|
102
|
+
radio_options = as_element_attributes(:config_list_view_radio, id: nil)
|
|
103
|
+
as_element(:config_list_view_label, title: tooltip) do
|
|
104
|
+
radio_button_tag('config_list_view', name, name == selected, **radio_options.to_h) + label
|
|
84
105
|
end
|
|
85
106
|
end
|
|
86
107
|
safe_join(buttons)
|
|
@@ -88,4 +109,4 @@ module ActiveScaffold
|
|
|
88
109
|
end
|
|
89
110
|
end
|
|
90
111
|
end
|
|
91
|
-
end
|
|
112
|
+
end
|
|
@@ -19,5 +19,16 @@ module ActiveScaffold
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
ActiveSupport.run_load_hooks(:active_scaffold_config_list)
|
|
22
|
+
{
|
|
23
|
+
config_list_views: :div,
|
|
24
|
+
config_list_view_selected: :div,
|
|
25
|
+
config_list_views_list: :ul,
|
|
26
|
+
config_list_view_item: :li,
|
|
27
|
+
config_list_view_label: :label,
|
|
28
|
+
config_list_sorting: :ol,
|
|
29
|
+
config_list_sorting_item: :li,
|
|
30
|
+
config_list_view_rename: :label,
|
|
31
|
+
config_list_view_global: :label
|
|
32
|
+
}.each { |name, tag| ActiveScaffold.set_element_tag(name, tag) }
|
|
22
33
|
ActiveScaffold.stylesheets << 'active_scaffold_config_list'
|
|
23
|
-
ActiveScaffold.javascripts << 'active_scaffold_config_list'
|
|
34
|
+
ActiveScaffold.javascripts << 'active_scaffold_config_list'
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_scaffold_config_list
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Cambra
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: active_scaffold
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 4.
|
|
18
|
+
version: 4.4.0
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 4.
|
|
25
|
+
version: 4.4.0
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: active_scaffold_sortable
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -49,6 +48,7 @@ files:
|
|
|
49
48
|
- README.md
|
|
50
49
|
- app/assets/javascripts/active_scaffold_config_list.js
|
|
51
50
|
- app/assets/stylesheets/active_scaffold_config_list.scss
|
|
51
|
+
- app/views/active_scaffold_overrides/_list.html.erb
|
|
52
52
|
- app/views/active_scaffold_overrides/_list_header.html.erb
|
|
53
53
|
- app/views/active_scaffold_overrides/_named_views.html.erb
|
|
54
54
|
- app/views/active_scaffold_overrides/_show_config_list_form.html.erb
|
|
@@ -73,7 +73,6 @@ homepage: http://activescaffold.com
|
|
|
73
73
|
licenses:
|
|
74
74
|
- MIT
|
|
75
75
|
metadata: {}
|
|
76
|
-
post_install_message:
|
|
77
76
|
rdoc_options: []
|
|
78
77
|
require_paths:
|
|
79
78
|
- lib
|
|
@@ -88,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
87
|
- !ruby/object:Gem::Version
|
|
89
88
|
version: '0'
|
|
90
89
|
requirements: []
|
|
91
|
-
rubygems_version: 3.
|
|
92
|
-
signing_key:
|
|
90
|
+
rubygems_version: 3.6.9
|
|
93
91
|
specification_version: 4
|
|
94
92
|
summary: User specific column configuration for ActiveScaffold
|
|
95
93
|
test_files: []
|