base_editing_bootstrap 0.9.1 → 0.10.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: 0c6c6f28177733d11676c8d4a02244cc35ecd6bdcd781810f5b8684e4d437740
4
- data.tar.gz: e74338339bd8cbb23c41c3ab297305b0808bc7330e28d5007b7b333e1aa04273
3
+ metadata.gz: ae3826e47810ce15c5ddb8c1e4abacb4af039cec40b2f2b835170691250357d0
4
+ data.tar.gz: '03069a335d73eaa8d449635c544315a154a66e18758f5d3e774f804e8fbf7d9b'
5
5
  SHA512:
6
- metadata.gz: 97129ae0001d5db7495a0f6001c6aeca698e226aeb78931296e0e14766f3fb4f11d8f138b881232668cc1703a76e6806ce0fd30f578d0764fd6bbb3cdf2cc661
7
- data.tar.gz: d0925d777f781941e8951e34d8d83710f2459da0cbba0f9354902cd4a5498bd3da49ceb978cf99bb1bd440f603593e6bec63a1d5d5f6fa1fa439ac465dcb3fe3
6
+ metadata.gz: 036470dfdaab3d46b054539d3a958bfed2138f443248f245917a1c258f420cf2a63174ff945ff164df62a001ad343814c48f87cf31c9cab696a9995b34d0b8ee
7
+ data.tar.gz: 2845c50faabf84b474f57c0144876e35661c22e38b042a4386f5c9f2eef01ba4f47b516cf6fff39cd051047920a1ac0de9da26978a5d0227952f8d201601a461
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
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.0 - 2024-06-26
6
+ #### Features
7
+ - Add sort configuration per controller - (0cca665) - Marino Bonetti
8
+ #### Miscellaneous Chores
9
+ - Add ignore to assets - (aff4ac6) - Marino Bonetti
10
+
11
+ - - -
12
+
5
13
  ## 0.9.1 - 2024-06-17
6
14
  #### Bug Fixes
7
15
  - 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
 
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.10.0
@@ -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.0
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-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails