base_editing_bootstrap 0.9.1 → 0.10.1

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: 0c6c6f28177733d11676c8d4a02244cc35ecd6bdcd781810f5b8684e4d437740
4
- data.tar.gz: e74338339bd8cbb23c41c3ab297305b0808bc7330e28d5007b7b333e1aa04273
3
+ metadata.gz: 0cfab325e65eaeb13a6e34182d3c1a151c2d017ef22b6ad738018f8371c9ad91
4
+ data.tar.gz: 73ea49a506e054334cb49990a3b5cd6acbae01914ff1d6432715d2239f39968b
5
5
  SHA512:
6
- metadata.gz: 97129ae0001d5db7495a0f6001c6aeca698e226aeb78931296e0e14766f3fb4f11d8f138b881232668cc1703a76e6806ce0fd30f578d0764fd6bbb3cdf2cc661
7
- data.tar.gz: d0925d777f781941e8951e34d8d83710f2459da0cbba0f9354902cd4a5498bd3da49ceb978cf99bb1bd440f603593e6bec63a1d5d5f6fa1fa439ac465dcb3fe3
6
+ metadata.gz: 71569182d6f892535f8a780e09d4fbf842e042ba23b365f650761d8913d033abc1b703e4d4219b1bc10f0c6de5110debed48b4078619957aee25be0cbec2ef66
7
+ data.tar.gz: 8c7211b8e0342d014870df332e469697f7d7253f5e7fac39e8c72bdc6be13a90d3bc78d7dd7d55840795b2016f724b92998911dc07a9917024ee0c966b07e6a9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
+ ## 0.10.1 - 2024-07-25
6
+ #### Bug Fixes
7
+ - Change from controller_name to controller_path (#3) - (8b123a4) - Jury Ghidinelli
8
+
9
+ - - -
10
+
11
+ ## 0.10.0 - 2024-06-26
12
+ #### Features
13
+ - Add sort configuration per controller - (0cca665) - Marino Bonetti
14
+ #### Miscellaneous Chores
15
+ - Add ignore to assets - (aff4ac6) - Marino Bonetti
16
+
17
+ - - -
18
+
5
19
  ## 0.9.1 - 2024-06-17
6
20
  #### Bug Fixes
7
21
  - Change http status check from symbol to number - (1ecd63d) - Marino Bonetti
data/README.md CHANGED
@@ -86,6 +86,9 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
86
86
  - Creare Controller:
87
87
  ```ruby
88
88
  class PostsController < BaseEditingController
89
+ ##
90
+ # Set default sort order for ransack
91
+ # self.default_sort= ["id"]
89
92
  end
90
93
  ```
91
94
  - Aggiungere la rotta: `resources :posts`
@@ -9,12 +9,19 @@ class BaseEditingController < RestrictedAreaController
9
9
  :new_custom_polymorphic_path,
10
10
  :show_custom_polymorphic_path
11
11
 
12
+ ##
13
+ # Configure default sort in the index query.
14
+ # Works like documented in https://activerecord-hackery.github.io/ransack/getting-started/sorting/#sorting-in-the-controller
15
+ class_attribute :default_sorts, default: ["id"]
16
+
12
17
  def index
13
18
  authorize base_class
14
19
 
15
20
  q = policy_scope(base_scope)
16
-
17
- @search_instance = search_class.new(q, current_user, params: params.permit(:page, :q => {})) # FIXME trovare modo per essere più "STRONG"
21
+ @search_instance = search_class.new(q, current_user,
22
+ params: params.permit(:page, :q => {}), # FIXME trovare modo per essere più "STRONG"
23
+ sorts: default_sorts
24
+ )
18
25
  @search_instance = yield(@search_instance) if block_given?
19
26
  end
20
27
 
@@ -79,7 +86,7 @@ class BaseEditingController < RestrictedAreaController
79
86
 
80
87
  def base_class
81
88
  return @_base_class if @_base_class
82
- controller = controller_name
89
+ controller = controller_path
83
90
  modello = controller.singularize.camelize.safe_constantize
84
91
  logger.debug { "Editazione del controller:#{controller} per modello: #{modello.to_s}" }
85
92
  raise "Non riesco a restituire la classe base per il controller #{controller}" if modello.nil?
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.10.1
@@ -7,24 +7,26 @@ module BaseEditingBootstrap::Searches
7
7
  include ActiveModel::Naming
8
8
  include ActiveModel::Conversion
9
9
 
10
- attr_reader :model_klass, :user, :params, :scope
10
+ attr_reader :model_klass, :user, :params, :scope, :sorts
11
11
 
12
12
  # @param [User] user
13
13
  # @param [ActiveRecord::Associations::CollectionProxy] scope
14
- def initialize(scope, user, params: {page: nil})
14
+ # @param [Array<String (frozen)>] sort
15
+ def initialize(scope, user, params: {page: nil}, sorts: ["id"])
15
16
  @model_klass = scope.klass
16
17
  @user = user
17
18
  @scope = scope
18
19
  @params = params
20
+ @sorts = sorts
19
21
  end
20
22
 
21
23
  ##
22
24
  # Risultato della ricerca, fa da pipeline verso ransack
25
+ # Impostando il sort nel caso in cui non sia già stato impostato da ransack
23
26
  def results
24
- ransack_query
25
- .result(distinct: true)
26
- .order(:id)
27
- .page(params[:page])
27
+ ransack_query.tap { |r|
28
+ r.sorts = @sorts if r.sorts.empty?
29
+ }.result(distinct: true).page(params[:page])
28
30
  end
29
31
 
30
32
  def ransack_query
@@ -22,7 +22,7 @@ module BaseEditingBootstrap
22
22
  opts = ["--no-helper", "--parent=BaseEditingController"]
23
23
  opts << "--force" if options.force?
24
24
  generate "controller", controller_class_name, *opts
25
-
25
+ # TODO usare i template ed aggiungere l'esempio della ricerca
26
26
  route "resources :#{plural_name}"
27
27
 
28
28
  template "spec/request.rb", File.join("spec/requests", "#{plural_file_name}_spec.rb")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_editing_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails