active_scaffold_config_list 3.5.0 → 3.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a83952873751f4e7149b4e05e87d2e10cd6d36d6554578e50839d590f89233be
4
- data.tar.gz: 6aa24c34a3a32f89238d70974bf509e21c8db01fbb54e66a25d22ceff0b5e0bc
3
+ metadata.gz: f2c3d3d9d64fafc128d38bf32437db1f53505bde01601d1186f562f3df76e3cf
4
+ data.tar.gz: f43e78ff81d757bef7fe7ea35d79a5ad73d5b1280dc6460a371e7cf98b212c9e
5
5
  SHA512:
6
- metadata.gz: 7dba2ca3fe3875206b92b44c9f18bf3e7f1b0ba1cc08eb49e7cf1441eba9763aed4307b8cbfa68ac4fb9ace1d05efa1352d434500c55ea6642ed95f64c236c0f
7
- data.tar.gz: b92ffd411117506b501bf1133b3777e6ce93307f1b5bee06d5de9dbc2e938dc3bfae821e941e09ce8450688a9eacb0633c08ea832a025d6e508b7776afbb853d
6
+ metadata.gz: 61ee9652c00712cf1a5c3163f358cc4c2c6d46accec2abde2c554aaa3604ce09d98c0af694028aba107d4c7254bb52d221a9921c279804eb678a9ea0850d9c51
7
+ data.tar.gz: 77e1bbda33907266fb31d67722a85c8e22d06b61bd0181a476c80157c52a32c30ba196d579625a5fd45874da2a8b600d900835fce0461cbb43ad6ecf658f364e
data/README.md ADDED
@@ -0,0 +1,93 @@
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
5
+
6
+ Usage:
7
+
8
+ ```rb
9
+ active_scaffold :model do |conf|
10
+ conf.actions.add :config_list
11
+ end
12
+ ````
13
+
14
+
15
+ Overview
16
+ ========
17
+
18
+ A plugin for Active Scaffold that provides the ability to choose the column to show in the scaffold list at run-time.
19
+
20
+ You have the option of defining a default set of columns for the controller. For example:
21
+ ```rb
22
+ config.config_list.default_columns = [:name, :project, :amount]
23
+ ```
24
+ If this is not defined then active_scaffold_config.list.columns is used.
25
+
26
+ This is useful when you want the option to look at a potentially large number of columns but be able to
27
+ easily reset back to something that fits on the screen without horizontal scrolling.
28
+
29
+ The available columns in the configure action are the columns defined in `list.columns`. For that reason, if
30
+ `config_list.default_columns` is not defined, then it will default to `list.columns`, and the users only will be able
31
+ to remove some columns, they won't be able to add other columns.
32
+
33
+ The configuration data will be saved on the session. It can be saved on the DB defining a method on the user model
34
+ (the one returned by current_user method) to return a record for current controller, or empty record if user has no
35
+ list configuration, and setting config_list to use that method.
36
+
37
+ ```rb
38
+ conf.config_list.save_to_user = :config_list_for
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
+
49
+ The model storing list configuration must have a config_list text column storing the columns list, and config_list_sort
50
+ serialized text column. For example:
51
+
52
+ ```rb
53
+ # == Schema Information
54
+ #
55
+ # Table name: list_configurations
56
+ #
57
+ # id :bigint not null, primary key
58
+ # config_list :text
59
+ # config_list_sorting :text
60
+ # created_at :datetime not null
61
+ # updated_at :datetime not null
62
+ # controller_id :string(255)
63
+ # user_id :bigint
64
+ #
65
+ # Indexes
66
+ #
67
+ # index_list_configurations_on_user_id (user_id)
68
+ #
69
+
70
+ class ListConfiguration < ApplicationRecord
71
+ belongs_to :user
72
+ serialize :config_list_sorting, JSON
73
+ end
74
+ ```
75
+
76
+ Then in the User model, define the association, and the method returning the config list for the requested controller.
77
+ The method has 2 arguments, `controller_id` and `controller_name`, so only need to save one of them, depending if user
78
+ configuration must be shared on different conditions for embedded controllers, and each parent for nested controllers,
79
+ or save unique configurations. The `controller_id` argument will be different in embedded controllers, nested controllers
80
+ and regular controllers, as it will use `active_scaffold_session_storage_key`, and the controller_name will be the same
81
+ always.
82
+
83
+ ```rb
84
+ class User < ActiveRecord::Base
85
+ has_many :list_configurations
86
+ def config_list_for(controller_id, controller_name)
87
+ # Use controller_id to allow having different columns on different nested or embedded conditions
88
+ list_configurations.where(controller_id: controller_id).first_or_initialize
89
+ # Or use controller_name for one configuration for the controller, even embedded or nested
90
+ list_configurations.where(controller_id: controller_name).first_or_initialize
91
+ end
92
+ end
93
+ ```
@@ -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,28 +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
- base.extend ClassMethods
8
- end
9
-
10
- module ClassMethods
11
- def config_list_session_storage_method
12
- @config_list_session_storage_method
13
- end
14
-
15
- def config_list_session_storage_method=(value)
16
- @config_list_session_storage_method = value
17
- end
18
7
  end
19
8
 
20
9
  def show_config_list
21
10
  respond_to do |type|
22
11
  type.html do
23
- render(:action => 'show_config_list_form', :layout => true)
12
+ render(action: 'show_config_list_form', layout: true)
24
13
  end
25
14
  type.js do
26
- render(:partial => 'show_config_list_form', :layout => false)
15
+ render(partial: 'show_config_list_form', layout: false)
27
16
  end
28
17
  end
29
18
  end
@@ -57,12 +46,24 @@ module ActiveScaffold::Actions
57
46
  end
58
47
 
59
48
  def config_list_session_storage_method
60
- respond_to?(:custom_config_list_session_storage) ? :custom_config_list_session_storage : :active_scaffold_session_storage
49
+ @config_list_session_storage_method ||=
50
+ if respond_to?(:custom_config_list_session_storage)
51
+ :custom_config_list_session_storage
52
+ else
53
+ :active_scaffold_session_storage
54
+ end
61
55
  end
62
56
 
63
57
  def config_list_session_storage
64
- self.class.config_list_session_storage_method = self.config_list_session_storage_method unless self.class.config_list_session_storage_method
65
- send(self.class.config_list_session_storage_method)
58
+ send(config_list_session_storage_method)
59
+ end
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
66
67
  end
67
68
 
68
69
  def active_scaffold_current_user
@@ -71,20 +72,19 @@ module ActiveScaffold::Actions
71
72
 
72
73
  def delete_config_list_params
73
74
  if active_scaffold_config.config_list.save_to_user && active_scaffold_current_user
74
- 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
75
76
  else
76
77
  config_list_session_storage['config_list'] = nil
77
78
  config_list_session_storage['config_list_sorting'] = nil
78
79
  end
79
80
  active_scaffold_config.list.user['sort'] = nil
80
- logger.debug "list #{active_scaffold_config.list.sorting.object_id}"
81
81
  @config_list_params = nil
82
82
  @config_list_sorting = nil
83
83
  end
84
84
 
85
85
  def save_config_list_params(config_list, config_list_sorting)
86
86
  if active_scaffold_config.config_list.save_to_user && active_scaffold_current_user
87
- 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)
88
88
  record.config_list = config_list.join(',')
89
89
  record.config_list_sorting = config_list_sorting if record.respond_to? :config_list_sorting
90
90
  record.save
@@ -99,10 +99,10 @@ module ActiveScaffold::Actions
99
99
  def objects_for_etag
100
100
  # only override when list_columns is called, so
101
101
  if @list_columns && config_list_record
102
- @last_modified = [@last_modified, config_list_record.updated_at].compact.maximum if config_list_record.respond_to? :updated_at
102
+ @last_modified = [@last_modified, config_list_record.updated_at].compact.max if config_list_record.respond_to? :updated_at
103
103
  objects = super
104
104
  if objects.is_a? Hash
105
- objects.merge(:etag => [objects[:etag], config_list_record])
105
+ objects.merge(etag: [objects[:etag], config_list_record])
106
106
  else
107
107
  [objects, config_list_record]
108
108
  end
@@ -113,20 +113,22 @@ module ActiveScaffold::Actions
113
113
 
114
114
  def config_list_record
115
115
  return @config_list_record if defined? @config_list_record
116
- @config_list_record = if active_scaffold_config.config_list.save_to_user
117
- if active_scaffold_current_user
118
- 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)
119
119
  end
120
- end
121
120
  end
122
121
 
123
122
  def config_list_params
124
- @config_list_params = if config_list_record
125
- params = config_list_record.config_list
126
- params.split(',').map(&:to_sym) if params
127
- else
128
- config_list_session_storage['config_list']
129
- 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
130
132
  @config_list_params || config_list_default_columns
131
133
  end
132
134
 
@@ -135,11 +137,14 @@ module ActiveScaffold::Actions
135
137
  end
136
138
 
137
139
  def config_list_sorting
138
- @config_list_sorting = if config_list_record
139
- config_list_record.config_list_sorting if config_list_record.respond_to? :config_list_sorting
140
- else
141
- config_list_session_storage['config_list_sorting']
142
- 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
143
148
  @config_list_sorting
144
149
  end
145
150
 
@@ -147,8 +152,9 @@ module ActiveScaffold::Actions
147
152
  @list_columns ||= begin
148
153
  columns = super
149
154
  if config_list_params.present?
150
- config_list = Hash[config_list_params.each_with_index.map{|c,i| [c,i]}]
151
- 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] }
152
158
  else
153
159
  columns
154
160
  end
@@ -158,7 +164,7 @@ module ActiveScaffold::Actions
158
164
  # The default security delegates to ActiveRecordPermissions.
159
165
  # You may override the method to customize.
160
166
  def config_list_authorized?
161
- authorized_for?(:action => :read)
167
+ authorized_for?(action: :read)
162
168
  end
163
169
  end
164
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,7 +1,7 @@
1
1
  module ActiveScaffoldConfigList
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 5
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -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.0
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-04-05 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
@@ -43,10 +43,10 @@ email: activescaffold@googlegroups.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files:
46
- - README
46
+ - README.md
47
47
  files:
48
48
  - LICENSE.txt
49
- - README
49
+ - README.md
50
50
  - app/views/active_scaffold_overrides/_show_config_list_form.html.erb
51
51
  - app/views/active_scaffold_overrides/_show_config_list_form_body.html.erb
52
52
  - app/views/active_scaffold_overrides/show_config_list_form.html.erb
@@ -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
data/README DELETED
@@ -1,28 +0,0 @@
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
4
-
5
- Usage:
6
- active_scaffold :model do |conf|
7
- conf.actions.add :config_list
8
- end
9
-
10
-
11
- Overview
12
-
13
- A plugin for Active Scaffold that provides the ability to choose the column to show in the scaffold list at run-time
14
-
15
- The configuration data will be saved on the session. It can be saved on the DB defining a method to return a record
16
- for current controller, or empty record if user has no list configuration, and setting config_list to use that method.
17
-
18
- conf.config_list.save_to_user = :config_list_for
19
-
20
- class User < ActiveRecord::Base
21
- has_many :list_configurations
22
- def config_list_for(controller_id, controller_name)
23
- list_configurations.where(:controller_id => controller_id).first_or_initialize # different columns on different nested or embedded conditions
24
- list_configurations.where(:controller_id => controller_name).first_or_initialize # one configuration for the controller, even embedded or nested
25
- end
26
- end
27
-
28
- The model storing list configuration must have a config_list text column storing the config list, and config_list_sort serialized text column.