active_scaffold_config_list 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be3b1357610333757d013332316debd39b636bb7f690a3cf57ed27088faf9abe
4
- data.tar.gz: 8940de8dc18e5575c74ed3604ddd22dfa6b06abf9a04503d1ffb2335858eb36c
3
+ metadata.gz: f2c3d3d9d64fafc128d38bf32437db1f53505bde01601d1186f562f3df76e3cf
4
+ data.tar.gz: f43e78ff81d757bef7fe7ea35d79a5ad73d5b1280dc6460a371e7cf98b212c9e
5
5
  SHA512:
6
- metadata.gz: 8171e1910707eca649a41a9df49b7c4333be31a65fde1d9ddfc083c19f92dabc76fd5fef0f5cd3b8f245b5a252033484a3b559a2ccd78a324247042de32ae776
7
- data.tar.gz: 6582db9e3c46b42c21330c4b67d0d726e6d55395db2e091849a59de9d09ff73b2b4ae261a2a6592819ffd7e9e7f308ca84660e57b35acbbe9b7daca05b40d73f
6
+ metadata.gz: 61ee9652c00712cf1a5c3163f358cc4c2c6d46accec2abde2c554aaa3604ce09d98c0af694028aba107d4c7254bb52d221a9921c279804eb678a9ea0850d9c51
7
+ data.tar.gz: 77e1bbda33907266fb31d67722a85c8e22d06b61bd0181a476c80157c52a32c30ba196d579625a5fd45874da2a8b600d900835fce0461cbb43ad6ecf658f364e
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- This works with Rails >= 4.0 and ActiveScaffold >= 3.4.4
2
- Version 3.3.x worked with Rails 3.2 and ActiveScaffold >= 3.4.4
3
- Version 3.2.x worked with Rails 3.2 and ActiveScaffold >= 3.3.0
1
+ This works with Rails >= 5.2 and ActiveScaffold >= 3.7.1
2
+ Version 3.4.x and 3.5.x worked with Rails >= 4.0 and ActiveScaffold >= 3.4.4
3
+ Version 3.3.x worked with Rails 3.2 and ActiveScaffold >= 3.4.4
4
+ Version 3.2.x worked with Rails 3.2 and ActiveScaffold >= 3.3.0
4
5
 
5
6
  Usage:
6
7
 
@@ -37,6 +38,14 @@ list configuration, and setting config_list to use that method.
37
38
  conf.config_list.save_to_user = :config_list_for
38
39
  ```
39
40
 
41
+ It can be changed globally for the app in `ActiveScaffold.defaults` in an initializer, such as:
42
+
43
+ ```rb
44
+ ActiveScaffold.defaults do |config|
45
+ config.config_list.save_to_user
46
+ end
47
+ ```
48
+
40
49
  The model storing list configuration must have a config_list text column storing the columns list, and config_list_sort
41
50
  serialized text column. For example:
42
51
 
@@ -1,16 +1,16 @@
1
- <% url_options = params_for(:action => :index, :escape => false, :config_list => nil) -%>
1
+ <% url_options = params_for(action: :index, escape: false, config_list: nil) -%>
2
2
  <%=
3
- options = {:id => element_form_id(:action => :config_list),
4
- :class => "as_form config_list",
5
- :remote => request.xhr?,
6
- :method => :get,
3
+ options = {id: element_form_id(action: :config_list),
4
+ class: "as_form config_list",
5
+ remote: request.xhr?,
6
+ method: :get,
7
7
  'data-loading' => true}
8
8
  form_tag url_options, options %>
9
9
  <h4><%= active_scaffold_config.config_list.label -%></h4>
10
- <%= render :partial => 'show_config_list_form_body' %>
10
+ <%= render 'show_config_list_form_body' %>
11
11
  <p class="form-footer">
12
- <%= submit_tag as_(:config_list), :class => "submit" %>
13
- <%= link_to as_(:reset), url_for(url_options.merge(:config_list => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %>
14
- <%= loading_indicator_tag(:action => :config_list) %>
12
+ <%= submit_tag as_(:config_list), class: "submit" %>
13
+ <%= link_to as_(:reset), url_for(url_options.merge(config_list: '')), class: 'as_cancel', remote: true, data: {refresh: true} %>
14
+ <%= loading_indicator_tag(action: :config_list) %>
15
15
  </p>
16
16
  </form>
@@ -1,33 +1,31 @@
1
1
  <ol class="form">
2
+ <% if config_list_columns? %>
2
3
  <li class="form-element">
3
4
  <dl><dt><label><%= as_ :columns %></label></dt>
4
- <dd><ul class="<%= active_scaffold_config.config_list.draggable ? 'draggable-lists' : 'sortable-container' %>" id="<%= element_form_id(:action => :config_list) %>-columns">
5
- <%
6
- if !config_list_params.nil? && config_list_params.is_a?(Array)
7
- config_list = config_list_params
8
- list_columns.concat active_scaffold_config.list.columns.visible_columns.select{|column| config_list.exclude? column.name}
9
- end
10
- %>
11
- <% list_columns.each do |c| %>
5
+ <dd><ul class="<%= active_scaffold_config.config_list.draggable ? 'draggable-lists' : 'sortable-container' %>" id="<%= element_form_id(action: :config_list) %>-columns">
6
+ <% config_list_columns.each do |label, column| %>
12
7
  <li class="sortable">
13
- <%= check_box_tag 'config_list[]', c.name.to_s, (config_list_params.nil? ? true : config_list_params.include?(c.name)), {:id => nil}%>
14
- <label><%= column_heading_label(c) %></label>
8
+ <%= check_box_tag 'config_list[]', column.to_s, (config_list_params.nil? ? true : config_list_params.include?(column)), {id: nil}%>
9
+ <label><%= label %></label>
15
10
  </li>
16
11
  <% end %>
17
12
  </ul></dd></dl>
18
13
  </li>
14
+ <% end %>
15
+ <% if config_list_sorting? %>
19
16
  <li class="form-element">
20
17
  <dl><dt><label><%= as_ :default_sorting %></label></dt>
21
18
  <dd><ol>
22
19
  <%
23
- columns_options = list_columns.select{|c| c.sortable?}.map{|c| [c.label, c.name]}
24
- order_options = ['asc', 'desc'].map{ |v| [as_(v), v] }
20
+ columns_options = list_columns.select(&:sortable?).map { |c| [c.label, c.name] }
21
+ order_options = ['asc', 'desc'].map { |v| [as_(v), v] }
25
22
  selected = config_list_sorting || []
26
23
  3.times do |i|
27
24
  %>
28
- <li><%= select_tag "config_list_sorting[#{i}][]", options_for_select(columns_options, :selected => selected[i].try(:first)), :include_blank => as_(:_select_), :class => 'column' %>
29
- <%= select_tag "config_list_sorting[#{i}][]", options_for_select(order_options, :selected => selected[i].try(:last)), :include_blank => as_(:_select_), :class => 'order' %></li>
25
+ <li><%= select_tag "config_list_sorting[#{i}][]", options_for_select(columns_options, selected: selected[i]&.first), include_blank: as_(:_select_), class: 'column' %>
26
+ <%= select_tag "config_list_sorting[#{i}][]", options_for_select(order_options, selected: selected[i]&.last), include_blank: as_(:_select_), class: 'order' %></li>
30
27
  <% end %>
31
28
  </ol></dd></dl>
32
29
  </li>
30
+ <% end %>
33
31
  </ol>
@@ -1,5 +1,5 @@
1
1
  <div class="active-scaffold">
2
2
  <div class="config_list-view view">
3
- <%= render :partial => 'show_config_list_form' -%>
3
+ <%= render 'show_config_list_form' -%>
4
4
  </div>
5
5
  </div>
@@ -2,17 +2,17 @@ module ActiveScaffold::Actions
2
2
  module ConfigList
3
3
 
4
4
  def self.included(base)
5
- base.before_action :store_config_list_params, :set_default_sorting, :only => [:index]
5
+ base.before_action :store_config_list_params, :set_default_sorting, only: [:index]
6
6
  base.helper_method :config_list_params, :config_list_sorting
7
7
  end
8
8
 
9
9
  def show_config_list
10
10
  respond_to do |type|
11
11
  type.html do
12
- render(:action => 'show_config_list_form', :layout => true)
12
+ render(action: 'show_config_list_form', layout: true)
13
13
  end
14
14
  type.js do
15
- render(:partial => 'show_config_list_form', :layout => false)
15
+ render(partial: 'show_config_list_form', layout: false)
16
16
  end
17
17
  end
18
18
  end
@@ -58,13 +58,21 @@ module ActiveScaffold::Actions
58
58
  send(config_list_session_storage_method)
59
59
  end
60
60
 
61
+ def config_list_session_storage_key
62
+ active_scaffold_session_storage_key
63
+ end
64
+
65
+ def config_list_controller_name
66
+ controller_name
67
+ end
68
+
61
69
  def active_scaffold_current_user
62
70
  @active_scaffold_current_user ||= send(self.class.active_scaffold_config.class.security.current_user_method)
63
71
  end
64
72
 
65
73
  def delete_config_list_params
66
74
  if active_scaffold_config.config_list.save_to_user && active_scaffold_current_user
67
- active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name).destroy
75
+ active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, config_list_session_storage_key, config_list_controller_name).destroy
68
76
  else
69
77
  config_list_session_storage['config_list'] = nil
70
78
  config_list_session_storage['config_list_sorting'] = nil
@@ -76,7 +84,7 @@ module ActiveScaffold::Actions
76
84
 
77
85
  def save_config_list_params(config_list, config_list_sorting)
78
86
  if active_scaffold_config.config_list.save_to_user && active_scaffold_current_user
79
- record = active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name)
87
+ record = active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, config_list_session_storage_key, config_list_controller_name)
80
88
  record.config_list = config_list.join(',')
81
89
  record.config_list_sorting = config_list_sorting if record.respond_to? :config_list_sorting
82
90
  record.save
@@ -94,7 +102,7 @@ module ActiveScaffold::Actions
94
102
  @last_modified = [@last_modified, config_list_record.updated_at].compact.max if config_list_record.respond_to? :updated_at
95
103
  objects = super
96
104
  if objects.is_a? Hash
97
- objects.merge(:etag => [objects[:etag], config_list_record])
105
+ objects.merge(etag: [objects[:etag], config_list_record])
98
106
  else
99
107
  [objects, config_list_record]
100
108
  end
@@ -105,20 +113,22 @@ module ActiveScaffold::Actions
105
113
 
106
114
  def config_list_record
107
115
  return @config_list_record if defined? @config_list_record
108
- @config_list_record = if active_scaffold_config.config_list.save_to_user
109
- if active_scaffold_current_user
110
- active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, active_scaffold_session_storage_key, controller_name)
116
+ @config_list_record =
117
+ if active_scaffold_config.config_list.save_to_user && active_scaffold_current_user
118
+ active_scaffold_current_user.send(active_scaffold_config.config_list.save_to_user, config_list_session_storage_key, config_list_controller_name)
111
119
  end
112
- end
113
120
  end
114
121
 
115
122
  def config_list_params
116
- @config_list_params = if config_list_record
117
- params = config_list_record.config_list
118
- params.split(',').map(&:to_sym) if params
119
- else
120
- config_list_session_storage['config_list']
121
- end unless defined? @config_list_params
123
+ unless defined? @config_list_params
124
+ @config_list_params =
125
+ if config_list_record
126
+ params = config_list_record.config_list
127
+ params.split(',').map(&:to_sym) if params
128
+ else
129
+ config_list_session_storage['config_list']
130
+ end
131
+ end
122
132
  @config_list_params || config_list_default_columns
123
133
  end
124
134
 
@@ -127,11 +137,14 @@ module ActiveScaffold::Actions
127
137
  end
128
138
 
129
139
  def config_list_sorting
130
- @config_list_sorting = if config_list_record
131
- config_list_record.config_list_sorting if config_list_record.respond_to? :config_list_sorting
132
- else
133
- config_list_session_storage['config_list_sorting']
134
- end unless defined? @config_list_sorting
140
+ unless defined? @config_list_sorting
141
+ @config_list_sorting =
142
+ if config_list_record
143
+ config_list_record.config_list_sorting if config_list_record.respond_to? :config_list_sorting
144
+ else
145
+ config_list_session_storage['config_list_sorting']
146
+ end
147
+ end
135
148
  @config_list_sorting
136
149
  end
137
150
 
@@ -139,8 +152,9 @@ module ActiveScaffold::Actions
139
152
  @list_columns ||= begin
140
153
  columns = super
141
154
  if config_list_params.present?
142
- config_list = Hash[config_list_params.each_with_index.map{|c,i| [c,i]}]
143
- columns.select{|column| config_list.include? column.name}.sort{|x,y| config_list[x.name] <=> config_list[y.name]}
155
+ config_list = config_list_params.each.with_index.to_h
156
+ columns.select { |column| config_list.include? column.name }.
157
+ sort { |x, y| config_list[x.name] <=> config_list[y.name] }
144
158
  else
145
159
  columns
146
160
  end
@@ -150,7 +164,7 @@ module ActiveScaffold::Actions
150
164
  # The default security delegates to ActiveRecordPermissions.
151
165
  # You may override the method to customize.
152
166
  def config_list_authorized?
153
- authorized_for?(:action => :read)
167
+ authorized_for?(action: :read)
154
168
  end
155
169
  end
156
170
  end
@@ -0,0 +1,24 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ module ConfigListHelpers
4
+ def config_list_sorting?
5
+ true
6
+ end
7
+
8
+ def config_list_columns?
9
+ true
10
+ end
11
+
12
+ def config_list_columns
13
+ columns =
14
+ if config_list_params.is_a?(Array)
15
+ config_list = config_list_params
16
+ list_columns.concat active_scaffold_config.list.columns.visible_columns.select { |column| config_list.exclude? column.name }
17
+ else
18
+ list_columns
19
+ end
20
+ columns.map { |c| [column_heading_label(c), c.name] }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -5,5 +5,11 @@ module ActiveScaffoldConfigList
5
5
  self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:show_config_list] = :get
6
6
  end
7
7
  end
8
+
9
+ initializer 'active_scaffold_config_list.action_view' do
10
+ ActiveSupport.on_load :action_view do
11
+ ActionView::Base.send :include, ActiveScaffold::Helpers::ConfigListHelpers
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldConfigList
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 5
5
- PATCH = 1
4
+ MINOR = 6
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -9,4 +9,9 @@ module ActiveScaffold
9
9
  module Config
10
10
  ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
11
11
  end
12
+
13
+ module Helpers
14
+ ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
15
+ end
12
16
  end
17
+ ActiveSupport.run_load_hooks(:active_scaffold_config_list)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_config_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-25 00:00:00.000000000 Z
11
+ date: 2024-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_scaffold
@@ -59,6 +59,7 @@ files:
59
59
  - config/locales/ru.yml
60
60
  - lib/active_scaffold/actions/config_list.rb
61
61
  - lib/active_scaffold/config/config_list.rb
62
+ - lib/active_scaffold/helpers/config_list_helpers.rb
62
63
  - lib/active_scaffold_config_list.rb
63
64
  - lib/active_scaffold_config_list/engine.rb
64
65
  - lib/active_scaffold_config_list/version.rb
@@ -74,14 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
75
  requirements:
75
76
  - - ">="
76
77
  - !ruby/object:Gem::Version
77
- version: '0'
78
+ version: '2.5'
78
79
  required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  requirements: []
84
- rubygems_version: 3.2.3
85
+ rubygems_version: 3.5.11
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: User specific column configuration for ActiveScaffold